Skip to content

Commit

Permalink
Rename Territory to Response Territory
Browse files Browse the repository at this point in the history
This is another wide ranging change that shouldn't affect anything,
as it's just a straightforward rename.

Issue #185: Change entity names
  • Loading branch information
Frank Duncan committed Jun 16, 2020
1 parent 7af5389 commit 148c586
Show file tree
Hide file tree
Showing 50 changed files with 302 additions and 287 deletions.
2 changes: 1 addition & 1 deletion SmokeTest.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Potentially

Creating shifts in the admin console
* shifts are made up of
* geography (territory in the new world)
* geography (response territory in the new world)
* position
* time (shift group)
* see All shifts
Expand Down
2 changes: 1 addition & 1 deletion app/admin/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def initialize(person)
can [:read, :update], Scheduler::DispatchConfig, region_id: region
can :read, Incidents::DispatchLog, region_id: region

can :manage, Incidents::Territory, region_id: region
can :manage, Incidents::ResponseTerritory, region_id: region

can :manage, RegionAdminProxy do |region|
region.region_id.nil? || region.region_id == region
Expand Down
6 changes: 3 additions & 3 deletions app/admin/incidents/notifications/roles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
safe_join(r.positions.map(&:name) + r.shifts.map(&:name), tag(:br))
}
column(:counties) { |r|
safe_join(r.role_scopes.includes{territory}.map{|rs| rs.territory ? "Territory: #{rs.territory.name}" : "County: #{rs.value}" }, tag(:br))
safe_join(r.role_scopes.includes{response_territory}.map{|rs| rs.response_territory ? "Response Territory: #{rs.response_territory.name}" : "County: #{rs.value}" }, tag(:br))
}
actions
end
Expand All @@ -32,7 +32,7 @@
f.has_many :role_scopes, allow_destroy: true do |sf|
sf.input :level, as: :assignable_select_admin
sf.input :value
sf.input :territory, collection: Incidents::Territory.for_region(f.object.region)
sf.input :response_territory, collection: Incidents::ResponseTerritory.for_region(f.object.region)
end
end
f.inputs do
Expand Down Expand Up @@ -103,7 +103,7 @@ def collection
end

def resource_params
[params.fetch(resource_request_name, {}).permit(:name, :region_id, position_ids: [], shift_ids: [], triggers_attributes: [:id, :event_id, :template, :use_sms, :_destroy], role_scopes_attributes: [:id, :_destroy, :level, :value, :territory_id])]
[params.fetch(resource_request_name, {}).permit(:name, :region_id, position_ids: [], shift_ids: [], triggers_attributes: [:id, :event_id, :template, :use_sms, :_destroy], role_scopes_attributes: [:id, :_destroy, :level, :value, :response_territory_id])]
end

after_build :set_region
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ActiveAdmin.register Incidents::Territory, as: 'Territory' do
ActiveAdmin.register Incidents::ResponseTerritory, as: 'Response Territory' do
menu parent: 'Incidents'

actions :all, except: :destroy
Expand Down
44 changes: 22 additions & 22 deletions app/assets/javascripts/incidents/dispatch_intake.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,17 @@ class window.DispatchIntakeController

@updateAddressFields(result)

@getTerritory result, (territory) =>
console.log territory
if !territory? or !territory.permissions.create
$('.inside-territory').collapse('hide')
$('.outside-territory').collapse('show')
number = if territory? then territory.dispatch_number else '855-891-7325'
@getResponseTerritory result, (response_territory) =>
console.log response_territory
if !response_territory? or !response_territory.permissions.create
$('.inside-response-territory').collapse('hide')
$('.outside-response-territory').collapse('show')
number = if response_territory? then response_territory.dispatch_number else '855-891-7325'
$('.dispatch-referral').text(number)
else
$('.inside-territory').collapse('show')
$('.outside-territory').collapse('hide')
@updateTerritoryDisplay(territory)
$('.inside-response-territory').collapse('show')
$('.outside-response-territory').collapse('hide')
@updateResponseTerritoryDisplay(response_territory)



Expand All @@ -102,10 +102,10 @@ class window.DispatchIntakeController

@updateAddressFields(result)

@getTerritory result, (territory) =>
number = if territory then territory.non_disaster_number else '800-RED-CROSS (800-733-2767)'
@getResponseTerritory result, (response_territory) =>
number = if response_territory then response_territory.non_disaster_number else '800-RED-CROSS (800-733-2767)'
$('.referral-number').text(number)
@updateTerritoryDisplay(territory)
@updateResponseTerritoryDisplay(response_territory)



Expand All @@ -127,24 +127,24 @@ class window.DispatchIntakeController
console.log loc
callback(loc)

updateTerritoryDisplay: (territory) ->
if territory?
region = territory.region_name || ''
name = territory.name || ''
updateResponseTerritoryDisplay: (response_territory) ->
if response_territory?
region = response_territory.region_name || ''
name = response_territory.name || ''
else
region = ''
name = ''
$('.dispatch-region-name').text(region)
$('.dispatch-territory-name').text(name)
$('.dispatch-response-territory-name').text(name)

@setFieldVal 'region_id', territory.region_id
@setFieldVal 'territory_id', territory.id
@setFieldVal 'region_id', response_territory.region_id
@setFieldVal 'response_territory_id', response_territory.id

getTerritory: (data, callback) ->
getResponseTerritory: (data, callback) ->
$.ajax
url: '/incidents/api/territories.json'
url: '/incidents/api/response_territories.json'
data:
territory_lookup:
response_territory_lookup:
data
success: (result, status, xhr) ->
callback(result)
Expand Down
14 changes: 7 additions & 7 deletions app/assets/javascripts/incidents/incidents.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,22 @@ class window.IncidentsTrackerController
$("#narrative-modal .modal-body").html(data)
setTimeout ( () -> $("#narrative-modal .modal-body").scrollTop(0) ), 100

class window.IncidentTerritoryController
class window.IncidentResponseTerritoryController
constructor: (@url) ->
$(document).on 'change', 'select[id$=territory_id]', () =>
@updateTerritory(true)
$(document).on 'change', 'select[id$=response_territory_id]', () =>
@updateResponseTerritory(true)

updateTerritory: (preserveTerritory) ->
updateResponseTerritory: (preserveResponseTerritory) ->

query = $('form').serialize()
if !preserveTerritory
query = query + "&incidents_incident[territory_id]="
if !preserveResponseTerritory
query = query + "&incidents_incident[response_territory_id]="

$.ajax
url: @url
data: query
success: (data, status, xhr) =>
$('.territory-info').html(data)
$('.response-territory-info').html(data)



Expand Down
27 changes: 27 additions & 0 deletions app/controllers/incidents/api/response_territories_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Incidents::Api::ResponseTerritoriesController < Incidents::BaseController
protect_from_forgery with: :null_session
respond_to :json

def index
authorize! :create, Incidents::Incident

lookup = ResponseTerritoryLookup.new(params.require(:response_territory_lookup).permit(:city, :state, :zip, :county))
matcher = Incidents::ResponseTerritoryMatcher.new(lookup, Incidents::ResponseTerritory.all)
@response_territory = matcher.match_response_territory
if @response_territory
respond_with @response_territory
else
render json: {status: 'not_found'}, status: :not_found
end
end

class ResponseTerritoryLookup
attr_accessor :city, :state, :zip, :county

def initialize attrs={}
attrs.each do |attr, val|
self.send "#{attr}=", val
end
end
end
end
27 changes: 0 additions & 27 deletions app/controllers/incidents/api/territories_controller.rb

This file was deleted.

4 changes: 2 additions & 2 deletions app/controllers/incidents/dat_incidents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def form_url
def update_resource(obj, attrs)
super(obj, attrs).tap {|success|
if success && (resource.incident.previous_changes.keys & [:address, :city, :state, :zip, :county, :lat, :lng]).present?
Incidents::TerritoryMatcher.new(obj.incident).perform
Incidents::ResponseTerritoryMatcher.new(obj.incident).perform
obj.incident.save
end
}
Expand Down Expand Up @@ -176,7 +176,7 @@ def incident_params

base = params.require(:incidents_dat_incident).fetch(:incident_attributes, {})
@_incident_params ||= base.permit([
:incident_type, :territory_id, :narrative, :status, :cas_event_number,
:incident_type, :response_territory_id, :narrative, :status, :cas_event_number,
:address, :city, :state, :zip, :lat, :lng, :county, :neighborhood, :address_directly_entered,
:num_adults, :num_children, :num_families,
{:team_lead_attributes => [:id, :person_id, :role, :response]},
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/incidents/dispatch_intake_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def create_resource obj

def resource_params
[params.fetch(:incidents_call_log, {}).permit(:call_type, :call_start, :contact_name, :contact_number, :address_entry,
:address, :city, :state, :zip, :county, :lat, :lng, :region_id, :territory_id,
:address, :city, :state, :zip, :county, :lat, :lng, :region_id, :response_territory_id,
:incident_type, :services_requested, :num_displaced, :referral_reason).merge(dispatching_region_id: current_region.id, creator_id: current_user.id)]
end

Expand Down
10 changes: 5 additions & 5 deletions app/controllers/incidents/incidents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def inline_editable?
helper_method :tab_authorized?
def tab_authorized?(name)
case name
when 'summary','territory' then true
when 'summary','response_territory' then true
when 'details', 'timeline', 'responders', 'attachments' then can? :read_details, resource
when 'cases' then resource.region.incidents_collect_case_details && can?(:read_case_details, resource)
when 'changes' then can? :read_changes, resource
Expand Down Expand Up @@ -124,10 +124,10 @@ def tab_authorized?(name)
def build_resource
@resource ||= super.tap{|i|
i.date ||= Date.current
unless i.territory
Incidents::TerritoryMatcher.new(i, Incidents::Territory.all).perform
unless i.response_territory
Incidents::ResponseTerritoryMatcher.new(i, Incidents::ResponseTerritory.all).perform
end
i.region = i.territory.try :region if i.territory
i.region = i.response_territory.try :region if i.response_territory
}
end

Expand All @@ -146,7 +146,7 @@ def resource

# Never trust parameters from the scary internet, only allow the white list through.
def resource_params
keys = [:territory_id, :date, :incident_type, :status, :narrative, :address, :city, :state, :zip, :neighborhood, :county, :lat, :lng, :address_directly_entered, :recruitment_message]
keys = [:response_territory_id, :date, :incident_type, :status, :narrative, :address, :city, :state, :zip, :neighborhood, :county, :lat, :lng, :address_directly_entered, :recruitment_message]

keys << :incident_number if params[:action] == 'create' && !has_incident_number_sequence?

Expand Down
4 changes: 2 additions & 2 deletions app/models/incidents/incident.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Incidents::Incident < ActiveRecord::Base

belongs_to :region, class_name: 'Roster::Region'
belongs_to :area, class_name: 'Roster::County'
belongs_to :territory, class_name: 'Incidents::Territory'
belongs_to :response_territory, class_name: 'Incidents::ResponseTerritory'

belongs_to :cas_incident, class_name: 'Incidents::CasIncident', primary_key: 'cas_incident_number', foreign_key: 'cas_event_number'
has_one :dat_incident, class_name: 'Incidents::DatIncident', inverse_of: :incident
Expand All @@ -35,7 +35,7 @@ class Incidents::Incident < ActiveRecord::Base
accepts_nested_attributes_for :event_logs

# We always want these to be present
validates :region, :date, :territory, presence: true
validates :region, :date, :response_territory, presence: true
validates :incident_number, presence: true, format: /\A\w*\d{2}-\d{3,}\z/, uniqueness: { scope: :region_id }

scope :for_region, -> region { where{region_id.in region}}
Expand Down
2 changes: 1 addition & 1 deletion app/models/incidents/new_dispatch_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def create
def create_incident
@incident = Incidents::Incident.create! do |i|
i.status = 'open'
[:region_id, :territory_id, :incident_type, :address, :city, :county, :state, :zip, :lat, :lng].each do |attr|
[:region_id, :response_territory_id, :incident_type, :address, :city, :county, :state, :zip, :lat, :lng].each do |attr|
i[attr] = call_log[attr]
end
i.date = i.region.time_zone.today
Expand Down
2 changes: 1 addition & 1 deletion app/models/incidents/notifications/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def match_scope role
case scope.level
when 'region' then true
when 'county' then scope.value.downcase == incident_county
when 'territory' then scope.territory_id == @incident.territory_id
when 'response_territory' then scope.response_territory_id == @incident.response_territory_id
else false
end
}
Expand Down
10 changes: 5 additions & 5 deletions app/models/incidents/notifications/role_scope.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
module Incidents::Notifications
class RoleScope < ActiveRecord::Base
belongs_to :role
belongs_to :territory, class_name: 'Incidents::Territory'
belongs_to :response_territory, class_name: 'Incidents::ResponseTerritory'

validates_presence_of :territory, if: ->(obj){obj.level == 'territory'}
validates_presence_of :response_territory, if: ->(obj){obj.level == 'response_territory'}

assignable_values_for :level do
%w(region territory county)
%w(region response_territory county)
end

before_validation :clean_values
def clean_values
if level == 'territory'
if level == 'response_territory'
value = nil
else
territory_id = nil
response_territory_id = nil
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions app/models/incidents/responders_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ def flex_responders
private

def dispatch_responders
@dispatch ||= (incident.territory && service.dispatch_assignments(territory: territory))
@dispatch ||= (incident.response_territory && service.dispatch_assignments(response_territory: response_territory))
end

def territory
incident.territory
def response_territory
incident.response_territory
end

def areas
territory.calendar_counties
response_territory.calendar_counties
end

def set_defaults
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Incidents::Territory < ActiveRecord::Base
class Incidents::ResponseTerritory < ActiveRecord::Base
belongs_to :region, class_name: 'Roster::Region'
belongs_to :dispatch_config, class_name: 'Scheduler::DispatchConfig'
has_and_belongs_to_many :calendar_counties, class_name: 'Roster::County'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
class Incidents::TerritoryMatcher
def initialize(incident, territories=nil)
class Incidents::ResponseTerritoryMatcher
def initialize(incident, response_territories=nil)
@incident = incident
@collection = territories || Incidents::Territory.for_region(@incident.region)
@collection = response_territories || Incidents::ResponseTerritory.for_region(@incident.region)
end

attr_reader :incident, :collection

def perform(use_default=false)
terr = match_territory
terr ||= default_territory if use_default
terr = match_response_territory
terr ||= default_response_territory if use_default
if terr
incident.territory = terr
incident.response_territory = terr
end
terr.present?
end

def match_territory
def match_response_territory
match_field(:zip_codes, incident.zip) || match_field(:cities, "#{incident.city}, #{incident.state}") || match_field(:counties, "#{incident.county}, #{incident.state}")
end

def default_territory
def default_response_territory
collection.detect{|terr| terr.is_default }
end

Expand Down
Loading

0 comments on commit 148c586

Please sign in to comment.