diff --git a/Gemfile b/Gemfile index c19dd107..928ed1d1 100644 --- a/Gemfile +++ b/Gemfile @@ -122,6 +122,7 @@ group :test do #gem 'capybara-webkit' #, '~>0.14.2' # version 1.1.0 does not yet compile in mavericks #gem 'selenium-webdriver', '~> 2.45.0.dev3' gem 'selenium-webdriver' + gem 'hashie' #gem 'poltergeist' #gem 'capybara-webkit' gem 'capybara-screenshot' diff --git a/Gemfile.lock b/Gemfile.lock index 82c9ff39..349294a5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -497,6 +497,7 @@ DEPENDENCIES foreman foundation-rails fuubar + hashie iso_country_codes jquery-rails jquery-ui-rails diff --git a/app/assets/javascripts/supplier/app/adapters/application.js.coffee b/app/assets/javascripts/supplier/app/adapters/application.js.coffee index 3e027bd4..b62f18b1 100644 --- a/app/assets/javascripts/supplier/app/adapters/application.js.coffee +++ b/app/assets/javascripts/supplier/app/adapters/application.js.coffee @@ -4,3 +4,17 @@ # "Accept": "application/json, text/javascript; q=0.01" App.ApplicationAdapter = DS.JSONAPIAdapter.extend namespace: 'supplier' + pathForType: (type)-> + type.underscore().pluralize() + createRecord: (store, type, snapshot)-> + data = {} + #var serializer = store.serializerFor(type.modelName); + serializer = Ember.get(snapshot.record, 'store').serializerFor('creation') + url = @buildURL(type.modelName, null, snapshot, 'createRecord') + + serializer.serializeIntoHash data, type, snapshot, includeId: true + + @ajax url, "POST", data: data + #debugger + #Ember.get(snapshot.record, 'store').serializerFor('creation').serialize(snapshot) + #3 diff --git a/app/assets/javascripts/supplier/app/controllers/index_controller.js.coffee b/app/assets/javascripts/supplier/app/controllers/index_controller.js.coffee index c0246e01..e4c4e345 100644 --- a/app/assets/javascripts/supplier/app/controllers/index_controller.js.coffee +++ b/app/assets/javascripts/supplier/app/controllers/index_controller.js.coffee @@ -2,29 +2,23 @@ App.IndexController = Ember.Controller.extend show_lists: true show_orders: true lists: (-> @store.peekAll('list')).property() - orders: (-> @store.peekAll('order')).property() + orders: Ember.computed -> @store.peekAll('order') sections: (-> @store.peekAll('section')).property() active_section: Ember.computed.alias 'globals.active_section' - active_lists: (-> + active_lists: Ember.computed 'lists.@each.state', 'active_section.id', -> + @get('orders') # trigger orders, otherwise observers are not initialized/triggered (active_orders) if section_id = @get('active_section.id') lists = @get('lists').filter (l)=>( l.get('section.id') == section_id && l.get('state') == 'active' ) else lists = @get('lists').filterBy('state', 'active') - lists.sortBy('created_at') # Not reversed, oldest on top, start with oldest order first :-) Customer happyness - ).property('lists.@each.state', 'active_section.id') + lists.sortBy('created_at') # Not reversed, oldest on top, start with oldest order first, work your way down :-) Customer happyness - active_orders: Ember.computed 'active_lists.[]', 'active_orders.@each.state', -> + active_orders: Ember.computed 'active_lists.[]', 'orders.@each.state', -> orders = Ember.A() @get('active_lists').forEach (list)-> list.get('orders').filterBy('needs_supplier_attention').forEach (order)-> orders.push order - return orders - #if @get('active_section.id') - # orders = @get('orders').filter (o)=>( o.get('section.id') == @get('active_section.id') && o.get('needs_supplier_attention') ) - #else - # orders = @get('orders').filter (o)->( o.get('needs_supplier_attention') ) - #orders.sortBy('created_at') # Not reversed, oldest on top, start with oldest order first :-) Customer happyness - #).property('orders.@each.state', 'active_section.id') + orders.sortBy('created_at') # Not reversed, oldest on top, start with oldest order first, work your way down :-) Customer happyness show_lists_table: Ember.computed 'show_lists', 'active_lists.[]', -> @get('show_lists') and @get('active_lists.length') diff --git a/app/assets/javascripts/supplier/app/models/employee-shift.js.coffee b/app/assets/javascripts/supplier/app/models/employee-shift.js.coffee index dde94f39..d76db434 100644 --- a/app/assets/javascripts/supplier/app/models/employee-shift.js.coffee +++ b/app/assets/javascripts/supplier/app/models/employee-shift.js.coffee @@ -2,8 +2,9 @@ attr = DS.attr App.EmployeeShift = DS.Model.extend start_from: attr('moment') end_on: attr('moment') - employee: DS.belongsTo 'employee' description: attr('string') + employee: DS.belongsTo 'employee', async: false + supplier: DS.belongsTo 'supplier', async: false calendar_event: (-> id: @id title: @get('title') @@ -11,7 +12,6 @@ App.EmployeeShift = DS.Model.extend end: @get('end_on') color: @get('employee.color') ).property('start_from', 'end_on', 'title') - supplier: DS.belongsTo('supplier') title: Ember.computed 'employee.name', 'description', -> if @get('description') diff --git a/app/assets/javascripts/supplier/app/models/list.js.coffee b/app/assets/javascripts/supplier/app/models/list.js.coffee index e82126bf..bda08e68 100644 --- a/app/assets/javascripts/supplier/app/models/list.js.coffee +++ b/app/assets/javascripts/supplier/app/models/list.js.coffee @@ -5,18 +5,17 @@ App.List = DS.Model.extend needs_payment: attr 'boolean' user_requests_closing: attr('boolean') # users: DS.hasMany('user', async: true) - users: DS.hasMany('user') is_paid: attr 'boolean' + price: attr 'number' #has_active_orders: attr 'boolean' - price: attr 'number' closed_at: DS.attr('date') + users: DS.hasMany('user', async: false) #table_number: attr 'number' - table: DS.belongsTo('table', inverse: 'active_list', async: true) + table: DS.belongsTo('table', inverse: 'active_list', async: false) # should be async, but synchroneously loading now fails with JSONAPI, this seems to work #users: DS.hasMany('user', inverse: 'active_list') - orders: DS.hasMany('order') - section: DS.belongsTo('section') - section_id: attr('string') + orders: DS.hasMany('order', async: false) + section: DS.belongsTo('section', async: false) # should be async, but synchroneously loading now fails with JSONAPI, this seems to work active: ( -> @get('state') is 'active' ).property('state') isClosed: -> @set('state', 'closed') diff --git a/app/assets/javascripts/supplier/app/models/order.js.coffee b/app/assets/javascripts/supplier/app/models/order.js.coffee index e32e4943..80ce79b0 100644 --- a/app/assets/javascripts/supplier/app/models/order.js.coffee +++ b/app/assets/javascripts/supplier/app/models/order.js.coffee @@ -11,7 +11,7 @@ App.Order = DS.Model.extend active: (-> @get('state') == 'active').property('state') delivered: (-> @get('state') == 'delivered').property('state') placed: (-> @get('state') == 'placed').property('state') - needs_supplier_attention: (-> (@get('state') == 'placed') || (@get('state') == 'active')).property('state') + needs_supplier_attention: (-> (@get('state') is 'placed') or (@get('state') is 'active')).property('state') isClosed: -> @set 'state', 'closed' diff --git a/app/assets/javascripts/supplier/app/models/product.js.coffee b/app/assets/javascripts/supplier/app/models/product.js.coffee index 5b6f3f32..d7c4a9d1 100644 --- a/app/assets/javascripts/supplier/app/models/product.js.coffee +++ b/app/assets/javascripts/supplier/app/models/product.js.coffee @@ -8,9 +8,9 @@ App.Product = DS.Model.extend Ember.Validations.Mixin, active: attr('boolean', defaultValue: true) position: attr('number', defaultValue: 0) image: attr() - product_category: DS.belongsTo('product_category') - product_orders: DS.hasMany('product_order') - product_variants: DS.hasMany('product_variant') + product_category: DS.belongsTo('product_category', async: false) + product_orders: DS.hasMany('product_order', async: false) + product_variants: DS.hasMany('product_variant', async: false) image_src: (-> image = @get('image') diff --git a/app/assets/javascripts/supplier/app/models/product_category.js.coffee b/app/assets/javascripts/supplier/app/models/product_category.js.coffee index c08f3246..fbf61157 100644 --- a/app/assets/javascripts/supplier/app/models/product_category.js.coffee +++ b/app/assets/javascripts/supplier/app/models/product_category.js.coffee @@ -1,8 +1,6 @@ attr = DS.attr App.ProductCategory = DS.Model.extend Ember.Validations.Mixin, name: attr('string') - products: DS.hasMany('product') - supplier: DS.belongsTo 'supplier' active_on_sunday: attr('boolean', defaultValue: true) active_on_monday: attr('boolean', defaultValue: true) active_on_tuesday: attr('boolean', defaultValue: true) @@ -15,6 +13,9 @@ App.ProductCategory = DS.Model.extend Ember.Validations.Mixin, end_on: attr('number') position: attr('number') + products: DS.hasMany('product', async: false) + supplier: DS.belongsTo 'supplier', async: false + sorted_products: (-> @get('products').sortBy('position') ).property('products.@each.position') availability_text: Ember.computed 'active_on_sunday', 'active_on_monday', 'active_on_tuesday', 'active_on_wednesday', 'active_on_thursday', 'active_on_friday', 'active_on_saturday', 'full_day', 'start_from', 'end_on', -> diff --git a/app/assets/javascripts/supplier/app/models/product_order.js.coffee b/app/assets/javascripts/supplier/app/models/product_order.js.coffee index ec0918ed..0459d9b6 100644 --- a/app/assets/javascripts/supplier/app/models/product_order.js.coffee +++ b/app/assets/javascripts/supplier/app/models/product_order.js.coffee @@ -5,7 +5,7 @@ App.ProductOrder = DS.Model.extend product_variant: attr('string') product_name: attr('string') product: DS.belongsTo('product', async: true) - order: DS.belongsTo('order') + order: DS.belongsTo('order', async: false) increment: -> @set('quantity', @get('quantity') + 1) total: (-> @get('quantity') * @get('price')).property('quantity', 'price') diff --git a/app/assets/javascripts/supplier/app/models/section-area.js.coffee b/app/assets/javascripts/supplier/app/models/section-area.js.coffee index a27ed082..368e405f 100644 --- a/app/assets/javascripts/supplier/app/models/section-area.js.coffee +++ b/app/assets/javascripts/supplier/app/models/section-area.js.coffee @@ -6,6 +6,6 @@ App.SectionArea = DS.Model.extend Ember.Validations.Mixin, position_x: attr 'number', defaultValue: 0 position_y: attr 'number', defaultValue: 0 rounded: attr 'boolean', defaultValue: false - section: DS.belongsTo('section') + section: DS.belongsTo('section', async: false) validations: title: {presence: true} diff --git a/app/assets/javascripts/supplier/app/models/section-element.js.coffee b/app/assets/javascripts/supplier/app/models/section-element.js.coffee index a1b112a7..ccf4a76f 100644 --- a/app/assets/javascripts/supplier/app/models/section-element.js.coffee +++ b/app/assets/javascripts/supplier/app/models/section-element.js.coffee @@ -3,4 +3,4 @@ App.SectionElement = DS.Model.extend App.SvgElementMixin, App.Rotation, position_x: attr 'number', defaultValue: 0 position_y: attr 'number', defaultValue: 0 rotation: attr 'number', defaultValue: 0 - section: DS.belongsTo('section') + section: DS.belongsTo('section', async: false) diff --git a/app/assets/javascripts/supplier/app/models/supplier.js.coffee b/app/assets/javascripts/supplier/app/models/supplier.js.coffee index bfb4aa3c..af33e958 100644 --- a/app/assets/javascripts/supplier/app/models/supplier.js.coffee +++ b/app/assets/javascripts/supplier/app/models/supplier.js.coffee @@ -15,9 +15,10 @@ App.Supplier = DS.Model.extend lat: attr 'number' lng: attr 'number' week_starts_on_monday: attr 'boolean' - product_categories: DS.hasMany 'product_category' orders_in_process_count: attr('number') orders_placed_count: attr('number') + + product_categories: DS.hasMany 'product_category', async: false employee_shifts: DS.hasMany('employee-shift') close: -> diff --git a/app/assets/javascripts/supplier/app/routes/application_route.js.coffee.erb b/app/assets/javascripts/supplier/app/routes/application.js.coffee.erb similarity index 98% rename from app/assets/javascripts/supplier/app/routes/application_route.js.coffee.erb rename to app/assets/javascripts/supplier/app/routes/application.js.coffee.erb index 177b63b4..eb65fc3b 100644 --- a/app/assets/javascripts/supplier/app/routes/application_route.js.coffee.erb +++ b/app/assets/javascripts/supplier/app/routes/application.js.coffee.erb @@ -131,11 +131,12 @@ App.ApplicationRoute = Ember.Route.extend @store.pushPayload(data.payload) if order_id = data.payload.data.id order = @store.peekRecord('order', order_id) - return if @get('globals.active_section.id') and order.get('section.id') isnt @get('globals.active_section.id') + return if @get('globals.active_section.id') and order.get('list.section.id') isnt @get('globals.active_section.id') @set 'globals.flash_message', order.get('display_with_table') try ion.sound.play('water_droplet') new_list: (data)-> - debugger + if data.payload + @store.pushPayload(data.payload) try ion.sound.play('water_droplet') list_changed_table: (data) -> @store.pushPayload('list', lists: [data.list]) list_closed: (data) -> list.isClosed() if list = @store.peekRecord('list', data.id) diff --git a/app/assets/javascripts/supplier/app/routes/employees_route.js.coffee b/app/assets/javascripts/supplier/app/routes/employees.js.coffee similarity index 100% rename from app/assets/javascripts/supplier/app/routes/employees_route.js.coffee rename to app/assets/javascripts/supplier/app/routes/employees.js.coffee diff --git a/app/assets/javascripts/supplier/app/routes/index_route.js.coffee b/app/assets/javascripts/supplier/app/routes/index.js.coffee similarity index 100% rename from app/assets/javascripts/supplier/app/routes/index_route.js.coffee rename to app/assets/javascripts/supplier/app/routes/index.js.coffee diff --git a/app/assets/javascripts/supplier/app/routes/lists_index_route.js.coffee b/app/assets/javascripts/supplier/app/routes/lists-index.js.coffee similarity index 100% rename from app/assets/javascripts/supplier/app/routes/lists_index_route.js.coffee rename to app/assets/javascripts/supplier/app/routes/lists-index.js.coffee diff --git a/app/assets/javascripts/supplier/app/routes/sections_route.js.coffee b/app/assets/javascripts/supplier/app/routes/sections_route.js.coffee index 9a0dd9d9..3af35b49 100644 --- a/app/assets/javascripts/supplier/app/routes/sections_route.js.coffee +++ b/app/assets/javascripts/supplier/app/routes/sections_route.js.coffee @@ -1,7 +1,4 @@ App.SectionsRoute = Ember.Route.extend - beforeModel: -> - @store.findAll 'section-element' - @store.findAll 'section-area' model: -> @store.peekAll 'section' # setupController: (controller, collection) -> diff --git a/app/assets/javascripts/supplier/app/store.js.coffee b/app/assets/javascripts/supplier/app/store.js.coffee index a77be262..1326e988 100644 --- a/app/assets/javascripts/supplier/app/store.js.coffee +++ b/app/assets/javascripts/supplier/app/store.js.coffee @@ -1,7 +1,8 @@ #App.ApplicationSerializer = DS.ActiveModelSerializer -App.ApplicationSerializer = DS.JSONAPISerializer.extend - keyForAttribute: (attr, method)-> attr +App.ApplicationSerializer = DS.JSONAPISerializer.extend {} +App.CreationSerializer = DS.ActiveModelSerializer.extend {} +# keyForAttribute: (attr, method)-> attr #App.ApplicationStore = DS.Store #adapter: DS.ActiveModelAdapter.extend #namespace: 'supplier' diff --git a/app/controllers/suppliers/employee_shifts_controller.rb b/app/controllers/suppliers/employee_shifts_controller.rb index b60d48a6..9a4e90bd 100644 --- a/app/controllers/suppliers/employee_shifts_controller.rb +++ b/app/controllers/suppliers/employee_shifts_controller.rb @@ -7,12 +7,12 @@ module Suppliers @employee_shifts.select! do |shift| current_supplier.employee_ids.include?(shift.employee.try(:id)) end - render json: JSONAPI::Serializer.serialize(@employee_shifts, serializer: Suppliers::EmployeeShiftSerializer, is_collection: true, include: %w[employee supplier]) + render json: JSONAPI::Serializer.serialize(@employee_shifts, serializer: Suppliers::EmployeeShiftSerializer, is_collection: true, include: %w[employee]) end def create @employee_shift.supplier = current_supplier @employee_shift.save - render json: JSONAPI::Serializer.serialize(@employee_shift, serializer: Suppliers::EmployeeShiftSerializer, include: %w[employee supplier]) + render json: JSONAPI::Serializer.serialize(@employee_shift, serializer: Suppliers::EmployeeShiftSerializer, include: %w[employee]) end def update @@ -31,6 +31,5 @@ module Suppliers def employee_shift_params params.require(:employee_shift).permit(:start_from, :end_on, :employee_id, :description) end - end end diff --git a/app/controllers/suppliers/lists_controller.rb b/app/controllers/suppliers/lists_controller.rb index e4ac6692..d3700e7f 100644 --- a/app/controllers/suppliers/lists_controller.rb +++ b/app/controllers/suppliers/lists_controller.rb @@ -23,13 +23,9 @@ module Suppliers render json: JSONAPI::Serializer.serialize(@lists, serializer: Suppliers::ListSerializer, is_collection: true, include: %w[ orders - orders.list orders.user orders.product_orders - orders.product_orders.product users - section - table ]) end diff --git a/app/controllers/suppliers/suppliers_controller.rb b/app/controllers/suppliers/suppliers_controller.rb index 5ed0e502..99e0d5da 100644 --- a/app/controllers/suppliers/suppliers_controller.rb +++ b/app/controllers/suppliers/suppliers_controller.rb @@ -6,6 +6,15 @@ module Suppliers def show current_supplier.sections.include_relations(:tables, :section_areas, :section_elements, product_categories: {products: :product_variants}) + #render json: JSONAPI::Serializer.serialize(current_supplier, serializer: Suppliers::SupplierSerializer, include: %w[ + #sections + #sections.tables + #sections.section_areas + #sections.section_elements + #product_categories + #product_categories.products + #product_categories.products.product_variants + #]) #.new(current_supplier).as_json render json: JSONAPI::Serializer.serialize(current_supplier, serializer: Suppliers::SupplierSerializer, include: %w[ sections sections.tables @@ -14,7 +23,7 @@ module Suppliers product_categories product_categories.products product_categories.products.product_variants - ]) #.new(current_supplier).as_json + ]) end def update diff --git a/app/controllers/users/lists_controller.rb b/app/controllers/users/lists_controller.rb index e0840dc8..5f3ada46 100644 --- a/app/controllers/users/lists_controller.rb +++ b/app/controllers/users/lists_controller.rb @@ -27,7 +27,7 @@ module Users def show @list ||= List.find(params[:id]) if params[:id] render json: {}, status: :not_found and return unless @list.present? && Array.wrap(@list.user_ids).include?(current_user.id) - render json: JSONAPI::Serializer.serialize(@list, serializer: Users::ListSerializer, include: %w[supplier users join_requests join_requests.list join_requests.user]) + render json: JSONAPI::Serializer.serialize(@list, serializer: Users::ListSerializer, include: %w[supplier users join_requests join_requests.user]) end # POST /user/list_needs_payment.json diff --git a/app/models/employee.rb b/app/models/employee.rb index 8bc1ede8..e1f27746 100644 --- a/app/models/employee.rb +++ b/app/models/employee.rb @@ -37,6 +37,10 @@ class Employee end end + def to_hash + attributes.merge(settings.as_json).merge("id" => id) + end + #validates :email, email: true has_and_belongs_to_many :suppliers, storing_keys: false has_many :orders diff --git a/app/models/list.rb b/app/models/list.rb index 83317e00..026487f7 100644 --- a/app/models/list.rb +++ b/app/models/list.rb @@ -320,11 +320,12 @@ class List table ]) # broadcast_supplier supplier.id, 'new_order', OrderSerializer.new(order) - broadcast_supplier supplier.id, 'new_list', supplier_orders_placed_count: orders_placed_count, payload: supplier_payload + broadcast_supplier supplier.id, 'new_list', supplier_orders_placed_count: orders_placed_count, payload: supplier_payload, list_id: self.id else # broadcast_users 'new_order', order: order.with_products_as_json, total_amount: price user_payload = JSONAPI::Serializer.serialize(order, serializer: Users::OrderSerializer, include: %w[list user product_orders product_orders.order]) supplier_payload = JSONAPI::Serializer.serialize(order, serializer: Suppliers::OrderSerializer, include: %w[ + list user product_orders ]) diff --git a/app/serializers/suppliers/employee_shift_serializer.rb b/app/serializers/suppliers/employee_shift_serializer.rb index 5f0d241d..c1892b9b 100644 --- a/app/serializers/suppliers/employee_shift_serializer.rb +++ b/app/serializers/suppliers/employee_shift_serializer.rb @@ -1,5 +1,6 @@ class Suppliers::EmployeeShiftSerializer include Qwaiter::SupplierBaseSerializer - attributes :start_from, :end_on, :employee_id, :supplier_id + attributes :start_from, :end_on has_one :supplier, serializer: Suppliers::SupplierSerializer + has_one :employee, serializer: Suppliers::EmployeeSerializer end diff --git a/app/serializers/suppliers/product_category_serializer.rb b/app/serializers/suppliers/product_category_serializer.rb index 1ad921c6..7cb48d8f 100644 --- a/app/serializers/suppliers/product_category_serializer.rb +++ b/app/serializers/suppliers/product_category_serializer.rb @@ -4,4 +4,5 @@ class Suppliers::ProductCategorySerializer :active_on_thursday, :active_on_friday, :active_on_saturday, :full_day, :start_from, :end_on, :position has_many :products, serializer: Suppliers::ProductSerializer + has_one :supplier, serializer: Suppliers::SupplierSerializer end diff --git a/app/serializers/suppliers/product_serializer.rb b/app/serializers/suppliers/product_serializer.rb index e42d97d3..df9f766e 100644 --- a/app/serializers/suppliers/product_serializer.rb +++ b/app/serializers/suppliers/product_serializer.rb @@ -10,5 +10,5 @@ class Suppliers::ProductSerializer end has_many :product_variants, serializer: Suppliers::ProductVariantSerializer - has_one :product_category, serializer: Suppliers::ProductSerializer + has_one :product_category, serializer: Suppliers::ProductCategorySerializer end diff --git a/app/serializers/suppliers/product_variant_serializer.rb b/app/serializers/suppliers/product_variant_serializer.rb index b6255eba..aa0ba964 100644 --- a/app/serializers/suppliers/product_variant_serializer.rb +++ b/app/serializers/suppliers/product_variant_serializer.rb @@ -1,4 +1,5 @@ class Suppliers::ProductVariantSerializer include Qwaiter::SupplierBaseSerializer attributes :name + has_one :product, serializer: Suppliers::ProductSerializer end diff --git a/app/serializers/suppliers/section_serializer.rb b/app/serializers/suppliers/section_serializer.rb index 24ffbaf9..b05eb744 100644 --- a/app/serializers/suppliers/section_serializer.rb +++ b/app/serializers/suppliers/section_serializer.rb @@ -1,7 +1,8 @@ class Suppliers::SectionSerializer include Qwaiter::SupplierBaseSerializer - attributes :title, :path, :width, :height + attributes :title, :width, :height #, :path has_many :tables, serializer: Suppliers::TableSerializer has_many :section_areas, serializer: Suppliers::SectionAreaSerializer has_many :section_elements, serializer: Suppliers::SectionElementSerializer + has_one :supplier, serializer: Suppliers::SupplierSerializer end diff --git a/app/services/join_request.rb b/app/services/join_request.rb index 9e0fe97c..9cb8aa2a 100644 --- a/app/services/join_request.rb +++ b/app/services/join_request.rb @@ -5,6 +5,10 @@ class JoinRequest end alias _id id + def list_id + list.try(:id) + end + def initialize(user: nil, list: nil, created_at: Time.now, updated_at: Time.now) @user, @list, @created_at, @updated_at = [user, list, created_at, updated_at] end diff --git a/app/views/suppliers/application/_head.html.erb b/app/views/suppliers/application/_head.html.erb index 12f6ec89..146ca377 100644 --- a/app/views/suppliers/application/_head.html.erb +++ b/app/views/suppliers/application/_head.html.erb @@ -2,7 +2,7 @@ //var $locale = '<%= I18n.locale %>'; //var supplier_id = '<%= current_supplier.id %>'; var supplier_object=<%= {id: current_supplier.id}.to_json.html_safe %>; -var employee_object=<%=raw current_employee.attributes.merge(id: current_employee.id).to_json %>; +var employee_object=<%=raw current_employee.to_json %>; var data_host = ''; var $asset_path = '/assets/'; var event_host = '<%= Qwaiter.event_host %>'; diff --git a/app/views/user/index.html.slim b/app/views/user/index.html.slim index 12c58798..474fd9f9 100644 --- a/app/views/user/index.html.slim +++ b/app/views/user/index.html.slim @@ -1,4 +1,4 @@ -.home-panel +/.home-panel .home-header = image_tag 'logo.png' .home-center a href="#" onClick="QMobile.scanQr()" = image_tag 'user/scan-logo.png' @@ -6,7 +6,7 @@ .home-footer-content = link_to content_tag(:span, 'P'), user_list_products_path, class: ['home-link', 'home-menu-link'] = link_to content_tag(:span, 'L'), user_active_list_path, class: ['home-link', 'home-list-link'] -- content_for :footer do +/- content_for :footer do javascript: $(function(){ Quser.home_loader(); diff --git a/config/routes.rb b/config/routes.rb index 1bf4b6cf..dc6cc751 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -54,7 +54,7 @@ Qwaiter::Application.routes.draw do # USER #default_url_options format: 'html' #get '/user/index' => 'user#index', as: :user_root - #get '/user' => 'user#index' + get '/user' => 'user#index' #get '/user/active_list(.:format)' => 'user#active_list', as: :user_active_list #get '/user/list_info' => 'user#list_info', as: :user_list_info, via: [:get, :options] #post '/user/needs_help' => 'user#needs_help', as: :user_needs_help diff --git a/lib/qwaiter/supplier_base_serializer.rb b/lib/qwaiter/supplier_base_serializer.rb index c7a64a90..6ec584b2 100644 --- a/lib/qwaiter/supplier_base_serializer.rb +++ b/lib/qwaiter/supplier_base_serializer.rb @@ -12,18 +12,17 @@ module Qwaiter::SupplierBaseSerializer end def format_name(attribute_name) - #attribute_name.to_s.dasherize - attribute_name.to_s + attribute_name.to_s.dasherize end def unformat_name(attribute_name) - #attribute_name.to_s.underscore - attribute_name.to_s + attribute_name.to_s.underscore end #alias_method :default_relationship_related_link, :relationship_related_link def relationship_related_link(attribute_name) - super if related_link_for_attributes.include?(attribute_name) + #super if related_link_for_attributes.include?(attribute_name) + super end def relationship_self_link(attribute_name) diff --git a/spec/requests/suppliers/supplier_payload_spec.rb b/spec/requests/suppliers/supplier_payload_spec.rb new file mode 100644 index 00000000..0801a9fe --- /dev/null +++ b/spec/requests/suppliers/supplier_payload_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe "asldfj", type: :request do + let(:supplier){ create :supplier } + let(:employee){ create :employee } + before do + supplier.add_employee(employee) + login_as employee, scope: :employee + end + it "works" do + supplier = create :supplier + get "/supplier/suppliers/#{supplier.id}.json" + api_response.data.relationships.product_categorie + included_section = api_response.included.find{|ih| ih['type'] == 'sections'} + included_section['relationships']['tables']['data'].should eq [] + included_section['relationships']['section-areas']['data'].should eq [] + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c0e16e7c..f9afb8dd 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -41,6 +41,25 @@ module FactoryAttributesFor super(obj, options).merge(build(obj).attributes.select{|k,v| k =~ /_id$/}).symbolize_keys end end + +module RequestSpecHelpers + module MethodsForHash + def method_missing(m, *args) + r = self[m.to_s.dasherize] + if r.is_a?(Hash) + r.extend MethodsForHash + end + r + end + end + def api_response + result = JSON.parse(response.body) + result.extend MethodsForHash + #result.extend Hashie::Extensions::DeepFind + result + end +end + module SpecSelectorHelpers def top_navigation '.navbar-fixed-top' @@ -61,6 +80,12 @@ module SpecSelectorHelpers end +class Ability + include CanCan::Ability + def initialize(record) + can :manage, :All + end +end class TestCounter < InMemoryQCounter #def incr(*args) #result = super @@ -103,6 +128,8 @@ RSpec.configure do |config| config.include SpecRouteHelpers, type: :feature config.include SpecEmberHelpers, type: :feature config.include SerializersTestHelpers, type: :serializer + config.include Warden::Test::Helpers, type: :request + config.include RequestSpecHelpers, type: :request #config.use_transactional_fixtures = true config.infer_base_class_for_anonymous_controllers = true config.filter_run_excluding broken: true @@ -165,10 +192,17 @@ RSpec.configure do |config| Qwaiter::Counter.connection.flush end - config.before :each, type: :feature do - #Supplier.any_instance.stub send_confirmation_instructions: true - Capybara.session_name = :default - end + config.before :each, type: :feature do + #Supplier.any_instance.stub send_confirmation_instructions: true + Capybara.session_name = :default + end + + config.around :each, type: :request do |example| + Warden.test_mode! + example.run + Warden.test_reset! + end + config.after :suite do =begin