Base Legislation::Process model and admin page
This commit is contained in:
5
app/controllers/admin/legislation/base_controller.rb
Normal file
5
app/controllers/admin/legislation/base_controller.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class Admin::Legislation::BaseController < Admin::BaseController
|
||||
include FeatureFlags
|
||||
|
||||
feature_flag :legislation
|
||||
end
|
||||
54
app/controllers/admin/legislation/processes_controller.rb
Normal file
54
app/controllers/admin/legislation/processes_controller.rb
Normal file
@@ -0,0 +1,54 @@
|
||||
class Admin::Legislation::ProcessesController < Admin::Legislation::BaseController
|
||||
has_filters %w{open next past all}, only: :index
|
||||
|
||||
load_and_authorize_resource :process, class: "Legislation::Process"
|
||||
|
||||
def index
|
||||
@processes = ::Legislation::Process.send(@current_filter).page(params[:page])
|
||||
end
|
||||
|
||||
def create
|
||||
@process = ::Legislation::Process.new(process_params)
|
||||
if @process.save
|
||||
redirect_to admin_legislation_processes_path
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@process.assign_attributes(process_params)
|
||||
if @process.update(process_params)
|
||||
redirect_to admin_legislation_processes_path
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@process.destroy
|
||||
redirect_to admin_legislation_processes_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def process_params
|
||||
params.require(:legislation_process).permit(
|
||||
:title,
|
||||
:description_summary,
|
||||
:target_summary,
|
||||
:description,
|
||||
:target,
|
||||
:how_to_participate,
|
||||
:additional_info,
|
||||
:start_date,
|
||||
:end_date,
|
||||
:debate_start_date,
|
||||
:debate_end_date,
|
||||
:draft_publication_date,
|
||||
:allegations_start_date,
|
||||
:allegations_end_date,
|
||||
:final_publication_date
|
||||
)
|
||||
end
|
||||
end
|
||||
5
app/controllers/legislation/base_controller.rb
Normal file
5
app/controllers/legislation/base_controller.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class Legislation::BaseController < ApplicationController
|
||||
include FeatureFlags
|
||||
|
||||
feature_flag :legislation
|
||||
end
|
||||
2
app/controllers/legislation/processes_controller.rb
Normal file
2
app/controllers/legislation/processes_controller.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
class Legislation::ProcessesController < Legislation::BaseController
|
||||
end
|
||||
@@ -5,7 +5,7 @@ module AdminHelper
|
||||
end
|
||||
|
||||
def official_level_options
|
||||
options = [["", 0]]
|
||||
options = [["",0]]
|
||||
(1..5).each do |i|
|
||||
options << [[t("admin.officials.level_#{i}"), setting["official_level_#{i}_name"]].compact.join(': '), i]
|
||||
end
|
||||
@@ -16,10 +16,14 @@ module AdminHelper
|
||||
Administrator.all.order('users.username asc').includes(:user).collect { |v| [ v.name, v.id ] }
|
||||
end
|
||||
|
||||
def admin_submit_action(resource)
|
||||
resource.persisted? ? "edit" : "new"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def namespace
|
||||
controller.class.parent.name.downcase
|
||||
controller.class.parent.name.downcase.gsub("::", "/")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -43,6 +43,8 @@ module Abilities
|
||||
|
||||
can [:read, :update, :destroy, :summary], SpendingProposal
|
||||
can [:search, :edit, :update, :create, :index, :destroy], Banner
|
||||
|
||||
can [:manage], ::Legislation::Process
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
5
app/models/legislation.rb
Normal file
5
app/models/legislation.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
module Legislation
|
||||
def self.table_name_prefix
|
||||
'legislation_'
|
||||
end
|
||||
end
|
||||
21
app/models/legislation/process.rb
Normal file
21
app/models/legislation/process.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
class Legislation::Process < ActiveRecord::Base
|
||||
acts_as_paranoid column: :hidden_at
|
||||
include ActsAsParanoidAliases
|
||||
|
||||
validates :title, presence: true
|
||||
validates :description, presence: true
|
||||
validates :target, presence: true
|
||||
validates :how_to_participate, presence: true
|
||||
validates :start_date, presence: true
|
||||
validates :end_date, presence: true
|
||||
validates :debate_start_date, presence: true
|
||||
validates :debate_end_date, presence: true
|
||||
validates :draft_publication_date, presence: true
|
||||
validates :allegations_start_date, presence: true
|
||||
validates :allegations_end_date, presence: true
|
||||
validates :final_publication_date, presence: true
|
||||
|
||||
scope :open, -> {where("start_date <= ? and end_date >= ?", Time.current, Time.current) }
|
||||
scope :next, -> {where("start_date > ?", Time.current) }
|
||||
scope :past, -> {where("end_date < ?", Time.current) }
|
||||
end
|
||||
@@ -35,6 +35,14 @@
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<% if feature?(:legislation) %>
|
||||
<li <%= "class=active" if controller_name == "processes" %>>
|
||||
<%= link_to admin_legislation_processes_path do %>
|
||||
<span class="icon-budget"></span><%= t("admin.menu.legislation") %>
|
||||
<% end %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<li <%= "class=active" if controller_name == "banners" %>>
|
||||
<%= link_to admin_banners_path do %>
|
||||
<span class="icon-eye"></span><%= t("admin.menu.banner") %>
|
||||
|
||||
1
app/views/admin/legislation/_menu.html.erb
Normal file
1
app/views/admin/legislation/_menu.html.erb
Normal file
@@ -0,0 +1 @@
|
||||
<%= render "admin/menu" %>
|
||||
155
app/views/admin/legislation/processes/_form.html.erb
Normal file
155
app/views/admin/legislation/processes/_form.html.erb
Normal file
@@ -0,0 +1,155 @@
|
||||
<%= form_for [:admin, @process] do |f| %>
|
||||
|
||||
<% if @process.errors.any? %>
|
||||
|
||||
<div id="error_explanation" data-alert class="callout alert" data-closable>
|
||||
<button class="close-button" aria-label="<%= t("application.close") %>" type="button" data-close>
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
|
||||
<strong>
|
||||
<%= @process.errors.count %>
|
||||
<%= t("admin.legislation.processes.errors.form.error", count: @process.errors.count) %>
|
||||
</strong>
|
||||
</div>
|
||||
|
||||
<% end %>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 medium-4 column">
|
||||
<%= f.label :title %>
|
||||
</div>
|
||||
<div class="small-12 medium-8 column">
|
||||
<%= f.text_field :title,
|
||||
label: false %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 medium-4 column">
|
||||
<%= f.label :description %>
|
||||
</div>
|
||||
<div class="small-12 medium-8 column">
|
||||
<%= f.text_area :description,
|
||||
label: false,
|
||||
rows: 5 %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 medium-4 column">
|
||||
<%= f.label :target %>
|
||||
</div>
|
||||
<div class="small-12 medium-8 column">
|
||||
<%= f.text_area :target,
|
||||
label: false,
|
||||
rows: 5 %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 medium-4 column">
|
||||
<%= f.label :how_to_participate %>
|
||||
</div>
|
||||
<div class="small-12 medium-8 column">
|
||||
<%= f.text_area :how_to_participate,
|
||||
label: false,
|
||||
rows: 5 %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 medium-4 column">
|
||||
<%= f.label :additional_info %>
|
||||
</div>
|
||||
<div class="small-12 medium-8 column">
|
||||
<%= f.text_area :additional_info,
|
||||
label: false,
|
||||
rows: 10 %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 medium-4 column">
|
||||
<%= f.label :start_date %>
|
||||
</div>
|
||||
<div class="small-12 medium-8 column">
|
||||
<%= f.text_field :start_date,
|
||||
label: false,
|
||||
class: "js-calendar-full",
|
||||
id: "start_date" %>
|
||||
</div>
|
||||
<div class="small-12 medium-4 column">
|
||||
<%= f.label :end_date %>
|
||||
</div>
|
||||
<div class="small-12 medium-8 column">
|
||||
<%= f.text_field :end_date,
|
||||
label: false,
|
||||
class: "js-calendar-full",
|
||||
id: "end_date" %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 medium-4 column">
|
||||
<%= f.label :debate_start_date %>
|
||||
</div>
|
||||
<div class="small-12 medium-8 column">
|
||||
<%= f.text_field :debate_start_date,
|
||||
label: false,
|
||||
class: "js-calendar-full",
|
||||
id: "debate_start_date" %>
|
||||
</div>
|
||||
<div class="small-12 medium-4 column">
|
||||
<%= f.label :debate_end_date %>
|
||||
</div>
|
||||
<div class="small-12 medium-8 column">
|
||||
<%= f.text_field :debate_end_date,
|
||||
label: false,
|
||||
class: "js-calendar-full",
|
||||
id: "debate_end_date" %>
|
||||
</div>
|
||||
<div class="small-12 medium-4 column">
|
||||
<%= f.label :draft_publication_date %>
|
||||
</div>
|
||||
<div class="small-12 medium-8 column">
|
||||
<%= f.text_field :draft_publication_date,
|
||||
label: false,
|
||||
class: "js-calendar-full",
|
||||
id: "draft_publication_date" %>
|
||||
</div>
|
||||
<div class="small-12 medium-4 column">
|
||||
<%= f.label :allegations_start_date %>
|
||||
</div>
|
||||
<div class="small-12 medium-8 column">
|
||||
<%= f.text_field :allegations_start_date,
|
||||
label: false,
|
||||
class: "js-calendar-full",
|
||||
id: "allegations_start_date" %>
|
||||
</div>
|
||||
<div class="small-12 medium-4 column">
|
||||
<%= f.label :allegations_end_date %>
|
||||
</div>
|
||||
<div class="small-12 medium-8 column">
|
||||
<%= f.text_field :allegations_end_date,
|
||||
label: false,
|
||||
class: "js-calendar-full",
|
||||
id: "allegations_end_date" %>
|
||||
</div>
|
||||
<div class="small-12 medium-4 column">
|
||||
<%= f.label :final_publication_date %>
|
||||
</div>
|
||||
<div class="small-12 medium-8 column">
|
||||
<%= f.text_field :final_publication_date,
|
||||
label: false,
|
||||
class: "js-calendar-full",
|
||||
id: "final_publication_date" %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="actions small-12 medium-3 column">
|
||||
<%= f.submit(class: "button expanded", value: t("admin.legislation.processes.#{admin_submit_action(@process)}.submit_button")) %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
13
app/views/admin/legislation/processes/edit.html.erb
Normal file
13
app/views/admin/legislation/processes/edit.html.erb
Normal file
@@ -0,0 +1,13 @@
|
||||
<div class="legislation-process-edit row">
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= link_to admin_legislation_processes_path, class: "back" do %>
|
||||
<span class="icon-angle-left"></span>
|
||||
<%= t("admin.legislation.processes.edit.back") %>
|
||||
<% end %>
|
||||
|
||||
<h1><%= @process.title %></h1>
|
||||
|
||||
<%= render "form" %>
|
||||
</div>
|
||||
</div>
|
||||
33
app/views/admin/legislation/processes/index.html.erb
Normal file
33
app/views/admin/legislation/processes/index.html.erb
Normal file
@@ -0,0 +1,33 @@
|
||||
<%= link_to t("admin.legislation.processes.index.create"),
|
||||
new_admin_legislation_process_path, class: "button success float-right" %>
|
||||
|
||||
<h2 class="inline-block"><%= t("admin.legislation.processes.index.title") %></h2>
|
||||
|
||||
<%= render 'shared/filter_subnav', i18n_namespace: "admin.legislation.processes.index" %>
|
||||
|
||||
<h3><%= page_entries_info @processes %></h3>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th><%= t("admin.legislation.processes.process.title") %></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
<% @processes.each do |process| %>
|
||||
<tr id="<%= dom_id(process) %>">
|
||||
<td class="small-12 medium-9">
|
||||
<%= link_to process.title, edit_admin_legislation_process_path(process) %>
|
||||
</td>
|
||||
|
||||
<td class="text-right">
|
||||
<%= link_to t("admin.legislation.processes.index.edit"), edit_admin_legislation_process_path(process),
|
||||
class: 'edit-banner button hollow' %>
|
||||
|
||||
<%= link_to t("admin.legislation.processes.index.delete"), admin_legislation_process_path(process),
|
||||
method: :delete,
|
||||
class: 'button hollow alert' %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<%= paginate @processes %>
|
||||
13
app/views/admin/legislation/processes/new.html.erb
Normal file
13
app/views/admin/legislation/processes/new.html.erb
Normal file
@@ -0,0 +1,13 @@
|
||||
<div class="legislation-process-new row">
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= link_to admin_legislation_processes_path, class: "back" do %>
|
||||
<span class="icon-angle-left"></span>
|
||||
<%= t("admin.legislation.processes.new.back") %>
|
||||
<% end %>
|
||||
|
||||
<h1><%= t("admin.legislation.processes.new.title") %></h1>
|
||||
|
||||
<%= render "form" %>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user