implementovane ulozenie do backend presuvanie reportov v dashboad
This commit is contained in:
parent
c82df663df
commit
eab71c2c4d
18
api.php
18
api.php
@ -16,10 +16,14 @@ switch ($action) {
|
||||
$result = array('report_id' => $report_id);
|
||||
break;
|
||||
case 'update':
|
||||
$result = reportUpdate($_REQUEST['report_id'], $_REQUEST['title'], $_REQUEST['description'], $_REQUEST['status'], $_REQUEST['group'], $_REQUEST['priority']);
|
||||
$suc = reportUpdate($_REQUEST['report_id'], $_REQUEST['title'], $_REQUEST['description'], $_REQUEST['status'], $_REQUEST['group'], $_REQUEST['priority']);
|
||||
if ($suc === false) $error = 'Update failed';
|
||||
$result = array('processed' => $suc);
|
||||
break;
|
||||
case 'delete':
|
||||
$result = reportDelete($_REQUEST['report_id']);
|
||||
$suc = reportDelete($_REQUEST['report_id']);
|
||||
if ($suc === false) $error = 'Update failed';
|
||||
$result = array('processed' => $suc);
|
||||
break;
|
||||
case 'get':
|
||||
$result = reportGet($_REQUEST['report_id']);
|
||||
@ -30,6 +34,16 @@ switch ($action) {
|
||||
case 'getallgrouped':
|
||||
$result = reportGetAllGrouped($_REQUEST['status']);
|
||||
break;
|
||||
case 'updateordnum':
|
||||
$suc = reportUpdateOrdnum($_REQUEST['ordnums']);
|
||||
if ($suc === false) $error = 'Update Ordnum failed';
|
||||
$result = array('processed' => $suc);
|
||||
break;
|
||||
case 'updatestatus':
|
||||
$suc = reportUpdateStatus($_REQUEST['report_id'], $_REQUEST['status']);
|
||||
if ($suc === false) $error = 'Update Status failed';
|
||||
$result = array('processed' => $suc);
|
||||
break;
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
@ -91,6 +91,11 @@ function dbCheck() {
|
||||
option('version', '2');
|
||||
$db_version = '2';
|
||||
}
|
||||
if ($db_version === '2') {
|
||||
$db->query("ALTER TABLE reports ADD COLUMN ordnum INTEGER DEFAULT 0");
|
||||
option('version', '3');
|
||||
$db_version = '3';
|
||||
}
|
||||
}
|
||||
|
||||
function option($key, $value = null)
|
||||
@ -148,7 +153,7 @@ function reportAdd($title, $description, $status = 0, $group = null, $priority =
|
||||
|
||||
function reportUpdate($report_id, $title, $description, $status = 0, $group = null, $priority = 0) {
|
||||
global $db;
|
||||
return $db->update('reports', [
|
||||
$stm = $db->update('reports', [
|
||||
'report_title' => $title,
|
||||
'report_description' => $description,
|
||||
'report_status' => $status,
|
||||
@ -157,13 +162,40 @@ function reportUpdate($report_id, $title, $description, $status = 0, $group = nu
|
||||
], [
|
||||
'report_id' => $report_id
|
||||
]);
|
||||
return ($stm->rowCount() > 0);
|
||||
}
|
||||
|
||||
function reportUpdateStatus($report_id, $status) {
|
||||
global $db;
|
||||
$stm = $db->update('reports', [
|
||||
'report_status' => $status
|
||||
], [
|
||||
'report_id' => $report_id
|
||||
]);
|
||||
return ($stm->rowCount() > 0);
|
||||
}
|
||||
|
||||
function reportUpdateOrdnum($ordnums) {
|
||||
global $db;
|
||||
$ordnums = json_decode($ordnums, true);
|
||||
$suc = true;
|
||||
foreach ($ordnums as $report_id => $ordnum) {
|
||||
$stm = $db->update('reports', [
|
||||
'ordnum' => $ordnum
|
||||
], [
|
||||
'report_id' => $report_id
|
||||
]);
|
||||
$suc &= ($stm->rowCount() > 0);
|
||||
}
|
||||
return $suc;
|
||||
}
|
||||
|
||||
function reportDelete($report_id) {
|
||||
global $db;
|
||||
return $db->delete('reports', [
|
||||
$stm = $db->delete('reports', [
|
||||
'report_id' => $report_id
|
||||
]);
|
||||
return ($stm->rowCount() > 0);
|
||||
}
|
||||
|
||||
function reportGet($report_id) {
|
||||
@ -175,14 +207,14 @@ function reportGet($report_id) {
|
||||
|
||||
function reportGetAll($status = null) {
|
||||
global $db;
|
||||
if ($status === null) $status = array(0, 1, 2, 3);
|
||||
return $db->select('reports', '*', [
|
||||
'ORDER' => 'report_priority',
|
||||
'ORDER' => ['report_priority', 'ordnum'],
|
||||
'report_status' => $status
|
||||
]);
|
||||
}
|
||||
|
||||
function reportGetAllGrouped($status = null) {
|
||||
if ($status === null) $status = array(0, 1, 2, 3);
|
||||
$all = reportGetAll($status);
|
||||
$groups = [];
|
||||
foreach ($all as $report) {
|
||||
|
@ -20,7 +20,9 @@ export const backend = {
|
||||
}
|
||||
var form_data = new FormData();
|
||||
Object.keys(data).forEach(key => {
|
||||
form_data.append(key, data[key]);
|
||||
let val = data[key];
|
||||
if (typeof val == 'object') val = JSON.stringify(val);
|
||||
form_data.append(key, val);
|
||||
});
|
||||
xhttp.open('POST', this.endpont + '?action=' + method);
|
||||
//xhttp.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
|
||||
@ -53,7 +55,7 @@ export const backend = {
|
||||
|
||||
update(id, title, description, status, group, priority) {
|
||||
return this.callPromise('update', {
|
||||
id: id,
|
||||
report_id: id,
|
||||
title: title,
|
||||
description: description,
|
||||
status: status,
|
||||
@ -62,11 +64,11 @@ export const backend = {
|
||||
},
|
||||
|
||||
delete(id) {
|
||||
return this.callPromise('delete', {id: id});
|
||||
return this.callPromise('delete', {report_id: id});
|
||||
},
|
||||
|
||||
get(id) {
|
||||
return this.callPromise('get', {id: id});
|
||||
return this.callPromise('get', {report_id: id});
|
||||
},
|
||||
|
||||
getAll() {
|
||||
@ -77,4 +79,12 @@ export const backend = {
|
||||
return this.callPromise('getallgrouped', {});
|
||||
},
|
||||
|
||||
updateOrdnum(ordnums) {
|
||||
return this.callPromise('updateordnum', {ordnums: ordnums});
|
||||
},
|
||||
|
||||
updateStatus(id, status) {
|
||||
return this.callPromise('updatestatus', {report_id: id, status: status});
|
||||
},
|
||||
|
||||
};
|
||||
|
@ -149,21 +149,68 @@ export default {
|
||||
this.itemsWaiting = all_grouped[1];
|
||||
this.itemsInProgress = all_grouped[2];
|
||||
this.itemsDone = all_grouped[3];
|
||||
})
|
||||
});
|
||||
},
|
||||
getDataByStatus(report_status) {
|
||||
let for_reorder = null;
|
||||
switch (report_status) {
|
||||
case 0:
|
||||
for_reorder = this.itemsUncategorized;
|
||||
break;
|
||||
case 1:
|
||||
for_reorder = this.itemsWaiting;
|
||||
break;
|
||||
case 2:
|
||||
for_reorder = this.itemsInProgress;
|
||||
break;
|
||||
case 3:
|
||||
for_reorder = this.itemsDone;
|
||||
break;
|
||||
}
|
||||
return for_reorder;
|
||||
},
|
||||
searchStatusByReportId(report_id) {
|
||||
for (let i = 0; i < this.itemsUncategorized.length; i++) {
|
||||
if (this.itemsUncategorized[i].report_id === report_id) return 0;
|
||||
}
|
||||
for (let i = 0; i < this.itemsWaiting.length; i++) {
|
||||
if (this.itemsWaiting[i].report_id === report_id) return 1;
|
||||
}
|
||||
for (let i = 0; i < this.itemsInProgress.length; i++) {
|
||||
if (this.itemsInProgress[i].report_id === report_id) return 2;
|
||||
}
|
||||
for (let i = 0; i < this.itemsDone.length; i++) {
|
||||
if (this.itemsDone[i].report_id === report_id) return 3;
|
||||
}
|
||||
},
|
||||
onDragChange(event) {
|
||||
// console.log("Presunuté:", event);
|
||||
// Napr. uložiť poradie do API
|
||||
// console.log("onDragChange", event);
|
||||
if (event.added) {
|
||||
console.log("Pridané:", event.added.element);
|
||||
// console.log("Pridané:", event.added.element);
|
||||
let report_id = event.added.element.report_id;
|
||||
let new_reprort_status = this.searchStatusByReportId(report_id);
|
||||
let for_reorder = this.getDataByStatus(new_reprort_status);
|
||||
backend.updateStatus(report_id, new_reprort_status).then(() => {
|
||||
this.updateOrdnum(for_reorder);
|
||||
});
|
||||
}
|
||||
if (event.moved) {
|
||||
console.log("Presunuté:", event.moved.element);
|
||||
// console.log("Presunuté:", event.moved.element);
|
||||
let report_status = event.moved.element.report_status;
|
||||
let for_reorder = this.getDataByStatus(report_status);
|
||||
this.updateOrdnum(for_reorder);
|
||||
}
|
||||
if (event.removed) {
|
||||
console.log("Odstranené:", event.removed.element);
|
||||
// console.log("Odstranené:", event.removed.element);
|
||||
}
|
||||
},
|
||||
updateOrdnum(for_reorder) {
|
||||
let new_ordnums = {};
|
||||
for (let i = 0; i < for_reorder.length; i++) {
|
||||
new_ordnums[for_reorder[i].report_id] = i;
|
||||
}
|
||||
backend.updateOrdnum(new_ordnums);
|
||||
},
|
||||
vypisData() {
|
||||
console.log(this.itemsUncategorized);
|
||||
console.log(this.itemsWaiting);
|
||||
|
Loading…
x
Reference in New Issue
Block a user