Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions app/controllers/organization_status_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
#
# ### Columns
#
# Name | Type | Attributes
# -------------- | ------------------ | ---------------------------
# **`active`** | `boolean` | `default(TRUE)`
# **`display`** | `boolean` |
# **`id`** | `integer` | `not null, primary key`
# **`name`** | `string(255)` |
# Name | Type | Attributes
# --------------- | ------------------ | ---------------------------
# **`active`** | `boolean` | `default(TRUE)`
# **`category`** | `string(255)` |
# **`display`** | `boolean` |
# **`id`** | `integer` | `not null, primary key`
# **`name`** | `string(255)` |
#

class OrganizationStatusTypesController < ApplicationController
Expand Down
7 changes: 5 additions & 2 deletions app/models/organization_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class OrganizationStatus < ActiveRecord::Base
belongs_to :participant

scope :displayable, -> { joins(:organization_status_type).where('organization_status_types.display = ?', true) }
scope :active, -> { where(active: true) }
scope :inactive, -> { where(active: false) }
scope :electrical, -> { joins(:organization_status_type).where('organization_status_types.category = ?', 'electrical') }
scope :structural, -> { joins(:organization_status_type).where('organization_status_types.category = ?', 'structural') }
scope :general, -> { joins(:organization_status_type).where('organization_status_types.category = ?', 'general') }
scope :active, -> { where(active: true) }
scope :inactive, -> { where(active: false) }
end
13 changes: 7 additions & 6 deletions app/models/organization_status_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
#
# ### Columns
#
# Name | Type | Attributes
# -------------- | ------------------ | ---------------------------
# **`active`** | `boolean` | `default(TRUE)`
# **`display`** | `boolean` |
# **`id`** | `integer` | `not null, primary key`
# **`name`** | `string(255)` |
# Name | Type | Attributes
# --------------- | ------------------ | ---------------------------
# **`active`** | `boolean` | `default(TRUE)`
# **`category`** | `string(255)` |
# **`display`** | `boolean` |
# **`id`** | `integer` | `not null, primary key`
# **`name`** | `string(255)` |
#

class OrganizationStatusType < ActiveRecord::Base
Expand Down
18 changes: 16 additions & 2 deletions app/views/organizations/_organization.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,22 @@
<td>
<% if !organization.organization_category.is_building %>
&mdash;
<% elsif can?(:read, organization.organization_statuses.displayable.last) %>
<%= link_to organization.organization_statuses.displayable.last.organization_status_type.name, [organization, :organization_statuses] unless organization.organization_statuses.displayable.blank? %>
<% elsif can?(:read, organization.organization_statuses.displayable.electrical.last) %>
<%= link_to organization.organization_statuses.displayable.electrical.last.organization_status_type.name, [organization, :organization_statuses] unless organization.organization_statuses.displayable.electrical.blank? %>
<% end %>
</td>
<td>
<% if !organization.organization_category.is_building %>
&mdash;
<% elsif can?(:read, organization.organization_statuses.displayable.structural.last) %>
<%= link_to organization.organization_statuses.displayable.structural.last.organization_status_type.name, [organization, :organization_statuses] unless organization.organization_statuses.displayable.structural.blank? %>
<% end %>
</td>
<td>
<% if !organization.organization_category.is_building %>
&mdash;
<% elsif can?(:read, organization.organization_statuses.displayable.general.last) %>
<%= link_to organization.organization_statuses.displayable.general.last.organization_status_type.name, [organization, :organization_statuses] unless organization.organization_statuses.displayable.general.blank? %>
<% end %>
</td>
<% end %>
Expand Down
4 changes: 3 additions & 1 deletion app/views/organizations/_organizations.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
<tr>
<th>Name</th>
<% if can?(:read, OrganizationStatus) %>
<th>Status</th>
<th>Electrical</th>
<th>Structural</th>
<th>General</th>
<% end %>
<th>Category</th>
</tr>
Expand Down
22 changes: 18 additions & 4 deletions app/views/organizations/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,27 @@
<% end %>
<% if can?(:read, OrganizationStatus) and @organization.organization_category.is_building %>
<p>
<strong>Status:</strong>
<% unless @organization.organization_statuses.displayable.last.blank? or not can?(:read, @organization.organization_statuses.displayable.last) %>
<%= link_to @organization.organization_statuses.displayable.last.organization_status_type.name, organization_organization_statuses_path(@organization) %> on <%= date_and_time @organization.organization_statuses.displayable.last.created_at %>
<strong>Electrical Status:</strong>
<% unless @organization.organization_statuses.displayable.electrical.last.blank? or not can?(:read, @organization.organization_statuses.displayable.last) %>
<%= link_to @organization.organization_statuses.displayable.electrical.last.organization_status_type.name, organization_organization_statuses_path(@organization) %> on <%= date_and_time @organization.organization_statuses.displayable.electrical.last.created_at %>
<% end %>
</p>
<p>
<strong>Structural Status:</strong>
<% unless @organization.organization_statuses.displayable.structural.last.blank? or not can?(:read, @organization.organization_statuses.displayable.last) %>
<%= link_to @organization.organization_statuses.displayable.structural.last.organization_status_type.name, organization_organization_statuses_path(@organization) %> on <%= date_and_time @organization.organization_statuses.displayable.structural.last.created_at %>
<% end %>
</p>
<p>
<strong>General Status:</strong>
<% unless @organization.organization_statuses.displayable.general.last.blank? or not can?(:read, @organization.organization_statuses.displayable.last) %>
<%= link_to @organization.organization_statuses.displayable.general.last.organization_status_type.name, organization_organization_statuses_path(@organization) %> on <%= date_and_time @organization.organization_statuses.displayable.general.last.created_at %>
<% end %>
</p>
<p>
<% if can?(:create, OrganizationStatus) %>
<%= link_to t('.update', :default => t("helpers.links.update")),
[:new, @organization, :organization_status], :class => 'btn btn-primary btn-xs' %>
[:new, @organization, :organization_status], :class => 'btn btn-primary btn-xs' %>
<% end %>
</p>
<% end %>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20190506153740_split_org_status_types.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class SplitOrgStatusTypes < ActiveRecord::Migration
def change
add_column :organization_status_types, :category, :string
end
end
7 changes: 4 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20190322200326) do
ActiveRecord::Schema.define(version: 20190506153740) do

create_table "certification_types", force: :cascade do |t|
t.string "name", limit: 255
Expand Down Expand Up @@ -146,9 +146,10 @@
end

create_table "organization_status_types", force: :cascade do |t|
t.string "name", limit: 255
t.string "name", limit: 255
t.boolean "display"
t.boolean "active", default: true
t.boolean "active", default: true
t.string "category", limit: 255
end

create_table "organization_statuses", force: :cascade do |t|
Expand Down
2 changes: 1 addition & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
csv_text = File.read(Rails.root.join('lib', 'seeds', gdrive_doc + 'organization_status_types.csv'))
csv = CSV.parse(csv_text, :headers => true)
csv.each do |row|
OrganizationStatusType.create(name: row['name'].strip, display: row['display'] == "TRUE")
OrganizationStatusType.create(name: row['name'].strip, display: row['display'] == "TRUE", category: row['category'].strip)
end

puts ' Charge Types'
Expand Down
26 changes: 13 additions & 13 deletions lib/seeds/2019-seeds - organization_status_types.csv
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name,display
Authorized for Plan Deviation,FALSE
First Floor Level,TRUE
First Floor Walls,TRUE
Stairs,TRUE
Second Floor Level,TRUE
Second Floor Walls,TRUE
Roof,TRUE
Final Structural Inspection,TRUE
First Floor Electrical,TRUE
Second Floor Electrical,TRUE
Final Electrical Inspection,TRUE
Note,FALSE
name,display,category
Authorized for Plan Deviation,FALSE,structural
First Floor Level,TRUE,structural
First Floor Walls,TRUE,structural
Stairs,TRUE,structural
Second Floor Level,TRUE,structural
Second Floor Walls,TRUE,structural
Roof,TRUE,structural
Final Structural Inspection,TRUE,structural
First Floor Electrical,TRUE,electrical
Second Floor Electrical,TRUE,electrical
Final Electrical Inspection,TRUE,electrical
Note,FALSE,general
13 changes: 7 additions & 6 deletions test/unit/organization_status_type_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
#
# ### Columns
#
# Name | Type | Attributes
# -------------- | ------------------ | ---------------------------
# **`active`** | `boolean` | `default(TRUE)`
# **`display`** | `boolean` |
# **`id`** | `integer` | `not null, primary key`
# **`name`** | `string(255)` |
# Name | Type | Attributes
# --------------- | ------------------ | ---------------------------
# **`active`** | `boolean` | `default(TRUE)`
# **`category`** | `string(255)` |
# **`display`** | `boolean` |
# **`id`** | `integer` | `not null, primary key`
# **`name`** | `string(255)` |
#

require 'test_helper'
Expand Down