Commit 42ccc689 by Mykhailo Makohin

add admin role and admin dashboard

parent 61c40a43
...@@ -24,6 +24,7 @@ gem 'bootstrap-sass' ...@@ -24,6 +24,7 @@ gem 'bootstrap-sass'
gem 'gmaps4rails' gem 'gmaps4rails'
gem 'remotipart' gem 'remotipart'
gem 'simple_form' gem 'simple_form'
gem 'activeadmin'
group :development, :test do group :development, :test do
gem 'byebug', platform: :mri gem 'byebug', platform: :mri
......
...@@ -24,6 +24,18 @@ GEM ...@@ -24,6 +24,18 @@ GEM
erubis (~> 2.7.0) erubis (~> 2.7.0)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3) rails-html-sanitizer (~> 1.0, >= 1.0.3)
activeadmin (2.0.0)
arbre (~> 1.2, >= 1.2.1)
formtastic (~> 3.1)
formtastic_i18n (~> 0.4)
inherited_resources (~> 1.7)
jquery-rails (~> 4.2)
kaminari (~> 1.0, >= 1.0.1)
railties (>= 5.0, < 6.0)
ransack (~> 2.1, >= 2.1.1)
sass (~> 3.4)
sprockets (>= 3.0, < 4.1)
sprockets-es6 (~> 0.9, >= 0.9.2)
activejob (5.0.7.2) activejob (5.0.7.2)
activesupport (= 5.0.7.2) activesupport (= 5.0.7.2)
globalid (>= 0.3.6) globalid (>= 0.3.6)
...@@ -38,9 +50,15 @@ GEM ...@@ -38,9 +50,15 @@ GEM
i18n (>= 0.7, < 2) i18n (>= 0.7, < 2)
minitest (~> 5.1) minitest (~> 5.1)
tzinfo (~> 1.1) tzinfo (~> 1.1)
arbre (1.2.1)
activesupport (>= 3.0.0)
arel (7.1.4) arel (7.1.4)
autoprefixer-rails (9.6.1.1) autoprefixer-rails (9.6.1.1)
execjs execjs
babel-source (5.8.35)
babel-transpiler (0.7.0)
babel-source (>= 4.0, < 6)
execjs (~> 2.0)
bcrypt (3.1.13) bcrypt (3.1.13)
bindex (0.8.1) bindex (0.8.1)
bootstrap-sass (3.4.1) bootstrap-sass (3.4.1)
...@@ -68,15 +86,26 @@ GEM ...@@ -68,15 +86,26 @@ GEM
faraday (0.15.4) faraday (0.15.4)
multipart-post (>= 1.2, < 3) multipart-post (>= 1.2, < 3)
ffi (1.11.1) ffi (1.11.1)
formtastic (3.1.5)
actionpack (>= 3.2.13)
formtastic_i18n (0.6.0)
globalid (0.4.2) globalid (0.4.2)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
gmaps4rails (2.1.2) gmaps4rails (2.1.2)
haml (5.1.2) haml (5.1.2)
temple (>= 0.8.0) temple (>= 0.8.0)
tilt tilt
has_scope (0.7.2)
actionpack (>= 4.1)
activesupport (>= 4.1)
hashie (3.6.0) hashie (3.6.0)
i18n (1.6.0) i18n (1.6.0)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
inherited_resources (1.10.0)
actionpack (>= 5.0, < 6.0)
has_scope (~> 0.6)
railties (>= 5.0, < 6.0)
responders (~> 2.0)
jbuilder (2.9.1) jbuilder (2.9.1)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
jquery-rails (4.3.5) jquery-rails (4.3.5)
...@@ -84,6 +113,18 @@ GEM ...@@ -84,6 +113,18 @@ GEM
railties (>= 4.2.0) railties (>= 4.2.0)
thor (>= 0.14, < 2.0) thor (>= 0.14, < 2.0)
jwt (2.2.1) jwt (2.2.1)
kaminari (1.1.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.1.1)
kaminari-activerecord (= 1.1.1)
kaminari-core (= 1.1.1)
kaminari-actionview (1.1.1)
actionview
kaminari-core (= 1.1.1)
kaminari-activerecord (1.1.1)
activerecord
kaminari-core (= 1.1.1)
kaminari-core (1.1.1)
listen (3.0.8) listen (3.0.8)
rb-fsevent (~> 0.9, >= 0.9.4) rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7) rb-inotify (~> 0.9, >= 0.9.7)
...@@ -124,6 +165,8 @@ GEM ...@@ -124,6 +165,8 @@ GEM
oauth2 (~> 1.1) oauth2 (~> 1.1)
omniauth (~> 1.9) omniauth (~> 1.9)
orm_adapter (0.5.0) orm_adapter (0.5.0)
polyamorous (2.3.0)
activerecord (>= 5.0)
puma (3.12.1) puma (3.12.1)
rack (2.0.7) rack (2.0.7)
rack-test (0.6.3) rack-test (0.6.3)
...@@ -152,6 +195,12 @@ GEM ...@@ -152,6 +195,12 @@ GEM
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
rake (12.3.3) rake (12.3.3)
ransack (2.3.0)
actionpack (>= 5.0)
activerecord (>= 5.0)
activesupport (>= 5.0)
i18n
polyamorous (= 2.3.0)
rb-fsevent (0.10.3) rb-fsevent (0.10.3)
rb-inotify (0.10.0) rb-inotify (0.10.0)
ffi (~> 1.0) ffi (~> 1.0)
...@@ -183,6 +232,10 @@ GEM ...@@ -183,6 +232,10 @@ GEM
sprockets (3.7.2) sprockets (3.7.2)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
rack (> 1, < 3) rack (> 1, < 3)
sprockets-es6 (0.9.2)
babel-source (>= 5.8.11)
babel-transpiler
sprockets (>= 3.0.0)
sprockets-rails (3.2.1) sprockets-rails (3.2.1)
actionpack (>= 4.0) actionpack (>= 4.0)
activesupport (>= 4.0) activesupport (>= 4.0)
...@@ -213,6 +266,7 @@ PLATFORMS ...@@ -213,6 +266,7 @@ PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
activeadmin
bootstrap-sass bootstrap-sass
byebug byebug
coffee-rails (~> 4.2) coffee-rails (~> 4.2)
......
ActiveAdmin.register_page "Dashboard" do
menu priority: 1, label: proc { I18n.t("active_admin.dashboard") }
content title: proc { I18n.t("active_admin.dashboard") } do
div class: "blank_slate_container", id: "dashboard_default_message" do
span class: "blank_slate" do
span I18n.t("active_admin.dashboard_welcome.welcome")
small I18n.t("active_admin.dashboard_welcome.call_to_action")
end
end
# Here is an example of a simple dashboard with columns and panels.
#
# columns do
# column do
# panel "Recent Posts" do
# ul do
# Post.recent(5).map do |post|
# li link_to(post.title, admin_post_path(post))
# end
# end
# end
# end
# column do
# panel "Info" do
# para "Welcome to ActiveAdmin."
# end
# end
# end
end # content
end
ActiveAdmin.register User do
permit_params :email, :role, :name, :location
end
//= require active_admin/base
// SASS variable overrides must be declared before loading up Active Admin's styles.
//
// To view the variables that Active Admin provides, take a look at
// `app/assets/stylesheets/active_admin/mixins/_variables.scss` in the
// Active Admin source.
//
// For example, to change the sidebar width:
// $sidebar-width: 242px;
// Active Admin's got SASS!
@import "active_admin/mixins";
@import "active_admin/base";
// Overriding any non-variable SASS must be done after the fact.
// For example, to change the default status-tag color:
//
// .status_tag { background: #6090DB; }
...@@ -5,7 +5,7 @@ class UsersController < ApplicationController ...@@ -5,7 +5,7 @@ class UsersController < ApplicationController
end end
def show def show
@user = resource @user = User.new
end end
def new def new
...@@ -39,7 +39,6 @@ class UsersController < ApplicationController ...@@ -39,7 +39,6 @@ class UsersController < ApplicationController
@user = resource @user = resource
@user.destroy @user.destroy
redirect_to users_path
end end
private private
...@@ -53,7 +52,7 @@ class UsersController < ApplicationController ...@@ -53,7 +52,7 @@ class UsersController < ApplicationController
end end
def user_params def user_params
params.require(:user).permit(:email, :name, :location) params.require(:user).permit(:email, :name, :location, :picture)
end end
end end
\ No newline at end of file
class User < ApplicationRecord class User < ApplicationRecord
attr_accessor :skip_password_validation attr_accessor :skip_password_validation
enum role: [:user, :admin]
after_initialize :set_default_role, :if => :new_record?
def set_default_role
self.role ||= :user
end
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable, :omniauthable, :recoverable, :rememberable, :validatable, :omniauthable,
......
...@@ -30,9 +30,6 @@ ...@@ -30,9 +30,6 @@
%a{:href => "#"}= t ("header.reports") %a{:href => "#"}= t ("header.reports")
%li %li
%a{:href => "#"} connectif %a{:href => "#"} connectif
%li
- if current_user
= link_to('Logout', destroy_user_session_path, method: :delete)
%ul.nav.nav-tabs.nav_btns %ul.nav.nav-tabs.nav_btns
%li.active %li.active
%a{"data-toggle" => "tab", :href => "#1"}= t 'header.people' %a{"data-toggle" => "tab", :href => "#1"}= t 'header.people'
...@@ -47,6 +44,19 @@ ...@@ -47,6 +44,19 @@
%div %div
%button.login_btn{"data-target" => "#modal3", "data-toggle" => "modal"} %button.login_btn{"data-target" => "#modal3", "data-toggle" => "modal"}
= image_tag ("login.png") = image_tag ("login.png")
- else
#sign_in
.dropdown.user_dropdown
%button#dropdownMenu1.dropdown-toggle{"aria-expanded" => "false", "aria-haspopup" => "true", "data-toggle" => "dropdown", :type => "button"}
%img{:alt => "Logo", :src => "", :width => "20"}/
%ul.dropdown-menu{"aria-labelledby" => "dropdownMenu1"}
- if current_user.admin?
%li
%a{:href => "/admin"} Адмін панель
%li
%a{:href => "#"} Профіль
%li
= link_to('Вийти', destroy_user_session_path, method: :delete)
.search_block .search_block
%input#search_field.search_field{:placeholder => "Пошук за іменем... ", :type => "text"}/ %input#search_field.search_field{:placeholder => "Пошук за іменем... ", :type => "text"}/
%button.search_btn %button.search_btn
......
...@@ -9,4 +9,5 @@ Bundler.require(*Rails.groups) ...@@ -9,4 +9,5 @@ Bundler.require(*Rails.groups)
module WarmCity module WarmCity
class Application < Rails::Application class Application < Rails::Application
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')] config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]
end
end end
Rails.application.routes.draw do Rails.application.routes.draw do
ActiveAdmin.routes(self)
devise_for :users, controllers: {omniauth_callbacks: "users/omniauth_callbacks",
registrations: "users"}
scope "(:locale)", locale: /en|uk/ do scope "(:locale)", locale: /en|uk/ do
root 'home#index' root 'home#index'
resources :users resources :users
end end
devise_for :users, controllers: {omniauth_callbacks: "users/omniauth_callbacks",
registrations: "users"}
end end
...@@ -4,6 +4,6 @@ class AddOmniauthToUsers < ActiveRecord::Migration[5.0] ...@@ -4,6 +4,6 @@ class AddOmniauthToUsers < ActiveRecord::Migration[5.0]
add_column :users, :uid, :string add_column :users, :uid, :string
add_column :users, :name, :string add_column :users, :name, :string
add_column :users, :location, :string add_column :users, :location, :string
add_column :users, :image, :text add_column :users, :picture, :text
end end
end end
class AddRoleToUsers < ActiveRecord::Migration[5.0]
def change
add_column :users, :role, :integer
end
end
class CreateActiveAdminComments < ActiveRecord::Migration[5.0]
def self.up
create_table :active_admin_comments do |t|
t.string :namespace
t.text :body
t.references :resource, polymorphic: true
t.references :author, polymorphic: true
t.timestamps
end
add_index :active_admin_comments, [:namespace]
end
def self.down
drop_table :active_admin_comments
end
end
...@@ -10,7 +10,21 @@ ...@@ -10,7 +10,21 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20190829110429) do ActiveRecord::Schema.define(version: 20190911111638) do
create_table "active_admin_comments", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "namespace"
t.text "body", limit: 65535
t.string "resource_type"
t.integer "resource_id"
t.string "author_type"
t.integer "author_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["author_type", "author_id"], name: "index_active_admin_comments_on_author_type_and_author_id", using: :btree
t.index ["namespace"], name: "index_active_admin_comments_on_namespace", using: :btree
t.index ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource_type_and_resource_id", using: :btree
end
create_table "users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| create_table "users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "email", default: "", null: false t.string "email", default: "", null: false
...@@ -24,7 +38,8 @@ ActiveRecord::Schema.define(version: 20190829110429) do ...@@ -24,7 +38,8 @@ ActiveRecord::Schema.define(version: 20190829110429) do
t.string "uid" t.string "uid"
t.string "name" t.string "name"
t.string "location" t.string "location"
t.text "image", limit: 65535 t.text "picture", limit: 65535
t.integer "role"
t.index ["email"], name: "index_users_on_email", unique: true, using: :btree t.index ["email"], name: "index_users_on_email", unique: true, using: :btree
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment