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
@@ -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