diff --git a/app/controllers/companies_controller.rb b/app/controllers/companies_controller.rb index dade852..5f5120d 100644 --- a/app/controllers/companies_controller.rb +++ b/app/controllers/companies_controller.rb @@ -6,9 +6,6 @@ class CompaniesController < ApplicationController @companies = Company.all end - # GET /companies/1 or /companies/1.json - def show - end # GET /companies/new def new @@ -25,7 +22,7 @@ class CompaniesController < ApplicationController respond_to do |format| if @company.save - format.html { redirect_to company_url(@company), notice: "Company was successfully created." } + format.html { redirect_to root_url, notice: "Company was successfully created." } format.json { render :show, status: :created, location: @company } else format.html { render :new, status: :unprocessable_entity } diff --git a/app/models/caf.rb b/app/models/caf.rb index c44d340..b3a53aa 100644 --- a/app/models/caf.rb +++ b/app/models/caf.rb @@ -1,6 +1,50 @@ class Caf < ApplicationRecord + after_create :populate_caf_info belongs_to :company + has_many :objectives, dependent: :destroy validates :name, presence: true validates :name, uniqueness: { scope: :company_id, message: "should be unique to the company"} + + private + def populate_caf_info + file = YAML.load_file(Rails.root.to_s + '/config/caf_text.yml') + objectives = file["objectives"] + + objectives.each do |objective| + objective_info = objective["objective"] + #

<%= objective_info["name"] %>
<%= objective_info["description"] %>

+ obj = self.objectives.create(name: objective_info["name"], description: objective_info["description"] ) + principles = objective_info["principles"] + + principles.each do |principle| + principle_info = principle["principle"] + #

<%= principle_info["name"] %>
<%= principle_info["description"]%>

+ pri = obj.principles.create(name: principle_info["name"], description: principle_info["description"]) + sub_principles = principle_info["sub-principles"] + + sub_principles.each do |sub_principle| + sub_principle_info = sub_principle["sub-principle"] + #

<%= sub_principle_info["name"]%>
<%= sub_principle_info["description"]%>

+ subpri = pri.subprinciples.create(name: sub_principle_info["name"], description: sub_principle_info["description"] ) + sub_principle_item_groups = sub_principle_info["subprincipleitemgroups"] + + sub_principle_item_groups.each do |key,value| + header = key["subprincipleitemgroup"] + # <%= header["type"] %> - <%= header["condition"] %>
+ subpriitemgroup = subpri.subprincipleitemgroups.create(type: header["type"], condition: header["condition"]) + subprincipleitem = header["subprincipleitem"] + + subprincipleitem.each do |subprinciple| + # <%= subprinciple %>
+ subpriitemgroup.subprinciples.create(description: subprinciple) + end + + end + + end + + end + end + end end diff --git a/app/models/company.rb b/app/models/company.rb index d0e85c8..43650a5 100644 --- a/app/models/company.rb +++ b/app/models/company.rb @@ -1,5 +1,5 @@ class Company < ApplicationRecord - has_many :cafs + has_many :cafs, dependent: :destroy has_and_belongs_to_many :users validates :name, presence: true validates :name, uniqueness: true diff --git a/app/models/objective.rb b/app/models/objective.rb index 8c75856..dc00c14 100644 --- a/app/models/objective.rb +++ b/app/models/objective.rb @@ -1,4 +1,4 @@ class Objective < ApplicationRecord belongs_to :caf - + has_many :principles, dependent: :destroy end diff --git a/app/models/principle.rb b/app/models/principle.rb index 64f6a05..a2e1ab0 100644 --- a/app/models/principle.rb +++ b/app/models/principle.rb @@ -1,3 +1,4 @@ class Principle < ApplicationRecord - belongs_to :caf + belongs_to :objective + has_many :subprinciples, dependent: :destroy end diff --git a/app/models/subprinciple.rb b/app/models/subprinciple.rb index 9e9fb39..d0b9a12 100644 --- a/app/models/subprinciple.rb +++ b/app/models/subprinciple.rb @@ -1,3 +1,4 @@ class Subprinciple < ApplicationRecord belongs_to :principle + has_many :subprincipleitemgroups, dependent: :destroy end diff --git a/app/models/subprincipleitemgroup.rb b/app/models/subprincipleitemgroup.rb index 398731e..78afd9a 100644 --- a/app/models/subprincipleitemgroup.rb +++ b/app/models/subprincipleitemgroup.rb @@ -1,3 +1,4 @@ class Subprincipleitemgroup < ApplicationRecord belongs_to :subprinciple + has_many :subprincipleitems, dependent: :destroy end diff --git a/app/views/companies/show.html.erb b/app/views/companies/show.html.erb index e749c7e..a76a9fc 100644 --- a/app/views/companies/show.html.erb +++ b/app/views/companies/show.html.erb @@ -1,10 +1,7 @@ -

<%= notice %>

- <%= render @company %>
<%= link_to "Edit this company", edit_company_path(@company) %> | <%= link_to "Back to companies", companies_path %> - <%= button_to "Destroy this company", @company, method: :delete %>
diff --git a/db/migrate/20230212065945_rename_type_to_kind_in_subprincipleitemgroup.rb b/db/migrate/20230212065945_rename_type_to_kind_in_subprincipleitemgroup.rb new file mode 100644 index 0000000..4e4cba6 --- /dev/null +++ b/db/migrate/20230212065945_rename_type_to_kind_in_subprincipleitemgroup.rb @@ -0,0 +1,4 @@ +class RenameTypeToKindInSubprincipleitemgroup < ActiveRecord::Migration[7.0] + def change + end +end