Skip to content

Commit

Permalink
Refactor Admin to AdminUser.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkravets committed Nov 16, 2015
1 parent 994fd2f commit 42d155e
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 39 deletions.
2 changes: 1 addition & 1 deletion 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)
Expand Down
@@ -1,12 +1,12 @@
class @AntsAdmins
class @AntsAdminUsers
constructor: (title='Admins', apiPath='/admin') ->
config =
title: title
showWithParent: true

arrayStore: new RailsArrayStore({
resource: 'admin'
path: "#{ apiPath }/admins"
path: "#{ apiPath }/admin_users"
sortBy: 'name'
searchable: true
})
Expand Down Expand Up @@ -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
return config
5 changes: 5 additions & 0 deletions app/controllers/admin/admin_users_controller.rb
@@ -0,0 +1,5 @@
module Admin
class AdminUsersController < Admin::BaseController
mongosteen
end
end
3 changes: 0 additions & 3 deletions app/controllers/admin/admins_controller.rb

This file was deleted.

3 changes: 0 additions & 3 deletions app/mailers/admin_mailer.rb

This file was deleted.

3 changes: 3 additions & 0 deletions app/mailers/admin_user_mailer.rb
@@ -0,0 +1,3 @@
class AdminUserMailer < Devise::Mailer

end
34 changes: 11 additions & 23 deletions app/models/admin.rb → app/models/admin_user.rb
@@ -1,4 +1,4 @@
class Admin
class AdminUser
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Search
Expand All @@ -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,
Expand Down Expand Up @@ -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




9 changes: 5 additions & 4 deletions app/views/ants/_profile.html.erb
@@ -1,9 +1,10 @@
<div class="sidebar-profile" style="display:none;">
<%= image_tag current_admin._list_item_thumbnail %>
<% user = current_admin_user %>
<%= image_tag user._list_item_thumbnail %>
<% name = (current_admin.name.presence || "").strip.split(' ').first %>
<% path = "#/settings/admins/view/#{current_admin.id}" %>
<% name = (user.name.presence || "").strip.split(' ').first %>
<% path = "#/settings/admins/view/#{user.id}" %>
<%= link_to name, path %>
<%= link_to "Sign out", destroy_admin_session_path, method: :delete %>
<%= link_to "Sign out", destroy_admin_user_session_path, method: :delete %>
</div>
2 changes: 1 addition & 1 deletion lib/ants/version.rb
@@ -1,3 +1,3 @@
module Ants
VERSION = "0.2.8"
VERSION = "0.3.0"
end

0 comments on commit 42d155e

Please sign in to comment.