Skip to content

Commit

Permalink
added option to filterByLocation #60
Browse files Browse the repository at this point in the history
  • Loading branch information
EliDeh committed Jul 30, 2019
1 parent 84708c0 commit 32aae11
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 78 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ Der Adobe Acrobat Reader DC wird für den Druck benötigt. Ist dieser nicht das
- Es ist nun möglich den Sofortdruck via Konfigeintrag automatisch auszuwählen (issue #58)
- .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)
- Optimierungen:
- main.js: Funktion 'checkConfig' überarbeitet
- npm update ausgeführt
Expand Down
24 changes: 24 additions & 0 deletions signaturenDruck/html/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,30 @@ <h2 class="subtitle is-4">Modus</h2>
</div>
<div class="box">
<h2 class="subtitle is-4">Signaturenaufbau</h2>
<div class="field is-horizontal" id="locLine">
<div class="field-label is-normal oneLabelSize" id="label_loc">
<label class="label">Standort</label>
</div>
<div class="field-body">
<div class="field">
<p class="control">
<input id="input_loc" class="input fullwidth" type="text" value="">
</p>
</div>
</div>
</div>
<div class="field is-horizontal" id="locRegExLine">
<div class="field-label is-normal oneLabelSize" id="label_locRegEx">
<label class="label">RegEx Standort</label>
</div>
<div class="field-body">
<div class="field">
<p class="control">
<input id="input_locRegEx" class="input fullwidth" type="text" value="">
</p>
</div>
</div>
</div>
<div class="field is-horizontal">
<div class="field-label is-normal oneLabelSize" id="label_example">
<label class="label">Beispiel</label>
Expand Down
43 changes: 24 additions & 19 deletions signaturenDruck/js/K10plus/loadDataFromFileK10plus.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const Shelfmark = require('../shelfmark.js')
const Modes = require('../classes/Modes')
const Formats = require('../classes/Formats')
const FormatLinesByMode = require('../classes/FormatLinesByMode')
const LocationCheck = require('../classes/LocationCheck')

module.exports = function (allLines) {
let obj = {
Expand Down Expand Up @@ -40,26 +41,30 @@ module.exports = function (allLines) {
'lines': ''
}
data.format = value.format
if (value.useRegEx) {
let regex = new RegExp(value.regEx)
if (regex.test(plainTxt) && sig.defaultSubMode === '') {
sig.defaultSubMode = value.id
}
let lines = plainTxt.match(regex)
if (lines !== null) {
lines.shift()
}
data.lines = lines
if (data.lines !== null) {
data.lines = FormatLinesByMode.formatLines(sig.location, data.lines, value.result)
}
if (config.get('filterByLoc') && !LocationCheck.locDoesMatch(value.locRegEx, sig.location)) {
data.lines = null
} else {
data.lines = plainTxt.split(value.delimiter)
if (sig.defaultSubMode === '') {
sig.defaultSubMode = value.id
}
if (data.lines !== null) {
data.lines = FormatLinesByMode.formatLines(sig.location, data.lines, value.result, formatArray[value.format].lines)
if (value.useRegEx) {
let regex = new RegExp(value.regEx)
if (regex.test(plainTxt) && sig.defaultSubMode === '') {
sig.defaultSubMode = value.id
}
let lines = plainTxt.match(regex)
if (lines !== null) {
lines.shift()
}
data.lines = lines
if (data.lines !== null) {
data.lines = FormatLinesByMode.formatLines(sig.location, data.lines, value.result)
}
} else {
data.lines = plainTxt.split(value.delimiter)
if (sig.defaultSubMode === '') {
sig.defaultSubMode = value.id
}
if (data.lines !== null) {
data.lines = FormatLinesByMode.formatLines(sig.location, data.lines, value.result, formatArray[value.format].lines)
}
}
}
sig.subModes.push(data)
Expand Down
11 changes: 11 additions & 0 deletions signaturenDruck/js/classes/LocationCheck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
locDoesMatch: function (regEx, loc) {
let regex = new RegExp(regEx)
if (loc.match(regex)) {
return true
} else {
return false
}
}

}
43 changes: 24 additions & 19 deletions signaturenDruck/js/classes/ShelfmarksFromSRUData.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const Modes = require('./Modes.js')
const config = remote.getGlobal('config')
const Formats = require('../classes/Formats')
const FormatLinesByMode = require('../classes/FormatLinesByMode')
const LocationCheck = require('../classes/LocationCheck')

class ShelfmarksFromSRUData {
/*
Expand Down Expand Up @@ -51,26 +52,30 @@ class ShelfmarksFromSRUData {
'lines': ''
}
data.format = value.format
if (value.useRegEx) {
let regex = new RegExp(value.regEx)
if (regex.test(sig.txtOneLine) && sig.defaultSubMode === '') {
sig.defaultSubMode = value.id
}
let lines = sig.txtOneLine.match(regex)
if (lines !== null) {
lines.shift()
}
data.lines = lines
if (data.lines !== null) {
data.lines = FormatLinesByMode.formatLines(sig.location, data.lines, value.result)
}
if (config.get('filterByLoc') && !LocationCheck.locDoesMatch(value.locRegEx, sig.location)) {
data.lines = null
} else {
data.lines = sig.txtOneLine.split(value.delimiter)
if (sig.defaultSubMode === '') {
sig.defaultSubMode = value.id
}
if (data.lines !== null) {
data.lines = FormatLinesByMode.formatLines(sig.location, data.lines, value.result, formatArray[value.format].lines)
if (value.useRegEx) {
let regex = new RegExp(value.regEx)
if (regex.test(sig.txtOneLine) && sig.defaultSubMode === '') {
sig.defaultSubMode = value.id
}
let lines = sig.txtOneLine.match(regex)
if (lines !== null) {
lines.shift()
}
data.lines = lines
if (data.lines !== null) {
data.lines = FormatLinesByMode.formatLines(sig.location, data.lines, value.result)
}
} else {
data.lines = sig.txtOneLine.split(value.delimiter)
if (sig.defaultSubMode === '') {
sig.defaultSubMode = value.id
}
if (data.lines !== null) {
data.lines = FormatLinesByMode.formatLines(sig.location, data.lines, value.result, formatArray[value.format].lines)
}
}
}
sig.subModes.push(data)
Expand Down
108 changes: 87 additions & 21 deletions signaturenDruck/js/configRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const { ipcRenderer, remote } = require('electron')

const config = remote.getGlobal('config')
const defaultProgramPath = remote.getGlobal('defaultProgramPath')
const LocationCheck = require('./classes/LocationCheck')

let modeNames = []
let modesData = []
Expand All @@ -26,38 +27,70 @@ let resultData = []
window.onload = function () {
getModes()
setModeSelect()
displayLocFilter()
loadExampleData()
}

function displayLocFilter () {
if (config.get('filterByLoc')) {
document.getElementById('locLine').style.display = 'flex'
document.getElementById('locRegExLine').style.display = 'flex'
} else {
document.getElementById('locLine').style.display = 'none'
document.getElementById('locRegExLine').style.display = 'none'
}
}

function close () {
ipcRenderer.send('closeConfigWindow')
}

function locDoesMatch () {
let regex = new RegExp(document.getElementById('input_locRegEx').value)
if (document.getElementById('input_loc').value.match(regex)) {
return true
} else {
return false
}
}

function createPreview () {
clearPreview()
let lines = document.getElementById('linesBox').childNodes
let data = []
lines.forEach(function (line) {
data.push(line.value)
})
resultData = data = FormatLinesByMode.formatLines(config.get('example.location'), linesData, data, linesData.length)
_.forEach(data, function (value) {
let d = document.createElement('div')
let p = document.createElement('p')
if (value === '') {
value = '<br/>'
if (config.get('filterByLoc') && !LocationCheck.locDoesMatch(document.getElementById('input_locRegEx').value, document.getElementById('input_loc').value)) {
alert('Der RegEx Standort erfasst nicht den festgelegten Standort!')
} else {
let lines = document.getElementById('linesBox').childNodes
let data = []
lines.forEach(function (line) {
data.push(line.value)
})
if (config.get('filterByLoc')) {
resultData = data = FormatLinesByMode.formatLines(document.getElementById('input_loc').value, linesData, data, linesData.length)
} else {
resultData = data = FormatLinesByMode.formatLines(config.get('example.location'), linesData, data, linesData.length)
}
p.innerHTML = value
d.appendChild(p)
document.getElementById('preview').appendChild(d)
})
_.forEach(data, function (value) {
let d = document.createElement('div')
let p = document.createElement('p')
if (value === '') {
value = '<br/>'
}
p.innerHTML = value
d.appendChild(p)
document.getElementById('preview').appendChild(d)
})
}
}

// loads and fills fields with exampleData form the config
function loadExampleData () {
document.getElementById('input_example').value = document.getElementById('input_example').placeholder = config.get('example.shelfmark')
document.getElementById('input_regEx').value = document.getElementById('input_regEx').placeholder = config.get('example.regex')
document.getElementById('input_delimiter').value = document.getElementById('input_delimiter').placeholder = config.get('example.delimiter')
if (config.get('filterByLoc')) {
document.getElementById('input_loc').value = document.getElementById('input_loc').placeholder = config.get('example.location')
document.getElementById('input_locRegEx').value = document.getElementById('input_locRegEx').placeholder = '^' + config.get('example.location') + '$'
}
}

function loadSubModeData () {
Expand All @@ -69,6 +102,15 @@ function loadSubModeData () {
} else {
enableDelimiter()
}
if (config.get('filterByLoc')) {
if (subModeData.exampleLoc) {
document.getElementById('input_loc').value = subModeData.exampleLoc
document.getElementById('input_locRegEx').value = subModeData.locRegEx
} else {
document.getElementById('input_loc').value = config.get('example.location')
document.getElementById('input_locRegEx').value = '^' + config.get('example.location') + '$'
}
}
document.getElementById('input_example').value = subModeData.exampleShelfmark
document.getElementById('input_regEx').value = subModeData.regEx
document.getElementById('input_delimiter').value = subModeData.delimiter
Expand Down Expand Up @@ -96,7 +138,11 @@ function displayPlaceholderInfo (lines = '') {
createPlaceholderLine('$' + i + ' - "' + value + '"')
i++
})
createPlaceholderLine('$LOC - "' + config.get('example.location') + '"')
if (config.get('filterByLoc')) {
createPlaceholderLine('$LOC - "' + document.getElementById('input_loc').value + '"')
} else {
createPlaceholderLine('$LOC - "' + config.get('example.location') + '"')
}
createPlaceholderLine('$DATE - "' + moment().format('DD.MM.YYYY') + '"')
}
}
Expand Down Expand Up @@ -302,6 +348,13 @@ function setValues (obj) {
obj.delimiter = document.getElementById('input_delimiter').value
obj.exampleShelfmark = document.getElementById('input_example').value
obj.result = getResult()
if (config.get('filterByLoc')) {
obj.exampleLoc = document.getElementById('input_loc').value
obj.locRegEx = document.getElementById('input_locRegEx').value
} else {
obj.exampleLoc = config.get('example.location')
obj.locRegEx = ''
}
}

function saveMode () {
Expand Down Expand Up @@ -348,8 +401,12 @@ function saveMode () {
function saveAndExit () {
if (document.getElementById('input_modeName').value !== '' && document.getElementById('input_subModeName').value !== '') {
if (getSubModeNameNew() === getSubModeNameOld()) {
saveMode()
close()
if (config.get('filterByLoc') && !LocationCheck.locDoesMatch(document.getElementById('input_locRegEx').value, document.getElementById('input_loc').value)) {
alert('Der RegEx Standort erfasst nicht den festgelegten Standort!')
} else {
saveMode()
close()
}
} else {
// better disable the button if condition is not met
alert('Für den neuen Untermodus muss noch ein Format festgelegt werden.')
Expand All @@ -365,10 +422,14 @@ function saveAndContinue () {
alert('Es liegbt bereits ein Modus mit diesem Namen vor.')
} else {
if (getSubModeNameNew() === getSubModeNameOld() || !subModeAlreadyExists(getSubModeNameNew())) {
saveMode()
if (config.get('filterByLoc') && !LocationCheck.locDoesMatch(document.getElementById('input_locRegEx').value, document.getElementById('input_loc').value)) {
alert('Der RegEx Standort erfasst nicht den festgelegten Standort!')
} else {
saveMode()

ipcRenderer.send('createNewModeFormat', getCurrentData())
close()
ipcRenderer.send('createNewModeFormat', getCurrentData())
close()
}
} else {
alert('Es liegt bereits ein Untermodus mit diesem Namen vor.')
}
Expand All @@ -386,6 +447,11 @@ function getCurrentData () {
data.example = {}
data.example.shelfmark = document.getElementById('input_example').value
data.example.parts = resultData
if (config.get('filterByLoc')) {
data.example.loc = document.getElementById('input_loc').value
} else {
data.example.loc = config.get('filterByLoc')
}
data.prevName = getSubModeNameOld()

return data
Expand Down
Loading

0 comments on commit 32aae11

Please sign in to comment.