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':
|
||||
$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',
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
@ -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
|
||||
]);
|
||||
}
|
||||
|
||||
?>
|
@ -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 {
|
||||
|
||||
|
@ -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});
|
||||
},
|
||||
|
||||
};
|
||||
|
@ -24,13 +24,65 @@
|
||||
<strong>{{ report.report_group }}</strong>
|
||||
</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>
|
||||
<h1 contenteditable="true" @blur="onTitleChange" ref="reportTitle">
|
||||
{{ report.report_title }}
|
||||
</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>
|
||||
</template>
|
||||
|
||||
@ -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: {},
|
||||
};
|
||||
</script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user