From 7e9be56fa679ae7994e63119a9095e91f917160d Mon Sep 17 00:00:00 2001 From: EliDeh Date: Tue, 21 Aug 2018 14:46:10 +0200 Subject: [PATCH] minor improvements --- signaturenDruck/printRenderer.js | 386 ++++++++++++++++--------------- 1 file changed, 197 insertions(+), 189 deletions(-) diff --git a/signaturenDruck/printRenderer.js b/signaturenDruck/printRenderer.js index 9b001de..3d3a35b 100644 --- a/signaturenDruck/printRenderer.js +++ b/signaturenDruck/printRenderer.js @@ -35,174 +35,38 @@ function main (ids, dataMan) { }) let size = _.groupBy(_.forEach(ids, function (value) { return value }), 'size') if (size.small) { - document.getElementById('userCard').className += ' small' - document.getElementById('currentUsername').className += ' small' - document.getElementById('currentDate').className += ' small' - _.forEach(size.small, function (value) { - let objct = value - if (objct.manual) { - let manualId = objct.id.split('m_')[1] - let shelfmark = dataMan[manualId] - for (let count = 0; count < objct.count; count++) { - let length = shelfmark.lines - let id = objct.id - let i = 1 - let div = document.createElement('div') - let line = document.createElement('p') - if (objct.short || length != 1) { - div.className = 'shelfmark indent small' - } else { - div.className = 'shelfmark center small' - } - div.id = id - let text = dataMan[manualId].lineTxts - let lineCount = length - text.forEach(element => { - if ((lineCount == 1) && (text.length == 1)) { - line.className = 'shelfmarkLine_' + i + ' oneLine' + ' small' - } else { - line.className = 'shelfmarkLine_' + i + ' small' - } - if (element == '') { - let emptyLine = document.createElement('br') - line.appendChild(emptyLine) - } else { - line.innerHTML = element - } - div.appendChild(line) - line = document.createElement('p') - i++ - }) - document.getElementById('toPrint').appendChild(div) - } - } else { - _.forEach(JSON.parse(file), function (key, value) { - let shelfmark = '' - let found = _.find(key, {'id': Number(objct.id)}) - if (found !== undefined) { - shelfmark = found - } - if (shelfmark != '') { - for (let count = 0; count < objct.count; count++) { - let length = shelfmark.txtLength - let id = shelfmark.id - let i = 1 - let div = document.createElement('div') - let line = document.createElement('p') - if (objct.short || length != 1) { - div.className = 'shelfmark indent small' - } else { - div.className = 'shelfmark center small' - } - div.id = id - if (objct.short && length == 1) { - let text = shelfmark.txt[0] - let indxSlash = text.indexOf('/') - let indxColon = text.indexOf(':') - shelfmark.txt = [] - shelfmark.txt[0] = text - let i = 0 - if (indxSlash !== -1) { - shelfmark.txt[0] = text.substring(0, indxSlash + 1) - shelfmark.txt[1] = text.substring(indxSlash + 1) - i = 1 - } - if (indxColon !== -1) { - if (i === 0) { - shelfmark.txt[0] = text.substring(0, indxColon + 1) - shelfmark.txt[1] = text.substring(indxColon + 1) - i = 1 - } else { - let i = 0 - let txt = [] - let length = shelfmark.txt.length - shelfmark.txt.forEach(element => { - let indx = element.indexOf(':') - if (indx !== -1) { - let j = 0 - while (j < i) { - txt[j] = shelfmark.txt[j] - j++ - } - let k = i - txt[k] = element.substring(0, indx) - k++ - txt[k] = element.substring(indx) - k++ - while (k <= length) { - txt[k] = shelfmark.txt[k - 1] - k++ - } - shelfmark.txt = txt - } - i++ - }) - } - } - i = 0 - let txt = [] - let length = shelfmark.txt.length - shelfmark.txt.forEach(element => { - let elementParts = element.split(' ') - if (elementParts.length >= 3) { - let j = 0 - while (j < i) { - txt[j] = shelfmark.txt[j] - j++ - } - let k = i - txt[k] = elementParts[0] + ' ' + elementParts[1] - k++ - txt[k] = element.substring(txt[k - 1].length) - k++ - while (k <= length) { - txt[k] = shelfmark.txt[k - 1] - k++ - } - shelfmark.txt = txt - } - i++ - }) - } - let text = shelfmark.txt - let lineCount = shelfmark.txt.length - text.forEach(element => { - if ((lineCount === 1) && (text.length === 1)) { - line.className = 'shelfmarkLine_' + i + ' oneLine' + ' small' - } else { - line.className = 'shelfmarkLine_' + i + ' small' - } - if (element == '') { - let emptyLine = document.createElement('br') - line.appendChild(emptyLine) - } else { - line.innerHTML = element - } - div.appendChild(line) - line = document.createElement('p') - i++ - }) - document.getElementById('toPrint').appendChild(div) - } - } - }) - } - }) + createSmall(size.small, dataMan, file) } if (size.big) { - _.forEach(size.big, function (value) { - let objct = value - if (objct.manual) { - let manualId = objct.id.split('m_')[1] - let shelfmark = dataMan[manualId] - let id = shelfmark.id + createBig(size.big, dataMan, file) + } +} + +function createSmall (data, dataMan, file) { + document.getElementById('userCard').className += ' small' + document.getElementById('currentUsername').className += ' small' + document.getElementById('currentDate').className += ' small' + _.forEach(data, function (value) { + let objct = value + if (objct.manual) { + let manualId = objct.id.split('m_')[1] + let shelfmark = dataMan[manualId] + for (let count = 0; count < objct.count; count++) { + let length = shelfmark.lines + let id = objct.id let i = 1 let div = document.createElement('div') let line = document.createElement('p') - div.className = 'shelfmark indent' + div.className = getShelfmarkClass(objct, length) div.id = id - shelfmark.lineTxts.forEach(element => { - line.className = 'shelfmarkLine_' + i + let text = dataMan[manualId].lineTxts + let lineCount = length + text.forEach(element => { + if ((lineCount == 1) && (text.length == 1)) { + line.className = 'shelfmarkLine_' + i + ' oneLine' + ' small' + } else { + line.className = 'shelfmarkLine_' + i + ' small' + } if (element == '') { let emptyLine = document.createElement('br') line.appendChild(emptyLine) @@ -214,39 +78,183 @@ function main (ids, dataMan) { i++ }) document.getElementById('toPrint').appendChild(div) - } else { - _.forEach(JSON.parse(file), function (key, value) { - let shelfmark = '' - let found = _.find(key, {'id': Number(objct.id)}) - if (found !== undefined) { - shelfmark = found - } - if (shelfmark != '') { - for (let count = 0; count < objct.count; count++) { - let id = shelfmark.id - let i = 1 - let div = document.createElement('div') - let line = document.createElement('p') - div.className = 'shelfmark indent' - div.id = id - shelfmark.txt.forEach(element => { - line.className = 'shelfmarkLine_' + i - if (element == '') { - let emptyLine = document.createElement('br') - line.appendChild(emptyLine) + } + } else { + _.forEach(JSON.parse(file), function (key, value) { + let shelfmark = '' + let found = _.find(key, {'id': Number(objct.id)}) + if (found !== undefined) { + shelfmark = found + } + if (shelfmark != '') { + for (let count = 0; count < objct.count; count++) { + let length = shelfmark.txtLength + let id = shelfmark.id + let i = 1 + let div = document.createElement('div') + let line = document.createElement('p') + div.className = getShelfmarkClass(objct, length) + div.id = id + if (objct.short && length == 1) { + let text = shelfmark.txt[0] + let indxSlash = text.indexOf('/') + let indxColon = text.indexOf(':') + shelfmark.txt = [] + shelfmark.txt[0] = text + let i = 0 + if (indxSlash !== -1) { + shelfmark.txt[0] = text.substring(0, indxSlash + 1) + shelfmark.txt[1] = text.substring(indxSlash + 1) + i = 1 + } + if (indxColon !== -1) { + if (i === 0) { + shelfmark.txt[0] = text.substring(0, indxColon + 1) + shelfmark.txt[1] = text.substring(indxColon + 1) + i = 1 } else { - line.innerHTML = element + let i = 0 + let txt = [] + let length = shelfmark.txt.length + shelfmark.txt.forEach(element => { + let indx = element.indexOf(':') + if (indx !== -1) { + let j = 0 + while (j < i) { + txt[j] = shelfmark.txt[j] + j++ + } + let k = i + txt[k] = element.substring(0, indx) + k++ + txt[k] = element.substring(indx) + k++ + while (k <= length) { + txt[k] = shelfmark.txt[k - 1] + k++ + } + shelfmark.txt = txt + } + i++ + }) + } + } + i = 0 + let txt = [] + let length = shelfmark.txt.length + shelfmark.txt.forEach(element => { + let elementParts = element.split(' ') + if (elementParts.length >= 3) { + let j = 0 + while (j < i) { + txt[j] = shelfmark.txt[j] + j++ + } + let k = i + txt[k] = elementParts[0] + ' ' + elementParts[1] + k++ + txt[k] = element.substring(txt[k - 1].length) + k++ + while (k <= length) { + txt[k] = shelfmark.txt[k - 1] + k++ + } + shelfmark.txt = txt } - div.appendChild(line) - line = document.createElement('p') i++ }) - document.getElementById('toPrint').appendChild(div) } + let text = shelfmark.txt + let lineCount = shelfmark.txt.length + text.forEach(element => { + if ((lineCount === 1) && (text.length === 1)) { + line.className = 'shelfmarkLine_' + i + ' oneLine' + ' small' + } else { + line.className = 'shelfmarkLine_' + i + ' small' + } + if (element == '') { + let emptyLine = document.createElement('br') + line.appendChild(emptyLine) + } else { + line.innerHTML = element + } + div.appendChild(line) + line = document.createElement('p') + i++ + }) + document.getElementById('toPrint').appendChild(div) } - }) - } - }) + } + }) + } + }) +} + +function createBig (data, dataMan, file) { + _.forEach(data, function (value) { + let objct = value + if (objct.manual) { + let manualId = objct.id.split('m_')[1] + let shelfmark = dataMan[manualId] + let id = shelfmark.id + let i = 1 + let div = document.createElement('div') + let line = document.createElement('p') + div.className = 'shelfmark indent' + div.id = id + shelfmark.lineTxts.forEach(element => { + line.className = 'shelfmarkLine_' + i + if (element == '') { + let emptyLine = document.createElement('br') + line.appendChild(emptyLine) + } else { + line.innerHTML = element + } + div.appendChild(line) + line = document.createElement('p') + i++ + }) + document.getElementById('toPrint').appendChild(div) + } else { + _.forEach(JSON.parse(file), function (key, value) { + let shelfmark = '' + let found = _.find(key, {'id': Number(objct.id)}) + if (found !== undefined) { + shelfmark = found + } + if (shelfmark != '') { + for (let count = 0; count < objct.count; count++) { + let id = shelfmark.id + let i = 1 + let div = document.createElement('div') + let line = document.createElement('p') + div.className = 'shelfmark indent' + div.id = id + shelfmark.txt.forEach(element => { + line.className = 'shelfmarkLine_' + i + if (element == '') { + let emptyLine = document.createElement('br') + line.appendChild(emptyLine) + } else { + line.innerHTML = element + } + div.appendChild(line) + line = document.createElement('p') + i++ + }) + document.getElementById('toPrint').appendChild(div) + } + } + }) + } + }) +} + +function getShelfmarkClass (objct, length) { + if (objct.short || length != 1) { + return 'shelfmark indent small' + } else { + return 'shelfmark center small' } }