diff --git a/client-tauri/src/components/fields/GenericField.tsx b/client-tauri/src/components/fields/GenericField.tsx
index 58f815002..638346950 100644
--- a/client-tauri/src/components/fields/GenericField.tsx
+++ b/client-tauri/src/components/fields/GenericField.tsx
@@ -67,18 +67,35 @@ export function GenericField({ fieldName, joiDefinition }: GenericFieldProps) {
const item: Joi.Description = joiDefinition.items[0];
if(item.type == "number") {
- if(item.rules.length == 1) {
- return (
-
-
-
-
-
- );
- }
- else {
- return (
comma_array, item rules are empty or bigger than one, this is not implemented.
);
- }
+ const props: any = {};
+
+ item.rules.forEach((rule: { args: any, name: string}) => {
+
+ switch (rule.name) {
+ case "integer":
+ if(props.pattern) {
+ return (props.pattern was already set, this is not implemented.
);
+ }
+ props.pattern = `(\\d+)(,\\s*\\d+)*`;
+ break;
+ case "min":
+ // TODO: Could validate this in frontend first.
+ break;
+ case "max":
+ // TODO: Could validate this in frontend first.
+ break;
+ default:
+ return (comma_array, item rule {rule.name} is not implemented.
);
+ }
+ });
+
+ return (
+
+
+
+
+
+ );
}
else {
return (comma_array, other types than numbers are not implemented yet.
);
@@ -89,6 +106,14 @@ export function GenericField({ fieldName, joiDefinition }: GenericFieldProps) {
return (comma_array, joi items are empty or bigger than one, this is not implemented
);
}
break;
+ case "alternatives":
+ return (
+
+
+
+
+
+ );
default:
console.log(joiDefinition);
return (GenericField.tsx:
"{fieldName}": requested type "{joiDefinition.type}" not found. Check console for further info.
)
diff --git a/client-tauri/src/pages/Dynamic.tsx b/client-tauri/src/pages/Dynamic.tsx
index 369ecd56a..182931c66 100644
--- a/client-tauri/src/pages/Dynamic.tsx
+++ b/client-tauri/src/pages/Dynamic.tsx
@@ -84,7 +84,7 @@ function Dynamic() {
action.values = validationResults.value.values;
const operation = new activeOperator.current(action);
operation.run(validationResults.value.input, (progress) => {
- console.log("Progress: " + progress.operationProgress);
+ console.log("OperationProgress: " + progress.operationProgress, "CurFileProgress: " + progress.curFileProgress);
}).then(async pdfFiles => {
console.log("Done");
console.log(pdfFiles);
diff --git a/shared-operations/src/functions/rotatePages.ts b/shared-operations/src/functions/rotatePages.ts
index 09218ec63..d6b203053 100644
--- a/shared-operations/src/functions/rotatePages.ts
+++ b/shared-operations/src/functions/rotatePages.ts
@@ -1,33 +1,75 @@
+import { Operator, Progress, oneToOne } from ".";
+
+import Joi from "@stirling-tools/joi";
+import { JoiPDFFileSchema } from "../wrappers/PdfFileJoi";
+
+import i18next from "i18next";
+
+import CommaArrayJoiExt from "../wrappers/CommaArrayJoiExt";
import { degrees } from "pdf-lib";
import { PdfFile, RepresentationType } from "../wrappers/PdfFile";
-export interface RotateParamsType {
- file: PdfFile;
- rotation: number|number[];
-}
+export class RotatePages extends Operator {
+ static type = "rotatePages";
-export async function rotatePages(params: RotateParamsType): Promise {
- const { file, rotation } = params;
-
- const pdfDoc = await file.pdfLibDocument;
- const pages = pdfDoc.getPages();
+ /**
+ * Validation & Localisation
+ */
- if (Array.isArray(rotation)) {
- if (rotation.length != pages.length) {
- throw new Error(`Number of given rotations '${rotation.length}' is not the same as the number of pages '${pages.length}'`);
- }
- for (let i=0; i {
- // Change page size
- const oldRotation = page.getRotation().angle;
- page.setRotation(degrees(oldRotation + rotation));
+ protected static inputSchema = JoiPDFFileSchema.label(i18next.t("inputs.pdffile.name")).description(i18next.t("inputs.pdffile.description"));
+ protected static valueSchema = Joi.object({
+ rotation: Joi.alternatives().try(
+ Joi.number().min(0).max(360).allow(null),
+ CommaArrayJoiExt.comma_array().items(Joi.number().integer().min(0).max(360))
+ ).label(i18next.t("values.rotation.friendlyName", { ns: "rotatePages" })).description(i18next.t("values.rotation.description", { ns: "rotatePages" }))
+ .example("90").example("-180").example("[90, 0, 270]"),
+ });
+ protected static outputSchema = JoiPDFFileSchema.label(i18next.t("outputs.pdffile.name")).description(i18next.t("outputs.pdffile.description"));
+
+ static schema = Joi.object({
+ input: RotatePages.inputSchema,
+ values: RotatePages.valueSchema.required(),
+ output: RotatePages.outputSchema
+ }).label(i18next.t("friendlyName", { ns: "rotatePages" })).description(i18next.t("description", { ns: "rotatePages" }));
+
+
+ /**
+ * Logic
+ */
+
+ /** Detect and remove white pages */
+ async run(input: PdfFile[], progressCallback: (state: Progress) => void): Promise {
+ return oneToOne(input, async (input, index, max) => {
+
+ const pdfDoc = await input.pdfLibDocument;
+ const pages = pdfDoc.getPages();
+
+ // Different rotations applied to each page
+ if (Array.isArray(this.actionValues.rotation)) {
+ if (this.actionValues.rotation.length != pages.length) {
+ throw new Error(`Number of given rotations '${this.actionValues.rotation.length}' is not the same as the number of pages '${pages.length}'`);
+ }
+ for (let pageIdx = 0; pageIdx < this.actionValues.rotation.length; pageIdx++) {
+ const oldRotation = pages[pageIdx].getRotation().angle;
+ pages[pageIdx].setRotation(degrees(oldRotation + this.actionValues.rotation[pageIdx]));
+
+ progressCallback({ curFileProgress: pageIdx/pages.length, operationProgress: index/max });
+ }
+ }
+ // Only one rotation applied to each page
+ else {
+ pages.forEach((page, pageIdx) => {
+ // Change page size
+ const oldRotation = page.getRotation().angle;
+ page.setRotation(degrees(oldRotation + this.actionValues.rotation));
+ progressCallback({ curFileProgress: pageIdx/pages.length, operationProgress: index/max });
+ });
+ }
+
+ progressCallback({ curFileProgress: 1, operationProgress: index/max });
+
+ return new PdfFile(input.originalFilename, pdfDoc, RepresentationType.PDFLibDocument, input.filename + "_rotated");
});
}
-
- return new PdfFile(file.originalFilename, pdfDoc, RepresentationType.PDFLibDocument, file.filename+"_rotated");
-}
\ No newline at end of file
+}