Class: ErpInventory::ErpApp::Organizer::AssetManagement::FacilitiesController

Inherits:
ErpApp::Organizer::BaseController
  • Object
show all
Defined in:
app/controllers/erp_inventory/erp_app/organizer/asset_management/facilities_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



45
46
47
48
49
50
51
52
# File 'app/controllers/erp_inventory/erp_app/organizer/asset_management/facilities_controller.rb', line 45

def create

  facility = Facility.new
  facility.description=params[:description]
  facility.save

  render :json => {:success => true, :data => facility.to_hash(:only => [:id, :description, :created_at, :updated_at])}
end

#destroyObject



67
68
69
70
71
72
# File 'app/controllers/erp_inventory/erp_app/organizer/asset_management/facilities_controller.rb', line 67

def destroy

  facility = Facility.find(params[:facility_id]).destroy
  render :json => {:success => true}

end

#editObject



54
55
# File 'app/controllers/erp_inventory/erp_app/organizer/asset_management/facilities_controller.rb', line 54

def edit
end

#indexObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/erp_inventory/erp_app/organizer/asset_management/facilities_controller.rb', line 7

def index
  offset = params[:start] || 0
  limit = params[:limit] || 25
  query_filter = params[:query_filter].blank? ? nil : params[:query_filter].strip

  factility_tbl = Facility.arel_table
  statement = Facility.order('created_at asc')

  unless query_filter.blank?
    statement = statement.where(factility_tbl[:description].matches(query_filter + '%'))
  end

  # Get total count of records
  total = statement.count

  # Apply limit and offset
  facilities = statement.offset(offset).limit(limit)

  render :json => {:success => true, :total => total, :facilities => facilities.collect { |facility| facility.to_hash(:only => [:id, :description, :created_at, :updated_at]) }}

end

#newObject



42
43
# File 'app/controllers/erp_inventory/erp_app/organizer/asset_management/facilities_controller.rb', line 42

def new
end

#showObject



35
36
37
38
39
40
# File 'app/controllers/erp_inventory/erp_app/organizer/asset_management/facilities_controller.rb', line 35

def show

  facility = Facility.find(params[:facility_id])
  render :json => {:success => true, :data => facility.to_hash(:only => [:id, :description, :created_at, :updated_at])}

end

#show_summaryObject



29
30
31
32
33
# File 'app/controllers/erp_inventory/erp_app/organizer/asset_management/facilities_controller.rb', line 29

def show_summary

  @facility = Facility.find(params[:id]) rescue nil

end

#updateObject



57
58
59
60
61
62
63
64
65
# File 'app/controllers/erp_inventory/erp_app/organizer/asset_management/facilities_controller.rb', line 57

def update

  facility = Facility.find(params[:facility_id])
  facility.description=params[:description]
  facility.save

  render :json => {:success => true, :data => facility.to_hash(:only => [:id, :description, :created_at, :updated_at])}

end