Skip to content

Commit

Permalink
Add Service functionality (#47)
Browse files Browse the repository at this point in the history
* Alma Print Daemon as a Service

Application reworked to function as a standard application and as a Windows service.

* Minor updates

Add autoupdate to two html pages.

* Version 2 Beta 02

Display version number in application title bar. Prevent multiple instances from running. Fix truncated margins in printouts.

* Add more config options

Added format options for A3, A4, A5, legal, letter, tabloid.
Added border settings for unit, top, right, bottom, and left.
Bump to beta-03.

* Bump version to general release
  • Loading branch information
mgobat authored May 4, 2022
1 parent f10f2a8 commit eace7a1
Show file tree
Hide file tree
Showing 19 changed files with 1,804 additions and 1,247 deletions.
Binary file removed .DS_Store
Binary file not shown.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# alma-print-daemon
The Alma Print Daemon is an Alma extension that helps you to automatically print letters and slips from the Alma Printout Queues.  With this new print daemon extension there is no need to use email based printing.  It will also automatically update itself when new versions are available for easy management and upkeep.
The Alma Print Daemon is an Alma extension that helps you to automatically print letters and slips from the Alma Printout Queues.  With this print daemon extension there is no need to use email based printing.  It will also automatically update itself when new versions are available for easy management and upkeep.

The application may be installed as a service on a Windows workstation using nssm (https://nssm.cc/).

The extension's configuration settings include:

Expand Down
85 changes: 73 additions & 12 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 @@ -86,13 +143,17 @@
<br>
<button type="button" id="addPrinterProfileButton" disabled="true" onclick="javascript:addPrinterProfile()">Add Printer Profile</button>
<button type="button" id="removePrinterProfileButton" disabled="true" onclick="javascript:removePrinterProfile()">Remove Printer Profile</button>
&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;<button type="submit">Save</button>
<button type="button" id="cancelSettings" onclick="javascript:window.close()">Cancel</button>
<br><br>
<button type="submit">Save and Continue Printing</button>
&emsp;
<button type="button" id="cancelSettings" onclick="javascript:resumePrinting()">Cancel and Continue Printing</button>

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


</div>
</div>
</form>
Expand Down
73 changes: 60 additions & 13 deletions configWindow.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const ipcRenderer = require('electron').ipcRenderer;
const {dialog, BrowserWindow} = require('electron').remote;
const me = require('electron').remote.getCurrentWindow()
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 All @@ -13,6 +13,7 @@ form.addEventListener('submit', submitForm);

//Handle saving of updated alma print daemon settings
function submitForm(e){
//document.getElementById("message").value = 'In submitForm';
e.preventDefault();
let badInterval = false;
let interval = 0;
Expand Down Expand Up @@ -51,14 +52,15 @@ function submitForm(e){
}
//If all required config values entered, it is ok to save.
if (apiKey.length && !badInterval && almaPrinterProfiles.length > 0) {

var configString = "{\"region\": \"" + region + "\",";
configString = configString + "\"apiKey\": \"" + apiKey + "\",";
configString = configString + "\"interval\": \"" + interval + "\",";
configString = configString + "\"autoStart\": \"" + autoStart.checked + "\",";
configString = configString + "\"almaPrinterProfiles\":";
configString = configString + JSON.stringify(almaPrinterProfiles);
configString = configString + "}";
me.closable = true;
//document.getElementById("message").value = 'Send save-settings: ' + configString;
ipcRenderer.send('save-settings', configString);
}
else {
Expand All @@ -70,6 +72,7 @@ function submitForm(e){

//Handle loading of alma print daemon settings
ipcRenderer.on('send-settings', (event, configSettings) => {
//document.getElementById("message").value = 'In send-settings';
let element = document.getElementById('region');
element.value = configSettings.region;
document.getElementById('apiKey').value = configSettings.apiKey;
Expand All @@ -91,6 +94,7 @@ ipcRenderer.on('send-settings', (event, configSettings) => {

//Handle loading local workstation printers
ipcRenderer.on('local-printers', (event, localPrinters) => {
//document.getElementById("message").value = 'In local-printers';
let i = 0;
var sel = document.getElementById('localPrinter');
console.log ('local-printers selectedLocalPrinter = ' + selectedLocalPrinter);
Expand All @@ -117,6 +121,7 @@ ipcRenderer.on('local-printers', (event, localPrinters) => {

//Handle loading Alma printers
ipcRenderer.on('alma-printers', (event, almaPrinters) => {
//document.getElementById("message").value = 'In Renderer load Alma printers ' + JSON.stringify(almaPrinters);
if (document.getElementById('apiKey').value.length > 0) {
globalAlmaPrinters = almaPrinters;
almaPrintersAvailable();
Expand All @@ -128,24 +133,21 @@ ipcRenderer.on('alma-printers', (event, almaPrinters) => {
}
if (document.getElementById('apiKey').value.length == 0 || almaPrinterProfiles.length == 0) {
document.getElementById("cancelSettings").disabled = true;
me.closable = false;
}
else {
me.closable = true;
}
})

//Function that communicates with Alma to get the Alma printers.
function getAlmaPrinters() {
console.log ('in getAlmaPrinters()');
//document.getElementById("message").value = 'In getAlmaPrinters';
const region = document.querySelector('#region').value;
const apiKey = document.querySelector('#apiKey').value;
const https = require('https');
let data = '';

let request = "https://api-" + region + ".hosted.exlibrisgroup.com/almaws/v1/conf/printers?apikey=" + apiKey + '&printout_queue=true&limit=100&format=json';
let request = "https://api-" + region + ".hosted.exlibrisgroup.com/almaws/v1/conf/printers?apikey=" + apiKey + '&printout_queue=true&limit=100&format=json';
console.log ("request = " + request);
//document.getElementById("message").value = request;
https.get(
request, (resp) =>{
// A chunk of data has been received.
Expand Down Expand Up @@ -283,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 @@ -321,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 @@ -335,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 @@ -376,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 @@ -390,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 @@ -414,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 All @@ -426,6 +456,7 @@ function updatePrinterSettings () {
}

function testAPIKey () {
//document.getElementById("message").value = 'In testAPIKey';
getAlmaPrinters();
}

Expand All @@ -440,4 +471,20 @@ function enableDisableSettings (divId, value) {
function disableAutomaticOptions(value) {
document.getElementById("interval").disabled = value;
document.getElementById("autostart").disabled = 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;
}
23 changes: 0 additions & 23 deletions docsErrorInterval.html

This file was deleted.

23 changes: 0 additions & 23 deletions docsErrorManual.html

This file was deleted.

Loading

0 comments on commit eace7a1

Please sign in to comment.