Skip to content

Commit 90678ad

Browse files
author
gilphilbert
committed
import/export
1 parent 9e0284e commit 90678ad

12 files changed

+263
-122
lines changed

TODO.md

-17
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
1-
# Preview
2-
* Fonts
3-
41
# New record
52
* Alter style for record needs to hide?
6-
* Shouldn't be able to change colors, etc. for christmas themes (won't do anything when printing)
7-
* Headers and footers (correct buttons)
8-
9-
# Design
10-
* Populate from database
11-
* Save to database
12-
13-
# Inport/Export
14-
* Everything
15-
16-
# Print
17-
* Fonts other than Retro may not work
18-
* More than one page
19-
* Haven't tested anything other than letter sized paper
203

214
# App
225
* Import from old system

public/fonts/fonts.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
font-weight: normal;
1212
}
1313
@font-face {
14-
font-family: 'Typewriter';
14+
font-family: 'ATypewriter';
1515
src: url('typewriter.woff2') format('woff2');
1616
src: url('typewriter.woff') format('woff');
1717
font-weight: normal;

src/App.vue

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<template>
2-
<NavBar @print="print" @design="this.designVisible = true" />
2+
<NavBar @print="print" @design="this.designVisible = true" @importExport="this.importExportVisible = true" />
33
<section class="section">
44
<div class="container">
55
<!--<router-link to="new" class="button is-primary">+ Add Record</router-link>-->
6-
<button @click="showNewRecord" class="button is-primary">+ Add Record</button>
6+
<div class="has-text-right" style="margin-bottom: 10px">
7+
<button @click="showNewRecord" class="button is-primary">+ Add Record</button>
8+
</div>
79
<table class="table is-fullwidth is-striped" id="record-table">
810
<thead>
911
<tr>
@@ -42,21 +44,24 @@
4244
<NewRecord :visible="newVisible" @close="closeNewRecord" :editId="recordToEdit"></NewRecord>
4345
<DeleteRecord :visible="deleteVisible" :recordid="recordToDelete" @close="closeDeleteRecord"></DeleteRecord>
4446
<DesignSettings :visible="designVisible" @close="closeDesignSettings"></DesignSettings>
47+
<ImportExport :visible="importExportVisible" @close="closeImportExport" @reload="getRecords"></ImportExport>
4548
</template>
4649

4750
<script>
4851
import NavBar from './components/NavBar.vue'
4952
import NewRecord from './views/NewRecord.vue'
5053
import DeleteRecord from './views/DeleteRecord.vue'
5154
import DesignSettings from './views/DesignSettings.vue'
55+
import ImportExport from './views/ImportExport.vue'
5256
5357
export default {
5458
name: 'App',
5559
components: {
5660
NavBar,
5761
NewRecord,
5862
DeleteRecord,
59-
DesignSettings
63+
DesignSettings,
64+
ImportExport
6065
},
6166
inject: [ '$styles', '$database', '$printer' ],
6267
data: () => {
@@ -66,7 +71,8 @@ export default {
6671
deleteVisible: false,
6772
recordToDelete: null,
6873
recordToEdit: null,
69-
designVisible: false
74+
designVisible: false,
75+
importExportVisible: false
7076
}
7177
},
7278
created: function () {
@@ -103,6 +109,9 @@ export default {
103109
closeDesignSettings: function () {
104110
this.designVisible = false
105111
},
112+
closeImportExport: function () {
113+
this.importExportVisible = false
114+
},
106115
print: function() {
107116
let ttp = []
108117
ttp = this.titles.filter((title) => {

src/assets/StyleDefines.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
},
5757
"retrocondensed": {
5858
"font": "retrocondensed",
59-
"name": "RetroCondensed",
59+
"name": "Retro Condensed",
6060
"titleSize": 10,
6161
"artistSize": 9,
6262
"margins": {

src/assets/database.js

+76-34
Original file line numberDiff line numberDiff line change
@@ -60,43 +60,85 @@ let Database = {
6060
}
6161
},
6262
titles: {
63-
get: id => {
64-
const title = _titles.get(id)
65-
return title
66-
},
67-
add: title => {
68-
const retVal = _titles.insert(title)
69-
_db.saveDatabase()
70-
return retVal
71-
},
72-
update: (id, title) => {
73-
let dbTitle = _titles.get(id)
74-
const keys = Object.keys(title)
75-
keys.forEach(key => {
76-
dbTitle[key] = title[key]
77-
})
78-
if (Object.keys(dbTitle).includes('styleOverride') && !keys.includes('styleOverride')) {
79-
delete(dbTitle.styleOverride)
63+
get: id => {
64+
const title = _titles.get(id)
65+
return title
66+
},
67+
add: title => {
68+
const retVal = _titles.insert(title)
69+
_db.saveDatabase()
70+
return retVal
71+
},
72+
update: (id, title) => {
73+
let dbTitle = _titles.get(id)
74+
const keys = Object.keys(title)
75+
keys.forEach(key => {
76+
dbTitle[key] = title[key]
77+
})
78+
if (Object.keys(dbTitle).includes('styleOverride') && !keys.includes('styleOverride')) {
79+
delete(dbTitle.styleOverride)
80+
}
81+
_titles.update(dbTitle)
82+
_db.saveDatabase()
83+
},
84+
remove: id => {
85+
id = parseInt(id)
86+
const title = _titles.findOne({ 'id': id })
87+
_titles.remove(title)
88+
_db.saveDatabase()
89+
},
90+
list: () => {
91+
const titles = _titles.find()/*.map(title => {
92+
return {
93+
title: title.sidea,
94+
sideb: title.sideb,
95+
artist: title.artist
8096
}
81-
_titles.update(dbTitle)
82-
_db.saveDatabase()
83-
},
84-
remove: id => {
85-
id = parseInt(id)
86-
const title = _titles.findOne({ 'id': id })
87-
_titles.remove(title)
97+
})*/
98+
return titles
99+
}
100+
},
101+
export: {
102+
csv: function () {
103+
let titles = _titles.chain().find().data({ removeMeta: 1 })
104+
let data = "data:text/csv;charset=utf-8,"
105+
titles.forEach(title => {
106+
data += [title.aside, title.bside, title.artist, title.artistb].join(',') + "\r\n"
107+
})
108+
return data
109+
},
110+
db: function () {
111+
return "data:text/json;charset=utf-8," + encodeURIComponent(_db.serialize())
112+
}
113+
},
114+
115+
import: {
116+
csv: function (data) {
117+
const lines = data.split('\r\n')
118+
lines.forEach(line => {
119+
let fields = line.split(',')
120+
if (fields.length >= 3) {
121+
_titles.insert({
122+
aside: fields[0],
123+
bside: fields[1],
124+
artist: fields[2],
125+
artistb: ((fields.length == 4) ? fields[3] : '')
126+
})
127+
}
128+
})
129+
_db.saveDatabase()
130+
return true
131+
},
132+
db: function (data) {
133+
const ob = JSON.parse(data)
134+
if (ob.filename === 'jukestudio.db') {
135+
_db.loadJSONObject(ob)
88136
_db.saveDatabase()
89-
},
90-
list: () => {
91-
const titles = _titles.find()/*.map(title => {
92-
return {
93-
title: title.sidea,
94-
sideb: title.sideb,
95-
artist: title.artist
96-
}
97-
})*/
98-
return titles
137+
_titles = _db.getCollection('titles')
138+
_options = _db.getCollection('options')
99139
}
140+
return true
141+
}
100142
}
101143
}
102144

src/assets/printer.js

+40-44
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ const pdfMake = require('pdfmake')
44
let database = null
55

66
pdfMake.fonts = {
7-
Retro: {
7+
retro: {
88
bold: new URL('fonts/Retro.ttf', document.location.toString()).toString()
99
},
10-
RetroCondensed: {
10+
retrocondensed: {
1111
bold: new URL('fonts/RetroCondensed.ttf', document.location.toString()).toString()
1212
},
13-
ATypewriter: {
13+
atypewriter: {
1414
bold: new URL('fonts/ATypewriter.ttf', document.location.toString()).toString()
1515
}
1616
}
@@ -20,7 +20,6 @@ function shadeColor2(color, percent) {
2020
return "#"+(0x1000000+(Math.round((t-R)*p)+R)*0x10000+(Math.round((t-G)*p)+G)*0x100+(Math.round((t-B)*p)+B)).toString(16).slice(1);
2121
}
2222

23-
2423
let Printer = {
2524
init: (db) => {
2625
database = db
@@ -79,9 +78,11 @@ let Printer = {
7978
dd.jsmeta.rows = 10
8079
break
8180
}
82-
for (let i = 0; i < titles.length; i += dd.jsmeta.columns * dd.jsmeta.rows) {
81+
let spliceTitles = JSON.parse(JSON.stringify(titles))
82+
while (spliceTitles.length > 0) {
83+
const pageTitles = spliceTitles.splice(0, dd.jsmeta.columns * dd.jsmeta.rows)
8384
dd.content.push({
84-
jsmeta: { titles: Printer.formatTitles(titles.slice(i, i + dd.jsmeta.columns + dd.jsmeta.rows), dd.jsmeta) }
85+
jsmeta: { titles: Printer.formatTitles(pageTitles, dd.jsmeta) }
8586
})
8687
}
8788
return dd;
@@ -367,43 +368,40 @@ let Printer = {
367368
// if we're supposed to have two columns and there's a corresponding title to populate
368369
const title_col2 = (dd.jsmeta.columns == 2 && page.jsmeta.titles.length > i + dd.jsmeta.rows) ? page.jsmeta.titles[i + dd.jsmeta.rows] : null
369370

370-
let columns = []
371-
372371
//get asides
373-
columns.push(this.getTitleASide(title))
374-
if (title_col2 !== null) {
375-
columns.push(this.getTitleASide(title_col2))
376-
} else {
377-
columns.push({ text: '', border: [false, false, false, false] })
378-
}
379-
380-
body.push(columns)
372+
let row = [this.getTitleASide(title)]
381373

382-
columns = []
383-
384-
//get artists
385-
columns.push(this.getTitleArtist(title))
386-
if (title_col2 !== null) {
387-
columns.push(this.getTitleArtist(title_col2))
388-
} else {
389-
columns.push({ text: '', border: [false, false, false, false] })
374+
if (dd.jsmeta.columns == 2) {
375+
if (title_col2) {
376+
row.push(this.getTitleASide(title_col2))
377+
} else {
378+
row.push({ text: '', border: [false, false, false, false] })
379+
}
390380
}
381+
body.push(row)
391382

383+
//get artists
384+
row = [this.getTitleArtist(title)]
392385

393-
body.push(columns)
394-
395-
columns = []
386+
if (dd.jsmeta.columns == 2) {
387+
if (title_col2 !== null) {
388+
row.push(this.getTitleArtist(title_col2))
389+
} else {
390+
row.push({ text: '', border: [false, false, false, false] })
391+
}
392+
}
393+
body.push(row)
396394

397395
//get bsides
398-
columns.push(this.getTitleBSide(title))
399-
if (title_col2 !== null) {
400-
columns.push(this.getTitleBSide(title_col2))
401-
} else {
402-
columns.push({ text: '', border: [false, false, false, false] })
396+
row = [this.getTitleBSide(title)]
397+
if (dd.jsmeta.columns == 2) {
398+
if (title_col2 !== null) {
399+
row.push(this.getTitleBSide(title_col2))
400+
} else {
401+
row.push({ text: '', border: [false, false, false, false] })
402+
}
403403
}
404-
405-
406-
body.push(columns)
404+
body.push(row)
407405
}
408406

409407
const spaced = dd.jsmeta.options.spacing
@@ -429,10 +427,10 @@ let Printer = {
429427
let str = title[side + 'side']
430428

431429
let canvas = document.createElement('canvas')
432-
canvas.width = 225
430+
canvas.width = "225px"
433431

434432
let context = canvas.getContext('2d')
435-
context.font = font.titleSize + 'px ' + font.name
433+
context.font = Math.ceil(font.titleSize) + 'px ' + font.font
436434
context.textAlign = 'center'
437435
context.textBaseline = 'middle';
438436

@@ -468,7 +466,7 @@ let Printer = {
468466
}
469467
}
470468

471-
_words.splice(_splitPoint, 0, '\n')
469+
_words[_splitPoint - 1] = _words[_splitPoint - 1] + '\n'
472470
str = _words.join(' ')
473471

474472
title[side + 'wrap'] = true
@@ -491,7 +489,7 @@ let Printer = {
491489
bwrap: false
492490
}
493491

494-
let font = null
492+
let font = StyleDefines.fonts[jsmeta.options.font]
495493
let style = null
496494

497495
if (jsmeta.options.allCaps) {
@@ -510,13 +508,11 @@ let Printer = {
510508
for (let key of ['style', 'primaryColor', 'shadeTitle', 'shadeArtist']) {
511509
formattedTitle[key] = title.styleOverride[key]
512510
}
513-
font = StyleDefines.fonts[title.styleOverride.font]
514511
style = StyleDefines.styles[title.styleOverride.style]
515512
} else {
516513
for (let key of ['style', 'primaryColor', 'shadeTitle', 'shadeArtist']) {
517514
formattedTitle[key] = jsmeta.options[key]
518515
}
519-
font = StyleDefines.fonts[jsmeta.options.font]
520516
style = StyleDefines.styles[jsmeta.options.style]
521517
}
522518

@@ -526,19 +522,19 @@ let Printer = {
526522
formattedTitle.mergeArtist = style.mergeArtist
527523

528524
//add font details
529-
formattedTitle.font = font.name
525+
formattedTitle.font = font.font
530526
formattedTitle.titleSize = font.titleSize
531527
formattedTitle.artistSize = font.artistSize
532528

533529
//provide the correct shades for fills
534530

535-
if (formattedTitle.shadeTitle === true) {
531+
if (formattedTitle.shadeTitle === true && (jsmeta.options.paperType === 'a4' || jsmeta.options.paperType === 'letter')) {
536532
formattedTitle.titleTint=shadeColor2(StyleDefines.colors[formattedTitle.primaryColor].primary, 0.8)
537533
} else {
538534
formattedTitle.titleTint='#ffffff'
539535
}
540536

541-
if (formattedTitle.shadeArtist === true) {
537+
if (formattedTitle.shadeArtist === true && (jsmeta.options.paperType === 'a4' || jsmeta.options.paperType === 'letter')) {
542538
formattedTitle.artistTint=shadeColor2(StyleDefines.colors[formattedTitle.primaryColor].primary, 0.8)
543539
} else {
544540
formattedTitle.artistTint='#ffffff'

0 commit comments

Comments
 (0)