diff --git a/app/assets/javascripts/user/application.js b/app/assets/javascripts/user/application.js index f6f7df16..cc75048e 100644 --- a/app/assets/javascripts/user/application.js +++ b/app/assets/javascripts/user/application.js @@ -30,7 +30,7 @@ //= require_directory . //= require_self var path_mapping = { - user_root: '/user', + user_root: '/user/home', join_occupied_table: '/user/join_occupied_table', list_products_for_table: '/user/list_products_for_table', list_products: '/user/list_products' @@ -67,7 +67,7 @@ function redirect_to(mapping, variables){ for(var name in variables){ vars.push(name + '=' +variables[name]) } - window.location = path_mapping[mapping] + '.html?' + vars.join('&') + window.location = root_url + path_mapping[mapping] + '.html?' + vars.join('&') } function currency(num) { return Qwaiter.currency(num); diff --git a/app/assets/javascripts/user/quser.js.coffee b/app/assets/javascripts/user/quser.js.coffee index 0976af0a..d24d1083 100644 --- a/app/assets/javascripts/user/quser.js.coffee +++ b/app/assets/javascripts/user/quser.js.coffee @@ -1,7 +1,16 @@ -data_host = '' +data_host = window.data_host +root_url = window.root_url window.Quser= + format_date: (utc) -> + formatted = '' + formatted += utc.substr(0,10) + formatted += ' ' + formatted += utc.substr(11, 5) + formatted + home_loader: -> + $.getJSON(data_host + '/user/list_info.json', (res) -> Quser.handle_active_list_default_actions(res)) handle_active_list: (callback) -> - $.get(data_host + '/user/list_info.json', (res) -> + $.getJSON(data_host + '/user/list_info.json', (res) -> if !res.list_active redirect_to 'user_root', {list_closed: 'true'} return @@ -15,6 +24,10 @@ window.Quser= $('.table-number').text(response.table_number) if response.supplier_name $('.supplier-name').text(response.supplier_name) + if response.not_present + $('.home-link').hide() + else + $('.home-link').show() Quser.list_needs_payment_default_action(response) Quser.list_needs_help_default_action(response) # join_request_active is to ensure that there are no more modals loaded when one is still active @@ -98,10 +111,10 @@ window.Quser= return unless window.active_list && !window.active_list.needs_payment $.post(data_host + '/user/list_needs_payment.json', (res) -> window.active_list = res; Quser.list_needs_payment_default_action(res)) load_active_list: () -> - $.get(data_host + '/user/active_list.json', (res) -> + $.getJSON(data_host + '/user/active_list.json', (res) -> window.active_list = res unless res.list_active - window.location = '/user/list_history/'+res._id + '.html?list_closed=true' + window.location = root_url + '/user/list_history/'+res._id + '.html?list_closed=true' return Quser.handle_active_list_default_actions(res) body = $('#active-list-table tbody') @@ -109,15 +122,17 @@ window.Quser= Quser.build_list_table(body, foot, res) ) load_history_list: () -> - match = window.document.URL.toString().match('([0-9a-zA-Z]+)(\\?|$)') + match = window.document.URL.toString().match('([0-9a-zA-Z]+)(.html)?(\\?|$)') if match list_id = match[1] else return - $.get(data_host + '/user/list_history/'+list_id+'.json', (res) -> + $.getJSON(data_host + '/user/list_history/'+list_id+'.json', (res) -> body = $('#history-list-table tbody') foot = $('#history-list-table tfoot') Quser.build_list_table(body, foot, res) + $('.list-created-at').text(Quser.format_date(res.created_at)) + $('.supplier-name').text(res.supplier_name) ) load_list_history: -> match = window.document.URL.toString().match('page=([0-9]+)') @@ -125,7 +140,7 @@ window.Quser= page = match[1] else page = 1 - $.get(data_host + '/user/list_history.json?page='+page, (res) -> + $.getJSON(data_host + '/user/list_history.json?page='+page, (res) -> Quser.paginate(res, '/user/list_history.html') container = $('#list-history-container') for list in res.lists @@ -134,9 +149,7 @@ window.Quser= link.attr('href', '/user/list_history/'+list._id + '.html') txt = list.supplier_name txt += ' - ' - txt += list.created_at.substr(0,10) - txt += ' ' - txt += list.created_at.substr(11, 5) + txt += Quser.format_date(list.created_at) link.text(txt) ) paginate: (wrapper, src) -> @@ -222,7 +235,7 @@ window.Quser= return Quser.populate_products_table('/user/list_products_for_table.json?table_id='+table_id) populate_products_table: (src)-> - $.get(data_host + src, (res) -> + $.getJSON(data_host + src, (res) -> if res.has_occupied_info include_order_buttons = !res.is_occupied delete(res['has_occupied_info']) @@ -272,7 +285,7 @@ window.Quser= ) actions_for_table: (table)-> table = JSON.parse(table) if typeof(table) == 'string' - $.get(data_host + '/user/table_info.json?table_id='+table.table_id, (res)-> + $.getJSON(data_host + '/user/table_info.json?table_id='+table.table_id, (res)-> if res.current_table_id if res.other_supplier redirect_to 'user_root', {message: 'table_is_from_other_supplier'} diff --git a/app/assets/stylesheets/user/structure.css.sass b/app/assets/stylesheets/user/structure.css.sass index 7ae7fe3a..03f83469 100644 --- a/app/assets/stylesheets/user/structure.css.sass +++ b/app/assets/stylesheets/user/structure.css.sass @@ -19,6 +19,8 @@ $side-spacing: 5px text-indent: -5000px &.active background-color: $qbrown-active + &.hide + display: none html background-image: $wood diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index eaac3324..1d8db856 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -1,9 +1,14 @@ class UserController < ApplicationController - before_filter :authenticate_user! + before_filter :allow_mobile #, :authenticate_user! layout 'phone' alias :list :active_list + def allow_mobile + headers['Access-Control-Allow-Origin'] = '*' + headers['Access-Control-Request-Method'] = '*' + end + def home handle_message_params end @@ -159,13 +164,17 @@ class UserController < ApplicationController def list_info respond_to do |format| format.json do - if !list.try(:active?) - current_user.list_is_closed! - render json: {list_active: false} - return + if list.present? + if !list.try(:active?) + current_user.list_is_closed! + render json: {list_active: false} + return + else + list_obj = list.as_json.merge(list_active: list.active? ).merge(list.join_requests_as_json) + render json: list_obj + end else - list_obj = list.as_json.merge(list_active: list.active? ).merge(list.join_requests_as_json) - render json: list_obj + render json: {not_present: true} end end end @@ -223,7 +232,7 @@ class UserController < ApplicationController format.html do end format.json do - render json: @list.with_orders_as_json + render json: @list.with_orders_as_json.merge(supplier_name: @list.supplier.name) end end end diff --git a/app/views/layouts/phone.html.slim b/app/views/layouts/phone.html.slim index c7336ee4..24639b2c 100644 --- a/app/views/layouts/phone.html.slim +++ b/app/views/layouts/phone.html.slim @@ -11,13 +11,15 @@ html lang="en" /[if lt IE 9] = javascript_include_tag "http://html5shim.googlecode.com/svn/trunk/html5.js" = stylesheet_link_tag "user/application", :media => "all" - link href="images/apple-touch-icon-144x144.png" rel="apple-touch-icon-precomposed" sizes="144x144" - link href="images/apple-touch-icon-114x114.png" rel="apple-touch-icon-precomposed" sizes="114x114" - link href="images/apple-touch-icon-72x72.png" rel="apple-touch-icon-precomposed" sizes="72x72" - link href="images/apple-touch-icon.png" rel="apple-touch-icon-precomposed" + link href="/images/apple-touch-icon-144x144.png" rel="apple-touch-icon-precomposed" sizes="144x144" + link href="/images/apple-touch-icon-114x114.png" rel="apple-touch-icon-precomposed" sizes="114x114" + link href="/images/apple-touch-icon-72x72.png" rel="apple-touch-icon-precomposed" sizes="72x72" + link href="/images/apple-touch-icon.png" rel="apple-touch-icon-precomposed" link href="/favicon.ico" rel="shortcut icon" javascript: var QMobile; + var data_host = 'http://localhost:3000'; + var root_url = 'file:///Users/bterkuile/Documents/workspace/Qwaiter/assets'; // Dummy holder when Qmobile object is not supplied by the mobile phone QMobile || (QMobile = { scanQr: function(){window.location = '/select_qrcode'}, @@ -33,7 +35,7 @@ html lang="en" span.icon-bar span.icon-bar span.icon-bar - a.brand href=user_root_path = image_tag 'icons/logo-small.png', alt: application_title + = link_to image_tag('icons/logo-small.png', alt: application_title), user_root_path, class: :brand .container.nav-collapse ul.nav#top-navigation-list li= link_to 'View history', user_list_history_path diff --git a/app/views/user/history_list.html.slim b/app/views/user/history_list.html.slim index c437604e..00e7f4e1 100644 --- a/app/views/user/history_list.html.slim +++ b/app/views/user/history_list.html.slim @@ -1,9 +1,9 @@ .page-header= title t('user.history_list.title', list: List.model_name.human) dl.dl-horizontal dt= List.human_attribute_name(:created_at) - dd= l @list.created_at, format: :short + dd.list-created-at dt= Supplier.model_name.human - dd= @list.supplier.name + dd.supplier-name .well table#history-list-table.table thead diff --git a/app/views/user/home.html.slim b/app/views/user/home.html.slim index 81da736f..b7b25125 100644 --- a/app/views/user/home.html.slim +++ b/app/views/user/home.html.slim @@ -4,6 +4,11 @@ a href="#" onClick="QMobile.scanQr()" = image_tag 'scan-logo.png' .home-footer .home-footer-content - - if list_open? - = link_to 'P', user_list_products_path, class: 'home-menu-link' - = link_to 'L', user_active_list_path, class: 'home-list-link' + = link_to 'P', user_list_products_path, class: [:hide, 'home-link', 'home-menu-link'] + = link_to 'L', user_active_list_path, class: [:hide, 'home-link', 'home-list-link'] +- content_for :footer do + javascript: + $(function(){ + Quser.home_loader(); + setInterval("Quser.home_loader()", 7500); + }); diff --git a/app/views/user/list_products_for_table.html.slim b/app/views/user/list_products_for_table.html.slim index 045f1ecc..57ead7e0 100644 --- a/app/views/user/list_products_for_table.html.slim +++ b/app/views/user/list_products_for_table.html.slim @@ -1,6 +1,6 @@ .page-header - .table-number= @table.number - .supplier-name= @table.supplier.name + .table-number + .supplier-name h4= t('user.show_products.title', products: Product.model_name.human_plural) .well table#products-table.table.table-hover diff --git a/config/routes.rb b/config/routes.rb index 0c45a2a5..5ab5556d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -37,7 +37,7 @@ Qrammer::Application.routes.draw do match '/supplier/settings' => 'supplier#update', as: :supplier_update_settings, via: [:put, :post] # USER - default_url_options format: 'html' + default_url_options format: 'html', host: 'bladiblah' 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/script/build_mobile_app.rb b/script/build_mobile_app.rb index 1c836a27..2963594d 100644 --- a/script/build_mobile_app.rb +++ b/script/build_mobile_app.rb @@ -1,3 +1,19 @@ +require 'fileutils' +include FileUtils +#rm_rf Rails.root.join('public', 'assets') +#`rake assets:precompile` +android_root = '/Users/bterkuile/Documents/workspace/Qwaiter/assets' +root_url = "file:///Users/bterkuile/Documents/workspace/Qwaiter/assets" +mkdir_p File.join(android_root, 'user') +rm_rf File.join(android_root, 'assets') +cp_r Rails.root.join('public', 'assets'), File.join(android_root, 'assets') +for css in Dir.glob(File.join(android_root, "**", "*.css")) + contents = File.read(css) + contents.gsub!(/url\("/, %|url("#{root_url}|) + contents.gsub!(/url\(\//, %|url(#{root_url}/|) + File.open(css, 'w'){|f| f.puts contents} +end + uc = UserController.new class << uc @@ -19,6 +35,9 @@ for action in uc.action_methods if File.exist?(Rails.root.join('app', 'views', 'user', "#{action}.html.slim")) puts "action #{action} found" result = uc.render_to_string(action: action.dup) + #result.sub! /
/, '