-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added solution picker to initiative creation screen
- Loading branch information
Showing
43 changed files
with
878 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class InitiativeSolution < ApplicationRecord | ||
belongs_to :solution | ||
belongs_to :solution_class | ||
belongs_to :initiative | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# frozen_string_literal: true | ||
|
||
class InitiativeStatus < ApplicationRecord | ||
end | ||
class InitiativeStatus < ApplicationRecord; end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,62 @@ | ||
# frozen_string_literal: true | ||
|
||
class Solution < ApplicationRecord | ||
# has_many :solution_classes | ||
has_many :solution_solution_classes, dependent: :destroy | ||
|
||
def self.deep_load_solutions | ||
Solution.all.includes( | ||
solution_solution_classes: { solution_class: { theme: :sector } } | ||
) | ||
end | ||
|
||
def self.hierarchy | ||
hierarchy = [] | ||
deep_load_solutions.find_each do |s| | ||
s.solution_solution_classes.each do |sc| | ||
sector = populate_sector(hierarchy, sc.solution_class) | ||
theme = populate_theme(sector, sc.solution_class) | ||
solution_class = populate_solution_class(theme, sc.solution_class.name) | ||
populate_solution(solution_class, sc.solution, sc.solution_class) | ||
end | ||
end | ||
hierarchy | ||
end | ||
|
||
def self.populate_sector(hierarchy, solution_class) | ||
name = solution_class.theme.sector.name | ||
sector = hierarchy.select { |s| s[:name] == name }.first | ||
if sector.nil? | ||
sector = { name: name, themes: [] } | ||
hierarchy << sector | ||
end | ||
sector | ||
end | ||
|
||
def self.populate_theme(sector, solution_class) | ||
name = solution_class.theme_name | ||
themes = sector[:themes] | ||
theme = themes.select { |t| t[:name] == name }.first | ||
if theme.nil? | ||
theme = { name: name, classes: [] } | ||
sector[:themes] << theme | ||
end | ||
theme | ||
end | ||
|
||
def self.populate_solution_class(theme, name) | ||
solution_class = theme[:classes].select { |t| t[:name] == name }.first | ||
if solution_class.nil? | ||
solution_class = { name: name, solutions: [] } | ||
theme[:classes] << solution_class | ||
end | ||
solution_class | ||
end | ||
|
||
def self.populate_solution(mapped_solution_class, solution, solution_class) | ||
name = solution.name | ||
solution = { | ||
name: name, solution_class_id: solution_class.id, solution_id: solution.id | ||
} | ||
mapped_solution_class[:solutions] << solution | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
|
||
class SolutionClass < ApplicationRecord | ||
belongs_to :theme | ||
delegate :name, to: :theme, prefix: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# frozen_string_literal: true | ||
|
||
class Tag < ApplicationRecord | ||
end | ||
class Tag < ApplicationRecord; end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<h1>Editing Initiative</h1> | ||
|
||
<%= render 'form', initiative: @initiative, groups: @groups, initiative_statuses: @initiative_statuses %> | ||
<%= render 'form', initiative: @initiative, groups: @groups, initiative_statuses: @initiative_statuses, taxonomy_hierarchy_json: @taxonomy_hierarchy_json %> | ||
|
||
<%= link_to 'Show', @initiative %> | | ||
<%= link_to 'Back', initiatives_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<h1>New Initiative</h1> | ||
|
||
<%= render 'form', initiative: @initiative, groups: @groups, initiative_statuses: @initiative_statuses %> | ||
<%= render 'form', initiative: @initiative, groups: @groups, initiative_statuses: @initiative_statuses, taxonomy_hierarchy_json: @taxonomy_hierarchy_json %> | ||
|
||
<%= link_to 'Back', initiatives_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateInitiativeSolutions < ActiveRecord::Migration[6.0] | ||
def change | ||
create_table :initiative_solutions do |t| | ||
t.references :solution, null: false, foreign_key: true | ||
t.references :solution_class, null: false, foreign_key: true | ||
t.references :initiative, null: false, foreign_key: true | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.