Skip to content

Commit 9d63feb

Browse files
Yelinzczosel
authored andcommitted
feat: add web dav edit integration
1 parent f75cece commit 9d63feb

File tree

7 files changed

+55
-20
lines changed

7 files changed

+55
-20
lines changed

addon/components/single-document-details.hbs

+15-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,20 @@
164164
</ul>
165165
</div>
166166

167-
<div class="uk-grid uk-grid-small {{if this.displayConvertButton 'uk-child-width-1-3' 'uk-child-width-1-2'}}" uk-grid>
167+
<div class="uk-grid uk-grid-small uk-child-width-1-2" uk-grid>
168+
{{#if this.displayWebDAVButton}}
169+
<div>
170+
<UkButton
171+
@size="small"
172+
class="uk-width-1"
173+
@onClick={{this.openWebDAV.perform}}
174+
data-test-web-dav-button
175+
>
176+
{{t "alexandria.document-details.web-dav"}}
177+
</UkButton>
178+
</div>
179+
{{/if}}
180+
168181
{{#if this.displayConvertButton}}
169182
<div>
170183
<UkButton
@@ -269,4 +282,4 @@
269282
</ul>
270283

271284
<TagManager @documents={{array @document}} />
272-
</div>
285+
</div>

addon/components/single-document-details.js

+35-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { action } from "@ember/object";
22
import { inject as service } from "@ember/service";
33
import { tracked } from "@glimmer/tracking";
4-
import { restartableTask, dropTask } from "ember-concurrency";
4+
import { task } from "ember-concurrency";
55
import lang from "flatpickr/dist/l10n";
66
import { DateTime } from "luxon";
77

@@ -40,14 +40,19 @@ export default class SingleDocumentDetailsComponent extends DocumentCard {
4040
return formats[this.locale] ?? defaultFormat;
4141
}
4242

43+
get isWordProcessingFormat() {
44+
return [
45+
"application/vnd.oasis.opendocument.text",
46+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
47+
].includes(this.args.document.latestFile?.value?.mimeType);
48+
}
49+
50+
get displayWebDAVButton() {
51+
return this.config.enableWebDAV && this.isWordProcessingFormat;
52+
}
53+
4354
get displayConvertButton() {
44-
return (
45-
this.config.enablePDFConversion &&
46-
[
47-
"application/vnd.oasis.opendocument.text",
48-
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
49-
].includes(this.args.document.latestFile?.value?.mimeType)
50-
);
55+
return this.config.enablePDFConversion && this.isWordProcessingFormat;
5156
}
5257

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

86-
@restartableTask *saveDocument(event) {
91+
saveDocument = task({ restartable: true }, async (event) => {
8792
event?.preventDefault();
8893

8994
try {
90-
yield this.args.document.save();
95+
await this.args.document.save();
9196
this.resetState();
9297
this.notification.success(this.intl.t("alexandria.success.update"));
9398
} catch (error) {
9499
this.args.document.rollbackAttributes();
95100
new ErrorHandler(this, error).notify("alexandria.errors.update");
96101
}
97-
}
102+
});
98103

99-
@dropTask *uploadReplacement(event) {
104+
uploadReplacement = task({ drop: true }, async (event) => {
100105
try {
101106
const [file] = event.target.files;
102-
yield this.documents.replace(this.args.document, file);
107+
await this.documents.replace(this.args.document, file);
103108
} catch (error) {
104109
new ErrorHandler(this, error).notify(
105110
"alexandria.errors.replace-document",
106111
);
107112
}
108-
}
113+
});
109114

110-
@dropTask
111-
*convertDocument(event) {
115+
convertDocument = task({ drop: true }, async (event) => {
112116
event?.preventDefault();
113117
try {
114118
const modelName = "document";
115119
const adapter = this.store.adapterFor(modelName);
116120
const url = adapter.buildURL(modelName, this.args.document.id);
117-
yield this.fetch.fetch(`${url}/convert`, {
121+
await this.fetch.fetch(`${url}/convert`, {
118122
method: "POST",
119123
});
120124

@@ -124,5 +128,18 @@ export default class SingleDocumentDetailsComponent extends DocumentCard {
124128
} catch (error) {
125129
new ErrorHandler(this, error).notify("alexandria.errors.convert-pdf");
126130
}
127-
}
131+
});
132+
133+
openWebDAV = task({ drop: true }, async (event) => {
134+
event?.preventDefault();
135+
try {
136+
const fileId = this.args.document.latestFile.value.id;
137+
138+
const file = await this.store.findRecord("file", fileId);
139+
140+
window.open(file.webdavUrl, "_blank");
141+
} catch (error) {
142+
new ErrorHandler(this, error).notify("alexandria.errors.open-webdav");
143+
}
144+
});
128145
}

addon/models/file.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export default class FileModel extends Model {
44
@attr variant;
55
@attr name;
66
@attr downloadUrl;
7+
@attr webdavUrl;
78
@attr metainfo;
89
@attr content; // needed for upload
910
@attr mimeType;

addon/services/alexandria-config.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default class AlexandriaConfigService extends Service {
77
zipDownloadNamespace = undefined;
88

99
enablePDFConversion = false;
10+
enableWebDAV = false;
1011

1112
markIcons = {};
1213

tests/dummy/app/services/alexandria-config.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import AlexandriaConfigService from "ember-alexandria/services/alexandria-config
55

66
export default class CustomAlexandriaConfigService extends AlexandriaConfigService {
77
enablePDFConversion = true;
8+
enableWebDAV = true;
89

910
markIcons = {
1011
decision: "stamp",

translations/de.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ alexandria:
7373
created-by-group: "Erstellt von Gruppe"
7474
replace: "Ersetzen"
7575
convert: "Zu PDF"
76+
web-dav: "Bearbeiten"
7677
tags:
7778
title: "Tags"
7879
add: "Hinzufügen"

translations/en.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ alexandria:
7373
created-by-group: "Created by group"
7474
replace: "Replace"
7575
convert: "To PDF"
76+
web-dav: "Edit"
7677
tags:
7778
title: "Tags"
7879
add: "Add"

0 commit comments

Comments
 (0)