New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promise looping support #161

Closed
tresf opened this Issue Feb 6, 2017 · 9 comments

Comments

Projects
None yet
3 participants
@tresf
Contributor

tresf commented Feb 6, 2017

The wiki provides detailed instructions for constructing and itterating through a promise loop however this could easily become part of the base API.

Proposal:

  • Take an array of config objects
  • Take an array of data objects
  • Allow both fail-on-error (break the chain) or resume-on-error (continue the chain) behavior
  • If the configArray count is less than the dataArray count, just keep using the last element until completed.

Example:

var resumeOnError = true; // complete chain resolves before throwing.  default=false
qz.printAll(configArray, dataArray, resumeOnError).then(function() {
   alert("Success")
}).catch(function(err) {
   alert("Some errors occurred: " + err); // TODO: handle multiple throws
});

@tresf tresf added this to the 2.1 milestone Feb 6, 2017

@bberenz

This comment has been minimized.

Member

bberenz commented May 22, 2017

Drafted into the API via d234a38

The print method now has an altered signature to allow for 4 overloaded versions:

print(configs, data);
print(configs, data, signatures, signingTimestamps);
print(configs, data, resumeOnError);
print(configs, data, resumeOnError, signatures, signingTimestamps);

configs, signatures, and signingTimestamps can be single values or arrays of those values.

The method also groups all print data assigned to configs under a map before printing, so any multiples of a config in the array will print associated data as a multi-page document, rather than all separate print jobs directed at that printer.

@tresf

This comment has been minimized.

Contributor

tresf commented May 26, 2017

@klabarge can you please test this feature out so that we can close the bug report?

The most important feature is to verify that our promise loop example works exactly the same as the new API feature. The new API feature allows the configs to be an array. The rest is done internally to make sure the correct jobs make it to the respective printers. If you send 2 configs and 1 data, both printers should receive a copy of the same job.

@tresf

This comment has been minimized.

Contributor

tresf commented Jun 14, 2017

@klabarge bump.

@tresf

This comment has been minimized.

Contributor

tresf commented Jul 7, 2017

I've begun testing this and it seems to fallback to PrintRaw in the following scenario:

  function printPDF() {
        var config = getUpdatedConfig();
        var opts = getUpdatedOptions(true);

        var printData1 = [
            { type: 'pixel', format: 'pdf', flavor: 'file', data: 'assets/pdf_sample.pdf', options: opts }
        ];
		
        var printData2 = [
	   { type: 'pixel', format: 'html', flavor: 'file', data: 'https://google.com', options: opts }
        ];

        qz.print(config, [printData1, printData2]).catch(displayError);
    }
@bberenz

This comment has been minimized.

Member

bberenz commented Jul 7, 2017

The data parameter is expecting an array of objects, so the array of arrays (of objects) is invalid. It would have to be formatted like:

var printData = [
  { type: 'pixel', format: 'pdf', flavor: 'file', data: 'assets/pdf_sample.pdf', options: opts },
  { type: 'pixel', format: 'html', flavor: 'file', data: 'https://google.com', options: opts }
];

qz.print(config, printData).catch(displayError);

But this is still invalid, as we currently don't support a mixture of different formats.

@tresf

This comment has been minimized.

Contributor

tresf commented Jul 7, 2017

The data parameter is expecting an array of objects, so the array of arrays (of objects) is invalid. It would have to be formatted like:

Then I think we designed it wrong. Currently our examples show ["foo", "bar"] for raw and that will break for multiples, right?

@bberenz

This comment has been minimized.

Member

bberenz commented Jul 7, 2017

Our examples also show [{pixel}, {pixel}] for pdf/html/images, which as you just saw also breaks for multiples.

With the current implementation for print([config1, config2], [{data1}, {data2}]) data/configs match up 1:1, for print(config1, [{data1}, {data2}]) config1 gets both data, and for print([config1, config2], {data1}) both configs get a copy of data1. (all independent of raw/pixel type/format).

It sounds like instead, you want print([config1, config2], [{data1}, {data2}]) where each config gets a copy of the data array (essentially the same as print([config1, config2], {data1})), and you have to use print([config1, config2], [[{data1}, {data2}], [{data3}, {data4}]]) for a 1:1 match up.

Current implementation matches what you have documented in the wiki, each {dataN} is 1:1 to each configN.

@bberenz

This comment has been minimized.

Member

bberenz commented Jul 7, 2017

Changed over to array of data-arrays under 530463c

@klabarge

This comment has been minimized.

Contributor

klabarge commented Jul 12, 2017

I tested the below three scenarios, all worked flawlessly.

The last unit test mixed raw and pixel printing.

1 config : many data

function printPDF() {
    var config = qz.configs.create('PDFWriter');

    var printData1 = [
        { type: 'pixel', format: 'pdf', flavor: 'file', data: 'assets/pdf_sample.pdf' }
    ];
    
    var printData2 = [
        { type: 'pixel', format: 'html', flavor: 'file', data: 'https://google.com' }
    ];

    var printData3 = [
        { type: 'pixel', format: 'image', flavor: 'file', data: 'assets/img/image_sample.png' }
    ];

    qz.print(config, [printData1, printData2, printData3]).catch(displayError);
}

many configs : 1 data

function printPDF() {
    var size = {width: 4, height: 6};
    
    var config1 = qz.configs.create("PDFWriter", {orientation: 'landscape', jobName: 'config1_landscape'});
    var config2 = qz.configs.create("PDFWriter", {size: size, jobName: 'config2_size'});
    var config3 = qz.configs.create("PDFWriter", {rotation: 15, jobName: 'config3_rotation'});

    var printData1 = [
        { type: 'pixel', format: 'pdf', flavor: 'file', data: 'assets/pdf_sample.pdf' }
    ];
    
    qz.print([config1, config2, config3], printData1).catch(displayError);
}

many configs : many data

function printPDF() {
    var size = {width: 4, height: 6};

    var config1 = qz.configs.create("PDFWriter", {orientation: 'landscape', jobName: 'config1_landscape'});
    var config2 = qz.configs.create("PDFWriter", {size: size, jobName: 'config2_size'});
    var config3 = qz.configs.create("PDFWriter", {rotation: 15, jobName: 'config3_rotation'});
    var config4 = qz.configs.create("zebra");

    var printData1 = [
        { type: 'pixel', format: 'pdf', flavor: 'file', data: 'assets/pdf_sample.pdf' }
    ];
    
    var printData2 = [
        { type: 'pixel', format: 'html', flavor: 'file', data: 'https://google.com' }
    ];

    var printData3 = [
        { type: 'pixel', format: 'image', flavor: 'file', data: 'assets/img/image_sample.png' }
    ];
    
    var printData4 = [
    '\nN\n',
    'q609\n',
    'Q203,26\n',
    'B5,26,0,1A,3,7,152,B,"1234"\n',
    'A310,26,0,3,1,1,N,"SKU 00000 MFG 0000"\n',
    'A310,56,0,3,1,1,N,"QZ PRINT APPLET"\n',
    'A310,86,0,3,1,1,N,"TEST PRINT SUCCESSFUL"\n',
    'A310,116,0,3,1,1,N,"FROM SAMPLE.HTML"\n',
    'A310,146,0,3,1,1,N,"QZ.IO"\n',
    { type: 'raw', format: 'image', flavor: 'file', data: 'assets/img/image_sample_bw.png', options: { language: 'EPL', x: 150, y: 300 } },
    '\nP1,1\n'
    ];

    qz.print([config1, config2, config4, config3], [printData1, printData2, printData4, printData3]).catch(displayError);
}

@tresf tresf closed this Jul 12, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment