2022-04-29 18:29:42 +08:00
|
|
|
<template>
|
|
|
|
<div class="step-table-container">
|
2022-05-06 17:59:22 +08:00
|
|
|
<div class="step-element-header" :class="{ 'editing-name': editingName }">
|
2022-06-03 17:52:10 +08:00
|
|
|
<div v-if="reorderElementUrl" class="step-element-grip" @click="$emit('reorder')">
|
2022-05-06 17:59:22 +08:00
|
|
|
<i class="fas fa-grip-vertical"></i>
|
|
|
|
</div>
|
|
|
|
<div class="step-element-name">
|
|
|
|
<InlineEdit
|
2022-06-03 17:52:10 +08:00
|
|
|
v-if="element.attributes.orderable.urls.update_url"
|
2022-05-06 17:59:22 +08:00
|
|
|
:value="element.attributes.orderable.name"
|
|
|
|
:characterLimit="255"
|
|
|
|
:placeholder="''"
|
|
|
|
:allowBlank="false"
|
|
|
|
:autofocus="editingName"
|
|
|
|
:attributeName="`${i18n.t('Table')} ${i18n.t('name')}`"
|
|
|
|
@editingEnabled="enableNameEdit"
|
|
|
|
@editingDisabled="disableNameEdit"
|
|
|
|
@update="updateName"
|
|
|
|
/>
|
2022-06-03 17:52:10 +08:00
|
|
|
<span v-else>
|
|
|
|
{{ element.attributes.orderable.name }}
|
|
|
|
</span>
|
2022-05-06 17:59:22 +08:00
|
|
|
</div>
|
|
|
|
<div class="step-element-controls">
|
2022-07-06 20:31:55 +08:00
|
|
|
<button v-if="element.attributes.orderable.urls.update_url" class="btn icon-btn btn-light" @click="enableNameEdit" tabindex="-1">
|
2022-05-06 17:59:22 +08:00
|
|
|
<i class="fas fa-pen"></i>
|
|
|
|
</button>
|
2022-07-06 20:31:55 +08:00
|
|
|
<button v-if="element.attributes.orderable.urls.delete_url" class="btn icon-btn btn-light" @click="showDeleteModal" tabindex="-1">
|
2022-05-06 17:59:22 +08:00
|
|
|
<i class="fas fa-trash"></i>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-07-06 20:31:55 +08:00
|
|
|
<div :class="'step-table ' + (editingTable ? 'edit' : 'view')" tabindex="0" @keyup.enter="enableTableEdit">
|
2022-06-03 17:52:10 +08:00
|
|
|
<div class="enable-edit-mode" v-if="!editingTable && element.attributes.orderable.urls.update_url" @click="enableTableEdit">
|
2022-05-06 17:59:22 +08:00
|
|
|
<i class="fas fa-pen"></i>
|
|
|
|
</div>
|
|
|
|
<div ref="hotTable" class="hot-table-container">
|
|
|
|
</div>
|
|
|
|
<div v-if="editingTable" class="edit-message">
|
|
|
|
{{ i18n.t('protocols.steps.table.edit_message') }}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="edit-buttons" v-if="editingTable">
|
|
|
|
<button class="btn icon-btn btn-primary" @click="updateTable">
|
|
|
|
<i class="fas fa-check"></i>
|
|
|
|
</button>
|
|
|
|
<button class="btn icon-btn btn-light" @click="disableTableEdit">
|
|
|
|
<i class="fas fa-times"></i>
|
|
|
|
</button>
|
|
|
|
</div>
|
2022-05-30 19:45:51 +08:00
|
|
|
<deleteElementModal v-if="confirmingDelete" @confirm="deleteElement" @cancel="closeDeleteModal"/>
|
2022-04-29 18:29:42 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-05-03 21:15:49 +08:00
|
|
|
import DeleteMixin from 'vue/protocol/mixins/components/delete.js'
|
2022-05-30 19:45:51 +08:00
|
|
|
import deleteElementModal from 'vue/protocol/modals/delete_element.vue'
|
2022-05-06 17:59:22 +08:00
|
|
|
import InlineEdit from 'vue/shared/inline_edit.vue'
|
2022-05-04 16:25:53 +08:00
|
|
|
|
2022-04-29 18:29:42 +08:00
|
|
|
export default {
|
2022-05-03 21:15:49 +08:00
|
|
|
name: 'StepTable',
|
2022-05-30 19:45:51 +08:00
|
|
|
components: { deleteElementModal, InlineEdit },
|
2022-05-03 21:15:49 +08:00
|
|
|
mixins: [DeleteMixin],
|
|
|
|
props: {
|
|
|
|
element: {
|
|
|
|
type: Object,
|
|
|
|
required: true
|
2022-06-03 17:52:10 +08:00
|
|
|
},
|
2022-06-07 18:10:10 +08:00
|
|
|
inRepository: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true
|
|
|
|
},
|
2022-06-03 17:52:10 +08:00
|
|
|
reorderElementUrl: {
|
|
|
|
type: String
|
2022-07-06 20:18:11 +08:00
|
|
|
},
|
|
|
|
isNew: {
|
|
|
|
type: Boolean, default: false
|
2022-05-03 21:15:49 +08:00
|
|
|
}
|
2022-05-06 17:59:22 +08:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
editingName: false,
|
|
|
|
editingTable: false,
|
|
|
|
tableObject: null
|
|
|
|
}
|
|
|
|
},
|
|
|
|
updated() {
|
|
|
|
this.loadTableData();
|
|
|
|
},
|
|
|
|
beforeUpdate() {
|
|
|
|
this.tableObject.destroy();
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.loadTableData();
|
2022-07-06 20:18:11 +08:00
|
|
|
|
|
|
|
if (this.isNew) this.enableTableEdit();
|
2022-05-06 17:59:22 +08:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
enableTableEdit() {
|
|
|
|
this.editingTable = true;
|
2022-07-06 20:18:11 +08:00
|
|
|
this.$nextTick(() => this.tableObject.selectCell(0,0));
|
2022-05-06 17:59:22 +08:00
|
|
|
},
|
|
|
|
disableTableEdit() {
|
|
|
|
this.editingTable = false;
|
|
|
|
},
|
|
|
|
enableNameEdit() {
|
|
|
|
this.editingName = true;
|
|
|
|
},
|
|
|
|
disableNameEdit() {
|
|
|
|
this.editingName = false;
|
|
|
|
},
|
|
|
|
updateName(name) {
|
|
|
|
this.element.attributes.orderable.name = name;
|
|
|
|
this.update();
|
|
|
|
},
|
|
|
|
updateTable() {
|
|
|
|
let tableData = JSON.stringify({data: this.tableObject.getData()});
|
|
|
|
this.element.attributes.orderable.contents = tableData;
|
|
|
|
this.update();
|
|
|
|
this.editingTable = false;
|
|
|
|
},
|
|
|
|
update() {
|
|
|
|
this.$emit('update', this.element)
|
|
|
|
},
|
|
|
|
loadTableData() {
|
|
|
|
let container = this.$refs.hotTable;
|
|
|
|
let data = JSON.parse(this.element.attributes.orderable.contents);
|
|
|
|
this.tableObject = new Handsontable(container, {
|
|
|
|
data: data.data,
|
|
|
|
width: '100%',
|
|
|
|
startRows: 5,
|
|
|
|
startCols: 5,
|
|
|
|
rowHeaders: true,
|
|
|
|
colHeaders: true,
|
|
|
|
contextMenu: this.editingTable,
|
|
|
|
formulas: true,
|
2022-07-06 20:18:11 +08:00
|
|
|
readOnly: !this.editingTable,
|
|
|
|
afterUnlisten: this.updateTable
|
2022-05-06 17:59:22 +08:00
|
|
|
});
|
|
|
|
}
|
2022-05-03 21:15:49 +08:00
|
|
|
}
|
2022-04-29 18:29:42 +08:00
|
|
|
}
|
2022-05-03 19:42:43 +08:00
|
|
|
</script>
|