143 lines
4.4 KiB
Ruby
143 lines
4.4 KiB
Ruby
module Suppliers
|
|
class SectionsController < Suppliers::ApplicationController
|
|
|
|
# GET /sections
|
|
# GET /sections.json
|
|
def index
|
|
@sections = current_supplier.sections
|
|
@sections.include_relation(:table)
|
|
@active_lists = current_supplier.active_lists
|
|
@active_table_ids = @active_lists.map(&:table_id).compact
|
|
|
|
respond_to do |format|
|
|
format.html # index.html.erb
|
|
format.json { render json: @sections }
|
|
end
|
|
end
|
|
|
|
# GET /sections/1
|
|
# GET /sections/1.json
|
|
def show
|
|
@section = Section.find_by_supplier_and_id(current_supplier, params[:id])
|
|
|
|
respond_to do |format|
|
|
format.html # show.html.erb
|
|
format.json { render json: @section }
|
|
end
|
|
end
|
|
|
|
# GET /sections/new
|
|
# GET /sections/new.json
|
|
def new
|
|
@section = Section.new
|
|
@section.supplier = current_supplier
|
|
|
|
respond_to do |format|
|
|
format.html # new.html.erb
|
|
format.json { render json: @section }
|
|
end
|
|
end
|
|
|
|
# GET /sections/1/edit
|
|
def edit
|
|
@section = Section.find_by_supplier_and_id(current_supplier, params[:id])
|
|
end
|
|
|
|
# POST /sections
|
|
# POST /sections.json
|
|
def create
|
|
@section = Section.new(params[:section])
|
|
@section.supplier = current_supplier
|
|
|
|
respond_to do |format|
|
|
if @section.save
|
|
format.html { redirect_to [:suppliers, @section], notice: t('action.create.successfull', model: Section.model_name.human) }
|
|
format.json { render json: @section, status: :created, location: @section }
|
|
else
|
|
format.html { render action: "new" }
|
|
format.json { render json: @section.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# PUT /sections/1
|
|
# PUT /sections/1.json
|
|
def update
|
|
@section = Section.find_by_supplier_and_id(current_supplier, params[:id])
|
|
|
|
respond_to do |format|
|
|
if @section.update_attributes(params[:section])
|
|
format.html { redirect_to [:suppliers, @section], notice: t('action.update.successfull', model: Section.model_name.human) }
|
|
format.json { head :no_content }
|
|
else
|
|
format.html { render action: "edit" }
|
|
format.json { render json: @section.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# DELETE /sections/1
|
|
# DELETE /sections/1.json
|
|
def destroy
|
|
@section = Section.find_by_supplier_and_id(current_supplier, params[:id])
|
|
@section.destroy
|
|
|
|
respond_to do |format|
|
|
format.html { redirect_to suppliers_sections_url, notice: t('action.destroy.successfull', model: Section.model_name.human) }
|
|
format.json { head :no_content }
|
|
end
|
|
end
|
|
|
|
# GET /sections/1/manage_tables
|
|
# GET /sections/1/manage_tables.json
|
|
def manage_tables
|
|
@section = Section.find_by_supplier_and_id(current_supplier, params[:id])
|
|
|
|
respond_to do |format|
|
|
format.html # show.html.erb
|
|
format.json { render json: @section }
|
|
end
|
|
end
|
|
|
|
# GET /sections/1/tables_view
|
|
# GET /sections/1/tables_view.json
|
|
def tables_view
|
|
@section = Section.find_by_supplier_and_id(current_supplier, params[:id])
|
|
|
|
respond_to do |format|
|
|
format.html # show.html.erb
|
|
format.json do
|
|
render json: @section.for_tables_as_json
|
|
end
|
|
end
|
|
end
|
|
|
|
# POST /sections/1/add_tables {number_start: 1423, number_end: 234234}
|
|
def add_tables
|
|
@section = Section.find_by_supplier_and_id(current_supplier, params[:id])
|
|
number_start = params[:number_start].to_i
|
|
number_end = params[:number_end].to_i
|
|
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
|
|
end
|
|
@section.arrange_tables_in_grid
|
|
render json: {ok: true}
|
|
end
|
|
|
|
# POST /sections/1/arrange_tables {number_start: 1423, number_end: 234234}
|
|
def arrange_tables
|
|
@section = Section.find_by_supplier_and_id(current_supplier, params[:id])
|
|
case params[:option]
|
|
when 'distributed' then @section.arrange_tables_in_grid
|
|
when 'by_row' then @section.arrange_tables_in_rows_of(params[:row_count].to_i)
|
|
when 'by_column' then @section.arrange_tables_in_columns_of(params[:column_count].to_i)
|
|
end
|
|
render json: {ok: true}
|
|
end
|
|
end
|
|
end
|