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

New Label Engine #12050

Merged
merged 43 commits into from
Aug 15, 2023
Merged

New Label Engine #12050

merged 43 commits into from
Aug 15, 2023

Conversation

cram42
Copy link
Contributor

@cram42 cram42 commented Nov 1, 2022

Description

Full custom PDF label support. Allows single page labels (for tape printers) or rectangles-on-a-page sheets (for label sticker paper). Renders to PDF using TCPDF.
Labels are defined as class files within App\Models\Labels, extending the Label abstract class. These define unit of measure, size, and feature support.
Helper functions are in place to make placing text, images, and barcodes easy.
Helper abstract classes are in place to allow multiple labels per page.
API endpoints have been created to find Label templates installed.
A custom (read: hacky) label DefaultLabel has been created to simulate the legacy label generator. When selected, all legacy settings remain available.

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Tested in my browser, as I don't know how to run the included test units (missing testing database).

Test Configuration:

  • PHP version: 7.4.30
  • MySQL version: 10.5.15-MariaDB
  • Webserver version: Apache/2.4.54 (Debian)
  • OS version: Debian GNU/Linux 11 (bullseye)

Checklist:

@cram42 cram42 requested a review from snipe as a code owner November 1, 2022 12:28
@probot-autolabeler probot-autolabeler bot added api backend dependencies Pull requests that update a dependency file frontend labels Nov 1, 2022
@snipe
Copy link
Owner

snipe commented Nov 1, 2022

Hi there - thanks for this! This is a pretty big PR - can you include some screenshots, etc?

@snipe
Copy link
Owner

snipe commented Nov 1, 2022

My inclination for revamping labels was actually going to be javascript-based, not PDF based, so people could change things on the fly and see how they'd look. That said, I'm curious to check out what you've done here.

@cram42
Copy link
Contributor Author

cram42 commented Nov 2, 2022

Hi!

Yeah, I tried a few options with JS and CSS but found the results when printing were inconsistent between printers and even between Chrome's print page and the system dialog. That's why I went with PDF, as we can set the exact page size and it will always print just so. That means it worked with label sheets (I tested on Avery L7162), and also on tape labels (Brother P-Touch tze 24mm).

Your idea of an instant preview is awesome. I'll see if I can get something like that working somehow.

I'll get some screenshots and photos together and attach them here.

@cram42
Copy link
Contributor Author

cram42 commented Nov 2, 2022

Each example below shows the Labels settings page, the assets included, the output from clicking Generate Label, and the output from selecting multiple on the assets index page and choosing Generate Labels from the bulk actions.

New Engine Disabled - Settings Page

Settings - Disabled

New Engine Enabled - DefaultLabel Selected

Settings - Enabled - DefaultLabel

New Engine Enabled - Custom Template Selected

Settings - Enabled - Custom Template

Test Prints

TestPrints

@cram42
Copy link
Contributor Author

cram42 commented Nov 2, 2022

New example using 24mm P-touch label tape

P-touch Labels

@cram42
Copy link
Contributor Author

cram42 commented Nov 2, 2022

The option for 2D Barcode Target allows the QR code URL to include the asset tag so we can use a portable scanner for quick identification. The new /ht/{asset_tag} route is a shorter version of /hardware/byTag/{asset_tag}, to allow for smaller QR codes.

@brianhoganm
Copy link

brianhoganm commented Nov 2, 2022 via email

@cram42
Copy link
Contributor Author

cram42 commented Nov 2, 2022

Looks good. But, can we add specific common fields to the label. Company, Location, Asset Tag, Serial and Person (First & Last Name) (IF ITEM IS CHECKED OUT). This would be very useful for creating student chromebook labels.

Edit: Just realised you wanted First Name and Last Name. Currently, they're separate fields, but I'll have a look at building a definition for concatenation.
Edit 2: OK, simple, there's a fullname attribute we can use. So Assigned To=assignedto.fullname; works.

Sure can. Currently, it's not super user-friendly. But, I just set the Fields Definition to Company=company.name;Asset Tag=asset_tag;Serial=serial;Assigned To=assignedto.username;, and removed any titles. Here's the result:

Fields

@snipe
Copy link
Owner

snipe commented Aug 15, 2023

This kind blew up Codacy for code quality :-/

We probably want to refactor this a bit.
https://app.codacy.com/gh/snipe/snipe-it/commit?cid=754883792&bid=3362446

@snipe
Copy link
Owner

snipe commented Aug 15, 2023

The show full screen icon doesn't seem to do anything?

Screenshot 2023-08-15 at 6 33 59 PM

It just opens a new blank window in safari.

Also we should probably be consistent with our placeholders/variables, at least as far as the users are concerned. We use {FOO} elsewhere in the system, like for the warranty URL.

Screenshot 2023-08-15 at 6 35 16 PM

I'm honestly finding this UI a little confusing and I'm not sure how it's supposed to work.

I'm getting [2023-08-15 10:41:19] local.ERROR: Error: Class 'TCPDF_STATIC' not found in /Users/snipe/Sites/snipe-it/snipe-it/app/Models/Labels/Label.php:537 when I try to load the list

@snipe
Copy link
Owner

snipe commented Aug 15, 2023

I might have to back this change out at least until we handle these issues :(

@snipe
Copy link
Owner

snipe commented Aug 15, 2023

So I think the reason the preview full screen page is blank is because I can't get the list to load, so it can't preview anything. :-/. I think we need to figure out the TCFPDF_STATIC issue first.

@snipe
Copy link
Owner

snipe commented Aug 15, 2023

Okay, I've fixed the composer conflicts and issues. Still seeing an issue with the rendering if assets are selected that don't belong to a company, since the method in Views/Label.php assumes $asset->company exists and then tries to grab the name property. :( Lots of people don't use companies with their assets, so it 500s out with "Trying to get property on non-object when trying to get the name of as non-existent property). Trying to fix this now.

I'm also not really in love with creating a new directory (app\View) when nothing else lives in there. I might refactor that as well.

@snipe
Copy link
Owner

snipe commented Aug 16, 2023

Also possibly related, though it might be an asset tag compatibility issue: #13472

@snipe
Copy link
Owner

snipe commented Aug 16, 2023

A few additional things.... I have 30 set as my "per page", but only 20 are showing up.

Screenshot 2023-08-16 at 1 37 17 AM

And I'm not 100% convinced that this field is even necessary?

Screenshot 2023-08-16 at 1 36 18 AM

I think it's probably more like "use a logo", since I'd expect Snipe-IT's label logo to be the default, unless the company it belongs to (if it has one) has a logo.

@snipe
Copy link
Owner

snipe commented Aug 18, 2023

@cram42 this may be a very stupid question, but I'm not sure how to add a new label template. I added a directory within the Tapes directory called Dymo, but it's not picking it up in the label template listings. Seems like it's just trying to scan that directory, but it's not showing :-/

@snipe
Copy link
Owner

snipe commented Aug 18, 2023

Never mind, I think I've got it

@snipe snipe mentioned this pull request Aug 18, 2023
@najirod
Copy link

najirod commented Aug 28, 2023

@snipe
I think there is a problem with small labels, qr code does not scale or something..

Screenshot 2023-08-28 at 12 23 51 PM
Screenshot 2023-08-28 at 12 23 20 PM
Screenshot 2023-08-28 at 12 21 45 PM

@snipe
Copy link
Owner

snipe commented Aug 28, 2023

@cram42 Are you able to take a look at @najirod's issue, or should we try to handle it?

@Robert-Azelis
Copy link
Contributor

Robert-Azelis commented Sep 5, 2023

I have a missing some options which would be useful for use, like:

  • change size of field
  • align field (right, centre, left)
  • align logo (left, right)
  • add/edit/delete templates (including rename)
  • selection of template to use before print labels
  • DataSource: drop-down list of available attributes to use

@snipe
Copy link
Owner

snipe commented Sep 5, 2023

add/edit/delete templates (including rename)

Renaming wouldn't make sense, since they are specific to the labels themselves.

selection of template to use before print labels

Not sure I understand. You can already select the template before printing.

DataSource: drop-down list of available attributes to use

Probably not feasible, as there are a ton of fields across assets, models, categories, etc. Would be a UI nightmare.

@Robert-Azelis
Copy link
Contributor

selection of template to use before print labels

Not sure I understand. You can already select the template before printing.

If you mean about select template in Labels setting, please bear in mind not all users have access, only admin, so if some user would like to generate labels from assets is not able select template to use (shets/tapes)

@Capobuf
Copy link

Capobuf commented Sep 18, 2023

I am currently not able to go over all the details of this PR, but does it implement #10557 (comment) in some way?

Any field can be added, as long as you know its internal id.
image

Nice!

First of all, thanks for the great job!

I'm a simple user but...how can we find the internal id from, for example, a custom field?

Thanks a lot!

@asuman1179
Copy link

I am trying to create my own Labels\Tapes\Brother setup but I am having issues trying to understand how to change the const to match what I need. @cram42 I am remarkably close but for some reason I have a larger space at the bottom of the tag that I just can figure out where I have gone wrong. The Tape i am using is DK-2211 and i selected 29mm x 45mm as the size for the setup.
tempsnip

@asuman1179
Copy link

Figured it out. I had removed the tag from below the QR code and put in the right column but some other place holder is holding that space.

@najirod
Copy link

najirod commented Sep 27, 2023

@cram42 Are you able to take a look at @najirod's issue, or should we try to handle it?

@snipe
I think my issue about small labels is not fixed yet, I tried again to check but found that there is another bug when you select the default label and setup with barcode it gives "TCPDF ERROR: Error in 1D barcode string"

Screenshot 2023-09-27 at 9 55 20 AM

@cram42
Copy link
Contributor Author

cram42 commented Sep 29, 2023

Sorry all for the absence. My grandfather's had a stroke so I've been at the hospital all day every day.

@snipe I think there is a problem with small labels, qr code does not scale or something..
[snip]

Yep, I get the feeling there may be a minimum QR size. Will check it out now.

[snip]
First of all, thanks for the great job!
I'm a simple user but...how can we find the internal id from, for example, a custom field?
Thanks a lot!

Under custom fields, you can enable the "DB Field" column.
image

@cram42 Are you able to take a look at @najirod's issue, or should we try to handle it?
@snipe I think my issue about small labels is not fixed yet, I tried again to check but found that there is another bug when you select the default label and setup with barcode it gives "TCPDF ERROR: Error in 1D barcode string"
[snip]

I think it's to do with the barcode content vs code format.

I'm going to spin up a dev instance here at the hospital and see if I can get some stuff sorted while gramps sleeps.

@KWWL-Ethan
Copy link

I am trying to create my own Labels\Tapes\Brother setup but I am having issues trying to understand how to change the const to match what I need. @cram42 I am remarkably close but for some reason I have a larger space at the bottom of the tag that I just can figure out where I have gone wrong. The Tape i am using is DK-2211 and i selected 29mm x 45mm as the size for the setup. tempsnip

Figured it out. I had removed the tag from below the QR code and put in the right column but some other place holder is holding that space.

@asuman1179 can you share with the class how you created your own label template? It would be very nice to tweak the existing Brother 24mm template to include both a 1D and 2D barcode.

@Robert-Azelis
Copy link
Contributor

I think will be great to add some option for create own template by "Save as" ;)
and very valuable if someone create simple instruction with description possible options how to adapt template.

@nikhil0426
Copy link

Hey there, sorry a bit new to Snipe-IT. Based on what I read above, if I know the internal ID, I can type it into the DataSource box under Field Definitions to make it appear on the label. I've tried doing this to add categories onto my label but regardless of whether I use "category" or "model.category" in the field definition, I can't get it to show up on my labels. Any advice?
image

@snipe
Copy link
Owner

snipe commented Nov 24, 2023

You'd probably have to try model.category.name

@myriad007
Copy link

Try adding data source like: _snipeit_project_name_6 Look at the posts above.

@bkgarry
Copy link

bkgarry commented Mar 5, 2024

really silly question, should Assigned To be showing who it is Checked Out to? Ours have users checked out but showing nothing for assigned to when generating labels

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api backend dependencies Pull requests that update a dependency file frontend skins
Projects
None yet
Development

Successfully merging this pull request may close these issues.