mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-07 15:25:00 +00:00
Ajout de commentaires supplémentaires aux motifs
This commit is contained in:
@@ -6,20 +6,20 @@ const algo = "AES-CBC";
|
||||
const URL_POST = "/asyncupload/temp_url/generate/post";
|
||||
|
||||
const keyDefinition = {
|
||||
name: algo,
|
||||
length: 256,
|
||||
name: algo,
|
||||
length: 256,
|
||||
};
|
||||
|
||||
const createFilename = (): string => {
|
||||
let text = "";
|
||||
const possible =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
let text = "";
|
||||
const possible =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
|
||||
for (let i = 0; i < 7; i++) {
|
||||
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
||||
}
|
||||
for (let i = 0; i < 7; i++) {
|
||||
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
||||
}
|
||||
|
||||
return text;
|
||||
return text;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -30,59 +30,59 @@ const createFilename = (): string => {
|
||||
* @returns {Promise<StoredObject>} A Promise that resolves to the newly created StoredObject.
|
||||
*/
|
||||
export const fetchNewStoredObject = async (): Promise<StoredObject> => {
|
||||
return makeFetch("POST", "/api/1.0/doc-store/stored-object/create", null);
|
||||
return makeFetch("POST", "/api/1.0/doc-store/stored-object/create", null);
|
||||
};
|
||||
|
||||
export const uploadVersion = async (
|
||||
uploadFile: ArrayBuffer,
|
||||
storedObject: StoredObject,
|
||||
uploadFile: ArrayBuffer,
|
||||
storedObject: StoredObject,
|
||||
): Promise<string> => {
|
||||
const params = new URLSearchParams();
|
||||
params.append("expires_delay", "180");
|
||||
params.append("submit_delay", "180");
|
||||
const asyncData: PostStoreObjectSignature = await makeFetch(
|
||||
"GET",
|
||||
`/api/1.0/doc-store/async-upload/temp_url/${storedObject.uuid}/generate/post` +
|
||||
"?" +
|
||||
params.toString(),
|
||||
);
|
||||
const suffix = createFilename();
|
||||
const filename = asyncData.prefix + suffix;
|
||||
const formData = new FormData();
|
||||
formData.append("redirect", asyncData.redirect);
|
||||
formData.append("max_file_size", asyncData.max_file_size.toString());
|
||||
formData.append("max_file_count", asyncData.max_file_count.toString());
|
||||
formData.append("expires", asyncData.expires.toString());
|
||||
formData.append("signature", asyncData.signature);
|
||||
formData.append(filename, new Blob([uploadFile]), suffix);
|
||||
const params = new URLSearchParams();
|
||||
params.append("expires_delay", "180");
|
||||
params.append("submit_delay", "180");
|
||||
const asyncData: PostStoreObjectSignature = await makeFetch(
|
||||
"GET",
|
||||
`/api/1.0/doc-store/async-upload/temp_url/${storedObject.uuid}/generate/post` +
|
||||
"?" +
|
||||
params.toString(),
|
||||
);
|
||||
const suffix = createFilename();
|
||||
const filename = asyncData.prefix + suffix;
|
||||
const formData = new FormData();
|
||||
formData.append("redirect", asyncData.redirect);
|
||||
formData.append("max_file_size", asyncData.max_file_size.toString());
|
||||
formData.append("max_file_count", asyncData.max_file_count.toString());
|
||||
formData.append("expires", asyncData.expires.toString());
|
||||
formData.append("signature", asyncData.signature);
|
||||
formData.append(filename, new Blob([uploadFile]), suffix);
|
||||
|
||||
const response = await window.fetch(asyncData.url, {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
});
|
||||
const response = await window.fetch(asyncData.url, {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
console.error("Error while sending file to store", response);
|
||||
throw new Error(response.statusText);
|
||||
}
|
||||
if (!response.ok) {
|
||||
console.error("Error while sending file to store", response);
|
||||
throw new Error(response.statusText);
|
||||
}
|
||||
|
||||
return Promise.resolve(filename);
|
||||
return Promise.resolve(filename);
|
||||
};
|
||||
|
||||
export const encryptFile = async (
|
||||
originalFile: ArrayBuffer,
|
||||
originalFile: ArrayBuffer,
|
||||
): Promise<[ArrayBuffer, Uint8Array, JsonWebKey]> => {
|
||||
const iv = crypto.getRandomValues(new Uint8Array(16));
|
||||
const key = await window.crypto.subtle.generateKey(keyDefinition, true, [
|
||||
"encrypt",
|
||||
"decrypt",
|
||||
]);
|
||||
const exportedKey = await window.crypto.subtle.exportKey("jwk", key);
|
||||
const encrypted = await window.crypto.subtle.encrypt(
|
||||
{ name: algo, iv: iv },
|
||||
key,
|
||||
originalFile,
|
||||
);
|
||||
const iv = crypto.getRandomValues(new Uint8Array(16));
|
||||
const key = await window.crypto.subtle.generateKey(keyDefinition, true, [
|
||||
"encrypt",
|
||||
"decrypt",
|
||||
]);
|
||||
const exportedKey = await window.crypto.subtle.exportKey("jwk", key);
|
||||
const encrypted = await window.crypto.subtle.encrypt(
|
||||
{ name: algo, iv: iv },
|
||||
key,
|
||||
originalFile,
|
||||
);
|
||||
|
||||
return Promise.resolve([encrypted, iv, exportedKey]);
|
||||
return Promise.resolve([encrypted, iv, exportedKey]);
|
||||
};
|
||||
|
@@ -2,9 +2,9 @@ import { fetchResults } from "ChillMainAssets/lib/api/apiMethods";
|
||||
import { GenericDocForAccompanyingPeriod } from "ChillDocStoreAssets/types/generic_doc";
|
||||
|
||||
export function fetch_generic_docs_by_accompanying_period(
|
||||
periodId: number,
|
||||
periodId: number,
|
||||
): Promise<GenericDocForAccompanyingPeriod[]> {
|
||||
return fetchResults(
|
||||
`/api/1.0/doc-store/generic-doc/by-period/${periodId}/index`,
|
||||
);
|
||||
return fetchResults(
|
||||
`/api/1.0/doc-store/generic-doc/by-period/${periodId}/index`,
|
||||
);
|
||||
}
|
||||
|
@@ -6,117 +6,116 @@ import { _createI18n } from "../../../../../ChillMainBundle/Resources/public/vue
|
||||
const i18n = _createI18n({});
|
||||
|
||||
const startApp = (
|
||||
divElement: HTMLDivElement,
|
||||
collectionEntry: null | HTMLLIElement,
|
||||
divElement: HTMLDivElement,
|
||||
collectionEntry: null | HTMLLIElement,
|
||||
): void => {
|
||||
console.log("app started", divElement);
|
||||
console.log("app started", divElement);
|
||||
|
||||
const inputTitle = collectionEntry?.querySelector("input[type='text']");
|
||||
const inputTitle = collectionEntry?.querySelector("input[type='text']");
|
||||
|
||||
const input_stored_object: HTMLInputElement | null =
|
||||
divElement.querySelector("input[data-stored-object]");
|
||||
if (null === input_stored_object) {
|
||||
throw new Error("input to stored object not found");
|
||||
}
|
||||
const input_stored_object: HTMLInputElement | null = divElement.querySelector(
|
||||
"input[data-stored-object]",
|
||||
);
|
||||
if (null === input_stored_object) {
|
||||
throw new Error("input to stored object not found");
|
||||
}
|
||||
|
||||
let existingDoc: StoredObject | null = null;
|
||||
if (input_stored_object.value !== "") {
|
||||
existingDoc = JSON.parse(input_stored_object.value);
|
||||
}
|
||||
const app_container = document.createElement("div");
|
||||
divElement.appendChild(app_container);
|
||||
let existingDoc: StoredObject | null = null;
|
||||
if (input_stored_object.value !== "") {
|
||||
existingDoc = JSON.parse(input_stored_object.value);
|
||||
}
|
||||
const app_container = document.createElement("div");
|
||||
divElement.appendChild(app_container);
|
||||
|
||||
const app = createApp({
|
||||
template:
|
||||
'<drop-file-widget :existingDoc="this.$data.existingDoc" :allowRemove="true" @addDocument="this.addDocument" @removeDocument="removeDocument"></drop-file-widget>',
|
||||
data() {
|
||||
return {
|
||||
existingDoc: existingDoc,
|
||||
inputTitle: inputTitle,
|
||||
};
|
||||
},
|
||||
components: {
|
||||
DropFileWidget,
|
||||
},
|
||||
methods: {
|
||||
addDocument: function ({
|
||||
stored_object,
|
||||
stored_object_version,
|
||||
file_name,
|
||||
}: {
|
||||
stored_object: StoredObject;
|
||||
stored_object_version: StoredObjectVersion;
|
||||
file_name: string;
|
||||
}): void {
|
||||
stored_object.title = file_name;
|
||||
console.log("object added", stored_object);
|
||||
console.log("version added", stored_object_version);
|
||||
this.$data.existingDoc = stored_object;
|
||||
this.$data.existingDoc.currentVersion = stored_object_version;
|
||||
input_stored_object.value = JSON.stringify(
|
||||
this.$data.existingDoc,
|
||||
);
|
||||
if (this.$data.inputTitle) {
|
||||
if (!this.$data.inputTitle?.value) {
|
||||
this.$data.inputTitle.value = file_name;
|
||||
}
|
||||
}
|
||||
},
|
||||
removeDocument: function (object: StoredObject): void {
|
||||
console.log("catch remove document", object);
|
||||
input_stored_object.value = "";
|
||||
this.$data.existingDoc = undefined;
|
||||
console.log("collectionEntry", collectionEntry);
|
||||
const app = createApp({
|
||||
template:
|
||||
'<drop-file-widget :existingDoc="this.$data.existingDoc" :allowRemove="true" @addDocument="this.addDocument" @removeDocument="removeDocument"></drop-file-widget>',
|
||||
data() {
|
||||
return {
|
||||
existingDoc: existingDoc,
|
||||
inputTitle: inputTitle,
|
||||
};
|
||||
},
|
||||
components: {
|
||||
DropFileWidget,
|
||||
},
|
||||
methods: {
|
||||
addDocument: function ({
|
||||
stored_object,
|
||||
stored_object_version,
|
||||
file_name,
|
||||
}: {
|
||||
stored_object: StoredObject;
|
||||
stored_object_version: StoredObjectVersion;
|
||||
file_name: string;
|
||||
}): void {
|
||||
stored_object.title = file_name;
|
||||
console.log("object added", stored_object);
|
||||
console.log("version added", stored_object_version);
|
||||
this.$data.existingDoc = stored_object;
|
||||
this.$data.existingDoc.currentVersion = stored_object_version;
|
||||
input_stored_object.value = JSON.stringify(this.$data.existingDoc);
|
||||
if (this.$data.inputTitle) {
|
||||
if (!this.$data.inputTitle?.value) {
|
||||
this.$data.inputTitle.value = file_name;
|
||||
}
|
||||
}
|
||||
},
|
||||
removeDocument: function (object: StoredObject): void {
|
||||
console.log("catch remove document", object);
|
||||
input_stored_object.value = "";
|
||||
this.$data.existingDoc = undefined;
|
||||
console.log("collectionEntry", collectionEntry);
|
||||
|
||||
if (null !== collectionEntry) {
|
||||
console.log("will remove collection");
|
||||
collectionEntry.remove();
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
if (null !== collectionEntry) {
|
||||
console.log("will remove collection");
|
||||
collectionEntry.remove();
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
app.use(i18n).mount(app_container);
|
||||
app.use(i18n).mount(app_container);
|
||||
};
|
||||
window.addEventListener("collection-add-entry", ((
|
||||
e: CustomEvent<CollectionEventPayload>,
|
||||
e: CustomEvent<CollectionEventPayload>,
|
||||
) => {
|
||||
const detail = e.detail;
|
||||
const divElement: null | HTMLDivElement = detail.entry.querySelector(
|
||||
"div[data-stored-object]",
|
||||
);
|
||||
const detail = e.detail;
|
||||
const divElement: null | HTMLDivElement = detail.entry.querySelector(
|
||||
"div[data-stored-object]",
|
||||
);
|
||||
|
||||
if (null === divElement) {
|
||||
throw new Error("div[data-stored-object] not found");
|
||||
}
|
||||
if (null === divElement) {
|
||||
throw new Error("div[data-stored-object] not found");
|
||||
}
|
||||
|
||||
startApp(divElement, detail.entry);
|
||||
startApp(divElement, detail.entry);
|
||||
}) as EventListener);
|
||||
|
||||
window.addEventListener("DOMContentLoaded", () => {
|
||||
const upload_inputs: NodeListOf<HTMLDivElement> = document.querySelectorAll(
|
||||
"div[data-stored-object]",
|
||||
);
|
||||
const upload_inputs: NodeListOf<HTMLDivElement> = document.querySelectorAll(
|
||||
"div[data-stored-object]",
|
||||
);
|
||||
|
||||
upload_inputs.forEach((input: HTMLDivElement): void => {
|
||||
// test for a parent to check if this is a collection entry
|
||||
let collectionEntry: null | HTMLLIElement = null;
|
||||
const parent = input.parentElement;
|
||||
console.log("parent", parent);
|
||||
if (null !== parent) {
|
||||
const grandParent = parent.parentElement;
|
||||
console.log("grandParent", grandParent);
|
||||
if (null !== grandParent) {
|
||||
if (
|
||||
grandParent.tagName.toLowerCase() === "li" &&
|
||||
grandParent.classList.contains("entry")
|
||||
) {
|
||||
collectionEntry = grandParent as HTMLLIElement;
|
||||
}
|
||||
}
|
||||
upload_inputs.forEach((input: HTMLDivElement): void => {
|
||||
// test for a parent to check if this is a collection entry
|
||||
let collectionEntry: null | HTMLLIElement = null;
|
||||
const parent = input.parentElement;
|
||||
console.log("parent", parent);
|
||||
if (null !== parent) {
|
||||
const grandParent = parent.parentElement;
|
||||
console.log("grandParent", grandParent);
|
||||
if (null !== grandParent) {
|
||||
if (
|
||||
grandParent.tagName.toLowerCase() === "li" &&
|
||||
grandParent.classList.contains("entry")
|
||||
) {
|
||||
collectionEntry = grandParent as HTMLLIElement;
|
||||
}
|
||||
startApp(input, collectionEntry);
|
||||
});
|
||||
}
|
||||
}
|
||||
startApp(input, collectionEntry);
|
||||
});
|
||||
});
|
||||
|
||||
export {};
|
||||
|
@@ -9,26 +9,26 @@ import ToastPlugin from "vue-toast-notification";
|
||||
const i18n = _createI18n({});
|
||||
|
||||
window.addEventListener("DOMContentLoaded", function (e) {
|
||||
document
|
||||
.querySelectorAll<HTMLDivElement>("div[data-download-button-single]")
|
||||
.forEach((el) => {
|
||||
const storedObject = JSON.parse(
|
||||
el.dataset.storedObject as string,
|
||||
) as StoredObject;
|
||||
const title = el.dataset.title as string;
|
||||
const app = createApp({
|
||||
components: { DownloadButton },
|
||||
data() {
|
||||
return {
|
||||
storedObject,
|
||||
title,
|
||||
classes: { btn: true, "btn-outline-primary": true },
|
||||
};
|
||||
},
|
||||
template:
|
||||
'<download-button :stored-object="storedObject" :at-version="storedObject.currentVersion" :classes="classes" :filename="title" :direct-download="true"></download-button>',
|
||||
});
|
||||
document
|
||||
.querySelectorAll<HTMLDivElement>("div[data-download-button-single]")
|
||||
.forEach((el) => {
|
||||
const storedObject = JSON.parse(
|
||||
el.dataset.storedObject as string,
|
||||
) as StoredObject;
|
||||
const title = el.dataset.title as string;
|
||||
const app = createApp({
|
||||
components: { DownloadButton },
|
||||
data() {
|
||||
return {
|
||||
storedObject,
|
||||
title,
|
||||
classes: { btn: true, "btn-outline-primary": true },
|
||||
};
|
||||
},
|
||||
template:
|
||||
'<download-button :stored-object="storedObject" :at-version="storedObject.currentVersion" :classes="classes" :filename="title" :direct-download="true"></download-button>',
|
||||
});
|
||||
|
||||
app.use(i18n).use(ToastPlugin).mount(el);
|
||||
});
|
||||
app.use(i18n).use(ToastPlugin).mount(el);
|
||||
});
|
||||
});
|
||||
|
@@ -8,66 +8,66 @@ import ToastPlugin from "vue-toast-notification";
|
||||
const i18n = _createI18n({});
|
||||
|
||||
window.addEventListener("DOMContentLoaded", function (e) {
|
||||
document
|
||||
.querySelectorAll<HTMLDivElement>("div[data-download-buttons]")
|
||||
.forEach((el) => {
|
||||
const app = createApp({
|
||||
components: { DocumentActionButtonsGroup },
|
||||
data() {
|
||||
const datasets = el.dataset as {
|
||||
filename: string;
|
||||
canEdit: string;
|
||||
storedObject: string;
|
||||
buttonSmall: string;
|
||||
davLink: string;
|
||||
davLinkExpiration: string;
|
||||
};
|
||||
document
|
||||
.querySelectorAll<HTMLDivElement>("div[data-download-buttons]")
|
||||
.forEach((el) => {
|
||||
const app = createApp({
|
||||
components: { DocumentActionButtonsGroup },
|
||||
data() {
|
||||
const datasets = el.dataset as {
|
||||
filename: string;
|
||||
canEdit: string;
|
||||
storedObject: string;
|
||||
buttonSmall: string;
|
||||
davLink: string;
|
||||
davLinkExpiration: string;
|
||||
};
|
||||
|
||||
const storedObject = JSON.parse(
|
||||
datasets.storedObject,
|
||||
) as StoredObject,
|
||||
filename = datasets.filename,
|
||||
canEdit = datasets.canEdit === "1",
|
||||
small = datasets.buttonSmall === "1",
|
||||
davLink =
|
||||
"davLink" in datasets && datasets.davLink !== ""
|
||||
? datasets.davLink
|
||||
: null,
|
||||
davLinkExpiration =
|
||||
"davLinkExpiration" in datasets
|
||||
? Number.parseInt(datasets.davLinkExpiration)
|
||||
: null;
|
||||
return {
|
||||
storedObject,
|
||||
filename,
|
||||
canEdit,
|
||||
small,
|
||||
davLink,
|
||||
davLinkExpiration,
|
||||
};
|
||||
},
|
||||
template:
|
||||
'<document-action-buttons-group :can-edit="canEdit" :filename="filename" :stored-object="storedObject" :small="small" :dav-link="davLink" :dav-link-expiration="davLinkExpiration" @on-stored-object-status-change="onStoredObjectStatusChange"></document-action-buttons-group>',
|
||||
methods: {
|
||||
onStoredObjectStatusChange: function (
|
||||
newStatus: StoredObjectStatusChange,
|
||||
): void {
|
||||
this.$data.storedObject.status = newStatus.status;
|
||||
this.$data.storedObject.filename = newStatus.filename;
|
||||
this.$data.storedObject.type = newStatus.type;
|
||||
const storedObject = JSON.parse(
|
||||
datasets.storedObject,
|
||||
) as StoredObject,
|
||||
filename = datasets.filename,
|
||||
canEdit = datasets.canEdit === "1",
|
||||
small = datasets.buttonSmall === "1",
|
||||
davLink =
|
||||
"davLink" in datasets && datasets.davLink !== ""
|
||||
? datasets.davLink
|
||||
: null,
|
||||
davLinkExpiration =
|
||||
"davLinkExpiration" in datasets
|
||||
? Number.parseInt(datasets.davLinkExpiration)
|
||||
: null;
|
||||
return {
|
||||
storedObject,
|
||||
filename,
|
||||
canEdit,
|
||||
small,
|
||||
davLink,
|
||||
davLinkExpiration,
|
||||
};
|
||||
},
|
||||
template:
|
||||
'<document-action-buttons-group :can-edit="canEdit" :filename="filename" :stored-object="storedObject" :small="small" :dav-link="davLink" :dav-link-expiration="davLinkExpiration" @on-stored-object-status-change="onStoredObjectStatusChange"></document-action-buttons-group>',
|
||||
methods: {
|
||||
onStoredObjectStatusChange: function (
|
||||
newStatus: StoredObjectStatusChange,
|
||||
): void {
|
||||
this.$data.storedObject.status = newStatus.status;
|
||||
this.$data.storedObject.filename = newStatus.filename;
|
||||
this.$data.storedObject.type = newStatus.type;
|
||||
|
||||
// remove eventual div which inform pending status
|
||||
document
|
||||
.querySelectorAll(
|
||||
`[data-docgen-is-pending="${this.$data.storedObject.id}"]`,
|
||||
)
|
||||
.forEach(function (el) {
|
||||
el.remove();
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
// remove eventual div which inform pending status
|
||||
document
|
||||
.querySelectorAll(
|
||||
`[data-docgen-is-pending="${this.$data.storedObject.id}"]`,
|
||||
)
|
||||
.forEach(function (el) {
|
||||
el.remove();
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
app.use(i18n).use(ToastPlugin).mount(el);
|
||||
});
|
||||
app.use(i18n).use(ToastPlugin).mount(el);
|
||||
});
|
||||
});
|
||||
|
@@ -2,7 +2,7 @@ import { DateTime } from "ChillMainAssets/types";
|
||||
import { StoredObject } from "ChillDocStoreAssets/types/index";
|
||||
|
||||
export interface GenericDocMetadata {
|
||||
isPresent: boolean;
|
||||
isPresent: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -15,57 +15,57 @@ export interface EmptyMetadata extends GenericDocMetadata {}
|
||||
* Minimal Metadata for a GenericDoc with a normalizer
|
||||
*/
|
||||
export interface BaseMetadata extends GenericDocMetadata {
|
||||
title: string;
|
||||
title: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* A generic doc is a document attached to a Person or an AccompanyingPeriod.
|
||||
*/
|
||||
export interface GenericDoc {
|
||||
type: "doc_store_generic_doc";
|
||||
uniqueKey: string;
|
||||
key: string;
|
||||
identifiers: object;
|
||||
context: "person" | "accompanying-period";
|
||||
doc_date: DateTime;
|
||||
metadata: GenericDocMetadata;
|
||||
storedObject: StoredObject | null;
|
||||
type: "doc_store_generic_doc";
|
||||
uniqueKey: string;
|
||||
key: string;
|
||||
identifiers: object;
|
||||
context: "person" | "accompanying-period";
|
||||
doc_date: DateTime;
|
||||
metadata: GenericDocMetadata;
|
||||
storedObject: StoredObject | null;
|
||||
}
|
||||
|
||||
export interface GenericDocForAccompanyingPeriod extends GenericDoc {
|
||||
context: "accompanying-period";
|
||||
context: "accompanying-period";
|
||||
}
|
||||
|
||||
interface BaseMetadataWithHtml extends BaseMetadata {
|
||||
html: string;
|
||||
html: string;
|
||||
}
|
||||
|
||||
export interface GenericDocForAccompanyingCourseDocument
|
||||
extends GenericDocForAccompanyingPeriod {
|
||||
key: "accompanying_course_document";
|
||||
metadata: BaseMetadataWithHtml;
|
||||
extends GenericDocForAccompanyingPeriod {
|
||||
key: "accompanying_course_document";
|
||||
metadata: BaseMetadataWithHtml;
|
||||
}
|
||||
|
||||
export interface GenericDocForAccompanyingCourseActivityDocument
|
||||
extends GenericDocForAccompanyingPeriod {
|
||||
key: "accompanying_course_activity_document";
|
||||
metadata: BaseMetadataWithHtml;
|
||||
extends GenericDocForAccompanyingPeriod {
|
||||
key: "accompanying_course_activity_document";
|
||||
metadata: BaseMetadataWithHtml;
|
||||
}
|
||||
|
||||
export interface GenericDocForAccompanyingCourseCalendarDocument
|
||||
extends GenericDocForAccompanyingPeriod {
|
||||
key: "accompanying_course_calendar_document";
|
||||
metadata: BaseMetadataWithHtml;
|
||||
extends GenericDocForAccompanyingPeriod {
|
||||
key: "accompanying_course_calendar_document";
|
||||
metadata: BaseMetadataWithHtml;
|
||||
}
|
||||
|
||||
export interface GenericDocForAccompanyingCoursePersonDocument
|
||||
extends GenericDocForAccompanyingPeriod {
|
||||
key: "person_document";
|
||||
metadata: BaseMetadataWithHtml;
|
||||
extends GenericDocForAccompanyingPeriod {
|
||||
key: "person_document";
|
||||
metadata: BaseMetadataWithHtml;
|
||||
}
|
||||
|
||||
export interface GenericDocForAccompanyingCourseWorkEvaluationDocument
|
||||
extends GenericDocForAccompanyingPeriod {
|
||||
key: "accompanying_period_work_evaluation_document";
|
||||
metadata: BaseMetadataWithHtml;
|
||||
extends GenericDocForAccompanyingPeriod {
|
||||
key: "accompanying_period_work_evaluation_document";
|
||||
metadata: BaseMetadataWithHtml;
|
||||
}
|
||||
|
@@ -4,73 +4,73 @@ import { SignedUrlGet } from "ChillDocStoreAssets/vuejs/StoredObjectButton/helpe
|
||||
export type StoredObjectStatus = "empty" | "ready" | "failure" | "pending";
|
||||
|
||||
export interface StoredObject {
|
||||
id: number;
|
||||
title: string | null;
|
||||
uuid: string;
|
||||
prefix: string;
|
||||
status: StoredObjectStatus;
|
||||
currentVersion:
|
||||
| null
|
||||
| StoredObjectVersionCreated
|
||||
| StoredObjectVersionPersisted;
|
||||
totalVersions: number;
|
||||
datas: object;
|
||||
/** @deprecated */
|
||||
creationDate: DateTime;
|
||||
createdAt: DateTime | null;
|
||||
createdBy: User | null;
|
||||
_permissions: {
|
||||
canEdit: boolean;
|
||||
canSee: boolean;
|
||||
};
|
||||
_links?: {
|
||||
dav_link?: {
|
||||
href: string;
|
||||
expiration: number;
|
||||
};
|
||||
downloadLink?: SignedUrlGet;
|
||||
id: number;
|
||||
title: string | null;
|
||||
uuid: string;
|
||||
prefix: string;
|
||||
status: StoredObjectStatus;
|
||||
currentVersion:
|
||||
| null
|
||||
| StoredObjectVersionCreated
|
||||
| StoredObjectVersionPersisted;
|
||||
totalVersions: number;
|
||||
datas: object;
|
||||
/** @deprecated */
|
||||
creationDate: DateTime;
|
||||
createdAt: DateTime | null;
|
||||
createdBy: User | null;
|
||||
_permissions: {
|
||||
canEdit: boolean;
|
||||
canSee: boolean;
|
||||
};
|
||||
_links?: {
|
||||
dav_link?: {
|
||||
href: string;
|
||||
expiration: number;
|
||||
};
|
||||
downloadLink?: SignedUrlGet;
|
||||
};
|
||||
}
|
||||
|
||||
export interface StoredObjectVersion {
|
||||
/**
|
||||
* filename of the object in the object storage
|
||||
*/
|
||||
filename: string;
|
||||
iv: number[];
|
||||
keyInfos: JsonWebKey;
|
||||
type: string;
|
||||
/**
|
||||
* filename of the object in the object storage
|
||||
*/
|
||||
filename: string;
|
||||
iv: number[];
|
||||
keyInfos: JsonWebKey;
|
||||
type: string;
|
||||
}
|
||||
|
||||
export interface StoredObjectVersionCreated extends StoredObjectVersion {
|
||||
persisted: false;
|
||||
persisted: false;
|
||||
}
|
||||
|
||||
export interface StoredObjectVersionPersisted
|
||||
extends StoredObjectVersionCreated {
|
||||
version: number;
|
||||
id: number;
|
||||
createdAt: DateTime | null;
|
||||
createdBy: User | null;
|
||||
extends StoredObjectVersionCreated {
|
||||
version: number;
|
||||
id: number;
|
||||
createdAt: DateTime | null;
|
||||
createdBy: User | null;
|
||||
}
|
||||
|
||||
export interface StoredObjectStatusChange {
|
||||
id: number;
|
||||
filename: string;
|
||||
status: StoredObjectStatus;
|
||||
type: string;
|
||||
id: number;
|
||||
filename: string;
|
||||
status: StoredObjectStatus;
|
||||
type: string;
|
||||
}
|
||||
|
||||
export interface StoredObjectVersionWithPointInTime
|
||||
extends StoredObjectVersionPersisted {
|
||||
"point-in-times": StoredObjectPointInTime[];
|
||||
"from-restored": StoredObjectVersionPersisted | null;
|
||||
extends StoredObjectVersionPersisted {
|
||||
"point-in-times": StoredObjectPointInTime[];
|
||||
"from-restored": StoredObjectVersionPersisted | null;
|
||||
}
|
||||
|
||||
export interface StoredObjectPointInTime {
|
||||
id: number;
|
||||
byUser: User | null;
|
||||
reason: "keep-before-conversion" | "keep-by-user";
|
||||
id: number;
|
||||
byUser: User | null;
|
||||
reason: "keep-before-conversion" | "keep-by-user";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,63 +82,63 @@ export type WopiEditButtonExecutableBeforeLeaveFunction = () => Promise<void>;
|
||||
* Object containing information for performering a POST request to a swift object store
|
||||
*/
|
||||
export interface PostStoreObjectSignature {
|
||||
method: "POST";
|
||||
max_file_size: number;
|
||||
max_file_count: 1;
|
||||
expires: number;
|
||||
submit_delay: 180;
|
||||
redirect: string;
|
||||
prefix: string;
|
||||
url: string;
|
||||
signature: string;
|
||||
method: "POST";
|
||||
max_file_size: number;
|
||||
max_file_count: 1;
|
||||
expires: number;
|
||||
submit_delay: 180;
|
||||
redirect: string;
|
||||
prefix: string;
|
||||
url: string;
|
||||
signature: string;
|
||||
}
|
||||
|
||||
export interface PDFPage {
|
||||
index: number;
|
||||
width: number;
|
||||
height: number;
|
||||
index: number;
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
export interface SignatureZone {
|
||||
index: number | null;
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
PDFPage: PDFPage;
|
||||
index: number | null;
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
PDFPage: PDFPage;
|
||||
}
|
||||
|
||||
export interface Signature {
|
||||
id: number;
|
||||
storedObject: StoredObject;
|
||||
zones: SignatureZone[];
|
||||
id: number;
|
||||
storedObject: StoredObject;
|
||||
zones: SignatureZone[];
|
||||
}
|
||||
|
||||
export type SignedState =
|
||||
| "pending"
|
||||
| "signed"
|
||||
| "rejected"
|
||||
| "canceled"
|
||||
| "error";
|
||||
| "pending"
|
||||
| "signed"
|
||||
| "rejected"
|
||||
| "canceled"
|
||||
| "error";
|
||||
|
||||
export interface CheckSignature {
|
||||
state: SignedState;
|
||||
storedObject: StoredObject;
|
||||
state: SignedState;
|
||||
storedObject: StoredObject;
|
||||
}
|
||||
|
||||
export type CanvasEvent = "select" | "add";
|
||||
|
||||
export interface ZoomLevel {
|
||||
id: number;
|
||||
zoom: number;
|
||||
label: {
|
||||
fr?: string;
|
||||
nl?: string;
|
||||
};
|
||||
id: number;
|
||||
zoom: number;
|
||||
label: {
|
||||
fr?: string;
|
||||
nl?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface GenericDoc {
|
||||
type: "doc_store_generic_doc";
|
||||
key: string;
|
||||
context: "person" | "accompanying-period";
|
||||
doc_date: DateTime;
|
||||
type: "doc_store_generic_doc";
|
||||
key: string;
|
||||
context: "person" | "accompanying-period";
|
||||
doc_date: DateTime;
|
||||
}
|
||||
|
@@ -1,67 +1,65 @@
|
||||
<template>
|
||||
<div v-if="isButtonGroupDisplayable" class="btn-group">
|
||||
<button
|
||||
:class="
|
||||
Object.assign({
|
||||
btn: true,
|
||||
'btn-outline-primary': true,
|
||||
'dropdown-toggle': true,
|
||||
'btn-sm': props.small,
|
||||
})
|
||||
"
|
||||
type="button"
|
||||
data-bs-toggle="dropdown"
|
||||
aria-expanded="false"
|
||||
>
|
||||
Actions
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li v-if="isEditableOnline">
|
||||
<wopi-edit-button
|
||||
:stored-object="props.storedObject"
|
||||
:classes="{ 'dropdown-item': true }"
|
||||
:execute-before-leave="props.executeBeforeLeave"
|
||||
></wopi-edit-button>
|
||||
</li>
|
||||
<li v-if="isEditableOnDesktop">
|
||||
<desktop-edit-button
|
||||
:classes="{ 'dropdown-item': true }"
|
||||
:edit-link="props.davLink"
|
||||
:expiration-link="props.davLinkExpiration"
|
||||
></desktop-edit-button>
|
||||
</li>
|
||||
<li v-if="isConvertibleToPdf">
|
||||
<convert-button
|
||||
:stored-object="props.storedObject"
|
||||
:filename="filename"
|
||||
:classes="{ 'dropdown-item': true }"
|
||||
></convert-button>
|
||||
</li>
|
||||
<li v-if="isDownloadable">
|
||||
<download-button
|
||||
:stored-object="props.storedObject"
|
||||
:at-version="props.storedObject.currentVersion"
|
||||
:filename="filename"
|
||||
:classes="{ 'dropdown-item': true }"
|
||||
:display-action-string-in-button="true"
|
||||
></download-button>
|
||||
</li>
|
||||
<li v-if="isHistoryViewable">
|
||||
<history-button
|
||||
:stored-object="props.storedObject"
|
||||
:can-edit="
|
||||
canEdit && props.storedObject._permissions.canEdit
|
||||
"
|
||||
></history-button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div v-else-if="'pending' === props.storedObject.status">
|
||||
<div class="btn btn-outline-info">Génération en cours</div>
|
||||
</div>
|
||||
<div v-else-if="'failure' === props.storedObject.status">
|
||||
<div class="btn btn-outline-danger">La génération a échoué</div>
|
||||
</div>
|
||||
<div v-if="isButtonGroupDisplayable" class="btn-group">
|
||||
<button
|
||||
:class="
|
||||
Object.assign({
|
||||
btn: true,
|
||||
'btn-outline-primary': true,
|
||||
'dropdown-toggle': true,
|
||||
'btn-sm': props.small,
|
||||
})
|
||||
"
|
||||
type="button"
|
||||
data-bs-toggle="dropdown"
|
||||
aria-expanded="false"
|
||||
>
|
||||
Actions
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li v-if="isEditableOnline">
|
||||
<wopi-edit-button
|
||||
:stored-object="props.storedObject"
|
||||
:classes="{ 'dropdown-item': true }"
|
||||
:execute-before-leave="props.executeBeforeLeave"
|
||||
></wopi-edit-button>
|
||||
</li>
|
||||
<li v-if="isEditableOnDesktop">
|
||||
<desktop-edit-button
|
||||
:classes="{ 'dropdown-item': true }"
|
||||
:edit-link="props.davLink"
|
||||
:expiration-link="props.davLinkExpiration"
|
||||
></desktop-edit-button>
|
||||
</li>
|
||||
<li v-if="isConvertibleToPdf">
|
||||
<convert-button
|
||||
:stored-object="props.storedObject"
|
||||
:filename="filename"
|
||||
:classes="{ 'dropdown-item': true }"
|
||||
></convert-button>
|
||||
</li>
|
||||
<li v-if="isDownloadable">
|
||||
<download-button
|
||||
:stored-object="props.storedObject"
|
||||
:at-version="props.storedObject.currentVersion"
|
||||
:filename="filename"
|
||||
:classes="{ 'dropdown-item': true }"
|
||||
:display-action-string-in-button="true"
|
||||
></download-button>
|
||||
</li>
|
||||
<li v-if="isHistoryViewable">
|
||||
<history-button
|
||||
:stored-object="props.storedObject"
|
||||
:can-edit="canEdit && props.storedObject._permissions.canEdit"
|
||||
></history-button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div v-else-if="'pending' === props.storedObject.status">
|
||||
<div class="btn btn-outline-info">Génération en cours</div>
|
||||
</div>
|
||||
<div v-else-if="'failure' === props.storedObject.status">
|
||||
<div class="btn btn-outline-danger">La génération a échoué</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
@@ -70,68 +68,66 @@ import ConvertButton from "./StoredObjectButton/ConvertButton.vue";
|
||||
import DownloadButton from "./StoredObjectButton/DownloadButton.vue";
|
||||
import WopiEditButton from "./StoredObjectButton/WopiEditButton.vue";
|
||||
import {
|
||||
is_extension_editable,
|
||||
is_extension_viewable,
|
||||
is_object_ready,
|
||||
is_extension_editable,
|
||||
is_extension_viewable,
|
||||
is_object_ready,
|
||||
} from "./StoredObjectButton/helpers";
|
||||
import {
|
||||
StoredObject,
|
||||
StoredObjectStatusChange,
|
||||
StoredObjectVersion,
|
||||
WopiEditButtonExecutableBeforeLeaveFunction,
|
||||
StoredObject,
|
||||
StoredObjectStatusChange,
|
||||
StoredObjectVersion,
|
||||
WopiEditButtonExecutableBeforeLeaveFunction,
|
||||
} from "../types";
|
||||
import DesktopEditButton from "ChillDocStoreAssets/vuejs/StoredObjectButton/DesktopEditButton.vue";
|
||||
import HistoryButton from "ChillDocStoreAssets/vuejs/StoredObjectButton/HistoryButton.vue";
|
||||
|
||||
interface DocumentActionButtonsGroupConfig {
|
||||
storedObject: StoredObject;
|
||||
small?: boolean;
|
||||
canEdit?: boolean;
|
||||
canDownload?: boolean;
|
||||
canConvertPdf?: boolean;
|
||||
returnPath?: string;
|
||||
storedObject: StoredObject;
|
||||
small?: boolean;
|
||||
canEdit?: boolean;
|
||||
canDownload?: boolean;
|
||||
canConvertPdf?: boolean;
|
||||
returnPath?: string;
|
||||
|
||||
/**
|
||||
* Will be the filename displayed to the user when he·she download the document
|
||||
* (the document will be saved on his disk with this name)
|
||||
*
|
||||
* If not set, 'document' will be used.
|
||||
*/
|
||||
filename?: string;
|
||||
/**
|
||||
* Will be the filename displayed to the user when he·she download the document
|
||||
* (the document will be saved on his disk with this name)
|
||||
*
|
||||
* If not set, 'document' will be used.
|
||||
*/
|
||||
filename?: string;
|
||||
|
||||
/**
|
||||
* If set, will execute this function before leaving to the editor
|
||||
*/
|
||||
executeBeforeLeave?: WopiEditButtonExecutableBeforeLeaveFunction;
|
||||
/**
|
||||
* If set, will execute this function before leaving to the editor
|
||||
*/
|
||||
executeBeforeLeave?: WopiEditButtonExecutableBeforeLeaveFunction;
|
||||
|
||||
/**
|
||||
* a link to download and edit file using webdav
|
||||
*/
|
||||
davLink?: string;
|
||||
/**
|
||||
* a link to download and edit file using webdav
|
||||
*/
|
||||
davLink?: string;
|
||||
|
||||
/**
|
||||
* the expiration date of the download, as a unix timestamp
|
||||
*/
|
||||
davLinkExpiration?: number;
|
||||
/**
|
||||
* the expiration date of the download, as a unix timestamp
|
||||
*/
|
||||
davLinkExpiration?: number;
|
||||
}
|
||||
|
||||
const emit =
|
||||
defineEmits<
|
||||
(
|
||||
e: "onStoredObjectStatusChange",
|
||||
newStatus: StoredObjectStatusChange,
|
||||
) => void
|
||||
>();
|
||||
defineEmits<
|
||||
(
|
||||
e: "onStoredObjectStatusChange",
|
||||
newStatus: StoredObjectStatusChange,
|
||||
) => void
|
||||
>();
|
||||
|
||||
const props = withDefaults(defineProps<DocumentActionButtonsGroupConfig>(), {
|
||||
small: false,
|
||||
canEdit: true,
|
||||
canDownload: true,
|
||||
canConvertPdf: true,
|
||||
returnPath:
|
||||
window.location.pathname +
|
||||
window.location.search +
|
||||
window.location.hash,
|
||||
small: false,
|
||||
canEdit: true,
|
||||
canDownload: true,
|
||||
canConvertPdf: true,
|
||||
returnPath:
|
||||
window.location.pathname + window.location.search + window.location.hash,
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -145,93 +141,93 @@ let tryiesForReady = 0;
|
||||
const maxTryiesForReady = 120;
|
||||
|
||||
const isButtonGroupDisplayable = computed<boolean>(() => {
|
||||
return (
|
||||
isDownloadable.value ||
|
||||
isEditableOnline.value ||
|
||||
isEditableOnDesktop.value ||
|
||||
isConvertibleToPdf.value
|
||||
);
|
||||
return (
|
||||
isDownloadable.value ||
|
||||
isEditableOnline.value ||
|
||||
isEditableOnDesktop.value ||
|
||||
isConvertibleToPdf.value
|
||||
);
|
||||
});
|
||||
|
||||
const isDownloadable = computed<boolean>(() => {
|
||||
return (
|
||||
props.storedObject.status === "ready" ||
|
||||
// happens when the stored object version is just added, but not persisted
|
||||
(props.storedObject.currentVersion !== null &&
|
||||
props.storedObject.status === "empty")
|
||||
);
|
||||
return (
|
||||
props.storedObject.status === "ready" ||
|
||||
// happens when the stored object version is just added, but not persisted
|
||||
(props.storedObject.currentVersion !== null &&
|
||||
props.storedObject.status === "empty")
|
||||
);
|
||||
});
|
||||
|
||||
const isEditableOnline = computed<boolean>(() => {
|
||||
return (
|
||||
props.storedObject.status === "ready" &&
|
||||
props.storedObject._permissions.canEdit &&
|
||||
props.canEdit &&
|
||||
props.storedObject.currentVersion !== null &&
|
||||
is_extension_editable(props.storedObject.currentVersion.type) &&
|
||||
props.storedObject.currentVersion.persisted !== false
|
||||
);
|
||||
return (
|
||||
props.storedObject.status === "ready" &&
|
||||
props.storedObject._permissions.canEdit &&
|
||||
props.canEdit &&
|
||||
props.storedObject.currentVersion !== null &&
|
||||
is_extension_editable(props.storedObject.currentVersion.type) &&
|
||||
props.storedObject.currentVersion.persisted !== false
|
||||
);
|
||||
});
|
||||
|
||||
const isEditableOnDesktop = computed<boolean>(() => {
|
||||
return isEditableOnline.value;
|
||||
return isEditableOnline.value;
|
||||
});
|
||||
|
||||
const isConvertibleToPdf = computed<boolean>(() => {
|
||||
return (
|
||||
props.storedObject.status === "ready" &&
|
||||
props.storedObject._permissions.canSee &&
|
||||
props.canConvertPdf &&
|
||||
props.storedObject.currentVersion !== null &&
|
||||
is_extension_viewable(props.storedObject.currentVersion.type) &&
|
||||
props.storedObject.currentVersion.type !== "application/pdf" &&
|
||||
props.storedObject.currentVersion.persisted !== false
|
||||
);
|
||||
return (
|
||||
props.storedObject.status === "ready" &&
|
||||
props.storedObject._permissions.canSee &&
|
||||
props.canConvertPdf &&
|
||||
props.storedObject.currentVersion !== null &&
|
||||
is_extension_viewable(props.storedObject.currentVersion.type) &&
|
||||
props.storedObject.currentVersion.type !== "application/pdf" &&
|
||||
props.storedObject.currentVersion.persisted !== false
|
||||
);
|
||||
});
|
||||
|
||||
const isHistoryViewable = computed<boolean>(() => {
|
||||
return props.storedObject.status === "ready";
|
||||
return props.storedObject.status === "ready";
|
||||
});
|
||||
|
||||
const checkForReady = function (): void {
|
||||
if (
|
||||
"ready" === props.storedObject.status ||
|
||||
"empty" === props.storedObject.status ||
|
||||
"failure" === props.storedObject.status ||
|
||||
// stop reloading if the page stays opened for a long time
|
||||
tryiesForReady > maxTryiesForReady
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (
|
||||
"ready" === props.storedObject.status ||
|
||||
"empty" === props.storedObject.status ||
|
||||
"failure" === props.storedObject.status ||
|
||||
// stop reloading if the page stays opened for a long time
|
||||
tryiesForReady > maxTryiesForReady
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
tryiesForReady = tryiesForReady + 1;
|
||||
tryiesForReady = tryiesForReady + 1;
|
||||
|
||||
setTimeout(onObjectNewStatusCallback, 5000);
|
||||
setTimeout(onObjectNewStatusCallback, 5000);
|
||||
};
|
||||
|
||||
const onObjectNewStatusCallback = async function (): Promise<void> {
|
||||
if (props.storedObject.status === "stored_object_created") {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
const new_status = await is_object_ready(props.storedObject);
|
||||
if (props.storedObject.status !== new_status.status) {
|
||||
emit("onStoredObjectStatusChange", new_status);
|
||||
return Promise.resolve();
|
||||
} else if ("failure" === new_status.status) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
if ("ready" !== new_status.status) {
|
||||
// we check for new status, unless it is ready
|
||||
checkForReady();
|
||||
}
|
||||
|
||||
if (props.storedObject.status === "stored_object_created") {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
const new_status = await is_object_ready(props.storedObject);
|
||||
if (props.storedObject.status !== new_status.status) {
|
||||
emit("onStoredObjectStatusChange", new_status);
|
||||
return Promise.resolve();
|
||||
} else if ("failure" === new_status.status) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
if ("ready" !== new_status.status) {
|
||||
// we check for new status, unless it is ready
|
||||
checkForReady();
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
checkForReady();
|
||||
checkForReady();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -4,36 +4,36 @@ import { _createI18n } from "ChillMainAssets/vuejs/_js/i18n";
|
||||
import App from "./App.vue";
|
||||
|
||||
const appMessages = {
|
||||
fr: {
|
||||
yes: "Oui",
|
||||
are_you_sure: "Êtes-vous sûr·e?",
|
||||
you_are_going_to_sign: "Vous allez signer le document",
|
||||
signature_confirmation: "Confirmation de la signature",
|
||||
sign: "Signer",
|
||||
choose_another_signature: "Choisir une autre zone",
|
||||
cancel: "Annuler",
|
||||
last_sign_zone: "Zone de signature précédente",
|
||||
next_sign_zone: "Zone de signature suivante",
|
||||
add_sign_zone: "Ajouter une zone de signature",
|
||||
click_on_document: "Cliquer sur le document",
|
||||
last_zone: "Zone précédente",
|
||||
next_zone: "Zone suivante",
|
||||
add_zone: "Ajouter une zone",
|
||||
another_zone: "Autre zone",
|
||||
electronic_signature_in_progress: "Signature électronique en cours...",
|
||||
loading: "Chargement...",
|
||||
remove_sign_zone: "Enlever la zone",
|
||||
return: "Retour",
|
||||
see_all_pages: "Voir toutes les pages",
|
||||
all_pages: "Toutes les pages",
|
||||
},
|
||||
fr: {
|
||||
yes: "Oui",
|
||||
are_you_sure: "Êtes-vous sûr·e?",
|
||||
you_are_going_to_sign: "Vous allez signer le document",
|
||||
signature_confirmation: "Confirmation de la signature",
|
||||
sign: "Signer",
|
||||
choose_another_signature: "Choisir une autre zone",
|
||||
cancel: "Annuler",
|
||||
last_sign_zone: "Zone de signature précédente",
|
||||
next_sign_zone: "Zone de signature suivante",
|
||||
add_sign_zone: "Ajouter une zone de signature",
|
||||
click_on_document: "Cliquer sur le document",
|
||||
last_zone: "Zone précédente",
|
||||
next_zone: "Zone suivante",
|
||||
add_zone: "Ajouter une zone",
|
||||
another_zone: "Autre zone",
|
||||
electronic_signature_in_progress: "Signature électronique en cours...",
|
||||
loading: "Chargement...",
|
||||
remove_sign_zone: "Enlever la zone",
|
||||
return: "Retour",
|
||||
see_all_pages: "Voir toutes les pages",
|
||||
all_pages: "Toutes les pages",
|
||||
},
|
||||
};
|
||||
|
||||
const i18n = _createI18n(appMessages);
|
||||
|
||||
const app = createApp({
|
||||
template: `<app></app>`,
|
||||
template: `<app></app>`,
|
||||
})
|
||||
.use(i18n)
|
||||
.component("app", App)
|
||||
.mount("#document-signature");
|
||||
.use(i18n)
|
||||
.component("app", App)
|
||||
.mount("#document-signature");
|
||||
|
@@ -1,208 +1,206 @@
|
||||
<script setup lang="ts">
|
||||
import { StoredObject, StoredObjectVersionCreated } from "../../types";
|
||||
import {
|
||||
encryptFile,
|
||||
fetchNewStoredObject,
|
||||
uploadVersion,
|
||||
encryptFile,
|
||||
fetchNewStoredObject,
|
||||
uploadVersion,
|
||||
} from "../../js/async-upload/uploader";
|
||||
import { computed, ref, Ref } from "vue";
|
||||
import FileIcon from "ChillDocStoreAssets/vuejs/FileIcon.vue";
|
||||
|
||||
interface DropFileConfig {
|
||||
existingDoc?: StoredObject;
|
||||
existingDoc?: StoredObject;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<DropFileConfig>(), {
|
||||
existingDoc: null,
|
||||
existingDoc: null,
|
||||
});
|
||||
|
||||
const emit =
|
||||
defineEmits<
|
||||
(
|
||||
e: "addDocument",
|
||||
{
|
||||
stored_object_version: StoredObjectVersionCreated,
|
||||
stored_object: StoredObject,
|
||||
file_name: string,
|
||||
},
|
||||
) => void
|
||||
>();
|
||||
defineEmits<
|
||||
(
|
||||
e: "addDocument",
|
||||
{
|
||||
stored_object_version: StoredObjectVersionCreated,
|
||||
stored_object: StoredObject,
|
||||
file_name: string,
|
||||
},
|
||||
) => void
|
||||
>();
|
||||
|
||||
const is_dragging: Ref<boolean> = ref(false);
|
||||
const uploading: Ref<boolean> = ref(false);
|
||||
const display_filename: Ref<string | null> = ref(null);
|
||||
|
||||
const has_existing_doc = computed<boolean>(() => {
|
||||
return props.existingDoc !== undefined && props.existingDoc !== null;
|
||||
return props.existingDoc !== undefined && props.existingDoc !== null;
|
||||
});
|
||||
|
||||
const onDragOver = (e: Event) => {
|
||||
e.preventDefault();
|
||||
e.preventDefault();
|
||||
|
||||
is_dragging.value = true;
|
||||
is_dragging.value = true;
|
||||
};
|
||||
|
||||
const onDragLeave = (e: Event) => {
|
||||
e.preventDefault();
|
||||
e.preventDefault();
|
||||
|
||||
is_dragging.value = false;
|
||||
is_dragging.value = false;
|
||||
};
|
||||
|
||||
const onDrop = (e: DragEvent) => {
|
||||
e.preventDefault();
|
||||
e.preventDefault();
|
||||
|
||||
const files = e.dataTransfer?.files;
|
||||
const files = e.dataTransfer?.files;
|
||||
|
||||
if (null === files || undefined === files) {
|
||||
console.error("no files transferred", e.dataTransfer);
|
||||
return;
|
||||
}
|
||||
if (files.length === 0) {
|
||||
console.error("no files given");
|
||||
return;
|
||||
}
|
||||
if (null === files || undefined === files) {
|
||||
console.error("no files transferred", e.dataTransfer);
|
||||
return;
|
||||
}
|
||||
if (files.length === 0) {
|
||||
console.error("no files given");
|
||||
return;
|
||||
}
|
||||
|
||||
handleFile(files[0]);
|
||||
handleFile(files[0]);
|
||||
};
|
||||
|
||||
const onZoneClick = (e: Event) => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
||||
const input = document.createElement("input");
|
||||
input.type = "file";
|
||||
input.addEventListener("change", onFileChange);
|
||||
const input = document.createElement("input");
|
||||
input.type = "file";
|
||||
input.addEventListener("change", onFileChange);
|
||||
|
||||
input.click();
|
||||
input.click();
|
||||
};
|
||||
|
||||
const onFileChange = async (event: Event): Promise<void> => {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const input = event.target as HTMLInputElement;
|
||||
|
||||
if (input.files && input.files[0]) {
|
||||
console.log("file added", input.files[0]);
|
||||
const file = input.files[0];
|
||||
await handleFile(file);
|
||||
if (input.files && input.files[0]) {
|
||||
console.log("file added", input.files[0]);
|
||||
const file = input.files[0];
|
||||
await handleFile(file);
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
throw "No file given";
|
||||
throw "No file given";
|
||||
};
|
||||
|
||||
const handleFile = async (file: File): Promise<void> => {
|
||||
uploading.value = true;
|
||||
display_filename.value = file.name;
|
||||
const type = file.type;
|
||||
uploading.value = true;
|
||||
display_filename.value = file.name;
|
||||
const type = file.type;
|
||||
|
||||
// create a stored_object if not exists
|
||||
let stored_object;
|
||||
if (null === props.existingDoc) {
|
||||
stored_object = await fetchNewStoredObject();
|
||||
} else {
|
||||
stored_object = props.existingDoc;
|
||||
}
|
||||
// create a stored_object if not exists
|
||||
let stored_object;
|
||||
if (null === props.existingDoc) {
|
||||
stored_object = await fetchNewStoredObject();
|
||||
} else {
|
||||
stored_object = props.existingDoc;
|
||||
}
|
||||
|
||||
const buffer = await file.arrayBuffer();
|
||||
const [encrypted, iv, jsonWebKey] = await encryptFile(buffer);
|
||||
const filename = await uploadVersion(encrypted, stored_object);
|
||||
const buffer = await file.arrayBuffer();
|
||||
const [encrypted, iv, jsonWebKey] = await encryptFile(buffer);
|
||||
const filename = await uploadVersion(encrypted, stored_object);
|
||||
|
||||
const stored_object_version: StoredObjectVersionCreated = {
|
||||
filename: filename,
|
||||
iv: Array.from(iv),
|
||||
keyInfos: jsonWebKey,
|
||||
type: type,
|
||||
persisted: false,
|
||||
};
|
||||
const stored_object_version: StoredObjectVersionCreated = {
|
||||
filename: filename,
|
||||
iv: Array.from(iv),
|
||||
keyInfos: jsonWebKey,
|
||||
type: type,
|
||||
persisted: false,
|
||||
};
|
||||
|
||||
const fileName = file.name;
|
||||
let file_name = "Nouveau document";
|
||||
const file_name_split = fileName.split(".");
|
||||
if (file_name_split.length > 1) {
|
||||
const extension = file_name_split
|
||||
? file_name_split[file_name_split.length - 1]
|
||||
: "";
|
||||
file_name = fileName.replace(extension, "").slice(0, -1);
|
||||
}
|
||||
const fileName = file.name;
|
||||
let file_name = "Nouveau document";
|
||||
const file_name_split = fileName.split(".");
|
||||
if (file_name_split.length > 1) {
|
||||
const extension = file_name_split
|
||||
? file_name_split[file_name_split.length - 1]
|
||||
: "";
|
||||
file_name = fileName.replace(extension, "").slice(0, -1);
|
||||
}
|
||||
|
||||
emit("addDocument", {
|
||||
stored_object,
|
||||
stored_object_version,
|
||||
file_name: file_name,
|
||||
});
|
||||
uploading.value = false;
|
||||
emit("addDocument", {
|
||||
stored_object,
|
||||
stored_object_version,
|
||||
file_name: file_name,
|
||||
});
|
||||
uploading.value = false;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="drop-file">
|
||||
<div
|
||||
v-if="!uploading"
|
||||
:class="{ area: true, dragging: is_dragging }"
|
||||
@click="onZoneClick"
|
||||
@dragover="onDragOver"
|
||||
@dragleave="onDragLeave"
|
||||
@drop="onDrop"
|
||||
>
|
||||
<p v-if="has_existing_doc" class="file-icon">
|
||||
<file-icon :type="props.existingDoc?.type"></file-icon>
|
||||
</p>
|
||||
<div class="drop-file">
|
||||
<div
|
||||
v-if="!uploading"
|
||||
:class="{ area: true, dragging: is_dragging }"
|
||||
@click="onZoneClick"
|
||||
@dragover="onDragOver"
|
||||
@dragleave="onDragLeave"
|
||||
@drop="onDrop"
|
||||
>
|
||||
<p v-if="has_existing_doc" class="file-icon">
|
||||
<file-icon :type="props.existingDoc?.type"></file-icon>
|
||||
</p>
|
||||
|
||||
<p v-if="display_filename !== null" class="display-filename">
|
||||
{{ display_filename }}
|
||||
</p>
|
||||
<!-- todo i18n -->
|
||||
<p v-if="has_existing_doc">
|
||||
Déposez un document ou cliquez ici pour remplacer le document
|
||||
existant
|
||||
</p>
|
||||
<p v-else>
|
||||
Déposez un document ou cliquez ici pour ouvrir le navigateur de
|
||||
fichier
|
||||
</p>
|
||||
</div>
|
||||
<div v-else class="waiting">
|
||||
<i class="fa fa-cog fa-spin fa-3x fa-fw"></i>
|
||||
<span class="sr-only">Loading...</span>
|
||||
</div>
|
||||
<p v-if="display_filename !== null" class="display-filename">
|
||||
{{ display_filename }}
|
||||
</p>
|
||||
<!-- todo i18n -->
|
||||
<p v-if="has_existing_doc">
|
||||
Déposez un document ou cliquez ici pour remplacer le document existant
|
||||
</p>
|
||||
<p v-else>
|
||||
Déposez un document ou cliquez ici pour ouvrir le navigateur de fichier
|
||||
</p>
|
||||
</div>
|
||||
<div v-else class="waiting">
|
||||
<i class="fa fa-cog fa-spin fa-3x fa-fw"></i>
|
||||
<span class="sr-only">Loading...</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.drop-file {
|
||||
width: 100%;
|
||||
|
||||
.file-icon {
|
||||
font-size: xx-large;
|
||||
}
|
||||
|
||||
.display-filename {
|
||||
font-variant: small-caps;
|
||||
font-weight: 200;
|
||||
}
|
||||
|
||||
& > .area,
|
||||
& > .waiting {
|
||||
width: 100%;
|
||||
height: 10rem;
|
||||
|
||||
.file-icon {
|
||||
font-size: xx-large;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
p {
|
||||
// require for display in DropFileModal
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
.display-filename {
|
||||
font-variant: small-caps;
|
||||
font-weight: 200;
|
||||
}
|
||||
|
||||
& > .area,
|
||||
& > .waiting {
|
||||
width: 100%;
|
||||
height: 10rem;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
p {
|
||||
// require for display in DropFileModal
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
& > .area {
|
||||
border: 4px dashed #ccc;
|
||||
|
||||
&.dragging {
|
||||
border: 4px dashed blue;
|
||||
}
|
||||
& > .area {
|
||||
border: 4px dashed #ccc;
|
||||
|
||||
&.dragging {
|
||||
border: 4px dashed blue;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
@@ -6,24 +6,24 @@ import { computed, reactive } from "vue";
|
||||
import { useToast } from "vue-toast-notification";
|
||||
|
||||
interface DropFileConfig {
|
||||
allowRemove: boolean;
|
||||
existingDoc?: StoredObject;
|
||||
allowRemove: boolean;
|
||||
existingDoc?: StoredObject;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<DropFileConfig>(), {
|
||||
allowRemove: false,
|
||||
allowRemove: false,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
(
|
||||
e: "addDocument",
|
||||
{
|
||||
stored_object: StoredObject,
|
||||
stored_object_version: StoredObjectVersion,
|
||||
file_name: string,
|
||||
},
|
||||
): void;
|
||||
(e: "removeDocument"): void;
|
||||
(
|
||||
e: "addDocument",
|
||||
{
|
||||
stored_object: StoredObject,
|
||||
stored_object_version: StoredObjectVersion,
|
||||
file_name: string,
|
||||
},
|
||||
): void;
|
||||
(e: "removeDocument"): void;
|
||||
}>();
|
||||
|
||||
const $toast = useToast();
|
||||
@@ -33,67 +33,67 @@ const state = reactive({ showModal: false });
|
||||
const modalClasses = { "modal-dialog-centered": true, "modal-md": true };
|
||||
|
||||
const buttonState = computed<"add" | "replace">(() => {
|
||||
if (props.existingDoc === undefined || props.existingDoc === null) {
|
||||
return "add";
|
||||
}
|
||||
if (props.existingDoc === undefined || props.existingDoc === null) {
|
||||
return "add";
|
||||
}
|
||||
|
||||
return "replace";
|
||||
return "replace";
|
||||
});
|
||||
|
||||
function onAddDocument({
|
||||
stored_object,
|
||||
stored_object_version,
|
||||
file_name,
|
||||
stored_object,
|
||||
stored_object_version,
|
||||
file_name,
|
||||
}: {
|
||||
stored_object: StoredObject;
|
||||
stored_object_version: StoredObjectVersion;
|
||||
file_name: string;
|
||||
stored_object: StoredObject;
|
||||
stored_object_version: StoredObjectVersion;
|
||||
file_name: string;
|
||||
}): void {
|
||||
const message =
|
||||
buttonState.value === "add" ? "Document ajouté" : "Document remplacé";
|
||||
$toast.success(message);
|
||||
emit("addDocument", { stored_object_version, stored_object, file_name });
|
||||
state.showModal = false;
|
||||
const message =
|
||||
buttonState.value === "add" ? "Document ajouté" : "Document remplacé";
|
||||
$toast.success(message);
|
||||
emit("addDocument", { stored_object_version, stored_object, file_name });
|
||||
state.showModal = false;
|
||||
}
|
||||
|
||||
function onRemoveDocument(): void {
|
||||
emit("removeDocument");
|
||||
emit("removeDocument");
|
||||
}
|
||||
|
||||
function openModal(): void {
|
||||
state.showModal = true;
|
||||
state.showModal = true;
|
||||
}
|
||||
|
||||
function closeModal(): void {
|
||||
state.showModal = false;
|
||||
state.showModal = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<button
|
||||
v-if="buttonState === 'add'"
|
||||
@click="openModal"
|
||||
class="btn btn-create"
|
||||
>
|
||||
Ajouter un document
|
||||
</button>
|
||||
<button v-else @click="openModal" class="btn btn-edit">
|
||||
Remplacer le document
|
||||
</button>
|
||||
<modal
|
||||
v-if="state.showModal"
|
||||
:modal-dialog-class="modalClasses"
|
||||
@close="closeModal"
|
||||
>
|
||||
<template v-slot:body>
|
||||
<drop-file-widget
|
||||
:existing-doc="existingDoc"
|
||||
:allow-remove="allowRemove"
|
||||
@add-document="onAddDocument"
|
||||
@remove-document="onRemoveDocument"
|
||||
></drop-file-widget>
|
||||
</template>
|
||||
</modal>
|
||||
<button
|
||||
v-if="buttonState === 'add'"
|
||||
@click="openModal"
|
||||
class="btn btn-create"
|
||||
>
|
||||
Ajouter un document
|
||||
</button>
|
||||
<button v-else @click="openModal" class="btn btn-edit">
|
||||
Remplacer le document
|
||||
</button>
|
||||
<modal
|
||||
v-if="state.showModal"
|
||||
:modal-dialog-class="modalClasses"
|
||||
@close="closeModal"
|
||||
>
|
||||
<template v-slot:body>
|
||||
<drop-file-widget
|
||||
:existing-doc="existingDoc"
|
||||
:allow-remove="allowRemove"
|
||||
@add-document="onAddDocument"
|
||||
@remove-document="onRemoveDocument"
|
||||
></drop-file-widget>
|
||||
</template>
|
||||
</modal>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss"></style>
|
||||
|
@@ -5,97 +5,97 @@ import DropFile from "ChillDocStoreAssets/vuejs/DropFileWidget/DropFile.vue";
|
||||
import DocumentActionButtonsGroup from "ChillDocStoreAssets/vuejs/DocumentActionButtonsGroup.vue";
|
||||
|
||||
interface DropFileConfig {
|
||||
allowRemove: boolean;
|
||||
existingDoc?: StoredObject;
|
||||
allowRemove: boolean;
|
||||
existingDoc?: StoredObject;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<DropFileConfig>(), {
|
||||
allowRemove: false,
|
||||
allowRemove: false,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
(
|
||||
e: "addDocument",
|
||||
{
|
||||
stored_object: StoredObject,
|
||||
stored_object_version: StoredObjectVersion,
|
||||
file_name: string,
|
||||
},
|
||||
): void;
|
||||
(e: "removeDocument"): void;
|
||||
(
|
||||
e: "addDocument",
|
||||
{
|
||||
stored_object: StoredObject,
|
||||
stored_object_version: StoredObjectVersion,
|
||||
file_name: string,
|
||||
},
|
||||
): void;
|
||||
(e: "removeDocument"): void;
|
||||
}>();
|
||||
|
||||
const has_existing_doc = computed<boolean>(() => {
|
||||
return props.existingDoc !== undefined && props.existingDoc !== null;
|
||||
return props.existingDoc !== undefined && props.existingDoc !== null;
|
||||
});
|
||||
|
||||
const dav_link_expiration = computed<number | undefined>(() => {
|
||||
if (props.existingDoc === undefined || props.existingDoc === null) {
|
||||
return undefined;
|
||||
}
|
||||
if (props.existingDoc.status !== "ready") {
|
||||
return undefined;
|
||||
}
|
||||
if (props.existingDoc === undefined || props.existingDoc === null) {
|
||||
return undefined;
|
||||
}
|
||||
if (props.existingDoc.status !== "ready") {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return props.existingDoc._links?.dav_link?.expiration;
|
||||
return props.existingDoc._links?.dav_link?.expiration;
|
||||
});
|
||||
|
||||
const dav_link_href = computed<string | undefined>(() => {
|
||||
if (props.existingDoc === undefined || props.existingDoc === null) {
|
||||
return undefined;
|
||||
}
|
||||
if (props.existingDoc.status !== "ready") {
|
||||
return undefined;
|
||||
}
|
||||
if (props.existingDoc === undefined || props.existingDoc === null) {
|
||||
return undefined;
|
||||
}
|
||||
if (props.existingDoc.status !== "ready") {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return props.existingDoc._links?.dav_link?.href;
|
||||
return props.existingDoc._links?.dav_link?.href;
|
||||
});
|
||||
|
||||
const onAddDocument = ({
|
||||
stored_object,
|
||||
stored_object_version,
|
||||
file_name,
|
||||
stored_object,
|
||||
stored_object_version,
|
||||
file_name,
|
||||
}: {
|
||||
stored_object: StoredObject;
|
||||
stored_object_version: StoredObjectVersion;
|
||||
file_name: string;
|
||||
stored_object: StoredObject;
|
||||
stored_object_version: StoredObjectVersion;
|
||||
file_name: string;
|
||||
}): void => {
|
||||
emit("addDocument", { stored_object, stored_object_version, file_name });
|
||||
emit("addDocument", { stored_object, stored_object_version, file_name });
|
||||
};
|
||||
|
||||
const onRemoveDocument = (e: Event): void => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
emit("removeDocument");
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
emit("removeDocument");
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<drop-file
|
||||
:existingDoc="props.existingDoc"
|
||||
@addDocument="onAddDocument"
|
||||
></drop-file>
|
||||
<div>
|
||||
<drop-file
|
||||
:existingDoc="props.existingDoc"
|
||||
@addDocument="onAddDocument"
|
||||
></drop-file>
|
||||
|
||||
<ul class="record_actions">
|
||||
<li v-if="has_existing_doc">
|
||||
<document-action-buttons-group
|
||||
:stored-object="props.existingDoc"
|
||||
:can-edit="props.existingDoc?.status === 'ready'"
|
||||
:can-download="true"
|
||||
:dav-link="dav_link_href"
|
||||
:dav-link-expiration="dav_link_expiration"
|
||||
/>
|
||||
</li>
|
||||
<li>
|
||||
<button
|
||||
v-if="allowRemove"
|
||||
class="btn btn-delete"
|
||||
@click="onRemoveDocument($event)"
|
||||
></button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<ul class="record_actions">
|
||||
<li v-if="has_existing_doc">
|
||||
<document-action-buttons-group
|
||||
:stored-object="props.existingDoc"
|
||||
:can-edit="props.existingDoc?.status === 'ready'"
|
||||
:can-download="true"
|
||||
:dav-link="dav_link_href"
|
||||
:dav-link-expiration="dav_link_expiration"
|
||||
/>
|
||||
</li>
|
||||
<li>
|
||||
<button
|
||||
v-if="allowRemove"
|
||||
class="btn btn-delete"
|
||||
@click="onRemoveDocument($event)"
|
||||
></button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss"></style>
|
||||
|
@@ -1,46 +1,46 @@
|
||||
<script setup lang="ts">
|
||||
interface FileIconConfig {
|
||||
type: string;
|
||||
type: string;
|
||||
}
|
||||
|
||||
const props = defineProps<FileIconConfig>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<i class="fa fa-file-pdf-o" v-if="props.type === 'application/pdf'"></i>
|
||||
<i
|
||||
class="fa fa-file-word-o"
|
||||
v-else-if="props.type === 'application/vnd.oasis.opendocument.text'"
|
||||
></i>
|
||||
<i
|
||||
class="fa fa-file-word-o"
|
||||
v-else-if="
|
||||
props.type ===
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
||||
"
|
||||
></i>
|
||||
<i
|
||||
class="fa fa-file-word-o"
|
||||
v-else-if="props.type === 'application/msword'"
|
||||
></i>
|
||||
<i
|
||||
class="fa fa-file-excel-o"
|
||||
v-else-if="
|
||||
props.type ===
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||
"
|
||||
></i>
|
||||
<i
|
||||
class="fa fa-file-excel-o"
|
||||
v-else-if="props.type === 'application/vnd.ms-excel'"
|
||||
></i>
|
||||
<i class="fa fa-file-image-o" v-else-if="props.type === 'image/jpeg'"></i>
|
||||
<i class="fa fa-file-image-o" v-else-if="props.type === 'image/png'"></i>
|
||||
<i
|
||||
class="fa fa-file-archive-o"
|
||||
v-else-if="props.type === 'application/x-zip-compressed'"
|
||||
></i>
|
||||
<i class="fa fa-file-code-o" v-else></i>
|
||||
<i class="fa fa-file-pdf-o" v-if="props.type === 'application/pdf'"></i>
|
||||
<i
|
||||
class="fa fa-file-word-o"
|
||||
v-else-if="props.type === 'application/vnd.oasis.opendocument.text'"
|
||||
></i>
|
||||
<i
|
||||
class="fa fa-file-word-o"
|
||||
v-else-if="
|
||||
props.type ===
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
||||
"
|
||||
></i>
|
||||
<i
|
||||
class="fa fa-file-word-o"
|
||||
v-else-if="props.type === 'application/msword'"
|
||||
></i>
|
||||
<i
|
||||
class="fa fa-file-excel-o"
|
||||
v-else-if="
|
||||
props.type ===
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||
"
|
||||
></i>
|
||||
<i
|
||||
class="fa fa-file-excel-o"
|
||||
v-else-if="props.type === 'application/vnd.ms-excel'"
|
||||
></i>
|
||||
<i class="fa fa-file-image-o" v-else-if="props.type === 'image/jpeg'"></i>
|
||||
<i class="fa fa-file-image-o" v-else-if="props.type === 'image/png'"></i>
|
||||
<i
|
||||
class="fa fa-file-archive-o"
|
||||
v-else-if="props.type === 'application/x-zip-compressed'"
|
||||
></i>
|
||||
<i class="fa fa-file-code-o" v-else></i>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss"></style>
|
||||
|
@@ -1,28 +1,28 @@
|
||||
<template>
|
||||
<a :class="props.classes" @click="download_and_open($event)" ref="btn">
|
||||
<i class="fa fa-file-pdf-o"></i>
|
||||
Télécharger en pdf
|
||||
</a>
|
||||
<a :class="props.classes" @click="download_and_open($event)" ref="btn">
|
||||
<i class="fa fa-file-pdf-o"></i>
|
||||
Télécharger en pdf
|
||||
</a>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import {
|
||||
build_convert_link,
|
||||
download_and_decrypt_doc,
|
||||
download_doc,
|
||||
build_convert_link,
|
||||
download_and_decrypt_doc,
|
||||
download_doc,
|
||||
} from "./helpers";
|
||||
import mime from "mime";
|
||||
import { reactive, ref } from "vue";
|
||||
import { StoredObject } from "../../types";
|
||||
|
||||
interface ConvertButtonConfig {
|
||||
storedObject: StoredObject;
|
||||
classes: Record<string, boolean>;
|
||||
filename?: string;
|
||||
storedObject: StoredObject;
|
||||
classes: Record<string, boolean>;
|
||||
filename?: string;
|
||||
}
|
||||
|
||||
interface DownloadButtonState {
|
||||
content: null | string;
|
||||
content: null | string;
|
||||
}
|
||||
|
||||
const props = defineProps<ConvertButtonConfig>();
|
||||
@@ -30,36 +30,34 @@ const state: DownloadButtonState = reactive({ content: null });
|
||||
const btn = ref<HTMLAnchorElement | null>(null);
|
||||
|
||||
async function download_and_open(event: Event): Promise<void> {
|
||||
const button = event.target as HTMLAnchorElement;
|
||||
const button = event.target as HTMLAnchorElement;
|
||||
|
||||
if (null === state.content) {
|
||||
event.preventDefault();
|
||||
if (null === state.content) {
|
||||
event.preventDefault();
|
||||
|
||||
const raw = await download_doc(
|
||||
build_convert_link(props.storedObject.uuid),
|
||||
);
|
||||
state.content = window.URL.createObjectURL(raw);
|
||||
const raw = await download_doc(build_convert_link(props.storedObject.uuid));
|
||||
state.content = window.URL.createObjectURL(raw);
|
||||
|
||||
button.href = window.URL.createObjectURL(raw);
|
||||
button.type = "application/pdf";
|
||||
button.href = window.URL.createObjectURL(raw);
|
||||
button.type = "application/pdf";
|
||||
|
||||
button.download = props.filename + ".pdf" || "document.pdf";
|
||||
}
|
||||
button.download = props.filename + ".pdf" || "document.pdf";
|
||||
}
|
||||
|
||||
button.click();
|
||||
const reset_pending = setTimeout(reset_state, 45000);
|
||||
button.click();
|
||||
const reset_pending = setTimeout(reset_state, 45000);
|
||||
}
|
||||
|
||||
function reset_state(): void {
|
||||
state.content = null;
|
||||
btn.value?.removeAttribute("download");
|
||||
btn.value?.removeAttribute("href");
|
||||
btn.value?.removeAttribute("type");
|
||||
state.content = null;
|
||||
btn.value?.removeAttribute("download");
|
||||
btn.value?.removeAttribute("href");
|
||||
btn.value?.removeAttribute("type");
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
i.fa::before {
|
||||
color: var(--bs-dropdown-link-hover-color);
|
||||
color: var(--bs-dropdown-link-hover-color);
|
||||
}
|
||||
</style>
|
||||
|
@@ -3,13 +3,13 @@ import Modal from "ChillMainAssets/vuejs/_components/Modal.vue";
|
||||
import { computed, reactive } from "vue";
|
||||
|
||||
export interface DesktopEditButtonConfig {
|
||||
editLink: null;
|
||||
classes: Record<string, boolean>;
|
||||
expirationLink: number | Date;
|
||||
editLink: null;
|
||||
classes: Record<string, boolean>;
|
||||
expirationLink: number | Date;
|
||||
}
|
||||
|
||||
interface DesktopEditButtonState {
|
||||
modalOpened: boolean;
|
||||
modalOpened: boolean;
|
||||
}
|
||||
|
||||
const state: DesktopEditButtonState = reactive({ modalOpened: false });
|
||||
@@ -17,80 +17,76 @@ const state: DesktopEditButtonState = reactive({ modalOpened: false });
|
||||
const props = defineProps<DesktopEditButtonConfig>();
|
||||
|
||||
const buildCommand = computed<string>(
|
||||
() => "vnd.libreoffice.command:ofe|u|" + props.editLink,
|
||||
() => "vnd.libreoffice.command:ofe|u|" + props.editLink,
|
||||
);
|
||||
|
||||
const editionUntilFormatted = computed<string>(() => {
|
||||
let d;
|
||||
let d;
|
||||
|
||||
if (props.expirationLink instanceof Date) {
|
||||
d = props.expirationLink;
|
||||
} else {
|
||||
d = new Date(props.expirationLink * 1000);
|
||||
}
|
||||
console.log(props.expirationLink);
|
||||
if (props.expirationLink instanceof Date) {
|
||||
d = props.expirationLink;
|
||||
} else {
|
||||
d = new Date(props.expirationLink * 1000);
|
||||
}
|
||||
console.log(props.expirationLink);
|
||||
|
||||
return new Intl.DateTimeFormat(undefined, {
|
||||
dateStyle: "long",
|
||||
timeStyle: "medium",
|
||||
}).format(d);
|
||||
return new Intl.DateTimeFormat(undefined, {
|
||||
dateStyle: "long",
|
||||
timeStyle: "medium",
|
||||
}).format(d);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<teleport to="body">
|
||||
<modal v-if="state.modalOpened" @close="state.modalOpened = false">
|
||||
<template v-slot:body>
|
||||
<div class="desktop-edit">
|
||||
<p class="center">
|
||||
Veuillez enregistrer vos modifications avant le
|
||||
</p>
|
||||
<p>
|
||||
<strong>{{ editionUntilFormatted }}</strong>
|
||||
</p>
|
||||
<teleport to="body">
|
||||
<modal v-if="state.modalOpened" @close="state.modalOpened = false">
|
||||
<template v-slot:body>
|
||||
<div class="desktop-edit">
|
||||
<p class="center">Veuillez enregistrer vos modifications avant le</p>
|
||||
<p>
|
||||
<strong>{{ editionUntilFormatted }}</strong>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a class="btn btn-primary" :href="buildCommand"
|
||||
>Ouvrir le document pour édition</a
|
||||
>
|
||||
</p>
|
||||
<p>
|
||||
<a class="btn btn-primary" :href="buildCommand"
|
||||
>Ouvrir le document pour édition</a
|
||||
>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<small
|
||||
>Le document peut être édité uniquement en utilisant
|
||||
Libre Office.</small
|
||||
>
|
||||
</p>
|
||||
<p>
|
||||
<small
|
||||
>Le document peut être édité uniquement en utilisant Libre
|
||||
Office.</small
|
||||
>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<small
|
||||
>En cas d'échec lors de l'enregistrement, sauver le
|
||||
document sur le poste de travail avant de le déposer
|
||||
à nouveau ici.</small
|
||||
>
|
||||
</p>
|
||||
<p>
|
||||
<small
|
||||
>En cas d'échec lors de l'enregistrement, sauver le document sur
|
||||
le poste de travail avant de le déposer à nouveau ici.</small
|
||||
>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<small
|
||||
>Vous pouvez naviguez sur d'autres pages pendant
|
||||
l'édition.</small
|
||||
>
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
</modal>
|
||||
</teleport>
|
||||
<a :class="props.classes" @click="state.modalOpened = true">
|
||||
<i class="fa fa-desktop"></i>
|
||||
Éditer sur le bureau
|
||||
</a>
|
||||
<p>
|
||||
<small
|
||||
>Vous pouvez naviguez sur d'autres pages pendant l'édition.</small
|
||||
>
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
</modal>
|
||||
</teleport>
|
||||
<a :class="props.classes" @click="state.modalOpened = true">
|
||||
<i class="fa fa-desktop"></i>
|
||||
Éditer sur le bureau
|
||||
</a>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.desktop-edit {
|
||||
text-align: center;
|
||||
text-align: center;
|
||||
}
|
||||
i.fa::before {
|
||||
color: var(--bs-dropdown-link-hover-color);
|
||||
color: var(--bs-dropdown-link-hover-color);
|
||||
}
|
||||
</style>
|
||||
|
@@ -1,26 +1,26 @@
|
||||
<template>
|
||||
<a
|
||||
v-if="!state.is_ready"
|
||||
:class="props.classes"
|
||||
@click="download_and_open()"
|
||||
title="Télécharger"
|
||||
>
|
||||
<i class="fa fa-download"></i>
|
||||
<template v-if="displayActionStringInButton">Télécharger</template>
|
||||
</a>
|
||||
<a
|
||||
v-else
|
||||
:class="props.classes"
|
||||
target="_blank"
|
||||
:type="props.atVersion.type"
|
||||
:download="buildDocumentName()"
|
||||
:href="state.href_url"
|
||||
ref="open_button"
|
||||
title="Ouvrir"
|
||||
>
|
||||
<i class="fa fa-external-link"></i>
|
||||
<template v-if="displayActionStringInButton">Ouvrir</template>
|
||||
</a>
|
||||
<a
|
||||
v-if="!state.is_ready"
|
||||
:class="props.classes"
|
||||
@click="download_and_open()"
|
||||
title="Télécharger"
|
||||
>
|
||||
<i class="fa fa-download"></i>
|
||||
<template v-if="displayActionStringInButton">Télécharger</template>
|
||||
</a>
|
||||
<a
|
||||
v-else
|
||||
:class="props.classes"
|
||||
target="_blank"
|
||||
:type="props.atVersion.type"
|
||||
:download="buildDocumentName()"
|
||||
:href="state.href_url"
|
||||
ref="open_button"
|
||||
title="Ouvrir"
|
||||
>
|
||||
<i class="fa fa-external-link"></i>
|
||||
<template v-if="displayActionStringInButton">Ouvrir</template>
|
||||
</a>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
@@ -30,112 +30,109 @@ import mime from "mime";
|
||||
import { StoredObject, StoredObjectVersion } from "../../types";
|
||||
|
||||
interface DownloadButtonConfig {
|
||||
storedObject: StoredObject;
|
||||
atVersion: StoredObjectVersion;
|
||||
classes: Record<string, boolean>;
|
||||
filename?: string;
|
||||
/**
|
||||
* if true, display the action string into the button. If false, displays only
|
||||
* the icon
|
||||
*/
|
||||
displayActionStringInButton?: boolean;
|
||||
/**
|
||||
* if true, will download directly the file on load
|
||||
*/
|
||||
directDownload?: boolean;
|
||||
storedObject: StoredObject;
|
||||
atVersion: StoredObjectVersion;
|
||||
classes: Record<string, boolean>;
|
||||
filename?: string;
|
||||
/**
|
||||
* if true, display the action string into the button. If false, displays only
|
||||
* the icon
|
||||
*/
|
||||
displayActionStringInButton?: boolean;
|
||||
/**
|
||||
* if true, will download directly the file on load
|
||||
*/
|
||||
directDownload?: boolean;
|
||||
}
|
||||
|
||||
interface DownloadButtonState {
|
||||
is_ready: boolean;
|
||||
is_running: boolean;
|
||||
href_url: string;
|
||||
is_ready: boolean;
|
||||
is_running: boolean;
|
||||
href_url: string;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<DownloadButtonConfig>(), {
|
||||
displayActionStringInButton: true,
|
||||
directDownload: false,
|
||||
displayActionStringInButton: true,
|
||||
directDownload: false,
|
||||
});
|
||||
const state: DownloadButtonState = reactive({
|
||||
is_ready: false,
|
||||
is_running: false,
|
||||
href_url: "#",
|
||||
is_ready: false,
|
||||
is_running: false,
|
||||
href_url: "#",
|
||||
});
|
||||
|
||||
const open_button = ref<HTMLAnchorElement | null>(null);
|
||||
|
||||
function buildDocumentName(): string {
|
||||
let document_name = props.filename ?? props.storedObject.title;
|
||||
let document_name = props.filename ?? props.storedObject.title;
|
||||
|
||||
if ("" === document_name || null === document_name) {
|
||||
document_name = "document";
|
||||
}
|
||||
if ("" === document_name || null === document_name) {
|
||||
document_name = "document";
|
||||
}
|
||||
|
||||
const ext = mime.getExtension(props.atVersion.type);
|
||||
const ext = mime.getExtension(props.atVersion.type);
|
||||
|
||||
if (null !== ext) {
|
||||
return document_name + "." + ext;
|
||||
}
|
||||
if (null !== ext) {
|
||||
return document_name + "." + ext;
|
||||
}
|
||||
|
||||
return document_name;
|
||||
return document_name;
|
||||
}
|
||||
|
||||
async function download_and_open(): Promise<void> {
|
||||
if (state.is_running) {
|
||||
console.log("state is running, aborting");
|
||||
return;
|
||||
}
|
||||
if (state.is_running) {
|
||||
console.log("state is running, aborting");
|
||||
return;
|
||||
}
|
||||
|
||||
state.is_running = true;
|
||||
state.is_running = true;
|
||||
|
||||
if (state.is_ready) {
|
||||
console.log("state is ready. This should not happens");
|
||||
return;
|
||||
}
|
||||
if (state.is_ready) {
|
||||
console.log("state is ready. This should not happens");
|
||||
return;
|
||||
}
|
||||
|
||||
let raw;
|
||||
let raw;
|
||||
|
||||
try {
|
||||
raw = await download_and_decrypt_doc(
|
||||
props.storedObject,
|
||||
props.atVersion,
|
||||
);
|
||||
} catch (e) {
|
||||
console.error("error while downloading and decrypting document");
|
||||
console.error(e);
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
raw = await download_and_decrypt_doc(props.storedObject, props.atVersion);
|
||||
} catch (e) {
|
||||
console.error("error while downloading and decrypting document");
|
||||
console.error(e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
state.href_url = window.URL.createObjectURL(raw);
|
||||
state.is_running = false;
|
||||
state.is_ready = true;
|
||||
state.href_url = window.URL.createObjectURL(raw);
|
||||
state.is_running = false;
|
||||
state.is_ready = true;
|
||||
|
||||
if (!props.directDownload) {
|
||||
await nextTick();
|
||||
open_button.value?.click();
|
||||
if (!props.directDownload) {
|
||||
await nextTick();
|
||||
open_button.value?.click();
|
||||
|
||||
console.log("open button should have been clicked");
|
||||
setTimeout(reset_state, 45000);
|
||||
}
|
||||
console.log("open button should have been clicked");
|
||||
setTimeout(reset_state, 45000);
|
||||
}
|
||||
}
|
||||
|
||||
function reset_state(): void {
|
||||
state.href_url = "#";
|
||||
state.is_ready = false;
|
||||
state.is_running = false;
|
||||
state.href_url = "#";
|
||||
state.is_ready = false;
|
||||
state.is_running = false;
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
if (props.directDownload) {
|
||||
download_and_open();
|
||||
}
|
||||
if (props.directDownload) {
|
||||
download_and_open();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
i.fa::before {
|
||||
color: var(--bs-dropdown-link-hover-color);
|
||||
color: var(--bs-dropdown-link-hover-color);
|
||||
}
|
||||
i.fa {
|
||||
margin-right: 0.5rem;
|
||||
margin-right: 0.5rem;
|
||||
}
|
||||
</style>
|
||||
|
@@ -1,20 +1,20 @@
|
||||
<script setup lang="ts">
|
||||
import HistoryButtonModal from "ChillDocStoreAssets/vuejs/StoredObjectButton/HistoryButton/HistoryButtonModal.vue";
|
||||
import {
|
||||
StoredObject,
|
||||
StoredObjectVersionWithPointInTime,
|
||||
StoredObject,
|
||||
StoredObjectVersionWithPointInTime,
|
||||
} from "./../../types";
|
||||
import { computed, reactive, ref, useTemplateRef } from "vue";
|
||||
import { get_versions } from "./HistoryButton/api";
|
||||
|
||||
interface HistoryButtonConfig {
|
||||
storedObject: StoredObject;
|
||||
canEdit: boolean;
|
||||
storedObject: StoredObject;
|
||||
canEdit: boolean;
|
||||
}
|
||||
|
||||
interface HistoryButtonState {
|
||||
versions: StoredObjectVersionWithPointInTime[];
|
||||
loaded: boolean;
|
||||
versions: StoredObjectVersionWithPointInTime[];
|
||||
loaded: boolean;
|
||||
}
|
||||
|
||||
const props = defineProps<HistoryButtonConfig>();
|
||||
@@ -22,47 +22,47 @@ const state = reactive<HistoryButtonState>({ versions: [], loaded: false });
|
||||
const modal = useTemplateRef<typeof HistoryButtonModal>("modal");
|
||||
|
||||
const download_version_and_open_modal = async function (): Promise<void> {
|
||||
if (null !== modal.value) {
|
||||
modal.value.open();
|
||||
} else {
|
||||
console.log("modal is null");
|
||||
}
|
||||
if (null !== modal.value) {
|
||||
modal.value.open();
|
||||
} else {
|
||||
console.log("modal is null");
|
||||
}
|
||||
|
||||
if (!state.loaded) {
|
||||
const versions = await get_versions(props.storedObject);
|
||||
if (!state.loaded) {
|
||||
const versions = await get_versions(props.storedObject);
|
||||
|
||||
for (const version of versions) {
|
||||
state.versions.push(version);
|
||||
}
|
||||
state.loaded = true;
|
||||
for (const version of versions) {
|
||||
state.versions.push(version);
|
||||
}
|
||||
state.loaded = true;
|
||||
}
|
||||
};
|
||||
|
||||
const onRestoreVersion = ({
|
||||
newVersion,
|
||||
newVersion,
|
||||
}: {
|
||||
newVersion: StoredObjectVersionWithPointInTime;
|
||||
newVersion: StoredObjectVersionWithPointInTime;
|
||||
}) => {
|
||||
state.versions.unshift(newVersion);
|
||||
state.versions.unshift(newVersion);
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<a @click="download_version_and_open_modal" class="dropdown-item">
|
||||
<history-button-modal
|
||||
ref="modal"
|
||||
:versions="state.versions"
|
||||
:stored-object="storedObject"
|
||||
:can-edit="canEdit"
|
||||
@restore-version="onRestoreVersion"
|
||||
></history-button-modal>
|
||||
<i class="fa fa-history"></i>
|
||||
Historique
|
||||
</a>
|
||||
<a @click="download_version_and_open_modal" class="dropdown-item">
|
||||
<history-button-modal
|
||||
ref="modal"
|
||||
:versions="state.versions"
|
||||
:stored-object="storedObject"
|
||||
:can-edit="canEdit"
|
||||
@restore-version="onRestoreVersion"
|
||||
></history-button-modal>
|
||||
<i class="fa fa-history"></i>
|
||||
Historique
|
||||
</a>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
i.fa::before {
|
||||
color: var(--bs-dropdown-link-hover-color);
|
||||
color: var(--bs-dropdown-link-hover-color);
|
||||
}
|
||||
</style>
|
||||
|
@@ -1,26 +1,26 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
StoredObject,
|
||||
StoredObjectVersionWithPointInTime,
|
||||
StoredObject,
|
||||
StoredObjectVersionWithPointInTime,
|
||||
} from "./../../../types";
|
||||
import HistoryButtonListItem from "ChillDocStoreAssets/vuejs/StoredObjectButton/HistoryButton/HistoryButtonListItem.vue";
|
||||
import { computed, reactive } from "vue";
|
||||
|
||||
interface HistoryButtonListConfig {
|
||||
versions: StoredObjectVersionWithPointInTime[];
|
||||
storedObject: StoredObject;
|
||||
canEdit: boolean;
|
||||
versions: StoredObjectVersionWithPointInTime[];
|
||||
storedObject: StoredObject;
|
||||
canEdit: boolean;
|
||||
}
|
||||
|
||||
const emit = defineEmits<{
|
||||
restoreVersion: [newVersion: StoredObjectVersionWithPointInTime];
|
||||
restoreVersion: [newVersion: StoredObjectVersionWithPointInTime];
|
||||
}>();
|
||||
|
||||
interface HistoryButtonListState {
|
||||
/**
|
||||
* Contains the number of the newly created version when a version is restored.
|
||||
*/
|
||||
restored: number;
|
||||
/**
|
||||
* Contains the number of the newly created version when a version is restored.
|
||||
*/
|
||||
restored: number;
|
||||
}
|
||||
|
||||
const props = defineProps<HistoryButtonListConfig>();
|
||||
@@ -28,11 +28,11 @@ const props = defineProps<HistoryButtonListConfig>();
|
||||
const state = reactive<HistoryButtonListState>({ restored: -1 });
|
||||
|
||||
const higher_version = computed<number>(() =>
|
||||
props.versions.reduce(
|
||||
(accumulator: number, version: StoredObjectVersionWithPointInTime) =>
|
||||
Math.max(accumulator, version.version),
|
||||
-1,
|
||||
),
|
||||
props.versions.reduce(
|
||||
(accumulator: number, version: StoredObjectVersionWithPointInTime) =>
|
||||
Math.max(accumulator, version.version),
|
||||
-1,
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -41,32 +41,32 @@ const higher_version = computed<number>(() =>
|
||||
* internally, keep track of the newly restored version
|
||||
*/
|
||||
const onRestored = ({
|
||||
newVersion,
|
||||
newVersion,
|
||||
}: {
|
||||
newVersion: StoredObjectVersionWithPointInTime;
|
||||
newVersion: StoredObjectVersionWithPointInTime;
|
||||
}) => {
|
||||
state.restored = newVersion.version;
|
||||
emit("restoreVersion", { newVersion });
|
||||
state.restored = newVersion.version;
|
||||
emit("restoreVersion", { newVersion });
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<template v-if="props.versions.length > 0">
|
||||
<div class="container">
|
||||
<template v-for="v in props.versions" :key="v.id">
|
||||
<history-button-list-item
|
||||
:version="v"
|
||||
:can-edit="canEdit"
|
||||
:is-current="higher_version === v.version"
|
||||
:stored-object="storedObject"
|
||||
@restore-version="onRestored"
|
||||
></history-button-list-item>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<p>Chargement des versions</p>
|
||||
</template>
|
||||
<template v-if="props.versions.length > 0">
|
||||
<div class="container">
|
||||
<template v-for="v in props.versions" :key="v.id">
|
||||
<history-button-list-item
|
||||
:version="v"
|
||||
:can-edit="canEdit"
|
||||
:is-current="higher_version === v.version"
|
||||
:stored-object="storedObject"
|
||||
@restore-version="onRestored"
|
||||
></history-button-list-item>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<p>Chargement des versions</p>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss"></style>
|
||||
|
@@ -1,8 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
StoredObject,
|
||||
StoredObjectPointInTime,
|
||||
StoredObjectVersionWithPointInTime,
|
||||
StoredObject,
|
||||
StoredObjectPointInTime,
|
||||
StoredObjectVersionWithPointInTime,
|
||||
} from "./../../../types";
|
||||
import UserRenderBoxBadge from "ChillMainAssets/vuejs/_components/Entity/UserRenderBoxBadge.vue";
|
||||
import { ISOToDatetime } from "./../../../../../../ChillMainBundle/Resources/public/chill/js/date";
|
||||
@@ -12,185 +12,173 @@ import DownloadButton from "ChillDocStoreAssets/vuejs/StoredObjectButton/Downloa
|
||||
import { computed } from "vue";
|
||||
|
||||
interface HistoryButtonListItemConfig {
|
||||
version: StoredObjectVersionWithPointInTime;
|
||||
storedObject: StoredObject;
|
||||
canEdit: boolean;
|
||||
isCurrent: boolean;
|
||||
version: StoredObjectVersionWithPointInTime;
|
||||
storedObject: StoredObject;
|
||||
canEdit: boolean;
|
||||
isCurrent: boolean;
|
||||
}
|
||||
|
||||
const emit = defineEmits<{
|
||||
restoreVersion: [newVersion: StoredObjectVersionWithPointInTime];
|
||||
restoreVersion: [newVersion: StoredObjectVersionWithPointInTime];
|
||||
}>();
|
||||
|
||||
const props = defineProps<HistoryButtonListItemConfig>();
|
||||
|
||||
const onRestore = ({
|
||||
newVersion,
|
||||
newVersion,
|
||||
}: {
|
||||
newVersion: StoredObjectVersionWithPointInTime;
|
||||
newVersion: StoredObjectVersionWithPointInTime;
|
||||
}) => {
|
||||
emit("restoreVersion", { newVersion });
|
||||
emit("restoreVersion", { newVersion });
|
||||
};
|
||||
|
||||
const isKeptBeforeConversion = computed<boolean>(() => {
|
||||
if ("point-in-times" in props.version) {
|
||||
return props.version["point-in-times"].reduce(
|
||||
(accumulator: boolean, pit: StoredObjectPointInTime) =>
|
||||
accumulator || "keep-before-conversion" === pit.reason,
|
||||
false,
|
||||
);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if ("point-in-times" in props.version) {
|
||||
return props.version["point-in-times"].reduce(
|
||||
(accumulator: boolean, pit: StoredObjectPointInTime) =>
|
||||
accumulator || "keep-before-conversion" === pit.reason,
|
||||
false,
|
||||
);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
const isRestored = computed<boolean>(
|
||||
() => props.version.version > 0 && null !== props.version["from-restored"],
|
||||
() => props.version.version > 0 && null !== props.version["from-restored"],
|
||||
);
|
||||
|
||||
const isDuplicated = computed<boolean>(
|
||||
() =>
|
||||
props.version.version === 0 && null !== props.version["from-restored"],
|
||||
() => props.version.version === 0 && null !== props.version["from-restored"],
|
||||
);
|
||||
|
||||
const classes = computed<{
|
||||
row: true;
|
||||
"row-hover": true;
|
||||
"blinking-1": boolean;
|
||||
"blinking-2": boolean;
|
||||
row: true;
|
||||
"row-hover": true;
|
||||
"blinking-1": boolean;
|
||||
"blinking-2": boolean;
|
||||
}>(() => ({
|
||||
row: true,
|
||||
"row-hover": true,
|
||||
"blinking-1": props.isRestored && 0 === props.version.version % 2,
|
||||
"blinking-2": props.isRestored && 1 === props.version.version % 2,
|
||||
row: true,
|
||||
"row-hover": true,
|
||||
"blinking-1": props.isRestored && 0 === props.version.version % 2,
|
||||
"blinking-2": props.isRestored && 1 === props.version.version % 2,
|
||||
}));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div :class="classes">
|
||||
<div
|
||||
class="col-12 tags"
|
||||
v-if="
|
||||
isCurrent ||
|
||||
isKeptBeforeConversion ||
|
||||
isRestored ||
|
||||
isDuplicated
|
||||
"
|
||||
>
|
||||
<span class="badge bg-success" v-if="isCurrent"
|
||||
>Version actuelle</span
|
||||
>
|
||||
<span class="badge bg-info" v-if="isKeptBeforeConversion"
|
||||
>Conservée avant conversion dans un autre format</span
|
||||
>
|
||||
<span class="badge bg-info" v-if="isRestored"
|
||||
>Restaurée depuis la version
|
||||
{{ version["from-restored"]?.version + 1 }}</span
|
||||
>
|
||||
<span class="badge bg-info" v-if="isDuplicated"
|
||||
>Dupliqué depuis un autre document</span
|
||||
>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<file-icon :type="version.type"></file-icon>
|
||||
<span
|
||||
><strong> #{{ version.version + 1 }} </strong></span
|
||||
>
|
||||
<template
|
||||
v-if="version.createdBy !== null && version.createdAt !== null"
|
||||
><strong v-if="version.version == 0">créé par</strong
|
||||
><strong v-else>modifié par</strong>
|
||||
<span class="badge-user"
|
||||
><UserRenderBoxBadge
|
||||
:user="version.createdBy"
|
||||
></UserRenderBoxBadge
|
||||
></span>
|
||||
<strong>à</strong>
|
||||
{{
|
||||
$d(ISOToDatetime(version.createdAt.datetime8601), "long")
|
||||
}}</template
|
||||
><template
|
||||
v-if="version.createdBy === null && version.createdAt !== null"
|
||||
><strong v-if="version.version == 0">Créé le</strong
|
||||
><strong v-else>modifié le</strong>
|
||||
{{
|
||||
$d(ISOToDatetime(version.createdAt.datetime8601), "long")
|
||||
}}</template
|
||||
>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<ul class="record_actions small slim on-version-actions">
|
||||
<li v-if="canEdit && !isCurrent">
|
||||
<restore-version-button
|
||||
:stored-object-version="props.version"
|
||||
@restore-version="onRestore"
|
||||
></restore-version-button>
|
||||
</li>
|
||||
<li>
|
||||
<download-button
|
||||
:stored-object="storedObject"
|
||||
:at-version="version"
|
||||
:classes="{
|
||||
btn: true,
|
||||
'btn-outline-primary': true,
|
||||
'btn-sm': true,
|
||||
}"
|
||||
:display-action-string-in-button="false"
|
||||
></download-button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div :class="classes">
|
||||
<div
|
||||
class="col-12 tags"
|
||||
v-if="isCurrent || isKeptBeforeConversion || isRestored || isDuplicated"
|
||||
>
|
||||
<span class="badge bg-success" v-if="isCurrent">Version actuelle</span>
|
||||
<span class="badge bg-info" v-if="isKeptBeforeConversion"
|
||||
>Conservée avant conversion dans un autre format</span
|
||||
>
|
||||
<span class="badge bg-info" v-if="isRestored"
|
||||
>Restaurée depuis la version
|
||||
{{ version["from-restored"]?.version + 1 }}</span
|
||||
>
|
||||
<span class="badge bg-info" v-if="isDuplicated"
|
||||
>Dupliqué depuis un autre document</span
|
||||
>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<file-icon :type="version.type"></file-icon>
|
||||
<span
|
||||
><strong> #{{ version.version + 1 }} </strong></span
|
||||
>
|
||||
<template v-if="version.createdBy !== null && version.createdAt !== null"
|
||||
><strong v-if="version.version == 0">créé par</strong
|
||||
><strong v-else>modifié par</strong>
|
||||
<span class="badge-user"
|
||||
><UserRenderBoxBadge :user="version.createdBy"></UserRenderBoxBadge
|
||||
></span>
|
||||
<strong>à</strong>
|
||||
{{
|
||||
$d(ISOToDatetime(version.createdAt.datetime8601), "long")
|
||||
}}</template
|
||||
><template v-if="version.createdBy === null && version.createdAt !== null"
|
||||
><strong v-if="version.version == 0">Créé le</strong
|
||||
><strong v-else>modifié le</strong>
|
||||
{{
|
||||
$d(ISOToDatetime(version.createdAt.datetime8601), "long")
|
||||
}}</template
|
||||
>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<ul class="record_actions small slim on-version-actions">
|
||||
<li v-if="canEdit && !isCurrent">
|
||||
<restore-version-button
|
||||
:stored-object-version="props.version"
|
||||
@restore-version="onRestore"
|
||||
></restore-version-button>
|
||||
</li>
|
||||
<li>
|
||||
<download-button
|
||||
:stored-object="storedObject"
|
||||
:at-version="version"
|
||||
:classes="{
|
||||
btn: true,
|
||||
'btn-outline-primary': true,
|
||||
'btn-sm': true,
|
||||
}"
|
||||
:display-action-string-in-button="false"
|
||||
></download-button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
div.tags {
|
||||
span.badge:not(:last-child) {
|
||||
margin-right: 0.5rem;
|
||||
}
|
||||
span.badge:not(:last-child) {
|
||||
margin-right: 0.5rem;
|
||||
}
|
||||
}
|
||||
// to make the animation restart, we have the same animation twice,
|
||||
// and alternate between both
|
||||
.blinking-1 {
|
||||
animation-name: backgroundColorPalette-1;
|
||||
animation-duration: 8s;
|
||||
animation-iteration-count: 1;
|
||||
animation-direction: normal;
|
||||
animation-timing-function: linear;
|
||||
animation-name: backgroundColorPalette-1;
|
||||
animation-duration: 8s;
|
||||
animation-iteration-count: 1;
|
||||
animation-direction: normal;
|
||||
animation-timing-function: linear;
|
||||
}
|
||||
@keyframes backgroundColorPalette-1 {
|
||||
0% {
|
||||
background: var(--bs-chill-green-dark);
|
||||
}
|
||||
25% {
|
||||
background: var(--bs-chill-green);
|
||||
}
|
||||
65% {
|
||||
background: var(--bs-chill-beige);
|
||||
}
|
||||
100% {
|
||||
background: unset;
|
||||
}
|
||||
0% {
|
||||
background: var(--bs-chill-green-dark);
|
||||
}
|
||||
25% {
|
||||
background: var(--bs-chill-green);
|
||||
}
|
||||
65% {
|
||||
background: var(--bs-chill-beige);
|
||||
}
|
||||
100% {
|
||||
background: unset;
|
||||
}
|
||||
}
|
||||
.blinking-2 {
|
||||
animation-name: backgroundColorPalette-2;
|
||||
animation-duration: 8s;
|
||||
animation-iteration-count: 1;
|
||||
animation-direction: normal;
|
||||
animation-timing-function: linear;
|
||||
animation-name: backgroundColorPalette-2;
|
||||
animation-duration: 8s;
|
||||
animation-iteration-count: 1;
|
||||
animation-direction: normal;
|
||||
animation-timing-function: linear;
|
||||
}
|
||||
@keyframes backgroundColorPalette-2 {
|
||||
0% {
|
||||
background: var(--bs-chill-green-dark);
|
||||
}
|
||||
25% {
|
||||
background: var(--bs-chill-green);
|
||||
}
|
||||
65% {
|
||||
background: var(--bs-chill-beige);
|
||||
}
|
||||
100% {
|
||||
background: unset;
|
||||
}
|
||||
0% {
|
||||
background: var(--bs-chill-green-dark);
|
||||
}
|
||||
25% {
|
||||
background: var(--bs-chill-green);
|
||||
}
|
||||
65% {
|
||||
background: var(--bs-chill-beige);
|
||||
}
|
||||
100% {
|
||||
background: unset;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
@@ -3,54 +3,54 @@ import Modal from "ChillMainAssets/vuejs/_components/Modal.vue";
|
||||
import { reactive } from "vue";
|
||||
import HistoryButtonList from "ChillDocStoreAssets/vuejs/StoredObjectButton/HistoryButton/HistoryButtonList.vue";
|
||||
import {
|
||||
StoredObject,
|
||||
StoredObjectVersionWithPointInTime,
|
||||
StoredObject,
|
||||
StoredObjectVersionWithPointInTime,
|
||||
} from "./../../../types";
|
||||
|
||||
interface HistoryButtonListConfig {
|
||||
versions: StoredObjectVersionWithPointInTime[];
|
||||
storedObject: StoredObject;
|
||||
canEdit: boolean;
|
||||
versions: StoredObjectVersionWithPointInTime[];
|
||||
storedObject: StoredObject;
|
||||
canEdit: boolean;
|
||||
}
|
||||
|
||||
const emit = defineEmits<{
|
||||
restoreVersion: [newVersion: StoredObjectVersionWithPointInTime];
|
||||
restoreVersion: [newVersion: StoredObjectVersionWithPointInTime];
|
||||
}>();
|
||||
|
||||
interface HistoryButtonModalState {
|
||||
opened: boolean;
|
||||
opened: boolean;
|
||||
}
|
||||
|
||||
const props = defineProps<HistoryButtonListConfig>();
|
||||
const state = reactive<HistoryButtonModalState>({ opened: false });
|
||||
|
||||
const open = () => {
|
||||
state.opened = true;
|
||||
state.opened = true;
|
||||
};
|
||||
|
||||
const onRestoreVersion = (payload: {
|
||||
newVersion: StoredObjectVersionWithPointInTime;
|
||||
newVersion: StoredObjectVersionWithPointInTime;
|
||||
}) => emit("restoreVersion", payload);
|
||||
|
||||
defineExpose({ open });
|
||||
</script>
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<modal v-if="state.opened" @close="state.opened = false">
|
||||
<template v-slot:header>
|
||||
<h3>Historique des versions du document</h3>
|
||||
</template>
|
||||
<template v-slot:body>
|
||||
<p>Les versions sont conservées pendant 90 jours.</p>
|
||||
<history-button-list
|
||||
:versions="props.versions"
|
||||
:can-edit="canEdit"
|
||||
:stored-object="storedObject"
|
||||
@restore-version="onRestoreVersion"
|
||||
></history-button-list>
|
||||
</template>
|
||||
</modal>
|
||||
</Teleport>
|
||||
<Teleport to="body">
|
||||
<modal v-if="state.opened" @close="state.opened = false">
|
||||
<template v-slot:header>
|
||||
<h3>Historique des versions du document</h3>
|
||||
</template>
|
||||
<template v-slot:body>
|
||||
<p>Les versions sont conservées pendant 90 jours.</p>
|
||||
<history-button-list
|
||||
:versions="props.versions"
|
||||
:can-edit="canEdit"
|
||||
:stored-object="storedObject"
|
||||
@restore-version="onRestoreVersion"
|
||||
></history-button-list>
|
||||
</template>
|
||||
</modal>
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss"></style>
|
||||
|
@@ -1,17 +1,17 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
StoredObjectVersionPersisted,
|
||||
StoredObjectVersionWithPointInTime,
|
||||
StoredObjectVersionPersisted,
|
||||
StoredObjectVersionWithPointInTime,
|
||||
} from "../../../types";
|
||||
import { useToast } from "vue-toast-notification";
|
||||
import { restore_version } from "./api";
|
||||
|
||||
interface RestoreVersionButtonProps {
|
||||
storedObjectVersion: StoredObjectVersionPersisted;
|
||||
storedObjectVersion: StoredObjectVersionPersisted;
|
||||
}
|
||||
|
||||
const emit = defineEmits<{
|
||||
restoreVersion: [newVersion: StoredObjectVersionWithPointInTime];
|
||||
restoreVersion: [newVersion: StoredObjectVersionWithPointInTime];
|
||||
}>();
|
||||
|
||||
const props = defineProps<RestoreVersionButtonProps>();
|
||||
@@ -19,21 +19,21 @@ const props = defineProps<RestoreVersionButtonProps>();
|
||||
const $toast = useToast();
|
||||
|
||||
const restore_version_fn = async () => {
|
||||
const newVersion = await restore_version(props.storedObjectVersion);
|
||||
const newVersion = await restore_version(props.storedObjectVersion);
|
||||
|
||||
$toast.success("Version restaurée");
|
||||
emit("restoreVersion", { newVersion });
|
||||
$toast.success("Version restaurée");
|
||||
emit("restoreVersion", { newVersion });
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<button
|
||||
class="btn btn-outline-action"
|
||||
@click="restore_version_fn"
|
||||
title="Restaurer"
|
||||
>
|
||||
<i class="fa fa-rotate-left"></i> Restaurer
|
||||
</button>
|
||||
<button
|
||||
class="btn btn-outline-action"
|
||||
@click="restore_version_fn"
|
||||
title="Restaurer"
|
||||
>
|
||||
<i class="fa fa-rotate-left"></i> Restaurer
|
||||
</button>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss"></style>
|
||||
|
@@ -1,33 +1,33 @@
|
||||
import {
|
||||
StoredObject,
|
||||
StoredObjectVersionPersisted,
|
||||
StoredObjectVersionWithPointInTime,
|
||||
StoredObject,
|
||||
StoredObjectVersionPersisted,
|
||||
StoredObjectVersionWithPointInTime,
|
||||
} from "../../../types";
|
||||
import {
|
||||
fetchResults,
|
||||
makeFetch,
|
||||
fetchResults,
|
||||
makeFetch,
|
||||
} from "../../../../../../ChillMainBundle/Resources/public/lib/api/apiMethods";
|
||||
|
||||
export const get_versions = async (
|
||||
storedObject: StoredObject,
|
||||
storedObject: StoredObject,
|
||||
): Promise<StoredObjectVersionWithPointInTime[]> => {
|
||||
const versions = await fetchResults<StoredObjectVersionWithPointInTime>(
|
||||
`/api/1.0/doc-store/stored-object/${storedObject.uuid}/versions`,
|
||||
);
|
||||
const versions = await fetchResults<StoredObjectVersionWithPointInTime>(
|
||||
`/api/1.0/doc-store/stored-object/${storedObject.uuid}/versions`,
|
||||
);
|
||||
|
||||
return versions.sort(
|
||||
(
|
||||
a: StoredObjectVersionWithPointInTime,
|
||||
b: StoredObjectVersionWithPointInTime,
|
||||
) => b.version - a.version,
|
||||
);
|
||||
return versions.sort(
|
||||
(
|
||||
a: StoredObjectVersionWithPointInTime,
|
||||
b: StoredObjectVersionWithPointInTime,
|
||||
) => b.version - a.version,
|
||||
);
|
||||
};
|
||||
|
||||
export const restore_version = async (
|
||||
version: StoredObjectVersionPersisted,
|
||||
version: StoredObjectVersionPersisted,
|
||||
): Promise<StoredObjectVersionWithPointInTime> => {
|
||||
return await makeFetch<null, StoredObjectVersionWithPointInTime>(
|
||||
"POST",
|
||||
`/api/1.0/doc-store/stored-object/restore-from-version/${version.id}`,
|
||||
);
|
||||
return await makeFetch<null, StoredObjectVersionWithPointInTime>(
|
||||
"POST",
|
||||
`/api/1.0/doc-store/stored-object/restore-from-version/${version.id}`,
|
||||
);
|
||||
};
|
||||
|
@@ -1,29 +1,27 @@
|
||||
<template>
|
||||
<a
|
||||
:class="Object.assign(props.classes, { btn: true })"
|
||||
@click="beforeLeave($event)"
|
||||
:href="
|
||||
build_wopi_editor_link(props.storedObject.uuid, props.returnPath)
|
||||
"
|
||||
>
|
||||
<i class="fa fa-paragraph"></i>
|
||||
Editer en ligne
|
||||
</a>
|
||||
<a
|
||||
:class="Object.assign(props.classes, { btn: true })"
|
||||
@click="beforeLeave($event)"
|
||||
:href="build_wopi_editor_link(props.storedObject.uuid, props.returnPath)"
|
||||
>
|
||||
<i class="fa fa-paragraph"></i>
|
||||
Editer en ligne
|
||||
</a>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import WopiEditButton from "./WopiEditButton.vue";
|
||||
import { build_wopi_editor_link } from "./helpers";
|
||||
import {
|
||||
StoredObject,
|
||||
WopiEditButtonExecutableBeforeLeaveFunction,
|
||||
StoredObject,
|
||||
WopiEditButtonExecutableBeforeLeaveFunction,
|
||||
} from "../../types";
|
||||
|
||||
interface WopiEditButtonConfig {
|
||||
storedObject: StoredObject;
|
||||
returnPath?: string;
|
||||
classes: Record<string, boolean>;
|
||||
executeBeforeLeave?: WopiEditButtonExecutableBeforeLeaveFunction;
|
||||
storedObject: StoredObject;
|
||||
returnPath?: string;
|
||||
classes: Record<string, boolean>;
|
||||
executeBeforeLeave?: WopiEditButtonExecutableBeforeLeaveFunction;
|
||||
}
|
||||
|
||||
const props = defineProps<WopiEditButtonConfig>();
|
||||
@@ -31,24 +29,24 @@ const props = defineProps<WopiEditButtonConfig>();
|
||||
let executed = false;
|
||||
|
||||
async function beforeLeave(event: Event): Promise<true> {
|
||||
if (props.executeBeforeLeave === undefined || executed === true) {
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
await props.executeBeforeLeave();
|
||||
executed = true;
|
||||
|
||||
const link = event.target as HTMLAnchorElement;
|
||||
link.click();
|
||||
|
||||
if (props.executeBeforeLeave === undefined || executed === true) {
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
await props.executeBeforeLeave();
|
||||
executed = true;
|
||||
|
||||
const link = event.target as HTMLAnchorElement;
|
||||
link.click();
|
||||
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
i.fa::before {
|
||||
color: var(--bs-dropdown-link-hover-color);
|
||||
color: var(--bs-dropdown-link-hover-color);
|
||||
}
|
||||
</style>
|
||||
|
@@ -1,235 +1,230 @@
|
||||
import {
|
||||
StoredObject,
|
||||
StoredObjectStatus,
|
||||
StoredObjectStatusChange,
|
||||
StoredObjectVersion,
|
||||
StoredObject,
|
||||
StoredObjectStatus,
|
||||
StoredObjectStatusChange,
|
||||
StoredObjectVersion,
|
||||
} from "../../types";
|
||||
import { makeFetch } from "../../../../../ChillMainBundle/Resources/public/lib/api/apiMethods";
|
||||
|
||||
const MIMES_EDIT = new Set([
|
||||
"application/vnd.ms-powerpoint",
|
||||
"application/vnd.ms-excel",
|
||||
"application/vnd.oasis.opendocument.text",
|
||||
"application/vnd.oasis.opendocument.text-flat-xml",
|
||||
"application/vnd.oasis.opendocument.spreadsheet",
|
||||
"application/vnd.oasis.opendocument.spreadsheet-flat-xml",
|
||||
"application/vnd.oasis.opendocument.presentation",
|
||||
"application/vnd.oasis.opendocument.presentation-flat-xml",
|
||||
"application/vnd.oasis.opendocument.graphics",
|
||||
"application/vnd.oasis.opendocument.graphics-flat-xml",
|
||||
"application/vnd.oasis.opendocument.chart",
|
||||
"application/msword",
|
||||
"application/vnd.ms-excel",
|
||||
"application/vnd.ms-powerpoint",
|
||||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
"application/vnd.ms-word.document.macroEnabled.12",
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
"application/vnd.ms-excel.sheet.binary.macroEnabled.12",
|
||||
"application/vnd.ms-excel.sheet.macroEnabled.12",
|
||||
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
||||
"application/vnd.ms-powerpoint.presentation.macroEnabled.12",
|
||||
"application/x-dif-document",
|
||||
"text/spreadsheet",
|
||||
"text/csv",
|
||||
"application/x-dbase",
|
||||
"text/rtf",
|
||||
"text/plain",
|
||||
"application/vnd.openxmlformats-officedocument.presentationml.slideshow",
|
||||
"application/vnd.ms-powerpoint",
|
||||
"application/vnd.ms-excel",
|
||||
"application/vnd.oasis.opendocument.text",
|
||||
"application/vnd.oasis.opendocument.text-flat-xml",
|
||||
"application/vnd.oasis.opendocument.spreadsheet",
|
||||
"application/vnd.oasis.opendocument.spreadsheet-flat-xml",
|
||||
"application/vnd.oasis.opendocument.presentation",
|
||||
"application/vnd.oasis.opendocument.presentation-flat-xml",
|
||||
"application/vnd.oasis.opendocument.graphics",
|
||||
"application/vnd.oasis.opendocument.graphics-flat-xml",
|
||||
"application/vnd.oasis.opendocument.chart",
|
||||
"application/msword",
|
||||
"application/vnd.ms-excel",
|
||||
"application/vnd.ms-powerpoint",
|
||||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
"application/vnd.ms-word.document.macroEnabled.12",
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
"application/vnd.ms-excel.sheet.binary.macroEnabled.12",
|
||||
"application/vnd.ms-excel.sheet.macroEnabled.12",
|
||||
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
||||
"application/vnd.ms-powerpoint.presentation.macroEnabled.12",
|
||||
"application/x-dif-document",
|
||||
"text/spreadsheet",
|
||||
"text/csv",
|
||||
"application/x-dbase",
|
||||
"text/rtf",
|
||||
"text/plain",
|
||||
"application/vnd.openxmlformats-officedocument.presentationml.slideshow",
|
||||
]);
|
||||
|
||||
const MIMES_VIEW = new Set([
|
||||
...MIMES_EDIT,
|
||||
[
|
||||
"image/svg+xml",
|
||||
"application/vnd.sun.xml.writer",
|
||||
"application/vnd.sun.xml.calc",
|
||||
"application/vnd.sun.xml.impress",
|
||||
"application/vnd.sun.xml.draw",
|
||||
"application/vnd.sun.xml.writer.global",
|
||||
"application/vnd.sun.xml.writer.template",
|
||||
"application/vnd.sun.xml.calc.template",
|
||||
"application/vnd.sun.xml.impress.template",
|
||||
"application/vnd.sun.xml.draw.template",
|
||||
"application/vnd.oasis.opendocument.text-master",
|
||||
"application/vnd.oasis.opendocument.text-template",
|
||||
"application/vnd.oasis.opendocument.text-master-template",
|
||||
"application/vnd.oasis.opendocument.spreadsheet-template",
|
||||
"application/vnd.oasis.opendocument.presentation-template",
|
||||
"application/vnd.oasis.opendocument.graphics-template",
|
||||
"application/vnd.ms-word.template.macroEnabled.12",
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.template",
|
||||
"application/vnd.ms-excel.template.macroEnabled.12",
|
||||
"application/vnd.openxmlformats-officedocument.presentationml.template",
|
||||
"application/vnd.ms-powerpoint.template.macroEnabled.12",
|
||||
"application/vnd.wordperfect",
|
||||
"application/x-aportisdoc",
|
||||
"application/x-hwp",
|
||||
"application/vnd.ms-works",
|
||||
"application/x-mswrite",
|
||||
"application/vnd.lotus-1-2-3",
|
||||
"image/cgm",
|
||||
"image/vnd.dxf",
|
||||
"image/x-emf",
|
||||
"image/x-wmf",
|
||||
"application/coreldraw",
|
||||
"application/vnd.visio2013",
|
||||
"application/vnd.visio",
|
||||
"application/vnd.ms-visio.drawing",
|
||||
"application/x-mspublisher",
|
||||
"application/x-sony-bbeb",
|
||||
"application/x-gnumeric",
|
||||
"application/macwriteii",
|
||||
"application/x-iwork-numbers-sffnumbers",
|
||||
"application/vnd.oasis.opendocument.text-web",
|
||||
"application/x-pagemaker",
|
||||
"application/x-fictionbook+xml",
|
||||
"application/clarisworks",
|
||||
"image/x-wpg",
|
||||
"application/x-iwork-pages-sffpages",
|
||||
"application/x-iwork-keynote-sffkey",
|
||||
"application/x-abiword",
|
||||
"image/x-freehand",
|
||||
"application/vnd.sun.xml.chart",
|
||||
"application/x-t602",
|
||||
"image/bmp",
|
||||
"image/png",
|
||||
"image/gif",
|
||||
"image/tiff",
|
||||
"image/jpg",
|
||||
"image/jpeg",
|
||||
"application/pdf",
|
||||
],
|
||||
...MIMES_EDIT,
|
||||
[
|
||||
"image/svg+xml",
|
||||
"application/vnd.sun.xml.writer",
|
||||
"application/vnd.sun.xml.calc",
|
||||
"application/vnd.sun.xml.impress",
|
||||
"application/vnd.sun.xml.draw",
|
||||
"application/vnd.sun.xml.writer.global",
|
||||
"application/vnd.sun.xml.writer.template",
|
||||
"application/vnd.sun.xml.calc.template",
|
||||
"application/vnd.sun.xml.impress.template",
|
||||
"application/vnd.sun.xml.draw.template",
|
||||
"application/vnd.oasis.opendocument.text-master",
|
||||
"application/vnd.oasis.opendocument.text-template",
|
||||
"application/vnd.oasis.opendocument.text-master-template",
|
||||
"application/vnd.oasis.opendocument.spreadsheet-template",
|
||||
"application/vnd.oasis.opendocument.presentation-template",
|
||||
"application/vnd.oasis.opendocument.graphics-template",
|
||||
"application/vnd.ms-word.template.macroEnabled.12",
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.template",
|
||||
"application/vnd.ms-excel.template.macroEnabled.12",
|
||||
"application/vnd.openxmlformats-officedocument.presentationml.template",
|
||||
"application/vnd.ms-powerpoint.template.macroEnabled.12",
|
||||
"application/vnd.wordperfect",
|
||||
"application/x-aportisdoc",
|
||||
"application/x-hwp",
|
||||
"application/vnd.ms-works",
|
||||
"application/x-mswrite",
|
||||
"application/vnd.lotus-1-2-3",
|
||||
"image/cgm",
|
||||
"image/vnd.dxf",
|
||||
"image/x-emf",
|
||||
"image/x-wmf",
|
||||
"application/coreldraw",
|
||||
"application/vnd.visio2013",
|
||||
"application/vnd.visio",
|
||||
"application/vnd.ms-visio.drawing",
|
||||
"application/x-mspublisher",
|
||||
"application/x-sony-bbeb",
|
||||
"application/x-gnumeric",
|
||||
"application/macwriteii",
|
||||
"application/x-iwork-numbers-sffnumbers",
|
||||
"application/vnd.oasis.opendocument.text-web",
|
||||
"application/x-pagemaker",
|
||||
"application/x-fictionbook+xml",
|
||||
"application/clarisworks",
|
||||
"image/x-wpg",
|
||||
"application/x-iwork-pages-sffpages",
|
||||
"application/x-iwork-keynote-sffkey",
|
||||
"application/x-abiword",
|
||||
"image/x-freehand",
|
||||
"application/vnd.sun.xml.chart",
|
||||
"application/x-t602",
|
||||
"image/bmp",
|
||||
"image/png",
|
||||
"image/gif",
|
||||
"image/tiff",
|
||||
"image/jpg",
|
||||
"image/jpeg",
|
||||
"application/pdf",
|
||||
],
|
||||
]);
|
||||
|
||||
export interface SignedUrlGet {
|
||||
method: "GET" | "HEAD";
|
||||
url: string;
|
||||
expires: number;
|
||||
object_name: string;
|
||||
method: "GET" | "HEAD";
|
||||
url: string;
|
||||
expires: number;
|
||||
object_name: string;
|
||||
}
|
||||
|
||||
function is_extension_editable(mimeType: string): boolean {
|
||||
return MIMES_EDIT.has(mimeType);
|
||||
return MIMES_EDIT.has(mimeType);
|
||||
}
|
||||
|
||||
function is_extension_viewable(mimeType: string): boolean {
|
||||
return MIMES_VIEW.has(mimeType);
|
||||
return MIMES_VIEW.has(mimeType);
|
||||
}
|
||||
|
||||
function build_convert_link(uuid: string) {
|
||||
return `/chill/wopi/convert/${uuid}`;
|
||||
return `/chill/wopi/convert/${uuid}`;
|
||||
}
|
||||
|
||||
function build_download_info_link(
|
||||
storedObject: StoredObject,
|
||||
atVersion: null | StoredObjectVersion,
|
||||
storedObject: StoredObject,
|
||||
atVersion: null | StoredObjectVersion,
|
||||
): string {
|
||||
const url = `/api/1.0/doc-store/async-upload/temp_url/${storedObject.uuid}/generate/get`;
|
||||
const url = `/api/1.0/doc-store/async-upload/temp_url/${storedObject.uuid}/generate/get`;
|
||||
|
||||
if (null !== atVersion) {
|
||||
const params = new URLSearchParams({ version: atVersion.filename });
|
||||
if (null !== atVersion) {
|
||||
const params = new URLSearchParams({ version: atVersion.filename });
|
||||
|
||||
return url + "?" + params.toString();
|
||||
}
|
||||
return url + "?" + params.toString();
|
||||
}
|
||||
|
||||
return url;
|
||||
return url;
|
||||
}
|
||||
|
||||
async function download_info_link(
|
||||
storedObject: StoredObject,
|
||||
atVersion: null | StoredObjectVersion,
|
||||
storedObject: StoredObject,
|
||||
atVersion: null | StoredObjectVersion,
|
||||
): Promise<SignedUrlGet> {
|
||||
return makeFetch("GET", build_download_info_link(storedObject, atVersion));
|
||||
return makeFetch("GET", build_download_info_link(storedObject, atVersion));
|
||||
}
|
||||
|
||||
function build_wopi_editor_link(uuid: string, returnPath?: string) {
|
||||
if (returnPath === undefined) {
|
||||
returnPath =
|
||||
window.location.pathname +
|
||||
window.location.search +
|
||||
window.location.hash;
|
||||
}
|
||||
if (returnPath === undefined) {
|
||||
returnPath =
|
||||
window.location.pathname + window.location.search + window.location.hash;
|
||||
}
|
||||
|
||||
return (
|
||||
`/chill/wopi/edit/${uuid}?returnPath=` + encodeURIComponent(returnPath)
|
||||
);
|
||||
return (
|
||||
`/chill/wopi/edit/${uuid}?returnPath=` + encodeURIComponent(returnPath)
|
||||
);
|
||||
}
|
||||
|
||||
function download_doc(url: string): Promise<Blob> {
|
||||
return window.fetch(url).then((r) => {
|
||||
if (r.ok) {
|
||||
return r.blob();
|
||||
}
|
||||
return window.fetch(url).then((r) => {
|
||||
if (r.ok) {
|
||||
return r.blob();
|
||||
}
|
||||
|
||||
throw new Error("Could not download document");
|
||||
});
|
||||
throw new Error("Could not download document");
|
||||
});
|
||||
}
|
||||
|
||||
async function download_and_decrypt_doc(
|
||||
storedObject: StoredObject,
|
||||
atVersion: null | StoredObjectVersion,
|
||||
storedObject: StoredObject,
|
||||
atVersion: null | StoredObjectVersion,
|
||||
): Promise<Blob> {
|
||||
const algo = "AES-CBC";
|
||||
const algo = "AES-CBC";
|
||||
|
||||
const atVersionToDownload = atVersion ?? storedObject.currentVersion;
|
||||
const atVersionToDownload = atVersion ?? storedObject.currentVersion;
|
||||
|
||||
if (null === atVersionToDownload) {
|
||||
throw new Error("no version associated to stored object");
|
||||
}
|
||||
if (null === atVersionToDownload) {
|
||||
throw new Error("no version associated to stored object");
|
||||
}
|
||||
|
||||
// sometimes, the downloadInfo may be embedded into the storedObject
|
||||
console.log("storedObject", storedObject);
|
||||
let downloadInfo;
|
||||
if (
|
||||
typeof storedObject._links !== "undefined" &&
|
||||
typeof storedObject._links.downloadLink !== "undefined"
|
||||
) {
|
||||
downloadInfo = storedObject._links.downloadLink;
|
||||
} else {
|
||||
downloadInfo = await download_info_link(
|
||||
storedObject,
|
||||
atVersionToDownload,
|
||||
);
|
||||
}
|
||||
// sometimes, the downloadInfo may be embedded into the storedObject
|
||||
console.log("storedObject", storedObject);
|
||||
let downloadInfo;
|
||||
if (
|
||||
typeof storedObject._links !== "undefined" &&
|
||||
typeof storedObject._links.downloadLink !== "undefined"
|
||||
) {
|
||||
downloadInfo = storedObject._links.downloadLink;
|
||||
} else {
|
||||
downloadInfo = await download_info_link(storedObject, atVersionToDownload);
|
||||
}
|
||||
|
||||
const rawResponse = await window.fetch(downloadInfo.url);
|
||||
const rawResponse = await window.fetch(downloadInfo.url);
|
||||
|
||||
if (!rawResponse.ok) {
|
||||
throw new Error(
|
||||
"error while downloading raw file " +
|
||||
rawResponse.status +
|
||||
" " +
|
||||
rawResponse.statusText,
|
||||
);
|
||||
}
|
||||
if (!rawResponse.ok) {
|
||||
throw new Error(
|
||||
"error while downloading raw file " +
|
||||
rawResponse.status +
|
||||
" " +
|
||||
rawResponse.statusText,
|
||||
);
|
||||
}
|
||||
|
||||
if (atVersionToDownload.iv.length === 0) {
|
||||
return rawResponse.blob();
|
||||
}
|
||||
if (atVersionToDownload.iv.length === 0) {
|
||||
return rawResponse.blob();
|
||||
}
|
||||
|
||||
const rawBuffer = await rawResponse.arrayBuffer();
|
||||
try {
|
||||
const key = await window.crypto.subtle.importKey(
|
||||
"jwk",
|
||||
atVersionToDownload.keyInfos,
|
||||
{ name: algo },
|
||||
false,
|
||||
["decrypt"],
|
||||
);
|
||||
const iv = Uint8Array.from(atVersionToDownload.iv);
|
||||
const decrypted = await window.crypto.subtle.decrypt(
|
||||
{ name: algo, iv: iv },
|
||||
key,
|
||||
rawBuffer,
|
||||
);
|
||||
const rawBuffer = await rawResponse.arrayBuffer();
|
||||
try {
|
||||
const key = await window.crypto.subtle.importKey(
|
||||
"jwk",
|
||||
atVersionToDownload.keyInfos,
|
||||
{ name: algo },
|
||||
false,
|
||||
["decrypt"],
|
||||
);
|
||||
const iv = Uint8Array.from(atVersionToDownload.iv);
|
||||
const decrypted = await window.crypto.subtle.decrypt(
|
||||
{ name: algo, iv: iv },
|
||||
key,
|
||||
rawBuffer,
|
||||
);
|
||||
|
||||
return Promise.resolve(new Blob([decrypted]));
|
||||
} catch (e) {
|
||||
console.error("encounter error while keys and decrypt operations");
|
||||
console.error(e);
|
||||
return Promise.resolve(new Blob([decrypted]));
|
||||
} catch (e) {
|
||||
console.error("encounter error while keys and decrypt operations");
|
||||
console.error(e);
|
||||
|
||||
throw e;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -239,48 +234,45 @@ async function download_and_decrypt_doc(
|
||||
* storage.
|
||||
*/
|
||||
async function download_doc_as_pdf(storedObject: StoredObject): Promise<Blob> {
|
||||
if (null === storedObject.currentVersion) {
|
||||
throw new Error("the stored object does not count any version");
|
||||
}
|
||||
if (null === storedObject.currentVersion) {
|
||||
throw new Error("the stored object does not count any version");
|
||||
}
|
||||
|
||||
if (storedObject.currentVersion?.type === "application/pdf") {
|
||||
return download_and_decrypt_doc(
|
||||
storedObject,
|
||||
storedObject.currentVersion,
|
||||
);
|
||||
}
|
||||
if (storedObject.currentVersion?.type === "application/pdf") {
|
||||
return download_and_decrypt_doc(storedObject, storedObject.currentVersion);
|
||||
}
|
||||
|
||||
const convertLink = build_convert_link(storedObject.uuid);
|
||||
const response = await fetch(convertLink);
|
||||
const convertLink = build_convert_link(storedObject.uuid);
|
||||
const response = await fetch(convertLink);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Could not convert the document: " + response.status);
|
||||
}
|
||||
if (!response.ok) {
|
||||
throw new Error("Could not convert the document: " + response.status);
|
||||
}
|
||||
|
||||
return response.blob();
|
||||
return response.blob();
|
||||
}
|
||||
|
||||
async function is_object_ready(
|
||||
storedObject: StoredObject,
|
||||
storedObject: StoredObject,
|
||||
): Promise<StoredObjectStatusChange> {
|
||||
const new_status_response = await window.fetch(
|
||||
`/api/1.0/doc-store/stored-object/${storedObject.uuid}/is-ready`,
|
||||
);
|
||||
const new_status_response = await window.fetch(
|
||||
`/api/1.0/doc-store/stored-object/${storedObject.uuid}/is-ready`,
|
||||
);
|
||||
|
||||
if (!new_status_response.ok) {
|
||||
throw new Error("could not fetch the new status");
|
||||
}
|
||||
if (!new_status_response.ok) {
|
||||
throw new Error("could not fetch the new status");
|
||||
}
|
||||
|
||||
return await new_status_response.json();
|
||||
return await new_status_response.json();
|
||||
}
|
||||
|
||||
export {
|
||||
build_convert_link,
|
||||
build_wopi_editor_link,
|
||||
download_and_decrypt_doc,
|
||||
download_doc,
|
||||
download_doc_as_pdf,
|
||||
is_extension_editable,
|
||||
is_extension_viewable,
|
||||
is_object_ready,
|
||||
build_convert_link,
|
||||
build_wopi_editor_link,
|
||||
download_and_decrypt_doc,
|
||||
download_doc,
|
||||
download_doc_as_pdf,
|
||||
is_extension_editable,
|
||||
is_extension_viewable,
|
||||
is_object_ready,
|
||||
};
|
||||
|
Reference in New Issue
Block a user