move towards mobile deployable app
This commit is contained in:
@@ -30,7 +30,7 @@
|
|||||||
//= require_directory .
|
//= require_directory .
|
||||||
//= require_self
|
//= require_self
|
||||||
var path_mapping = {
|
var path_mapping = {
|
||||||
user_root: '/user',
|
user_root: '/user/home',
|
||||||
join_occupied_table: '/user/join_occupied_table',
|
join_occupied_table: '/user/join_occupied_table',
|
||||||
list_products_for_table: '/user/list_products_for_table',
|
list_products_for_table: '/user/list_products_for_table',
|
||||||
list_products: '/user/list_products'
|
list_products: '/user/list_products'
|
||||||
@@ -67,7 +67,7 @@ function redirect_to(mapping, variables){
|
|||||||
for(var name in variables){
|
for(var name in variables){
|
||||||
vars.push(name + '=' +variables[name])
|
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) {
|
function currency(num) {
|
||||||
return Qwaiter.currency(num);
|
return Qwaiter.currency(num);
|
||||||
|
|||||||
@@ -1,7 +1,16 @@
|
|||||||
data_host = ''
|
data_host = window.data_host
|
||||||
|
root_url = window.root_url
|
||||||
window.Quser=
|
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) ->
|
handle_active_list: (callback) ->
|
||||||
$.get(data_host + '/user/list_info.json', (res) ->
|
$.getJSON(data_host + '/user/list_info.json', (res) ->
|
||||||
if !res.list_active
|
if !res.list_active
|
||||||
redirect_to 'user_root', {list_closed: 'true'}
|
redirect_to 'user_root', {list_closed: 'true'}
|
||||||
return
|
return
|
||||||
@@ -15,6 +24,10 @@ window.Quser=
|
|||||||
$('.table-number').text(response.table_number)
|
$('.table-number').text(response.table_number)
|
||||||
if response.supplier_name
|
if response.supplier_name
|
||||||
$('.supplier-name').text(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_payment_default_action(response)
|
||||||
Quser.list_needs_help_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
|
# 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
|
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))
|
$.post(data_host + '/user/list_needs_payment.json', (res) -> window.active_list = res; Quser.list_needs_payment_default_action(res))
|
||||||
load_active_list: () ->
|
load_active_list: () ->
|
||||||
$.get(data_host + '/user/active_list.json', (res) ->
|
$.getJSON(data_host + '/user/active_list.json', (res) ->
|
||||||
window.active_list = res
|
window.active_list = res
|
||||||
unless res.list_active
|
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
|
return
|
||||||
Quser.handle_active_list_default_actions(res)
|
Quser.handle_active_list_default_actions(res)
|
||||||
body = $('#active-list-table tbody')
|
body = $('#active-list-table tbody')
|
||||||
@@ -109,15 +122,17 @@ window.Quser=
|
|||||||
Quser.build_list_table(body, foot, res)
|
Quser.build_list_table(body, foot, res)
|
||||||
)
|
)
|
||||||
load_history_list: () ->
|
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
|
if match
|
||||||
list_id = match[1]
|
list_id = match[1]
|
||||||
else
|
else
|
||||||
return
|
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')
|
body = $('#history-list-table tbody')
|
||||||
foot = $('#history-list-table tfoot')
|
foot = $('#history-list-table tfoot')
|
||||||
Quser.build_list_table(body, foot, res)
|
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: ->
|
load_list_history: ->
|
||||||
match = window.document.URL.toString().match('page=([0-9]+)')
|
match = window.document.URL.toString().match('page=([0-9]+)')
|
||||||
@@ -125,7 +140,7 @@ window.Quser=
|
|||||||
page = match[1]
|
page = match[1]
|
||||||
else
|
else
|
||||||
page = 1
|
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')
|
Quser.paginate(res, '/user/list_history.html')
|
||||||
container = $('#list-history-container')
|
container = $('#list-history-container')
|
||||||
for list in res.lists
|
for list in res.lists
|
||||||
@@ -134,9 +149,7 @@ window.Quser=
|
|||||||
link.attr('href', '/user/list_history/'+list._id + '.html')
|
link.attr('href', '/user/list_history/'+list._id + '.html')
|
||||||
txt = list.supplier_name
|
txt = list.supplier_name
|
||||||
txt += ' - '
|
txt += ' - '
|
||||||
txt += list.created_at.substr(0,10)
|
txt += Quser.format_date(list.created_at)
|
||||||
txt += ' '
|
|
||||||
txt += list.created_at.substr(11, 5)
|
|
||||||
link.text(txt)
|
link.text(txt)
|
||||||
)
|
)
|
||||||
paginate: (wrapper, src) ->
|
paginate: (wrapper, src) ->
|
||||||
@@ -222,7 +235,7 @@ window.Quser=
|
|||||||
return
|
return
|
||||||
Quser.populate_products_table('/user/list_products_for_table.json?table_id='+table_id)
|
Quser.populate_products_table('/user/list_products_for_table.json?table_id='+table_id)
|
||||||
populate_products_table: (src)->
|
populate_products_table: (src)->
|
||||||
$.get(data_host + src, (res) ->
|
$.getJSON(data_host + src, (res) ->
|
||||||
if res.has_occupied_info
|
if res.has_occupied_info
|
||||||
include_order_buttons = !res.is_occupied
|
include_order_buttons = !res.is_occupied
|
||||||
delete(res['has_occupied_info'])
|
delete(res['has_occupied_info'])
|
||||||
@@ -272,7 +285,7 @@ window.Quser=
|
|||||||
)
|
)
|
||||||
actions_for_table: (table)->
|
actions_for_table: (table)->
|
||||||
table = JSON.parse(table) if typeof(table) == 'string'
|
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.current_table_id
|
||||||
if res.other_supplier
|
if res.other_supplier
|
||||||
redirect_to 'user_root', {message: 'table_is_from_other_supplier'}
|
redirect_to 'user_root', {message: 'table_is_from_other_supplier'}
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ $side-spacing: 5px
|
|||||||
text-indent: -5000px
|
text-indent: -5000px
|
||||||
&.active
|
&.active
|
||||||
background-color: $qbrown-active
|
background-color: $qbrown-active
|
||||||
|
&.hide
|
||||||
|
display: none
|
||||||
|
|
||||||
html
|
html
|
||||||
background-image: $wood
|
background-image: $wood
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
class UserController < ApplicationController
|
class UserController < ApplicationController
|
||||||
before_filter :authenticate_user!
|
before_filter :allow_mobile #, :authenticate_user!
|
||||||
layout 'phone'
|
layout 'phone'
|
||||||
|
|
||||||
alias :list :active_list
|
alias :list :active_list
|
||||||
|
|
||||||
|
def allow_mobile
|
||||||
|
headers['Access-Control-Allow-Origin'] = '*'
|
||||||
|
headers['Access-Control-Request-Method'] = '*'
|
||||||
|
end
|
||||||
|
|
||||||
def home
|
def home
|
||||||
handle_message_params
|
handle_message_params
|
||||||
end
|
end
|
||||||
@@ -159,13 +164,17 @@ class UserController < ApplicationController
|
|||||||
def list_info
|
def list_info
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json do
|
format.json do
|
||||||
if !list.try(:active?)
|
if list.present?
|
||||||
current_user.list_is_closed!
|
if !list.try(:active?)
|
||||||
render json: {list_active: false}
|
current_user.list_is_closed!
|
||||||
return
|
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
|
else
|
||||||
list_obj = list.as_json.merge(list_active: list.active? ).merge(list.join_requests_as_json)
|
render json: {not_present: true}
|
||||||
render json: list_obj
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -223,7 +232,7 @@ class UserController < ApplicationController
|
|||||||
format.html do
|
format.html do
|
||||||
end
|
end
|
||||||
format.json do
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -11,13 +11,15 @@ html lang="en"
|
|||||||
/[if lt IE 9]
|
/[if lt IE 9]
|
||||||
= javascript_include_tag "http://html5shim.googlecode.com/svn/trunk/html5.js"
|
= javascript_include_tag "http://html5shim.googlecode.com/svn/trunk/html5.js"
|
||||||
= stylesheet_link_tag "user/application", :media => "all"
|
= 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-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-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-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.png" rel="apple-touch-icon-precomposed"
|
||||||
link href="/favicon.ico" rel="shortcut icon"
|
link href="/favicon.ico" rel="shortcut icon"
|
||||||
javascript:
|
javascript:
|
||||||
var QMobile;
|
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
|
// Dummy holder when Qmobile object is not supplied by the mobile phone
|
||||||
QMobile || (QMobile = {
|
QMobile || (QMobile = {
|
||||||
scanQr: function(){window.location = '/select_qrcode'},
|
scanQr: function(){window.location = '/select_qrcode'},
|
||||||
@@ -33,7 +35,7 @@ html lang="en"
|
|||||||
span.icon-bar
|
span.icon-bar
|
||||||
span.icon-bar
|
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
|
.container.nav-collapse
|
||||||
ul.nav#top-navigation-list
|
ul.nav#top-navigation-list
|
||||||
li= link_to 'View history', user_list_history_path
|
li= link_to 'View history', user_list_history_path
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
.page-header= title t('user.history_list.title', list: List.model_name.human)
|
.page-header= title t('user.history_list.title', list: List.model_name.human)
|
||||||
dl.dl-horizontal
|
dl.dl-horizontal
|
||||||
dt= List.human_attribute_name(:created_at)
|
dt= List.human_attribute_name(:created_at)
|
||||||
dd= l @list.created_at, format: :short
|
dd.list-created-at
|
||||||
dt= Supplier.model_name.human
|
dt= Supplier.model_name.human
|
||||||
dd= @list.supplier.name
|
dd.supplier-name
|
||||||
.well
|
.well
|
||||||
table#history-list-table.table
|
table#history-list-table.table
|
||||||
thead
|
thead
|
||||||
|
|||||||
@@ -4,6 +4,11 @@
|
|||||||
a href="#" onClick="QMobile.scanQr()" = image_tag 'scan-logo.png'
|
a href="#" onClick="QMobile.scanQr()" = image_tag 'scan-logo.png'
|
||||||
.home-footer
|
.home-footer
|
||||||
.home-footer-content
|
.home-footer-content
|
||||||
- if list_open?
|
= link_to 'P', user_list_products_path, class: [:hide, 'home-link', 'home-menu-link']
|
||||||
= link_to 'P', user_list_products_path, class: 'home-menu-link'
|
= link_to 'L', user_active_list_path, class: [:hide, 'home-link', 'home-list-link']
|
||||||
= link_to 'L', user_active_list_path, class: 'home-list-link'
|
- content_for :footer do
|
||||||
|
javascript:
|
||||||
|
$(function(){
|
||||||
|
Quser.home_loader();
|
||||||
|
setInterval("Quser.home_loader()", 7500);
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
.page-header
|
.page-header
|
||||||
.table-number= @table.number
|
.table-number
|
||||||
.supplier-name= @table.supplier.name
|
.supplier-name
|
||||||
h4= t('user.show_products.title', products: Product.model_name.human_plural)
|
h4= t('user.show_products.title', products: Product.model_name.human_plural)
|
||||||
.well
|
.well
|
||||||
table#products-table.table.table-hover
|
table#products-table.table.table-hover
|
||||||
|
|||||||
+1
-1
@@ -37,7 +37,7 @@ Qrammer::Application.routes.draw do
|
|||||||
match '/supplier/settings' => 'supplier#update', as: :supplier_update_settings, via: [:put, :post]
|
match '/supplier/settings' => 'supplier#update', as: :supplier_update_settings, via: [:put, :post]
|
||||||
|
|
||||||
# USER
|
# USER
|
||||||
default_url_options format: 'html'
|
default_url_options format: 'html', host: 'bladiblah'
|
||||||
match '/user' => 'user#home', as: :user_root
|
match '/user' => 'user#home', as: :user_root
|
||||||
get '/user/active_list(.:format)' => 'user#active_list', as: :user_active_list
|
get '/user/active_list(.:format)' => 'user#active_list', as: :user_active_list
|
||||||
get '/user/list_info' => 'user#list_info', as: :user_list_info
|
get '/user/list_info' => 'user#list_info', as: :user_list_info
|
||||||
|
|||||||
@@ -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
|
uc = UserController.new
|
||||||
class << uc
|
class << uc
|
||||||
@@ -19,6 +35,9 @@ for action in uc.action_methods
|
|||||||
if File.exist?(Rails.root.join('app', 'views', 'user', "#{action}.html.slim"))
|
if File.exist?(Rails.root.join('app', 'views', 'user', "#{action}.html.slim"))
|
||||||
puts "action #{action} found"
|
puts "action #{action} found"
|
||||||
result = uc.render_to_string(action: action.dup)
|
result = uc.render_to_string(action: action.dup)
|
||||||
|
#result.sub! /<head>/, '<head><base href="file:///Users/bterkuile/Documents/workspace/Qwaiter/assets/" target="_self" />'
|
||||||
|
result.gsub! /(href|src)="([^#])/, %|\\1="#{root_url}\2|
|
||||||
|
File.open(File.join(android_root, 'user', "#{action}.html"), 'w'){|f| f.puts result}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
view = view = ActionView::Base.new(uc.view_paths)
|
view = view = ActionView::Base.new(uc.view_paths)
|
||||||
@@ -35,4 +54,3 @@ class << view
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
# view.render()
|
# view.render()
|
||||||
binding.pry
|
|
||||||
|
|||||||
Reference in New Issue
Block a user