Skip to content

Commit

Permalink
Add more config options
Browse files Browse the repository at this point in the history
Added format options for A3, A4, A5, legal, letter, tabloid.
Added border settings for unit, top, right, bottom, and left.
Bump to beta-03.
  • Loading branch information
mgobat committed Feb 2, 2022
1 parent c3148c4 commit 3732ce1
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 35 deletions.
76 changes: 67 additions & 9 deletions configWindow.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
}
#infoi {
z-index: 10;
}
}
.column {
float: left;
width: 50%;
}
</style>
</head>
<body>
Expand Down Expand Up @@ -52,7 +56,7 @@
<br>
<div id="container">
<div id="addprofile" >
<div id ="newPrinterProfile" style="display:none; overflow:auto; height:250px; border:1px solid black; padding-left:15px">
<div id ="newPrinterProfile" style="display:none; overflow:auto; height:350px; border:1px solid black; padding-left:15px">
<br>
<label>Select Alma Printer Queue(s):</label>
<select id = "almaPrinter"
Expand All @@ -69,12 +73,65 @@
style="width: 545px;">
</select>
<br><br>
<input type="radio" id="portrait" name="orientation" value="portrait" checked="checked">Portrait
&emsp;<input type="radio" id="landscape" name="orientation" value="landscape">Landscape
<br>
<input type="radio" id="color" name="color" value="true" checked="checked">Color
&emsp;<input type="radio" id="grayscale" name="color" value="false" >Grayscale
<br><br>
<div class="row">
<div class="column">
<label for="letterFormat">Format:</label>
<select id = "letterFormat" name="letterFormat"
size = "1"
style="width: 75px;">
<option value="A3">A3</option>
<option value="A4">A4</option>
<option value="A5">A5</option>
<option value="Legal">Legal</option>
<option value="Letter">Letter</option>
<option value="Tabloid">Tabloid</option>
</select>
</div>
<div class="column">
<label for="borderUnits">Border unit of measure:</label>
<select id = "borderUnits" name="borderUnits"
size = "1"
style="width: 100px;">
<option value="mm">millimeters</option>
<option value="cm">centimeters</option>
<option value="in">inches</option>
<option value="px">pixels</option>
</select>
</div>
</div>
<div class="row"><br><br></div>
<div class="row">
<div class="column">
<label for="borderTop">Border Top:</label>
<input type="text" id="borderTop" name="borderTop" size="5">
</div>
<div class="column">
<label for="borderRight">Border Right:</label>
<input type="text" id="borderRight" name="borderRight" size="5"><br>
</div>
</div>
<div class="row">
<div class="column">
<label for="borderBottom">Border Bottom:</label>
<input type="text" id="borderBottom" name="borderBottom" size="5">
</div>
<div class="column">
<label for="borderLeft">Border Left:</label>
<input type="text" id="borderLeft" name="borderLeft" size="5">
</div>
</div>
<div class="row"><br><br><br></div>
<div class="row">
<div class="column">
<input type="radio" id="portrait" name="orientation" value="portrait" checked="checked">Portrait<br>
<input type="radio" id="landscape" name="orientation" value="landscape">Landscape
</div>
<div class="column">
<input type="radio" id="color" name="color" value="true" checked="checked">Color<br>
<input type="radio" id="grayscale" name="color" value="false" >Grayscale
</div>
</div>
<br><br><br>
<button type="button" id="addOK" onclick="javascript:savePrinterProfile()">OK</button>
<button type="button" id="addCancel" onclick="javascript:showPrinterProfiles()">Cancel</button>
</div>
Expand All @@ -92,9 +149,10 @@
<button type="button" id="cancelSettings" onclick="javascript:resumePrinting()">Cancel and Continue Printing</button>

<!--
<input type='text' id='message' size=50>
<input type='text' id='message' size=1000>
<br>
-->


</div>
</div>
Expand Down
50 changes: 45 additions & 5 deletions configWindow.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const ipcRenderer = require('electron').ipcRenderer;
const {dialog} = require('electron').remote;
const defaultBorder = ".4" //This was the hardcoded default pre-2.0.0-beta-03
let selectedLocalPrinter;
let almaPrinterProfiles;
let displayName;
Expand Down Expand Up @@ -120,7 +121,7 @@ ipcRenderer.on('local-printers', (event, localPrinters) => {

//Handle loading Alma printers
ipcRenderer.on('alma-printers', (event, almaPrinters) => {
//document.getElementById("message").value = 'In alma-printers: ' & almaPrinters;
//document.getElementById("message").value = 'In Renderer load Alma printers ' + JSON.stringify(almaPrinters);
if (document.getElementById('apiKey').value.length > 0) {
globalAlmaPrinters = almaPrinters;
almaPrintersAvailable();
Expand Down Expand Up @@ -284,11 +285,18 @@ function savePrinterProfile () {
else {
colorValue = 'false';
}

const format = document.querySelector('#letterFormat').value;
const units = document.querySelector('#borderUnits').value;
const top = document.querySelector('#borderTop').value;
const right = document.querySelector('#borderRight').value;
const bottom = document.querySelector('#borderBottom').value;
const left = document.querySelector('#borderLeft').value;

var x = document.getElementById("almaPrinter");
for (var i = 0; i < x.options.length; i++) {
if (x.options[i].selected) {
jsonObj = {almaPrinter: x.options[i].value, localPrinter: localPrinterSelected, orientation: orientationValue, color: colorValue};
jsonObj = {almaPrinter: x.options[i].value, localPrinter: localPrinterSelected, orientation: orientationValue, color: colorValue, letterFormat: format, borderUnits: units, borderTop: top, borderRight: right, borderBottom: bottom, borderLeft: left};
almaPrinterProfiles.splice(almaPrinterProfiles.length, 0, jsonObj);
}
}
Expand Down Expand Up @@ -322,8 +330,12 @@ function removeAvailablePrinters() {
}

function appendPrinterProfiles(almaPrinters, data) {
var myObj = document.getElementById('profiles');
if (myObj !== null)
myObj.remove();
var mainContainer = document.getElementById("printerProfiles");
var div = document.createElement('div');
var letterFormat, borderUnits, borderTop, borderRight, borderBottom, borderLeft;
div.id = 'profiles'
mainContainer.appendChild(div);
var secondContainer = document.getElementById('profiles');
Expand All @@ -336,11 +348,25 @@ function appendPrinterProfiles(almaPrinters, data) {
else {
div.innerHTML = '<hr>';
}
if (data[i].letterFormat == undefined)
letterFormat = 'Letter'
else
letterFormat = data[i].letterFormat;
if (data[i].borderUnits == undefined)
borderUnits = "in";
else
borderUnits = data[i].borderUnits;
borderTop = setBorderValue(data[i].borderTop);
borderRight = setBorderValue(data[i].borderRight)
borderBottom = setBorderValue(data[i].borderBottom);
borderLeft = setBorderValue(data[i].borderLeft);
div.innerHTML = div.innerHTML + '<input type="checkbox" id="printerProfile" onclick="javascript:setRemovePrinterProfileButtonState();" value="' + i + '">';
div.innerHTML = div.innerHTML + 'Alma Printer: ' + displayName + '<br>';
div.innerHTML = div.innerHTML + '&emsp; Local Printer: ' + decodeURIComponent(data[i].localPrinter ) + '<br>';
div.innerHTML = div.innerHTML + '&emsp; Orientation: ' + data[i].orientation + '<br>';
div.innerHTML = div.innerHTML + '&emsp; Color: ' + data[i].color + '<br>';
div.innerHTML = div.innerHTML + '&emsp; Format: ' + letterFormat + '<br>';
div.innerHTML = div.innerHTML + '&emsp; Border (' + borderUnits + '): top ' + borderTop + ', right ' + borderRight + ', bottom ' + borderBottom + ', left ' + borderLeft + '<br>';
secondContainer.appendChild(div);
}
}
Expand Down Expand Up @@ -377,7 +403,8 @@ function setAddOKButtonState () {
}

function buildAlmaPrinterDisplayName(almaPrinters, id) {
let printerCount = almaPrinters.total_record_count;
//let printerCount = almaPrinters.total_record_count;
let printerCount = almaPrinters.printer.length;
for (let i = 0; i < printerCount; i++) {
if (almaPrinters.printer[i].id == id) {
displayName = almaPrinters.printer[i].name
Expand All @@ -391,7 +418,8 @@ function buildAlmaPrinterDisplayName(almaPrinters, id) {
}

function almaPrintersAvailable() {
let printerCount = globalAlmaPrinters.total_record_count;
//let printerCount = globalAlmaPrinters.total_record_count;
let printerCount = globalAlmaPrinters.printer.length;
let inUse;
let iCount = 0;
let i;
Expand All @@ -415,7 +443,8 @@ function almaPrintersAvailable() {
function updatePrinterSettings () {
//Remove the current printer profiles....
var myObj = document.getElementById('profiles');
myObj.remove();
if (myObj !== null)
myObj.remove();
//Rebuild available Alma printers and reload them
almaPrintersAvailable();
loadAvailableAlmaPrinters();
Expand Down Expand Up @@ -447,4 +476,15 @@ function disableAutomaticOptions(value) {
function resumePrinting(){
//document.getElementById("message").value = 'in resumePrinting';
ipcRenderer.send('print-continue');
}

function setBorderValue (value) {
if (value == undefined)
return defaultBorder;
else if (value == "")
return "0";
else if (isNaN(value))
return "0";
else
return value;
}
2 changes: 1 addition & 1 deletion docsPrintIntervalPaused.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="UTF-8">
<title>Alma Print Daemon 2.0-beta-02</title>
<title>Alma Print Daemon 2.0.0-beta-03</title>
</head>
<style>
#notification {
Expand Down
2 changes: 1 addition & 1 deletion docsPrintedInterval.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="UTF-8">
<title>Alma Print Daemon 2.0-beta-02</title>
<title>Alma Print Daemon 2.0.0-beta-03</title>
</head>
<style>
#notification {
Expand Down
2 changes: 1 addition & 1 deletion docsPrintedManual.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="UTF-8">
<title>Alma Print Daemon 2.0-beta-02</title>
<title>Alma Print Daemon 2.0.0-beta-03</title>
</head>
<style>
#notification {
Expand Down
69 changes: 53 additions & 16 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const printer = require('node-native-printer');
const ipcMain = require('electron').ipcMain;
const log = require('electron-log');
const {autoUpdater} = require('electron-updater');
const defaultBorder = ".4" //This was the hardcoded default pre-2.0.0-beta-03

autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = 'silly';
Expand All @@ -34,7 +35,7 @@ let useLocalPrinter;
let menuOffset = 0;

const getPrinterQueues = async type =>
await alma.getp(`/conf/printers?printout_queue=${type}`);
await alma.getp(`/conf/printers?printout_queue=${type}&limit=100`);

const getPrintouts = async (printer_id = useAlmaPrinters, limit = 100) =>
await alma.getp(`/task-lists/printouts?status=Pending${printer_id}&limit=${limit}`);
Expand Down Expand Up @@ -111,7 +112,7 @@ const getAlmaPrinters = async () => {
almaPrinterQueues = await getPrinterQueues('true');
//WriteLog ("from getAlmaPrinters APIKEY = " + process.env.ALMA_APIKEY);
//WriteLog ("from getAlmaPrinters APIPATH = " + process.env.ALMA_APIPATH);
console.log ("In GetAlmaPrinters: " + JSON.stringify(almaPrinterQueues));
//console.log ("In getAlmaPrinters async: " + JSON.stringify(almaPrinterQueues));
}

// This method will be called when Electron has finished
Expand Down Expand Up @@ -183,7 +184,7 @@ function createWindow () {
width: 600,
height: 595,
show: true,
title: "Alma Print Daemon 2.0-beta-02",
title: "Alma Print Daemon 2.0.0-beta-03",
webPreferences: {
//preload: path.join(__dirname, 'preload.js'),
nodeIntegration: true
Expand All @@ -197,15 +198,15 @@ function createWindow () {
mainWindow.loadURL('File://' + __dirname + '\\configWindow.html');
WriteLog ('After trying to load configWindow.html');
localPrinterList = mainWindow.webContents.getPrinters();
console.log (localPrinterList);
//console.log (localPrinterList);
mainWindow.webContents.on('did-finish-load', () => {
console.log ('did-finish-load for configWindow');
console.log ('Send saved settings to configWindow');
//console.log ('did-finish-load for configWindow');
//console.log ('Send saved settings to configWindow');
mainWindow.webContents.send('send-settings', configSettings);
console.log ('Send local printers to configWindow');
//console.log ('Send local printers to configWindow');
mainWindow.webContents.send('local-printers', localPrinterList);
console.log ('Send alma printers to configWindow');
console.log (almaPrinterQueues);
//console.log ('Send alma printers to configWindow');
//console.log (almaPrinterQueues);
mainWindow.webContents.send('alma-printers', almaPrinterQueues);
})
}
Expand Down Expand Up @@ -359,6 +360,11 @@ ipcMain.on('save-settings', function(e, configString){
//app.quit();
//Reload configuration
initConfiguration();
if (almaPrinterQueues == undefined) {
console.log ('Just saved settings - get alma printer queues, if necessary');
getAlmaPrinters();
}

setup = false;
//...and resume printing
if (configSettings.interval == 0) {
Expand Down Expand Up @@ -424,10 +430,31 @@ function getLocalPrinter(almaPrinter) {
break;
}
}
let letterFormat, borderUnits, borderTop, borderRight, borderBottom, borderLeft;
if (configSettings.almaPrinterProfiles[i].letterFormat == undefined)
letterFormat = 'Letter';
else
letterFormat = configSettings.almaPrinterProfiles[i].letterFormat;

if (configSettings.almaPrinterProfiles[i].borderUnits == undefined)
borderUnits = "in";
else
borderUnits = configSettings.almaPrinterProfiles[i].borderUnits;

borderTop = setBorderValue(configSettings.almaPrinterProfiles[i].borderTop) + borderUnits;
borderRight = setBorderValue(configSettings.almaPrinterProfiles[i].borderRight) + borderUnits;
borderBottom = setBorderValue(configSettings.almaPrinterProfiles[i].borderBottom) + borderUnits;
borderLeft = setBorderValue(configSettings.almaPrinterProfiles[i].borderLeft) + borderUnits;

pdfOptions = {
format: 'Letter',
format: letterFormat,
orientation: configSettings.almaPrinterProfiles[i].orientation,
border: '.4in',
border: {
top: borderTop,
right: borderRight,
bottom: borderBottom,
left: borderLeft
},
script: 'lib\\pdf_a4_portrait.js',
phantomPath: 'lib\\phantomjs.exe'
};
Expand All @@ -440,6 +467,15 @@ function getLocalPrinter(almaPrinter) {
console.log ("Local printer settings: useLandscape = " + useLandscape + " useColor = " + useColor + " useLocalPrinter = " + useLocalPrinter);
}

function setBorderValue (value) {
if (value == undefined)
return defaultBorder;
else if (isNaN(value))
return defaultBorder;
else
return value;
}

function displayConfigPage() {

//clear timer so request isn't trigered.
Expand All @@ -450,15 +486,16 @@ function displayConfigPage() {
mainWindow.loadURL('File://' + __dirname + '\\configWindow.html');
WriteLog ('After trying to load configWindow.html');
localPrinterList = mainWindow.webContents.getPrinters();
console.log (localPrinterList);
//console.log (localPrinterList);
mainWindow.webContents.on('did-finish-load', () => {
if (setup) {
console.log ('did-finish-load for configWindow');
console.log ('Send saved settings to configWindow');
//console.log ('did-finish-load for configWindow');
//console.log ('Send saved settings to configWindow');
mainWindow.webContents.send('send-settings', configSettings);
console.log ('Send local printers to configWindow');
//console.log ('Send local printers to configWindow');
mainWindow.webContents.send('local-printers', localPrinterList);
console.log ('Send alma printers to configWindow');
//console.log ('Send alma printers to configWindow');
WriteLog('In displayConfigPage, on-did-finish-load, sending Alma Printer Queues = ' + JSON.stringify(almaPrinterQueues));
mainWindow.webContents.send('alma-printers', almaPrinterQueues);
}
})
Expand Down
Loading

0 comments on commit 3732ce1

Please sign in to comment.