diff --git a/README.md b/README.md
index e6818a3a..46cd59bb 100644
--- a/README.md
+++ b/README.md
@@ -202,6 +202,8 @@ module.exports = function () {
### Others
- `enablePDFConversion`: Set to `true` to enable docx/odt to pdf conversion. Make sure the backend is enabled aswell.
+- `enableWebDAV`: Set to `true` to enable docx/xlsx editing with WebDAV. Make sure the backend is enabled aswell.
+- `allowedWebDAVMimeTypes`: Sets the allowed editable mime types (default: docx, xlsx). Make sure the list is the same as in the backend.
- `namespace`: Set to API namespace
- `zipDownloadHost`: Set if the ZIP download is different
- `zipDownloadNamespace`: Set if the ZIP download is namespaced
diff --git a/addon/components/single-document-details.js b/addon/components/single-document-details.js
index 5130343f..4c71d5af 100644
--- a/addon/components/single-document-details.js
+++ b/addon/components/single-document-details.js
@@ -32,19 +32,23 @@ export default class SingleDocumentDetailsComponent extends Component {
return formats[this.locale] ?? defaultFormat;
}
- get isWordProcessingFormat() {
- return [
- "application/vnd.oasis.opendocument.text",
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
- ].includes(this.args.document.latestFile?.value?.mimeType);
- }
-
get displayWebDAVButton() {
- return this.config.enableWebDAV && this.isWordProcessingFormat;
+ return (
+ this.config.enableWebDAV &&
+ this.config.allowedWebDAVMimeTypes.includes(
+ this.args.document.latestFile?.value?.mimeType,
+ )
+ );
}
get displayConvertButton() {
- return this.config.enablePDFConversion && this.isWordProcessingFormat;
+ return (
+ this.config.enablePDFConversion &&
+ [
+ "application/vnd.oasis.opendocument.text",
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
+ ].includes(this.args.document.latestFile?.value?.mimeType)
+ );
}
@action updateDocumentTitle({ target: { value: title } }) {
@@ -125,11 +129,19 @@ export default class SingleDocumentDetailsComponent extends Component {
openWebDAV = task({ drop: true }, async (event) => {
event?.preventDefault();
try {
- const fileId = this.args.document.latestFile.value.id;
+ const modelName = "document";
+ const adapter = this.store.adapterFor(modelName);
+ let url = adapter.buildURL(modelName, this.args.document.id);
+ url = url.replace("/documents", "/webdav");
+ const response = await this.fetch.fetch(url);
+
+ const webdavUrl = (await response.json()).data.attributes["webdav-url"];
- const file = await this.store.findRecord("file", fileId);
+ if (!webdavUrl) {
+ throw new Error(this.intl.t("alexandria.errors.open-webdav"));
+ }
- window.open(file.webdavUrl, "_blank");
+ window.open(webdavUrl, "_blank");
} catch (error) {
new ErrorHandler(this, error).notify("alexandria.errors.open-webdav");
}
diff --git a/addon/services/alexandria-config.js b/addon/services/alexandria-config.js
index 402c31b2..a8e657a5 100644
--- a/addon/services/alexandria-config.js
+++ b/addon/services/alexandria-config.js
@@ -8,6 +8,10 @@ export default class AlexandriaConfigService extends Service {
enablePDFConversion = false;
enableWebDAV = false;
+ allowedWebDAVMimeTypes = [
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
+ ];
markIcons = {};
diff --git a/tests/integration/components/single-document-details-test.js b/tests/integration/components/single-document-details-test.js
index 4565dad3..ba8d3fff 100644
--- a/tests/integration/components/single-document-details-test.js
+++ b/tests/integration/components/single-document-details-test.js
@@ -162,4 +162,31 @@ module("Integration | Component | single-document-details", function (hooks) {
assert.dom("[data-test-convert-button]").exists();
});
+
+ test("it renders WebDAV button", async function (assert) {
+ this.selectedDocument = {
+ latestFile: { value: { mimeType: "application/pdf" } },
+ };
+
+ await render(
+ hbs``,
+ );
+
+ assert.dom("[data-test-web-dav-button]").doesNotExist();
+
+ this.selectedDocument = {
+ latestFile: {
+ value: {
+ mimeType:
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
+ },
+ },
+ };
+
+ await render(
+ hbs``,
+ );
+
+ assert.dom("[data-test-web-dav-button]").exists();
+ });
});
diff --git a/translations/de.yaml b/translations/de.yaml
index 6d57dcb7..c3d449e8 100644
--- a/translations/de.yaml
+++ b/translations/de.yaml
@@ -23,6 +23,7 @@ alexandria:
convert-pdf: "Während dem Umwandeln ist ein Fehler aufgetreten."
invalid-file-type: 'In der Kategorie "{category}" können nur {types} hochgeladen werden.'
file-too-large: "Die hochgeladene Datei ist zu gross."
+ open-webdav: "Dokument konnte nicht zum Bearbeiten geöffnet werden."
success:
delete-document: "Das Dokument wurde erfolgreich gelöscht."
diff --git a/translations/en.yaml b/translations/en.yaml
index 13c85f80..6a10dba3 100644
--- a/translations/en.yaml
+++ b/translations/en.yaml
@@ -23,6 +23,7 @@ alexandria:
convert-pdf: "While converting, an error occured. Please try again."
invalid-file-type: 'In category "{category}" only {types} can be uploaded.'
file-too-large: "The uploaded file is too large."
+ open-webdav: "Document could not be opened to be edited."
success:
delete-document: "Document deleted successfully"