Permalink
Browse files

lookup for users

  • Loading branch information...
1 parent b5de8a9 commit 46d01337139d3557e027eb19fc76e87cfbb5869f Dimitri Kurashvili committed Jul 11, 2012
@@ -3,8 +3,10 @@ class Sys::UsersController < ApplicationController
# მომხმარებლების საწყისი გვერდი.
def index
+ @q = params[:q]
@title = 'მომხმარებლები'
- @users = User.desc(:_id).paginate(page: params[:page], per_page: 5)
+ @users = User.by_q(@q).desc(:created_at).paginate(page: params[:page], per_page: 5)
+ render :json => {:q => @q, :d => render_to_string(:partial => 'sys/users/list')} if request.xhr?
end
# მომხმარებლის რედაქტირება.
@@ -2,7 +2,7 @@
class Ext::Gis::Message
include Mongoid::Document
include Mongoid::Timestamps
- include Ext::Queryable
+ include Telasi::Queryable
field :on, type: Boolean
field :sent, type: Boolean, default: false
@@ -1,5 +1,5 @@
# -*- encoding : utf-8 -*-
-module Ext::Queryable
+module Telasi::Queryable
module ClassMethods
def search_by_q(q, *fields)
words = q.split if q #.find_all{|word| word[0] != '@'} unless q.blank?
View
@@ -3,6 +3,7 @@ class User
include Mongoid::Document
include Mongoid::Timestamps
include Telasi::StandardPhoto
+ include Telasi::Queryable
attr_accessor :password_confirmation
@@ -67,6 +68,9 @@ class User
before_create :before_user_create
before_update :before_user_update
+ index :email
+ index [[:email, Mongo::ASCENDING], [:mobile, Mongo::ASCENDING], [:first_name, Mongo::ASCENDING], [:last_name, Mongo::ASCENDING]]
+
# მომხმარებლის ავტორიზაცია.
def self.authenticate(email, pwd)
user = User.where(:email => email).first
@@ -89,6 +93,10 @@ def self.correct_email?(email)
not not (email =~ /^\S+@\S+$/)
end
+ def self.by_q(q)
+ self.search_by_q(q, :email, :mobile, :first_name, :last_name)
+ end
+
def password
@password
end
@@ -0,0 +1,36 @@
+<table class="table table-bordered table-striped">
+ <thead>
+ <tr>
+ <th width="45" class="center"><%= icon('picture') %></th>
+ <th width="300">მომხმარებელი</th>
+ <th>როლები</th>
+ <th width="16"><%= icon('cog') %></th>
+ </tr>
+ </thead>
+ <tbody>
+ <% if @users.any? %>
+ <% @users.each do |u| -%>
+ <tr>
+ <td width="45" class="center"><%= image_tag(u.normal_photo) %></td>
+ <td>
+ <%= u.full_name %><br>
+ <span class="muted">
+ <%= icon_text (u.email_confirmed ? 'ok-sign' : 'question-sign'), mail_to(u.email) %>
+ <%= C12.format_mobile u.mobile %>
+ </span>
+ </td>
+ <td>
+ <%= render partial: 'users/roles', locals: {user: u} %>
+ </td>
+ <td>
+ <%= link_to icon('pencil', tooltip: 'შეცვლა', tooltip_placement: :left), sys_edit_user_path(id: u.id) %>
+ <%= link_to icon('trash', tooltip: 'წაშლა', tooltip_placement: :left), sys_delete_user_path(id: u.id), method: :delete, confirm: 'ნამდვილად გინდათ წაშლა?' unless u == current_user %>
+ </td>
+ </tr>
+ <% end %>
+ <% else %>
+ <tr><td class="muted" colspan="4">სია ცარიელია.</td></tr>
+ <% end %>
+ </tbody>
+</table>
+<%= paginate @users %>
@@ -1,33 +1,14 @@
+<script type="text/javascript">
+ $(function() {
+ Telasi.simpleSearchSetup({url: '<%= sys_users_url %>'});
+ });
+</script>
<div class="page-header">
<h2>მომხმარებლების მართვა</h2>
</div>
-<table class="table table-bordered table-striped">
- <thead>
- <tr>
- <th width="45" class="center"><%= icon('picture') %></th>
- <th width="300">მომხმარებელი</th>
- <th>როლები</th>
- <th width="16"><%= icon('cog') %></th>
- </tr>
- </thead>
- <% @users.each do |u| -%>
- <tr>
- <td width="45" class="center"><%= image_tag(u.normal_photo) %></td>
- <td>
- <%= u.full_name %><br>
- <span class="muted">
- <%= icon_text (u.email_confirmed ? 'ok-sign' : 'question-sign'), mail_to(u.email) %>
- <%= C12.format_mobile u.mobile %>
- </span>
- </td>
- <td>
- <%= render partial: 'users/roles', locals: {user: u} %>
- </td>
- <td>
- <%= link_to icon('pencil', tooltip: 'შეცვლა', tooltip_placement: :left), sys_edit_user_path(id: u.id) %>
- <%= link_to icon('trash', tooltip: 'წაშლა', tooltip_placement: :left), sys_delete_user_path(id: u.id), method: :delete, confirm: 'ნამდვილად გინდათ წაშლა?' unless u == current_user %>
- </td>
- </tr>
- <% end %>
-</table>
-<%= paginate @users %>
+<div class="btn-toolbar">
+ <input id="search-field" type="text" autofocus placeholder="ძებნა..."/>
+</div>
+<div id="search-result">
+ <%= render partial: 'sys/users/list' %>
+</div>

0 comments on commit 46d0133

Please sign in to comment.