Add description field to administrator users like evaluators description
This commit is contained in:
@@ -28,4 +28,22 @@ class Admin::AdministratorsController < Admin::BaseController
|
||||
|
||||
redirect_to admin_administrators_path
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
if @administrator.update(update_administrator_params)
|
||||
notice = t("admin.administrators.form.updated")
|
||||
redirect_to admin_administrators_path, notice: notice
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_administrator_params
|
||||
params.require(:administrator).permit(:description)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -77,7 +77,9 @@ module AdminHelper
|
||||
end
|
||||
|
||||
def admin_select_options
|
||||
Administrator.all.order("users.username asc").includes(:user).collect { |v| [ v.name, v.id ] }
|
||||
Administrator.with_user
|
||||
.collect { |v| [ v.description_or_name, v.id ] }
|
||||
.sort_by { |a| a[0] }
|
||||
end
|
||||
|
||||
def admin_submit_action(resource)
|
||||
|
||||
@@ -51,7 +51,7 @@ module Abilities
|
||||
can :comment_as_administrator, [Debate, Comment, Proposal, Poll::Question, Budget::Investment,
|
||||
Legislation::Question, Legislation::Proposal, Legislation::Annotation, Topic]
|
||||
|
||||
can [:search, :create, :index, :destroy], ::Administrator
|
||||
can [:search, :create, :index, :destroy, :edit, :update], ::Administrator
|
||||
can [:search, :create, :index, :destroy], ::Moderator
|
||||
can [:search, :show, :edit, :update, :create, :index, :destroy, :summary], ::Valuator
|
||||
can [:search, :create, :index, :destroy], ::Manager
|
||||
|
||||
@@ -3,4 +3,14 @@ class Administrator < ApplicationRecord
|
||||
delegate :name, :email, :name_and_email, to: :user
|
||||
|
||||
validates :user_id, presence: true, uniqueness: true
|
||||
|
||||
scope :with_user, -> { includes(:user) }
|
||||
|
||||
def description_or_name
|
||||
description.presence || name
|
||||
end
|
||||
|
||||
def description_or_name_and_email
|
||||
"#{description_or_name} (#{email})"
|
||||
end
|
||||
end
|
||||
|
||||
15
app/views/admin/administrators/edit.html.erb
Normal file
15
app/views/admin/administrators/edit.html.erb
Normal file
@@ -0,0 +1,15 @@
|
||||
<%= back_link_to admin_administrators_path %>
|
||||
|
||||
<h2><%= t("admin.administrators.form.edit_title") %></h2>
|
||||
|
||||
<div class="callout highlight">
|
||||
<strong><%= @administrator.name %></strong><br>
|
||||
<%= @administrator.email %>
|
||||
</div>
|
||||
|
||||
<div class="margin-top">
|
||||
<%= form_for [:admin, @administrator] do |f| %>
|
||||
<%= f.text_field :description %>
|
||||
<%= f.submit class: "button success" %>
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -11,6 +11,7 @@
|
||||
<th scope="col" class="text-center"><%= t("admin.administrators.index.id") %></th>
|
||||
<th scope="col"><%= t("admin.administrators.index.name") %></th>
|
||||
<th scope="col"><%= t("admin.administrators.index.email") %></th>
|
||||
<th scope="col"><%= t("admin.administrators.index.description") %></th>
|
||||
<th scope="col" class="small-3"><%= t("admin.shared.actions") %></th>
|
||||
</thead>
|
||||
<% @administrators.each do |administrator| %>
|
||||
@@ -24,13 +25,18 @@
|
||||
<td>
|
||||
<%= administrator.email %>
|
||||
</td>
|
||||
<td>
|
||||
<%= administrator.description %>
|
||||
</td>
|
||||
<td>
|
||||
<% if administrator.persisted? %>
|
||||
<%= link_to t("admin.actions.edit"),
|
||||
edit_admin_administrator_path(administrator),
|
||||
class: "button hollow" %>
|
||||
<%= link_to t("admin.administrators.administrator.delete"),
|
||||
admin_administrator_path(administrator),
|
||||
method: :delete,
|
||||
class: "button hollow alert expanded"
|
||||
%>
|
||||
class: "button hollow alert" %>
|
||||
<% else %>
|
||||
<%= link_to t("admin.administrators.administrator.add"),
|
||||
{ controller: "admin/administrators", action: :create,
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
</td>
|
||||
<td class="small">
|
||||
<% if investment.administrator.present? %>
|
||||
<span title="<%= t("admin.budget_investments.index.assigned_admin") %>">
|
||||
<%= investment.administrator.name %>
|
||||
</span>
|
||||
<span title="<%= t("admin.budget_investments.index.assigned_admin") %>">
|
||||
<%= investment.administrator.description_or_name %>
|
||||
</span>
|
||||
<% else %>
|
||||
<%= t("admin.budget_investments.index.no_admin_assigned") %>
|
||||
<% end %>
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
|
||||
<div class="small-12 medium-6">
|
||||
<%= f.select(:administrator_id,
|
||||
@admins.collect{ |a| [a.name_and_email, a.id ] },
|
||||
@admins.collect{ |a| [a.description_or_name_and_email, a.id ] },
|
||||
{ include_blank: t("admin.budget_investments.edit.undefined") }) %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user