From 17b3494033bcf179ef6696e2dc1cbb8d029a0bc1 Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Tue, 11 Sep 2012 10:34:54 +0200 Subject: [PATCH] add some styling on tables view --- app/assets/images/icons/list.svg | 39 ++++--------------- app/assets/images/icons/menu.svg | 13 ++++--- .../javascripts/supplier/qsupplier.js.coffee | 8 ++++ .../supplier/section_tables.css.sass | 9 +++++ .../suppliers/sections_controller.rb | 4 +- app/models/list.rb | 10 +++++ app/models/section.rb | 31 +++++++++++++++ .../suppliers/sections/tables_view.html.slim | 2 + 8 files changed, 79 insertions(+), 37 deletions(-) diff --git a/app/assets/images/icons/list.svg b/app/assets/images/icons/list.svg index 9ac430a3..93b2fac6 100644 --- a/app/assets/images/icons/list.svg +++ b/app/assets/images/icons/list.svg @@ -15,7 +15,10 @@ id="svg2" version="1.1" inkscape:version="0.48.2 r9819" - sodipodi:docname="New document 1"> + sodipodi:docname="list.svg" + inkscape:export-filename="/Users/bterkuile/companytools/development/rails/qrammer/app/assets/images/icons/list.png" + inkscape:export-xdpi="21.549999" + inkscape:export-ydpi="21.549999"> - - - - - + inkscape:version="0.48.2 r9819" + sodipodi:docname="menu.svg" + inkscape:export-filename="/Users/bterkuile/companytools/development/rails/qrammer/app/assets/images/icons/menu.png" + inkscape:export-xdpi="9.2299995" + inkscape:export-ydpi="9.2299995"> diff --git a/app/assets/javascripts/supplier/qsupplier.js.coffee b/app/assets/javascripts/supplier/qsupplier.js.coffee index 38238943..0d3261ae 100644 --- a/app/assets/javascripts/supplier/qsupplier.js.coffee +++ b/app/assets/javascripts/supplier/qsupplier.js.coffee @@ -157,3 +157,11 @@ root.Qsupplier= row.append($('').text(order_txts.join(', '))) row.append($('').html(currency(order.total_amount))) foot.append(''+currency(res.total_amount)+'') + update_section_tables_view: (section_id)-> + $.get(data_host + '/supplier/sections/'+section_id+'/tables_view.json', (res)-> + for table in res.tables + to = $('#section-table-'+table._id) + if table.occupied then to.addClass('occupied') else to.removeClass('occupied') + if table.needs_help then to.addClass('needs_help') else to.removeClass('needs_help') + if table.needs_payment then to.addClass('needs_payment') else to.removeClass('needs_payment') + ) diff --git a/app/assets/stylesheets/supplier/section_tables.css.sass b/app/assets/stylesheets/supplier/section_tables.css.sass index 19bac1b5..a94e368b 100644 --- a/app/assets/stylesheets/supplier/section_tables.css.sass +++ b/app/assets/stylesheets/supplier/section_tables.css.sass @@ -28,6 +28,15 @@ .section-table position: absolute cursor: move + &.occupied + background-color: #ffa + &.needs_help + background-color: #7f7 + &.needs_payment + background-color: #f77 + a + &:hover + text-decoration: none &.section-tables-inactive .section-table margin-top: 10px diff --git a/app/controllers/suppliers/sections_controller.rb b/app/controllers/suppliers/sections_controller.rb index 1af3e37c..863e5960 100644 --- a/app/controllers/suppliers/sections_controller.rb +++ b/app/controllers/suppliers/sections_controller.rb @@ -103,7 +103,9 @@ module Suppliers respond_to do |format| format.html # show.html.erb - format.json { render json: @section } + format.json do + render json: @section.for_tables_as_json + end end end end diff --git a/app/models/list.rb b/app/models/list.rb index bc0bca2d..efc143b7 100644 --- a/app/models/list.rb +++ b/app/models/list.rb @@ -26,6 +26,12 @@ class List } }|, reduce_function: '_sum' + view :active_by_section_id_view, type: :custom, map_function: %|function(doc){ + if(doc.ruby_class == 'List' && doc.state == 'active' && doc.section_id){ + emit(doc.section_id, 1); + } + }|, reduce_function: '_sum' + view :for_user_view, type: :custom, map_function: %|function(doc){ if(doc.ruby_class == 'List' && doc.user_ids && doc.user_ids.length){ doc.user_ids.forEach(function(uid){ @@ -45,6 +51,10 @@ class List list end + def self.active_for_section(section_id, options = {}) + database.view(active_by_section_id_view(key: section_id, reduce: false, include_docs: true)) + end + def self.for_user(user, options = {}) with_pagination_options(options) do |options| database.view(for_user_view({startkey: ["#{user.id}\u9999"], endkey: [user.id], include_docs: true, reduce: false, descending: true}.merge(options))) diff --git a/app/models/section.rb b/app/models/section.rb index aac28a87..60ed7dc7 100644 --- a/app/models/section.rb +++ b/app/models/section.rb @@ -22,6 +22,19 @@ class Section section end + def occupied_tables + return @occupied_tables if @occupied_tables.present? + @active_lists = List.active_for_section(self.id) + @active_lists.include_relation(:table) + @occupied_tables = @active_lists.map(&:table) + end + + def active_lists + return @active_lists if @active_lists.present? + @active_lists = List.active_for_section(self.id) + end + + def width self.path.last.try(:first).to_f - self.path.first.try(:first).to_f end @@ -47,4 +60,22 @@ class Section path_will_change! end end + + def as_json + super.merge(width: width, height: height) + end + + def for_tables_as_json + return @for_tables_as_json if @for_tables_as_json.present? + h = as_json + h[:tables] = [] + for table in tables + ht = table.as_json + ht[:occupied] = occupied_tables.include?(table) + ht[:needs_help] = ht[:occupied] ? active_lists.find{|l| l.table_id == table.id}.try(:needs_help).present? : false + ht[:needs_payment] = ht[:occupied] ? active_lists.find{|l| l.table_id == table.id}.try(:needs_payment).present? : false + h[:tables] << ht + end + @for_tables_as_json = h + end end diff --git a/app/views/suppliers/sections/tables_view.html.slim b/app/views/suppliers/sections/tables_view.html.slim index 1293a46c..145976cb 100644 --- a/app/views/suppliers/sections/tables_view.html.slim +++ b/app/views/suppliers/sections/tables_view.html.slim @@ -17,4 +17,6 @@ active_section_container.find('.section-table').each(function(){ Qsupplier.position_table_in_active_section(active_section_container, $(this), false); }); + Qsupplier.update_section_tables_view('#{@section.id}'); + setInterval("Qsupplier.update_section_tables_view('#{@section.id}')", 7500); });