Compare commits
2
Commits
b44985b75f
...
f09c92f201
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f09c92f201 | ||
|
|
368bf670b9 |
No files matched your search
@@ -1,5 +1,4 @@
|
|||||||
.session_secret
|
.session_secret
|
||||||
.gitea_token
|
|
||||||
public/files/*
|
public/files/*
|
||||||
!public/files/.gitkeep
|
!public/files/.gitkeep
|
||||||
data/labels/*
|
data/labels/*
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ require 'sinatra'
|
|||||||
require "sinatra/reloader"
|
require "sinatra/reloader"
|
||||||
require 'tmpdir'
|
require 'tmpdir'
|
||||||
require 'net/http'
|
require 'net/http'
|
||||||
require 'json'
|
|
||||||
require_relative 'lib/receipt_builder'
|
require_relative 'lib/receipt_builder'
|
||||||
require_relative 'lib/label_repository'
|
require_relative 'lib/label_repository'
|
||||||
|
|
||||||
@@ -155,45 +154,6 @@ helpers do
|
|||||||
receipt.print!(PRINTER_DEVICE_EPSON)
|
receipt.print!(PRINTER_DEVICE_EPSON)
|
||||||
end
|
end
|
||||||
|
|
||||||
GITEA_TOKEN_FILE = File.join(File.dirname(__FILE__), '.gitea_token')
|
|
||||||
|
|
||||||
def fetch_open_issues(repo)
|
|
||||||
token = File.read(GITEA_TOKEN_FILE).strip
|
|
||||||
uri = URI("https://git.priesol.net/api/v1/repos/randy/#{repo}/issues?state=open&type=issues&limit=50")
|
|
||||||
req = Net::HTTP::Get.new(uri)
|
|
||||||
req['Authorization'] = "token #{token}"
|
|
||||||
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }
|
|
||||||
raise "Gitea API returned #{res.code}" unless res.is_a?(Net::HTTPSuccess)
|
|
||||||
|
|
||||||
JSON.parse(res.body)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Prints a receipt-style summary of a repo's open issues -- number, title,
|
|
||||||
# labels, one separator per issue, total at the end.
|
|
||||||
def print_issues(repo)
|
|
||||||
issues = fetch_open_issues(repo).sort_by { |i| i['number'] }
|
|
||||||
|
|
||||||
receipt = ReceiptBuilder.new
|
|
||||||
receipt.align(:center).bold.text("Open issues: #{repo}\n").bold(false)
|
|
||||||
receipt.text("#{Time.now.strftime('%Y-%m-%d %H:%M')}\n")
|
|
||||||
receipt.align(:left).text(('-' * 32) + "\n")
|
|
||||||
|
|
||||||
if issues.empty?
|
|
||||||
receipt.text("(no open issues)\n")
|
|
||||||
else
|
|
||||||
issues.each do |issue|
|
|
||||||
receipt.bold.text("##{issue['number']} #{issue['title']}\n").bold(false)
|
|
||||||
labels = issue['labels'].map { |l| l['name'] }.join(', ')
|
|
||||||
receipt.text("#{labels}\n") unless labels.empty?
|
|
||||||
receipt.text(('-' * 32) + "\n")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
receipt.text("Total: #{issues.size}\n")
|
|
||||||
receipt.feed(3).cut
|
|
||||||
receipt.print!(PRINTER_DEVICE_EPSON)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Renders ZPL to a PNG via Labelary's public API for an inline preview.
|
# Renders ZPL to a PNG via Labelary's public API for an inline preview.
|
||||||
# Fixed at the Datamax label size (4x6in @ 8dpmm ~= 203dpi) -- good enough
|
# Fixed at the Datamax label size (4x6in @ 8dpmm ~= 203dpi) -- good enough
|
||||||
# for a thumbnail, not meant to be exact for other sizes.
|
# for a thumbnail, not meant to be exact for other sizes.
|
||||||
@@ -253,16 +213,6 @@ get '/' do
|
|||||||
erb :index
|
erb :index
|
||||||
end
|
end
|
||||||
|
|
||||||
post '/issues/print' do
|
|
||||||
begin
|
|
||||||
print_issues('home-gitops')
|
|
||||||
flash 'Open issues sent to printer', 'success'
|
|
||||||
rescue => e
|
|
||||||
flash "Failed to print issues (#{e.message})", 'danger'
|
|
||||||
end
|
|
||||||
redirect '/'
|
|
||||||
end
|
|
||||||
|
|
||||||
get '/upload' do
|
get '/upload' do
|
||||||
erb :upload
|
erb :upload
|
||||||
end
|
end
|
||||||
@@ -270,21 +220,37 @@ end
|
|||||||
post '/shipping/zpl' do
|
post '/shipping/zpl' do
|
||||||
zpl = params[:zpl].to_s
|
zpl = params[:zpl].to_s
|
||||||
name = params[:save_as].to_s
|
name = params[:save_as].to_s
|
||||||
|
|
||||||
if zpl.strip.empty?
|
if zpl.strip.empty?
|
||||||
flash 'ZPL text is empty', 'warning'
|
flash 'ZPL text is empty', 'warning'
|
||||||
elsif name.empty?
|
redirect '/upload'
|
||||||
flash 'Name is required to save', 'warning'
|
end
|
||||||
else
|
|
||||||
LABEL_REPO.save(name: name, type: 'zpl', content: zpl)
|
case params[:commit]
|
||||||
if params[:commit] == 'save_and_print'
|
when 'save', 'save_and_print'
|
||||||
begin
|
if name.empty?
|
||||||
print_to_datamax(zpl)
|
flash 'Name is required to save', 'warning'
|
||||||
flash "Saved '#{name}' and sent to printer", 'success'
|
|
||||||
rescue => e
|
|
||||||
flash "Saved '#{name}', but print failed (#{e.message})", 'danger'
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
flash "Saved '#{name}'", 'success'
|
LABEL_REPO.save(name: name, type: 'zpl', content: zpl)
|
||||||
|
if params[:commit] == 'save_and_print'
|
||||||
|
begin
|
||||||
|
print_to_datamax(zpl)
|
||||||
|
flash "Saved '#{name}' and sent to printer", 'success'
|
||||||
|
rescue => e
|
||||||
|
flash "Saved '#{name}', but print failed (#{e.message})", 'danger'
|
||||||
|
end
|
||||||
|
else
|
||||||
|
flash "Saved '#{name}'", 'success'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
# No explicit save/save_and_print action -- e.g. a plain API/CI call.
|
||||||
|
# labelprint stays a "dumb" print API here: just print, nothing saved.
|
||||||
|
begin
|
||||||
|
print_to_datamax(zpl)
|
||||||
|
flash 'ZPL sent to printer', 'success'
|
||||||
|
rescue => e
|
||||||
|
flash "ZPL print failed (#{e.message})", 'danger'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
redirect '/upload'
|
redirect '/upload'
|
||||||
@@ -354,21 +320,37 @@ end
|
|||||||
post '/epson/raw' do
|
post '/epson/raw' do
|
||||||
content = params[:content].to_s
|
content = params[:content].to_s
|
||||||
name = params[:save_as].to_s
|
name = params[:save_as].to_s
|
||||||
|
|
||||||
if content.strip.empty?
|
if content.strip.empty?
|
||||||
flash 'Receipt text is empty', 'warning'
|
flash 'Receipt text is empty', 'warning'
|
||||||
elsif name.empty?
|
redirect '/epson'
|
||||||
flash 'Name is required to save', 'warning'
|
end
|
||||||
else
|
|
||||||
LABEL_REPO.save(name: name, type: 'escpos', content: content)
|
case params[:commit]
|
||||||
if params[:commit] == 'save_and_print'
|
when 'save', 'save_and_print'
|
||||||
begin
|
if name.empty?
|
||||||
print_raw_escpos(content)
|
flash 'Name is required to save', 'warning'
|
||||||
flash "Saved '#{name}' and sent to printer", 'success'
|
|
||||||
rescue => e
|
|
||||||
flash "Saved '#{name}', but print failed (#{e.message})", 'danger'
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
flash "Saved '#{name}'", 'success'
|
LABEL_REPO.save(name: name, type: 'escpos', content: content)
|
||||||
|
if params[:commit] == 'save_and_print'
|
||||||
|
begin
|
||||||
|
print_raw_escpos(content)
|
||||||
|
flash "Saved '#{name}' and sent to printer", 'success'
|
||||||
|
rescue => e
|
||||||
|
flash "Saved '#{name}', but print failed (#{e.message})", 'danger'
|
||||||
|
end
|
||||||
|
else
|
||||||
|
flash "Saved '#{name}'", 'success'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
# No explicit save/save_and_print action -- e.g. a plain API/CI call.
|
||||||
|
# labelprint stays a "dumb" print API here: just print, nothing saved.
|
||||||
|
begin
|
||||||
|
print_raw_escpos(content)
|
||||||
|
flash 'Sent to Epson printer', 'success'
|
||||||
|
rescue => e
|
||||||
|
flash "Epson print failed (#{e.message})", 'danger'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
redirect '/epson'
|
redirect '/epson'
|
||||||
|
|||||||
@@ -9,13 +9,3 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card mt-3">
|
|
||||||
<div class="card-body">
|
|
||||||
<h5 class="card-title">home-gitops open issues</h5>
|
|
||||||
<p class="card-text">Print a receipt-style summary of currently open issues.</p>
|
|
||||||
<form action="/issues/print" method="POST">
|
|
||||||
<button class="btn btn-secondary" type="submit">Print open issues</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
Reference in new issue
Block a user