Skip to content

Commit

Permalink
added search by EPN #41
Browse files Browse the repository at this point in the history
  • Loading branch information
EliDeh committed Jul 31, 2019
1 parent 32aae11 commit 8df9710
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 30 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ Der Adobe Acrobat Reader DC wird für den Druck benötigt. Ist dieser nicht das
- .json Konfigurationsdateien werden nun formatiert angelegt (issue #37)
- Ein Menü mit den Optionen 'Schließen', 'Format', 'Modus wurde hinzugefügt. Der entsprechende Konfigeintrag ist 'showMenu', Standardwert ist 'false' (issue #32)
- Der Konfigeintrag 'filterByLoc' ermöglicht das festlegen von Formaten für gewisse Standorte. Standardwert ist 'false' (issue #60)
- Das SRU-Fenster wurde die Auswahl zwischen PPN/EPN ergänzt. Dafür ist der Konfigeintrag 'SRU.QueryPart1EPN' nötig, der Standardwert ist '?version=1.1&operation=searchRetrieve&query=pica.epn=' (issue #41)
- Optimierungen:
- main.js: Funktion 'checkConfig' überarbeitet
- npm update ausgeführt
Expand Down
6 changes: 6 additions & 0 deletions signaturenDruck/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
</span>
<span id="sru" class="level-item">
Sofortdruck <span style="margin: 9px 6px 6px 6px;"><input id="chkbx_printImmediately" type="checkbox"></span>
<span class="select">
<select id="select_dataMode">
<option value='PPN'>PPN</option>
<option value='EPN'>EPN</option>
</select>
</span>
<input id="input_barcode" class="input" type="text" placeholder="Barcode">
<button id="btn_barcode" class="button"><i class="fas fa-plus"></i></button>
</span>
Expand Down
11 changes: 9 additions & 2 deletions signaturenDruck/js/classes/DataFromSRU.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@ class DataFromSRU {
----- End Constructor -----
*/

loadData (barcode) {
let url = config.get('SRU.SRUAddress') + config.get('SRU.QueryPart1') + barcode + config.get('SRU.QueryPart2')
loadData (key, mode) {
let url
let queryPart1
if (mode === 'PPN') {
queryPart1 = config.get('SRU.QueryPart1')
} else {
queryPart1 = config.get('SRU.QueryPart1EPN')
}
url = config.get('SRU.SRUAddress') + queryPart1 + key + config.get('SRU.QueryPart2')
let request = net.request(url)
let allData = ''
let data = ''
Expand Down
27 changes: 20 additions & 7 deletions signaturenDruck/js/classes/ShelfmarksFromSRUData.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,21 @@ class ShelfmarksFromSRUData {
----- End Constructor -----
*/

getShelfmark (xml, barcode) {
getShelfmark (xml, key, dataMode) {
let sig = new Shelfmark()
let mode = new Modes()
let formats = new Formats()
let formatArray = formats.formats
let occ = getOccurrence(xml, barcode)
sig.error = getError(xml, key, dataMode)

sig.error = getError(xml)
if (sig.error === '') {
let occ = getOccurrence(xml, key)
sig.id = 99 // gets overwritten at a later stage
sig.ppn = getPPN(xml)
if (dataMode === 'PPN') {
sig.ppn = getPPN(xml)
} else {
sig.ppn = getEPN(xml)
}
sig.date = getDate(xml, occ)
sig.txtOneLine = getTxt(xml, occ)
sig.exNr = getExNr(xml, occ)
Expand Down Expand Up @@ -125,6 +129,15 @@ function getPPN (object) {
}
}

function getEPN (object) {
let data = _.find(object['zs:searchRetrieveResponse']['zs:records']['zs:record']['zs:recordData']['record']['datafield'], { 'tag': '203@' })
if (data !== undefined) {
return data['subfield']['$t']
} else {
return ''
}
}

function getDate (object, occ) {
let parent = _.find(object['zs:searchRetrieveResponse']['zs:records']['zs:record']['zs:recordData']['record']['datafield'], { 'tag': '201B', 'occurrence': occ })
let data = _.find(parent['subfield'], { 'code': '0' })
Expand Down Expand Up @@ -174,12 +187,12 @@ function getLoanIndication (object, occ) {
}
}

function getError (object) {
function getError (object, key, mode) {
try {
if (object['zs:searchRetrieveResponse']['zs:numberOfRecords'] > 0) {
if (object && object['zs:searchRetrieveResponse'] && object['zs:searchRetrieveResponse']['zs:numberOfRecords'] > 0) {
return ''
} else {
return 'Barcode wurde nicht gefunden'
return mode + ': <b>' + key + '</b> wurde nicht gefunden.'
}
} catch (e) {
return e.message
Expand Down
54 changes: 37 additions & 17 deletions signaturenDruck/js/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,18 @@ window.onload = function () {
document.getElementById('defaultPath').innerHTML = config.get('defaultDownloadPath')
} else {
document.getElementById('defaultPath').innerHTML = 'nicht vorhanden'
alert('Die Datei ' + config.get('defaultDownloadPath') + ' ist nicht vorhanden.')
swal.fire('Achtung', 'Die Datei <b>' + config.get('defaultDownloadPath') + '</b> ist nicht vorhanden.', 'info')
}
} else {
document.getElementById('dnl').style.display = 'none'
document.getElementById('sru').style.display = 'flex'
if (config.get('SRU.printImmediately')) {
document.getElementById('chkbx_printImmediately').checked = true
}
if (!config.get('SRU.QueryPart1EPN')) {
document.getElementById('select_dataMode').disabled = true
swal.fire('Achtung', 'In der config.json fehlt der Eintrag: <b>SRU.QueryPart1EPN</b>\n\ndaher wurde die Suche via EPN deaktiviert.', 'info')
}
}

// Check the support for the File API support
Expand Down Expand Up @@ -92,25 +96,29 @@ ipcRenderer.on('removeManualSignatures', function (event) {
})

// ipc listener to add provided data to the SRU obj
ipcRenderer.on('addSRUdata', function (event, xml, barcode) {
ipcRenderer.on('addSRUdata', function (event, xml, barcode, mode) {
let data = new ShelfmarksFromSRUData()
let shelfmark = data.getShelfmark(xml, barcode)
let shelfmark = data.getShelfmark(xml, barcode, mode)
if (shelfmark.error !== '') {
swal.fire('Achtung', shelfmark.error, 'error')
.then(() => {})
} else {
let index = objSRU.all.length
objSRU.all[index] = shelfmark
objSRU.all[index].id = index + 1
table.readSRUData(objSRU.all)
if (document.getElementById('chkbx_printImmediately').checked) {
let node = document.getElementById('print_' + (index + 1))
node.click()
printButton(event, true)
}
table.clearManualSignaturesTable()
if (table.manualSignature !== undefined && table.manualSignature !== null && table.manualSignature.length !== 0) {
table.addManualSignaturesToTable(table.manualSignature)
if (shelfmark.PPN) {
let index = objSRU.all.length
objSRU.all[index] = shelfmark
objSRU.all[index].id = index + 1
table.readSRUData(objSRU.all)
if (document.getElementById('chkbx_printImmediately').checked) {
let node = document.getElementById('print_' + (index + 1))
node.click()
printButton(event, true)
}
table.clearManualSignaturesTable()
if (table.manualSignature !== undefined && table.manualSignature !== null && table.manualSignature.length !== 0) {
table.addManualSignaturesToTable(table.manualSignature)
}
} else {
swal.fire('Achtung', 'Signatur mit ' + mode + ': ' + barcode + ' wurde nicht gefunden.', 'info')
}
}
})
Expand Down Expand Up @@ -149,7 +157,7 @@ function deleteFromPath (path) {
if (err) {
throw err
} else {
alert('Die Datei wurde gelöscht.')
swal.fire('Achtung', 'Die Datei wurde gelöscht.', 'info')
}
})
}
Expand Down Expand Up @@ -224,7 +232,7 @@ function selectByDate () {

// function to submit the barcode
function submitBarcode () {
ipcRenderer.send('loadFromSRU', document.getElementById('input_barcode').value)
ipcRenderer.send('loadFromSRU', document.getElementById('input_barcode').value, document.getElementById('select_dataMode').value)
document.getElementById('input_barcode').value = ''
}

Expand All @@ -247,6 +255,18 @@ function openEditorWindow (event) {
}
}

function changePlaceholder () {
let selectValue = document.getElementById('select_dataMode').value
let input = document.getElementById('input_barcode')
if (selectValue === 'PPN') {
input.placeholder = 'Barcode'
} else {
input.placeholder = 'EPN'
}
}

// adds eventlistener to the PPN / EPN select
document.getElementById('select_dataMode').addEventListener('change', changePlaceholder)
// adds event listener to the create manually button
document.getElementById('btn_createManualSignatures').addEventListener('click', openManualSignaturesWindow)
// adds event listener to the deleteList button
Expand Down
9 changes: 5 additions & 4 deletions signaturenDruck/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const configNew = {
printImmediately: false,
SRUAddress: 'http://sru.k10plus.de/opac-de-27',
QueryPart1: '?version=1.1&operation=searchRetrieve&query=pica.bar=',
QueryPart1EPN: '?version=1.1&operation=searchRetrieve&query=pica.epn=',
QueryPart2: '&maximumRecords=1&recordSchema=picaxml'
},
print: {
Expand Down Expand Up @@ -177,10 +178,10 @@ ipcMain.on('saveManualSignatures', function (event, data) {
})

// listens on loadFromSRU, invokes the loadAndAddFromSRU function with the provided barcode
ipcMain.on('loadFromSRU', function (event, barcode) {
if (barcode !== '') {
sruData.loadData(barcode).then(function (data) {
mainWindow.webContents.send('addSRUdata', data, barcode)
ipcMain.on('loadFromSRU', function (event, key, mode) {
if (key !== '') {
sruData.loadData(key, mode).then(function (data) {
mainWindow.webContents.send('addSRUdata', data, key, mode)
})
}
})
Expand Down

0 comments on commit 8df9710

Please sign in to comment.