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:
rickyandClaude Opus 5.5 committed 2026-11-16 08:42:16 -05:00
commit 3e29f14f76
41 files changed
+2194

No files matched your search

+61
View File
@@ -0,0 +1,61 @@
#The MIT License (MIT)
#
#Copyright (c) 2026 rick barrette
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# The print agent's API (redmine-qbo-label-agent). The agent runs on the printer's network, so Redmine never
# needs to reach the printer: the agent signs in with its printer's token (Authorization: Bearer <token>),
# asks for the next label every couple of seconds, prints it, and reports back.
#
# POST /label_agent/poll { "agent": { "version", "printer_model", "printer_address",
# "printer_status" } } (agent is optional)
# => { "job": { "id", "lines", "copies", "max_length_mm", "min_length_mm" } | null, "poll_seconds" }
# POST /label_agent/jobs/:id/result { "status": "printed" | "failed", "error": "..." }
# => { "ok": true }
class LabelAgentController < ActionController::API
before_action :authenticate_agent
def poll
@printer.seen!(ip: request.remote_ip, agent: agent_params)
job = LabelJob.claim_next(@printer)
log_request(job ? "sent job #{job.id}" : 'no job')
render json: { job: job&.to_agent_json, poll_seconds: RedmineQboLabels::Settings.poll_seconds }
end
def result
job = @printer.label_jobs.find_by(id: params[:id])
return render(json: { error: 'not found' }, status: :not_found) unless job
# A repeated report (the agent retrying after a dropped connection) changes nothing
job.finish!(printed: params[:status] == 'printed', error: params[:error]) unless job.finished?
log_request("job #{job.id} #{job.status}#{" (#{job.error})" if job.error.present?}")
render json: { ok: true, status: job.status }
end
private
def authenticate_agent
token = request.authorization.to_s[/\ABearer\s+(\S+)\z/, 1]
@printer = LabelPrinter.authenticate(token)
return if @printer
Rails.logger.warn "[redmine_qbo_labels] Print agent from #{request.remote_ip} has an unknown token"
render json: { error: 'unauthorized' }, status: :unauthorized
end
def agent_params
agent = params[:agent]
agent.respond_to?(:permit) ? agent.permit(:version, :printer_model, :printer_address, :printer_status).to_h : nil
end
def log_request(message)
return unless RedmineQboLabels::Settings.log_requests?
Rails.logger.info "[redmine_qbo_labels] #{@printer.name} agent (#{request.remote_ip}): #{message}"
end
end
+59
View File
@@ -0,0 +1,59 @@
#The MIT License (MIT)
#
#Copyright (c) 2026 rick barrette
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# The Print label dialog: opened from an issue, estimate or invoice (new), sends the label to a printer's
# queue (create), and follows it until it's printed (show, polled by the dialog). The dialog asks for show's
# JSON with an Accept header, not a .json URL: Redmine treats .json as the REST API, without the session.
class LabelJobsController < ApplicationController
before_action :authorize_global
before_action :find_source, only: [:new, :create]
before_action :find_printers, only: [:new, :create]
def new
@lines = @source.lines
@copies = 1
respond_to { |format| format.js }
end
def create
@lines = Array(params[:lines]).first(LabelJob::MAX_LINES)
@copies = params[:copies].to_i.clamp(1, LabelJob::MAX_COPIES)
printer = @printers.find { |p| p.id == params[:printer_id].to_i } || @printers.first
@job = LabelJob.new(label_printer: printer, user: User.current, lines: @lines, copies: @copies,
source_type: @source.type, source_id: @source.id.to_s)
@job.save if printer
respond_to { |format| format.js }
end
def show
@job = LabelJob.find_by(id: params[:id])
return render_404 unless @job && (@job.user_id == User.current.id || User.current.admin?)
LabelJob.expire_lapsed unless @job.finished?
@job.reload
respond_to do |format|
format.json do
render json: { id: @job.id, status: @job.status, status_label: @job.status_label, error: @job.error,
finished: @job.finished?, printer_online: @job.label_printer.online? }
end
end
end
private
def find_source
@source = RedmineQboLabels::LabelSource.find(params[:source_type], params[:source_id])
render_404 unless @source
end
def find_printers
@printers = LabelPrinter.active.sorted.to_a
end
end
@@ -0,0 +1,82 @@
#The MIT License (MIT)
#
#Copyright (c) 2026 rick barrette
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Administration » Label printers: the printers (one print agent each), their agents' tokens and status, and
# the labels printed lately
class LabelPrintersController < ApplicationController
layout 'admin'
self.main_menu = false
menu_item :label_printers
before_action :require_admin
before_action :find_printer, only: [:edit, :update, :destroy, :regenerate_token]
def index
@printers = LabelPrinter.sorted.to_a
LabelJob.expire_lapsed
@jobs = LabelJob.recent.includes(:label_printer, :user).limit(50)
end
def new
@printer = LabelPrinter.new
end
def create
@printer = LabelPrinter.new(printer_params)
@printer.generate_token
if @printer.save
render_token
else
render action: 'new'
end
end
def edit; end
def update
if @printer.update(printer_params)
flash[:notice] = l(:notice_successful_update)
redirect_to label_printers_path
else
render action: 'edit'
end
end
# A new token for the printer's agent; the old one stops working right away
def regenerate_token
@printer.generate_token
@printer.save!
render_token
end
def destroy
@printer.destroy
flash[:notice] = l(:notice_successful_delete)
redirect_to label_printers_path
end
private
def find_printer
@printer = LabelPrinter.find(params[:id])
rescue ActiveRecord::RecordNotFound
render_404
end
def printer_params
params.require(:label_printer).permit(:name, :active)
end
# The token is only ever shown here, right after it's made
def render_token
response.headers['Cache-Control'] = 'no-store'
render action: 'token'
end
end
+102
View File
@@ -0,0 +1,102 @@
#The MIT License (MIT)
#
#Copyright (c) 2026 rick barrette
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# A label sent to a label printer. Queued until the printer's agent picks it up (printing), then printed or
# failed; one its agent never picks up expires (RedmineQboLabels::Settings.job_expiry), so a label doesn't
# print long after it was asked for.
class LabelJob < ApplicationRecord
STATUSES = %w[queued printing printed failed expired].freeze
FINISHED = %w[printed failed expired].freeze
MAX_LINES = 4
MAX_LINE_LENGTH = 40
MAX_COPIES = 10
# A label the agent took but never reported on
PRINTING_TIMEOUT = 2.minutes
# Finished jobs are kept this long
KEEP_FOR = 30.days
belongs_to :label_printer
belongs_to :user, optional: true
serialize :lines, coder: JSON, type: Array
validates :status, inclusion: { in: STATUSES }
validates :copies, numericality: { only_integer: true, greater_than: 0, less_than_or_equal_to: MAX_COPIES }
validate :validate_lines
before_validation :normalize_lines, on: :create
scope :recent, -> { order(created_at: :desc, id: :desc) }
def finished?
FINISHED.include?(status)
end
# The next queued label for a printer, marked as printing, or nil. Lapsed jobs are expired first.
def self.claim_next(printer)
expire_lapsed
transaction do
job = printer.label_jobs.where(status: 'queued').order(:id).lock.first
job&.update!(status: 'printing', claimed_at: Time.current)
job
end
end
# Queued jobs past their expiry, and printing jobs the agent never reported on; old finished jobs go
def self.expire_lapsed
now = Time.current
where(status: 'queued').where(created_at: ...RedmineQboLabels::Settings.job_expiry.ago)
.update_all(status: 'expired', finished_at: now, updated_at: now,
error: I18n.t(:text_qbo_labels_job_expired))
where(status: 'printing').where(claimed_at: ...PRINTING_TIMEOUT.ago)
.update_all(status: 'failed', finished_at: now, updated_at: now,
error: I18n.t(:text_qbo_labels_job_unconfirmed))
where(created_at: ...KEEP_FOR.ago).delete_all
end
# The agent's report: printed, or failed with why
def finish!(printed:, error: nil)
update!(status: printed ? 'printed' : 'failed', finished_at: Time.current,
error: printed ? nil : error.to_s.truncate(1000).presence || I18n.t(:text_qbo_labels_job_failed))
end
# What the agent needs to print it
def to_agent_json
{
id: id, lines: lines, copies: copies,
max_length_mm: RedmineQboLabels::Settings.max_length_mm,
min_length_mm: RedmineQboLabels::Settings.min_length_mm
}
end
def status_label
I18n.t("label_qbo_labels_status_#{status}")
end
def source
RedmineQboLabels::LabelSource.find(source_type, source_id) if source_type.present?
end
private
def normalize_lines
self.lines = Array(lines).map { |line| line.to_s.squish }
self.lines = lines.map(&:upcase) if RedmineQboLabels::Settings.uppercase?
self.lines = lines.reject(&:blank?)
end
def validate_lines
if lines.blank?
errors.add(:base, :qbo_labels_no_text)
elsif lines.size > MAX_LINES || lines.any? { |line| line.length > MAX_LINE_LENGTH }
errors.add(:base, :qbo_labels_text_too_long, count: MAX_LINE_LENGTH)
end
end
end
+72
View File
@@ -0,0 +1,72 @@
#The MIT License (MIT)
#
#Copyright (c) 2026 rick barrette
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# A label printer, reached through the print agent on its network. The agent signs in with a token and asks
# for labels every couple of seconds (LabelAgentController).
class LabelPrinter < ApplicationRecord
TOKEN_PREFIX = 'qbl_'
# The agent counts as online when it asked for labels within this time
ONLINE_WITHIN = 30.seconds
# How often an agent's polls update last_seen_at (saves a write every 2 seconds)
SEEN_RESOLUTION = 15.seconds
has_many :label_jobs, dependent: :delete_all
validates :name, presence: true, length: { maximum: 60 }, uniqueness: { case_sensitive: false }
validates :token_digest, presence: true
scope :active, -> { where(active: true) }
scope :sorted, -> { order(:name) }
attr_reader :token
def self.digest(token)
Digest::SHA256.hexdigest(token.to_s)
end
# The active printer whose agent has this token, or nil
def self.authenticate(token)
return nil unless token.to_s.start_with?(TOKEN_PREFIX)
active.find_by(token_digest: digest(token))
end
# Makes a new token (kept in #token until the record is reloaded) and returns it
def generate_token
@token = "#{TOKEN_PREFIX}#{SecureRandom.base58(32)}"
self.token_digest = self.class.digest(@token)
@token
end
def online?
last_seen_at.present? && last_seen_at > ONLINE_WITHIN.ago
end
# Records an agent's poll, and what it says about the printer when it says anything
def seen!(ip:, agent: nil)
changes = {}
changes[:last_seen_at] = Time.current if last_seen_at.nil? || last_seen_at < SEEN_RESOLUTION.ago
changes[:last_ip] = ip if ip.present? && ip != last_ip
if agent.is_a?(Hash)
{ agent_version: 'version', printer_model: 'printer_model', printer_address: 'printer_address',
printer_status: 'printer_status' }.each do |column, key|
next unless agent.key?(key)
value = agent[key].to_s.truncate(250).presence
changes[column] = value if value != self[column]
end
end
update_columns(changes.merge(updated_at: Time.current)) if changes.any?
end
def to_s
name
end
end
@@ -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) %>
+69
View File
@@ -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>
+7
View File
@@ -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 %>
+3
View File
@@ -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();
+11
View File
@@ -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>
+6
View File
@@ -0,0 +1,6 @@
<h2><%= link_to l(:label_label_printer_plural), label_printers_path %> &#187; <%= @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 %>
+98
View File
@@ -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 %>
+6
View File
@@ -0,0 +1,6 @@
<h2><%= link_to l(:label_label_printer_plural), label_printers_path %> &#187; <%= 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 %>
+30
View File
@@ -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 %> &#187; <%= @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>
+42
View File
@@ -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' %>
&ndash;
<%= 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>