Fixes and add label to tables

This commit is contained in:
2022-04-16 15:21:07 -05:00
parent 073cc9452e
commit 8b0ddff515
13 changed files with 76 additions and 38 deletions
+1
View File
@@ -51,3 +51,4 @@ erl_crash.dump
public/user
/config/master.key
/public/*.pem
+2
View File
@@ -15,6 +15,7 @@ gem 'slim-rails'
# Gems used only for assets and not required
#gem 'jsonapi-serializers', path: '/home/benjamin/development/rails/components/jsonapi-serializers'
gem 'jsonapi-serializers', github: 'bterkuile/jsonapi-serializers'
gem 'ruby-handlebars'
group :assets do
gem 'bourbon' #, '4.0.2' #animation keyframes
gem 'coffee-rails', '>= 5.0.0'
@@ -133,6 +134,7 @@ group :test do
gem 'timecop'
gem 'turnip'
gem 'webmock'
gem 'rails-controller-testing'
#gem 'rb-fsevent', require: false #if RUBY_PLATFORM =~ /darwin/i
end
+9
View File
@@ -322,6 +322,7 @@ GEM
mime-types
mimemagic (~> 0.3.0)
terrapin (~> 0.6.0)
parslet (1.8.2)
pickadate-rails (3.5.6.0)
railties (>= 3.1.0)
poltergeist (1.18.1)
@@ -365,6 +366,10 @@ GEM
bundler (>= 1.15.0)
railties (= 6.1.4.4)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
actionview (>= 5.0.1.rc1)
activesupport (>= 5.0.1.rc1)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
@@ -410,6 +415,8 @@ GEM
rspec-mocks (~> 3.10)
rspec-support (~> 3.10)
rspec-support (3.10.3)
ruby-handlebars (0.4.0)
parslet (~> 1.6, >= 1.6.2)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
sass (3.4.25)
@@ -526,9 +533,11 @@ DEPENDENCIES
puma (~> 4.3.10)
rack-cors
rails (~> 6.1.0)
rails-controller-testing
rqrcode
rspec-its
rspec-rails
ruby-handlebars
sass-rails
simplecov
simply_stored!
+3 -1
View File
@@ -45,6 +45,8 @@ class DashboardController < ApplicationController
# GET /select_qr_image.svg
def table_qr_image
@table = Table.find(params[:table_id])
hbs = Handlebars::Handlebars.new
@qr_template = hbs.compile(@table.supplier.table_qr_template)
#code = [get_the_app_url, {table_id: @table.id}.to_json].join('?')
code = "q.mozo.bar/s?t=#{@table.id}"
size = RQRCode.minimum_qr_size_from_string(code)
@@ -53,7 +55,7 @@ class DashboardController < ApplicationController
render text: "Pending table_qr_image"
}
format.svg {
render qrcode: code, level: :l, unit: 10, table_number: @table.number, qcontainer: true
render qrcode: code, level: :l, unit: 10, table_number: @qr_template.call(@table), qcontainer: true
}
format.png do
render qrcode: code, level: :l, unit: 10, table_number: @table.number, qcontainer: true
@@ -75,7 +75,7 @@ module Suppliers
private
def table_params
permitted_attributes = [:number, :section_id, :position_x, :position_y, :width, :height]
permitted_attributes = [:number, :label, :section_id, :position_x, :position_y, :width, :height]
# do not raise in development and test for json communication
if request.format.json?
params.require(:table).slice(*permitted_attributes).permit!
+1 -2
View File
@@ -11,8 +11,6 @@ class Supplier
product_categories.products
product_categories.products.product_variants
]
#devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable, :confirmable
property :name
@@ -30,6 +28,7 @@ class Supplier
property :week_starts_on_monday, type: :boolean, default: true
property :employee_settings_storage
property :user_message
property :table_qr_template, default: '{{#if label}}{{number}} - {{label}}{{else}}{{number}}{{/if}}'
# PAYMENT
property :accept_bitpay, type: :boolean, default: false
+1
View File
@@ -4,6 +4,7 @@ class Table
per_page_method :limit_value #kaminari
property :number, type: Integer, default: 1
property :label
property :position_x, type: Float, default: 0
property :position_y, type: Float, default: 0
property :needs_help, type: :boolean, default: false
+1 -1
View File
@@ -7,7 +7,7 @@ test:
validation_framework: :active_model #optional
#database: "http://mozo:secret@localhost:5984/qwaiter_test"
#Testing can only be done as couchdb admin, since it requires creating and destroying the database
database: "mozo_test"
database: "http://admin:<%= ENV['COUCHDB_ADMIN_PASSWORD']%>@localhost:5984/mozo_test"
# database: "http://admin:secret@localhost:5984/qwaiter_test"
production:
validation_framework: :active_model #optional
+1
View File
@@ -72,6 +72,7 @@ class InMemoryQCounter
#couch_settings = YAML.load_file(couch_settings_path)[environment]
couch_settings = YAML.safe_load(ERB.new(File.read(couch_settings_path)).result, [Symbol], [], ['default'])[environment]
database = couch_settings['database'].sub 'localhost', 'host.docker.internal'
#database = couch_settings['database']
#database = couch_settings['database'].sub 'localhost', '172.17.0.1'
db = CouchRest.database(database) # for debug: db = CouchPotato.database.couchrest_database
design_doc = "_design/order_counter"
+7 -1
View File
@@ -4,6 +4,7 @@
# 1. ensure this script is run from the project's root, not the drb_counter directory
pwd_dirname=$(basename $(pwd));
script_dirname="drb_counter";
arch=$(uname)
if [ "$pwd_dirname" == "$script_dirname" ]; then
echo "PWD DIRNAME: "$pwd_dirname;
echo "You must run this script from the project's root dir (../) for the Dockerfile to have access to the configs to COPY";
@@ -23,7 +24,12 @@ docker build -f drb_counter/Dockerfile -t mozo_drb_counter .
# docker run --network=host --env DRB_ENV=production --env COUCHDB_ADMIN_PASSWORD=$COUCHDB_ADMIN_PASSWORD -t -i --rm mozo_drb_counter bash
# 5. Spin up the counter container from the generated image
docker run --network=host --env DRB_ENV=production --env COUCHDB_ADMIN_PASSWORD=$COUCHDB_ADMIN_PASSWORD --add-host=host.docker.internal:host-gateway --restart unless-stopped --detach --name=mozo_drb_counter mozo_drb_counter
if [ $arch == "Darwin" ]; then
echo "Running the created image using the Mac Darwin port exposing"
docker run -p 9022:9022 --env DRB_ENV=production --env COUCHDB_ADMIN_PASSWORD=$COUCHDB_ADMIN_PASSWORD --add-host=host.docker.internal:host-gateway --restart unless-stopped --detach --name=mozo_drb_counter mozo_drb_counter
else
docker run --network=host --env DRB_ENV=production --env COUCHDB_ADMIN_PASSWORD=$COUCHDB_ADMIN_PASSWORD --add-host=host.docker.internal:host-gateway --restart unless-stopped --detach --name=mozo_drb_counter mozo_drb_counter
fi
# To just start the container created through al these steps without rebuilding them:
# docker container start $(docker ps -a -q --filter ancestor=mozo_drb_counter)
+17 -21
View File
@@ -1,6 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
@@ -14,7 +12,7 @@
height="333.07086"
id="svg2991"
version="1.1"
inkscape:version="0.48.5 r10040"
inkscape:version="1.0.2 (e86c8708, 2021-01-15)"
sodipodi:docname="qr_container.svg">
<defs
id="defs3">
@@ -178,17 +176,18 @@
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="2.1440801"
inkscape:cx="80.481439"
inkscape:cy="258.02219"
inkscape:cx="128.05429"
inkscape:cy="314.29086"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="false"
units="mm"
inkscape:window-width="1440"
inkscape:window-height="856"
inkscape:window-height="771"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="0" />
inkscape:window-y="25"
inkscape:window-maximized="0"
inkscape:document-rotation="0" />
<metadata
id="metadata2995">
<rdf:RDF>
@@ -211,15 +210,16 @@
transform="matrix(0.65,0,0,0.65,8.5,-112)">#qrcode
</g>
<text
x="215.10553"
x="292.50552"
y="166.40939"
id="text3799"
xml:space="preserve"
style="font-size:22px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:end;line-height:125%;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:end;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
sodipodi:linespacing="125%"><tspan
x="150"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:22px;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:end;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:end;fill:#000000;fill-opacity:1;stroke:none"><tspan
x="141"
y="177"
id="tspan3801">#table_number</tspan></text>
text-anchor="middle"
id="tspan3801"
style="font-family:sans-serif">#table_number</tspan></text>
<g
id="g3021"
transform="translate(-4,-16)">
@@ -227,22 +227,18 @@
x="81.717873"
y="-104.40486"
id="text7"
style="font-size:37.90859985px">
<tspan
style="font-size:37.9086px;line-height:0%"><tspan
x="81.717873"
y="-104.40486"
id="tspan9"
style="font-size:29.77246857px;fill:#231f20;font-family:Arial Rounded MT Bold;-inkscape-font-specification:Arial Rounded MT Bold">MOZO</tspan>
</text>
style="font-size:29.7725px;font-family:'Arial Rounded MT Bold';-inkscape-font-specification:'Arial Rounded MT Bold';fill:#231f20">MOZO</tspan></text>
<text
x="170.18417"
y="-104.40486"
id="text19"
style="font-size:29.77246857px;fill:#634227;font-family:HelveticaRounded-Bold">
<tspan
style="font-size:29.7725px;line-height:0%;font-family:HelveticaRounded-Bold;fill:#634227"><tspan
id="tspan3938"
style="font-family:Arial Rounded MT Bold;-inkscape-font-specification:Arial Rounded MT Bold">.BAR</tspan>
</text>
style="font-family:'Arial Rounded MT Bold';-inkscape-font-specification:'Arial Rounded MT Bold'">.BAR</tspan></text>
</g>
<g
id="g3036"

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

@@ -0,0 +1,21 @@
# encoding: UTF-8
require 'rails_helper'
describe DashboardController, type: :controller do
before :each do
setup_supplier_for_controller
end
describe "GET #table_qr_image" do
it "does render the svg image" do
table = create :table, supplier: @supplier, number: 7
get :table_qr_image, params: {table_id: table.id}, format: :svg
expect(response.body).to include %[id="tspan3801">7</tspan>]
end
it "does render the svg image with table label if present" do
table = create :table, supplier: @supplier, number: 7, label: "The love seat"
get :table_qr_image, params: {table_id: table.id}, format: :svg
expect(response.body).to include %[id="tspan3801">7 - The love seat</tspan>]
end
end
end
@@ -24,13 +24,13 @@ describe Suppliers::TablesController, type: :controller do
describe "GET #show" do
it "assigns the requested table to @table" do
table = create :table, supplier: @supplier
get :show, id: table, format: :json
get :show, params: {id: table}, format: :json
assigns(:table).should eq(table)
end
it "should not display a table of another supplier" do
table = create :table
get :show, id: table, format: :json
get :show, params: {id: table}, format: :json
response.status.should == 404
end
end
@@ -39,13 +39,13 @@ describe Suppliers::TablesController, type: :controller do
context "with valid attributes" do
it "creates a new table" do
expect{
post :create, table: {number: 22}
post :create, params: {table: {number: 22}}
}.to change(Table, :count).by(1)
end
it "should not be possible to create a table for another supplier, linked to signed in supplier instead" do
supplier2 = create :supplier
expect { post :create, table: {number: 6, supplier_id: supplier2.id} }.to change{ Table.count }.by(1)
expect { post :create, params: {table: {number: 6, supplier_id: supplier2.id}} }.to change{ Table.count }.by(1)
created_table = Table.find_by_number(6)
expect( created_table.supplier_id ).to eq @supplier.id
end
@@ -59,27 +59,27 @@ describe Suppliers::TablesController, type: :controller do
context "valid attributes" do
it "located the requested table" do
put :update, id: @table.id, table: {number: 22}
put :update, params: {id: @table.id, table: {number: 22}}
@table.reload
assigns(:table).should eq(@table)
end
it "changes @table's number attribute" do
put :update, id: @table, table: {number: "14"}
put :update, params: {id: @table, table: {number: "14"}}
@table.reload
@table.number.should eq(14)
end
it "should not be possible to update a table to another supplier" do
supplier2 = create :supplier
put :update, id: @table.id, table: {number: 6, supplier_id: supplier2.id}
put :update, params: {id: @table.id, table: {number: 6, supplier_id: supplier2.id}}
@table.reload
expect( @table.supplier_id ).to eq @supplier.id
end
it "should not be possible to update a table of another supplier" do
table = create :table, number: 11
put :update, id: table.id, table: {number: 6}
put :update, params: {id: table.id, table: {number: 6}}
table.reload
table.number.should == 11
end
@@ -87,7 +87,7 @@ describe Suppliers::TablesController, type: :controller do
context "invalid attributes" do
it "returns an error response" do
#put :update, id: @table, format: :json, table: {number: 'aaa'}
#put :update, params: {id: @table, format: :json, table: {number: 'aaa'}}
#TODO: when proper invalid tables exist expect( JSON.parse(response.body)['errors'] ).to be_present
end
end
@@ -100,14 +100,14 @@ describe Suppliers::TablesController, type: :controller do
it "deletes the table" do
expect{
delete :destroy, id: @table
delete :destroy, params: {id: @table}
}.to change(Table, :count).by(-1)
end
it "should not be possible to delete a table of another supplier" do
table = create :table
expect{
delete :destroy, id: table
delete :destroy, params: {id: table}
}.to_not change(Table, :count)
end
end