Base progress
This commit is contained in:
@@ -6,6 +6,7 @@ App.ApplicationAdapter = DS.JSONAPIAdapter.extend
|
||||
namespace: 'supplier'
|
||||
pathForType: (type)->
|
||||
type.underscore().pluralize()
|
||||
# Code for createRecord and updateRecord taken from ember data v2.0.0 restadapter
|
||||
createRecord: (store, type, snapshot)->
|
||||
data = {}
|
||||
#var serializer = store.serializerFor(type.modelName);
|
||||
@@ -15,6 +16,12 @@ App.ApplicationAdapter = DS.JSONAPIAdapter.extend
|
||||
serializer.serializeIntoHash data, type, snapshot, includeId: true
|
||||
|
||||
@ajax url, "POST", data: data
|
||||
#debugger
|
||||
#Ember.get(snapshot.record, 'store').serializerFor('creation').serialize(snapshot)
|
||||
#3
|
||||
|
||||
updateRecord: (store, type, snapshot)->
|
||||
data = {}
|
||||
#var serializer = store.serializerFor(type.modelName);
|
||||
serializer = Ember.get(snapshot.record, 'store').serializerFor('creation')
|
||||
id = snapshot.id
|
||||
url = @buildURL(type.modelName, id, snapshot, 'updateRecord')
|
||||
serializer.serializeIntoHash data, type, snapshot, includeId: true
|
||||
@ajax url, "PUT", data: data
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
App.ScheduleView = Ember.Component.extend
|
||||
event_changed: (event)->
|
||||
@get('globals.current_employee').store.findRecord('employee-shift', event.id).then (employee_shift)->
|
||||
if employee_shift = @get('globals.current_employee').store.peekRecord('employee-shift', event.id)
|
||||
return unless event.start and event.end
|
||||
employee_shift.set 'start_from', event.start
|
||||
employee_shift.set 'end_on', event.end
|
||||
employee_shift.save()
|
||||
@@ -13,7 +14,9 @@ App.ScheduleView = Ember.Component.extend
|
||||
save: -> callbacks.save.call(@, employee_shift) if callbacks.save
|
||||
destroy_callback: -> callbacks.destroy.call(@, employee_shift) if callbacks.destroy
|
||||
classNames: ['schedule-view']
|
||||
didInsertElement: ->
|
||||
|
||||
didRender: -> @drawCalendar()
|
||||
drawCalendar: ->
|
||||
placeholder = @$('#schedule-placeholder')
|
||||
events = @get('globals.current_supplier.employee_shifts').filter((employee_shift) -> employee_shift.get('employee.active') ).map( (employee_shift)->employee_shift.get('calendar_event') )
|
||||
editable = !!@get('globals.current_employee.manager')
|
||||
@@ -45,7 +48,7 @@ App.ScheduleView = Ember.Component.extend
|
||||
destroy: (shift)->
|
||||
placeholder.fullCalendar('removeEvents', [event.id])
|
||||
timeFormat: 'H(:mm)'
|
||||
axisFormat: 'H:mm'
|
||||
slotLabelFormat: 'H:mm'
|
||||
lang: moment.locale()
|
||||
if editable
|
||||
fullCalendarOptions.select = (start, end, jsEvent, view) =>
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
td.actions
|
||||
if (can "manage" "tables")
|
||||
a.table-edit{ action 'editTable' table }: span
|
||||
a.table-destroy{ action 'destroyTable' table }: span
|
||||
unless table.list
|
||||
a.table-destroy{ action 'destroyTable' table }: span
|
||||
.form-actions
|
||||
if (can "manage" "tables")
|
||||
a.form-action-new.new-table-button{action "newTable"}= t 'table.new_button'
|
||||
|
||||
@@ -58,16 +58,20 @@ private
|
||||
I18n.locale = params[:locale].presence.try(:to_sym) || Rails.configuration.i18n.default_locale
|
||||
end
|
||||
|
||||
#def _render_with_renderer_json(resource, options)
|
||||
#serializer = build_json_serializer(resource, options)
|
||||
|
||||
#binding.pry
|
||||
#if serializer
|
||||
#super(serializer, options)
|
||||
#else
|
||||
#super
|
||||
#end
|
||||
#end
|
||||
def _render_with_renderer_json(resource, options)
|
||||
return super if resource.is_a?(Hash)
|
||||
options[:serializer] ||= begin
|
||||
if resource.is_a?(SimplyStored::Couch)
|
||||
#infer based on controller path replacing actual controller part with resouce part /lists/:id/table
|
||||
"#{self.class.name.deconstantize}::#{resource.class.name.demodulize}Serializer".constantize
|
||||
else
|
||||
# infer based on controller path
|
||||
"#{controller_path.classify}Serializer".constantize
|
||||
end
|
||||
end
|
||||
options[:is_collection] = params[:id].blank? unless options.has_key?(:is_collection)
|
||||
JSONAPI::Serializer.serialize(resource, options).to_json
|
||||
end
|
||||
|
||||
def layout_by_resource(*args)
|
||||
#if devise_controller?
|
||||
|
||||
@@ -5,25 +5,27 @@ module Suppliers
|
||||
@employee_shifts.include_relations(:employee, :supplier)
|
||||
# Only select shifts from currently linked and employees
|
||||
@employee_shifts.select! do |shift|
|
||||
current_supplier.employee_ids.include?(shift.employee.try(:id))
|
||||
return false unless current_supplier.employee_ids.include?(shift.employee.try(:id))
|
||||
shift.employee.enrich_with_settings current_supplier.settings_for(shift.employee)
|
||||
true
|
||||
end
|
||||
render json: JSONAPI::Serializer.serialize(@employee_shifts, serializer: Suppliers::EmployeeShiftSerializer, is_collection: true, include: %w[employee])
|
||||
render json: @employee_shifts, 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])
|
||||
render json: @employee_shift, include: %w[employee]
|
||||
end
|
||||
|
||||
def update
|
||||
@employee_shift.update employee_shift_params
|
||||
render json: JSONAPI::Serializer.serialize(@employee_shift, serializer: Suppliers::EmployeeShiftSerializer)
|
||||
render json: @employee_shift
|
||||
end
|
||||
|
||||
def destroy
|
||||
head :forbidden and return unless @employee_shift.supplier_id == current_supplier.id
|
||||
@employee_shift.destroy
|
||||
head :ok
|
||||
head :no_content
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -8,13 +8,13 @@ module Suppliers
|
||||
# GET /employees.json
|
||||
def index
|
||||
@employees = current_supplier.employees
|
||||
render json: JSONAPI::Serializer.serialize(@employees, serializer: Suppliers::EmployeeSerializer, is_collection: true)
|
||||
render json: @employees
|
||||
end
|
||||
|
||||
# GET /employees/1
|
||||
# GET /employees/1.json
|
||||
def show
|
||||
render json: JSONAPI::Serializer.serialize(@employee, serializer: Suppliers::EmployeeSerializer)
|
||||
render json: @employee
|
||||
end
|
||||
|
||||
# POST /employees
|
||||
@@ -37,7 +37,7 @@ module Suppliers
|
||||
end
|
||||
|
||||
if valid
|
||||
render json: @employee, serializer: Suppliers::EmployeeSerializer, status: :created
|
||||
render json: @employee
|
||||
else
|
||||
render json: {errors: @employee.errors}, status: :unprocessable_entity
|
||||
end
|
||||
@@ -47,12 +47,10 @@ module Suppliers
|
||||
# PUT /employees/1.json
|
||||
def update
|
||||
#current_supplier.settings_for(@employee).update!(employee_params)
|
||||
respond_to do |format|
|
||||
if @employee.update_attributes(employee_params)
|
||||
format.json { head :no_content }
|
||||
else
|
||||
format.json { render json: {errors: @employee.errors}, status: :unprocessable_entity }
|
||||
end
|
||||
if @employee.update_attributes(employee_params)
|
||||
render json: @employee
|
||||
else
|
||||
render json: {errors: @employee.errors}, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
@@ -61,10 +59,7 @@ module Suppliers
|
||||
def destroy
|
||||
head :forbidden and return if @employee == current_employee # do not remove self at the moment
|
||||
current_supplier.remove_employee @employee
|
||||
|
||||
respond_to do |format|
|
||||
format.json { head :no_content }
|
||||
end
|
||||
head :no_content
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -21,12 +21,12 @@ module Suppliers
|
||||
end
|
||||
@lists.include_relation(:table, :users, orders: {user: nil, product_orders: :product})
|
||||
|
||||
render json: JSONAPI::Serializer.serialize(@lists, serializer: Suppliers::ListSerializer, is_collection: true, include: %w[
|
||||
render json: @lists, include: %w[
|
||||
orders
|
||||
orders.user
|
||||
orders.product_orders
|
||||
users
|
||||
])
|
||||
]
|
||||
end
|
||||
|
||||
|
||||
@@ -52,14 +52,14 @@ module Suppliers
|
||||
@lists = List.for_supplier_created_at current_supplier, @start_time..@end_time
|
||||
@lists.include_relation(:table) # for number
|
||||
|
||||
render json: JSONAPI::Serializer.serialize(@lists, serializer: Suppliers::ListSerializer, is_collection: true, include: %w[table])
|
||||
render json: @lists, include: %w[table]
|
||||
end
|
||||
|
||||
# GET /lists/1
|
||||
# GET /lists/1.json
|
||||
def show
|
||||
@list = List.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
render json: JSONAPI::Serializer.serialize(@list, serializer: Suppliers::ListSerializer)
|
||||
render json: @list
|
||||
end
|
||||
|
||||
# GET /lists/1/extra_info
|
||||
@@ -115,26 +115,26 @@ module Suppliers
|
||||
def destroy
|
||||
@list = List.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
@list.destroy
|
||||
head :ok
|
||||
head :no_content
|
||||
end
|
||||
# POST /supplier/lists/1/close
|
||||
def close
|
||||
@list = List.find_by_supplier_id_and_id(current_supplier.id, params[:id])
|
||||
@list.close!
|
||||
head :ok
|
||||
head :no_content
|
||||
end
|
||||
|
||||
# POST /supplier/lists/1/mark_helped
|
||||
def mark_helped
|
||||
@list = List.find_by_supplier_id_and_id(current_supplier.id, params[:id])
|
||||
@list.mark_helped!
|
||||
head :ok
|
||||
head :no_content
|
||||
end
|
||||
|
||||
def remove_needs_payment
|
||||
@list = List.find_by_supplier_id_and_id(current_supplier.id, params[:id])
|
||||
@list.remove_needs_payment!
|
||||
head :ok
|
||||
head :no_content
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -8,11 +8,7 @@ module Suppliers
|
||||
else
|
||||
@orders = Order.for_supplier(current_supplier, page: params[:page], per_page: params['per_page'] || 25)
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.json { render json: @orders }
|
||||
end
|
||||
render json: @orders
|
||||
end
|
||||
|
||||
def cancel
|
||||
@@ -23,22 +19,21 @@ module Suppliers
|
||||
|
||||
def show
|
||||
@order = current_supplier.find_order(params[:id])
|
||||
respond_to do |format|
|
||||
format.json { render json: @order }
|
||||
end
|
||||
render json: @order
|
||||
end
|
||||
|
||||
# POST /orders/1/mark_in_process
|
||||
def mark_in_process
|
||||
@order = Order.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
@order.is_being_processed!
|
||||
head :ok
|
||||
head :no_content
|
||||
end
|
||||
|
||||
# POST /orders/1/is_delivered
|
||||
def mark_delivered
|
||||
@order = Order.find_by_supplier_id_and_id(current_supplier.id, params[:id])
|
||||
@order.is_delivered!
|
||||
render nothing: true
|
||||
head :no_content
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -3,11 +3,11 @@ module Suppliers
|
||||
prepend_before_action :find_page, only: [:show]
|
||||
def index
|
||||
@pages = Page.all_for_suppliers(locale: params[:locale])
|
||||
render json: JSONAPI::Serializer.serialize(@pages, serializer: Suppliers::PageSerializer, is_collection: true)
|
||||
render json: @pages
|
||||
end
|
||||
|
||||
def show
|
||||
render json: JSONAPI::Serializer.serialize(@page, serializer: Suppliers::PageSerializer)
|
||||
render json: @page
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -106,11 +106,7 @@ module Suppliers
|
||||
def destroy
|
||||
@product_category = ProductCategory.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
@product_category.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to suppliers_product_categories_url, notice: t('action.destroy.successfull', model: ProductCategory.model_name.human) }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
head :no_content
|
||||
end
|
||||
|
||||
# POST /supplier/product_categories/sort
|
||||
|
||||
@@ -54,7 +54,7 @@ module Suppliers
|
||||
#@product_variant = ProductVariant.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
@product_variant = ProductVariant.find(params[:id])
|
||||
@product_variant.destroy
|
||||
render json: {}
|
||||
head :no_content
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -81,11 +81,7 @@ module Suppliers
|
||||
def destroy
|
||||
#@product = Product.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
@product.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to suppliers_products_url, notice: t('action.destroy.successfull', model: Product.model_name.human) }
|
||||
format.json { head :ok }
|
||||
end
|
||||
head :no_content
|
||||
end
|
||||
|
||||
def preview_products
|
||||
|
||||
@@ -2,13 +2,13 @@ module Suppliers
|
||||
class SectionAreasController < Suppliers::ApplicationController
|
||||
def index
|
||||
@section_areas = SectionArea.for_supplier(current_supplier)
|
||||
render json: JSONAPI::Serializer.serialize(@section_areas, serializer: Suppliers::SectionAreaSerializer, is_collection: true)
|
||||
render json: @section_areas
|
||||
end
|
||||
|
||||
def create
|
||||
@section_area.supplier = current_supplier
|
||||
if @section_area.save
|
||||
render json: JSONAPI::Serializer.serialize(@section_area, serializer: Suppliers::SectionAreaSerializer)
|
||||
render json: @section_area
|
||||
else
|
||||
render json: {errors: @section.errors}, status: :unprocessable_entity
|
||||
end
|
||||
@@ -16,7 +16,7 @@ module Suppliers
|
||||
|
||||
def update
|
||||
if @section_area.update_attributes section_area_params
|
||||
render json: JSONAPI::Serializer.serialize(@section_area, serializer: Suppliers::SectionAreaSerializer)
|
||||
render json: @section_area
|
||||
else
|
||||
render json: {errors: @section.errors}, status: :unprocessable_entity
|
||||
end
|
||||
@@ -24,7 +24,7 @@ module Suppliers
|
||||
|
||||
def destroy
|
||||
@section_area.destroy
|
||||
head :ok
|
||||
head :no_content
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -2,13 +2,13 @@ module Suppliers
|
||||
class SectionElementsController < Suppliers::ApplicationController
|
||||
def index
|
||||
@section_elements = SectionElement.for_supplier(current_supplier)
|
||||
render json: JSONAPI::Serializer.serialize(@section_elements, serializer: Suppliers::SectionElementSerializer, is_collection: true)
|
||||
render json: @section_elements
|
||||
end
|
||||
|
||||
def create
|
||||
@section_element.supplier = current_supplier
|
||||
if @section_element.save
|
||||
render json: JSONAPI::Serializer.serialize(@section_element, serializer: Suppliers::SectionElementSerializer)
|
||||
render json: @section_element
|
||||
else
|
||||
render json: {errors: @section.errors}, status: :unprocessable_entity
|
||||
end
|
||||
@@ -16,15 +16,15 @@ module Suppliers
|
||||
|
||||
def update
|
||||
if @section_element.update_attributes section_element_params
|
||||
render json: JSONAPI::Serializer.serialize(@section_element, serializer: Suppliers::SectionElementSerializer)
|
||||
render json: @section_element
|
||||
else
|
||||
render json: {errors: @section.errors}, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@section_element.destroy()
|
||||
head :ok
|
||||
@section_element.destroy
|
||||
head :no_content
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -17,7 +17,7 @@ module Suppliers
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
render json: JSONAPI::Serializer.serialize(@sections, serializer: Suppliers::ExtendedSectionSerializer, is_collection: true)
|
||||
render json: @sections
|
||||
end
|
||||
|
||||
# GET /sections/1
|
||||
@@ -25,11 +25,7 @@ module Suppliers
|
||||
def show
|
||||
@section = Section.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
@tables = @section.tables_with_active_list_id
|
||||
|
||||
respond_to do |format|
|
||||
format.html { render action: 'tables_view' }# show.html.erb
|
||||
format.json { render json: @section }
|
||||
end
|
||||
render json: @section
|
||||
end
|
||||
|
||||
# GET /sections/new
|
||||
@@ -37,11 +33,7 @@ module Suppliers
|
||||
def new
|
||||
@section = Section.new
|
||||
@section.supplier = current_supplier
|
||||
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
format.json { render json: @section }
|
||||
end
|
||||
render json: @section
|
||||
end
|
||||
|
||||
# GET /sections/1/edit
|
||||
@@ -56,7 +48,7 @@ module Suppliers
|
||||
@section.supplier = current_supplier
|
||||
|
||||
if @section.save
|
||||
render json: @section, serializer: Suppliers::SectionSerializer, status: :created
|
||||
render json: @section
|
||||
else
|
||||
render json: {errors: @section.errors}, status: :unprocessable_entity
|
||||
end
|
||||
@@ -68,7 +60,7 @@ module Suppliers
|
||||
@section = Section.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
|
||||
if @section.update_attributes(section_params)
|
||||
head :ok
|
||||
render json: @section
|
||||
else
|
||||
render json: {errors: @section.errors}, status: :unprocessable_entity
|
||||
end
|
||||
@@ -80,7 +72,7 @@ module Suppliers
|
||||
@section = Section.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
@section.destroy
|
||||
|
||||
head :ok
|
||||
head :no_content
|
||||
end
|
||||
|
||||
# GET /sections/1/manage_tables
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
module Suppliers
|
||||
class SuppliersController < Suppliers::ApplicationController
|
||||
def index
|
||||
render json: {}
|
||||
|
||||
end
|
||||
|
||||
@@ -15,7 +16,7 @@ module Suppliers
|
||||
#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[
|
||||
render json: current_supplier, include: %w[
|
||||
sections
|
||||
sections.tables
|
||||
sections.section_areas
|
||||
@@ -23,13 +24,13 @@ module Suppliers
|
||||
product_categories
|
||||
product_categories.products
|
||||
product_categories.products.product_variants
|
||||
])
|
||||
]
|
||||
end
|
||||
|
||||
def update
|
||||
@supplier = current_supplier
|
||||
current_supplier.update_attributes(supplier_params)
|
||||
render json: JSONAPI::Serializer.serialize( current_supplier, serializer: Suppliers::SupplierSerializer)
|
||||
render json: current_supplier
|
||||
end
|
||||
|
||||
def switch_to
|
||||
|
||||
@@ -2,7 +2,7 @@ module Suppliers
|
||||
class SvgElementsController < Suppliers::ApplicationController
|
||||
def index
|
||||
@svg_elements = SvgElement.active
|
||||
render json: JSONAPI::Serializer.serialize(@svg_elements, serializer: Suppliers::SvgElementSerializer)
|
||||
render json: @svg_elements
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -62,7 +62,7 @@ module Suppliers
|
||||
@table= Table.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
@table.destroy
|
||||
|
||||
head :ok
|
||||
head :no_content
|
||||
end
|
||||
|
||||
def qr_codes
|
||||
|
||||
@@ -8,12 +8,13 @@ module Users
|
||||
#lists.reject!{|l| l.id == params[:exclude_list]} if params[:exclude_list].present?
|
||||
#lists.reject!{|l| l.id == current_user.active_list_id } if current_user && current_user.active_list_id.present? # see spec Loading lists and switching to the order products view works, lists loading may unlink active list orders
|
||||
lists.include_relation(:users, :supplier)
|
||||
render json: JSONAPI::Serializer.serialize(lists, serializer: Users::ListSerializer, include: %w[supplier users], is_collection: true, meta: {total_pages: lists.total_pages, page: lists.current_page}) #, root: :lists
|
||||
render json: lists, include: %w[supplier users], meta: {total_pages: lists.total_pages, page: lists.current_page} #, root: :lists
|
||||
end
|
||||
|
||||
#EMBER
|
||||
def current
|
||||
@list = current_user.active_list
|
||||
params[:id] = @list.id # serializer determines collection or not based on the presence of this
|
||||
show
|
||||
end
|
||||
|
||||
@@ -21,13 +22,13 @@ module Users
|
||||
list = List.find(params[:id])
|
||||
render json: {}, status: :not_found and return unless list.present?
|
||||
@table = list.table
|
||||
render json: JSONAPI::Serializer.serialize(@table, serializer: Users::TableSerializer)
|
||||
render json: @table
|
||||
end
|
||||
|
||||
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.user])
|
||||
render json: @list, include: %w[supplier users join_requests join_requests.user]
|
||||
end
|
||||
|
||||
# POST /user/list_needs_payment.json
|
||||
@@ -35,7 +36,7 @@ module Users
|
||||
@list = active_list
|
||||
render json: json_alert('messages.no_active_list', list_active: false) and return unless @list.try(:id).to_s == params[:id]
|
||||
@list.needs_payment!
|
||||
render json: JSONAPI::Serializer.serialize(@list, serializer: Users::ListSerializer)
|
||||
render json: @list
|
||||
end
|
||||
|
||||
# POST /user/lists/:id/move_table.json?table_id=....
|
||||
@@ -80,7 +81,7 @@ module Users
|
||||
def reject_join_request
|
||||
render js: '' and return unless params[:user_id].present?
|
||||
active_list && active_list.reject_join_request_for_user!(params[:user_id])
|
||||
head :ok
|
||||
head :no_content
|
||||
end
|
||||
|
||||
# POST /user/approve_join_request?user_id=1
|
||||
@@ -88,7 +89,7 @@ module Users
|
||||
render js: '' and return unless params[:user_id].present?
|
||||
@user = User.find(params[:user_id])
|
||||
active_list && active_list.approve_join_request_for_user!(@user)
|
||||
head :ok
|
||||
head :no_content
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -8,7 +8,7 @@ module Users
|
||||
@list = List.find(params[:list_id])
|
||||
render json: {}, status: :not_found and return unless @list.present? && Array.wrap(@list.user_ids).include?(current_user.id)
|
||||
orders = @list.orders.include_relation(:product_orders)
|
||||
render json: JSONAPI::Serializer.serialize(orders, serializer: Users::OrderSerializer, include: %w[list user product_orders product_orders.order], is_collection: true)
|
||||
render json: orders, include: %w[list user product_orders product_orders.order]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -2,14 +2,10 @@ module Users
|
||||
class ProductCategoriesController < Users::ApplicationController
|
||||
#EMBER
|
||||
def index
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: {} and return unless params[:table_id].present?
|
||||
table = Table.find(params[:table_id])
|
||||
product_categories = table.supplier.product_categories.include_relation('products') # not yet implemented for many to many
|
||||
render json: product_categories #, serializer: ProductCategorySerializer
|
||||
end
|
||||
end
|
||||
render json: {} and return unless params[:table_id].present?
|
||||
table = Table.find(params[:table_id])
|
||||
product_categories = table.supplier.product_categories.include_relation('products') # not yet implemented for many to many
|
||||
render json: product_categories #, serializer: ProductCategorySerializer
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,13 +10,11 @@ module Users
|
||||
table = Table.find(params[:id])
|
||||
supplier = table.supplier
|
||||
supplier.product_categories.include_relations(products: :product_variants)
|
||||
render json: JSONAPI::Serializer.serialize(supplier, serializer: Users::SupplierSerializer, include: %w[
|
||||
render json: supplier, include: %w[
|
||||
product_categories
|
||||
product_categories.products
|
||||
product_categories.supplier
|
||||
product_categories.products.product_variants
|
||||
product_categories.products.product_variants.product
|
||||
])
|
||||
]
|
||||
end
|
||||
|
||||
# POST /tables/:id/needs_help.json
|
||||
@@ -25,7 +23,7 @@ module Users
|
||||
render json: json_alert('messages.no_active_list', list_active: false) and return unless active_list.present?
|
||||
active_list.needs_help!
|
||||
#render json: JSONAPI::Serializer.serialize(@table, serializer: Users::TableSerializer)
|
||||
render json: {}
|
||||
head :no_content
|
||||
end
|
||||
|
||||
# POST /user/tables/:id/join
|
||||
@@ -35,7 +33,7 @@ module Users
|
||||
if @list = @table.active_list
|
||||
@list.send_table_join_request_for_user! current_user
|
||||
end
|
||||
head :ok
|
||||
head :no_content
|
||||
end
|
||||
|
||||
# GET /user/table_info.json
|
||||
@@ -61,15 +59,18 @@ module Users
|
||||
end
|
||||
|
||||
# Used by the user Ember app
|
||||
# NOTE: ordering on a table always creates a new list or failes if the conditions for creating a new
|
||||
# list are not met. To order on an already open list send the request to the lists controller
|
||||
# POST /user/tables/:id/order_products
|
||||
def order_products
|
||||
table = Table.find(params[:id])
|
||||
res = {}
|
||||
res[:active_list_present] = true if active_list.present?
|
||||
res[:occupied] = table.occupied?
|
||||
res[:reserved] = table.reserved?
|
||||
res[:supplier_closed] = table.supplier.closed?
|
||||
res[:no_product_orders] = true unless product_orders = new_order_product_orders.presence
|
||||
unless res[:occupied] or res[:supplier_closed] or res[:no_product_orders]
|
||||
unless res[:occupied] or res[:supplier_closed] or res[:no_product_orders] or res[:active_list_present]
|
||||
# Create new list
|
||||
list = List.from_table( table, current_user )
|
||||
res[:active_list_id] = list.id # used to set the active list in the app
|
||||
|
||||
@@ -8,6 +8,9 @@ class EmployeeShift
|
||||
belongs_to :supplier
|
||||
belongs_to :employee
|
||||
|
||||
validates :start_from, presence: true
|
||||
validates :end_on, presence: true
|
||||
|
||||
view :for_supplier_view, type: :custom, map_function: %|function(doc){
|
||||
if(doc.ruby_class == 'EmployeeShift' && doc.start_from && doc.end_on){
|
||||
emit([doc.supplier_id, doc.end_on], 1)
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
class ListSerializer < Qwaiter::Serializer
|
||||
# user ids for facebook pictures
|
||||
#embed :ids
|
||||
attributes :state, :needs_help, :needs_payment, :user_requests_closing, :is_paid, :price, :table_id, :table_number, :section_id, :user_ids, :supplier_id, :closed_at #, :has_active_orders
|
||||
|
||||
#def has_active_orders
|
||||
#object.has_active_orders?
|
||||
#end
|
||||
end
|
||||
@@ -1,4 +0,0 @@
|
||||
class SectionSerializer < Qwaiter::Serializer
|
||||
attributes :title, :path, :width, :height
|
||||
has_many :tables
|
||||
end
|
||||
@@ -1,5 +0,0 @@
|
||||
class SupplierTableSerializer < Qwaiter::Serializer
|
||||
self.root = :table
|
||||
attributes :number, :width, :height, :position_x, :position_y, :section_id, :needs_help
|
||||
has_one :supplier, serializer: Suppliers::SupplierSerializer
|
||||
end
|
||||
@@ -1,17 +0,0 @@
|
||||
class TableSerializer < Qwaiter::Serializer
|
||||
attributes :number, :width, :height, :position_x, :position_y, :section_id, :occupied #, :alist_id
|
||||
|
||||
#def list_id
|
||||
#object.active_list_id || object.active_list.try(:id)
|
||||
#end
|
||||
|
||||
#def list
|
||||
#object.active_list
|
||||
#end
|
||||
|
||||
def list
|
||||
object.active_list
|
||||
end
|
||||
|
||||
has_one :list, key: :active_list_id
|
||||
end
|
||||
@@ -1,34 +0,0 @@
|
||||
#class ListExtendedSerializer
|
||||
#render json: {
|
||||
#list: list.serialized_with_status_join_requests_and_supplier_counters.merge(order_ids: list.orders.map(&:id)),
|
||||
#}
|
||||
#.merge(ActiveModel::ArraySerializer.new(list.supplier.product_categories, each_serializer: ProductCategorySerializer, root: :product_categories).as_json)
|
||||
#.merge(ActiveModel::ArraySerializer.new(list.orders, each_serializer: OrderSerializer, root: :orders).as_json)
|
||||
#end
|
||||
=begin
|
||||
class UserExtendedListSerializer < Qwaiter::Serializer
|
||||
# user ids for facebook pictures
|
||||
self.root = :list
|
||||
attributes :extended_version, :state, :needs_help, :needs_payment, :user_requests_closing, :is_paid, :price,
|
||||
:table_id, :table_number, :section_id, :user_ids, :supplier_id, :closed_at, :cached_supplier_name
|
||||
#:supplier_orders_in_process_count, :supplier_orders_placed_count
|
||||
|
||||
def has_active_orders
|
||||
object.has_active_orders?
|
||||
end
|
||||
|
||||
def cached_supplier_name
|
||||
object.supplier.name
|
||||
end
|
||||
has_many :orders
|
||||
#has_many :product_categories
|
||||
has_one :table, serializer: Users::TableSerializer # this one add a lot of stuff
|
||||
has_many :join_requests, serializer: JoinRequestSerializer
|
||||
has_many :users, serializer: Users::UserSerializer
|
||||
#has_one :supplier # added by other resource
|
||||
|
||||
def extended_version
|
||||
true
|
||||
end
|
||||
end
|
||||
=end
|
||||
@@ -1,10 +0,0 @@
|
||||
class UserExtendedSupplierSerializer < Qwaiter::Serializer
|
||||
self.root = :supplier
|
||||
attributes :extended_version, :open, :name, :orders_in_process_count, :orders_placed_count
|
||||
has_many :product_categories
|
||||
#has_many :products only product in category!!!!!!
|
||||
|
||||
def extended_version
|
||||
true
|
||||
end
|
||||
end
|
||||
@@ -1,5 +0,0 @@
|
||||
class UserExtendedTableSerializer < Qwaiter::Serializer
|
||||
self.root = :table
|
||||
attributes :number, :width, :height, :position_x, :position_y, :section_id, :occupied, :needs_help
|
||||
has_one :supplier, serializer: UserExtendedSupplierSerializer
|
||||
end
|
||||
@@ -1,5 +1,6 @@
|
||||
class Waiter::SectionSerializer < Qwaiter::Serializer
|
||||
root 'section'
|
||||
attributes :title, :path, :width, :height
|
||||
class Waiter::SectionSerializer
|
||||
include Qwaiter::WaiterBaseSerializer
|
||||
attributes :title, :width, :height
|
||||
has_many :tables, serializer: Waiter::TableSerializer
|
||||
has_one :supplier, serializer: Waiter::SupplierSerializer
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Waiter::SupplierSerializer < Qwaiter::Serializer
|
||||
root 'supplier'
|
||||
class Waiter::SupplierSerializer
|
||||
include Qwaiter::WaiterBaseSerializer
|
||||
attributes :open, :name, :lat, :lng, :time_zone, :address, :house_number, :house_number_addition, :postal_code, :city, :country,
|
||||
:facebook_promotion_url, :iens_profile, :week_starts_on_monday, :orders_in_process_count, :orders_placed_count
|
||||
end
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
class Waiter::TableSerializer < Qwaiter::Serializer
|
||||
class Waiter::TableSerializer
|
||||
include Qwaiter::WaiterBaseSerializer
|
||||
attributes :number, :width, :height, :position_x, :position_y, :section_id, :needs_help
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user