From 42d155e1e183515fe9b7fdb5dcdc4e2a2def52cc Mon Sep 17 00:00:00 2001 From: Alexander Kravets Date: Mon, 16 Nov 2015 12:10:48 +0200 Subject: [PATCH] Refactor Admin to AdminUser. --- Gemfile.lock | 2 +- .../{admins.coffee => admin_users.coffee} | 8 ++--- .../admin/admin_users_controller.rb | 5 +++ app/controllers/admin/admins_controller.rb | 3 -- app/mailers/admin_mailer.rb | 3 -- app/mailers/admin_user_mailer.rb | 3 ++ app/models/{admin.rb => admin_user.rb} | 34 ++++++------------- app/views/ants/_profile.html.erb | 9 ++--- lib/ants/version.rb | 2 +- 9 files changed, 30 insertions(+), 39 deletions(-) rename app/assets/javascripts/ants/{admins.coffee => admin_users.coffee} (89%) create mode 100644 app/controllers/admin/admin_users_controller.rb delete mode 100644 app/controllers/admin/admins_controller.rb delete mode 100644 app/mailers/admin_mailer.rb create mode 100644 app/mailers/admin_user_mailer.rb rename app/models/{admin.rb => admin_user.rb} (81%) diff --git a/Gemfile.lock b/Gemfile.lock index 8b91a24..a38ef29 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - ants (0.2.8) + ants (0.3.0) devise mongoid (>= 4.0) mongoid-slug (>= 4.0.0) diff --git a/app/assets/javascripts/ants/admins.coffee b/app/assets/javascripts/ants/admin_users.coffee similarity index 89% rename from app/assets/javascripts/ants/admins.coffee rename to app/assets/javascripts/ants/admin_users.coffee index b2aa300..2210278 100644 --- a/app/assets/javascripts/ants/admins.coffee +++ b/app/assets/javascripts/ants/admin_users.coffee @@ -1,4 +1,4 @@ -class @AntsAdmins +class @AntsAdminUsers constructor: (title='Admins', apiPath='/admin') -> config = title: title @@ -6,7 +6,7 @@ class @AntsAdmins arrayStore: new RailsArrayStore({ resource: 'admin' - path: "#{ apiPath }/admins" + path: "#{ apiPath }/admin_users" sortBy: 'name' searchable: true }) @@ -47,7 +47,7 @@ class @AntsAdmins if input.object input.$el.removeClass 'input-required' input.$label.html 'Change Password' - input.config.placeholder = 'Type new password here to update the current one' + input.config.placeholder = 'Type new password & hit Save' input._add_placeholder() - return config \ No newline at end of file + return config diff --git a/app/controllers/admin/admin_users_controller.rb b/app/controllers/admin/admin_users_controller.rb new file mode 100644 index 0000000..14e517d --- /dev/null +++ b/app/controllers/admin/admin_users_controller.rb @@ -0,0 +1,5 @@ +module Admin + class AdminUsersController < Admin::BaseController + mongosteen + end +end diff --git a/app/controllers/admin/admins_controller.rb b/app/controllers/admin/admins_controller.rb deleted file mode 100644 index b10fb24..0000000 --- a/app/controllers/admin/admins_controller.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Admin::AdminsController < Admin::BaseController - mongosteen -end diff --git a/app/mailers/admin_mailer.rb b/app/mailers/admin_mailer.rb deleted file mode 100644 index 376eaa8..0000000 --- a/app/mailers/admin_mailer.rb +++ /dev/null @@ -1,3 +0,0 @@ -class AdminMailer < Devise::Mailer - -end diff --git a/app/mailers/admin_user_mailer.rb b/app/mailers/admin_user_mailer.rb new file mode 100644 index 0000000..c5961c9 --- /dev/null +++ b/app/mailers/admin_user_mailer.rb @@ -0,0 +1,3 @@ +class AdminUserMailer < Devise::Mailer + +end diff --git a/app/models/admin.rb b/app/models/admin_user.rb similarity index 81% rename from app/models/admin.rb rename to app/models/admin_user.rb index 8e7523e..533fa8d 100644 --- a/app/models/admin.rb +++ b/app/models/admin_user.rb @@ -1,4 +1,4 @@ -class Admin +class AdminUser include Mongoid::Document include Mongoid::Timestamps include Mongoid::Search @@ -8,7 +8,6 @@ class Admin field :name field :permissions, type: Array - # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :registerable and :omniauthable devise :database_authenticatable, @@ -36,56 +35,45 @@ class Admin field :current_sign_in_ip, type: String field :last_sign_in_ip, type: String - ## Validations validates :name, presence: true - ## Search search_in :name, :email ## Scopes default_scope -> { asc(:name) } - ## Indexes index({ name: 1 }) index({ email: 1 }, { unique: true }) - ## Helpers def devise_mailer - AdminMailer + AdminUserMailer end - def _list_item_title name.empty? ? email : name end - def _list_item_subtitle last_sign_in_ago end - def _list_item_thumbnail - "//www.gravatar.com/avatar/#{ Digest::MD5.hexdigest(email) }?s=80&d=retro&r=g" + hex = Digest::MD5.hexdigest(email) + "//www.gravatar.com/avatar/#{hex}?s=80&d=retro&r=g" end - private - def last_sign_in_ago - if current_sign_in_at - 'Seen ' + ActionController::Base.helpers.time_ago_in_words(current_sign_in_at) + ' ago' - else - 'Never seen' - end + def last_sign_in_ago + if current_sign_in_at + time = ActionController::Base.helpers.time_ago_in_words(current_sign_in_at) + "Seen #{time} ago" + else + "Never seen" end - + end end - - - - diff --git a/app/views/ants/_profile.html.erb b/app/views/ants/_profile.html.erb index 19700e7..3df7ab1 100644 --- a/app/views/ants/_profile.html.erb +++ b/app/views/ants/_profile.html.erb @@ -1,9 +1,10 @@ diff --git a/lib/ants/version.rb b/lib/ants/version.rb index 95b341e..c5a075b 100644 --- a/lib/ants/version.rb +++ b/lib/ants/version.rb @@ -1,3 +1,3 @@ module Ants - VERSION = "0.2.8" + VERSION = "0.3.0" end