More Tweaks

This commit is contained in:
Peter Hart 2018-06-02 17:09:54 -04:00
parent 8040ef8f05
commit 7966d6888c
8 changed files with 133 additions and 247 deletions

4
.gitignore vendored
View File

@ -3,3 +3,7 @@ build/
node_modules/ node_modules/
.idea/ .idea/
*.log *.log
*~
*.pdf
functions/index.*
functions/index/

View File

@ -1,232 +0,0 @@
(function (_, Kotlin) {
'use strict';
var Kind_CLASS = Kotlin.Kind.CLASS;
var throwCCE = Kotlin.throwCCE;
var until = Kotlin.kotlin.ranges.until_dqglrj$;
var chunked = Kotlin.kotlin.collections.chunked_ba2ldo$;
function get_cm($receiver) {
return $receiver / 2.54;
}
function get_asPoints($receiver) {
return $receiver * 72;
}
function Entry(eventNbr, event, lane, heat, swimmer, team) {
this.eventNbr = eventNbr;
this.event = event;
this.lane = lane;
this.heat = heat;
this.swimmer = swimmer;
this.team = team;
}
Entry.$metadata$ = {
kind: Kind_CLASS,
simpleName: 'Entry',
interfaces: []
};
Entry.prototype.component1 = function () {
return this.eventNbr;
};
Entry.prototype.component2 = function () {
return this.event;
};
Entry.prototype.component3 = function () {
return this.lane;
};
Entry.prototype.component4 = function () {
return this.heat;
};
Entry.prototype.component5 = function () {
return this.swimmer;
};
Entry.prototype.component6 = function () {
return this.team;
};
Entry.prototype.copy_cdqwiw$ = function (eventNbr, event, lane, heat, swimmer, team) {
return new Entry(eventNbr === void 0 ? this.eventNbr : eventNbr, event === void 0 ? this.event : event, lane === void 0 ? this.lane : lane, heat === void 0 ? this.heat : heat, swimmer === void 0 ? this.swimmer : swimmer, team === void 0 ? this.team : team);
};
Entry.prototype.toString = function () {
return 'Entry(eventNbr=' + Kotlin.toString(this.eventNbr) + (', event=' + Kotlin.toString(this.event)) + (', lane=' + Kotlin.toString(this.lane)) + (', heat=' + Kotlin.toString(this.heat)) + (', swimmer=' + Kotlin.toString(this.swimmer)) + (', team=' + Kotlin.toString(this.team)) + ')';
};
Entry.prototype.hashCode = function () {
var result = 0;
result = result * 31 + Kotlin.hashCode(this.eventNbr) | 0;
result = result * 31 + Kotlin.hashCode(this.event) | 0;
result = result * 31 + Kotlin.hashCode(this.lane) | 0;
result = result * 31 + Kotlin.hashCode(this.heat) | 0;
result = result * 31 + Kotlin.hashCode(this.swimmer) | 0;
result = result * 31 + Kotlin.hashCode(this.team) | 0;
return result;
};
Entry.prototype.equals = function (other) {
return this === other || (other !== null && (typeof other === 'object' && (Object.getPrototypeOf(this) === Object.getPrototypeOf(other) && (Kotlin.equals(this.eventNbr, other.eventNbr) && Kotlin.equals(this.event, other.event) && Kotlin.equals(this.lane, other.lane) && Kotlin.equals(this.heat, other.heat) && Kotlin.equals(this.swimmer, other.swimmer) && Kotlin.equals(this.team, other.team)))));
};
function Meet(meet, entries) {
this.meet = meet;
this.entries = entries;
}
Meet.$metadata$ = {
kind: Kind_CLASS,
simpleName: 'Meet',
interfaces: []
};
Meet.prototype.component1 = function () {
return this.meet;
};
Meet.prototype.component2 = function () {
return this.entries;
};
Meet.prototype.copy_khic54$ = function (meet, entries) {
return new Meet(meet === void 0 ? this.meet : meet, entries === void 0 ? this.entries : entries);
};
Meet.prototype.toString = function () {
return 'Meet(meet=' + Kotlin.toString(this.meet) + (', entries=' + Kotlin.toString(this.entries)) + ')';
};
Meet.prototype.hashCode = function () {
var result = 0;
result = result * 31 + Kotlin.hashCode(this.meet) | 0;
result = result * 31 + Kotlin.hashCode(this.entries) | 0;
return result;
};
Meet.prototype.equals = function (other) {
return this === other || (other !== null && (typeof other === 'object' && (Object.getPrototypeOf(this) === Object.getPrototypeOf(other) && (Kotlin.equals(this.meet, other.meet) && Kotlin.equals(this.entries, other.entries)))));
};
function hydrateEntry(entry) {
return new Entry(entry.eventNbr, entry.event, entry.lane, entry.heat, entry.swimmer, entry.team);
}
var collectionSizeOrDefault = Kotlin.kotlin.collections.collectionSizeOrDefault_ba2ldo$;
var ArrayList_init = Kotlin.kotlin.collections.ArrayList_init_ww73n8$;
function iterate(list) {
var tmp$;
var $receiver = until(0, typeof (tmp$ = list.length) === 'number' ? tmp$ : throwCCE());
var destination = ArrayList_init(collectionSizeOrDefault($receiver, 10));
var tmp$_0;
tmp$_0 = $receiver.iterator();
while (tmp$_0.hasNext()) {
var item = tmp$_0.next();
destination.add_11rb$(list[item]);
}
return destination;
}
function hydrateMeet(meet) {
var tmp$ = meet.meet;
var $receiver = iterate(meet.entries);
var destination = ArrayList_init(collectionSizeOrDefault($receiver, 10));
var tmp$_0;
tmp$_0 = $receiver.iterator();
while (tmp$_0.hasNext()) {
var item = tmp$_0.next();
destination.add_11rb$(hydrateEntry(item));
}
return new Meet(tmp$, destination);
}
function main$lambda(req, res) {
var doc = new (require('pdfkit'))({autoFirstPage: false});
var meetInfo = hydrateMeet(req.body);
res.setHeader('Content-Disposition', 'attachment;filename=' + '"' + 'lane-slips-' + meetInfo.meet + '.pdf' + '"');
res.setHeader('Content-Type', 'application/pdf');
doc.pipe(res);
var tmp$;
tmp$ = chunked(meetInfo.entries, 6).iterator();
while (tmp$.hasNext()) {
var element = tmp$.next();
doc.addPage();
var tmp$_0, tmp$_0_0;
var index = 0;
tmp$_0 = element.iterator();
while (tmp$_0.hasNext()) {
var item = tmp$_0.next();
var index_0 = (tmp$_0_0 = index, index = tmp$_0_0 + 1 | 0, tmp$_0_0);
writeSlip(item, doc, index_0 % 2, index_0 / 2 | 0);
}
drawDashes(doc);
}
return doc.end();
}
function main(args) {
var fireFunctions = require('firebase-functions');
fireFunctions.config();
exports.laneslips = fireFunctions.https.onRequest(main$lambda);
}
function drawDashes(doc) {
var dashOptions = {};
dashOptions.space = 10;
doc.moveTo(get_asPoints(get_cm(10.25)), get_asPoints(get_cm(1.0))).lineTo(get_asPoints(get_cm(10.25)), get_asPoints(get_cm(27.0))).dash(5, dashOptions).stroke();
doc.moveTo(get_asPoints(get_cm(1.0)), get_asPoints(get_cm(9.5))).lineTo(get_asPoints(get_cm(21.0)), get_asPoints(get_cm(9.5))).dash(5, dashOptions).stroke();
doc.moveTo(get_asPoints(get_cm(1.0)), get_asPoints(get_cm(18.5))).lineTo(get_asPoints(get_cm(21.0)), get_asPoints(get_cm(18.5))).dash(5, dashOptions).stroke();
}
function writeSlip($receiver, doc, x, y) {
var xOffset = get_asPoints(get_cm(10.0)) * x;
var yOffset = get_asPoints(get_cm(8.0)) * y;
var leftMargin = get_asPoints(get_cm(0.9)) + xOffset;
var opts = {};
opts.width = get_asPoints(get_cm(8.5));
opts.align = 'center';
doc.fontSize(13);
doc.font('Helvetica-Bold');
doc.text('Southern Ohio Swim League', leftMargin, get_asPoints(get_cm(1.5)) + yOffset, opts);
doc.fontSize(11);
doc.font('Times-Roman');
var eventY = get_asPoints(get_cm(2.3)) + yOffset;
doc.text('EVENT #' + $receiver.eventNbr + ' - ' + $receiver.event, leftMargin, eventY);
var lineSeparation = get_asPoints(get_cm(1.0));
var laneY = eventY + lineSeparation;
doc.text('Lane:', leftMargin, laneY);
var colWidth = get_asPoints(get_cm(1.3));
doc.text('1', leftMargin + colWidth * 1, laneY);
doc.text('2', leftMargin + colWidth * 2, laneY);
doc.text('3', leftMargin + colWidth * 3, laneY);
doc.text('4', leftMargin + colWidth * 4, laneY);
doc.text('5', leftMargin + colWidth * 5, laneY);
doc.text('6', leftMargin + colWidth * 6, laneY);
doc.circle(leftMargin + colWidth * $receiver.lane + get_asPoints(get_cm(0.1)), laneY + get_asPoints(get_cm(0.15)), get_asPoints(get_cm(0.3)));
doc.stroke();
var heatY = laneY + lineSeparation;
doc.text('Heat:', leftMargin, heatY);
doc.text('1', leftMargin + colWidth * 1, heatY);
doc.text('2', leftMargin + colWidth * 2, heatY);
doc.text('3', leftMargin + colWidth * 3, heatY);
doc.text('4', leftMargin + colWidth * 4, heatY);
doc.text('5', leftMargin + colWidth * 5, heatY);
doc.text('6', leftMargin + colWidth * 6, heatY);
doc.circle(leftMargin + colWidth * $receiver.heat + get_asPoints(get_cm(0.1)), heatY + get_asPoints(get_cm(0.15)), get_asPoints(get_cm(0.3)));
doc.stroke();
var nameY = heatY + lineSeparation;
doc.text('Name: ' + $receiver.swimmer, leftMargin, nameY);
var teamY = nameY + lineSeparation;
doc.text('Team: ' + $receiver.team, leftMargin, teamY);
var timesY = teamY + lineSeparation * 1.5;
doc.text('Times:', leftMargin, timesY);
doc.moveTo(leftMargin + colWidth, timesY + 14).lineTo(leftMargin + colWidth + get_asPoints(get_cm(2.0)), timesY + 14).stroke();
doc.moveTo(leftMargin + colWidth + get_asPoints(get_cm(2.7)), timesY + 14).lineTo(leftMargin + colWidth + get_asPoints(get_cm(4.7)), timesY + 14).stroke();
doc.moveTo(leftMargin + colWidth + get_asPoints(get_cm(5.4)), timesY + 14).lineTo(leftMargin + colWidth + get_asPoints(get_cm(7.4)), timesY + 14).stroke();
var officialTimesY = timesY + lineSeparation * 1.5;
doc.text('Official Time:', leftMargin, officialTimesY);
doc.moveTo(leftMargin + colWidth * 2, officialTimesY + 14).lineTo(leftMargin + colWidth * 2 + get_asPoints(get_cm(4.0)), officialTimesY + 14).stroke();
var placeY = officialTimesY + lineSeparation * 1.25;
doc.text('Place:', leftMargin, placeY);
doc.text('1', leftMargin + colWidth * 1, placeY);
doc.text('2', leftMargin + colWidth * 2, placeY);
doc.text('3', leftMargin + colWidth * 3, placeY);
doc.text('4', leftMargin + colWidth * 4, placeY);
doc.text('5', leftMargin + colWidth * 5, placeY);
doc.text('6', leftMargin + colWidth * 6, placeY);
}
var package$online = _.online || (_.online = {});
var package$cinphart = package$online.cinphart || (package$online.cinphart = {});
var package$laneslips = package$cinphart.laneslips || (package$cinphart.laneslips = {});
package$laneslips.get_cm_yrwdxr$ = get_cm;
package$laneslips.get_asPoints_yrwdxr$ = get_asPoints;
package$laneslips.Entry = Entry;
package$laneslips.Meet = Meet;
package$laneslips.hydrateEntry_za3rmp$ = hydrateEntry;
package$laneslips.iterate_za3rmp$ = iterate;
package$laneslips.hydrateMeet_za3rmp$ = hydrateMeet;
package$laneslips.main_kand9s$ = main;
package$laneslips.drawDashes_za3rmp$ = drawDashes;
package$laneslips.writeSlip_dmpztf$ = writeSlip;
main([]);
Kotlin.defineModule('index', _);
return _;
}(module.exports, require('kotlin')));
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
// Kotlin.kotlin_module_metadata(66049, "index", "H4sIAAAAAAAAAJVUTVMTQRDNfmR30knIuAiEBRVBRVFwCWh5BcFCSikraJXXZTNFttzsxN1ByN3iB3jy4MmDR8/+Af0J/B57JkNY8ORl35t+Pd39eqq2RCzvJ8BvCxyeJnHKgERx2u+GmYBKEqYsT+J+DuXtVGQDcD5wgUlgbaQDIOwTS8XeQQbWy1RAWR3B2RdZnB6CLS+D3WWhADc/jns9loEtWNgDiHivz1PMXi3wVoGvFfh6gT8p8KdgR7yPM7GPR2GSg7vJecLCFMpcdLEX6YZ59znvoCPBz4d6zZgAuye/LtbIYpZDNeJJwiIR8zQH+1WcS+2kzzOBRfewmLzpDZ2vbA3SsBdHbwd9rBvmb3icYpqzxY8OEgZmhO46WXi8hb2xtP0ujQVYHR5BrTtAQbDhIstMQVUH1VhuLJg84OrkDHYvxE3bYXaI69/IsnAAboZe44yB0+OdI+xXOc7w0j4+ERgnYAy8DExaApuUqIFfg5rgEJNazRLGbeQ2LSOX6GqsaJxUaFK/Ke/b9AaegN7U6pzGBY33ND5ulvxvpj9N7/pmMNYao4s+zN1esptGUA5qv0gJpfsoWSg9+FdaQqmC0sxVaZE+9KlX8wrhoIqJj64mTtFl1blGV3zi2Z4ZuEFDCrM0KOa2HLqKie7O6ZxUl2lLXlsaTrZ4JXMNNQdxXSKmz0/QW8WU96efDRlu0HnMqGOV+rMXw8CdS4GvxJz/bpJT0rRaZlDeDDyHOrIoIpHjIII+VzXWdLwucbdCx2R854+FtKEcKEovotcuqHeRMH5Ot+l19QAEH1f1Vkx1VwxGseqI1UZqfVjG2B2nE0hJi9ApX61h50y2aarmZwbSaZV6ZrS1t7b22tbe2tprW3tsa49ycT8MuaSKWtIkmp9RS6jRWf2oVlDVq1CeGriKkSADC8pkRY2s7rbGkM0Wk/7LwqXObT0PDvqFmFDy9W/wL9qlo788BQAA");

View File

@ -9,7 +9,7 @@ curl -O -J -H "Content-Type: application/json" 'http://localhost:5000/swimteamma
"event":"Girls 8&U 100 Yd Medley Relay", "event":"Girls 8&U 100 Yd Medley Relay",
"lane":1, "lane":1,
"heat":1, "heat":1,
"swimmer":"A", "swimmer":"This is a really really really long name to see what happens",
"team":"Delshire" "team":"Delshire"
}, },
{ {

88
local-test-heats.sh Normal file
View File

@ -0,0 +1,88 @@
#!/bin/bash
curl -O -J -H "Content-Type: application/json" 'http://localhost:5000/swimteammanager-179e8/us-central1/heatSheets' -d '
{
"meet":"Delshire vs Woodhaven",
"entries":[
{
"eventNbr":1,
"event":"Girls 8&U 100 Yd Medley Relay",
"lane":1,
"heat":1,
"swimmer":"This is a really really really long name to see what happens",
"team":"Delshire"
},
{
"eventNbr":1,
"event":"Girls 8&U 100 Yd Medley Relay",
"lane":1,
"heat":1,
"swimmer":"A",
"team":"Delshire"
},
{
"eventNbr":1,
"event":"Girls 8&U 100 Yd Medley Relay",
"lane":1,
"heat":1,
"swimmer":"A",
"team":"Delshire"
},
{
"eventNbr":1,
"event":"Girls 8&U 100 Yd Medley Relay",
"lane":1,
"heat":1,
"swimmer":"A",
"team":"Delshire"
},
{
"eventNbr":1,
"event":"Girls 8&U 100 Yd Medley Relay",
"lane":1,
"heat":1,
"swimmer":"A",
"team":"Delshire"
},
{
"eventNbr":1,
"event":"Girls 8&U 100 Yd Medley Relay",
"lane":1,
"heat":1,
"swimmer":"A",
"team":"Delshire"
},
{
"eventNbr":1,
"event":"Girls 8&U 100 Yd Medley Relay",
"lane":1,
"heat":1,
"swimmer":"A",
"team":"Delshire"
},
{
"eventNbr":1,
"event":"Girls 8&U 100 Yd Medley Relay",
"lane":1,
"heat":1,
"swimmer":"A",
"team":"Delshire"
},
{
"eventNbr":1,
"event":"Girls 8&U 100 Yd Medley Relay",
"lane":1,
"heat":1,
"swimmer":"A",
"team":"Delshire"
},
{
"eventNbr":1,
"event":"Girls 8&U 100 Yd Medley Relay",
"lane":1,
"heat":1,
"swimmer":"A",
"team":"Delshire"
}
]
}'

View File

@ -31,7 +31,7 @@ fun main(args: Array<String>) {
exports.laneslips = fireFunctions.https.onRequest { req, res -> exports.laneslips = fireFunctions.https.onRequest { req, res ->
val doc = js("new (require('pdfkit'))({autoFirstPage:false})") val doc = js("new (require('pdfkit'))({autoFirstPage:false})")
val margins = js("{margin:18}")
val meetInfo = hydrateMeet(req.body) val meetInfo = hydrateMeet(req.body)
res.setHeader("Content-Disposition", "attachment;filename=\"lane-slips-${meetInfo.meet}.pdf\"") res.setHeader("Content-Disposition", "attachment;filename=\"lane-slips-${meetInfo.meet}.pdf\"")
@ -39,32 +39,60 @@ fun main(args: Array<String>) {
doc.pipe(res) doc.pipe(res)
meetInfo.entries.chunked(6).forEach { meetInfo.entries
doc.addPage() .sortedWith(compareBy({it.lane},{it.eventNbr},{it.heat}))
.chunked(6).forEach {
doc.addPage(margins)
drawDashes(doc)
it.forEachIndexed { index, slip -> it.forEachIndexed { index, slip ->
slip.writeSlip(doc, index % 2, index / 2) slip.writeSlip(doc, index % 2, index / 2)
} }
drawDashes(doc)
} }
doc.end() doc.end()
} }
exports.heatSheets = fireFunctions.https.onRequest { req, res ->
val doc = js("new (require('pdfkit'))({autoFirstPage:false})")
val margins = js("{margin:18}")
val meetInfo = hydrateMeet(req.body)
res.setHeader("Content-Disposition", "attachment;filename=\"heat-sheet-${meetInfo.meet}.pdf\"")
res.setHeader("Content-Type", "application/pdf")
doc.pipe(res)
meetInfo.entries
.sortedWith(compareBy({it.eventNbr},{it.heat},{it.lane}))
.chunked(6).forEach {
doc.addPage(margins)
drawDashes(doc)
it.forEachIndexed { index, slip ->
slip.writeSlip(doc, index % 2, index / 2)
}
}
doc.end()
}
} }
fun drawDashes(doc : dynamic) { fun drawDashes(doc : dynamic) {
val dashOptions = js("{}") val dashOptions = js("{}")
dashOptions.space = 10 dashOptions.space = 10
doc.save()
doc.moveTo(10.25.cm.asPoints, 1.0.cm.asPoints).lineTo(10.25.cm.asPoints, 27.0.cm.asPoints).dash(5, dashOptions).stroke() doc.moveTo(10.25.cm.asPoints, 1.0.cm.asPoints).lineTo(10.25.cm.asPoints, 27.0.cm.asPoints).dash(5, dashOptions).stroke()
doc.moveTo(1.0.cm.asPoints, 9.5.cm.asPoints).lineTo(21.0.cm.asPoints, 9.5.cm.asPoints).dash(5, dashOptions).stroke() doc.moveTo(1.0.cm.asPoints, 10.0.cm.asPoints).lineTo(21.0.cm.asPoints, 10.0.cm.asPoints).dash(5, dashOptions).stroke()
doc.moveTo(1.0.cm.asPoints, 18.5.cm.asPoints).lineTo(21.0.cm.asPoints, 18.5.cm.asPoints).dash(5, dashOptions).stroke() doc.moveTo(1.0.cm.asPoints, 19.0.cm.asPoints).lineTo(21.0.cm.asPoints, 19.0.cm.asPoints).dash(5, dashOptions).stroke()
doc.restore()
} }
fun Entry.writeSlip(doc: dynamic, x: Int, y: Int) { fun Entry.writeSlip(doc: dynamic, x: Int, y: Int) {
val xOffset = 10.0.cm.asPoints * x val xOffset = 10.0.cm.asPoints * x
val yOffset = 8.0.cm.asPoints * y val yOffset = 9.0.cm.asPoints * y
val leftMargin = 0.9.cm.asPoints + xOffset val leftMargin = 1.0.cm.asPoints + xOffset
val opts = js("{}") val opts = js("{}")
opts.width=8.5.cm.asPoints opts.width=8.5.cm.asPoints
@ -82,7 +110,7 @@ fun Entry.writeSlip(doc: dynamic, x: Int, y: Int) {
val eventY = 2.3.cm.asPoints + yOffset val eventY = 2.3.cm.asPoints + yOffset
doc.text("EVENT #${eventNbr} - ${event}", leftMargin, eventY) doc.text("EVENT #${eventNbr} - ${event}", leftMargin, eventY)
val lineSeparation = 1.0.cm.asPoints val lineSeparation = 0.75.cm.asPoints
val laneY = eventY + lineSeparation val laneY = eventY + lineSeparation
doc.text("Lane:", leftMargin, laneY) doc.text("Lane:", leftMargin, laneY)
@ -111,13 +139,13 @@ fun Entry.writeSlip(doc: dynamic, x: Int, y: Int) {
val nameY = heatY + lineSeparation val nameY = heatY + lineSeparation
doc.text("Name: $swimmer", leftMargin, nameY) doc.text("Name: $swimmer", leftMargin, nameY, js("{width:288,align:'left',height:28}"))
val teamY = nameY + lineSeparation val teamY = nameY + lineSeparation * 1.25
doc.text("Team: $team", leftMargin, teamY) doc.text("Team: $team", leftMargin, teamY)
val timesY = teamY + lineSeparation * 1.5 val timesY = teamY + lineSeparation * 1.25
doc.text("Times:", leftMargin, timesY) doc.text("Times:", leftMargin, timesY)
doc.moveTo(leftMargin + colWidth, timesY + 14) doc.moveTo(leftMargin + colWidth, timesY + 14)