Skip to content

refactor: use webdav endpoint #821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 24 additions & 12 deletions addon/components/single-document-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }) {
Expand Down Expand Up @@ -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");
}
Expand Down
4 changes: 4 additions & 0 deletions addon/services/alexandria-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down
27 changes: 27 additions & 0 deletions tests/integration/components/single-document-details-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`<SingleDocumentDetails @document={{this.selectedDocument}} />`,
);

assert.dom("[data-test-web-dav-button]").doesNotExist();

this.selectedDocument = {
latestFile: {
value: {
mimeType:
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
},
},
};

await render(
hbs`<SingleDocumentDetails @document={{this.selectedDocument}} />`,
);

assert.dom("[data-test-web-dav-button]").exists();
});
});
1 change: 1 addition & 0 deletions translations/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
1 change: 1 addition & 0 deletions translations/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading