diff options
Diffstat (limited to 'users')
-rw-r--r-- | users/app/assets/javascripts/users.js | 4 | ||||
-rw-r--r-- | users/app/controllers/v1/users_controller.rb | 12 | ||||
-rw-r--r-- | users/app/views/users/index.html.haml | 13 | ||||
-rw-r--r-- | users/config/routes.rb | 2 |
4 files changed, 20 insertions, 11 deletions
diff --git a/users/app/assets/javascripts/users.js b/users/app/assets/javascripts/users.js index eed1961..1d05692 100644 --- a/users/app/assets/javascripts/users.js +++ b/users/app/assets/javascripts/users.js @@ -10,7 +10,7 @@ }; poll_users = function(query, process) { - return $.get("/users.json", { + return $.get("/1/users.json", { query: query }).done(process); }; @@ -66,7 +66,7 @@ $('#new_session').submit(srp.login); $('#update_login_and_password').submit(prevent_default); $('#update_login_and_password').submit(srp.update); - return $('.user.typeahead').typeahead({ + return $('#user-typeahead').typeahead({ source: poll_users }); }); diff --git a/users/app/controllers/v1/users_controller.rb b/users/app/controllers/v1/users_controller.rb index e7516bc..e117fc7 100644 --- a/users/app/controllers/v1/users_controller.rb +++ b/users/app/controllers/v1/users_controller.rb @@ -2,11 +2,21 @@ module V1 class UsersController < UsersBaseController skip_before_filter :verify_authenticity_token - before_filter :authorize, :only => [:update] before_filter :fetch_user, :only => [:update] + before_filter :authorize, :only => [:update] + before_filter :authorize_admin, :only => [:index] respond_to :json + def index + if params[:query] + @users = User.by_login.startkey(params[:query]).endkey(params[:query].succ) + respond_with @users.map(&:login).sort + else + render :json => {'error' => 'query required', 'status' => :unprocessable_entity} + end + end + def create @user = User.create(params[:user]) respond_with @user # return ID instead? diff --git a/users/app/views/users/index.html.haml b/users/app/views/users/index.html.haml index 254e177..fc1001e 100644 --- a/users/app/views/users/index.html.haml +++ b/users/app/views/users/index.html.haml @@ -2,13 +2,12 @@ = form_tag users_path, :method => :get, :class => "form-search" do .input-append - = text_field_tag :query, "", :class => "user typeahead span2 search-query", :autocomplete => :off - %button.btn{:type => :submit} Search + = text_field_tag :query, params[:query], :id => 'user-typeahead', :class => "search-query", :autocomplete => :off + %button.btn{:type => :submit}= t(:search) -%table.table.table-hover +%table.table.table-striped %tr - %th Login - %th Created - %th Action + %th= t(:username) + %th= t(:created) + %th= t(:updated) = render @users.all - diff --git a/users/config/routes.rb b/users/config/routes.rb index 9eff2a1..693ae7a 100644 --- a/users/config/routes.rb +++ b/users/config/routes.rb @@ -5,7 +5,7 @@ Rails.application.routes.draw do defaults: {format: 'json'} } do resources :sessions, :only => [:new, :create, :update] delete "logout" => "sessions#destroy", :as => "logout" - resources :users, :only => [:create, :update, :destroy] + resources :users, :only => [:create, :update, :destroy, :index] end get "login" => "sessions#new", :as => "login" |