implementovane pridavanie priloh typu "comment",
dynamicka uprava komentarov dvojklikom
This commit is contained in:
parent
e870a62b89
commit
82e14b8fa4
57
api.php
57
api.php
@ -28,22 +28,35 @@ switch ($action) {
|
|||||||
case 'get':
|
case 'get':
|
||||||
$result = reportGet($_REQUEST['report_id']);
|
$result = reportGet($_REQUEST['report_id']);
|
||||||
break;
|
break;
|
||||||
case 'getall':
|
case 'getAll':
|
||||||
$result = reportGetAll($_REQUEST['status']);
|
$result = reportGetAll($_REQUEST['status']);
|
||||||
break;
|
break;
|
||||||
case 'getallgrouped':
|
case 'getAllGrouped':
|
||||||
$result = reportGetAllGrouped($_REQUEST['status']);
|
$result = reportGetAllGrouped($_REQUEST['status']);
|
||||||
break;
|
break;
|
||||||
case 'updateordnum':
|
case 'updateOrdNum':
|
||||||
$suc = reportUpdateOrdnum($_REQUEST['ordnums']);
|
$suc = reportUpdateOrdnum($_REQUEST['ordnums']);
|
||||||
if ($suc === false) $error = 'Update Ordnum failed';
|
if ($suc === false) $error = 'Update Ordnum failed';
|
||||||
$result = array('processed' => $suc);
|
$result = array('processed' => $suc);
|
||||||
break;
|
break;
|
||||||
case 'updatestatus':
|
case 'updateStatus':
|
||||||
$suc = reportUpdateStatus($_REQUEST['report_id'], $_REQUEST['status']);
|
$suc = reportUpdateStatus($_REQUEST['report_id'], $_REQUEST['status']);
|
||||||
if ($suc === false) $error = 'Update Status failed';
|
if ($suc === false) $error = 'Update Status failed';
|
||||||
$result = array('processed' => $suc);
|
$result = array('processed' => $suc);
|
||||||
break;
|
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');
|
header('Content-Type: application/json');
|
||||||
@ -107,28 +120,28 @@ function help()
|
|||||||
'report_id' => 'Report id',
|
'report_id' => 'Report id',
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'getall' => [
|
'getAll' => [
|
||||||
'name' => 'getall',
|
'name' => 'getAll',
|
||||||
'description' => 'Get all reports',
|
'description' => 'Get all reports',
|
||||||
'params' => [
|
'params' => [
|
||||||
'status' => '(ptional) Report status, default: 0,1,2,3',
|
'status' => '(ptional) Report status, default: 0,1,2,3',
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'getallgrouped' => [
|
'getAllGrouped' => [
|
||||||
'name' => 'getallgrouped',
|
'name' => 'getAllGrouped',
|
||||||
'description' => 'Get all reports grouped by group',
|
'description' => 'Get all reports grouped by group',
|
||||||
'params' => [
|
'params' => [
|
||||||
'status' => '(ptional) Report status, default: 0,1,2,3',
|
'status' => '(ptional) Report status, default: 0,1,2,3',
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'updateordnum' => [
|
'updateOrdNum' => [
|
||||||
'name' => 'updateordnum',
|
'name' => 'updateordnum',
|
||||||
'description' => 'Update report ordnum',
|
'description' => 'Update report ordnum',
|
||||||
'params' => [
|
'params' => [
|
||||||
'ordnums' => 'Report ordnums in json format {report_id: ordnum, ...}',
|
'ordnums' => 'Report ordnums in json format {report_id: ordnum, ...}',
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'updatestatus' => [
|
'updateStatus' => [
|
||||||
'name' => 'updatestatus',
|
'name' => 'updatestatus',
|
||||||
'description' => 'Update report status',
|
'description' => 'Update report status',
|
||||||
'params' => [
|
'params' => [
|
||||||
@ -136,6 +149,30 @@ function help()
|
|||||||
'status' => 'Report status',
|
'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',
|
||||||
|
]
|
||||||
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -217,4 +217,45 @@ function reportGetAllGrouped($status = null) {
|
|||||||
return $groups;
|
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
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
@ -405,6 +405,34 @@ button:focus-visible,
|
|||||||
text-align: justify;
|
text-align: justify;
|
||||||
white-space: pre-line
|
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) {
|
@media (max-width: 600px) {
|
||||||
#report .report-header {
|
#report .report-header {
|
||||||
|
|
||||||
|
@ -70,19 +70,31 @@ export const backend = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getAll() {
|
getAll() {
|
||||||
return this.callPromise('getall', {});
|
return this.callPromise('getAll', {});
|
||||||
},
|
},
|
||||||
|
|
||||||
getAllGrouped(status) {
|
getAllGrouped(status) {
|
||||||
return this.callPromise('getallgrouped', {});
|
return this.callPromise('getAllGrouped', {});
|
||||||
},
|
},
|
||||||
|
|
||||||
updateOrdnum(ordnums) {
|
updateOrdnum(ordnums) {
|
||||||
return this.callPromise('updateordnum', {ordnums: ordnums});
|
return this.callPromise('updateOrdNum', {ordnums: ordnums});
|
||||||
},
|
},
|
||||||
|
|
||||||
updateStatus(id, status) {
|
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});
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -24,13 +24,65 @@
|
|||||||
<strong>{{ report.report_group }}</strong>
|
<strong>{{ report.report_group }}</strong>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<button @click="reportDelete"><font-awesome-icon :icon="['fas', 'trash-can']" /> Zmazať</button>
|
<button @click="reportDelete">
|
||||||
|
<font-awesome-icon :icon="['fas', 'trash-can']" /> Zmazať
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<h1 contenteditable="true" @blur="onTitleChange" ref="reportTitle">
|
<h1 contenteditable="true" @blur="onTitleChange" ref="reportTitle">
|
||||||
{{ report.report_title }}
|
{{ report.report_title }}
|
||||||
</h1>
|
</h1>
|
||||||
<p class="description" contenteditable="true" @blur="onDescriptionChange" ref="reportDescription">{{ report.report_description }}</p>
|
<p
|
||||||
|
class="description"
|
||||||
|
contenteditable="true"
|
||||||
|
@blur="onDescriptionChange"
|
||||||
|
ref="reportDescription"
|
||||||
|
>
|
||||||
|
{{ report.report_description }}
|
||||||
|
</p>
|
||||||
|
<div class="attachments">
|
||||||
|
<div
|
||||||
|
class="attachment"
|
||||||
|
v-for="attachment in attachments"
|
||||||
|
:key="attachment.attachment_id"
|
||||||
|
>
|
||||||
|
<div class="attachment-header">
|
||||||
|
<span class="created"
|
||||||
|
><font-awesome-icon :icon="['fas', 'calendar-days']" />
|
||||||
|
{{ attachment.created_dt }}</span
|
||||||
|
>
|
||||||
|
<span class="author"
|
||||||
|
><font-awesome-icon :icon="['fas', 'user']" />
|
||||||
|
{{ attachment.attachment_author }}</span
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="attachment-content"
|
||||||
|
:contenteditable="attachment.editable ?? false"
|
||||||
|
@dblclick="attachment.editable = true"
|
||||||
|
@blur="attachment.editable = false; updateAttachmentContent($event, attachment);"
|
||||||
|
>
|
||||||
|
{{ attachment.attachment_content }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="attachment-new">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="description">Nový komentár:</label>
|
||||||
|
<textarea
|
||||||
|
ref="attachmentNewContent"
|
||||||
|
rows="5"
|
||||||
|
class="form-control"
|
||||||
|
placeholder="Nove zistenia alebo riesenia"
|
||||||
|
required
|
||||||
|
></textarea>
|
||||||
|
</div>
|
||||||
|
<div class="form-actions">
|
||||||
|
<button @click="attachmentAdd">
|
||||||
|
<font-awesome-icon :icon="['fas', 'circle-plus']" /> Pridať
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -55,24 +107,38 @@ export default {
|
|||||||
created_dt: "--",
|
created_dt: "--",
|
||||||
ordnum: 0,
|
ordnum: 0,
|
||||||
},
|
},
|
||||||
|
attachments: [
|
||||||
|
{
|
||||||
|
attachment_id: 0,
|
||||||
|
attachment_type: "comment",
|
||||||
|
attachment_content: "Nacitavam report",
|
||||||
|
created_dt: "--",
|
||||||
|
},
|
||||||
|
],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
console.log(this.report_id);
|
// console.log(this.report_id);
|
||||||
this.loadReportData();
|
this.loadReportData();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
loadReportData() {
|
loadReportData() {
|
||||||
backend.get(this.report_id).then((report) => {
|
backend.get(this.report_id).then((report) => {
|
||||||
this.report = 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) {
|
onTitleChange(event) {
|
||||||
backend.update(this.report_id, { report_title: event.target.innerText });
|
backend.update(this.report_id, { report_title: event.target.innerText });
|
||||||
},
|
},
|
||||||
onDescriptionChange(event) {
|
onDescriptionChange(event) {
|
||||||
backend.update(this.report_id, { report_description: event.target.innerText });
|
backend.update(this.report_id, {
|
||||||
|
report_description: event.target.innerText,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
reportDelete() {
|
reportDelete() {
|
||||||
if (!confirm("Naozaj chcete report zmazať?")) return;
|
if (!confirm("Naozaj chcete report zmazať?")) return;
|
||||||
@ -81,8 +147,29 @@ export default {
|
|||||||
this.$router.push("/");
|
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: {},
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user