Class: Admin::PropertyDataController
- Inherits:
-
AdminController
- Object
- AdminController
- Admin::PropertyDataController
- Defined in:
- app/controllers/admin/property_data_controller.rb
Overview
Controller for managing property data.
Instance Method Summary collapse
-
#asset_condition_form ⇒ Object
Displays a form for creating a fixed_assets.conditions property data item.
-
#asset_conditions ⇒ Object
Displays a list of fixed_assets.conditions property data items.
-
#asset_make_form ⇒ Object
Displays a form for creating a fixed_assets.makes property data item.
-
#asset_makes ⇒ Object
Displays a list of fixed_assets.makes property data items.
-
#asset_type_form ⇒ Object
Displays a form for creating a fixed_assets.types property data item.
-
#asset_types ⇒ Object
Displays a list of fixed_assets.types property data items.
-
#create ⇒ Object
POST /property_data POST /property_data.json Creates a new property data item.
-
#destroy ⇒ Object
DELETE /property_data/1 DELETE /property_data/1.json Deletes an existing property data item.
-
#edit ⇒ Object
GET /property_data/1/edit Displays a form for editing a property data item.
-
#index ⇒ Object
GET /property_data GET /property_data.json Displays a list of property data.
-
#new ⇒ Object
GET /property_data/new Displays a form for creating new property data.
-
#reason_uninspectable_buildings ⇒ Object
Displays a list of reason_uninspectable.building property data items.
-
#reason_uninspectable_units ⇒ Object
Displays a list of reason_uninspectable.unit property data items.
-
#ru_building_form ⇒ Object
Displays a form for creating a reason_uninspectable.building property data item.
-
#ru_unit_form ⇒ Object
Displays a form for creating a reason_uninspectable.unit property data item.
-
#show ⇒ Object
GET /property_data/1 GET /property_data/1.json Displays the details of a specific property data item.
-
#update ⇒ Object
PATCH/PUT /property_data/1 PATCH/PUT /property_data/1.json Updates an existing property data item.
Instance Method Details
#asset_condition_form ⇒ Object
Displays a form for creating a fixed_assets.conditions property data item.
208 209 210 211 212 |
# File 'app/controllers/admin/property_data_controller.rb', line 208 def asset_condition_form @property_data = PropertyData.new @key = 'fixed_assets.conditions' render 'admin/property_data/new' end |
#asset_conditions ⇒ Object
Displays a list of fixed_assets.conditions property data items.
170 171 172 173 174 175 176 177 |
# File 'app/controllers/admin/property_data_controller.rb', line 170 def asset_conditions @property_data = PropertyData.where(key: 'fixed_assets.conditions').page params[:page] @meta = { form_for: 'conditions', page: 'Asset Condition' } render 'admin/property_data/index' end |
#asset_make_form ⇒ Object
Displays a form for creating a fixed_assets.makes property data item.
201 202 203 204 205 |
# File 'app/controllers/admin/property_data_controller.rb', line 201 def asset_make_form @property_data = PropertyData.new @key = 'fixed_assets.makes' render 'admin/property_data/new' end |
#asset_makes ⇒ Object
Displays a list of fixed_assets.makes property data items.
160 161 162 163 164 165 166 167 |
# File 'app/controllers/admin/property_data_controller.rb', line 160 def asset_makes @property_data = PropertyData.where(key: 'fixed_assets.makes').page params[:page] @meta = { form_for: 'makes', page: 'Asset Make' } render 'admin/property_data/index' end |
#asset_type_form ⇒ Object
Displays a form for creating a fixed_assets.types property data item.
194 195 196 197 198 |
# File 'app/controllers/admin/property_data_controller.rb', line 194 def asset_type_form @property_data = PropertyData.new @key = 'fixed_assets.types' render 'admin/property_data/new' end |
#asset_types ⇒ Object
Displays a list of fixed_assets.types property data items.
150 151 152 153 154 155 156 157 |
# File 'app/controllers/admin/property_data_controller.rb', line 150 def asset_types @property_data = PropertyData.where(key: 'fixed_assets.types').page params[:page] @meta = { form_for: 'types', page: 'Asset Type' } render 'admin/property_data/index' end |
#create ⇒ Object
POST /property_data POST /property_data.json Creates a new property data item.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/controllers/admin/property_data_controller.rb', line 40 def create params = property_data_params params[:created_by_id] = current_user.id @property_data = PropertyData.find_by_key(params[:key]) value = JSON(@property_data.value) value.push(params[:value]) @property_data.value = value.to_s @property_data.property_id = params[:property_id] respond_to do |format| if @property_data.save format.html do redirect_to params[:redirect_url], notice: 'Data was successfully created.' end format.json { render :show, status: :created, location: @property_data } else format.html { render :new } format.json { render json: @property_data.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /property_data/1 DELETE /property_data/1.json Deletes an existing property data item.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'app/controllers/admin/property_data_controller.rb', line 98 def destroy value = params[:property_data][:value] key = params[:property_data][:key] @property_data = PropertyData.find_by_key(key) arr = JSON(@property_data.value) if arr.include? value arr.delete(value) @property_data.value = arr.to_s @property_data.property_id = Property.first.id if @property_data.property_id == 0 @property_data.save end url = @property_data.key.split(/[_,.]/) respond_to do |format| format.html do # return render json: url.join('/').last(1) if url.join('/').last(1) == 's' redirect_to '/admin/property_data/' + url.join('/'), notice: url.join(' ').titleize + ' was successfully removed.' else redirect_to '/admin/property_data/' + url.join('/') + 's', notice: url.join(' ').titleize + ' was successfully removed.' end # redirect_to '/admin/property_data/' + url.join('/') + 's', # notice: url.join(' ').titleize + ' was successfully removed.' end format.json { head :no_content } end end |
#edit ⇒ Object
GET /property_data/1/edit Displays a form for editing a property data item.
30 31 32 33 34 35 |
# File 'app/controllers/admin/property_data_controller.rb', line 30 def edit @old_string = params[:property_data][:old_string] if params[:property_data] @key = @property_data.key # render json: @old_string end |
#index ⇒ Object
GET /property_data GET /property_data.json Displays a list of property data.
11 12 13 14 15 |
# File 'app/controllers/admin/property_data_controller.rb', line 11 def index @property_data = PropertyData.page params[:page] render action: :index, layout: request.xhr?.nil? end |
#new ⇒ Object
GET /property_data/new Displays a form for creating new property data.
24 25 26 |
# File 'app/controllers/admin/property_data_controller.rb', line 24 def new @property_data = PropertyData.new end |
#reason_uninspectable_buildings ⇒ Object
Displays a list of reason_uninspectable.building property data items.
130 131 132 133 134 135 136 137 |
# File 'app/controllers/admin/property_data_controller.rb', line 130 def reason_uninspectable_buildings @property_data = PropertyData.where(key: 'reason_uninspectable.building').page params[:page] @meta = { form_for: 'buildings', page: 'Reason Uninspectable Building' } render 'admin/property_data/index' end |
#reason_uninspectable_units ⇒ Object
Displays a list of reason_uninspectable.unit property data items.
140 141 142 143 144 145 146 147 |
# File 'app/controllers/admin/property_data_controller.rb', line 140 def reason_uninspectable_units @property_data = PropertyData.where(key: 'reason_uninspectable.unit').page params[:page] @meta = { form_for: 'units', page: 'Reason Uninspectable Unit' } render 'admin/property_data/index' end |
#ru_building_form ⇒ Object
Displays a form for creating a reason_uninspectable.building property data item.
180 181 182 183 184 |
# File 'app/controllers/admin/property_data_controller.rb', line 180 def ru_building_form @property_data = PropertyData.new @key = 'reason_uninspectable.building' render 'admin/property_data/new' end |
#ru_unit_form ⇒ Object
Displays a form for creating a reason_uninspectable.unit property data item.
187 188 189 190 191 |
# File 'app/controllers/admin/property_data_controller.rb', line 187 def ru_unit_form @property_data = PropertyData.new @key = 'reason_uninspectable.unit' render 'admin/property_data/new' end |
#show ⇒ Object
GET /property_data/1 GET /property_data/1.json Displays the details of a specific property data item.
20 |
# File 'app/controllers/admin/property_data_controller.rb', line 20 def show; end |
#update ⇒ Object
PATCH/PUT /property_data/1 PATCH/PUT /property_data/1.json Updates an existing property data item.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/controllers/admin/property_data_controller.rb', line 68 def update params = property_data_params params[:updated_by_id] = current_user.id @property_data = PropertyData.find_by_key(params[:key]) value = JSON(@property_data.value) value.delete(params[:old_string]) if params[:old_string] value.push(params[:value]) @property_data.value = value.to_s @property_data.property_id = params[:property_id] url = @property_data.key.split(/[_,.]/) respond_to do |format| if @property_data.save url = '/admin/property_data/' + url.join('/') if(url[url.size - 1] != 's') then url += 's' end format.html { redirect_to url, notice: 'Property data was successfully updated.' } format.json { render :show, status: :ok, location: @property_data } else format.html { render :edit } format.json { render json: @property_data.errors, status: :unprocessable_entity } end end end |