Skip to content

Commit

Permalink
feat: add button to convert to pdf
Browse files Browse the repository at this point in the history
Integrates backend endpoint to convert docx, odt to pdf
  • Loading branch information
Yelinz committed Feb 21, 2024
1 parent 4dad0e1 commit e2e6951
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
14 changes: 13 additions & 1 deletion addon/components/single-document-details.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,19 @@
</ul>
</div>

<div class="uk-grid-small uk-child-width-1-2" uk-grid>
<div class="uk-grid-small {{if this.displayConvertButton 'uk-child-width-1-3' 'uk-child-width-1-2'}}" uk-grid>
{{#if this.displayConvertButton}}
<div>
<UkButton
@size="small"
class="uk-width-1"
@onClick={{perform this.convertDocument}}
>
{{t "alexandria.document-details.convert"}}
</UkButton>
</div>
{{/if}}

<div uk-form-custom>
<input
data-test-replace
Expand Down
31 changes: 28 additions & 3 deletions addon/components/single-document-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import { ErrorHandler } from "ember-alexandria/helpers/error-handler";
// TODO: This should be refactored and the SingleDocumentDetailsComponent should NOT
// be inheriting from DocumentCard
export default class SingleDocumentDetailsComponent extends DocumentCard {
@service router;
@service("alexandria-documents") documents;
@service("alexandria-tags") tags;
@service("alexandria-side-panel") sidePanel;
@service("alexandria-config") config;
@service router;
@service intl;
@service store;
@service fetch;

@tracked editTitle = false;
@tracked editDescription = false;
Expand All @@ -30,6 +31,16 @@ export default class SingleDocumentDetailsComponent extends DocumentCard {
return formats[language] ?? defaultFormat;
}

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

@action updateDocumentTitle({ target: { value: title } }) {
this.validTitle = Boolean(title);
this.args.document.title = title;
Expand Down Expand Up @@ -86,4 +97,18 @@ export default class SingleDocumentDetailsComponent extends DocumentCard {
);
}
}

@dropTask
*convertDocument(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`);
this.notification.success(this.intl.t("alexandria.success.covert-pdf"));
} catch (error) {
new ErrorHandler(this, error).notify("alexandria.errors.convert-pdf");
}
}
}
3 changes: 2 additions & 1 deletion addon/models/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export default class FileModel extends Model {
@attr name;
@attr downloadUrl;
@attr metainfo;
@attr content;
@attr content; // needed for upload
@attr mimeType;
@attr checksum;

@attr createdAt;
Expand Down
6 changes: 6 additions & 0 deletions addon/services/alexandria-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import Service from "@ember/service";
import { tracked } from "@glimmer/tracking";

export default class AlexandriaConfigService extends Service {
namespace = undefined;
zipDownloadHost = undefined;
zipDownloadNamespace = undefined;

enableConversion = true;

markIcons = {};

@tracked alexandriaQueryParams = {};
Expand Down
3 changes: 3 additions & 0 deletions translations/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ alexandria:
update: "Your changes chould'nt be saved. Please try again."
no-permission: "You don't have permission to perform this action."
move-document: "While moving {count, plural, one {the document} other {# documents}}, an error occured. Please try again."
covert-pdf: "While converting, an error occured. Please try again."

success:
delete-document: "Document deleted successfully"
Expand All @@ -30,6 +31,7 @@ alexandria:
} uploaded successfully.
update: "Changes saved."
move-document: "{count, plural, one {Document} other {# documents}} moved successfully"
covert-pdf: "Document converted successfully."

category-nav:
all-files: "All documents"
Expand Down Expand Up @@ -70,6 +72,7 @@ alexandria:
created-by-user: "Created by user"
created-by-group: "Created by group"
replace: "Replace"
convert: "To PDF"
tags:
title: "Tags"
add: "Add"
Expand Down

0 comments on commit e2e6951

Please sign in to comment.