Skip to content

Commit

Permalink
refactored, removed experimental i18n functions
Browse files Browse the repository at this point in the history
  • Loading branch information
arnobaer committed Nov 17, 2019
1 parent 712b38d commit dd6c880
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 117 deletions.
62 changes: 31 additions & 31 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="de">
<meta charset="utf-8">
<title>LabelPress</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
Expand All @@ -8,119 +8,119 @@

<div class="w3-container">
<header>
<h1 class="tr">Find labels</span></h1>
<h1><span lang="de">Archäologische Fundzettel</span></h1>
</header>
</div>

<div class="w3-container">

<div class="w3-row">
<a class="tab" data-target="project" href="#">
<div class="w3-third tablink w3-bottombar w3-hover-light-grey w3-padding w3-border-red tr">Project</div>
<div class="w3-third tablink w3-bottombar w3-hover-light-grey w3-padding w3-border-red"><span lang="de">Maßnahme</span></div>
</a>
<a class="tab" data-target="finds" href="#">
<div class="w3-third tablink w3-bottombar w3-hover-light-grey w3-padding tr">Finds</div>
<div class="w3-third tablink w3-bottombar w3-hover-light-grey w3-padding"><span lang="de">Funde</span></div>
</a>
<a class="tab" data-target="settings" href="#">
<div class="w3-third tablink w3-bottombar w3-hover-light-grey w3-padding tr">Settings</div>
<div class="w3-third tablink w3-bottombar w3-hover-light-grey w3-padding"><span lang="de">Einstellungen</span></div>
</a>
</div>

<div id="project">
<header>
<h3>Angaben zur Maßnahme</h3>
<h3><span lang="de">Angaben zur Maßnahme</span></h3>
</header>
<p>
<label for="form_pp">Politische Gemeinde</label><br />
<label for="form_pp"><span lang="de">Politische Gemeinde</span></label><br />
<input type="text" id="form_pp" class="w3-input w3-border" value="">
</p>
<p>
<label for="form_kg">Katastralgemeinde</label><br />
<label for="form_kg"><span lang="de">Katastralgemeinde</span></label><br />
<input type="text" id="form_kg" class="w3-input w3-border" value="">
</p>
<p>
<label for="form_mn">Maßnahme</label><br />
<label for="form_mn"><span lang="de">Maßnahme</span></label><br />
<input type="text" id="form_mn" class="w3-input w3-border" value="">
</p>
<p>
<label for="form_mnr">Maßnahme-Nr.</label><br />
<label for="form_mnr"><span lang="de">Maßnahme-Nr.</span></label><br />
<input type="text" id="form_mnr" class="w3-input w3-border" value="">
</p>
<p>
<label for="form_institution">Institution</label><br />
<label for="form_institution"><span lang="de">Institution</span></label><br />
<input type="text" id="form_institution" class="w3-input w3-border" value="">
</p>
</div>

<div id="finds">
<header>
<h3>Eingabe der Fundliste</h3>
<h3><span lang="de">Eingabe der Fundliste</span></h3>
</header>
<p>Kopieren und Einfügen direkt aus der Tabellenkalkulation.</p>
<p><span lang="de">Kopieren und Einfügen direkt aus der Tabellenkalkulation.</span></p>
<p>
<label for="form_input">Fundliste</label><br />
<label for="form_input"><span lang="de">Fundliste</span></label><br />
<textarea id="form_input" class="w3-input w3-border" rows="12">123 31.12.2019 42/1 7 42 Fe Nagel SF1</textarea>
</p>
</div>

<div id="settings">
<header>
<h3>Einstellungen</h3>
<h3><span lang="de">Einstellungen</span></h3>
</header>
<p>
<label for="separator">Trennzeichen</label><br />
<label for="separator"><span lang="de">Trennzeichen</span></label><br />
<select id="separator" class="w3-input w3-border">
<option value="\t">Tabulator (\t)</option>
<option value=";">Semikolon (;)</option>
<option value=",">Komma (,)</option>
<option value="\t"><span lang="de">Tabulator (\t)</span></option>
<option value=";"><span lang="de">Semikolon (;)</span></option>
<option value=","><span lang="de">Komma (,)</span></option>
</select>
</p>
<p>Konfiguration der Spalten, mit 1 beginnend. Wert 0 bedeutet deaktiviert.</p>
<p><span lang="de">Konfiguration der Spalten, mit 1 beginnend. Wert 0 bedeutet deaktiviert.</span></p>
<p>
<label for="col_number">Spalte für Fund-Nr.</label><br />
<label for="col_number"><span lang="de">Spalte für Fund-Nr.</span></label><br />
<input type="number" id="col_number" class="w3-input w3-border" value="1" min="0">
</p>
<p>
<label for="col_date">Spalte für Datum</label><br />
<label for="col_date"><span lang="de">Spalte für Datum</span></label><br />
<input type="number" id="col_date" class="w3-input w3-border" value="2" min="0">
</p>
<p>
<label for="col_parcel">Spalte für Parzelle</label><br />
<label for="col_parcel"><span lang="de">Spalte für Parzelle</span></label><br />
<input type="number" id="col_parcel" class="w3-input w3-border" value="3" min="0">
</p>
<p>
<label for="col_trench">Spalte für Schnitt</label><br />
<label for="col_trench"><span lang="de">Spalte für Schnitt</span></label><br />
<input type="number" id="col_trench" class="w3-input w3-border" value="4" min="0">
</p>
<p>
<label for="col_object">Spalte für Objekt-Nr.</label><br />
<label for="col_object"><span lang="de">Spalte für Objekt-Nr.</span></label><br />
<input type="number" id="col_object" class="w3-input w3-border" value="5" min="0">
</p>
<p>
<label for="col_context">Spalte für SE-Nr.</label><br />
<label for="col_context"><span lang="de">Spalte für SE-Nr.</span></label><br />
<input type="number" id="col_context" class="w3-input w3-border" value="6" min="0">
</p>
<p>
<label for="col_material">Spalte für Material</label><br />
<label for="col_material"><span lang="de">Spalte für Material</span></label><br />
<input type="number" id="col_material" class="w3-input w3-border" value="7" min="0">
</p>
<p>
<label for="col_type">Spalte für Fundbezeichnung</label><br />
<label for="col_type"><span lang="de">Spalte für Fundbezeichnung</span></label><br />
<input type="number" id="col_type" class="w3-input w3-border" value="8" min="0">
</p>
<p>
<label for="col_comment">Spalte für Anmerkung</label><br />
<label for="col_comment"><span lang="de">Spalte für Anmerkung</span></label><br />
<input type="number" id="col_comment" class="w3-input w3-border" value="9" min="0">
</p>
</div>
</div>

<div class="w3-container">
<p><button class="w3-button w3-red tr" id="form_submit">Generate PDF</button></p>
<p><button class="w3-button w3-red" id="form_submit"><span lang="de">PDF erzeugen</span></button></p>
</div>

<footer class="w3-container">
<p class="w3-text-gray"><a href="https://github.com/burgried/labelpress/" title="">LabelPress</a> Version 1.0.0 | Created with &hearts; by <a href="https://burgried.at/" title="Verein zur Erhaltung und Erforschung der Burg Ried am Riederberg">burgried.at</a></p>
<p class="w3-text-gray"><a href="https://github.com/burgried/labelpress/" title="LabelPress">LabelPress</a> Version 1.0.0 | Created with &hearts; by <a href="https://burgried.at/" title="Verein zur Erhaltung und Erforschung der Burg Ried am Riederberg">burgried.at</a></p>
</footer>

<script src="./index.js"></script>
Expand Down
22 changes: 1 addition & 21 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {generate} from './pdf.js'
import {find, get, i18n} from './util.js'
import {find, get} from './util.js'

function registerTabs(id) {
function hideTabs(id) {
Expand All @@ -26,24 +26,4 @@ window.onload = function() {
get('#form_submit').onclick = function() {
generate()
}

// i18n translate
var messages = {
'Find labels': {
'de': 'Archäologische Fundzettel'
},
'Project': {
'de': 'Maßnahme'
},
'Finds': {
'de': 'Funde'
},
'Settings': {
'de': 'Einstellungen'
},
'Generate PDF': {
'de': 'PDF erzeugen'
}
}
i18n(messages)
}
125 changes: 71 additions & 54 deletions src/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,36 @@ function parseInput() {
return items
}

function Label() {
this.width = 57.0
this.height = 77.0
this.lineHeight = 8.5
this.columns = [21.5, 37.0, 29.3, 21.5]
}

Label.prototype.drawLines = function(x, y, doc) {
var i
doc.setLineWidth(0.35)
// Rect
doc.rect(x, y, this.width, this.height, 'S')
doc.setLineWidth(0.22)
// Horizontal lines
for (i = 1; i < 7; i++) {
doc.line(x, y + this.height - (this.lineHeight * i),
x + this.width, y + this.height - (this.lineHeight * i))
}
// Vertical lines
for (i = 0; i < this.columns.length; i++) {
doc.line(x + this.columns[i], y + this.height - (this.lineHeight * (i + 2)),
x + this.columns[i], y + this.height - (this.lineHeight * (i + 3)))
}
}

Label.prototype.render = function(item, x, y, doc) {
doc.setDrawColor('black')
this.drawLines(x, y, doc)
};

module.exports.generate = function() {

// Parse input data (from spread sheet, tab separated)
Expand All @@ -75,20 +105,28 @@ module.exports.generate = function() {
var col_1 = 29.3
var col_2 = 37

var row_count = 3
var col_count = 3
var card_count = col_count * row_count

var marginLeft = 15.0
var marginTop = 20.0
var padding = 4.0

var i
var item

var margin_top
var margin_left
var pos_y
var pos_x

for (i = 0; i < items.length; i++) {
var label = new Label()
item = items[i]

margin_top = 20 + (Math.floor((i % 9) / 3) * (card_height + 4))
margin_left = 15 + ((i % 3) * (card_width + 4))
pos_y = marginTop + (Math.floor((i % card_count) / col_count) * (card_height + padding))
pos_x = marginLeft + ((i % row_count) * (card_width + padding))

// Put 9 cards on every page
if (i != 0 && i % 9 == 0) {
if (i != 0 && i % card_count == 0) {
doc.addPage()
}

Expand All @@ -98,87 +136,66 @@ module.exports.generate = function() {
doc.setFontSize(7)

// Top label
doc.text(margin_left+1,margin_top+2.9, "Maßnahme/Nr.")
doc.text(pos_x+1,pos_y+2.9, "Maßnahme/Nr.")

doc.setFontSize(10)

// Address
doc.text(margin_left+1,margin_top+7.3, document.getElementById('form_pp').value)
doc.text(margin_left+1,margin_top+12, document.getElementById('form_kg').value)
doc.text(pos_x+1,pos_y+7.3, document.getElementById('form_pp').value)
doc.text(pos_x+1,pos_y+12, document.getElementById('form_kg').value)

doc.setFontType('bold')

// Project
doc.text(margin_left+1,margin_top+16.5, document.getElementById('form_mn').value)
doc.text(pos_x+1,pos_y+16.5, document.getElementById('form_mn').value)

doc.setFontSize(14)

// Project ID
doc.text(margin_left+1,margin_top+22.5, document.getElementById('form_mnr').value)
doc.text(pos_x+1,pos_y+22.5, document.getElementById('form_mnr').value)

doc.setFontType('normal')
doc.setFontSize(7)

// Left column labels
doc.text(margin_left+1,margin_top+card_height-(line_height*1)+2.7, "Fund-Nr.")
doc.text(margin_left+1,margin_top+card_height-(line_height*2)+2.7, "Anmerkung")
doc.text(margin_left+1,margin_top+card_height-(line_height*3)+2.7, "Material")
doc.text(margin_left+1,margin_top+card_height-(line_height*4)+2.7, "Fläche-Nr.")
doc.text(margin_left+1,margin_top+card_height-(line_height*5)+2.7, "Datum")
doc.text(margin_left+1,margin_top+card_height-(line_height*6)+2.7, "Grundstück-Nr.")
var keys, values
keys = ['Fund-Nr.', 'Anmerkung', 'Material', 'Fläche-Nr.', 'Datum', 'Grundstück-Nr.']
var j
for (j = 0; j < keys.length; j++) {
doc.text(pos_x + 1.0, pos_y + label.height - (label.lineHeight * (j + 1)) + 2.7, keys[j])
}

// Right column labels
doc.text(margin_left+col_0+1,margin_top+card_height-(line_height*3)+2.7, "Fundbezeichnung")
doc.text(margin_left+col_2+1,margin_top+card_height-(line_height*4)+2.7, "SE-Nr.")
doc.text(margin_left+col_1+1,margin_top+card_height-(line_height*5)+2.7, "Objekt-Nr.")
doc.text(margin_left+col_0+1,margin_top+card_height-(line_height*6)+2.7, "Institution")

keys = ['Fundbezeichnung', 'SE-Nr.', 'Objekt-Nr.', 'Institution']
for (j = 0; j < keys.length; j++) {
doc.text(pos_x + label.columns[j] + 1.0 , pos_y + label.height-(label.lineHeight * (j + 3)) + 2.7, keys[j])
}
doc.setFontType('normal')
doc.setFontSize(10)

// Left column values
doc.text(margin_left+card_width-1.5, margin_top+card_height-(line_height*6)+6.5, document.getElementById('form_institution').value, 'right')
doc.text(margin_left+card_width-1.5, margin_top+card_height-(line_height*5)+6.5, item.object, 'right')
doc.text(margin_left+card_width-1.5, margin_top+card_height-(line_height*4)+6.5, item.context, 'right')
doc.text(margin_left+card_width-1.5, margin_top+card_height-(line_height*3)+6.5, item.type, 'right')
doc.text(pos_x+card_width-1.5, pos_y+card_height-(line_height*6)+6.5, document.getElementById('form_institution').value, 'right')
doc.text(pos_x+card_width-1.5, pos_y+card_height-(line_height*5)+6.5, item.object, 'right')
doc.text(pos_x+card_width-1.5, pos_y+card_height-(line_height*4)+6.5, item.context, 'right')
doc.text(pos_x+card_width-1.5, pos_y+card_height-(line_height*3)+6.5, item.type, 'right')

// Right column values
doc.text(margin_left+col_0-1.5, margin_top+card_height-(line_height*6)+6.5, item.parcel, 'right')
doc.text(margin_left+col_1-1.5, margin_top+card_height-(line_height*5)+6.5, item.date, 'right')
doc.text(margin_left+col_2-1.5, margin_top+card_height-(line_height*4)+6.5, item.trench, 'right')
doc.text(margin_left+col_0-1.5, margin_top+card_height-(line_height*3)+6.5, item.material, 'right')
doc.text(pos_x+col_0-1.5, pos_y+card_height-(line_height*6)+6.5, item.parcel, 'right')
doc.text(pos_x+col_1-1.5, pos_y+card_height-(line_height*5)+6.5, item.date, 'right')
doc.text(pos_x+col_2-1.5, pos_y+card_height-(line_height*4)+6.5, item.trench, 'right')
doc.text(pos_x+col_0-1.5, pos_y+card_height-(line_height*3)+6.5, item.material, 'right')

// Comment
doc.text(margin_left+card_width-1.5,margin_top+card_height-(line_height*2)+6.5, item.comment, {align: 'right', maxWidth: card_width-5})
doc.text(pos_x+card_width-1.5,pos_y+card_height-(line_height*2)+6.5, item.comment, {align: 'right', maxWidth: card_width-5})

doc.setFontSize(20)

// Find number
doc.text(margin_left+card_width-2, margin_top+card_height-1.8, item.number, 'right')

doc.setLineWidth(0.35)
doc.setDrawColor(0)

// Card rect
doc.rect(margin_left, margin_top, card_width, card_height, 'S')

doc.setLineWidth(0.22)

// Horizontal lines
doc.line(margin_left, margin_top+card_height-line_height, margin_left+card_width, margin_top+card_height-line_height)
doc.line(margin_left, margin_top+card_height-(line_height*2), margin_left+card_width, margin_top+card_height-(line_height*2))
doc.line(margin_left, margin_top+card_height-(line_height*3), margin_left+card_width, margin_top+card_height-(line_height*3))
doc.line(margin_left, margin_top+card_height-(line_height*4), margin_left+card_width, margin_top+card_height-(line_height*4))
doc.line(margin_left, margin_top+card_height-(line_height*5), margin_left+card_width, margin_top+card_height-(line_height*5))
doc.line(margin_left, margin_top+card_height-(line_height*6), margin_left+card_width, margin_top+card_height-(line_height*6))
doc.text(pos_x+card_width-2, pos_y+card_height-1.8, item.number, 'right')

// Vertical lines
doc.line(margin_left+col_0, margin_top+card_height-(line_height*5), margin_left+col_0, margin_top+card_height-(line_height*6))
doc.line(margin_left+col_1, margin_top+card_height-(line_height*4), margin_left+col_1, margin_top+card_height-(line_height*5))
doc.line(margin_left+col_2, margin_top+card_height-(line_height*3), margin_left+col_2, margin_top+card_height-(line_height*4))
doc.line(margin_left+col_0, margin_top+card_height-(line_height*2), margin_left+col_0, margin_top+card_height-(line_height*3))
label.render(item, pos_x, pos_y, doc)
}

// Write output
doc.output('dataurlnewwindow')
doc.output('dataurlnewwindow');
}
12 changes: 1 addition & 11 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
module.exports.find = function(id) {
return Array.prototype.slice.call(document.querySelectorAll(id))
}

module.exports.get = function(id) {
return document.querySelectorAll(id)[0]
}
module.exports.i18n = function(messages) {
var lang = navigator.language.split('-')[0]
module.exports.find('.tr').forEach(function(el) {
var key = el.innerText.trim()
if (messages[key]) {
if (messages[key][lang]) {
el.innerText = messages[key][lang]
}
}
})
}

0 comments on commit dd6c880

Please sign in to comment.