Admin interface #6
32
app/assets/stylesheets/management/_record_table.css.scss
Normal file
32
app/assets/stylesheets/management/_record_table.css.scss
Normal file
@ -0,0 +1,32 @@
|
||||
.record-table {
|
||||
@extend .table;
|
||||
|
||||
td {
|
||||
vertical-align: middle !important;
|
||||
}
|
||||
|
||||
.actions {
|
||||
@extend .pull-right;
|
||||
@extend .btn-group;
|
||||
white-space: nowrap;
|
||||
|
||||
a {
|
||||
@extend .btn;
|
||||
@extend .btn-default;
|
||||
}
|
||||
}
|
||||
|
||||
.toggle {
|
||||
a {
|
||||
@extend .btn;
|
||||
}
|
||||
|
||||
a.checked {
|
||||
@extend .btn-success;
|
||||
}
|
||||
|
||||
a.unchecked {
|
||||
@extend .btn-primary;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
//= require_directory .
|
||||
|
||||
@import "bootstrap-sprockets";
|
||||
@import "bootswatch/simplex/variables";
|
||||
@import "bootstrap";
|
||||
@import "bootswatch/simplex/bootswatch";
|
||||
@import "navbar";
|
||||
@import "record_table";
|
20
app/controllers/management/users_controller.rb
Normal file
20
app/controllers/management/users_controller.rb
Normal file
@ -0,0 +1,20 @@
|
||||
module Management
|
||||
class UsersController < ManagementController
|
||||
before_action :assign_user, only: [:toggle_admin]
|
||||
|
||||
def index
|
||||
@users = User.all
|
||||
end
|
||||
|
||||
def toggle_admin
|
||||
@user.admin = !@user.admin
|
||||
@user.save
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def assign_user
|
||||
@user = User.find params[:id]
|
||||
end
|
||||
end
|
||||
end
|
@ -21,7 +21,7 @@ html
|
||||
.navbar-collapse.collapse
|
||||
ul.nav.navbar-nav
|
||||
li.active = link_to 'Home', root_path
|
||||
li = link_to 'Users', root_path
|
||||
li = link_to 'Users', management_users_path
|
||||
div.container
|
||||
== yield
|
||||
= javascript_include_tag "management/application"
|
||||
|
17
app/views/management/users/_user.html.slim
Normal file
17
app/views/management/users/_user.html.slim
Normal file
@ -0,0 +1,17 @@
|
||||
tr id="user-#{user.id}"
|
||||
td = user.email
|
||||
td = user.speaker_profile.try(:first_name) or '-'
|
||||
td = user.speaker_profile.try(:last_name) or '-'
|
||||
td
|
||||
- if user.admin?
|
||||
span.toggle
|
||||
= link_to glyph(:check), toggle_admin_management_user_path(user), remote: true, method: :post, data: {confirm: t(:are_you_sure)}, class: 'checked'
|
||||
- else
|
||||
span.toggle
|
||||
= link_to glyph(:unchecked), toggle_admin_management_user_path(user), remote: true, method: :post, data: {confirm: t(:are_you_sure)}, class: 'unchecked'
|
||||
td
|
||||
.actions
|
||||
= link_to management_user_path(user), title: t(:edit)
|
||||
= glyph(:share)
|
||||
= link_to edit_management_user_path(user), title: t(:edit)
|
||||
= glyph(:edit)
|
14
app/views/management/users/index.html.slim
Normal file
14
app/views/management/users/index.html.slim
Normal file
@ -0,0 +1,14 @@
|
||||
.row
|
||||
.panel.panel-primary
|
||||
.panel-heading
|
||||
h3.panel-title = User.model_name.human(count: 2)
|
||||
table.record-table
|
||||
thead
|
||||
tr
|
||||
th = User.human_attribute_name(:email)
|
||||
th = SpeakerProfile.human_attribute_name(:first_name)
|
||||
th = SpeakerProfile.human_attribute_name(:last_name)
|
||||
th = SpeakerProfile.human_attribute_name(:admin)
|
||||
th
|
||||
tbody
|
||||
= render @users
|
1
app/views/management/users/toggle_admin.js.erb
Normal file
1
app/views/management/users/toggle_admin.js.erb
Normal file
@ -0,0 +1 @@
|
||||
$('#user-<%= @user.id %>').replaceWith('<%= j render @user %>');
|
2
config/locales/management.bg.yml
Normal file
2
config/locales/management.bg.yml
Normal file
@ -0,0 +1,2 @@
|
||||
bg:
|
||||
are_you_sure: Сигурен ли си?
|
2
config/locales/management.en.yml
Normal file
2
config/locales/management.en.yml
Normal file
@ -0,0 +1,2 @@
|
||||
en:
|
||||
are_you_sure: Are you sure?
|
@ -4,8 +4,13 @@ Rails.application.routes.draw do
|
||||
|
||||
devise_for :users, controllers: {registrations: 'registrations', sessions: 'sessions'}
|
||||
|
||||
scope :management, module: :management do
|
||||
namespace :management do
|
||||
get '/', to: 'home#index'
|
||||
resources :users do
|
||||
member do
|
||||
post 'toggle_admin'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
root 'home#index'
|
||||
|
12
spec/controllers/management/users_controller_spec.rb
Normal file
12
spec/controllers/management/users_controller_spec.rb
Normal file
@ -0,0 +1,12 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Management::UsersController, :type => :controller do
|
||||
|
||||
describe "GET index" do
|
||||
it "returns http success" do
|
||||
get :index
|
||||
expect(response).to be_success
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue
Block a user