2024-09-17 21:19:44 +08:00
|
|
|
<template>
|
|
|
|
<div ref="modal" @keydown.esc="close" class="modal" tabindex="-1" role="dialog">
|
|
|
|
<div class="modal-dialog" role="document">
|
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
|
|
|
<button @click="close" type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="sn-icon sn-icon-close"></i></button>
|
|
|
|
<h4 class="modal-title">
|
|
|
|
{{ i18n.t("assets.file_versions_modal.title") }}
|
|
|
|
</h4>
|
|
|
|
</div>
|
|
|
|
<div class="modal-body">
|
2024-09-18 19:51:03 +08:00
|
|
|
<div class="relative" v-if="fileVersions">
|
|
|
|
<div v-for="(fileVersion, index) in fileVersions" :key="fileVersion.id">
|
|
|
|
<div class="flex w-full border border-sn-light-grey rounded mb-1.5 p-1.5 items-center">
|
|
|
|
<div class="basis-3/4">
|
|
|
|
<div class="mb-1.5">
|
|
|
|
<span v-if="fileVersion.attributes.version === 1" class="bg-sn-science-blue text-sn-white me-2 px-2 py-0.5 rounded">
|
|
|
|
{{ i18n.t("assets.file_versions_modal.original_file") }}
|
|
|
|
</span>
|
|
|
|
<span v-else class="bg-sn-grey-300 me-2 px-2 py-0.5 rounded">v{{ fileVersion.attributes.version }}</span>
|
|
|
|
<a :href="fileVersion.attributes.url" target="_blank">{{ fileVersion.attributes.filename }}</a>
|
|
|
|
<small class="inline-block ml-1" v-if="fileVersion.attributes.restored_from_version">
|
|
|
|
({{ i18n.t("assets.file_versions_modal.restored_from_version", { version: fileVersion.attributes.restored_from_version }) }})
|
|
|
|
</small>
|
|
|
|
</div>
|
|
|
|
<div class="flex text-xs text-sn-grey justify-start">
|
|
|
|
<div class="mr-3">{{ fileVersion.attributes.created_at }}</div>
|
|
|
|
<div class="mr-3">{{ fileVersion.attributes.created_by.full_name }}</div>
|
|
|
|
<div>{{ Math.round(fileVersion.attributes.byte_size/1024) }}KB</div>
|
|
|
|
</div>
|
2024-09-17 21:19:44 +08:00
|
|
|
</div>
|
|
|
|
|
2024-09-18 19:51:03 +08:00
|
|
|
<div class="basis-1/4 flex justify-end">
|
|
|
|
<a class="btn btn-icon p-0 mr-3"đ
|
|
|
|
v-if="enabled || index === 0"
|
|
|
|
:href="fileVersion.attributes.url"
|
|
|
|
target="_blank"
|
|
|
|
data-render-tooltip="true"
|
|
|
|
:title="i18n.t('assets.file_versions_modal.download')"
|
|
|
|
>
|
|
|
|
<i class="sn-icon sn-icon-export"></i>
|
|
|
|
</a>
|
|
|
|
<a v-if="restoreVersionUrl && index !== 0"
|
|
|
|
@click="restoreVersion(fileVersion.attributes.version)"
|
|
|
|
data-render-tooltip="true"
|
|
|
|
:title="i18n.t('assets.file_versions_modal.restore')"
|
|
|
|
class="btn btn-icon p-0 mr-3"
|
|
|
|
>
|
|
|
|
<i class="sn-icon sn-icon-restore"></i>
|
|
|
|
</a>
|
|
|
|
</div>
|
2024-09-17 21:19:44 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2024-09-18 19:51:03 +08:00
|
|
|
<div v-if="!enabled" class="absolute bottom-0 w-full h-[150px] bg-gradient-to-t from-white to-transparent"></div>
|
2024-09-17 21:19:44 +08:00
|
|
|
</div>
|
|
|
|
<div v-else class="sci-loader"></div>
|
2024-09-18 19:51:03 +08:00
|
|
|
<div v-if="!enabled" class="bg-sn-super-light-blue p-4 rounded flex items-start">
|
|
|
|
<div class="mr-2">
|
|
|
|
<i class="sn-icon sn-icon-upgrade"></i>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<h3 class="mt-1 mb-2">{{ i18n.t('assets.file_versions_modal.title') }}</h3>
|
|
|
|
{{ i18n.t('assets.file_versions_modal.disabled_disclaimer') }}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="modal-footer">
|
|
|
|
<button type='button' class='btn btn-secondary' @click="close">
|
|
|
|
{{ i18n.t('general.cancel') }}
|
|
|
|
</button>
|
|
|
|
<a v-if="!enabled" :href="enableUrl" class='btn btn-primary' target="_blank">
|
|
|
|
{{ i18n.t('assets.file_versions_modal.enable_button') }}
|
|
|
|
</a>
|
2024-09-17 21:19:44 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import modalMixin from './modal_mixin';
|
|
|
|
import axios from '../../packs/custom_axios';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'FileVersionsModal',
|
|
|
|
props: {
|
2024-09-17 22:26:45 +08:00
|
|
|
versionsUrl: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
restoreVersionUrl: {
|
2024-09-17 21:19:44 +08:00
|
|
|
type: String,
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mixins: [modalMixin],
|
|
|
|
data() {
|
|
|
|
return {
|
2024-09-18 19:51:03 +08:00
|
|
|
fileVersions: null,
|
|
|
|
enabled: null,
|
|
|
|
enableUrl: null
|
2024-09-17 21:19:44 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
created() {
|
2024-09-17 22:26:45 +08:00
|
|
|
this.loadVersions();
|
|
|
|
},
|
2024-09-18 19:51:03 +08:00
|
|
|
beforeUnmount() {
|
|
|
|
document.querySelectorAll('[data-render-tooltip]').forEach((e) => {
|
|
|
|
window.destroyTooltip(e);
|
|
|
|
});
|
|
|
|
},
|
2024-09-17 22:26:45 +08:00
|
|
|
methods: {
|
|
|
|
loadVersions() {
|
|
|
|
axios.get(this.versionsUrl).then((response) => {
|
|
|
|
this.fileVersions = response.data.data;
|
2024-09-18 19:51:03 +08:00
|
|
|
this.enabled = response.data.enabled;
|
|
|
|
this.enableUrl = response.data.enable_url;
|
|
|
|
this.$nextTick(() => {
|
|
|
|
document.querySelectorAll('[data-render-tooltip]').forEach((e) => {
|
|
|
|
window.initTooltip(e);
|
|
|
|
});
|
|
|
|
});
|
2024-09-17 22:26:45 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
restoreVersion(version) {
|
|
|
|
axios.post(this.restoreVersionUrl, { version: version }).then(() => {
|
|
|
|
this.loadVersions();
|
|
|
|
this.$emit('fileVersionRestored');
|
|
|
|
});
|
|
|
|
}
|
2024-09-17 21:19:44 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|