Skip to content

Commit 2b9dd8b

Browse files
authored
feature: ask user the number of copies to print (#1213)
* api(print): add multiple copies modal * api(print): fix printDB logging and copies buttons * api(print): fix dialog css and add en translation * eslint: linted code * eslint: final fix * config(print): add setting to evalute max copies * gallery: add multiple config setting * config: add new setting default value * lint: linted php code * print: only pass copies if more than one is requested * api (print): declare copies var earlier * Fixup --------- Co-authored-by: Andreas Skomski
1 parent c5bc36b commit 2b9dd8b

File tree

10 files changed

+158
-19
lines changed

10 files changed

+158
-19
lines changed

api/print.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
$imageHandler->debugLevel = $config['dev']['loglevel'];
3434
$vars['randomName'] = $imageHandler->createNewFilename('random');
3535
$vars['fileName'] = $_GET['filename'];
36+
$vars['copies'] = $_GET['copies'];
3637
$vars['uniqueName'] = substr($vars['fileName'], 0, -4) . '-' . $vars['randomName'];
3738
$vars['sourceFile'] = FolderEnum::IMAGES->absolute() . DIRECTORY_SEPARATOR . $vars['fileName'];
3839
$vars['printFile'] = FolderEnum::PRINT->absolute() . DIRECTORY_SEPARATOR . $vars['uniqueName'];
@@ -188,7 +189,21 @@
188189
// print image
189190
$status = 'ok';
190191
$linecount = 0;
191-
$cmd = sprintf($config['commands']['print'], $vars['printFile']);
192+
$copies = (int)$vars['copies'];
193+
194+
if ($copies > 1) {
195+
$cmd = sprintf(
196+
$config['commands']['print'],
197+
$vars['copies'],
198+
$vars['printFile']
199+
);
200+
} else {
201+
$cmd = sprintf(
202+
$config['commands']['print'],
203+
$vars['printFile']
204+
);
205+
}
206+
$logger->info($cmd);
192207
$cmd .= ' 2>&1'; //Redirect stderr to stdout, otherwise error messages get lost.
193208

194209
exec($cmd, $output, $returnValue);
@@ -223,7 +238,13 @@
223238
}
224239

225240
if ($status === 'ok') {
226-
$printManager->addToPrintDb($vars['fileName'], $vars['uniqueName']);
241+
if ($copies > 1) {
242+
for ($i = 1; $i <= $copies; $i++) {
243+
$printManager->addToPrintDb($vars['fileName'], $vars['uniqueName'] . '-' . $i);
244+
}
245+
} else {
246+
$printManager->addToPrintDb($vars['fileName'], $vars['uniqueName']);
247+
}
227248

228249
if ($config['print']['limit'] > 0) {
229250
$linecount = $printManager->getPrintCountFromDB();

assets/js/chromakeying.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ function saveImage(filename, cb) {
255255
if (photoboothTools.isPrinting) {
256256
photoboothTools.console.log('Printing already in progress!');
257257
} else {
258-
photoboothTools.printImage(resp.filename, () => {
258+
photoboothTools.printImage(resp.filename, 1, () => {
259259
$('[data-command="print-btn"]').trigger('blur');
260260
});
261261
}
@@ -345,7 +345,7 @@ $(function () {
345345
if (!resp.success) {
346346
return;
347347
}
348-
photoboothTools.printImage(resp.filename, () => {
348+
photoboothTools.printImage(resp.filename, 1, () => {
349349
$('[data-command="print-btn"]').trigger('blur');
350350
});
351351
});

assets/js/core.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,19 +1119,24 @@ const photoBooth = (function () {
11191119

11201120
if (config.print.auto && config.filters.enabled === false) {
11211121
setTimeout(function () {
1122-
photoboothTools.printImage(filename, () => {
1122+
photoboothTools.printImage(filename, 1, () => {
11231123
remoteBuzzerClient.inProgress(false);
11241124
});
11251125
}, config.print.auto_delay);
11261126
}
11271127

1128-
buttonPrint.off('click').on('click', (event) => {
1128+
buttonPrint.off('click').on('click', async (event) => {
11291129
event.preventDefault();
11301130
event.stopPropagation();
1131-
photoboothTools.printImage(filename, () => {
1132-
remoteBuzzerClient.inProgress(false);
1133-
buttonPrint.trigger('blur');
1134-
});
1131+
1132+
const copies = config.print.max_multi === 1 ? 1 : await photoboothTools.askCopies();
1133+
1134+
if (copies && !isNaN(copies)) {
1135+
photoboothTools.printImage(filename, copies, () => {
1136+
remoteBuzzerClient.inProgress(false);
1137+
buttonPrint.trigger('blur');
1138+
});
1139+
}
11351140
});
11361141

11371142
resultPage

assets/js/photoswipe.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function initPhotoSwipeFromDOM(gallerySelector) {
147147
isButton: true,
148148
html: '<i class="' + config.icons.print + '"></i>',
149149

150-
onClick: (event, el, pswp) => {
150+
onClick: async (event, el, pswp) => {
151151
event.preventDefault();
152152
event.stopPropagation();
153153

@@ -156,12 +156,16 @@ function initPhotoSwipeFromDOM(gallerySelector) {
156156
} else {
157157
const img = pswp.currSlide.data.src.split('\\').pop().split('/').pop();
158158

159-
photoboothTools.printImage(img, () => {
160-
if (typeof remoteBuzzerClient !== 'undefined') {
161-
remoteBuzzerClient.inProgress(false);
162-
}
163-
pswp.close();
164-
});
159+
const copies = config.print.max_multi === 1 ? 1 : await photoboothTools.askCopies();
160+
161+
if (copies && !isNaN(copies)) {
162+
photoboothTools.printImage(img, copies, () => {
163+
if (typeof remoteBuzzerClient !== 'undefined') {
164+
remoteBuzzerClient.inProgress(false);
165+
}
166+
pswp.close();
167+
});
168+
}
165169
}
166170
}
167171
});

assets/js/tools.js

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ const photoboothTools = (function () {
145145
iconWrap.appendChild(icon);
146146
button.appendChild(iconWrap);
147147

148+
if (label === '') {
149+
return button;
150+
}
151+
148152
const labelWrap = document.createElement('span');
149153
labelWrap.classList.add(prefix + 'button--label');
150154
labelWrap.innerHTML = api.getTranslation(label);
@@ -234,6 +238,70 @@ const photoboothTools = (function () {
234238
});
235239
};
236240

241+
api.askCopies = async () => {
242+
return new Promise((resolve) => {
243+
const element = document.createElement('dialog');
244+
element.classList.add('dialog');
245+
element.classList.add('rotarygroup');
246+
247+
const message = document.createElement('div');
248+
message.classList.add('dialog-message');
249+
message.textContent = api.getTranslation('print:choose_copies');
250+
element.appendChild(message);
251+
252+
const inputSection = document.createElement('div');
253+
inputSection.classList.add('buttonbar--print-copies');
254+
const minusButton = api.button.create('', 'fa fa-minus', 'default', '');
255+
const plusButton = api.button.create('', 'fa fa-plus', 'default', '');
256+
const inputText = document.createElement('input');
257+
inputText.classList.add('form-input-copies');
258+
inputText.value = '1';
259+
minusButton.addEventListener('click', () => {
260+
const oldValue = parseInt(inputText.value, 10);
261+
inputText.value = String(Math.max(1, oldValue - 1));
262+
});
263+
plusButton.addEventListener('click', () => {
264+
const oldValue = parseInt(inputText.value, 10);
265+
inputText.value = String(Math.min(config.print.max_multi, oldValue + 1));
266+
});
267+
inputSection.append(minusButton);
268+
inputSection.append(inputText);
269+
inputSection.append(plusButton);
270+
element.append(inputSection);
271+
272+
const buttonbar = document.createElement('div');
273+
buttonbar.classList.add('dialog-buttonbar');
274+
element.appendChild(buttonbar);
275+
276+
// confirm
277+
const confirmButton = api.button.create('print', 'fa fa-check', 'default', 'dialog-');
278+
confirmButton.addEventListener('click', () => {
279+
element.close(true);
280+
element.remove();
281+
resolve(inputText.value);
282+
});
283+
buttonbar.appendChild(confirmButton);
284+
285+
// cancel
286+
const cancelButton = api.button.create('cancel', 'fa fa-times', 'default', 'dialog-');
287+
cancelButton.addEventListener('click', () => {
288+
element.close(false);
289+
element.remove();
290+
resolve(false);
291+
});
292+
buttonbar.appendChild(cancelButton);
293+
294+
element.addEventListener('cancel', function () {
295+
element.close(false);
296+
element.remove();
297+
resolve(false);
298+
});
299+
300+
document.body.append(element);
301+
element.showModal();
302+
});
303+
};
304+
237305
api.reloadPage = function () {
238306
window.location.reload();
239307
};
@@ -282,7 +350,7 @@ const photoboothTools = (function () {
282350
}, to);
283351
};
284352

285-
api.printImage = function (imageSrc, cb) {
353+
api.printImage = function (imageSrc, copies, cb) {
286354
if (api.isVideoFile(imageSrc)) {
287355
api.console.log('ERROR: An error occurred: attempt to print non printable file.');
288356
api.overlay.showError(api.getTranslation('no_printing'));
@@ -299,7 +367,8 @@ const photoboothTools = (function () {
299367
method: 'GET',
300368
url: environment.publicFolders.api + '/print.php',
301369
data: {
302-
filename: imageSrc
370+
filename: imageSrc,
371+
copies: copies
303372
},
304373
success: (data) => {
305374
api.console.log('Picture processed: ', data);

assets/sass/components/_button.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,11 @@
165165
justify-content: flex-end;
166166
}
167167
}
168+
.buttonbar--print-copies {
169+
display: flex;
170+
flex-wrap: nowrap;
171+
align-items: center;
172+
justify-content: center;
173+
gap: 0.5rem;
174+
padding: 0.5rem 1rem;
175+
}

assets/sass/components/_form.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,12 @@
1616
.form-message {
1717
margin-bottom: 0.5em;
1818
}
19+
.form-input-copies {
20+
border: 1px solid rgba(0, 0, 0, 0.5);
21+
width: 20%;
22+
border-radius: 0.25rem;
23+
padding: 0.75rem 1rem;
24+
margin-bottom: 0;
25+
font-size: 2rem;
26+
text-align: center;
27+
}

lib/configsetup.inc.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,17 @@
15301530
'range_step' => 500,
15311531
'unit' => 'milliseconds',
15321532
],
1533+
'max_multiple_prints' => [
1534+
'view' => 'advanced',
1535+
'type' => 'range',
1536+
'placeholder' => $defaultConfig['print']['max_multi'],
1537+
'name' => 'print[max_multi]',
1538+
'value' => $config['print']['max_multi'],
1539+
'range_min' => 1,
1540+
'range_max' => 10,
1541+
'range_step' => 1,
1542+
'unit' => 'empty',
1543+
],
15331544
'print_limit' => [
15341545
'view' => 'expert',
15351546
'type' => 'number',

resources/lang/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@
542542
"manual:preview:preview_videoWidth": "Enter a value which is used as width for preview by device cam.",
543543
"manual:print:button_show_cups": "Show a button on startpage to easily access CUPS (Common Unix Printing System).",
544544
"manual:print:button_show_printUnlock": "Show a button on start page to unlock print once print got locked.",
545+
"manual:print:max_multiple_prints": "If greater than 1 a dialog will appear showing the user how many copies to print. This settings define the maximum number of copies can be printed each time the button is pressed.",
545546
"manual:print:print_auto": "If enabled, the picture will immediately printed after it was taken.",
546547
"manual:print:print_auto_delay": "Enter in milliseconds by which the automatic printing of the image is delayed.",
547548
"manual:print:print_crop": "If enabled, pictures are cropped at print by given height and width (px).",
@@ -764,6 +765,8 @@
764765
"print": "Print",
765766
"print:button_show_cups": "Show CUPS button",
766767
"print:button_show_printUnlock": "Show print unlock button",
768+
"print:choose_copies": "Choose how many copies of this image to print",
769+
"print:max_multiple_prints": "Choose the maximum number of copies to print each time",
767770
"print:print_auto": "Print picture immediately after taken",
768771
"print:print_auto_delay": "Delay printing of the image",
769772
"print:print_crop": "Crop picture at print",

src/Configuration/PhotoboothConfiguration.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,15 @@ protected function addPrint(): NodeDefinition
214214
->then(function (string $value): int { return intval($value); })
215215
->end()
216216
->end()
217+
->integerNode('max_multi')
218+
->min(1)
219+
->max(10)
220+
->defaultValue(1)
221+
->beforeNormalization()
222+
->ifString()
223+
->then(function (string $value): int { return intval($value); })
224+
->end()
225+
->end()
217226
->integerNode('limit')
218227
->defaultValue(0)
219228
->beforeNormalization()

0 commit comments

Comments
 (0)