2022-04-21 21:12:34 +08:00
|
|
|
<template>
|
2023-03-02 18:33:40 +08:00
|
|
|
<div v-if="protocol.id" class="task-protocol">
|
2023-09-21 15:45:20 +08:00
|
|
|
<div ref="header" class="task-section-header ml-[-1rem] w-[calc(100%_+_2rem)] px-4 bg-sn-white sticky top-0 transition" v-if="!inRepository">
|
2023-09-28 21:40:48 +08:00
|
|
|
<div class="flex items-center grow">
|
|
|
|
<div class="portocol-header-left-part grow">
|
|
|
|
<template v-if="headerSticked && moduleName">
|
|
|
|
<i class="sn-icon sn-icon-navigator sci--layout--navigator-open cursor-pointer p-1.5 border rounded border-sn-light-grey mr-4"></i>
|
2023-11-28 22:09:21 +08:00
|
|
|
<div @click="scrollTop" class="task-section-title w-[calc(100%_-_35rem)] min-w-[5rem] cursor-pointer">
|
2023-09-28 21:40:48 +08:00
|
|
|
<h2 class="truncate leading-6">{{ moduleName }}</h2>
|
2023-08-29 21:45:07 +08:00
|
|
|
</div>
|
2023-09-28 21:40:48 +08:00
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<a class="task-section-caret" tabindex="0" role="button" data-toggle="collapse" href="#protocol-content" aria-expanded="true" aria-controls="protocol-content">
|
|
|
|
<i class="sn-icon sn-icon-right"></i>
|
|
|
|
<div class="task-section-title truncate">
|
|
|
|
<h2>{{ i18n.t('Protocol') }}</h2>
|
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
</template>
|
2023-09-29 17:44:38 +08:00
|
|
|
<div :class="{'hidden': headerSticked}">
|
|
|
|
<div class="my-module-protocol-status">
|
|
|
|
<!-- protocol status dropdown gets mounted here -->
|
|
|
|
</div>
|
2022-07-05 18:49:12 +08:00
|
|
|
</div>
|
2022-04-26 20:13:17 +08:00
|
|
|
</div>
|
2022-05-04 17:49:57 +08:00
|
|
|
</div>
|
2022-07-05 18:49:12 +08:00
|
|
|
<div class="actions-block">
|
2023-11-28 22:09:21 +08:00
|
|
|
<div class="protocol-buttons-group shrink-0">
|
2023-01-03 19:25:22 +08:00
|
|
|
<a v-if="urls.add_step_url"
|
2023-08-09 17:01:20 +08:00
|
|
|
class="btn btn-secondary"
|
2023-09-12 23:33:47 +08:00
|
|
|
:title="i18n.t('protocols.steps.new_step_title')"
|
2023-01-03 19:25:22 +08:00
|
|
|
@keyup.enter="addStep(steps.length)"
|
|
|
|
@click="addStep(steps.length)"
|
|
|
|
tabindex="0">
|
2023-06-08 14:33:37 +08:00
|
|
|
<span class="sn-icon sn-icon-new-task" aria-hidden="true"></span>
|
2022-07-05 18:49:12 +08:00
|
|
|
<span>{{ i18n.t("protocols.steps.new_step") }}</span>
|
|
|
|
</a>
|
2023-08-09 17:01:20 +08:00
|
|
|
<template v-if="steps.length > 0">
|
|
|
|
<button class="btn btn-secondary" @click="collapseSteps" tabindex="0">
|
|
|
|
{{ i18n.t("protocols.steps.collapse_label") }}
|
|
|
|
</button>
|
|
|
|
<button class="btn btn-secondary" @click="expandSteps" tabindex="0">
|
|
|
|
{{ i18n.t("protocols.steps.expand_label") }}
|
|
|
|
</button>
|
|
|
|
</template>
|
2022-07-05 18:49:12 +08:00
|
|
|
<ProtocolOptions
|
|
|
|
v-if="protocol.attributes && protocol.attributes.urls"
|
|
|
|
:protocol="protocol"
|
|
|
|
@protocol:delete_steps="deleteSteps"
|
|
|
|
:canDeleteSteps="steps.length > 0 && urls.delete_steps_url !== null"
|
|
|
|
/>
|
2023-08-09 17:01:20 +08:00
|
|
|
<button class="btn btn-light icon-btn" data-toggle="modal" data-target="#print-protocol-modal" tabindex="0">
|
|
|
|
<span class="sn-icon sn-icon-printer" aria-hidden="true"></span>
|
|
|
|
</button>
|
|
|
|
<a v-if="steps.length > 0 && urls.reorder_steps_url"
|
|
|
|
class="btn btn-light icon-btn"
|
|
|
|
data-toggle="modal"
|
|
|
|
@click="startStepReorder"
|
|
|
|
@keyup.enter="startStepReorder"
|
|
|
|
:class="{'disabled': steps.length == 1}"
|
|
|
|
tabindex="0" >
|
|
|
|
<i class="sn-icon sn-icon-sort" aria-hidden="true"></i>
|
|
|
|
</a>
|
2022-07-05 18:49:12 +08:00
|
|
|
</div>
|
2022-04-26 20:13:17 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-03-02 18:33:40 +08:00
|
|
|
<div id="protocol-content" class="protocol-content collapse in" aria-expanded="true">
|
2023-10-09 17:28:18 +08:00
|
|
|
<div class="sci-divider" v-if="!inRepository"></div>
|
2023-09-11 18:03:17 +08:00
|
|
|
<div class="mb-4">
|
|
|
|
<div class="protocol-name mt-4" v-if="!inRepository">
|
2022-04-26 20:13:17 +08:00
|
|
|
<InlineEdit
|
2022-06-06 19:56:22 +08:00
|
|
|
v-if="urls.update_protocol_name_url"
|
2022-05-03 21:18:48 +08:00
|
|
|
:value="protocol.attributes.name"
|
2022-04-26 20:13:17 +08:00
|
|
|
:characterLimit="255"
|
|
|
|
:placeholder="i18n.t('my_modules.protocols.protocol_status_bar.enter_name')"
|
2022-08-10 21:39:45 +08:00
|
|
|
:allowBlank="!inRepository"
|
2022-04-26 20:13:17 +08:00
|
|
|
:attributeName="`${i18n.t('Protocol')} ${i18n.t('name')}`"
|
|
|
|
@update="updateName"
|
|
|
|
/>
|
2022-06-03 17:52:10 +08:00
|
|
|
<span v-else>
|
|
|
|
{{ protocol.attributes.name }}
|
|
|
|
</span>
|
2022-04-21 21:12:34 +08:00
|
|
|
</div>
|
2023-02-13 16:50:39 +08:00
|
|
|
<ProtocolMetadata v-if="protocol.attributes && protocol.attributes.in_repository" :protocol="protocol" @update="updateProtocol" @publish="startPublish"/>
|
2023-01-05 18:42:59 +08:00
|
|
|
<div :class="inRepository ? 'protocol-section protocol-information' : ''">
|
|
|
|
<div v-if="inRepository" id="protocol-description" class="protocol-section-header">
|
|
|
|
<div class="protocol-description-container">
|
2024-06-07 18:05:31 +08:00
|
|
|
<a class="protocol-section-caret"
|
|
|
|
role="button"
|
|
|
|
data-toggle="collapse"
|
|
|
|
href="#protocol-description-container"
|
|
|
|
aria-expanded="false"
|
|
|
|
aria-controls="protocol-description-container">
|
2023-06-15 21:12:51 +08:00
|
|
|
<i class="sn-icon sn-icon-right"></i>
|
2024-06-07 18:05:31 +08:00
|
|
|
<span id="protocolDescriptionLabel" class="protocol-section-title" data-e2e="e2e-TX-protocolTemplates-protocolDescription-title">
|
2023-01-05 18:42:59 +08:00
|
|
|
<h2>
|
|
|
|
{{ i18n.t("protocols.header.protocol_description") }}
|
|
|
|
</h2>
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-06-07 18:05:31 +08:00
|
|
|
<div id="protocol-description-container"
|
|
|
|
class="text-base"
|
|
|
|
:class=" inRepository ? 'protocol-description collapse in' : ''"
|
|
|
|
data-e2e="e2e-IF-protocolTemplates-protocolDescription-content">
|
2023-09-11 18:03:17 +08:00
|
|
|
<div v-if="urls.update_protocol_description_url">
|
2023-01-05 18:42:59 +08:00
|
|
|
<Tinymce
|
|
|
|
:value="protocol.attributes.description"
|
|
|
|
:value_html="protocol.attributes.description_view"
|
|
|
|
:placeholder="i18n.t('my_modules.protocols.protocol_status_bar.empty_description_edit_label')"
|
|
|
|
:updateUrl="urls.update_protocol_description_url"
|
|
|
|
:objectType="'Protocol'"
|
|
|
|
:objectId="parseInt(protocol.id)"
|
|
|
|
:fieldName="'protocol[description]'"
|
|
|
|
:lastUpdated="protocol.attributes.updated_at"
|
2023-04-25 21:12:19 +08:00
|
|
|
:assignableMyModuleId="protocol.attributes.assignable_my_module_id"
|
2023-05-17 17:40:14 +08:00
|
|
|
:characterLimit="1000000"
|
2023-01-05 18:42:59 +08:00
|
|
|
@update="updateDescription"
|
|
|
|
/>
|
|
|
|
</div>
|
2024-01-31 16:32:19 +08:00
|
|
|
<div v-else-if="protocol.attributes.description_view" v-html="wrappedTables" class="view-text-element"></div>
|
2023-01-05 18:42:59 +08:00
|
|
|
<div v-else class="empty-protocol-description">
|
|
|
|
{{ i18n.t("protocols.no_text_placeholder") }}
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-06-03 17:52:10 +08:00
|
|
|
</div>
|
2022-04-21 21:12:34 +08:00
|
|
|
</div>
|
2023-01-05 18:42:59 +08:00
|
|
|
<div :class="inRepository ? 'protocol-section protocol-steps-section protocol-information' : ''">
|
|
|
|
<div v-if="inRepository" id="protocol-steps" class="protocol-section-header">
|
|
|
|
<div class="protocol-steps-container">
|
|
|
|
<a class="protocol-section-caret" role="button" data-toggle="collapse" href="#protocol-steps-container" aria-expanded="false" aria-controls="protocol-steps-container">
|
2023-06-15 21:12:51 +08:00
|
|
|
<i class="sn-icon sn-icon-right"></i>
|
2024-06-07 18:05:31 +08:00
|
|
|
<span id="protocolStepsLabel" class="protocol-section-title" data-e2e="e2e-TX-protocol-templateSteps-title">
|
2023-01-05 18:42:59 +08:00
|
|
|
<h2>
|
|
|
|
{{ i18n.t("protocols.header.protocol_steps") }}
|
|
|
|
</h2>
|
|
|
|
</span>
|
|
|
|
</a>
|
2022-04-26 20:13:17 +08:00
|
|
|
</div>
|
2023-01-05 18:42:59 +08:00
|
|
|
</div>
|
2023-10-09 17:28:18 +08:00
|
|
|
<div class="sci-divider my-4" v-if="!inRepository"></div>
|
2023-01-05 18:42:59 +08:00
|
|
|
<div id="protocol-steps-container" :class=" inRepository ? 'protocol-steps collapse in' : ''">
|
2023-10-03 21:03:37 +08:00
|
|
|
<div v-if="urls.add_step_url && inRepository" class="py-5 flex flex-row gap-8 justify-between">
|
2023-09-13 20:57:03 +08:00
|
|
|
<a
|
|
|
|
class="btn btn-secondary"
|
|
|
|
:title="i18n.t('protocols.steps.new_step_title')"
|
2024-06-07 18:05:31 +08:00
|
|
|
data-e2e="e2e-BT-protocol-templateSteps-newStepTop"
|
2023-09-13 20:57:03 +08:00
|
|
|
@keyup.enter="addStep(steps.length)"
|
|
|
|
@click="addStep(steps.length)"
|
|
|
|
tabindex="0">
|
|
|
|
<span class="sn-icon sn-icon-new-task" aria-hidden="true"></span>
|
|
|
|
<span>{{ i18n.t("protocols.steps.new_step") }}</span>
|
|
|
|
</a>
|
2023-10-03 21:03:37 +08:00
|
|
|
<div v-if="steps.length > 0" class="flex justify-between items-center gap-4">
|
2024-06-07 18:05:31 +08:00
|
|
|
<button @click="collapseSteps" class="btn btn-secondary flex px-4" tabindex="0" data-e2e="e2e-BT-protocol-templateSteps-collapse">
|
2023-10-03 21:03:37 +08:00
|
|
|
{{ i18n.t("protocols.steps.collapse_label") }}
|
|
|
|
</button>
|
2024-06-07 18:05:31 +08:00
|
|
|
<button @click="expandSteps" class="btn btn-secondary flex px-4" tabindex="0" data-e2e="e2e-BT-protocol-templateSteps-expand">
|
2023-10-03 21:03:37 +08:00
|
|
|
{{ i18n.t("protocols.steps.expand_label") }}
|
|
|
|
</button>
|
|
|
|
<a v-if="steps.length > 0 && urls.reorder_steps_url"
|
|
|
|
class="btn btn-light icon-btn"
|
|
|
|
data-toggle="modal"
|
2024-06-07 18:05:31 +08:00
|
|
|
data-e2e="e2e-BT-protocol-templateSteps-reorder"
|
2023-10-03 21:03:37 +08:00
|
|
|
@click="startStepReorder"
|
|
|
|
@keyup.enter="startStepReorder"
|
|
|
|
:class="{'disabled': steps.length == 1}"
|
|
|
|
tabindex="0" >
|
|
|
|
<i class="sn-icon sn-icon-sort" aria-hidden="true"></i>
|
|
|
|
</a>
|
|
|
|
</div>
|
2023-09-13 20:57:03 +08:00
|
|
|
</div>
|
2023-09-22 17:59:39 +08:00
|
|
|
<div class="protocol-steps pb-8">
|
2023-09-12 23:33:47 +08:00
|
|
|
<div v-for="(step, index) in steps" :key="step.id" class="step-block">
|
2024-06-07 18:05:31 +08:00
|
|
|
<div v-if="index > 0 && urls.add_step_url" class="insert-step" @click="addStep(index)" data-e2e="e2e-BT-protocol-templateSteps-insertStep">
|
2023-09-12 23:33:47 +08:00
|
|
|
<i class="sn-icon sn-icon-new-task"></i>
|
2023-01-05 18:42:59 +08:00
|
|
|
</div>
|
2023-09-12 23:33:47 +08:00
|
|
|
<Step
|
2023-11-20 18:38:41 +08:00
|
|
|
ref="steps"
|
2023-09-12 23:33:47 +08:00
|
|
|
:step.sync="steps[index]"
|
|
|
|
@reorder="startStepReorder"
|
|
|
|
:inRepository="inRepository"
|
|
|
|
:stepToReload="stepToReload"
|
2023-10-18 18:03:12 +08:00
|
|
|
:activeDragStep="activeDragStep"
|
2023-09-12 23:33:47 +08:00
|
|
|
@step:delete="updateStepsPosition"
|
|
|
|
@step:update="updateStep"
|
|
|
|
@stepUpdated="refreshProtocolStatus"
|
|
|
|
@step:insert="updateStepsPosition"
|
|
|
|
@step:elements:loaded="stepToReload = null"
|
|
|
|
@step:move_element="reloadStep"
|
|
|
|
@step:attachemnts:loaded="stepToReload = null"
|
|
|
|
@step:move_attachment="reloadStep"
|
2023-10-18 18:03:12 +08:00
|
|
|
@step:drag_enter="dragEnter"
|
2023-09-12 23:33:47 +08:00
|
|
|
:reorderStepUrl="steps.length > 1 ? urls.reorder_steps_url : null"
|
|
|
|
:assignableMyModuleId="protocol.attributes.assignable_my_module_id"
|
|
|
|
/>
|
2024-06-07 18:05:31 +08:00
|
|
|
<div v-if="(index === steps.length - 1) && urls.add_step_url" class="insert-step" @click="addStep(index + 1)" data-e2e="e2e-BT-protocol-templateSteps-insertStep">
|
2024-02-26 01:28:39 +08:00
|
|
|
<i class="sn-icon sn-icon-new-task"></i>
|
|
|
|
</div>
|
2023-09-12 23:33:47 +08:00
|
|
|
</div>
|
2023-09-13 20:57:03 +08:00
|
|
|
<div v-if="steps.length > 0 && urls.add_step_url && inRepository" class="py-5">
|
|
|
|
<a
|
2023-09-12 23:33:47 +08:00
|
|
|
class="btn btn-secondary"
|
|
|
|
:title="i18n.t('protocols.steps.new_step_title')"
|
2024-06-07 18:05:31 +08:00
|
|
|
data-e2e="e2e-BT-protocol-templateSteps-newStepBottom"
|
2023-09-12 23:33:47 +08:00
|
|
|
@keyup.enter="addStep(steps.length)"
|
|
|
|
@click="addStep(steps.length)"
|
|
|
|
tabindex="0">
|
|
|
|
<span class="sn-icon sn-icon-new-task" aria-hidden="true"></span>
|
|
|
|
<span>{{ i18n.t("protocols.steps.new_step") }}</span>
|
|
|
|
</a>
|
|
|
|
</div>
|
2023-01-05 18:42:59 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-04-26 20:13:17 +08:00
|
|
|
</div>
|
2022-04-21 21:12:34 +08:00
|
|
|
</div>
|
2022-05-30 19:45:51 +08:00
|
|
|
<ReorderableItemsModal v-if="reordering"
|
|
|
|
:title="i18n.t('protocols.reorder_steps.modal.title')"
|
|
|
|
:items="steps"
|
|
|
|
:includeNumbers="true"
|
|
|
|
@reorder="updateStepOrder"
|
|
|
|
@close="closeStepReorderModal"
|
|
|
|
/>
|
2023-02-13 16:50:39 +08:00
|
|
|
<PublishProtocol v-if="publishing"
|
|
|
|
:protocol="protocol"
|
|
|
|
@publish="publishProtocol"
|
2023-03-07 16:49:21 +08:00
|
|
|
@cancel="closePublishModal"
|
2023-02-13 16:50:39 +08:00
|
|
|
/>
|
2023-10-26 18:01:48 +08:00
|
|
|
<clipboardPasteModal v-if="showClipboardPasteModal"
|
|
|
|
:image="pasteImages"
|
|
|
|
:objects="steps"
|
|
|
|
:objectType="'step'"
|
|
|
|
:selectedObjectId="firstObjectInViewport()"
|
|
|
|
@files="uploadFilesToStep"
|
|
|
|
@cancel="showClipboardPasteModal = false"
|
|
|
|
/>
|
2022-04-26 20:13:17 +08:00
|
|
|
</div>
|
2022-04-21 21:12:34 +08:00
|
|
|
</template>
|
|
|
|
|
2024-01-04 23:34:36 +08:00
|
|
|
<script>
|
|
|
|
import InlineEdit from '../shared/inline_edit.vue';
|
|
|
|
import Step from './step';
|
|
|
|
import ProtocolMetadata from './protocolMetadata';
|
|
|
|
import ProtocolOptions from './protocolOptions';
|
|
|
|
import Tinymce from '../shared/tinymce.vue';
|
|
|
|
import ReorderableItemsModal from '../shared/reorderable_items_modal.vue';
|
|
|
|
import PublishProtocol from './modals/publish_protocol.vue';
|
|
|
|
import clipboardPasteModal from '../shared/content/attachments/clipboard_paste_modal.vue';
|
|
|
|
import AssetPasteMixin from '../shared/content/attachments/mixins/paste.js';
|
2022-05-30 19:45:51 +08:00
|
|
|
|
2024-01-04 23:34:36 +08:00
|
|
|
import UtilsMixin from '../mixins/utils.js';
|
|
|
|
import stackableHeadersMixin from '../mixins/stackableHeadersMixin';
|
|
|
|
import moduleNameObserver from '../mixins/moduleNameObserver';
|
2022-04-22 19:07:51 +08:00
|
|
|
|
2024-01-04 23:34:36 +08:00
|
|
|
export default {
|
|
|
|
name: 'ProtocolContainer',
|
|
|
|
props: {
|
|
|
|
protocolUrl: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
Step, InlineEdit, ProtocolOptions, Tinymce, ReorderableItemsModal, ProtocolMetadata, PublishProtocol, clipboardPasteModal
|
|
|
|
},
|
|
|
|
mixins: [UtilsMixin, stackableHeadersMixin, moduleNameObserver, AssetPasteMixin],
|
|
|
|
computed: {
|
2024-01-31 16:32:19 +08:00
|
|
|
wrappedTables() {
|
|
|
|
return window.wrapTables(this.protocol.attributes.description_view);
|
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
inRepository() {
|
|
|
|
return this.protocol.attributes.in_repository;
|
2022-04-21 21:12:34 +08:00
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
linked() {
|
|
|
|
return this.protocol.attributes.linked;
|
|
|
|
},
|
|
|
|
urls() {
|
|
|
|
return this.protocol.attributes.urls || {};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
protocol: {
|
|
|
|
attributes: {}
|
2023-10-26 18:01:48 +08:00
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
steps: [],
|
|
|
|
reordering: false,
|
|
|
|
publishing: false,
|
|
|
|
stepToReload: null,
|
|
|
|
activeDragStep: null
|
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
$.get(this.protocolUrl, (result) => {
|
|
|
|
this.protocol = result.data;
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.refreshProtocolStatus();
|
|
|
|
if (!this.inRepository) {
|
|
|
|
window.addEventListener('scroll', this.initStackableHeaders, false);
|
|
|
|
this.initStackableHeaders();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$.get(this.urls.steps_url, (result) => {
|
|
|
|
this.steps = result.data;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
beforeUnmount() {
|
|
|
|
if (!this.inRepository) {
|
|
|
|
window.removeEventListener('scroll', this.initStackableHeaders, false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getHeader() {
|
|
|
|
return this.$refs.header;
|
2022-05-27 18:49:10 +08:00
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
reloadStep(step) {
|
|
|
|
this.stepToReload = step;
|
|
|
|
},
|
|
|
|
collapseSteps() {
|
|
|
|
$('.step-container .collapse').collapse('hide');
|
|
|
|
},
|
|
|
|
expandSteps() {
|
|
|
|
$('.step-container .collapse').collapse('show');
|
|
|
|
},
|
|
|
|
deleteSteps() {
|
|
|
|
$.post(this.urls.delete_steps_url, () => {
|
|
|
|
this.steps = [];
|
|
|
|
}).fail(() => {
|
|
|
|
HelperModule.flashAlertMsg(this.i18n.t('errors.general'), 'danger');
|
|
|
|
});
|
2022-04-21 21:12:34 +08:00
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
refreshProtocolStatus() {
|
|
|
|
if (this.inRepository) return;
|
|
|
|
// legacy method from app/assets/javascripts/my_modules/protocols.js
|
|
|
|
refreshProtocolStatusBar();
|
|
|
|
|
|
|
|
// Update protocol options drowpdown for linked tasks
|
|
|
|
this.refreshProtocolDropdownOptions();
|
|
|
|
},
|
|
|
|
refreshProtocolDropdownOptions() {
|
|
|
|
if (!this.linked && this.inRepository) return;
|
|
|
|
|
2022-05-03 21:18:48 +08:00
|
|
|
$.get(this.protocolUrl, (result) => {
|
2024-01-04 23:34:36 +08:00
|
|
|
this.protocol.attributes.urls = result.data.attributes.urls;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
updateProtocol(attributes) {
|
|
|
|
this.protocol.attributes = attributes;
|
|
|
|
},
|
|
|
|
updateName(newName) {
|
|
|
|
this.protocol.attributes.name = newName;
|
|
|
|
$.ajax({
|
|
|
|
type: 'PATCH',
|
|
|
|
url: this.urls.update_protocol_name_url,
|
|
|
|
data: { protocol: { name: newName } },
|
|
|
|
success: () => {
|
2023-03-03 16:55:42 +08:00
|
|
|
this.refreshProtocolStatus();
|
2024-01-04 23:34:36 +08:00
|
|
|
}
|
2022-04-21 21:12:34 +08:00
|
|
|
});
|
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
updateDescription(protocol) {
|
|
|
|
this.protocol.attributes = protocol.attributes;
|
|
|
|
this.refreshProtocolStatus();
|
2023-08-29 21:45:07 +08:00
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
addStep(position) {
|
|
|
|
$.post(this.urls.add_step_url, { position }, (result) => {
|
|
|
|
result.data.newStep = true;
|
|
|
|
this.updateStepsPosition(result.data);
|
2023-03-14 20:03:37 +08:00
|
|
|
|
2024-01-04 23:34:36 +08:00
|
|
|
// scroll to bottom if step was appended at the end
|
|
|
|
if (position === this.steps.length - 1) {
|
|
|
|
this.$nextTick(() => this.scrollToBottom());
|
2022-04-22 19:07:51 +08:00
|
|
|
}
|
2024-01-04 23:34:36 +08:00
|
|
|
this.refreshProtocolStatus();
|
|
|
|
}).fail((data) => {
|
|
|
|
HelperModule.flashAlertMsg(data.responseJSON.error ? Object.values(data.responseJSON.error).join(', ') : I18n.t('errors.general'), 'danger');
|
|
|
|
});
|
|
|
|
},
|
|
|
|
updateStepsPosition(step, action = 'add') {
|
|
|
|
const { position } = step.attributes;
|
|
|
|
if (action === 'delete') {
|
|
|
|
this.steps.splice(position, 1);
|
|
|
|
}
|
|
|
|
const unordered_steps = this.steps.map((s) => {
|
|
|
|
if (s.attributes.position >= position) {
|
|
|
|
if (action === 'add') {
|
|
|
|
s.attributes.position += 1;
|
|
|
|
} else {
|
|
|
|
s.attributes.position -= 1;
|
2022-04-22 19:07:51 +08:00
|
|
|
}
|
|
|
|
}
|
2024-01-04 23:34:36 +08:00
|
|
|
return s;
|
|
|
|
});
|
|
|
|
if (action === 'add') {
|
|
|
|
unordered_steps.push(step);
|
|
|
|
}
|
|
|
|
this.reorderSteps(unordered_steps);
|
|
|
|
},
|
|
|
|
updateStep(attributes) {
|
|
|
|
this.steps[attributes.position].attributes = {
|
|
|
|
...this.steps[attributes.position].attributes,
|
|
|
|
...attributes
|
|
|
|
};
|
|
|
|
this.refreshProtocolStatus();
|
|
|
|
},
|
|
|
|
reorderSteps(steps) {
|
|
|
|
this.steps = steps.sort((a, b) => a.attributes.position - b.attributes.position);
|
|
|
|
this.refreshProtocolStatus();
|
|
|
|
},
|
|
|
|
updateStepOrder(orderedSteps) {
|
|
|
|
orderedSteps.forEach((step, position) => {
|
|
|
|
const index = this.steps.findIndex((e) => e.id === step.id);
|
|
|
|
this.steps[index].attributes.position = position;
|
|
|
|
});
|
2022-05-30 19:45:51 +08:00
|
|
|
|
2024-01-04 23:34:36 +08:00
|
|
|
const stepPositions = {
|
|
|
|
step_positions: this.steps.map(
|
|
|
|
(step) => [step.id, step.attributes.position]
|
|
|
|
)
|
|
|
|
};
|
2022-05-30 19:45:51 +08:00
|
|
|
|
2024-01-04 23:34:36 +08:00
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: this.protocol.attributes.urls.reorder_steps_url,
|
|
|
|
data: JSON.stringify(stepPositions),
|
|
|
|
contentType: 'application/json',
|
|
|
|
dataType: 'json',
|
|
|
|
error: (() => HelperModule.flashAlertMsg(this.i18n.t('errors.general'), 'danger')),
|
|
|
|
success: (() => this.reorderSteps(this.steps))
|
|
|
|
});
|
|
|
|
},
|
|
|
|
startStepReorder() {
|
|
|
|
this.reordering = true;
|
|
|
|
},
|
|
|
|
closeStepReorderModal() {
|
|
|
|
this.reordering = false;
|
|
|
|
},
|
|
|
|
startPublish() {
|
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url: this.urls.version_comment_url,
|
|
|
|
contentType: 'application/json',
|
|
|
|
dataType: 'json',
|
|
|
|
success: (result) => {
|
|
|
|
this.protocol.attributes.version_comment = result.version_comment;
|
|
|
|
this.publishing = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
closePublishModal() {
|
|
|
|
this.publishing = false;
|
|
|
|
},
|
|
|
|
scrollToBottom() {
|
|
|
|
window.scrollTo(0, document.body.scrollHeight);
|
|
|
|
},
|
|
|
|
publishProtocol(comment) {
|
|
|
|
this.protocol.attributes.version_comment = comment;
|
|
|
|
$.post(this.urls.publish_url, { version_comment: comment, view: 'show' });
|
|
|
|
},
|
|
|
|
scrollTop() {
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
setTimeout(() => {
|
|
|
|
$('.my_module-name .view-mode').trigger('click');
|
|
|
|
$('.my_module-name .input-field').focus();
|
|
|
|
}, 300);
|
|
|
|
},
|
|
|
|
dragEnter(id) {
|
|
|
|
this.activeDragStep = id;
|
|
|
|
},
|
|
|
|
uploadFilesToStep(file, stepId) {
|
|
|
|
this.$refs.steps.find((child) => child.step?.id == stepId).uploadFiles(file);
|
|
|
|
},
|
|
|
|
firstObjectInViewport() {
|
|
|
|
const step = $('.step-container:not(.locked)').toArray().find((element) => {
|
|
|
|
const { top, bottom } = element.getBoundingClientRect();
|
|
|
|
return bottom > 0 && top < window.innerHeight;
|
|
|
|
});
|
|
|
|
return step ? step.dataset.id : null;
|
2022-04-22 19:07:51 +08:00
|
|
|
}
|
2022-04-21 21:12:34 +08:00
|
|
|
}
|
2024-01-04 23:34:36 +08:00
|
|
|
};
|
|
|
|
</script>
|