diff --git a/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/StoredObjectButton/IsCurrentlyEdited.vue b/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/StoredObjectButton/IsCurrentlyEdited.vue index 3228a8a52..ba8352278 100644 --- a/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/StoredObjectButton/IsCurrentlyEdited.vue +++ b/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/StoredObjectButton/IsCurrentlyEdited.vue @@ -6,12 +6,22 @@ import Modal from "ChillMainAssets/vuejs/_components/Modal.vue"; import {computed, reactive} from "vue"; import {localizeList} from "ChillMainAssets/lib/localizationHelper/localizationHelper"; import {User} from "ChillMainAssets/types"; -import {STORED_OBJECT_LOCK_IS_CURRENTLY_EDITED, +import { + STORED_OBJECT_LOCK_IS_CURRENTLY_EDITED, STORED_OBJECT_LOCK_IS_CURRENTLY_EDITED_WITHOUT_USERS, + STORED_OBJECT_LOCK_IS_CURRENTLY_EDITED_SHORT, + STORED_OBJECT_LOCK_IS_CURRENTLY_EDITED_WITHOUT_USERS_SHORT, STORED_OBJECT_LOCK_EDITING_SINCE, STORED_OBJECT_LOCK_LIST_OF_USERS_MAY_BE_INCOMPLETE, + STORED_OBJECT_LOCK_FORCE_REMOVE_LOCK, + STORED_OBJECT_LOCK_FORCE_REMOVE_LOCK_POSSIBLE_EXPLAIN, + STORED_OBJECT_LOCK_FORCE_REMOVE_LOCK_WARNING, + STORED_OBJECT_LOCK_REMOVE_LOCK_FAILURE, + STORED_OBJECT_LOCK_REMOVE_LOCK_SUCCESS, trans} from "translator"; import {ISOToDatetime} from "ChillMainAssets/chill/js/date"; +import {remove_lock} from "ChillDocStoreAssets/vuejs/StoredObjectButton/helpers"; +import {useToast} from "vue-toast-notification"; interface IsCurrentlyEditedConfig { storedObject: StoredObject & {lock: StoredObjectLock} @@ -23,16 +33,35 @@ const state = reactive({ modalOpened: false, }); +const toast = useToast(); + const sinceDate = computed(() => ISOToDatetime(props.storedObject.lock.createdAt.datetime)) -const onModalClose = function() { +const onModalClose = function(): void { state.modalOpened = false; } -const openModal = function() { +const openModal = function(): void { state.modalOpened = true; } +const removeLock = async function (): Promise { + if (window.confirm(trans(STORED_OBJECT_LOCK_FORCE_REMOVE_LOCK_WARNING, {nb: props.storedObject.lock.users.length}))) { + try { + await remove_lock(props.storedObject); + } catch (e: unknown) { + toast.error(trans(STORED_OBJECT_LOCK_REMOVE_LOCK_FAILURE, {status: (e as Error).toString()})); + + return Promise.reject(e); + } + toast.success(trans(STORED_OBJECT_LOCK_REMOVE_LOCK_SUCCESS)); + + return Promise.resolve(); + } else { + console.log('User did not confirmed edit'); + } +} + diff --git a/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/StoredObjectButton/helpers.ts b/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/StoredObjectButton/helpers.ts index 8dbad34b7..2981377ef 100644 --- a/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/StoredObjectButton/helpers.ts +++ b/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/StoredObjectButton/helpers.ts @@ -264,6 +264,21 @@ async function is_object_ready( return await new_status_response.json(); } +async function remove_lock(storedObject: StoredObject): Promise { + const remove_lock_response = await window.fetch( + `/api/1.0/doc-store/stored-object/${storedObject.uuid}/lock`, + {method: 'DELETE'} + ) + + if (remove_lock_response.ok) { + return Promise.resolve(); + } else if (remove_lock_response.status === 412) { + return Promise.resolve(); + } else { + throw new Error("Could not remove lock: status code: " + remove_lock_response.status + ' message: ' + remove_lock_response.statusText); + } +} + export { build_convert_link, build_wopi_editor_link, @@ -274,4 +289,5 @@ export { is_extension_editable, is_extension_viewable, is_object_ready, + remove_lock, }; diff --git a/src/Bundle/ChillDocStoreBundle/translations/messages+intl-icu.fr.yml b/src/Bundle/ChillDocStoreBundle/translations/messages+intl-icu.fr.yml index 3ad9bc2d6..577ef2ae0 100644 --- a/src/Bundle/ChillDocStoreBundle/translations/messages+intl-icu.fr.yml +++ b/src/Bundle/ChillDocStoreBundle/translations/messages+intl-icu.fr.yml @@ -11,9 +11,21 @@ workflow: stored_object: lock: - is_currently_edited: Le document est en cours d'édition par {byUsers} - is_currently_edited_without_users: Le document est en cours d'édition + is_currently_edited: Le document est en cours d'édition par {byUsers}, un verrou est placé sur le document. + is_currently_edited_short: Le document est en cours d'édition par {byUsers} + is_currently_edited_without_users: Le document est en cours d'édition, un verrou est placé sur le document. + is_currently_edited_without_users_short: Le document est en cours d'édition list_of_users_may_be_incomplete: La liste des utilisateurs mentionné peut être incomplète. editing_since: > L'édition a débuté le {since, date, long} à {since, time, short} + force_remove_lock_possible_explain: Vous pouvez supprimer le verrou à l'édition. Les modifications apportées par l'utilisateur pourront être perdues. Veuillez le contacter au préalable. + force_remove_lock: Supprimer le verrou à l'édition + force_remove_lock_warning: >- + J'ai pris contact avec {nb, plural, + =0 {l'utilisateur} + one {l'utilisateur} + other {les utilisateurs} + }, et je confirme vouloir supprimer le verrou à l'édition. + remove_lock_failure: 'Le verrou n''a pas pu être supprimé: {status}' + remove_lock_success: Le verrou a été supprimé