Base progress

This commit is contained in:
2015-09-16 11:50:55 +02:00
parent ef894f9e02
commit 6a085b1ca2
52 changed files with 3686 additions and 1818 deletions
+14 -10
View File
@@ -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
+5 -10
View File
@@ -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
+7 -6
View File
@@ -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
+1 -1
View File
@@ -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
+8 -7
View File
@@ -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