diff --git a/.gitignore b/.gitignore index 13e841c4..2f615afe 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ # git config --global core.excludesfile ~/.gitignore_global # Ignore bundler config -/.bundle +.bundle # Ignore the default SQLite database. /db/*.sqlite3 diff --git a/Models.dia b/Models.dia index c29c1de7..ec9c700c 100644 Binary files a/Models.dia and b/Models.dia differ diff --git a/app/assets/javascripts/user/app/controllers/application_controller.js.coffee b/app/assets/javascripts/user/app/controllers/application_controller.js.coffee index 5cd1df0e..1eb15657 100644 --- a/app/assets/javascripts/user/app/controllers/application_controller.js.coffee +++ b/app/assets/javascripts/user/app/controllers/application_controller.js.coffee @@ -21,6 +21,7 @@ App.ApplicationController = Ember.Controller.extend @set 'notice', '' ).observes('currentPath') events: + notify: (notification) -> @set 'notice', notification.message list_helped: -> @set 'list.needs_help', false list_needs_help: -> @set 'list.needs_help', true # incoming from other users list_is_paid: -> @set 'list.needs_payment', false diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index ff2aee60..0d82ea3c 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -1,4 +1,4 @@ - class DashboardController < ApplicationController +class DashboardController < ApplicationController layout 'theme1' before_action :allow_all_origins, only: :error_report @@ -13,6 +13,10 @@ render nothing: true end + def scan + + end + def close_window render layout: false end diff --git a/app/models/list.rb b/app/models/list.rb index 007a5dd0..5cb85323 100644 --- a/app/models/list.rb +++ b/app/models/list.rb @@ -52,6 +52,14 @@ class List } }], reduce_function: '_sum' + view :active_users_view, type: :custom, map_function: %[function(doc){ + if(doc.ruby_class == 'List' && doc.state == 'active'){ + doc.user_ids && doc.user_ids.forEach(function(uid){ + emit([doc.supplier_id, uid], 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){ diff --git a/config/routes.rb b/config/routes.rb index a698dfc3..42af8b1f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -87,7 +87,7 @@ Qwaiter::Application.routes.draw do #get '/bars-restaurants' => 'dashboard#bars_restaurants', as: :bars_restaurants #get '/clients' => 'dashboard#clients' #get '/contact' => 'dashboard#contact' - get '/s' => redirect('/scan'), as: :scan + get '/s' => 'dashboard#scan', as: :scan # DEVELOPMENT ONLY get '/qr' => 'dashboard#qr' diff --git a/drb_counter/Dockerfile b/drb_counter/Dockerfile new file mode 100644 index 00000000..aa7a6537 --- /dev/null +++ b/drb_counter/Dockerfile @@ -0,0 +1,28 @@ +FROM ruby:2.2.0 + +# throw errors if Gemfile has been modified since Gemfile.lock +RUN bundle config --global frozen 1 + +RUN mkdir -p /usr/src/app + +WORKDIR /usr/src/app + +# Test +#RUN apt-get update && apt-get install -y qt5-default libqt5webkit5-dev --no-install-recommends && rm -rf /var/lib/apt/lists/* +# Standard +#RUN apt-get update && apt-get install -y nodejs --no-install-recommends && rm -rf /var/lib/apt/lists/* +#RUN apt-get update && apt-get install -y mysql-client postgresql-client sqlite3 --no-install-recommends && rm -rf /var/lib/apt/lists/* +# Specific +#RUN apt-get update && apt-get install -y dos2unix --no-install-recommends && rm -rf /var/lib/apt/lists/* + +COPY Gemfile /usr/src/app/ +COPY Gemfile.lock /usr/src/app/ +#COPY vendor/cache /usr/src/app/vendor/cache +#RUN bundle install --local +RUN rm -rf /usr/src/app/.bundle +RUN bundle install + +COPY . /usr/src/app + +EXPOSE 9022 +CMD ["ruby", "drb_counter.rb"] diff --git a/drb_counter/Gemfile b/drb_counter/Gemfile new file mode 100644 index 00000000..0ef2abef --- /dev/null +++ b/drb_counter/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +gem "couchrest" +gem "pry" diff --git a/drb_counter/Gemfile.lock b/drb_counter/Gemfile.lock new file mode 100644 index 00000000..3cd7ec73 --- /dev/null +++ b/drb_counter/Gemfile.lock @@ -0,0 +1,196 @@ +GEM + remote: https://rubygems.org/ + specs: + coderay (1.1.0) + couchrest (1.2.0) + mime-types (~> 1.15) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + rest-client (~> 1.6.1) + method_source (0.8.2) + mime-types (1.25.1) + multi_json (1.10.1) + pry (0.10.1) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + rdoc (4.2.0) + rest-client (1.6.8) + mime-types (~> 1.16) + rdoc (>= 2.4.2) + slop (3.6.0) + +PLATFORMS + ruby + +DEPENDENCIES + couchrest + pry diff --git a/drb_counter/couchdb_design.yml b/drb_counter/couchdb_design.yml new file mode 100644 index 00000000..7bb546a2 --- /dev/null +++ b/drb_counter/couchdb_design.yml @@ -0,0 +1,8 @@ +views: + by_supplier_id_and_state: + map: | + function(doc) { + if(doc.ruby_class && doc.ruby_class == 'Order') emit([doc['supplier_id'], doc['state']], 1); + } + reduce: _sum +language: "javascript" diff --git a/bin/drb_counter.rb b/drb_counter/drb_counter.rb similarity index 61% rename from bin/drb_counter.rb rename to drb_counter/drb_counter.rb index 6225babd..84edb967 100755 --- a/bin/drb_counter.rb +++ b/drb_counter/drb_counter.rb @@ -1,6 +1,8 @@ #!/usr/bin/env ruby # Make drb server require 'rubygems' +require 'drb' +require 'pry' #require File.expand_path('../lib/in_memory_q_counter', File.dirname(__FILE__)) # This is a non thread safe replacement for the # couchbase counter mechanism since every test needs @@ -16,14 +18,18 @@ class InMemoryQCounter end def get(key, options = {}) - store[key] + value = store[key] + debug "Get key #{key} (#{value})" + value end def set(key, value) + debug "Set key #{key} to #{value}" store[key] = value end def incr(key, options = {}) + debug "Increment key #{key}" # store[key] ||= options[:initial].to_i # store[key] += 1 if store[key] @@ -34,6 +40,7 @@ class InMemoryQCounter end def decr(key, options = {}) + debug "Decrement key #{key}" # store[key] ||= options[:initial].to_i # store[key] -= 1 if store[key] @@ -44,22 +51,45 @@ class InMemoryQCounter end def flush + debug "Flushing store" store.clear end + def debug(message) + puts message + end + def reload_stats! require 'yaml' require 'couchrest' require 'pry' - binding.pry - couch_settings_path = File.join(ENV['MOZO_PATH'], 'config/couchdb.yml') + couch_settings_path = 'config/couchdb.yml' puts "Couch settings path: #{couch_settings_path}" puts "Environment: #{environment.inspect}" couch_settings = YAML.load_file(couch_settings_path)[environment] database = couch_settings['database'] db = CouchRest.database(database) - view_result = db.view("_design/order/_view/by_supplier_id_and_state", reduce: true, group_level: 2) + design_doc = "_design/order_counter" + view_path = File.join design_doc, "_view/by_supplier_id_and_state" + tries = 0 + begin + view_result = db.view(view_path, reduce: true, group: true, group_level: 2) + rescue RestClient::ResourceNotFound => e + puts "Database view #{view_path} not found" + design_doc_path = File.expand_path('../couchdb_design.yml', __FILE__) + doc = YAML.load_file design_doc_path + doc['_id'] = design_doc + db.save_doc(doc) + if tries < 3 + tries += 1 + retry + else + raise e + end + # view not available, initialize as zero + end counts = view_result ? view_result['rows'] : nil + puts "Initialize with: #{counts.to_yaml}" if counts counts.each do |count_spec| supplier_id, order_state = count_spec['key'] @@ -70,17 +100,11 @@ class InMemoryQCounter end end end - rescue RestClient::ResourceNotFound - # view not available, initialize as zero rescue => e raise e end end -require 'drb' -require 'daemons' drb_port = 9022 -Daemons.run_proc('DRBcounter', dir_mode: :normal, dir: File.expand_path("#{File.dirname(__FILE__)}/../tmp/pids")) do - environment = (%w[production staging development test] & ARGV).first - DRb.start_service "druby://:#{drb_port}", InMemoryQCounter.new(reload_stats: true, environment: environment) - DRb.thread.join -end +environment = (%w[production staging development test] & ARGV).first || 'development' +DRb.start_service "druby://:#{drb_port}", InMemoryQCounter.new(reload_stats: true, environment: environment) +DRb.thread.join diff --git a/faye/Dockerfile b/faye/Dockerfile new file mode 100644 index 00000000..f2b3dcbf --- /dev/null +++ b/faye/Dockerfile @@ -0,0 +1,29 @@ +FROM ruby:2.2.0 + +# throw errors if Gemfile has been modified since Gemfile.lock +RUN bundle config --global frozen 1 + +RUN mkdir -p /usr/src/app + +WORKDIR /usr/src/app +RUN apt-get update +# Test +#RUN apt-get update && apt-get install -y qt5-default libqt5webkit5-dev --no-install-recommends && rm -rf /var/lib/apt/lists/* +# Standard +#RUN apt-get update && apt-get install -y nodejs --no-install-recommends && rm -rf /var/lib/apt/lists/* +#RUN apt-get update && apt-get install -y mysql-client postgresql-client sqlite3 --no-install-recommends && rm -rf /var/lib/apt/lists/* +# Specific +#RUN apt-get update && apt-get install -y dos2unix --no-install-recommends && rm -rf /var/lib/apt/lists/* + +COPY Gemfile /usr/src/app/ +COPY Gemfile.lock /usr/src/app/ +#COPY vendor/cache /usr/src/app/vendor/cache +#RUN bundle install --local +RUN rm -rf /usr/src/app/.bundle +RUN bundle install + +COPY . /usr/src/app +ENV FAYE_PORT=9296 +EXPOSE $FAYE_PORT +CMD thin start -R config.ru -p $FAYE_PORT + diff --git a/faye/Gemfile b/faye/Gemfile new file mode 100644 index 00000000..9be00b22 --- /dev/null +++ b/faye/Gemfile @@ -0,0 +1,5 @@ +source 'https://rubygems.org' + +gem "faye" +gem "thin" +gem "pry" diff --git a/faye/Gemfile.lock b/faye/Gemfile.lock new file mode 100644 index 00000000..23235c76 --- /dev/null +++ b/faye/Gemfile.lock @@ -0,0 +1,51 @@ +GEM + remote: https://rubygems.org/ + specs: + addressable (2.3.7) + coderay (1.1.0) + cookiejar (0.3.2) + daemons (1.1.9) + em-http-request (1.1.2) + addressable (>= 2.3.4) + cookiejar + em-socksify (>= 0.3) + eventmachine (>= 1.0.3) + http_parser.rb (>= 0.6.0) + em-socksify (0.3.0) + eventmachine (>= 1.0.0.beta.4) + eventmachine (1.0.7) + faye (1.1.0) + cookiejar (>= 0.3.0) + em-http-request (>= 0.3.0) + eventmachine (>= 0.12.0) + faye-websocket (>= 0.9.1) + multi_json (>= 1.0.0) + rack (>= 1.0.0) + websocket-driver (>= 0.5.1) + faye-websocket (0.9.2) + eventmachine (>= 0.12.0) + websocket-driver (>= 0.5.1) + http_parser.rb (0.6.0) + method_source (0.8.2) + multi_json (1.10.1) + pry (0.10.1) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + rack (1.6.0) + slop (3.6.0) + thin (1.6.3) + daemons (~> 1.0, >= 1.0.9) + eventmachine (~> 1.0) + rack (~> 1.0) + websocket-driver (0.5.1) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.1) + +PLATFORMS + ruby + +DEPENDENCIES + faye + pry + thin diff --git a/fig.yml b/fig.yml index 463e1fca..9291cff5 100644 --- a/fig.yml +++ b/fig.yml @@ -6,14 +6,18 @@ db: - 5984 net: host counters: - image: ruby:2.2 -web: - build: . - #command: bundle exec unicorn -p 3000 -c ./config/unicorn.rb - command: rails s + build: drb_counter + net: host volumes: - - .:/usr/src/app - ports: - - "3000:3000" - #links: - # #- db + - config:/usr/src/app/config +faye: + build: faye + net: host +#web: + #build: . + #command: bundle exec unicorn -p 3000 -c ./config/unicorn.rb + #command: rails s + #volumes: + #- .:/usr/src/app + #ports: + #- "3000:3000"