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

Print labels with username and current date. #43

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ Or you can pass these parameters:
These are the endpoints which Mete supports,
but are not (yet) part of the specification or have additional parameters:

(currently none, yay)
* `POST /users/%uid%/buy_barcode.json` - buys the drink with the barcode `%barcode%` for the user with the id `%id%`
26 changes: 26 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require 'net/http'
require 'date'

class UsersController < ApplicationController
include ApplicationHelper

Expand Down Expand Up @@ -96,6 +99,29 @@ def buy_barcode
buy_drink
end
end

# POST /users/1/print_label
# POST /users/1/print_label.json
def print_label
@user = User.find(params[:id])
text = "#{@user.name} #{Date.today.iso8601}"
uri = URI('http://labello/print')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configureable!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, we need a configuration file. But we need this for #5 anyway.

res = Net::HTTP.post_form(
uri,
'text' => text,
'font' => 'lettergothic',
'align' => 'left',
'fontSize' => '42'
)
result = res.body
respond_to do |format|
format.html do
flash[:info] = "Labello responded with '#{result}'."
redirect_to @user
end
format.json { render json: {"result" => result } }
end
end

# GET /users/1/pay?amount=1.5
def payment
Expand Down
2 changes: 2 additions & 0 deletions app/views/users/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- if @user.audit?
%li
= link_to 'show logs', audits_path(:user => @user)
%li
= link_to 'print label', print_label_user_path(@user), :method => :post
%li
= link_to 'delete user', @user, :method => :delete, :data => {:confirm => "Really delete #{@user.name}’s account?"}
.page-header
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
get 'payment'
get 'buy'
post 'buy_barcode'
post 'print_label'
end
collection do
get 'stats'
Expand Down