2022-04-21 21:12:34 +08:00
|
|
|
<template>
|
2022-04-26 20:13:17 +08:00
|
|
|
<div class="task-protocol">
|
|
|
|
<div class="task-section-header">
|
|
|
|
<a class="task-section-caret" role="button" data-toggle="collapse" href="#protocol-content" aria-expanded="true" aria-controls="protocol-content">
|
|
|
|
<i class="fas fa-caret-right"></i>
|
|
|
|
<div class="task-section-title">
|
|
|
|
<h2>{{ i18n.t('Protocol') }}</h2>
|
|
|
|
</div>
|
|
|
|
<span v-if="protocol.linked" class="status-label linked">
|
|
|
|
[{{ protocol.name }}]
|
|
|
|
</span>
|
|
|
|
<span class="status-label" v-else>
|
|
|
|
[{{ i18n.t('my_modules.protocols.protocol_status_bar.unlinked') }}]
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
<div class="sci-btn-group actions-block">
|
2022-04-29 18:29:42 +08:00
|
|
|
<a class="btn btn-primary" @click="addStep(steps.length)">
|
2022-04-26 20:13:17 +08:00
|
|
|
<span class="fas fa-plus" aria-hidden="true"></span>
|
|
|
|
<span>New step</span>
|
2022-04-21 21:12:34 +08:00
|
|
|
</a>
|
2022-04-26 20:13:17 +08:00
|
|
|
<a class="btn btn-default" data-toggle="modal" data-target="#print-protocol-modal">
|
|
|
|
<span class="fas fa-print" aria-hidden="true"></span>
|
|
|
|
<span>Print</span>
|
|
|
|
</a>
|
|
|
|
<div class="dropdown sci-dropdown">
|
|
|
|
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownProtocolOptions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
|
|
|
<span class="fas fa-cog"></span>
|
|
|
|
<span>Protocol options</span>
|
|
|
|
<span class="caret"></span>
|
|
|
|
</button>
|
|
|
|
<ul class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownProtocolOptions">
|
|
|
|
<li>
|
|
|
|
<a>
|
|
|
|
<span class="fas fa-edit"></span>
|
|
|
|
<span>Load from repository</span>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<a>
|
|
|
|
<span class="fas fa-download"></span>
|
|
|
|
<span>Import protocol</span>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<a>
|
|
|
|
<span class="fas fa-upload"></span>
|
|
|
|
<span>Export protocol</span>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<a>
|
|
|
|
<span class="fas fa-save"></span>
|
|
|
|
<span>Save to repository</span>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
2022-04-21 21:12:34 +08:00
|
|
|
</div>
|
2022-04-26 20:13:17 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div v-if="protocol.id" id="protocol-content" class="protocol-content collapse in" aria-expanded="true">
|
|
|
|
<div class="protocol-description">
|
|
|
|
<div class="protocol-name">
|
|
|
|
<InlineEdit
|
|
|
|
:value="protocol.name"
|
|
|
|
:characterLimit="255"
|
|
|
|
:placeholder="i18n.t('my_modules.protocols.protocol_status_bar.enter_name')"
|
|
|
|
:allowBlank="true"
|
|
|
|
:attributeName="`${i18n.t('Protocol')} ${i18n.t('name')}`"
|
|
|
|
@update="updateName"
|
|
|
|
/>
|
2022-04-21 21:12:34 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-04-26 20:13:17 +08:00
|
|
|
<div class="protocol-steps">
|
|
|
|
<template v-for="(step, index) in steps">
|
|
|
|
<div class="step-block" :key="step.id">
|
2022-04-28 17:13:38 +08:00
|
|
|
<div v-if="index > 0" class="insert-step" @click="addStep(index)">
|
2022-04-26 20:13:17 +08:00
|
|
|
<i class="fas fa-plus"></i>
|
2022-04-28 17:13:38 +08:00
|
|
|
</div>
|
2022-04-26 20:13:17 +08:00
|
|
|
<Step
|
|
|
|
:step.sync="steps[index]"
|
|
|
|
@step:delete="updateStepsPosition"
|
2022-04-28 17:13:38 +08:00
|
|
|
@step:update="updateStep"
|
2022-04-26 20:13:17 +08:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
<button class="btn btn-primary" @click="addStep(steps.length)">
|
|
|
|
<i class="fas fa-plus"></i>
|
|
|
|
{{ i18n.t("protocols.steps.new_step") }}
|
|
|
|
</button>
|
2022-04-21 21:12:34 +08:00
|
|
|
</div>
|
2022-04-26 20:13:17 +08:00
|
|
|
</div>
|
2022-04-21 21:12:34 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-04-26 20:13:17 +08:00
|
|
|
import InlineEdit from 'vue/shared/inline_edit.vue'
|
2022-04-22 19:07:51 +08:00
|
|
|
import Step from 'vue/protocol/step'
|
|
|
|
|
2022-04-21 21:12:34 +08:00
|
|
|
export default {
|
|
|
|
name: 'ProtocolContainer',
|
|
|
|
props: {
|
2022-04-22 19:07:51 +08:00
|
|
|
protocolUrl: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
stepsUrl: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
addStepUrl: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
2022-04-26 20:13:17 +08:00
|
|
|
},
|
|
|
|
editable:{
|
|
|
|
Boolean,
|
|
|
|
required: true
|
2022-04-22 19:07:51 +08:00
|
|
|
}
|
2022-04-21 21:12:34 +08:00
|
|
|
},
|
2022-04-26 20:13:17 +08:00
|
|
|
components: { Step, InlineEdit },
|
2022-04-21 21:12:34 +08:00
|
|
|
data() {
|
|
|
|
return {
|
2022-04-22 19:07:51 +08:00
|
|
|
protocol: {},
|
|
|
|
steps: {}
|
2022-04-21 21:12:34 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
$.get(this.protocolUrl, (data) => {
|
|
|
|
this.protocol = data;
|
|
|
|
});
|
2022-04-22 19:07:51 +08:00
|
|
|
$.get(this.stepsUrl, (result) => {
|
|
|
|
this.steps = result.data
|
|
|
|
})
|
2022-04-21 21:12:34 +08:00
|
|
|
},
|
2022-04-22 19:07:51 +08:00
|
|
|
methods: {
|
2022-04-26 20:13:17 +08:00
|
|
|
updateName(newName) {
|
|
|
|
this.protocol.name = newName;
|
|
|
|
$.ajax({
|
|
|
|
type: 'PATCH',
|
|
|
|
url: this.protocolUrl,
|
|
|
|
data: { protocol: { name: newName } }
|
|
|
|
});
|
|
|
|
},
|
2022-04-22 19:07:51 +08:00
|
|
|
addStep(position) {
|
|
|
|
$.post(this.addStepUrl, {position: position}, (result) => {
|
|
|
|
this.updateStepsPosition(result.data)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
updateStepsPosition(step, action = 'add') {
|
|
|
|
let position = step.attributes.position;
|
|
|
|
if (action === 'delete') {
|
|
|
|
this.steps.splice(position, 1)
|
|
|
|
}
|
|
|
|
let unordered_steps = this.steps.map( s => {
|
|
|
|
if (s.attributes.position >= position) {
|
|
|
|
if (action === 'add') {
|
|
|
|
s.attributes.position += 1;
|
|
|
|
} else {
|
|
|
|
s.attributes.position -= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
})
|
|
|
|
if (action === 'add') {
|
|
|
|
unordered_steps.push(step);
|
|
|
|
}
|
|
|
|
this.reorderSteps(unordered_steps)
|
|
|
|
|
|
|
|
},
|
2022-04-29 18:29:42 +08:00
|
|
|
updateStep(attributes) {
|
|
|
|
this.steps[attributes.position].attributes = attributes
|
2022-04-28 17:13:38 +08:00
|
|
|
},
|
2022-04-22 19:07:51 +08:00
|
|
|
reorderSteps(steps) {
|
|
|
|
this.steps = steps.sort((a, b) => a.attributes.position - b.attributes.position);
|
|
|
|
}
|
|
|
|
}
|
2022-04-21 21:12:34 +08:00
|
|
|
}
|
|
|
|
</script>
|