Add CRUD Milestone on Admin::BudgetInvestment. Rename Checkpoint to Milestone.
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
class Admin::BudgetInvestmentMilestonesController < Admin::BaseController
|
||||
|
||||
before_action :load_budget_investment, only: [:index, :new, :create, :edit, :update, :destroy]
|
||||
before_action :load_budget_investment_milestone, only: [:edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
def new
|
||||
@milestone = Budget::Investment::Milestone.new
|
||||
end
|
||||
|
||||
def create
|
||||
@milestone = Budget::Investment::Milestone.new(milestone_params)
|
||||
@milestone.investment = @investment
|
||||
if @milestone.save
|
||||
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment), notice: t('admin.milestones.create.notice')
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
if @milestone.update(milestone_params)
|
||||
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment), notice: t('admin.milestones.update.notice')
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@milestone.destroy
|
||||
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment), notice: t('admin.milestones.delete.notice')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def milestone_params
|
||||
params.require(:budget_investment_milestone)
|
||||
.permit(:title, :description, :budget_investment_id)
|
||||
end
|
||||
|
||||
def load_budget_investment
|
||||
@investment = Budget::Investment.find params[:budget_investment_id]
|
||||
end
|
||||
|
||||
def load_budget_investment_milestone
|
||||
@milestone = Budget::Investment::Milestone.find params[:id]
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
@@ -20,7 +20,7 @@ class Budget
|
||||
has_many :valuator_assignments, dependent: :destroy
|
||||
has_many :valuators, through: :valuator_assignments
|
||||
has_many :comments, as: :commentable
|
||||
has_many :checkpoints
|
||||
has_many :milestones
|
||||
|
||||
validates :title, presence: true
|
||||
validates :author, presence: true
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
class Budget
|
||||
class Investment
|
||||
class Checkpoint < ActiveRecord::Base
|
||||
class Milestone < ActiveRecord::Base
|
||||
belongs_to :investment
|
||||
|
||||
validates :title, presence: true
|
||||
validates :investment, presence: true
|
||||
|
||||
def self.title_max_length
|
||||
80
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
<%= form_for [:admin, @investment.budget, @investment, @milestone] do |f| %>
|
||||
|
||||
<%= f.text_field :title, maxlength: Budget::Investment::Milestone.title_max_length %>
|
||||
<%= f.text_area :description %>
|
||||
|
||||
<%= f.submit nil, class: "button success" %>
|
||||
<% end %>
|
||||
@@ -0,0 +1,5 @@
|
||||
<%= back_link_to admin_budget_budget_investment_path(@investment.budget, @investment) %>
|
||||
|
||||
<h2><%= t("admin.milestones.edit.title") %></h2>
|
||||
|
||||
<%= render '/admin/budget_investment_milestones/form' %>
|
||||
10
app/views/admin/budget_investment_milestones/new.html.erb
Normal file
10
app/views/admin/budget_investment_milestones/new.html.erb
Normal file
@@ -0,0 +1,10 @@
|
||||
<div class="milestone-new row">
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= back_link_to admin_budget_budget_investment_path(@investment.budget, @investment) %>
|
||||
|
||||
<h1><%= t("admin.milestones.new.creating") %></h1>
|
||||
|
||||
<%= render "form" %>
|
||||
</div>
|
||||
</div>
|
||||
32
app/views/admin/budget_investments/_milestones.html.erb
Normal file
32
app/views/admin/budget_investments/_milestones.html.erb
Normal file
@@ -0,0 +1,32 @@
|
||||
<% if @investment.milestones.any? %>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= t("admin.milestones.index.table_id") %></th>
|
||||
<th><%= t("admin.milestones.index.table_title") %></th>
|
||||
<th><%= t("admin.milestones.index.table_description") %></th>
|
||||
<th><%= t("admin.milestones.index.table_actions") %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @investment.milestones.each do |milestone| %>
|
||||
<tr id="<%= dom_id(milestone) %>" class="milestone">
|
||||
<td>
|
||||
<%= milestone.id %>
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to milestone.title, edit_admin_budget_budget_investment_budget_investment_milestone_path(@investment.budget, @investment, milestone) %>
|
||||
</td>
|
||||
<td class="small">
|
||||
<%= milestone.description %>
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to t("admin.milestones.index.delete"), admin_budget_budget_investment_budget_investment_milestone_path(@investment.budget, @investment, milestone),
|
||||
method: :delete,
|
||||
class: 'button hollow alert expanded' %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% end %>
|
||||
@@ -47,3 +47,12 @@
|
||||
<%= link_to t("admin.budget_investments.show.edit_dossier"), edit_valuation_budget_budget_investment_path(@budget, @investment) %>
|
||||
</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<h2><%= t("admin.budget_investments.show.milestone") %></h2>
|
||||
|
||||
<%= render 'admin/budget_investments/milestones' %>
|
||||
|
||||
<p>
|
||||
<%= link_to t("admin.budget_investments.show.new_milestone"), new_admin_budget_budget_investment_budget_investment_milestone_path(@budget, @investment) %>
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user