Class: Admin::PropertyDataController

Inherits:
AdminController
  • Object
show all
Defined in:
app/controllers/admin/property_data_controller.rb

Overview

Controller for managing property data.

Instance Method Summary collapse

Instance Method Details

#asset_condition_formObject

Displays a form for creating a fixed_assets.conditions property data item.



212
213
214
215
216
# File 'app/controllers/admin/property_data_controller.rb', line 212

def asset_condition_form
  @property_data = PropertyData.new
  @key = 'fixed_assets.conditions'
  render 'admin/property_data/new'
end

#asset_conditionsObject

Displays a list of fixed_assets.conditions property data items.



174
175
176
177
178
179
180
181
# File 'app/controllers/admin/property_data_controller.rb', line 174

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_formObject

Displays a form for creating a fixed_assets.makes property data item.



205
206
207
208
209
# File 'app/controllers/admin/property_data_controller.rb', line 205

def asset_make_form
  @property_data = PropertyData.new
  @key = 'fixed_assets.makes'
  render 'admin/property_data/new'
end

#asset_makesObject

Displays a list of fixed_assets.makes property data items.



164
165
166
167
168
169
170
171
# File 'app/controllers/admin/property_data_controller.rb', line 164

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_formObject

Displays a form for creating a fixed_assets.types property data item.



198
199
200
201
202
# File 'app/controllers/admin/property_data_controller.rb', line 198

def asset_type_form
  @property_data = PropertyData.new
  @key = 'fixed_assets.types'
  render 'admin/property_data/new'
end

#asset_typesObject

Displays a list of fixed_assets.types property data items.



154
155
156
157
158
159
160
161
# File 'app/controllers/admin/property_data_controller.rb', line 154

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

#createObject

POST /property_data POST /property_data.json Creates a new property data item.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/admin/property_data_controller.rb', line 44

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

#destroyObject

DELETE /property_data/1 DELETE /property_data/1.json Deletes an existing property data item.



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
128
129
130
131
# File 'app/controllers/admin/property_data_controller.rb', line 102

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

#editObject

GET /property_data/1/edit Displays a form for editing a property data item.



34
35
36
37
38
39
# File 'app/controllers/admin/property_data_controller.rb', line 34

def edit
  @old_string = params[:property_data][:old_string] if params[:property_data]
  @key = @property_data.key

  # render json: @old_string
end

#indexObject

GET /property_data GET /property_data.json Displays a list of property data.



11
12
13
14
15
16
17
18
19
# File 'app/controllers/admin/property_data_controller.rb', line 11

def index
  @property_data = PropertyData.page params[:page]

  if request.xhr?
    render action: :index ,layout: false
  else
    render action: :index, layout: true
  end
end

#newObject

GET /property_data/new Displays a form for creating new property data.



28
29
30
# File 'app/controllers/admin/property_data_controller.rb', line 28

def new
  @property_data = PropertyData.new
end

#reason_uninspectable_buildingsObject

Displays a list of reason_uninspectable.building property data items.



134
135
136
137
138
139
140
141
# File 'app/controllers/admin/property_data_controller.rb', line 134

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_unitsObject

Displays a list of reason_uninspectable.unit property data items.



144
145
146
147
148
149
150
151
# File 'app/controllers/admin/property_data_controller.rb', line 144

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_formObject

Displays a form for creating a reason_uninspectable.building property data item.



184
185
186
187
188
# File 'app/controllers/admin/property_data_controller.rb', line 184

def ru_building_form
  @property_data = PropertyData.new
  @key = 'reason_uninspectable.building'
  render 'admin/property_data/new'
end

#ru_unit_formObject

Displays a form for creating a reason_uninspectable.unit property data item.



191
192
193
194
195
# File 'app/controllers/admin/property_data_controller.rb', line 191

def ru_unit_form
  @property_data = PropertyData.new
  @key = 'reason_uninspectable.unit'
  render 'admin/property_data/new'
end

#showObject

GET /property_data/1 GET /property_data/1.json Displays the details of a specific property data item.



24
# File 'app/controllers/admin/property_data_controller.rb', line 24

def show; end

#updateObject

PATCH/PUT /property_data/1 PATCH/PUT /property_data/1.json Updates an existing property data item.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/controllers/admin/property_data_controller.rb', line 72

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