Fixes and updates.

This commit is contained in:
Wynne Crisman
2020-01-16 09:31:12 -08:00
parent 2e57558ef4
commit a20e42e360
25 changed files with 346 additions and 820 deletions

View File

@@ -2,54 +2,15 @@ import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
import {SimpleSchema} from 'meteor/aldeed:simple-schema';
import LabelFormats from '/imports/LabelFormats.js';
if(Meteor.isServer) {
const puppeteer = require('puppeteer');
//let Future = Npm.require('fibers/future');
//
//async function printLabels(data, callback) {
// let params = "";
// let url = Meteor.absoluteUrl("/LabelPrint");
//
// params = Object.keys(data).map(function(k) {
// return encodeURIComponent(k) + "=" + encodeURIComponent(data[k]);
// }).join('&');
//
// url += "?" + params;
//
// const browser = await puppeteer.launch();
// const page = await browser.newPage();
// console.log("Going to: " + url);
// await page.goto(url, {waitUntil: 'networkidle0'});
// // By removing the `path` option, we will receive a `Buffer` from `page.pdf`.
// const pdf = await page.pdf({ width: "6in", height: "4in"}); // format: "A4" //path: 'C:\\Users\\Grumpy\\label.pdf'
//
// await browser.close();
// callback(null, pdf);
//}
Meteor.methods({
//printLabels: function(width, height, layout, title1, title2, ingredients, date) {
// console.log("Loaded Label");
// let future = new Future();
//
// let boundCallback = Meteor.bindEnvironment(function(err, res) {
// if(err) {
// future.throw(err);
// }
// else {
// future.return(res);
// }
// });
//
// printLabels({width, height, layout, title1, title2, ingredients, date}, boundCallback);
//
// return future.wait();
//}
async printLabels(width, height, layout, title1, title2, ingredients, date) {
let data = {width, height, layout, title1, title2, ingredients, date};
async printLabels(format, title1, title2, ingredients, date) {
let data = {format, title1, title2, ingredients, date};
let params = "";
let url = Meteor.absoluteUrl("/PrintLabel");
@@ -64,11 +25,8 @@ if(Meteor.isServer) {
const browser = await puppeteer.launch();
const page = await browser.newPage();
//url = Meteor.absoluteUrl("/StaticTest.html");
//url = Meteor.absoluteUrl("/StaticTest.html");
console.log("Going to: " + url);
await page.goto(url, {waitUntil: 'networkidle0'}); //, {waitUntil: 'networkidle0'}
const pdf = await page.pdf({width: '3in', height: '2in'}); //path: 'C:\\Users\\Grumpy\\label.pdf',
const pdf = await page.pdf({width: LabelFormats[format].width, height: LabelFormats[format].height}); //path: 'C:\\Users\\Grumpy\\label.pdf',
//const pdf = await page.pdf({format: 'A4'});
//await page.pdf({path: 'C:\\Users\\Grumpy\\label.pdf', width: '6in', height: '4in'});
await browser.close();
@@ -85,7 +43,6 @@ if(Meteor.isServer) {
//Note: Price data looks like this: {XZ5Z3CM49NDrJNADA /* MeasureID */: {price: 10.5, effectiveDate: ISODate("2017-01-12T13:14:18.876-08:00"), previousPrice: 9}, ...}
//Measures is an array of MeasureIDs valid for this product.
let products = Meteor.collections.Products.find({}, {fields: {_id: 1, name: 1, measures: 1, prices: 1}, sort: {order: 1}}).fetch();
//let measuresById = measures.reduce((map, measure) => (map[measure._id] = measure), {});
let measuresById = {};
let barcodesByProductAndMeasureIds = {};
let result = {};
@@ -93,11 +50,6 @@ if(Meteor.isServer) {
for(measure of measures) measuresById[measure._id] = measure;
for(barcode of barcodes) barcodesByProductAndMeasureIds[barcode.productAndMeasureId] = barcode.barcodeId;
//console.log(measuresById);
//for(let measureId of Object.keys(measuresById)) {
// console.log(measureId + ":" + measuresById[measureId].name);
//}
for(let product of products) {
for(let measureId of product.measures) {