mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-04-16 10:59:31 +00:00
Add lock removal functionality to IsCurrentlyEdited component
- Added a button to forcefully remove WebDAV locks with confirmation and toast notifications. - Introduced a `remove_lock` helper function and updated corresponding TypeScript imports. - Enhanced French translations with new keys for lock removal messages and better wording. - Adjusted display logic to show short lock status messages in the dropdown.
This commit is contained in:
@@ -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<Date|null>(() => 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<void> {
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -43,14 +72,19 @@ const openModal = function() {
|
||||
<p v-if="props.storedObject.lock.users.length > 0">{{ trans(STORED_OBJECT_LOCK_IS_CURRENTLY_EDITED, {byUsers: localizeList(props.storedObject.lock.users.map((u: User) => u.label))} ) }}.<template v-if="props.storedObject.lock.method === 'wopi'"> {{ trans(STORED_OBJECT_LOCK_LIST_OF_USERS_MAY_BE_INCOMPLETE) }}</template></p>
|
||||
<p v-else>{{ trans(STORED_OBJECT_LOCK_IS_CURRENTLY_EDITED_WITHOUT_USERS) }}</p>
|
||||
<p v-if="sinceDate !== null">{{ trans(STORED_OBJECT_LOCK_EDITING_SINCE, {since: sinceDate}) }}</p>
|
||||
|
||||
<div v-if="props.storedObject._permissions.canEdit && props.storedObject.lock.method === 'webdav'" class="alert alert-danger">
|
||||
<p><i class="bi bi-exclamation-lg"></i>{{ trans(STORED_OBJECT_LOCK_FORCE_REMOVE_LOCK_POSSIBLE_EXPLAIN) }}</p>
|
||||
<button class="btn btn-delete" @click="removeLock">{{ trans(STORED_OBJECT_LOCK_FORCE_REMOVE_LOCK) }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</modal>
|
||||
</teleport>
|
||||
<button class="dropdown-item" type="button" @click="openModal()">
|
||||
<span class="currently-edited"><currently-editing-icon></currently-editing-icon></span>
|
||||
<span v-if="props.storedObject.lock.users.length > 0">{{ trans(STORED_OBJECT_LOCK_IS_CURRENTLY_EDITED, {byUsers: localizeList([props.storedObject.lock.users[0].label]) } ) }}<span v-if="props.storedObject.lock.users.length > 1"> (+{{ props.storedObject.lock.users.length - 1 }})</span></span>
|
||||
<span v-else>{{ trans(STORED_OBJECT_LOCK_IS_CURRENTLY_EDITED_WITHOUT_USERS) }}</span>
|
||||
<span v-if="props.storedObject.lock.users.length > 0">{{ trans(STORED_OBJECT_LOCK_IS_CURRENTLY_EDITED_SHORT, {byUsers: localizeList([props.storedObject.lock.users[0].label]) } ) }}<span v-if="props.storedObject.lock.users.length > 1"> (+{{ props.storedObject.lock.users.length - 1 }})</span></span>
|
||||
<span v-else>{{ trans(STORED_OBJECT_LOCK_IS_CURRENTLY_EDITED_WITHOUT_USERS_SHORT) }}</span>
|
||||
</button>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -264,6 +264,21 @@ async function is_object_ready(
|
||||
return await new_status_response.json();
|
||||
}
|
||||
|
||||
async function remove_lock(storedObject: StoredObject): Promise<void> {
|
||||
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,
|
||||
};
|
||||
|
||||
@@ -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é
|
||||
|
||||
|
||||
Reference in New Issue
Block a user