Dynamic pages, language switcher and fix schedule drag drop time mismatch bug
This commit is contained in:
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 427 B |
@@ -5,3 +5,29 @@
|
|||||||
store: -> @__container__.lookup('controller:application').store
|
store: -> @__container__.lookup('controller:application').store
|
||||||
@App.modals = Ember.Namespace.create()
|
@App.modals = Ember.Namespace.create()
|
||||||
@Modals = @App.modals
|
@Modals = @App.modals
|
||||||
|
|
||||||
|
Ember.$.ajaxPrefilter (options) ->
|
||||||
|
locale = $locale
|
||||||
|
app_version = 0
|
||||||
|
params =
|
||||||
|
locale: $locale
|
||||||
|
app_version: 0
|
||||||
|
if options.type.toUpperCase() == 'GET'
|
||||||
|
if options.data
|
||||||
|
options.data += "&#{$.param(params)}"
|
||||||
|
else
|
||||||
|
options.data = $.param(params)
|
||||||
|
if options.type.toUpperCase() == 'POST'
|
||||||
|
if options.data
|
||||||
|
if typeof(options.data) == 'string'
|
||||||
|
if options.data[0] == '{' || options.data[0] == '[' # json
|
||||||
|
object = JSON.parse(options.data)
|
||||||
|
$.extend object, params
|
||||||
|
options.data = JSON.stringify(object)
|
||||||
|
else
|
||||||
|
options.data += "&#{$.param(params)}"
|
||||||
|
else
|
||||||
|
options.data = params
|
||||||
|
else
|
||||||
|
options.data = $.param(params)
|
||||||
|
true
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
App.LanguageSwitcherComponent = Ember.Component.extend
|
||||||
|
classNames: ['language-switcher-container']
|
||||||
|
locales: (-> ['en', 'nl']).property()
|
||||||
|
actions:
|
||||||
|
switchTo: (locale)->
|
||||||
|
setLocale locale
|
||||||
|
@get('targetObject.store').all("page").invoke 'reload'
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
App.ScheduleController = Ember.ArrayController.extend
|
App.ScheduleController = Ember.ArrayController.extend
|
||||||
event_changed: (event)->
|
event_changed: (event)->
|
||||||
@store.find('employee-shift', event.id).then (employee_shift)->
|
@store.find('employee-shift', event.id).then (employee_shift)->
|
||||||
employee_shift.set 'start_from', event.start.toDate()
|
employee_shift.set 'start_from', event.start
|
||||||
employee_shift.set 'end_on', event.end.toDate()
|
employee_shift.set 'end_on', event.end
|
||||||
employee_shift.save()
|
employee_shift.save()
|
||||||
editEvent: (id, callbacks)->
|
editEvent: (id, callbacks)->
|
||||||
if employee_shift = @store.all('employee-shift').findBy('id', id)
|
if employee_shift = @store.all('employee-shift').findBy('id', id)
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
Ember.Handlebars.helper 'flag', (locale, options)->
|
||||||
|
"<img src=\"#{$assets_path}supplier/flags/flag-#{locale}.png\">".htmlSafe()
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
Ember.Handlebars.registerHelper 'page-body-helper', (resource, params..., options)->
|
||||||
|
body = @get resource
|
||||||
|
template = Ember.Handlebars.compile('body')
|
||||||
|
body.htmlSafe()
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
attr = DS.attr
|
||||||
|
App.Page = DS.Model.extend
|
||||||
|
title: attr 'string'
|
||||||
|
body: attr 'string'
|
||||||
@@ -14,6 +14,8 @@ App.Router.map ->
|
|||||||
@resource 'list', path: ':list_id'
|
@resource 'list', path: ':list_id'
|
||||||
@resource 'employees', ->
|
@resource 'employees', ->
|
||||||
@resource 'employee', path: ':employee_id'
|
@resource 'employee', path: ':employee_id'
|
||||||
|
@resource 'pages', ->
|
||||||
|
@resource 'page', path: ':page_id'
|
||||||
@route 'orders_display' # chromecast etc
|
@route 'orders_display' # chromecast etc
|
||||||
@route 'menu'
|
@route 'menu'
|
||||||
@route 'settings'
|
@route 'settings'
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
each locale in locales
|
||||||
|
a.language-switch-button{ action "switchTo" locale}= flag locale
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
.row: .small-12.columns
|
||||||
|
h2=model.title
|
||||||
|
/= page-body model.body
|
||||||
|
view page-body templateBody=model.body
|
||||||
@@ -36,6 +36,7 @@ if editIensProfile
|
|||||||
App.NumberField valueBinding="controller.model.iens_profile"
|
App.NumberField valueBinding="controller.model.iens_profile"
|
||||||
= image_tag 'supplier/settings/iens-example.png'
|
= image_tag 'supplier/settings/iens-example.png'
|
||||||
span=t "settings.reviews.explanation"
|
span=t "settings.reviews.explanation"
|
||||||
|
.row: .small-12.columns= language-switcher
|
||||||
.form-row.form-actions
|
.form-row.form-actions
|
||||||
if saving
|
if saving
|
||||||
button.button.submit-supplier-settings.disabled
|
button.button.submit-supplier-settings.disabled
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
App.PageBodyView = Ember.View.extend
|
||||||
|
setTemplate: (->
|
||||||
|
body = @get('templateBody')
|
||||||
|
body ||= ""
|
||||||
|
try
|
||||||
|
template = Ember.Handlebars.compile(body)
|
||||||
|
catch
|
||||||
|
template = Ember.Handlebars.compile(tspan('page.cannot_compile'))
|
||||||
|
@set 'template', template
|
||||||
|
@rerender()
|
||||||
|
).on('init').observes('templateBody')
|
||||||
@@ -25,6 +25,7 @@ String.prototype.capitalize = function() { return this.charAt(0).toUpperCase() +
|
|||||||
window.time_zones = <%= ActiveSupport::TimeZone.all.map{|tz| {name: tz.name, formatted: "GMT#{tz.formatted_offset} #{tz.name}"}}.to_json.html_safe %>;
|
window.time_zones = <%= ActiveSupport::TimeZone.all.map{|tz| {name: tz.name, formatted: "GMT#{tz.formatted_offset} #{tz.name}"}}.to_json.html_safe %>;
|
||||||
window.countries = <%= IsoCountryCodes.all.map{|cc| {name: cc.name}}.to_json.html_safe %>;
|
window.countries = <%= IsoCountryCodes.all.map{|cc| {name: cc.name}}.to_json.html_safe %>;
|
||||||
|
|
||||||
|
|
||||||
var path_mapping = {
|
var path_mapping = {
|
||||||
user_root: '/user',
|
user_root: '/user',
|
||||||
join_occupied_table: '/user/join_occupied_table',
|
join_occupied_table: '/user/join_occupied_table',
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
class List
|
|
||||||
constructor: (@attributes)->
|
|
||||||
id: -> @attributes.id || @attributes._id
|
|
||||||
table_number: -> @attributes.table_number
|
|
||||||
total_amount: -> @attributes.total_amount
|
|
||||||
section_title: -> @attributes.section_title
|
|
||||||
needs_help: -> @attributes.needs_help
|
|
||||||
needs_payment: -> @attributes.needs_payment
|
|
||||||
active: -> @attributes.state == 'active'
|
|
||||||
table_id: -> @attributes.table_id
|
|
||||||
products: -> @attributes.products || []
|
|
||||||
has_active_orders: -> @attributes.has_active_orders
|
|
||||||
supplier_name: -> @attributes.supplier_name
|
|
||||||
created_at: -> @attributes.created_at
|
|
||||||
display: ->
|
|
||||||
txt = @supplier_name()
|
|
||||||
txt += ' - '
|
|
||||||
txt += Quser.format_date(@created_at())
|
|
||||||
txt
|
|
||||||
|
|
||||||
@List = List
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
class Order
|
|
||||||
constructor: (@attributes)->
|
|
||||||
table_number: -> @attributes.table_number
|
|
||||||
id: -> @attributes.id || @attributes._id
|
|
||||||
total_amount: -> @attributes.total_amount
|
|
||||||
section_title: -> @attributes.section_title
|
|
||||||
list_id: -> @attributes.list_id
|
|
||||||
state: -> @attributes.state
|
|
||||||
display: ->
|
|
||||||
order_txts = []
|
|
||||||
return '' unless @attributes.products
|
|
||||||
for product in @attributes.products
|
|
||||||
order_txts.push(product.name + ' (' + product.number + ')')
|
|
||||||
order_txts.join(', ')
|
|
||||||
can_process: -> @attributes.state == 'placed'
|
|
||||||
|
|
||||||
@Order = Order
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
.language-switcher-container
|
||||||
|
.language-switch-button
|
||||||
|
+button($bg: $secondary-color, $padding: $button-tny)
|
||||||
|
margin: 0
|
||||||
|
margin-right: 8px
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
module Suppliers
|
||||||
|
class PagesController < Suppliers::ApplicationController
|
||||||
|
prepend_before_action :find_page, only: [:show]
|
||||||
|
def index
|
||||||
|
@pages = Page.all_for_suppliers(locale: params[:locale])
|
||||||
|
render json: @pages, each_serializer: Suppliers::PageSerializer
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
render json: @page, serializer: Suppliers::PageSerializer
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def find_page
|
||||||
|
@page = Page.suppliers_page(params[:id], locale: params[:locale])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,6 +1,24 @@
|
|||||||
class Page
|
class Page
|
||||||
include Cmtool::Includes::Page
|
include Cmtool::Includes::Page
|
||||||
|
include ActiveModel::SerializerSupport
|
||||||
def self.layouts
|
def self.layouts
|
||||||
%w[theme1 theme1-home]
|
%w[theme1 theme1-home]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.suppliers_page(name, locale: :en)
|
||||||
|
find_by_name_and_locale("suppliers-#{name}", locale) || NullPage.new(name, locale: locale)
|
||||||
|
end
|
||||||
|
|
||||||
|
class NullPage < NullModel
|
||||||
|
attr_reader :name, :locale, :title, :body
|
||||||
|
def initialize(name, locale: 'en')
|
||||||
|
@name = name
|
||||||
|
@locale = locale
|
||||||
|
@body = ::I18n.t('page.not_found', locale: locale)
|
||||||
|
end
|
||||||
|
|
||||||
|
def title
|
||||||
|
@title ||= name.to_s.humanize.gsub(/\W/, ' ')
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
class Suppliers::PageSerializer < Qwaiter::Serializer
|
||||||
|
self.root = :page
|
||||||
|
attributes :name, :title, :body, :locale, :position
|
||||||
|
def name
|
||||||
|
object.name.to_s.sub /^suppliers-/, ''
|
||||||
|
end
|
||||||
|
|
||||||
|
def id
|
||||||
|
name
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
NullModel = Naught.build do
|
||||||
|
include ActiveModel::SerializerSupport
|
||||||
|
def created_at
|
||||||
|
@created_at ||= Time.current
|
||||||
|
end
|
||||||
|
alias_method :updated_at, :created_at
|
||||||
|
end
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
var supplier_object=<%= {id: current_supplier.id}.to_json.html_safe %>;
|
var supplier_object=<%= {id: current_supplier.id}.to_json.html_safe %>;
|
||||||
var employee_object=<%=raw Suppliers::EmployeeSerializer.new(current_employee, root: false).to_json %>;
|
var employee_object=<%=raw Suppliers::EmployeeSerializer.new(current_employee, root: false).to_json %>;
|
||||||
var data_host = '';
|
var data_host = '';
|
||||||
|
var $asset_path = '/assets/';
|
||||||
var event_host = '<%= Qwaiter.event_host %>';
|
var event_host = '<%= Qwaiter.event_host %>';
|
||||||
//var datepicker_options = {dateFormat: 'yy-mm-dd', firstDay: <%= current_supplier.week_starts_on_monday? ? 1 : 0 %>};
|
//var datepicker_options = {dateFormat: 'yy-mm-dd', firstDay: <%= current_supplier.week_starts_on_monday? ? 1 : 0 %>};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
|
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
|
||||||
en:
|
en:
|
||||||
hello: "Hello world"
|
hello: "Hello world"
|
||||||
|
page:
|
||||||
|
not_found: "404 The page you were looking for could not be found"
|
||||||
menu:
|
menu:
|
||||||
home: Home
|
home: Home
|
||||||
about: About
|
about: About
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
# Sample localization file for English. Add more files in this directory for other locales.
|
# Sample localization file for English. Add more files in this directory for other locales.
|
||||||
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
|
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
|
||||||
nl:
|
nl:
|
||||||
|
page:
|
||||||
|
not_found: "404 de pagina die u probeert te bereiken kan niet worden gevonden"
|
||||||
menu:
|
menu:
|
||||||
home: Home
|
home: Home
|
||||||
about: Over mozo.bar
|
about: Over mozo.bar
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
en:
|
en:
|
||||||
supplier:
|
supplier:
|
||||||
|
page:
|
||||||
|
cannot_compile: There is an error in the page that prevented it from being displayed.
|
||||||
confirm:
|
confirm:
|
||||||
cancel: "Cancel"
|
cancel: "Cancel"
|
||||||
confirm: "OK"
|
confirm: "OK"
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
nl:
|
nl:
|
||||||
supplier:
|
supplier:
|
||||||
|
page:
|
||||||
|
cannot_compile: There is an error in the page that prevented it from being displayed.
|
||||||
confirm:
|
confirm:
|
||||||
cancel: Sluit
|
cancel: Sluit
|
||||||
confirm: Ja
|
confirm: Ja
|
||||||
|
|||||||
@@ -165,6 +165,7 @@ Qwaiter::Application.routes.draw do
|
|||||||
post :mark_delivered
|
post :mark_delivered
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
resources :pages, only: [:index, :show], constraints: {id: /.*/}
|
||||||
root to: 'sections#index'
|
root to: 'sections#index'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
FactoryGirl.define do
|
||||||
|
factory :page do
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Page do
|
||||||
|
describe '.suppliers_page' do
|
||||||
|
it 'finds by symbol locale' do
|
||||||
|
page = create :page, name: "suppliers-about", locale: 'en', title: 'About'
|
||||||
|
Page.suppliers_page('about', locale: :en).should eq page
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'actually uses the locale argument' do
|
||||||
|
page = create :page, name: "suppliers-about", locale: 'nl', title: 'About'
|
||||||
|
Page.suppliers_page('about', locale: 'nl').should eq page
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns a NullPage when no page found' do
|
||||||
|
page = Page.suppliers_page('non-existent', locale: 'nl')
|
||||||
|
page.should be_a Page::NullPage
|
||||||
|
page.title.should == 'Non existent'
|
||||||
|
page.locale.should == 'nl'
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user