From 0d10ef2b5a45b74610477d8c5ae0d06a6303f409 Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Thu, 30 Aug 2012 11:12:23 +0200 Subject: [PATCH] supplier updates mostly --- .gitignore | 2 + Qr scan.mm | 39 ++- app/assets/stylesheets/tablet/application.css | 9 - .../stylesheets/tablet/structure.css.sass | 4 + app/controllers/supplier_controller.rb | 25 ++ app/controllers/user_controller.rb | 2 + app/models/supplier.rb | 24 ++ app/models/table.rb | 4 + app/views/layouts/tablet.html.slim | 13 + app/views/supplier/edit.html.slim | 31 ++ config/application.rb | 1 + config/locales/en.yml | 3 + config/routes.rb | 6 + lib/rqrcode-rails3/qr_container.svg | 259 +++++++++++++++- lib/rqrcode-rails3/waiter.svg | 282 ++++++++++++++++++ spec/models/supplier_spec.rb | 62 ++++ stories | 89 +++--- 17 files changed, 789 insertions(+), 66 deletions(-) create mode 100644 app/views/supplier/edit.html.slim create mode 100644 lib/rqrcode-rails3/waiter.svg create mode 100644 spec/models/supplier_spec.rb diff --git a/.gitignore b/.gitignore index 64bcc76e..6e8cc1a3 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ public/system vendor/cache public/google* replication_design.html +.DS_Store +stories.html diff --git a/Qr scan.mm b/Qr scan.mm index 21770de8..f047faf5 100644 --- a/Qr scan.mm +++ b/Qr scan.mm @@ -6,22 +6,32 @@ - + - + - - - - + + + + + + + + + + + + + + @@ -45,13 +55,17 @@ + + + + - + @@ -64,11 +78,18 @@ Show products with ordering options

- - +
+ + + + + + + +
diff --git a/app/assets/stylesheets/tablet/application.css b/app/assets/stylesheets/tablet/application.css index 0f96e07c..61fbe6b7 100644 --- a/app/assets/stylesheets/tablet/application.css +++ b/app/assets/stylesheets/tablet/application.css @@ -1,13 +1,4 @@ /* - * This is a manifest file that'll be compiled into application.css, which will include all the files - * listed below. - * - * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, - * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. - * - * You're free to add application-wide styles to this file and they'll appear at the top of the - * compiled file, but it's generally better to create a new file per style scope. - * *= require_self *= require_directory . */ diff --git a/app/assets/stylesheets/tablet/structure.css.sass b/app/assets/stylesheets/tablet/structure.css.sass index eab1da4c..d802d120 100644 --- a/app/assets/stylesheets/tablet/structure.css.sass +++ b/app/assets/stylesheets/tablet/structure.css.sass @@ -43,3 +43,7 @@ body margin-bottom: 30px float: left margin-right: 30px +.supplier-is-closed + .alert + form + margin: 0 diff --git a/app/controllers/supplier_controller.rb b/app/controllers/supplier_controller.rb index 0073594d..0e40c82e 100644 --- a/app/controllers/supplier_controller.rb +++ b/app/controllers/supplier_controller.rb @@ -1,9 +1,34 @@ class SupplierController < ApplicationController before_filter :authenticate_supplier! + layout 'tablet' def home render layout: 'tablet' end + + # GET /supplier/settings + def edit + @supplier = current_supplier + end + + # POST /supplier/settings + def update + @supplier = current_supplier + if current_supplier.update_attributes(params[:supplier]) + redirect_to supplier_root_path + else + render action: :edit + end + end + + def mark_as_open + current_supplier.mark_as_open! + redirect_to :back + end + def mark_as_closed + current_supplier.mark_as_closed! + redirect_to :back + end # GET /suppliers/1/active_orders # GET /suppliers/1/active_orders.json def active_orders diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index b6153ab3..3933d922 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -31,6 +31,8 @@ class UserController < ApplicationController @table = Table.find(params[:table_id]) res = {} res[:ocupied] = @table.occupied? + res[:reserved] = @table.reserved? + res[:supplier_closed] = @table.supplier.closed? if list.present? res[:other_supplier] = true if list.supplier_id != @table.supplier_id res[:current_table_id] = list.table_id diff --git a/app/models/supplier.rb b/app/models/supplier.rb index 89f834db..4fcb887e 100644 --- a/app/models/supplier.rb +++ b/app/models/supplier.rb @@ -4,6 +4,14 @@ class Supplier devise :database_authenticatable, :recoverable, :rememberable, :trackable property :name + property :open, type: :boolean, default: false + + #WIFI + property :offer_wifi + property :wifi_ssid + property :wifi_type + property :wifi_password + #has_many :orders, through: :lists has_many :products, dependent: :destroy has_many :product_categories, dependent: :destroy @@ -38,6 +46,22 @@ class Supplier tables.reject{|t| t.section_id.present? } end + def open? + open + end + def closed? + !open? + end + + def mark_as_open! + self.open = true + save + end + def mark_as_closed! + self.open = false + save + end + private def add_section_on_create diff --git a/app/models/table.rb b/app/models/table.rb index 65837e08..4a9e48a2 100644 --- a/app/models/table.rb +++ b/app/models/table.rb @@ -27,6 +27,10 @@ class Table @is_occupied = !self.class.database.view(self.class.active_lists(key: id, reduce: true)).zero? end + def reserved? + false + end + def name number end diff --git a/app/views/layouts/tablet.html.slim b/app/views/layouts/tablet.html.slim index 940b97b5..e182611c 100644 --- a/app/views/layouts/tablet.html.slim +++ b/app/views/layouts/tablet.html.slim @@ -40,6 +40,11 @@ html lang="en" = current_supplier.email b.caret ul.dropdown-menu + - if current_supplier.open? + li + = form_tag supplier_mark_as_closed_path do + = submit_tag t('supplier.close'), class: [:btn, 'btn-danger'], onClick: %|$(this).parents('form').submit()| + li= link_to 'Settings', supplier_settings_path li= link_to 'Logout', destroy_supplier_session_path, method: :delete .container.nav-collapse @@ -53,6 +58,14 @@ html lang="en" .alert.alert-success a.close data-dismiss="alert" × div= flash[:notice] + - if current_supplier.closed? + .row.supplier-is-closed + .span12 + .alert.alert-block + button.close{data-dismiss="alert"} x + p = t('supplier.you_are_currently_closed_alert') + = form_tag supplier_mark_as_open_path do + = submit_tag t('supplier.mark_as_open_button'), class: [:btn, 'btn-primary'] .row .span12 = content_for?(:content) ? yield(:content) : yield diff --git a/app/views/supplier/edit.html.slim b/app/views/supplier/edit.html.slim new file mode 100644 index 00000000..b2dd04a1 --- /dev/null +++ b/app/views/supplier/edit.html.slim @@ -0,0 +1,31 @@ += form_for @supplier, url: supplier_update_settings_path, html: {class: 'form-horizontal'} do |f| + = render 'error_messages', target: current_supplier + .control-group class=(@supplier.errors[:name].any? ? 'error' : nil) + = f.label :name, class: 'control-label' + .controls + = f.text_field :name, class: 'text_field' + .control-group class=(@supplier.errors[:email].any? ? 'error' : nil) + = f.label :email, class: 'control-label' + .controls + = f.text_field :email, class: 'text_field' + .control-group class=(@supplier.errors[:offer_wifi].any? ? 'error' : nil) + = f.label :offer_wifi, class: 'control-label' + .controls + = f.check_box :offer_wifi, class: 'checkbox' + .control-group class=(@supplier.errors[:wifi_ssid].any? ? 'error' : nil) + = f.label :wifi_ssid, class: 'control-label' + .controls + = f.text_field :wifi_ssid, class: 'text_field' + .control-group class=(@supplier.errors[:wifi_type].any? ? 'error' : nil) + = f.label :wifi_type, class: 'control-label' + .controls + = f.select :wifi_type, options_for_select([['web', 'web40'], ['WPA2 Personal', 'wpa2personal']], @supplier.wifi_type) + .control-group class=(@supplier.errors[:wifi_password].any? ? 'error' : nil) + = f.label :wifi_password, class: 'control-label' + .controls + = f.text_field :wifi_password, class: 'text_field' + + .form-actions + = f.submit nil, class: 'btn btn-primary' + ' + = link_to t("helpers.links.cancel"), suppliers_path, class: 'btn' diff --git a/config/application.rb b/config/application.rb index 7e0259a1..584ab998 100644 --- a/config/application.rb +++ b/config/application.rb @@ -72,6 +72,7 @@ module Qrammer # Enable the asset pipeline config.assets.enabled = true + #config.assets.precompile += ['tablet/application.css'] # Version of your assets, change this if you want to expire all your assets config.assets.version = '1.0' diff --git a/config/locales/en.yml b/config/locales/en.yml index 93d85b16..9689e058 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -61,6 +61,9 @@ en: active_lists: Active %{lists} active_lists: title: Active %{lists} + close: Close the shop + you_are_currently_closed_alert: 'You are currently closed and not able to take orders' + mark_as_open_button: 'Open up the place!' user: active_list: title: Active %{list} diff --git a/config/routes.rb b/config/routes.rb index 4834d7b0..7bb7c797 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -29,6 +29,12 @@ Qrammer::Application.routes.draw do post '/supplier/mark_order_in_process' => 'supplier#mark_order_in_process', as: :supplier_mark_order_in_process post '/supplier/order_is_delivered' => 'supplier#order_is_delivered', as: :supplier_order_is_delivered + post '/supplier/mark_as_open' => 'supplier#mark_as_open', as: :supplier_mark_as_open + post '/supplier/mark_as_closed' => 'supplier#mark_as_closed', as: :supplier_mark_as_closed + + get '/supplier/settings' => 'supplier#edit', as: :supplier_settings + match '/supplier/settings' => 'supplier#update', as: :supplier_update_settings, via: [:put, :post] + match '/user' => 'user#home', as: :user_root get '/user/active_list(.:format)' => 'user#active_list', as: :user_active_list get '/user/list_info' => 'user#list_info', as: :user_list_info diff --git a/lib/rqrcode-rails3/qr_container.svg b/lib/rqrcode-rails3/qr_container.svg index 99b5291a..52455868 100644 --- a/lib/rqrcode-rails3/qr_container.svg +++ b/lib/rqrcode-rails3/qr_container.svg @@ -14,7 +14,7 @@ id="svg2991" version="1.1" inkscape:version="0.48.2 r9819" - sodipodi:docname="table_qr_image.svg"> + sodipodi:docname="qr_container.svg"> + + + #table_number + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/rqrcode-rails3/waiter.svg b/lib/rqrcode-rails3/waiter.svg new file mode 100644 index 00000000..8caaa24e --- /dev/null +++ b/lib/rqrcode-rails3/waiter.svg @@ -0,0 +1,282 @@ + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spec/models/supplier_spec.rb b/spec/models/supplier_spec.rb new file mode 100644 index 00000000..976e4e77 --- /dev/null +++ b/spec/models/supplier_spec.rb @@ -0,0 +1,62 @@ +require 'spec_helper' + +describe Supplier do + before :each do + @supplier = build :supplier + end + # property open + describe :open do + it 'should be false by default' do + @supplier.open.should == false + end + + it 'should not be open? by default' do + @supplier.open?.should == false + end + + it 'should be closed? by default' do + @supplier.closed?.should == true + end + + describe :mark_as_open! do + before :each do + @supplier.mark_as_open! + end + it 'should be persisted in the database' do + @supplier.reload + @supplier.open.should == true + end + + it 'should be open?' do + @supplier.open?.should == true + end + + it 'should not be closed?' do + @supplier.closed?.should == false + end + + end + + describe :mark_as_closed! do + before :each do + @supplier.mark_as_open! + @supplier.mark_as_closed! + end + + it 'should be persisted in the database' do + @supplier.reload + @supplier.open.should == false + end + + it 'should be open?' do + @supplier.open?.should == false + end + + it 'should not be closed?' do + @supplier.closed?.should == true + end + end + + end + +end diff --git a/stories b/stories index ed5563b3..80f2bfbc 100644 --- a/stories +++ b/stories @@ -1,35 +1,33 @@ Stories: -- Person moves to different table -- Person tries to create list on occupied table -- Person walks away without paying -- Person checks out menu through qr scan - - Other persion occupies the table by placing an order - - Person tries to order something - -> Is informed that the table is not occupied +* Person moves to different table +* Person tries to create list on occupied table +* Person walks away without paying +* Person checks out menu through qr scan +** Other persion occupies the table by placing an order +** Person tries to order something +** -> Is informed that the table is not occupied -> redirect to user_root_path -- Person1 check out the products by scanning the Qr of an empty table - - Person2 checks out the products by scanning the Qr of the same table - - Person2 places order and gets the list -- Person has an active list and creates an order - - Supplier closes the list - - Person submits order - -> Cannot orde on closed list +* Person1 check out the products by scanning the Qr of an empty table +** Person2 checks out the products by scanning the Qr of the same table +** Person2 places order and gets the list +* Person has an active list and creates an order +** Supplier closes the list +** Person submits order +** -> Cannot orde on closed list Person actions: - When list is open: - - Move table - - Make order - - Request bill - - When no list is open: - - Open list - - Subscribe to existing list - - Request menu - - General actions - - View history - - Access settings - - I have a question +* When list is open: +** Move table +** Make order +** Request bill +* When no list is open: +** Open list +** Subscribe to existing list +** Request menu +* General actions +** View history +** Access settings +** I have a question Alleen restaurant kan rekening afsluiten, als dit nog niet is gebeurd voor een tafel kan een nieuwe persoon geen lijst openen. Alert melding bij restaurant als iemand dit probeert @@ -50,25 +48,28 @@ Actielijst: - Barman en vaste tafels Jukebox koppeling -Wireless wachtwoord via qr code +Wireless wachtwoord -> Login optie +Aparte view voor lijsten die de rekening vragen +Aparte view voor lijsten die aandacht nodig hebben handle closed list on list update for user list +Show warning when closing a list with active orders! -Scan qr button: - If table is not occupied: - - if there is an open list - - if the scan is of the same supplier - - Offer to move table - - else - - Cannot perform action with open list - - else - View menu direct - - When order is placed: - - create list - - add order to list - - table is assigned to person (occupied) - If table is occupied: - - Offer to Join +Scan qr button (see mindmap Qr code.mm for actual version of this schema): +* If table is not occupied: +** if there is an open list +*** if the scan is of the same supplier +**** Offer to move table +*** else +**** Cannot perform action with open list +** else +*** View menu direct +*** When order is placed: +**** create list +**** add order to list +**** table is assigned to person (occupied) +* If table is occupied: +** Offer to Join