2023-08-03 22:03:40 +08:00
|
|
|
<template>
|
2023-08-31 21:50:35 +08:00
|
|
|
<div class="result-wrapper bg-white px-4 py-2 mb-4">
|
|
|
|
<div class="result-header flex justify-between py-2">
|
2023-08-17 22:32:42 +08:00
|
|
|
<div class="result-head-left">
|
|
|
|
<InlineEdit
|
|
|
|
:value="result.attributes.name"
|
|
|
|
:class="{ 'result-element--locked': !urls.update_url }"
|
|
|
|
:characterLimit="255"
|
|
|
|
:allowBlank="false"
|
|
|
|
:attributeName="`${i18n.t('Result')} ${i18n.t('name')}`"
|
|
|
|
:autofocus="editingName"
|
|
|
|
:placeholder="i18n.t('my_modules.results.placeholder')"
|
|
|
|
:defaultValue="i18n.t('my_modules.results.default_name')"
|
|
|
|
@editingEnabled="editingName = true"
|
|
|
|
@editingDisabled="editingName = false"
|
|
|
|
:editOnload="result.newResult == true"
|
|
|
|
@update="updateName"
|
|
|
|
/>
|
2023-08-10 22:48:08 +08:00
|
|
|
</div>
|
2023-08-31 21:50:35 +08:00
|
|
|
<div class="result-head-right flex elements-actions-container">
|
2023-08-17 22:32:42 +08:00
|
|
|
<input type="file" class="hidden" ref="fileSelector" @change="loadFromComputer" multiple />
|
|
|
|
<div ref="elementsDropdownButton" v-if="urls.update_url" class="dropdown">
|
|
|
|
<button class="btn btn-light dropdown-toggle insert-button" type="button" :id="'resultInsertMenu_' + result.id" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
2023-08-31 21:50:35 +08:00
|
|
|
{{ i18n.t('my_modules.results.insert.button') }}
|
2023-08-17 22:32:42 +08:00
|
|
|
<span class="sn-icon sn-icon-down"></span>
|
|
|
|
</button>
|
|
|
|
<ul ref="elementsDropdown" class="dropdown-menu insert-element-dropdown dropdown-menu-right" :aria-labelledby="'resultInsertMenu_' + result.id">
|
|
|
|
<li class="title">
|
2023-08-31 21:50:35 +08:00
|
|
|
{{ i18n.t('my_modules.results.insert.title') }}
|
2023-08-17 22:32:42 +08:00
|
|
|
</li>
|
|
|
|
<li class="action" @click="createElement('table')">
|
2023-08-31 21:50:35 +08:00
|
|
|
<i class="sn-icon sn-icon-tables"></i>
|
|
|
|
{{ i18n.t('my_modules.results.insert.table') }}
|
2023-08-17 22:32:42 +08:00
|
|
|
</li>
|
|
|
|
<li class="action dropdown-submenu-item">
|
2023-08-31 21:50:35 +08:00
|
|
|
<i class="sn-icon sn-icon-tables"></i>
|
|
|
|
{{ i18n.t('my_modules.results.insert.well_plate') }}
|
2023-08-17 22:32:42 +08:00
|
|
|
<span class="caret"></span>
|
|
|
|
|
|
|
|
<ul class="dropdown-submenu">
|
|
|
|
<li v-for="option in wellPlateOptions" :key="option.dimensions.toString()" class="action" @click="createElement('table', option.dimensions, true)">
|
2023-08-31 21:50:35 +08:00
|
|
|
{{ i18n.t(option.label) }}
|
2023-08-17 22:32:42 +08:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
<li class="action" @click="createElement('text')">
|
2023-08-31 21:50:35 +08:00
|
|
|
<i class="sn-icon sn-icon-result-text"></i>
|
|
|
|
{{ i18n.t('my_modules.results.insert.text') }}
|
2023-08-17 22:32:42 +08:00
|
|
|
</li>
|
|
|
|
<li class="action dropdown-submenu-item">
|
2023-08-31 21:50:35 +08:00
|
|
|
<i class="sn-icon sn-icon-files"></i>
|
|
|
|
{{ i18n.t('my_modules.results.insert.attachment') }}
|
2023-08-17 22:32:42 +08:00
|
|
|
<span class="caret"></span>
|
|
|
|
<ul class="dropdown-submenu">
|
|
|
|
<li class="action" @click="openLoadFromComputer">
|
2023-08-31 21:50:35 +08:00
|
|
|
{{ i18n.t('my_modules.results.insert.add_file') }}
|
2023-08-17 22:32:42 +08:00
|
|
|
</li>
|
|
|
|
<li class="action" v-if="result.attributes.wopi_enabled" @click="openWopiFileModal">
|
2023-08-31 21:50:35 +08:00
|
|
|
{{ i18n.t('assets.create_wopi_file.button_text') }}
|
2023-08-17 22:32:42 +08:00
|
|
|
</li>
|
|
|
|
<li class="action" v-if="result.attributes.marvinjs_enabled" @click="openMarvinJsModal($refs.marvinJsButton)">
|
2023-08-31 21:50:35 +08:00
|
|
|
<span
|
|
|
|
class="new-marvinjs-upload-button text-sn-black text-decoration-none"
|
|
|
|
:data-object-id="result.id"
|
|
|
|
ref="marvinJsButton"
|
|
|
|
:data-marvin-url="result.attributes.marvinjs_context.marvin_js_asset_url"
|
|
|
|
:data-object-type="result.attributes.type"
|
|
|
|
tabindex="0"
|
|
|
|
>
|
|
|
|
{{ i18n.t('marvinjs.new_button') }}
|
|
|
|
</span>
|
2023-08-17 22:32:42 +08:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<a href="#"
|
|
|
|
ref="comments"
|
|
|
|
class="open-comments-sidebar btn icon-btn btn-light"
|
|
|
|
data-turbolinks="false"
|
|
|
|
data-object-type="Result"
|
|
|
|
:data-object-id="result.id">
|
|
|
|
<i class="sn-icon sn-icon-comments"></i>
|
|
|
|
</a>
|
|
|
|
<div ref="actionsDropdownButton" class="dropdown">
|
|
|
|
<button class="btn btn-light icon-btn dropdown-toggle insert-button" type="button" :id="'resultOptionsMenu_' + result.id" data-toggle="dropdown" data-display="static" aria-haspopup="true" aria-expanded="true">
|
|
|
|
<i class="sn-icon sn-icon-more-hori"></i>
|
|
|
|
</button>
|
|
|
|
<ul ref="actionsDropdown" class="dropdown-menu dropdown-menu-right insert-element-dropdown" :aria-labelledby="'resultOptionsMenu_' + result.id">
|
|
|
|
<li class="action" @click="openReorderModal">
|
2023-08-31 21:50:35 +08:00
|
|
|
{{ i18n.t('my_modules.results.actions.rearrange') }}
|
2023-08-17 22:32:42 +08:00
|
|
|
</li>
|
|
|
|
<li class="action" @click="duplicateResult">
|
2023-08-31 21:50:35 +08:00
|
|
|
{{ i18n.t('my_modules.results.actions.duplicate') }}
|
2023-08-17 22:32:42 +08:00
|
|
|
</li>
|
|
|
|
<li class="action" @click="archiveResult">
|
2023-08-31 21:50:35 +08:00
|
|
|
{{ i18n.t('my_modules.results.actions.archive') }}
|
2023-08-17 22:32:42 +08:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2023-08-17 14:29:34 +08:00
|
|
|
</div>
|
2023-08-10 22:48:08 +08:00
|
|
|
</div>
|
2023-09-04 15:40:32 +08:00
|
|
|
|
|
|
|
<div class="relative ml-1 bottom-17 w-356 h-15 font-normal font-hairline text-xs leading-4">
|
|
|
|
{{ i18n.t('protocols.steps.timestamp', {date: result.attributes.created_at, user: result.attributes.created_by }) }}
|
|
|
|
</div>
|
|
|
|
|
2023-08-09 19:58:25 +08:00
|
|
|
<ReorderableItemsModal v-if="reordering"
|
|
|
|
title="Placeholder title for this modal"
|
|
|
|
:items="reorderableElements"
|
|
|
|
@reorder="updateElementOrder"
|
|
|
|
@close="closeReorderModal"
|
|
|
|
/>
|
2023-08-10 22:48:08 +08:00
|
|
|
<div>
|
2023-08-31 21:50:35 +08:00
|
|
|
<div v-for="(element, index) in orderedElements" :key="index" class="pt-6 border-0 border-t border-dotted border-sn-sleepy-grey mt-6">
|
2023-08-10 22:48:08 +08:00
|
|
|
<component
|
|
|
|
:is="elements[index].attributes.orderable_type"
|
|
|
|
:element.sync="elements[index]"
|
|
|
|
:inRepository="false"
|
|
|
|
:reorderElementUrl="elements.length > 1 ? urls.reorder_elements_url : ''"
|
|
|
|
:assignableMyModuleId="result.attributes.my_module_id"
|
|
|
|
:isNew="element.isNew"
|
|
|
|
@component:delete="deleteElement"
|
|
|
|
@update="updateElement"
|
|
|
|
@reorder="openReorderModal"
|
|
|
|
@component:insert="insertElement"
|
2023-08-21 15:22:56 +08:00
|
|
|
@moved="moveElement"
|
2023-08-10 22:48:08 +08:00
|
|
|
/>
|
2023-08-31 21:50:35 +08:00
|
|
|
</div>
|
2023-08-10 22:48:08 +08:00
|
|
|
<Attachments v-if="attachments.length"
|
2023-08-31 21:50:35 +08:00
|
|
|
class="pt-6 border-0 border-t border-dotted border-sn-sleepy-grey mt-6"
|
2023-08-10 22:48:08 +08:00
|
|
|
:parent="result"
|
|
|
|
:attachments="attachments"
|
|
|
|
:attachmentsReady="attachmentsReady"
|
|
|
|
@attachments:openFileModal="showFileModal = true"
|
|
|
|
@attachment:deleted="attachmentDeleted"
|
|
|
|
@attachment:uploaded="loadAttachments"
|
2023-08-11 20:48:20 +08:00
|
|
|
@attachments:order="changeAttachmentsOrder"
|
|
|
|
@attachments:viewMode="changeAttachmentsViewMode"
|
|
|
|
@attachment:viewMode="updateAttachmentViewMode"/>
|
2023-08-10 22:48:08 +08:00
|
|
|
</div>
|
2023-08-03 22:03:40 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-08-21 15:22:56 +08:00
|
|
|
import axios from '../../packs/custom_axios.js';
|
2023-08-10 22:48:08 +08:00
|
|
|
import ReorderableItemsModal from '../shared/reorderable_items_modal.vue';
|
|
|
|
import ResultTable from '../shared/content/table.vue';
|
|
|
|
import ResultText from '../shared/content/text.vue';
|
|
|
|
import Attachments from '../shared/content/attachments.vue';
|
2023-08-17 22:32:42 +08:00
|
|
|
import InlineEdit from '../shared/inline_edit.vue'
|
2023-08-10 22:48:08 +08:00
|
|
|
|
|
|
|
import AttachmentsMixin from '../shared/content/mixins/attachments.js'
|
|
|
|
import WopiFileModal from '../shared/content/attachments/mixins/wopi_file_modal.js'
|
|
|
|
import UtilsMixin from '../mixins/utils.js'
|
2023-08-03 22:03:40 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'Results',
|
|
|
|
props: {
|
2023-08-21 15:22:56 +08:00
|
|
|
result: { type: Object, required: true },
|
|
|
|
resultToReload: { type: Number, required: false }
|
2023-08-09 19:58:25 +08:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
reordering: false,
|
2023-08-10 22:48:08 +08:00
|
|
|
elements: [],
|
|
|
|
attachments: [],
|
|
|
|
attachmentsReady: false,
|
2023-08-11 20:48:20 +08:00
|
|
|
showFileModal: false,
|
|
|
|
wellPlateOptions: [
|
2023-08-31 21:50:35 +08:00
|
|
|
{ label: 'my_modules.results.insert.well_plate_options.32_x_48', dimensions: [32, 48] },
|
|
|
|
{ label: 'my_modules.results.insert.well_plate_options.16_x_24', dimensions: [16, 24] },
|
|
|
|
{ label: 'my_modules.results.insert.well_plate_options.8_x_12', dimensions: [8, 12] },
|
|
|
|
{ label: 'my_modules.results.insert.well_plate_options.6_x_8', dimensions: [6, 8] },
|
|
|
|
{ label: 'my_modules.results.insert.well_plate_options.6_x_4', dimensions: [6, 4] },
|
|
|
|
{ label: 'my_modules.results.insert.well_plate_options.2_x_3', dimensions: [2, 3] }
|
2023-08-17 22:32:42 +08:00
|
|
|
],
|
|
|
|
editingName: false
|
2023-08-09 19:58:25 +08:00
|
|
|
}
|
|
|
|
},
|
2023-08-10 22:48:08 +08:00
|
|
|
mixins: [UtilsMixin, AttachmentsMixin, WopiFileModal],
|
2023-08-09 19:58:25 +08:00
|
|
|
components: {
|
2023-08-10 22:48:08 +08:00
|
|
|
ReorderableItemsModal,
|
|
|
|
ResultTable,
|
|
|
|
ResultText,
|
2023-08-17 22:32:42 +08:00
|
|
|
Attachments,
|
|
|
|
InlineEdit
|
2023-08-09 19:58:25 +08:00
|
|
|
},
|
2023-08-21 15:22:56 +08:00
|
|
|
watch: {
|
|
|
|
resultToReload() {
|
|
|
|
if (this.resultToReload == this.result.id) {
|
|
|
|
this.loadElements();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2023-08-09 19:58:25 +08:00
|
|
|
computed: {
|
|
|
|
reorderableElements() {
|
|
|
|
return this.orderedElements.map((e) => { return { id: e.id, attributes: e.attributes.orderable } })
|
|
|
|
},
|
|
|
|
orderedElements() {
|
|
|
|
return this.elements.sort((a, b) => a.attributes.position - b.attributes.position);
|
|
|
|
},
|
|
|
|
urls() {
|
|
|
|
return this.result.attributes.urls || {}
|
|
|
|
}
|
|
|
|
},
|
2023-08-10 22:48:08 +08:00
|
|
|
created() {
|
|
|
|
this.loadAttachments();
|
|
|
|
this.loadElements();
|
|
|
|
},
|
2023-08-09 19:58:25 +08:00
|
|
|
methods: {
|
|
|
|
openReorderModal() {
|
|
|
|
this.reordering = true;
|
|
|
|
},
|
|
|
|
closeReorderModal() {
|
|
|
|
this.reordering = false;
|
|
|
|
},
|
|
|
|
updateElementOrder(orderedElements) {
|
|
|
|
orderedElements.forEach((element, position) => {
|
|
|
|
let index = this.elements.findIndex((e) => e.id === element.id);
|
|
|
|
this.elements[index].attributes.position = position;
|
|
|
|
});
|
|
|
|
|
|
|
|
let elementPositions = {
|
|
|
|
result_orderable_element_positions: this.elements.map(
|
|
|
|
(element) => [element.id, element.attributes.position]
|
|
|
|
)
|
|
|
|
};
|
|
|
|
|
|
|
|
axios.post(this.urls.reorder_elements_url, elementPositions, {
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
'Accept': 'application/json'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(() => {
|
2023-08-11 20:48:20 +08:00
|
|
|
this.$emit('resultUpdated');
|
2023-08-09 19:58:25 +08:00
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
HelperModule.flashAlertMsg(this.i18n.t('errors.general'), 'danger');
|
|
|
|
});
|
|
|
|
},
|
2023-08-11 20:48:20 +08:00
|
|
|
deleteElement(position) {
|
|
|
|
this.elements.splice(position, 1)
|
|
|
|
let unorderedElements = this.elements.map( e => {
|
|
|
|
if (e.attributes.position >= position) {
|
|
|
|
e.attributes.position -= 1;
|
|
|
|
}
|
|
|
|
return e;
|
|
|
|
})
|
|
|
|
this.$emit('resultUpdated')
|
2023-08-10 22:48:08 +08:00
|
|
|
},
|
2023-08-11 20:48:20 +08:00
|
|
|
updateElement(element, skipRequest=false, callback) {
|
|
|
|
let index = this.elements.findIndex((e) => e.id === element.id);
|
|
|
|
this.elements[index].isNew = false;
|
|
|
|
|
|
|
|
if (skipRequest) {
|
|
|
|
this.elements[index].attributes.orderable = element.attributes.orderable;
|
|
|
|
this.$emit('resultUpdated');
|
|
|
|
} else {
|
|
|
|
$.ajax({
|
|
|
|
url: element.attributes.orderable.urls.update_url,
|
|
|
|
method: 'PUT',
|
|
|
|
data: element.attributes.orderable,
|
|
|
|
success: (result) => {
|
|
|
|
this.elements[index].attributes.orderable = result.data.attributes;
|
|
|
|
this.$emit('resultUpdated');
|
|
|
|
|
|
|
|
// optional callback after successful update
|
|
|
|
if(typeof callback === 'function') {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).fail(() => {
|
|
|
|
HelperModule.flashAlertMsg(this.i18n.t('errors.general'), 'danger');
|
|
|
|
})
|
|
|
|
}
|
2023-08-10 22:48:08 +08:00
|
|
|
},
|
|
|
|
insertElement(element) {
|
2023-08-11 20:48:20 +08:00
|
|
|
let position = element.attributes.position;
|
|
|
|
this.elements = this.elements.map( s => {
|
|
|
|
if (s.attributes.position >= position) {
|
|
|
|
s.attributes.position += 1;
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
})
|
|
|
|
this.elements.push(element);
|
2023-08-10 22:48:08 +08:00
|
|
|
},
|
|
|
|
loadElements() {
|
|
|
|
$.get(this.urls.elements_url, (result) => {
|
|
|
|
this.elements = result.data
|
2023-08-21 15:22:56 +08:00
|
|
|
this.$emit('result:elements:loaded');
|
2023-08-10 22:48:08 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
loadAttachments() {
|
|
|
|
this.attachmentsReady = false
|
|
|
|
|
|
|
|
$.get(this.urls.attachments_url, (result) => {
|
|
|
|
this.attachments = result.data
|
|
|
|
|
|
|
|
if (this.attachments.findIndex((e) => e.attributes.attached === false) >= 0) {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.loadAttachments()
|
|
|
|
}, 10000)
|
|
|
|
} else {
|
|
|
|
this.attachmentsReady = true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.showFileModal = false;
|
|
|
|
},
|
|
|
|
attachmentDeleted(id) {
|
|
|
|
this.attachments = this.attachments.filter((a) => a.id !== id );
|
|
|
|
this.$emit('resultUpdated');
|
|
|
|
},
|
2023-08-11 20:48:20 +08:00
|
|
|
createElement(elementType, tableDimensions = [5,5], plateTemplate = false) {
|
|
|
|
$.post(this.urls[`create_${elementType}_url`], { tableDimensions: tableDimensions, plateTemplate: plateTemplate }, (result) => {
|
|
|
|
result.data.isNew = true;
|
|
|
|
this.elements.push(result.data)
|
2023-08-17 22:32:42 +08:00
|
|
|
this.$emit('resultUpdated')
|
2023-08-11 20:48:20 +08:00
|
|
|
}).fail(() => {
|
|
|
|
HelperModule.flashAlertMsg(this.i18n.t('errors.general'), 'danger');
|
|
|
|
}).done(() => {
|
|
|
|
this.$parent.$nextTick(() => {
|
|
|
|
const children = this.$children
|
|
|
|
const lastChild = children[children.length - 1]
|
|
|
|
lastChild.$el.scrollIntoView(false)
|
|
|
|
window.scrollBy({
|
|
|
|
top: 200,
|
|
|
|
behavior: 'smooth'
|
|
|
|
});
|
|
|
|
})
|
|
|
|
});
|
|
|
|
},
|
2023-08-17 14:29:34 +08:00
|
|
|
archiveResult() {
|
|
|
|
|
|
|
|
},
|
|
|
|
duplicateResult() {
|
2023-08-23 21:05:31 +08:00
|
|
|
axios.post(this.urls.duplicate_url).then((_) => {
|
|
|
|
this.$emit('duplicated');
|
|
|
|
});
|
2023-08-21 15:22:56 +08:00
|
|
|
},
|
|
|
|
moveElement(position, target_id) {
|
|
|
|
this.elements.splice(position, 1)
|
|
|
|
let unorderedElements = this.elements.map( e => {
|
|
|
|
if (e.attributes.position >= position) {
|
|
|
|
e.attributes.position -= 1;
|
|
|
|
}
|
|
|
|
return e;
|
|
|
|
})
|
|
|
|
this.$emit('resultUpdated')
|
|
|
|
this.$emit('result:move_element', target_id)
|
2023-08-17 22:32:42 +08:00
|
|
|
},
|
|
|
|
updateName(name) {
|
2023-08-23 21:05:31 +08:00
|
|
|
axios.patch(this.urls.update_url, { result: { name: name } }).then((_) => {
|
|
|
|
this.$emit('updated');
|
2023-08-17 22:32:42 +08:00
|
|
|
});
|
2023-08-17 14:29:34 +08:00
|
|
|
}
|
2023-08-03 22:03:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|