Skip to content

Commit 2132ccb

Browse files
committed
Enhance create-a-print-job action with new options and utility function
- Added 'removeLettersSeries' and updated 'removeLettersWithPhrase' properties to the create-a-print-job action for improved letter management. - Introduced 'parseObject' utility function to handle parsing of letter series input. - Updated form data submission to include new properties for better API interaction.
1 parent 2426314 commit 2132ccb

File tree

2 files changed

+80
-5
lines changed

2 files changed

+80
-5
lines changed

components/intelliprint/actions/create-a-print-job/create-a-print-job.mjs

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import {
1010
POSTAGE_SERVICE_OPTIONS,
1111
SPLITTING_METHOD_OPTIONS,
1212
} from "../../common/constants.mjs";
13-
import { camelCaseToSnakeCase } from "../../common/utils.mjs";
13+
import {
14+
camelCaseToSnakeCase, parseObject,
15+
} from "../../common/utils.mjs";
1416
import intelliprint from "../../intelliprint.app.mjs";
1517

1618
export default {
@@ -125,16 +127,22 @@ export default {
125127
description: "Whether to mark letters of this Print Job as confidential.",
126128
optional: true,
127129
},
128-
removeLetters: {
130+
removeLettersWithPhrase: {
129131
type: "string",
130-
label: "Remove Letters",
132+
label: "Remove Letters With Phrase",
131133
description: "Remove letter objects that have this phrase in their content.",
132134
optional: true,
133135
},
136+
removeLettersSeries: {
137+
type: "string",
138+
label: "Remove Letters Series",
139+
description: "An array of letters' indexes that have been removed.",
140+
optional: true,
141+
},
134142
nudgeX: {
135143
type: "integer",
136-
label: "Nudge X",
137-
description: "What amount in mm to move the first page of each letter horizontally. A positive number moves the page right, a negative number moves the page left.",
144+
label: "Remove Letters Series",
145+
description: "An array of letters' indexes that have been removed.",
138146
optional: true,
139147
},
140148
nudgeY: {
@@ -168,6 +176,21 @@ export default {
168176
intelliprint,
169177
filePath,
170178
syncDir,
179+
splittingMethod,
180+
splitOnPhrase,
181+
splitOnPage,
182+
doubleSided,
183+
doubleSidedSpecificPages,
184+
premiumQuality,
185+
postageService,
186+
idealEnvelope,
187+
mailDate,
188+
firstPageBackground,
189+
otherPagesBackground,
190+
nudgeX,
191+
nudgeY,
192+
removeLettersWithPhrase,
193+
removeLettersSeries,
171194
...data
172195
} = this;
173196

@@ -181,6 +204,33 @@ export default {
181204
knownLength: metadata.size,
182205
filename: metadata.name,
183206
});
207+
formData.append("printing", JSON.stringify({
208+
double_sided: doubleSided,
209+
double_sided_specific_pages: doubleSidedSpecificPages,
210+
premium_quality: premiumQuality,
211+
}));
212+
formData.append("splitting", JSON.stringify({
213+
method: splittingMethod,
214+
phrase: splitOnPhrase,
215+
pages: splitOnPage,
216+
}));
217+
formData.append("postage", JSON.stringify({
218+
service: postageService,
219+
ideal_envelope: idealEnvelope,
220+
mail_date: mailDate,
221+
}));
222+
formData.append("backgrounds", JSON.stringify({
223+
first_page: firstPageBackground,
224+
other_pages: otherPagesBackground,
225+
}));
226+
formData.append("nudge", JSON.stringify({
227+
x: nudgeX,
228+
y: nudgeY,
229+
}));
230+
formData.append("remove_letters", JSON.stringify({
231+
with_phrase: removeLettersWithPhrase,
232+
series: parseObject(removeLettersSeries),
233+
}));
184234
for (const [
185235
key,
186236
value,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return item;
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
return obj;
24+
};
25+
126
export const camelCaseToSnakeCase = (str) => {
227
return str?.replace(/([A-Z])/g, "_$1").toLowerCase();
328
};

0 commit comments

Comments
 (0)