Skip to content
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

feat: add button to convert to pdf #700

Merged
merged 1 commit into from
Feb 27, 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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ module.exports = function () {
};
```

### Others

- `enablePDFConversion`: Set to `true` to enable docx/odt to pdf conversion. Make sure the backend is enabled aswell.
- `namespace`: Set to API namespace
- `zipDownloadHost`: Set if the ZIP download is different
- `zipDownloadNamespace`: Set if the ZIP download is namespaced

## Contributing

See the [Contributing](CONTRIBUTING.md) guide for details.
Expand Down
7 changes: 5 additions & 2 deletions addon/components/document-view.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="uk-flex uk-flex-middle uk-padding-small">
<DocumentUploadButton
@category={{@filters.category}}
@afterUpload={{this.afterUpload}}
@afterUpload={{this.refreshDocumentList}}
data-test-upload
/>

Expand Down Expand Up @@ -86,7 +86,10 @@
{{/if}}
</div>
</div>
<DocumentsSidePanel @selectedDocuments={{this.documents.selectedDocuments}} />
<DocumentsSidePanel
@selectedDocuments={{this.documents.selectedDocuments}}
@refreshDocumentList={{this.refreshDocumentList}}
/>
</div>

<div
Expand Down
2 changes: 1 addition & 1 deletion addon/components/document-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export default class DocumentViewComponent extends Component {
}

@action
afterUpload() {
refreshDocumentList() {
this.uploadedDocuments++;
}

Expand Down
5 changes: 4 additions & 1 deletion addon/components/documents-side-panel.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
<div class="uk-overflow-auto">
<div class="uk-padding-small">
{{#if (eq @selectedDocuments.length 1)}}
<SingleDocumentDetails @document={{object-at 0 @selectedDocuments}} />
<SingleDocumentDetails
@document={{object-at 0 @selectedDocuments}}
@refreshDocumentList={{@refreshDocumentList}}
/>
{{else}}
<MultiDocumentDetails
@selectedDocuments={{@selectedDocuments}}
Expand Down
15 changes: 14 additions & 1 deletion 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-small uk-child-width-1-2" uk-grid>
<div class="uk-grid 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}}
data-test-convert-button
>
{{t "alexandria.document-details.convert"}}
</UkButton>
</div>
{{/if}}

<div uk-form-custom>
<input
data-test-replace
Expand Down
35 changes: 33 additions & 2 deletions addon/components/single-document-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ 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-config") config;
@service("alexandria-side-panel") sidePanel;
@service router;
@service intl;
@service store;
@service fetch;

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

get displayConvertButton() {
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 } }) {
this.validTitle = Boolean(title);
this.args.document.title = title;
Expand Down Expand Up @@ -86,4 +98,23 @@ 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`, {
method: "POST",
});

this.args.refreshDocumentList();

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;

enablePDFConversion = false;

markIcons = {};

@tracked alexandriaQueryParams = {};
Expand Down
2 changes: 2 additions & 0 deletions tests/dummy/app/services/alexandria-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { macroCondition, isTesting } from "@embroider/macros";
import AlexandriaConfigService from "ember-alexandria/services/alexandria-config";

export default class CustomAlexandriaConfigService extends AlexandriaConfigService {
enablePDFConversion = true;

markIcons = {
decision: "stamp",
};
Expand Down
24 changes: 24 additions & 0 deletions tests/integration/components/single-document-details-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,28 @@ module("Integration | Component | single-document-details", function (hooks) {

assert.dom("[data-test-date]").hasText("10/31/2023");
});

test("it renders conversion", async function (assert) {
this.selectedDocument = {
latestFile: { value: { mimeType: "application/pdf" } },
};

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

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

this.selectedDocument = {
latestFile: {
value: { mimeType: "application/vnd.oasis.opendocument.text" },
},
};

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

assert.dom("[data-test-convert-button]").exists();
});
});
3 changes: 3 additions & 0 deletions translations/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ alexandria:
update: "Änderungen konnten nicht gespeichert werden. Versuchen Sie es erneut."
no-permission: "Sie haben keine Berechtigung, diese Aktion auszuführen."
move-document: "Beim Verschieben {count, plural, one {des Dokumentes} other {von # Dokumenten}} ist ein Fehler aufgetreten"
convert-pdf: "Während dem Umwandeln ist ein Fehler aufgetreten."

success:
delete-document: "Das Dokument wurde erfolgreich gelöscht."
Expand All @@ -30,6 +31,7 @@ alexandria:
} erfolgreich hochgeladen.
update: "Änderungen wurden gespeichert."
move-document: "{count, plural, one {Das Dokument wurde} other {# Dokumente wurden}} erfolgreich verschoben"
convert-pdf: "Dokument wurde erfolgreich umgewandelt."

category-nav:
all-files: "Alle Dokumente"
Expand Down Expand Up @@ -70,6 +72,7 @@ alexandria:
created-by-user: "Erstellt von Benutzer"
created-by-group: "Erstellt von Gruppe"
replace: "Ersetzen"
convert: "Zu PDF"
tags:
title: "Tags"
add: "Hinzufügen"
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."
convert-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"
convert-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
Loading