Skip to content
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 · 14 comments
Closed

Promise looping support #161

tresf opened this issue Feb 6, 2017 · 14 comments
Milestone

Comments

@tresf
Copy link
Contributor

tresf commented Feb 6, 2017

Edit:

This feature is 2.1.0+, relevant commits: 6671317, 91984dd, 91984dd


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
@akberenz
Copy link
Member

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
Copy link
Contributor Author

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
Copy link
Contributor Author

tresf commented Jun 14, 2017

@klabarge bump.

@tresf
Copy link
Contributor Author

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);
    }

@akberenz
Copy link
Member

akberenz 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
Copy link
Contributor Author

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?

@akberenz
Copy link
Member

akberenz 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.

@akberenz
Copy link
Member

akberenz commented Jul 7, 2017

Changed over to array of data-arrays under 530463c

@klabarge
Copy link
Member

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);
}

@harikesh409
Copy link

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);
}

If any of the file in printData is unavailable the printing is getting braked and not proceeding with the preceding items.

@tresf
Copy link
Contributor Author

tresf commented Feb 14, 2020

@harikesh409 please try { resumeOnError = true}, per https://qz.io/api/qz.

@harikesh409
Copy link

harikesh409 commented Feb 14, 2020

@harikesh409 please try { resumeOnError = true}, per https://qz.io/api/qz.

Tried giving it as a single value and as an array also but still it is not moving to the next values.

qz.print(configs,data, true) If I give like this it is working but if I pass as [resumeOnError=true], as per https://qz.io/api/qz it is not working.

@harikesh409
Copy link

@harikesh409 please try { resumeOnError = true}, per https://qz.io/api/qz.

Tried giving it as a single value and as an array also but still it is not moving to the next values.

qz.print(configs,data, true) If I give like this it is working but if I pass as [resumeOnError=true], as per https://qz.io/api/qz it is not working.

Check this

if (typeof arguments[2] === 'boolean') {
                    resumeOnError = arguments[2];

                    if (arguments.length >= 5) {
                        signatures = arguments[3];
                        signaturesTimestamps = arguments[4];
                    }
                } else if (arguments.length >= 4) {
                    signatures = arguments[2];
                    signaturesTimestamps = arguments[3];
                }

                //ensure values are arrays for consistency
                if (signatures && !Array.isArray(signatures)) { signatures = [signatures]; }
                if (signaturesTimestamps && !Array.isArray(signaturesTimestamps)) { signaturesTimestamps = [signaturesTimestamps]; }
            }

the value of resumeOnError is being assigned only if it is boolean but if we pass the option as an array or object the if condition is getting failed and and the default value false is taken.

@tresf
Copy link
Contributor Author

tresf commented Feb 14, 2020

qz.print(configs,data, true) If I give like this it is working

Sorry, it's:

qz.print(configs,data, /* resumeOnError */ true);

My comment with it being an object was not correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants