section improvements, area elements mostly

This commit is contained in:
2015-03-03 16:43:57 +01:00
parent 196f998c38
commit c038ca3954
40 changed files with 679 additions and 55 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ class DashboardController < ApplicationController
if Rails.env.test?
@tables = Table.all
else
@tables = List.active.map(&:table) | Supplier.find_by_name('Bora').tables.sample(3)
@tables = List.active.map(&:table) | Supplier.find_by_name('Mozo').tables.select{|t| t.number.between? 20, 50}.sample(3)
end
respond_to do |format|
format.html { render layout: 'phone' }
@@ -0,0 +1,36 @@
module Suppliers
class SectionAreasController < Suppliers::ApplicationController
def index
@section_areas = SectionArea.for_supplier(current_supplier)
render json: @section_areas, each_serializer: Suppliers::SectionAreaSerializer
end
def create
@section_area.supplier = current_supplier
if @section_area.save
render json: @section_area, serializer: Suppliers::SectionAreaSerializer
else
render json: {errors: @section.errors}, status: :unprocessable_entity
end
end
def update
if @section_area.update_attributes section_area_params
render json: @section_area, serializer: Suppliers::SectionAreaSerializer
else
render json: {errors: @section.errors}, status: :unprocessable_entity
end
end
def destroy
@section_area.destroy
head :ok
end
private
def section_area_params
params.require(:section_area).permit %i[title width height position_x position_y section_id rounded]
end
end
end
@@ -22,6 +22,11 @@ module Suppliers
end
end
def destroy
@section_element.destroy()
head :ok
end
private
def section_element_params
@@ -124,14 +124,16 @@ module Suppliers
@section = Section.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
number_start = params[:number_start].to_i
number_end = params[:number_end].to_i
added_tables = []
for table_number in number_start..number_end
next if table_number.zero?
table = Table.new(number: table_number)
table.supplier = current_supplier
table.section = @section
table.save
added_tables << table
end
@section.arrange_tables_in_grid
@section.arrange_tables_in_grid added_tables
table_json = ActiveModel::ArraySerializer.new(@section.tables, each_serializer: SupplierTableSerializer, root: false).as_json
render json: {tables: table_json}
end