mirror of
https://github.com/rickbarrette/redmine_qbo_labels.git
synced 2026-11-18 01:50:36 -05:00
New plugin: print part labels on a Brother QL printer
Print label in the top-right actions of issues, estimates and invoices prints the customer's last name and the PO number (W/E/I + number) in big bold letters on a 62mm continuous roll, with a preview of the label and its status until it's printed. A print agent on the printer's network (redmine_qbo_label_agent) asks Redmine for labels every couple of seconds with its printer's token, so labels print from anywhere. Administration » Label printers: printers, agent tokens and status, recent labels. Settings: label lengths, capitals, poll interval, how long a label waits for an offline agent, and logging the agents' requests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
3e29f14f76
41 files changed
+2194
No files matched your search
@@ -0,0 +1,5 @@
|
||||
<%# Print label on an issue's page: Redmine's issue actions have no hook, so the link goes there from here %>
|
||||
<template id="qbo-label-issue-link"><%= render partial: 'label_hooks/print_link', locals: { source_type: 'issue', source_id: issue.id } %></template>
|
||||
<%= javascript_tag do %>
|
||||
$(function() { QboLabels.placeIssueLink('#qbo-label-issue-link'); });
|
||||
<% end %>
|
||||
@@ -0,0 +1,4 @@
|
||||
<%# Print label, in the top-right actions of an issue, estimate or invoice; opens the print dialog %>
|
||||
<%= link_to sprite_icon('qbo-label-print', l(:button_qbo_labels_print), plugin: 'redmine_qbo_labels'),
|
||||
new_label_job_path(source_type: source_type, source_id: source_id),
|
||||
remote: true, class: 'icon icon-qbo-label-print', title: l(:button_qbo_labels_print) %>
|
||||
@@ -0,0 +1,69 @@
|
||||
<%# The Print label dialog: the label's lines (filled from the issue, estimate or invoice), a preview drawn
|
||||
the way the print agent draws it (assets/javascripts/qbo_labels.js), copies and printer %>
|
||||
<div id="qbo-label-dialog"
|
||||
data-max-length-mm="<%= RedmineQboLabels::Settings.max_length_mm %>"
|
||||
data-min-length-mm="<%= RedmineQboLabels::Settings.min_length_mm %>"
|
||||
data-uppercase="<%= RedmineQboLabels::Settings.uppercase? %>"
|
||||
data-text-printing="<%= l(:text_qbo_labels_printing) %>"
|
||||
data-text-waiting="<%= l(:text_qbo_labels_waiting) %>"
|
||||
data-text-offline="<%= l(:text_qbo_labels_offline) %>"
|
||||
data-text-lost="<%= l(:text_qbo_labels_lost_contact) %>">
|
||||
<% if @printers.empty? %>
|
||||
<p class="nodata"><%= l(:text_qbo_labels_no_printers) %></p>
|
||||
<% else %>
|
||||
<%= form_tag label_jobs_path, remote: true, id: 'qbo-label-form' do %>
|
||||
<%= hidden_field_tag :source_type, @source.type %>
|
||||
<%= hidden_field_tag :source_id, @source.id %>
|
||||
<% if @job&.errors&.any? %>
|
||||
<div id="errorExplanation"><ul><% @job.errors.full_messages.each do |message| %><li><%= message %></li><% end %></ul></div>
|
||||
<% end %>
|
||||
|
||||
<div class="qbo-label-preview-wrap">
|
||||
<canvas class="qbo-label-preview" width="1" height="1" aria-label="<%= l(:label_qbo_labels_preview) %>"></canvas>
|
||||
<div class="qbo-label-size"></div>
|
||||
</div>
|
||||
|
||||
<div class="tabular">
|
||||
<p>
|
||||
<label for="qbo_label_line_0"><%= l(:field_qbo_labels_name) %></label>
|
||||
<%= text_field_tag 'lines[]', @lines[0], id: 'qbo_label_line_0', class: 'qbo-label-line',
|
||||
maxlength: LabelJob::MAX_LINE_LENGTH, autocomplete: 'off' %>
|
||||
</p>
|
||||
<p>
|
||||
<label for="qbo_label_line_1"><%= l(:field_qbo_labels_po_number) %></label>
|
||||
<%= text_field_tag 'lines[]', @lines[1], id: 'qbo_label_line_1', class: 'qbo-label-line',
|
||||
maxlength: LabelJob::MAX_LINE_LENGTH, autocomplete: 'off' %>
|
||||
</p>
|
||||
<p>
|
||||
<label for="qbo_label_copies"><%= l(:field_qbo_labels_copies) %></label>
|
||||
<%= number_field_tag :copies, @copies, id: 'qbo_label_copies', min: 1, max: LabelJob::MAX_COPIES,
|
||||
class: 'qbo-label-copies' %>
|
||||
</p>
|
||||
<% if @printers.size > 1 %>
|
||||
<p>
|
||||
<label for="qbo_label_printer"><%= l(:field_qbo_labels_printer) %></label>
|
||||
<%= select_tag :printer_id,
|
||||
options_for_select(@printers.map { |p| ["#{p.name}#{" (#{l(:label_qbo_labels_offline)})" unless p.online?}", p.id] },
|
||||
params[:printer_id] || @printers.find(&:online?)&.id),
|
||||
id: 'qbo_label_printer' %>
|
||||
</p>
|
||||
<% elsif !@printers.first.online? %>
|
||||
<p class="qbo-label-warning"><%= l(:text_qbo_labels_printer_offline, name: @printers.first.name) %></p>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<p class="buttons">
|
||||
<%= submit_tag l(:button_qbo_labels_print), class: 'qbo-label-submit', data: { disable_with: l(:button_qbo_labels_print) } %>
|
||||
<%= link_to_function l(:button_cancel), 'hideModal(this);' %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<div class="qbo-label-status" hidden>
|
||||
<p class="qbo-label-status-text"></p>
|
||||
<p class="buttons">
|
||||
<%= button_tag l(:button_qbo_labels_print_another), type: 'button', onclick: 'QboLabels.again();', class: 'qbo-label-again' %>
|
||||
<%= button_tag l(:button_close), type: 'button', onclick: 'hideModal(this);' %>
|
||||
</p>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -0,0 +1,7 @@
|
||||
<% if @job.persisted? %>
|
||||
QboLabels.follow(<%= raw({ url: label_job_path(@job), printer: @job.label_printer.name,
|
||||
printer_online: @job.label_printer.online? }.to_json) %>);
|
||||
<% else %>
|
||||
$('#ajax-modal').html('<%= escape_javascript(render partial: 'label_jobs/dialog') %>');
|
||||
QboLabels.initDialog();
|
||||
<% end %>
|
||||
@@ -0,0 +1,3 @@
|
||||
$('#ajax-modal').html('<%= escape_javascript(render partial: 'label_jobs/dialog') %>');
|
||||
showModal('ajax-modal', '480px', '<%= escape_javascript(l(:label_qbo_labels_print_title)) %>');
|
||||
QboLabels.initDialog();
|
||||
@@ -0,0 +1,11 @@
|
||||
<%= error_messages_for 'printer' %>
|
||||
<div class="box tabular">
|
||||
<p>
|
||||
<%= f.text_field :name, size: 30, maxlength: 60, required: true %>
|
||||
<em class="info"><%= l(:text_qbo_labels_printer_name) %></em>
|
||||
</p>
|
||||
<p>
|
||||
<%= f.check_box :active %>
|
||||
<em class="info"><%= l(:text_qbo_labels_printer_active) %></em>
|
||||
</p>
|
||||
</div>
|
||||
@@ -0,0 +1,6 @@
|
||||
<h2><%= link_to l(:label_label_printer_plural), label_printers_path %> » <%= @printer.name %></h2>
|
||||
|
||||
<%= labelled_form_for :label_printer, @printer, url: label_printer_path(@printer), html: { method: :patch } do |f| %>
|
||||
<%= render partial: 'label_printers/form', locals: { f: f } %>
|
||||
<%= submit_tag l(:button_save) %>
|
||||
<% end %>
|
||||
@@ -0,0 +1,98 @@
|
||||
<%# Administration » Label printers %>
|
||||
<div class="contextual">
|
||||
<%= link_to sprite_icon('add', l(:label_qbo_labels_new_printer)), new_label_printer_path, class: 'icon icon-add' %>
|
||||
<%= link_to sprite_icon('settings', l(:label_settings)), plugin_settings_path('redmine_qbo_labels'), class: 'icon icon-settings' %>
|
||||
</div>
|
||||
|
||||
<h2><%= l(:label_label_printer_plural) %></h2>
|
||||
|
||||
<% if @printers.empty? %>
|
||||
<p class="nodata"><%= l(:text_qbo_labels_no_printers_admin) %></p>
|
||||
<% else %>
|
||||
<div class="autoscroll">
|
||||
<table class="list label-printers">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= l(:field_name) %></th>
|
||||
<th><%= l(:field_qbo_labels_agent) %></th>
|
||||
<th><%= l(:field_qbo_labels_printer) %></th>
|
||||
<th><%= l(:field_qbo_labels_last_seen) %></th>
|
||||
<th><%= l(:field_active) %></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @printers.each do |printer| %>
|
||||
<tr>
|
||||
<td class="name"><%= printer.name %></td>
|
||||
<td>
|
||||
<% if printer.online? %>
|
||||
<span class="status-online"><%= l(:label_qbo_labels_online) %></span>
|
||||
<% else %>
|
||||
<span class="status-offline"><%= l(:label_qbo_labels_offline) %></span>
|
||||
<% end %>
|
||||
<% if printer.agent_version.present? %><br><small><%= l(:label_qbo_labels_agent_version, version: printer.agent_version) %></small><% end %>
|
||||
</td>
|
||||
<td>
|
||||
<% if printer.printer_model.present? || printer.printer_address.present? %>
|
||||
<%= [printer.printer_model, printer.printer_address].compact_blank.join(' @ ') %>
|
||||
<% else %>
|
||||
<span class="qbo-label-muted"><%= l(:label_qbo_labels_printer_not_found) %></span>
|
||||
<% end %>
|
||||
<% if printer.printer_status.present? %><br><small><%= printer.printer_status %></small><% end %>
|
||||
</td>
|
||||
<td>
|
||||
<%= printer.last_seen_at ? format_time(printer.last_seen_at) : '-' %>
|
||||
<% if printer.last_ip.present? %><br><small><%= printer.last_ip %></small><% end %>
|
||||
</td>
|
||||
<td><%= checked_image printer.active? %></td>
|
||||
<td class="buttons">
|
||||
<%= link_to sprite_icon('edit', l(:button_edit)), edit_label_printer_path(printer), class: 'icon icon-edit' %>
|
||||
<%= link_to sprite_icon('key', l(:button_qbo_labels_new_token)), regenerate_token_label_printer_path(printer),
|
||||
method: :post, class: 'icon icon-key', data: { confirm: l(:text_qbo_labels_new_token_confirm) } %>
|
||||
<%= link_to sprite_icon('del', l(:button_delete)), label_printer_path(printer), method: :delete,
|
||||
class: 'icon icon-del', data: { confirm: l(:text_are_you_sure) } %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<h3><%= l(:label_qbo_labels_recent_jobs) %></h3>
|
||||
<% if @jobs.empty? %>
|
||||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% else %>
|
||||
<div class="autoscroll">
|
||||
<table class="list label-jobs">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= l(:field_created_on) %></th>
|
||||
<th><%= l(:field_qbo_labels_label) %></th>
|
||||
<th><%= l(:field_qbo_labels_copies) %></th>
|
||||
<th><%= l(:field_qbo_labels_for) %></th>
|
||||
<th><%= l(:field_user) %></th>
|
||||
<th><%= l(:field_qbo_labels_printer) %></th>
|
||||
<th><%= l(:field_status) %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @jobs.each do |job| %>
|
||||
<tr>
|
||||
<td><%= format_time(job.created_at) %></td>
|
||||
<td class="lines"><%= safe_join(job.lines.map { |line| h(line) }, tag.br) %></td>
|
||||
<td><%= job.copies %></td>
|
||||
<td><%= job.source_type.present? ? l("label_qbo_labels_source_#{job.source_type}") + " #{job.source_id}" : '-' %></td>
|
||||
<td><%= job.user ? link_to_user(job.user) : '-' %></td>
|
||||
<td><%= job.label_printer&.name %></td>
|
||||
<td class="status-<%= job.status %>">
|
||||
<%= job.status_label %>
|
||||
<% if job.error.present? %><br><small><%= job.error %></small><% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -0,0 +1,6 @@
|
||||
<h2><%= link_to l(:label_label_printer_plural), label_printers_path %> » <%= l(:label_qbo_labels_new_printer) %></h2>
|
||||
|
||||
<%= labelled_form_for :label_printer, @printer, url: label_printers_path, html: { method: :post } do |f| %>
|
||||
<%= render partial: 'label_printers/form', locals: { f: f } %>
|
||||
<%= submit_tag l(:button_create) %>
|
||||
<% end %>
|
||||
@@ -0,0 +1,30 @@
|
||||
<%# Shown once, right after a printer is added or gets a new token: the agent's token and how to run the agent %>
|
||||
<% redmine_url = "#{Setting.protocol}://#{Setting.host_name}".chomp('/') %>
|
||||
<h2><%= link_to l(:label_label_printer_plural), label_printers_path %> » <%= @printer.name %></h2>
|
||||
|
||||
<div class="flash warning"><%= l(:text_qbo_labels_token_once) %></div>
|
||||
|
||||
<div class="box">
|
||||
<p><strong><%= l(:field_qbo_labels_token) %></strong></p>
|
||||
<pre class="qbo-label-token"><%= @printer.token %></pre>
|
||||
|
||||
<p><%= l(:text_qbo_labels_compose_intro) %></p>
|
||||
<pre class="qbo-label-token">services:
|
||||
label-agent:
|
||||
build: https://github.com/rickbarrette/redmine_qbo_label_agent.git
|
||||
restart: always
|
||||
# Host networking lets the agent find the printer on the local network (Bonjour/mDNS)
|
||||
network_mode: host
|
||||
environment:
|
||||
REDMINE_URL: <%= redmine_url %>
|
||||
AGENT_TOKEN: <%= @printer.token %>
|
||||
PRINTER_MODEL: QL-820NWB
|
||||
# Optional: skip the network search and use this printer
|
||||
# PRINTER: tcp://192.168.0.100
|
||||
# DEBUG, INFO or WARNING
|
||||
LOG_LEVEL: INFO
|
||||
</pre>
|
||||
<p><em class="info"><%= l(:text_qbo_labels_compose_after) %></em></p>
|
||||
</div>
|
||||
|
||||
<p><%= link_to l(:button_back), label_printers_path %></p>
|
||||
@@ -0,0 +1,42 @@
|
||||
<%# Settings for redmine_qbo_labels (Administration » Plugins » Configure) %>
|
||||
<% s = RedmineQboLabels::Settings %>
|
||||
<% field = ->(key) { "settings[#{key}]" } %>
|
||||
|
||||
<p><%= link_to sprite_icon('document', l(:label_label_printer_plural)), label_printers_path, class: 'icon icon-document' %></p>
|
||||
|
||||
<fieldset class="box tabular">
|
||||
<legend><%= l(:label_qbo_labels_label_settings) %></legend>
|
||||
<p>
|
||||
<label for="qbo_labels_min_length"><%= l(:field_qbo_labels_length) %></label>
|
||||
<%= number_field_tag field.call('min_length_in'), s.min_length_in, id: 'qbo_labels_min_length', min: 0.5, max: 12, step: 0.1, style: 'width: 5em' %>
|
||||
–
|
||||
<%= number_field_tag field.call('max_length_in'), s.max_length_in, id: 'qbo_labels_max_length', min: 1, max: 12, step: 0.1, style: 'width: 5em' %>
|
||||
<%= l(:label_qbo_labels_inches) %>
|
||||
<em class="info"><%= l(:text_qbo_labels_length) %></em>
|
||||
</p>
|
||||
<p>
|
||||
<label for="qbo_labels_uppercase"><%= l(:field_qbo_labels_uppercase) %></label>
|
||||
<%= hidden_field_tag field.call('uppercase'), '0', id: nil %>
|
||||
<%= check_box_tag field.call('uppercase'), '1', s.uppercase?, id: 'qbo_labels_uppercase' %>
|
||||
</p>
|
||||
</fieldset>
|
||||
|
||||
<fieldset class="box tabular">
|
||||
<legend><%= l(:label_qbo_labels_agent_settings) %></legend>
|
||||
<p>
|
||||
<label for="qbo_labels_poll"><%= l(:field_qbo_labels_poll_seconds) %></label>
|
||||
<%= number_field_tag field.call('poll_seconds'), s.poll_seconds, id: 'qbo_labels_poll', min: 1, max: 60, style: 'width: 5em' %>
|
||||
<em class="info"><%= l(:text_qbo_labels_poll_seconds) %></em>
|
||||
</p>
|
||||
<p>
|
||||
<label for="qbo_labels_expiry"><%= l(:field_qbo_labels_job_expiry) %></label>
|
||||
<%= number_field_tag field.call('job_expiry_minutes'), s.job_expiry.in_minutes.round, id: 'qbo_labels_expiry', min: 1, max: 1440, style: 'width: 5em' %>
|
||||
<em class="info"><%= l(:text_qbo_labels_job_expiry) %></em>
|
||||
</p>
|
||||
<p>
|
||||
<label for="qbo_labels_log"><%= l(:field_qbo_labels_log_requests) %></label>
|
||||
<%= hidden_field_tag field.call('log_requests'), '0', id: nil %>
|
||||
<%= check_box_tag field.call('log_requests'), '1', s.log_requests?, id: 'qbo_labels_log' %>
|
||||
<em class="info"><%= l(:text_qbo_labels_log_requests) %></em>
|
||||
</p>
|
||||
</fieldset>
|
||||
Reference in new issue
Block a user