scinote-web/app/javascript/vue/protocol/protocolMetadata.vue

210 lines
8.8 KiB
Vue
Raw Normal View History

<template>
<div class="protocol-section protocol-information mb-4" data-e2e="e2e-CO-protocolTemplates-protocolDetails">
2023-01-05 18:42:59 +08:00
<div id="protocol-details" class="protocol-section-header">
<div class="protocol-details-container">
2023-12-28 03:09:36 +08:00
<a class="protocol-section-caret" role="button" data-toggle="collapse"
href="#details-container" aria-expanded="false" aria-controls="details-container">
2023-06-15 21:12:51 +08:00
<i class="sn-icon sn-icon-right"></i>
2023-01-05 18:42:59 +08:00
<span id="protocolDetailsLabel" class="protocol-section-title">
<h2 data-e2e="e2e-TX-protocolTemplates-protocolDetails-title">
2023-01-05 18:42:59 +08:00
{{ i18n.t("protocols.header.details") }}
</h2>
<span class="protocol-code" data-e2e="e2e-TX-protocolTemplates-protocolDetails-protocolId">{{ protocol.attributes.code }}</span>
2023-01-05 18:42:59 +08:00
</span>
</a>
</div>
<div class="actions-block">
2023-12-28 03:09:36 +08:00
<a class="btn btn-light icon-btn pull-right"
:href="protocol.attributes.urls.print_protocol_url" target="_blank"
data-e2e="e2e-BT-protocolTemplates-protocolDetails-print">
2023-06-08 14:33:37 +08:00
<span class="sn-icon sn-icon-printer" aria-hidden="true"></span>
2023-01-05 18:42:59 +08:00
</a>
<button class="btn btn-light" @click="openVersionsModal" data-e2e="e2e-BT-protocolTemplates-protocolDetails-versions">
2023-12-28 03:09:36 +08:00
{{ i18n.t("protocols.header.versions") }}
</button>
<button v-if="protocol.attributes.urls.publish_url"
@click="$emit('publish')" class="btn btn-primary" data-e2e="e2e-BT-protocolTemplates-protocolDetails-publish">
2023-12-28 03:09:36 +08:00
{{ i18n.t("protocols.header.publish") }}</button>
<button v-if="protocol.attributes.urls.save_as_draft_url"
:disabled="protocol.attributes.has_draft || creatingDraft"
@click="saveAsdraft" class="btn btn-secondary" data-e2e="e2e-BT-protocolTemplates-protocolDetails-saveAsDraft">
2023-12-28 03:09:36 +08:00
{{ i18n.t("protocols.header.save_as_draft") }}
</button>
2023-01-05 18:42:59 +08:00
</div>
</div>
<div id="details-container" class="protocol-details collapse in">
<div class="protocol-metadata">
<p class="data-block">
<span data-e2e="e2e-TX-protocolTemplates-protocolDetails-versionLabel">{{ i18n.t("protocols.header.version") }}</span>
<b data-e2e="e2e-TX-protocolTemplates-protocolDetails-version">{{ titleVersion }}</b>
2023-01-05 18:42:59 +08:00
</p>
<p class="data-block" v-if="protocol.attributes.published">
<span data-e2e="e2e-TX-protocolTemplates-protocolDetails-publishedOnLabel">{{ i18n.t("protocols.header.published_on") }}</span>
<b data-e2e="e2e-TX-protocolTemplates-protocolDetails-publishedOn">{{ protocol.attributes.published_on_formatted }}</b>
</p>
<p class="data-block" v-if="protocol.attributes.published" data-e2e="e2e-TX-protocolTemplates-protocolDetails-publishedBy">
<span>{{ i18n.t("protocols.header.published_by") }}</span>
<img :src="protocol.attributes.published_by.avatar" class="rounded-full"/>
{{ protocol.attributes.published_by.name }}
</p>
2023-01-05 18:42:59 +08:00
<p class="data-block">
<span data-e2e="e2e-TX-protocolTemplates-protocolDetails-updatedAtLabel">{{ i18n.t("protocols.header.updated_at") }}</span>
<b data-e2e="e2e-TX-protocolTemplates-protocolDetails-updatedAt">{{ protocol.attributes.updated_at_formatted }}</b>
2023-01-05 18:42:59 +08:00
</p>
<p class="data-block">
<span data-e2e="e2e-TX-protocolTemplates-protocolDetails-createdAtLabel">{{ i18n.t("protocols.header.created_at") }}</span>
<b data-e2e="e2e-TX-protocolTemplates-protocolDetails-createdAt">{{ protocol.attributes.created_at_formatted }}</b>
2023-01-05 18:42:59 +08:00
</p>
<p class="data-block" data-e2e="e2e-TX-protocolTemplates-protocolDetails-createdBy">
<span>{{ i18n.t("protocols.header.added_by") }}</span>
<img :src="protocol.attributes.added_by.avatar" class="rounded-full"/>
2023-01-05 18:42:59 +08:00
{{ protocol.attributes.added_by.name }}
</p>
<p class="data-block authors-data">
<span data-e2e="e2e-TX-protocolTemplates-protocolDetails-authorsLabel">{{ i18n.t("protocols.header.authors") }}</span>
2023-01-05 18:42:59 +08:00
<span class="authors-list" v-if="protocol.attributes.urls.update_protocol_authors_url">
<InlineEdit
:value="protocol.attributes.authors"
:placeholder="i18n.t('protocols.header.add_authors')"
:allowBlank="true"
:attributeName="`${i18n.t('Protocol')} ${i18n.t('protocols.header.authors_list')}`"
:characterLimit="10000"
:dataE2e="'protocolTemplates-protocolDetails-authors'"
2023-01-05 18:42:59 +08:00
@update="updateAuthors"
/>
</span>
<span class="authors-list" data-e2e="e2e-TX-protocolTemplates-protocolDetails-authorsPublished" v-else>
2023-01-05 18:42:59 +08:00
{{ protocol.attributes.authors }}
</span>
</p>
<p class="data-block keywords-data">
<span data-e2e="e2e-TX-protocolTemplates-protocolDetails-keywordsLabel">{{ i18n.t("protocols.header.keywords") }}</span>
<span
class="keywords-list"
v-if="protocol.attributes.urls.update_protocol_authors_url || protocol.attributes.keywords.length">
2023-01-05 18:42:59 +08:00
<DropdownSelector
:inputTagMode="true"
:options="this.protocol.attributes.keywords"
:placeholder="i18n.t('protocols.header.add_keywords')"
:selectorId="'keywordsSelector'"
:singleSelect="false"
:closeOnSelect="false"
:noEmptyOption="false"
:selectAppearance="'tag'"
:viewMode="protocol.attributes.urls.update_protocol_keywords_url == null"
:dataE2e="'e2e-IF-protocolTemplates-protocolDetails-keywords'"
2023-01-05 18:42:59 +08:00
@dropdown:changed="updateKeywords"
/>
</span>
</p>
</div>
</div>
</div>
2023-12-28 03:09:36 +08:00
<Teleport to="body">
<VersionsModal v-if="VersionsModalObject" :protocol="VersionsModalObject"
@close="VersionsModalObject = null"
@reloadPage="reloadPage"
@redirectToProtocols="redirectToProtocols"/>
</Teleport>
</template>
<script>
2023-12-28 03:09:36 +08:00
/* global HelperModule */
import InlineEdit from '../shared/inline_edit.vue';
import DropdownSelector from '../shared/legacy/dropdown_selector.vue';
import VersionsModal from '../protocols/modals/versions.vue';
2023-12-28 03:09:36 +08:00
export default {
name: 'ProtocolMetadata',
components: { InlineEdit, DropdownSelector, VersionsModal },
props: {
protocol: {
type: Object,
required: true
}
2023-12-28 03:09:36 +08:00
},
data() {
return {
VersionsModalObject: null,
creatingDraft: false
2023-12-28 03:09:36 +08:00
};
},
computed: {
titleVersion() {
const createdFromVersion = this.protocol.attributes.created_from_version;
2023-12-28 03:09:36 +08:00
if (this.protocol.attributes.published) {
return this.protocol.attributes.version;
}
2023-12-28 03:09:36 +08:00
if (!createdFromVersion) {
return this.i18n.t('protocols.draft');
}
2023-12-28 03:09:36 +08:00
return this.i18n.t('protocols.header.draft_with_from_version', { nr: createdFromVersion });
}
},
methods: {
saveAsdraft() {
if (this.creatingDraft) {
return;
}
this.creatingDraft = true;
2024-03-01 20:37:31 +08:00
$.post(this.protocol.attributes.urls.save_as_draft_url, (result) => {
this.creatingDraft = false;
2024-03-01 20:37:31 +08:00
window.location.replace(result.url);
}).error(() => {
this.creatingDraft = false;
HelperModule.flashAlertMsg(this.i18n.t('errors.general'));
2024-03-01 20:37:31 +08:00
});
},
2023-12-28 03:09:36 +08:00
updateAuthors(authors) {
$.ajax({
type: 'PATCH',
url: this.protocol.attributes.urls.update_protocol_authors_url,
data: { protocol: { authors } },
success: (result) => {
this.$emit('update', result.data.attributes);
},
error: (data) => {
let message;
if (data.responseJSON) {
message = Object.values(data.responseJSON).join(', ');
} else {
message = this.i18n.t('errors.general');
}
2023-12-28 03:09:36 +08:00
HelperModule.flashAlertMsg(message);
}
});
},
updateKeywords(keywords) {
const uniqueKeywords = [...new Set(keywords.map((kw) => kw.trim()).filter((kw) => !!kw))];
2023-12-28 03:09:36 +08:00
$.ajax({
type: 'PATCH',
url: this.protocol.attributes.urls.update_protocol_keywords_url,
data: { keywords: uniqueKeywords },
2023-12-28 03:09:36 +08:00
success: (result) => {
this.$emit('update', result.data.attributes);
}
});
},
openVersionsModal() {
this.VersionsModalObject = {
id: this.protocol.id,
2024-02-28 19:42:31 +08:00
name: this.protocol.attributes.name,
2023-12-28 03:09:36 +08:00
urls: {
versions_modal: this.protocol.attributes.urls.versions_modal
}
};
},
reloadPage() {
window.location.reload();
},
redirectToProtocols() {
window.location.href = this.protocol.attributes.urls.redirect_to_protocols;
}
}
2023-12-28 03:09:36 +08:00
};
</script>