pridana API metoda getallgrouped,

implementovane nacitanie dat do Dashboard z backend
This commit is contained in:
Igor Miňo 2025-05-04 15:08:57 +02:00
parent 93126ecd47
commit c82df663df
5 changed files with 257 additions and 82 deletions

29
api.php
View File

@ -2,6 +2,8 @@
include_once 'config.php';
$action = $_REQUEST['action'];
$result = null;
$error = null;
switch ($action) {
default:
@ -9,7 +11,9 @@ switch ($action) {
$result = help();
break;
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;
case 'update':
$result = reportUpdate($_REQUEST['report_id'], $_REQUEST['title'], $_REQUEST['description'], $_REQUEST['status'], $_REQUEST['group'], $_REQUEST['priority']);
@ -23,13 +27,26 @@ switch ($action) {
case 'getall':
$result = reportGetAll($_REQUEST['status']);
break;
case 'getallgrouped':
$result = reportGetAllGrouped($_REQUEST['status']);
break;
}
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;
function help() {
function help()
{
return [
'actions' => [
'help' => 'Show this help',
@ -37,10 +54,8 @@ function help() {
'update' => 'Update report',
'delete' => 'Delete report',
'get' => 'Get report',
'getall' => 'Get all reports'
'getall' => 'Get all reports',
'getallgrouped' => 'Get all reports grouped by group',
]
];
}
?>

View File

@ -1,5 +1,9 @@
<?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/Medoo/src/Medoo.php';

194
lib/functions.inc.php Normal file
View 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;
}
?>

View File

@ -73,4 +73,8 @@ export const backend = {
return this.callPromise('getall', {});
},
getAllGrouped(status) {
return this.callPromise('getallgrouped', {});
},
};

View File

@ -4,7 +4,7 @@
<h2>Nezaradené</h2>
<draggable
v-model="itemsUncategorized"
item-key="id"
item-key="report_id"
:group="{ name: 'itemsUncategorized', pull: true, put: true }"
@change="onDragChange"
@start="onDragStart"
@ -18,9 +18,9 @@
}"
>
<Report
:title="element.title"
:description="element.description"
:date="element.date"
:title="element.report_title"
:description="element.report_description"
:date="element.created_dt"
/>
</div>
</template>
@ -30,7 +30,7 @@
<h2>Čakajúce</h2>
<draggable
v-model="itemsWaiting"
item-key="id"
item-key="report_id"
:group="{ name: 'itemsWaiting', pull: true, put: true }"
@change="onDragChange"
@start="onDragStart"
@ -44,9 +44,9 @@
}"
>
<Report
:title="element.title"
:description="element.description"
:date="element.date"
:title="element.report_title"
:description="element.report_description"
:date="element.created_dt"
/>
</div>
</template>
@ -56,7 +56,7 @@
<h2>Rozpracované</h2>
<draggable
v-model="itemsInProgress"
item-key="id"
item-key="report_id"
:group="{ name: 'itemsInProgress', pull: true, put: true }"
@change="onDragChange"
@start="onDragStart"
@ -70,9 +70,9 @@
}"
>
<Report
:title="element.title"
:description="element.description"
:date="element.date"
:title="element.report_title"
:description="element.report_description"
:date="element.created_dt"
/>
</div>
</template>
@ -82,7 +82,7 @@
<h2>Hotové</h2>
<draggable
v-model="itemsDone"
item-key="id"
item-key="report_id"
:group="{ name: 'itemsDone', pull: true, put: true }"
@change="onDragChange"
@start="onDragStart"
@ -96,9 +96,9 @@
}"
>
<Report
:title="element.title"
:description="element.description"
:date="element.date"
:title="element.report_title"
:description="element.report_description"
:date="element.created_dt"
/>
</div>
</template>
@ -120,13 +120,14 @@ function onDragEnd(evt) {
itemDragable.value = 0;
}
function isDragable(element) {
return itemDragable.value === element.id;
return itemDragable.value === element.report_id;
}
</script>
<script>
import Report from "../components/Report.vue";
import draggable from "vuedraggable";
import { backend } from "../backend";
export default {
components: {
@ -135,67 +136,21 @@ export default {
},
data() {
return {
itemsUncategorized: [
{
id: 1,
title: "Pridať bug",
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",
},
],
itemsUncategorized: [],
itemsWaiting: [],
itemsInProgress: [],
itemsDone: [],
};
},
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) {
// console.log("Presunuté:", event);
// Napr. uložiť poradie do API
@ -225,5 +180,8 @@ export default {
});
},
},
mounted() {
this.loadData();
},
};
</script>