pridana API metoda getallgrouped,
implementovane nacitanie dat do Dashboard z backend
This commit is contained in:
parent
93126ecd47
commit
c82df663df
29
api.php
29
api.php
@ -2,6 +2,8 @@
|
|||||||
include_once 'config.php';
|
include_once 'config.php';
|
||||||
|
|
||||||
$action = $_REQUEST['action'];
|
$action = $_REQUEST['action'];
|
||||||
|
$result = null;
|
||||||
|
$error = null;
|
||||||
|
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
default:
|
default:
|
||||||
@ -9,7 +11,9 @@ switch ($action) {
|
|||||||
$result = help();
|
$result = help();
|
||||||
break;
|
break;
|
||||||
case 'add':
|
case 'add':
|
||||||
$result = reportAdd($_REQUEST['title'], $_REQUEST['description'], $_REQUEST['status'], $_REQUEST['group'], $_REQUEST['priority']);
|
$report_id = reportAdd($_REQUEST['title'], $_REQUEST['description'], $_REQUEST['status'], $_REQUEST['group'], $_REQUEST['priority']);
|
||||||
|
if ($report_id === false) $error = 'Report add failed';
|
||||||
|
$result = array('report_id' => $report_id);
|
||||||
break;
|
break;
|
||||||
case 'update':
|
case 'update':
|
||||||
$result = reportUpdate($_REQUEST['report_id'], $_REQUEST['title'], $_REQUEST['description'], $_REQUEST['status'], $_REQUEST['group'], $_REQUEST['priority']);
|
$result = reportUpdate($_REQUEST['report_id'], $_REQUEST['title'], $_REQUEST['description'], $_REQUEST['status'], $_REQUEST['group'], $_REQUEST['priority']);
|
||||||
@ -23,13 +27,26 @@ switch ($action) {
|
|||||||
case 'getall':
|
case 'getall':
|
||||||
$result = reportGetAll($_REQUEST['status']);
|
$result = reportGetAll($_REQUEST['status']);
|
||||||
break;
|
break;
|
||||||
|
case 'getallgrouped':
|
||||||
|
$result = reportGetAllGrouped($_REQUEST['status']);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
echo json_encode($result);
|
$origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : '*';
|
||||||
|
header('Access-Control-Allow-Origin: ' . $origin);
|
||||||
|
header('Access-Control-Allow-Credentials: true');
|
||||||
|
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
|
||||||
|
header('Access-Control-Allow-Headers: Origin, Content-Type, Accept');
|
||||||
|
echo json_encode(
|
||||||
|
is_null($error)
|
||||||
|
? array('status' => 'OK', 'data' => $result)
|
||||||
|
: array('status' => 'ERROR', 'msg' => $error),
|
||||||
|
);
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
function help() {
|
function help()
|
||||||
|
{
|
||||||
return [
|
return [
|
||||||
'actions' => [
|
'actions' => [
|
||||||
'help' => 'Show this help',
|
'help' => 'Show this help',
|
||||||
@ -37,10 +54,8 @@ function help() {
|
|||||||
'update' => 'Update report',
|
'update' => 'Update report',
|
||||||
'delete' => 'Delete report',
|
'delete' => 'Delete report',
|
||||||
'get' => 'Get report',
|
'get' => 'Get report',
|
||||||
'getall' => 'Get all reports'
|
'getall' => 'Get all reports',
|
||||||
|
'getallgrouped' => 'Get all reports grouped by group',
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
@ -1,5 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
if (file_exists('c:/php/includes/igor.php')) {
|
||||||
|
require_once 'c:/php/includes/igor.php';
|
||||||
|
}
|
||||||
|
|
||||||
require_once __DIR__.'/lib/functions.inc.php';
|
require_once __DIR__.'/lib/functions.inc.php';
|
||||||
require_once __DIR__.'/lib/Medoo/src/Medoo.php';
|
require_once __DIR__.'/lib/Medoo/src/Medoo.php';
|
||||||
|
|
||||||
|
194
lib/functions.inc.php
Normal file
194
lib/functions.inc.php
Normal file
@ -0,0 +1,194 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check database
|
||||||
|
*/
|
||||||
|
function dbCheck() {
|
||||||
|
global $db;
|
||||||
|
$db_version = option('version');
|
||||||
|
if ($db_version === null) {
|
||||||
|
$db->create('options', [
|
||||||
|
'key' => [
|
||||||
|
'VARCHAR(64)',
|
||||||
|
'NOT NULL',
|
||||||
|
'UNIQUE'
|
||||||
|
],
|
||||||
|
'value' => [
|
||||||
|
'TEXT',
|
||||||
|
'NOT NULL'
|
||||||
|
],
|
||||||
|
'created_at' => [
|
||||||
|
'DATETIME',
|
||||||
|
'DEFAULT CURRENT_TIMESTAMP'
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
option('version', '0');
|
||||||
|
$db_version = '0';
|
||||||
|
}
|
||||||
|
if ($db_version === '0') {
|
||||||
|
$db->create('reports', [
|
||||||
|
'report_id' => [
|
||||||
|
'INTEGER',
|
||||||
|
'PRIMARY KEY',
|
||||||
|
'AUTOINCREMENT'
|
||||||
|
],
|
||||||
|
'report_title' => [
|
||||||
|
'VARCHAR(255)',
|
||||||
|
'DEFAULT NULL'
|
||||||
|
],
|
||||||
|
'report_description' => [
|
||||||
|
'TEXT',
|
||||||
|
'DEFAULT NULL'
|
||||||
|
],
|
||||||
|
'report_status' => [
|
||||||
|
'INTEGER',
|
||||||
|
'DEFAULT 0'
|
||||||
|
],
|
||||||
|
'report_group' => [
|
||||||
|
'VARCHAR(255)',
|
||||||
|
'DEFAULT NULL'
|
||||||
|
],
|
||||||
|
'report_priority' => [
|
||||||
|
'INTEGER',
|
||||||
|
'DEFAULT 0'
|
||||||
|
],
|
||||||
|
'created_dt' => [
|
||||||
|
'DATETIME',
|
||||||
|
'DEFAULT NULL'
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
option('version', '1');
|
||||||
|
$db_version = '1';
|
||||||
|
}
|
||||||
|
if ($db_version === '1') {
|
||||||
|
$db->create('attachments', [
|
||||||
|
'attachment_id' => [
|
||||||
|
'INTEGER',
|
||||||
|
'PRIMARY KEY',
|
||||||
|
'AUTOINCREMENT'
|
||||||
|
],
|
||||||
|
'report_id' => [
|
||||||
|
'INTEGER',
|
||||||
|
'NOT NULL'
|
||||||
|
],
|
||||||
|
'attachment_type' => [
|
||||||
|
'VARCHAR(255)',
|
||||||
|
'DEFAULT NULL'
|
||||||
|
],
|
||||||
|
'attachment_content' => [
|
||||||
|
'TEXT',
|
||||||
|
'DEFAULT NULL'
|
||||||
|
],
|
||||||
|
'created_dt' => [
|
||||||
|
'DATETIME',
|
||||||
|
'DEFAULT NULL'
|
||||||
|
],
|
||||||
|
'updated_dt' => [
|
||||||
|
'DATETIME',
|
||||||
|
'DEFAULT NULL'
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
option('version', '2');
|
||||||
|
$db_version = '2';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function option($key, $value = null)
|
||||||
|
{
|
||||||
|
global $db;
|
||||||
|
if (tableExits('options') === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if ($value === null) {
|
||||||
|
return $db->get('options', 'value', [
|
||||||
|
'key' => $key
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
$exits = $db->get('options', 'value', [
|
||||||
|
'key' => $key
|
||||||
|
]);
|
||||||
|
if ($exits !== null) {
|
||||||
|
return $db->update('options', [
|
||||||
|
'value' => $value
|
||||||
|
], [
|
||||||
|
'key' => $key
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
return $db->insert('options', [
|
||||||
|
'key' => $key,
|
||||||
|
'value' => $value
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function tableExits($table) {
|
||||||
|
global $db;
|
||||||
|
return $db->get('sqlite_master', 'name', [
|
||||||
|
'type' => 'table',
|
||||||
|
'name' => $table
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reports
|
||||||
|
*/
|
||||||
|
function reportAdd($title, $description, $status = 0, $group = null, $priority = 0) {
|
||||||
|
global $db;
|
||||||
|
$status = intval($status);
|
||||||
|
$priority = intval($priority);
|
||||||
|
$db->insert('reports', [
|
||||||
|
'report_title' => $title,
|
||||||
|
'report_description' => $description,
|
||||||
|
'report_status' => $status,
|
||||||
|
'report_group' => $group,
|
||||||
|
'report_priority' => $priority,
|
||||||
|
'created_dt' => date('Y-m-d H:i:s')
|
||||||
|
]);
|
||||||
|
return $db->id();
|
||||||
|
}
|
||||||
|
|
||||||
|
function reportUpdate($report_id, $title, $description, $status = 0, $group = null, $priority = 0) {
|
||||||
|
global $db;
|
||||||
|
return $db->update('reports', [
|
||||||
|
'report_title' => $title,
|
||||||
|
'report_description' => $description,
|
||||||
|
'report_status' => $status,
|
||||||
|
'report_group' => $group,
|
||||||
|
'report_priority' => $priority,
|
||||||
|
], [
|
||||||
|
'report_id' => $report_id
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function reportDelete($report_id) {
|
||||||
|
global $db;
|
||||||
|
return $db->delete('reports', [
|
||||||
|
'report_id' => $report_id
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function reportGet($report_id) {
|
||||||
|
global $db;
|
||||||
|
return $db->get('reports', '*', [
|
||||||
|
'report_id' => $report_id
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function reportGetAll($status = null) {
|
||||||
|
global $db;
|
||||||
|
return $db->select('reports', '*', [
|
||||||
|
'ORDER' => 'report_priority',
|
||||||
|
'report_status' => $status
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function reportGetAllGrouped($status = null) {
|
||||||
|
if ($status === null) $status = array(0, 1, 2, 3);
|
||||||
|
$all = reportGetAll($status);
|
||||||
|
$groups = [];
|
||||||
|
foreach ($all as $report) {
|
||||||
|
$groups[$report['report_status']][] = $report;
|
||||||
|
}
|
||||||
|
return $groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -73,4 +73,8 @@ export const backend = {
|
|||||||
return this.callPromise('getall', {});
|
return this.callPromise('getall', {});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getAllGrouped(status) {
|
||||||
|
return this.callPromise('getallgrouped', {});
|
||||||
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<h2>Nezaradené</h2>
|
<h2>Nezaradené</h2>
|
||||||
<draggable
|
<draggable
|
||||||
v-model="itemsUncategorized"
|
v-model="itemsUncategorized"
|
||||||
item-key="id"
|
item-key="report_id"
|
||||||
:group="{ name: 'itemsUncategorized', pull: true, put: true }"
|
:group="{ name: 'itemsUncategorized', pull: true, put: true }"
|
||||||
@change="onDragChange"
|
@change="onDragChange"
|
||||||
@start="onDragStart"
|
@start="onDragStart"
|
||||||
@ -18,9 +18,9 @@
|
|||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<Report
|
<Report
|
||||||
:title="element.title"
|
:title="element.report_title"
|
||||||
:description="element.description"
|
:description="element.report_description"
|
||||||
:date="element.date"
|
:date="element.created_dt"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -30,7 +30,7 @@
|
|||||||
<h2>Čakajúce</h2>
|
<h2>Čakajúce</h2>
|
||||||
<draggable
|
<draggable
|
||||||
v-model="itemsWaiting"
|
v-model="itemsWaiting"
|
||||||
item-key="id"
|
item-key="report_id"
|
||||||
:group="{ name: 'itemsWaiting', pull: true, put: true }"
|
:group="{ name: 'itemsWaiting', pull: true, put: true }"
|
||||||
@change="onDragChange"
|
@change="onDragChange"
|
||||||
@start="onDragStart"
|
@start="onDragStart"
|
||||||
@ -44,9 +44,9 @@
|
|||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<Report
|
<Report
|
||||||
:title="element.title"
|
:title="element.report_title"
|
||||||
:description="element.description"
|
:description="element.report_description"
|
||||||
:date="element.date"
|
:date="element.created_dt"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -56,7 +56,7 @@
|
|||||||
<h2>Rozpracované</h2>
|
<h2>Rozpracované</h2>
|
||||||
<draggable
|
<draggable
|
||||||
v-model="itemsInProgress"
|
v-model="itemsInProgress"
|
||||||
item-key="id"
|
item-key="report_id"
|
||||||
:group="{ name: 'itemsInProgress', pull: true, put: true }"
|
:group="{ name: 'itemsInProgress', pull: true, put: true }"
|
||||||
@change="onDragChange"
|
@change="onDragChange"
|
||||||
@start="onDragStart"
|
@start="onDragStart"
|
||||||
@ -70,9 +70,9 @@
|
|||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<Report
|
<Report
|
||||||
:title="element.title"
|
:title="element.report_title"
|
||||||
:description="element.description"
|
:description="element.report_description"
|
||||||
:date="element.date"
|
:date="element.created_dt"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -82,7 +82,7 @@
|
|||||||
<h2>Hotové</h2>
|
<h2>Hotové</h2>
|
||||||
<draggable
|
<draggable
|
||||||
v-model="itemsDone"
|
v-model="itemsDone"
|
||||||
item-key="id"
|
item-key="report_id"
|
||||||
:group="{ name: 'itemsDone', pull: true, put: true }"
|
:group="{ name: 'itemsDone', pull: true, put: true }"
|
||||||
@change="onDragChange"
|
@change="onDragChange"
|
||||||
@start="onDragStart"
|
@start="onDragStart"
|
||||||
@ -96,9 +96,9 @@
|
|||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<Report
|
<Report
|
||||||
:title="element.title"
|
:title="element.report_title"
|
||||||
:description="element.description"
|
:description="element.report_description"
|
||||||
:date="element.date"
|
:date="element.created_dt"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -120,13 +120,14 @@ function onDragEnd(evt) {
|
|||||||
itemDragable.value = 0;
|
itemDragable.value = 0;
|
||||||
}
|
}
|
||||||
function isDragable(element) {
|
function isDragable(element) {
|
||||||
return itemDragable.value === element.id;
|
return itemDragable.value === element.report_id;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Report from "../components/Report.vue";
|
import Report from "../components/Report.vue";
|
||||||
import draggable from "vuedraggable";
|
import draggable from "vuedraggable";
|
||||||
|
import { backend } from "../backend";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@ -135,67 +136,21 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
itemsUncategorized: [
|
itemsUncategorized: [],
|
||||||
{
|
itemsWaiting: [],
|
||||||
id: 1,
|
itemsInProgress: [],
|
||||||
title: "Pridať bug",
|
itemsDone: [],
|
||||||
description:
|
|
||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam massa eros, porta id, vestibulum sit amet, malesuada in, sapien. Donec nec justo eget felis facilisis fermentum.",
|
|
||||||
date: "2025-04-13 01:30:18",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
title: "Resetovat pismo",
|
|
||||||
description:
|
|
||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam massa eros, porta id, vestibulum sit amet, malesuada in, sapien. Donec nec justo eget felis facilisis fermentum.",
|
|
||||||
date: "2025-04-13 01:30:18",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
itemsWaiting: [
|
|
||||||
{
|
|
||||||
id: 11,
|
|
||||||
title: "Vymena obrazkov za ikonky",
|
|
||||||
description:
|
|
||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam massa eros, porta id, vestibulum sit amet, malesuada in, sapien. Donec nec justo eget felis facilisis fermentum.",
|
|
||||||
date: "2025-04-13 01:30:18",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 12,
|
|
||||||
title:
|
|
||||||
"Doplnit serverove ikoky a toto bude dlhy nadpis, ze ako sa s tym vysporiada",
|
|
||||||
description:
|
|
||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam massa eros, porta id, vestibulum sit amet, malesuada in, sapien. Donec nec justo eget felis facilisis fermentum.",
|
|
||||||
date: "2025-04-13 01:30:18",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 13,
|
|
||||||
title: "Rozdelit na 2 polozky na fakture",
|
|
||||||
description:
|
|
||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam massa eros, porta id, vestibulum sit amet, malesuada in, sapien. Donec nec justo eget felis facilisis fermentum.",
|
|
||||||
date: "2025-04-13 01:30:18",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
itemsInProgress: [
|
|
||||||
{
|
|
||||||
id: 21,
|
|
||||||
title: "Imeplemtovat logovanie",
|
|
||||||
description:
|
|
||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam massa eros, porta id, vestibulum sit amet, malesuada in, sapien. Donec nec justo eget felis facilisis fermentum.",
|
|
||||||
date: "2025-04-13 15:11:23",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
itemsDone: [
|
|
||||||
{
|
|
||||||
id: 31,
|
|
||||||
title: "Doplnit preklady",
|
|
||||||
description:
|
|
||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam massa eros, porta id, vestibulum sit amet, malesuada in, sapien. Donec nec justo eget felis facilisis fermentum.",
|
|
||||||
date: "2025-04-13 01:30:18",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
loadData() {
|
||||||
|
backend.getAllGrouped(Array(0,1,2,3)).then((all_grouped) => {
|
||||||
|
this.itemsUncategorized = all_grouped[0];
|
||||||
|
this.itemsWaiting = all_grouped[1];
|
||||||
|
this.itemsInProgress = all_grouped[2];
|
||||||
|
this.itemsDone = all_grouped[3];
|
||||||
|
})
|
||||||
|
},
|
||||||
onDragChange(event) {
|
onDragChange(event) {
|
||||||
// console.log("Presunuté:", event);
|
// console.log("Presunuté:", event);
|
||||||
// Napr. uložiť poradie do API
|
// Napr. uložiť poradie do API
|
||||||
@ -225,5 +180,8 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
mounted() {
|
||||||
|
this.loadData();
|
||||||
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user