diff --git a/app/controllers/admin/officials_controller.rb b/app/controllers/admin/officials_controller.rb
new file mode 100644
index 000000000..023f0f7fc
--- /dev/null
+++ b/app/controllers/admin/officials_controller.rb
@@ -0,0 +1,32 @@
+class Admin::OfficialsController < Admin::BaseController
+
+ def index
+ @officials = User.officials.page(params[:page])
+ end
+
+ def search
+ @users = User.with_email(params[:email]).page(params[:page])
+ end
+
+ def edit
+ @user = User.find(params[:id])
+ end
+
+ def update
+ @user = User.find(params[:id])
+ @user.update(user_params)
+ redirect_to admin_officials_path, notice: t("admin.officials.flash.official_updated")
+ end
+
+ def destroy
+ @official = User.officials.find(params[:id])
+ @official.remove_official_position!
+ redirect_to admin_officials_path, notice: t("admin.officials.flash.official_destroyed")
+ end
+
+ private
+ def user_params
+ params.require(:user).permit(:official_position, :official_level)
+ end
+
+end
\ No newline at end of file
diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb
new file mode 100644
index 000000000..b369d2cbc
--- /dev/null
+++ b/app/controllers/admin/settings_controller.rb
@@ -0,0 +1,17 @@
+class Admin::SettingsController < Admin::BaseController
+
+ def index
+ @settings = Setting.all
+ end
+
+ def update
+ @setting = Setting.find(params[:id])
+ @setting.update(settings_params)
+ redirect_to admin_settings_path, notice: t("admin.settings.flash.updated")
+ end
+
+ private
+ def settings_params
+ params.require(:setting).permit(:value)
+ end
+end
\ No newline at end of file
diff --git a/app/controllers/admin/tags_controller.rb b/app/controllers/admin/tags_controller.rb
index ecacdbdb2..03cfeb64f 100644
--- a/app/controllers/admin/tags_controller.rb
+++ b/app/controllers/admin/tags_controller.rb
@@ -1,5 +1,4 @@
class Admin::TagsController < Admin::BaseController
- layout 'admin'
before_action :find_tag, only: [:update, :destroy]
respond_to :html, :js
diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb
index a7fef3aa2..09d325e08 100644
--- a/app/helpers/admin_helper.rb
+++ b/app/helpers/admin_helper.rb
@@ -4,6 +4,14 @@ module AdminHelper
render "/#{namespace}/menu"
end
+ def official_level_options
+ options = []
+ (0..5).each do |i|
+ options << [[t("admin.officials.level_#{i}"), Setting.value_for("official_level_#{i}_name")].compact.join(': '), i]
+ end
+ options
+ end
+
private
def namespace
diff --git a/app/models/setting.rb b/app/models/setting.rb
new file mode 100644
index 000000000..1a52ebe60
--- /dev/null
+++ b/app/models/setting.rb
@@ -0,0 +1,7 @@
+class Setting < ActiveRecord::Base
+ default_scope { order(key: :desc) }
+
+ def self.value_for(key)
+ where(key: key).pluck(:value).first
+ end
+end
\ No newline at end of file
diff --git a/app/models/user.rb b/app/models/user.rb
index 205a6bf5f..16d1de154 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -8,6 +8,9 @@ class User < ActiveRecord::Base
validates :first_name, presence: true, unless: :use_nickname?
validates :last_name, presence: true, unless: :use_nickname?
validates :nickname, presence: true, if: :use_nickname?
+ validates :official_level, inclusion: {in: 0..5}
+
+ scope :officials, -> { where("official_level > 0") }
def name
use_nickname? ? nickname : "#{first_name} #{last_name}"
@@ -25,4 +28,21 @@ class User < ActiveRecord::Base
def moderator?
@is_moderator ||= Moderator.where(user_id: id).exists?
end
+
+ def official?
+ official_level && official_level > 0
+ end
+
+ def add_official_position!(position, level)
+ return if position.blank? || level.blank?
+ update official_position: position, official_level: level.to_i
+ end
+
+ def remove_official_position!
+ update official_position: nil, official_level: 0
+ end
+
+ def self.with_email(e)
+ e.present? ? where(email: e) : none
+ end
end
diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb
index 8ea2b27af..88410238b 100644
--- a/app/views/admin/_menu.html.erb
+++ b/app/views/admin/_menu.html.erb
@@ -1,5 +1,7 @@
diff --git a/app/views/admin/comments/index.html.erb b/app/views/admin/comments/index.html.erb
index 1555fda0c..796ba5ebc 100644
--- a/app/views/admin/comments/index.html.erb
+++ b/app/views/admin/comments/index.html.erb
@@ -1,14 +1,12 @@
-
-
<%= t("admin.debates.index.title") %>
+
<%= t("admin.debates.index.title") %>
+
+
+
<%= @debate.title %>
+
<%= @debate.description %>
-
<%= @debate.title %>
-
<%= @debate.description %>
-
-
- <%= link_to t('admin.actions.restore'), restore_admin_debate_path(@debate),
- method: :put, data: { confirm: t('admin.actions.confirm') } %>
-
+ <%= link_to t('admin.actions.restore'), restore_admin_debate_path(@debate),
+ method: :put, data: { confirm: t('admin.actions.confirm') } %>
\ No newline at end of file
diff --git a/app/views/admin/officials/edit.html.erb b/app/views/admin/officials/edit.html.erb
new file mode 100644
index 000000000..b986df2b5
--- /dev/null
+++ b/app/views/admin/officials/edit.html.erb
@@ -0,0 +1,14 @@
+
<%= t("admin.officials.edit.title") %>
+
+<%= @user.name %> (<%= @user.email %>)
+<%= form_for @user, url: admin_official_path(@user) do |f| %>
+ <%= f.text_field :official_position %>
+ <%= f.select :official_level, official_level_options %>
+ <%= f.submit %>
+
+ <% if @user.official? %>
+ <%= link_to t("admin.officials.edit.destroy"), admin_official_path(@user), method: :delete, class: 'button tiny alert' %>
+ <% else %>
+ <%= link_to t("admin.officials.edit.cancel"), admin_officials_path, class: 'button tiny alert' %>
+ <% end %>
+<% end %>
\ No newline at end of file
diff --git a/app/views/admin/officials/index.html.erb b/app/views/admin/officials/index.html.erb
new file mode 100644
index 000000000..d0a98a963
--- /dev/null
+++ b/app/views/admin/officials/index.html.erb
@@ -0,0 +1,25 @@
+
<%= t("admin.officials.index.title") %>
+
+
+<%= form_for(User.new, url: search_admin_officials_path, as: :user, method: :get) do |f| %>
+ <%= text_field_tag :email, "", label: false, placeholder: t("admin.officials.index.search_email_placeholder") %>
+ <%= f.submit t("admin.officials.index.search") %>
+<% end %>
+
+
+
+<%= page_entries_info @officials %>
+
+
+
+<% @officials.each do |official| %>
+ <%= link_to official.name, edit_admin_official_path(official) %>
+ <%= official.official_position %>
+ <%= t("admin.officials.level_#{official.official_level}") %>
+
+<% end %>
+
+
+
+<%= paginate @officials %>
+
\ No newline at end of file
diff --git a/app/views/admin/officials/search.html.erb b/app/views/admin/officials/search.html.erb
new file mode 100644
index 000000000..9549c7ad0
--- /dev/null
+++ b/app/views/admin/officials/search.html.erb
@@ -0,0 +1,21 @@
+
<%= t("admin.officials.search.title") %>
+
+
+<%= form_for(User.new, url: search_admin_officials_path, as: :user, method: :get) do |f| %>
+ <%= text_field_tag :email, "", label: false, placeholder: t("admin.officials.index.search_email_placeholder") %>
+ <%= f.submit t("admin.officials.search.search") %>
+<% end %>
+
+
+
+<%= page_entries_info @users %>
+
+
+
+<% @users.each do |user| %>
+ <%= link_to user.name, edit_admin_official_path(user) %>
+ <%= user.official_position %>
+ <%= t("admin.officials.level_#{user.official_level}") %>
+ <%= link_to user.official? ? t("admin.officials.search.edit_official") : t("admin.officials.search.make_official"), edit_admin_official_path(user) %>
+<% end %>
+
\ No newline at end of file
diff --git a/app/views/admin/settings/index.html.erb b/app/views/admin/settings/index.html.erb
new file mode 100644
index 000000000..321b307d0
--- /dev/null
+++ b/app/views/admin/settings/index.html.erb
@@ -0,0 +1,15 @@
+
<%= t("admin.settings.index.title") %>
+
+
+ <% @settings.each do |setting| %>
+ -
+ <%= setting.key.classify %>
+
+ <%= form_for(setting, url: admin_setting_path(setting), html: { id: "edit_#{dom_id(setting)}"}) do |f| %>
+ <%= f.text_field :value, label: false, id: dom_id(setting) %>
+ <%= f.submit(class: "button radius tiny") %>
+ <% end %>
+
+
+ <% end %>
+
\ No newline at end of file
diff --git a/app/views/admin/tags/index.html.erb b/app/views/admin/tags/index.html.erb
index 4dbbed167..f272df1f3 100644
--- a/app/views/admin/tags/index.html.erb
+++ b/app/views/admin/tags/index.html.erb
@@ -1,29 +1,26 @@
-
-
<%= t("admin.tags.index.add_tag") %>
+
<%= t("admin.tags.index.add_tag") %>
- <%= form_for(@tag, url: admin_tags_path, as: :tag) do |f| %>
- <%= f.text_field :name, placeholder: t("admin.tags.name.placeholder") %>
- <%= f.check_box :featured, label: false %>
- <%= t("admin.tags.mark_as_featured") %>
- <%= f.submit(class: "button radius small") %>
+<%= form_for(@tag, url: admin_tags_path, as: :tag) do |f| %>
+ <%= f.text_field :name, placeholder: t("admin.tags.name.placeholder") %>
+ <%= f.check_box :featured, label: false %>
+ <%= t("admin.tags.mark_as_featured") %>
+ <%= f.submit(class: "button radius small") %>
+<% end %>
+
+
<%= t("admin.tags.index.title") %>
+
+
+ <% @tags.each do |tag| %>
+ -
+ <%= tag.name %>
+
+ <%= form_for(tag, url: admin_tag_path(tag), as: :tag, html: { id: "edit_tag_#{tag.id}"}) do |f| %>
+ <%= f.check_box :featured, label: false, id: "tag_featured_#{tag.id}" %>
+ <%= t("admin.tags.mark_as_featured") %>
+ <%= f.submit(class: "button radius tiny") %>
+ <%= link_to t("admin.tags.destroy"), admin_tag_path(tag), method: :delete, class: 'button tiny alert' %>
+ <% end %>
+
+
<% end %>
-
-
- <%= t("admin.tags.index.title") %>
-
-
- <% @tags.each do |tag| %>
- -
- <%= tag.name %>
-
- <%= form_for(tag, url: admin_tag_path(tag), as: :tag, html: { id: "edit_tag_#{tag.id}"}) do |f| %>
- <%= f.check_box :featured, label: false, id: "tag_featured_#{tag.id}" %>
- <%= t("admin.tags.mark_as_featured") %>
- <%= f.submit(class: "button radius tiny") %>
- <%= link_to t("admin.tags.destroy"), admin_tag_path(tag), method: :delete, class: 'button tiny alert' %>
- <% end %>
-
-
- <% end %>
-
-
+
\ No newline at end of file
diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb
index c754951f2..1d4157a8f 100644
--- a/app/views/layouts/admin.html.erb
+++ b/app/views/layouts/admin.html.erb
@@ -27,7 +27,10 @@
<%= side_menu %>
- <%= yield %>
+