From 6b24c375cbf39ad407b504d1ac386566a1571c76 Mon Sep 17 00:00:00 2001
From: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Date: Wed, 13 Feb 2013 17:28:28 +0200
Subject: [PATCH] style admin -> users page. Search by username too

---
 app/models/user.rb                    |   2 +-
 app/views/admin/users/index.html.haml | 108 +++++++++++++-------------
 2 files changed, 57 insertions(+), 53 deletions(-)

diff --git a/app/models/user.rb b/app/models/user.rb
index 8c1a8b42b..3ad8f1c33 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -138,7 +138,7 @@ class User < ActiveRecord::Base
     end
 
     def search query
-      where("name LIKE :query or email LIKE :query", query: "%#{query}%")
+      where("name LIKE :query OR email LIKE :query OR username LIKE :query", query: "%#{query}%")
     end
   end
 
diff --git a/app/views/admin/users/index.html.haml b/app/views/admin/users/index.html.haml
index 87d6309ae..f5bb8b068 100644
--- a/app/views/admin/users/index.html.haml
+++ b/app/views/admin/users/index.html.haml
@@ -3,56 +3,60 @@
   = link_to 'New User', new_admin_user_path, class: "btn btn-small pull-right"
 %br
 
-= form_tag admin_users_path, method: :get, class: 'form-inline' do
-  = text_field_tag :name, params[:name], class: "xlarge"
-  = submit_tag "Search", class: "btn submit btn-primary"
-%ul.nav.nav-tabs
-  %li{class: "#{'active' unless params[:filter]}"}
-    = link_to admin_users_path do
-      Active
-      %span.badge= User.active.count
-  %li{class: "#{'active' if params[:filter] == "admins"}"}
-    = link_to admin_users_path(filter: "admins") do
-      Admins
-      %span.badge= User.admins.count
-  %li{class: "#{'active' if params[:filter] == "blocked"}"}
-    = link_to admin_users_path(filter: "blocked") do
-      Blocked
-      %span.badge= User.blocked.count
-  %li{class: "#{'active' if params[:filter] == "wop"}"}
-    = link_to admin_users_path(filter: "wop") do
-      Without projects
-      %span.badge= User.without_projects.count
+.row
+  .span3
+    .admin-filter
+      = form_tag admin_users_path, method: :get, class: 'form-inline' do
+        = search_field_tag :name, params[:name], placeholder: 'Name, email or username', class: 'search-text-input span2'
+        = button_tag type: 'submit', class: 'btn' do
+          %i.icon-search
+      %ul.nav.nav-pills.nav-stacked
+        %li{class: "#{'active' unless params[:filter]}"}
+          = link_to admin_users_path do
+            Active
+            %small.pull-right= User.active.count
+        %li{class: "#{'active' if params[:filter] == "admins"}"}
+          = link_to admin_users_path(filter: "admins") do
+            Admins
+            %small.pull-right= User.admins.count
+        %li{class: "#{'active' if params[:filter] == "blocked"}"}
+          = link_to admin_users_path(filter: "blocked") do
+            Blocked
+            %small.pull-right= User.blocked.count
+        %li{class: "#{'active' if params[:filter] == "wop"}"}
+          = link_to admin_users_path(filter: "wop") do
+            Without projects
+            %small.pull-right= User.without_projects.count
+      %hr
+      = link_to 'Reset', admin_users_path, class: "btn btn-cancel"
 
-%table
-  %thead
-    %tr
-      %th Admin
-      %th
-        Name
-        %i.icon-sort-down
-      %th Username
-      %th Email
-      %th Projects
-      %th Edit
-      %th.cred Danger Zone!
-
-  - @admin_users.each do |user|
-    %tr
-      %td= check_box_tag "admin",   1, user.admin, disabled: :disabled
-      %td= link_to user.name, [:admin, user]
-      %td= user.username
-      %td= user.email
-      %td= user.users_projects.count
-      %td= link_to 'Edit', edit_admin_user_path(user), id: "edit_#{dom_id(user)}", class: "btn btn-small"
-      %td.bgred
-        - if user == current_user
-          %span.cred It's you!
-        - else
-          - if user.blocked
-            = link_to 'Unblock', unblock_admin_user_path(user), method: :put, class: "btn btn-small success"
-          - else
-            = link_to 'Block', block_admin_user_path(user), confirm: 'USER WILL BE BLOCKED! Are you sure?', method: :put, class: "btn btn-small btn-remove"
-          = link_to 'Destroy', [:admin, user], confirm: "USER #{user.name} WILL BE REMOVED! Are you sure?", method: :delete, class: "btn btn-small btn-remove"
-
-= paginate @admin_users, theme: "admin"
+  .span9
+    .ui-box
+      %h5.title
+        Users (#{@admin_users.total_count})
+      %ul.well-list
+        - @admin_users.each do |user|
+          %li
+            - if user.blocked?
+              %i.icon-lock.cred
+            - else
+              %i.icon-user.cgreen
+            = link_to user.name, [:admin, user]
+            - if user.admin?
+              %strong.cred (Admin)
+            - if user == current_user
+              %span.cred It's you!
+            .pull-right
+              %span.light
+                %i.icon-envelope
+                = mail_to user.email, user.email, class: 'light'
+              &nbsp;
+              = link_to 'Edit', edit_admin_user_path(user), id: "edit_#{dom_id(user)}", class: "btn btn-small"
+              - unless user == current_user
+                - if user.blocked
+                  = link_to 'Unblock', unblock_admin_user_path(user), method: :put, class: "btn btn-small success"
+                - else
+                  = link_to 'Block', block_admin_user_path(user), confirm: 'USER WILL BE BLOCKED! Are you sure?', method: :put, class: "btn btn-small btn-remove"
+                = link_to 'Destroy', [:admin, user], confirm: "USER #{user.name} WILL BE REMOVED! Are you sure?", method: :delete, class: "btn btn-small btn-remove"
+        %li.bottom
+          = paginate @admin_users, theme: "gitlab"
-- 
2.30.9