Skip to content

Commit

Permalink
feat: add web dav edit integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Yelinz committed Mar 1, 2024
1 parent 74d7f50 commit 3267227
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 20 deletions.
17 changes: 15 additions & 2 deletions addon/components/single-document-details.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,20 @@
</ul>
</div>

<div class="uk-grid uk-grid-small {{if this.displayConvertButton 'uk-child-width-1-3' 'uk-child-width-1-2'}}" uk-grid>
<div class="uk-grid uk-grid-small uk-child-width-1-2" uk-grid>
{{#if this.displayWebDAVButton}}
<div>
<UkButton
@size="small"
class="uk-width-1"
@onClick={{this.openWebDAV.perform}}
data-test-web-dav-button
>
{{t "alexandria.document-details.web-dav"}}
</UkButton>
</div>
{{/if}}

{{#if this.displayConvertButton}}
<div>
<UkButton
Expand Down Expand Up @@ -269,4 +282,4 @@
</ul>

<TagManager @documents={{array @document}} />
</div>
</div>
53 changes: 35 additions & 18 deletions addon/components/single-document-details.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import { tracked } from "@glimmer/tracking";
import { restartableTask, dropTask } from "ember-concurrency";
import { task } from "ember-concurrency";
import lang from "flatpickr/dist/l10n";
import { DateTime } from "luxon";

Expand Down Expand Up @@ -40,14 +40,19 @@ export default class SingleDocumentDetailsComponent extends DocumentCard {
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;
}

get displayConvertButton() {
return (
this.config.enablePDFConversion &&
[
"application/vnd.oasis.opendocument.text",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
].includes(this.args.document.latestFile?.value?.mimeType)
);
return this.config.enablePDFConversion && this.isWordProcessingFormat;
}

@action updateDocumentTitle({ target: { value: title } }) {
Expand Down Expand Up @@ -83,38 +88,37 @@ export default class SingleDocumentDetailsComponent extends DocumentCard {
this.documents.enableShortcuts();
}

@restartableTask *saveDocument(event) {
saveDocument = task({ restartable: true }, async (event) => {
event?.preventDefault();

try {
yield this.args.document.save();
await this.args.document.save();
this.resetState();
this.notification.success(this.intl.t("alexandria.success.update"));
} catch (error) {
this.args.document.rollbackAttributes();
new ErrorHandler(this, error).notify("alexandria.errors.update");
}
}
});

@dropTask *uploadReplacement(event) {
uploadReplacement = task({ drop: true }, async (event) => {
try {
const [file] = event.target.files;
yield this.documents.replace(this.args.document, file);
await this.documents.replace(this.args.document, file);
} catch (error) {
new ErrorHandler(this, error).notify(
"alexandria.errors.replace-document",
);
}
}
});

@dropTask
*convertDocument(event) {
convertDocument = task({ drop: true }, async (event) => {
event?.preventDefault();
try {
const modelName = "document";
const adapter = this.store.adapterFor(modelName);
const url = adapter.buildURL(modelName, this.args.document.id);
yield this.fetch.fetch(`${url}/convert`, {
await this.fetch.fetch(`${url}/convert`, {
method: "POST",
});

Expand All @@ -124,5 +128,18 @@ export default class SingleDocumentDetailsComponent extends DocumentCard {
} catch (error) {
new ErrorHandler(this, error).notify("alexandria.errors.convert-pdf");
}
}
});

openWebDAV = task({ drop: true }, async (event) => {
event?.preventDefault();
try {
const fileId = this.args.document.latestFile.value.id;

const file = await this.store.findRecord("file", fileId);

window.open(file.webdavUrl, "_blank");
} catch (error) {
new ErrorHandler(this, error).notify("alexandria.errors.open-webdav");
}
})
}
1 change: 1 addition & 0 deletions addon/models/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export default class FileModel extends Model {
@attr variant;
@attr name;
@attr downloadUrl;
@attr webdavUrl;
@attr metainfo;
@attr content; // needed for upload
@attr mimeType;
Expand Down

0 comments on commit 3267227

Please sign in to comment.