diff --git a/api.php b/api.php index 7931f39..38b31b6 100644 --- a/api.php +++ b/api.php @@ -28,22 +28,35 @@ switch ($action) { case 'get': $result = reportGet($_REQUEST['report_id']); break; - case 'getall': + case 'getAll': $result = reportGetAll($_REQUEST['status']); break; - case 'getallgrouped': + case 'getAllGrouped': $result = reportGetAllGrouped($_REQUEST['status']); break; - case 'updateordnum': + case 'updateOrdNum': $suc = reportUpdateOrdnum($_REQUEST['ordnums']); if ($suc === false) $error = 'Update Ordnum failed'; $result = array('processed' => $suc); break; - case 'updatestatus': + case 'updateStatus': $suc = reportUpdateStatus($_REQUEST['report_id'], $_REQUEST['status']); if ($suc === false) $error = 'Update Status failed'; $result = array('processed' => $suc); break; + case 'attachmentAdd': + $suc = attachmentAdd($_REQUEST['report_id'], $_REQUEST['attachment_type'], $_REQUEST['attachment_content']); + if ($suc === false) $error = 'Attachment add failed'; + $result = array('processed' => $suc); + break; + case 'attachmentUpdate': + $suc = attachmentUpdate($_REQUEST['attachment_id'], $_REQUEST['attachment_content']); + if ($suc === false) $error = 'Attachment update failed'; + $result = array('processed' => $suc); + break; + case 'attachmentGetAll': + $result = attachmentGetAll($_REQUEST['report_id']); + break; } header('Content-Type: application/json'); @@ -107,28 +120,28 @@ function help() 'report_id' => 'Report id', ] ], - 'getall' => [ - 'name' => 'getall', + 'getAll' => [ + 'name' => 'getAll', 'description' => 'Get all reports', 'params' => [ 'status' => '(ptional) Report status, default: 0,1,2,3', ] ], - 'getallgrouped' => [ - 'name' => 'getallgrouped', + 'getAllGrouped' => [ + 'name' => 'getAllGrouped', 'description' => 'Get all reports grouped by group', 'params' => [ 'status' => '(ptional) Report status, default: 0,1,2,3', ] ], - 'updateordnum' => [ + 'updateOrdNum' => [ 'name' => 'updateordnum', 'description' => 'Update report ordnum', 'params' => [ 'ordnums' => 'Report ordnums in json format {report_id: ordnum, ...}', ] ], - 'updatestatus' => [ + 'updateStatus' => [ 'name' => 'updatestatus', 'description' => 'Update report status', 'params' => [ @@ -136,6 +149,30 @@ function help() 'status' => 'Report status', ] ], + 'attachmentAdd' => [ + 'name' => 'attachmentAdd', + 'description' => 'Add attachment to report', + 'params' => [ + 'report_id' => 'Report id', + 'content_type' => 'Attachment content type', + 'content' => 'Attachment content', + ] + ], + 'attachmentUpdate' => [ + 'name' => 'attachmentUpdate', + 'description' => 'Update attachment', + 'params' => [ + 'attachment_id' => 'Attachment id', + 'content' => 'Attachment content; if empty, attachment will be deleted', + ] + ], + 'attachmentGetAll' => [ + 'name' => 'attachmentGetAll', + 'description' => 'Get all attachments for report', + 'params' => [ + 'report_id' => 'Report id', + ] + ] ] ]; } diff --git a/lib/functions.inc.php b/lib/functions.inc.php index 10e8c25..214cba2 100644 --- a/lib/functions.inc.php +++ b/lib/functions.inc.php @@ -217,4 +217,45 @@ function reportGetAllGrouped($status = null) { return $groups; } +/** + * Attachments + */ +function attachmentAdd($report_id, $attachment_type, $attachment_content) { + global $db; + $stm = $db->insert('attachments', [ + 'report_id' => $report_id, + 'attachment_type' => $attachment_type, + 'attachment_content' => $attachment_content, + 'created_dt' => date('Y-m-d H:i:s') + ]); + return ($stm->rowCount() > 0); +} + +function attachmentUpdate($attachment_id, $attachment_content) { + global $db; + if (strlen(trim($attachment_content)) <= 0) return attachmentDelete($attachment_id); + $stm = $db->update('attachments', [ + 'attachment_content' => $attachment_content + ], [ + 'attachment_id' => $attachment_id + ]); + return ($stm->rowCount() > 0); +} + +function attachmentDelete($attachment_id) { + global $db; + $stm = $db->delete('attachments', [ + 'attachment_id' => $attachment_id + ]); + return ($stm->rowCount() > 0); +} + +function attachmentGetAll($report_id) { + global $db; + return $db->select('attachments', '*', [ + 'ORDER' => ['created_dt' => 'ASC'], + 'report_id' => $report_id + ]); +} + ?> \ No newline at end of file diff --git a/webapp/src/assets/css/style.css b/webapp/src/assets/css/style.css index 57d3b43..9b8468f 100644 --- a/webapp/src/assets/css/style.css +++ b/webapp/src/assets/css/style.css @@ -405,6 +405,34 @@ button:focus-visible, text-align: justify; white-space: pre-line } +#report .attachments { + display: flex; + flex-direction: column; +} +#report .attachments .attachment { + display: flex; + flex-direction: column; + background-color: var(--color-bg2); + text-align: justify; + white-space: pre-line; + margin-top: 10px; +} +#report .attachments .attachment .attachment-header { + display: flex; + flex-direction: row; + justify-content: space-between; + background-color: var(--color-bg0); +} +#report .attachments .attachment .attachment-header .created, +#report .attachments .attachment .attachment-header .author { + padding: 2px 10px; +} +#report .attachments .attachment .attachment-content { + padding: 10px; +} +#report .attachment-new { + margin-top: 30px; +} @media (max-width: 600px) { #report .report-header { diff --git a/webapp/src/backend.js b/webapp/src/backend.js index 846cf02..cbe10f3 100644 --- a/webapp/src/backend.js +++ b/webapp/src/backend.js @@ -70,19 +70,31 @@ export const backend = { }, getAll() { - return this.callPromise('getall', {}); + return this.callPromise('getAll', {}); }, getAllGrouped(status) { - return this.callPromise('getallgrouped', {}); + return this.callPromise('getAllGrouped', {}); }, updateOrdnum(ordnums) { - return this.callPromise('updateordnum', {ordnums: ordnums}); + return this.callPromise('updateOrdNum', {ordnums: ordnums}); }, updateStatus(id, status) { - return this.callPromise('updatestatus', {report_id: id, status: status}); + return this.callPromise('updateStatus', {report_id: id, status: status}); + }, + + attachmentAdd(report_id, attachment_type, attachment_content) { + return this.callPromise('attachmentAdd', {report_id: report_id, attachment_type: attachment_type, attachment_content: attachment_content}); + }, + + attachmentUpdate(attachment_id, attachment_content) { + return this.callPromise('attachmentUpdate', {attachment_id: attachment_id, attachment_content: attachment_content}); + }, + + attachmentGetAll(report_id) { + return this.callPromise('attachmentGetAll', {report_id: report_id}); }, }; diff --git a/webapp/src/views/Report.vue b/webapp/src/views/Report.vue index 9027c39..a80db69 100644 --- a/webapp/src/views/Report.vue +++ b/webapp/src/views/Report.vue @@ -24,13 +24,65 @@ {{ report.report_group }}
{{ report.report_description }}
++ {{ report.report_description }} +
+ + @@ -55,24 +107,38 @@ export default { created_dt: "--", ordnum: 0, }, + attachments: [ + { + attachment_id: 0, + attachment_type: "comment", + attachment_content: "Nacitavam report", + created_dt: "--", + }, + ], }; }, mounted() { - console.log(this.report_id); + // console.log(this.report_id); this.loadReportData(); }, methods: { loadReportData() { backend.get(this.report_id).then((report) => { this.report = report; - console.log(this.report); + // console.log(this.report); + }); + backend.attachmentGetAll(this.report_id).then((attachments) => { + this.attachments = attachments; + // console.log(this.attachments); }); }, onTitleChange(event) { backend.update(this.report_id, { report_title: event.target.innerText }); }, onDescriptionChange(event) { - backend.update(this.report_id, { report_description: event.target.innerText }); + backend.update(this.report_id, { + report_description: event.target.innerText, + }); }, reportDelete() { if (!confirm("Naozaj chcete report zmazať?")) return; @@ -81,8 +147,29 @@ export default { this.$router.push("/"); }); }, + attachmentAdd() { + this.loading = true; + backend + .attachmentAdd( + this.report_id, + "comment", + this.$refs.attachmentNewContent.value + ) + .then(() => { + this.$refs.attachmentNewContent.value = ""; + this.loadReportData(); + this.loading = false; + }); + }, + updateAttachmentContent(event, attachment) { + this.loading = true; + backend + .attachmentUpdate(attachment.attachment_id, event.target.innerText) + .then(() => { + this.loadReportData(); + this.loading = false; + }); + }, }, - components: {}, - watch: {}, };