Commit 1e5aa0effffa60cc5f5a953011cfb40a37b6a862

Authored by Aleksei Kvitinskii
1 parent 6323cdda

add tags autocomplete

app/controllers/tags_controller.rb 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +class TagsController < ApplicationController
  2 + def index
  3 + end
  4 +
  5 + def autocomplete
  6 + tags = Project.tag_counts.limit 8
  7 + tags = tags.where('name like ?', "%#{params[:term]}%") unless params[:term].blank?
  8 + tags = tags.map {|t| t.name}
  9 +
  10 + respond_to do |format|
  11 + format.json { render json: tags}
  12 + end
  13 + end
  14 +
  15 +end
... ...
app/views/projects/_form.html.haml
... ... @@ -57,9 +57,19 @@
57 57 $(function(){
58 58 var tag_field = $('#tag_field').tagify();
59 59  
  60 +
  61 + tag_field.tagify('inputField').autocomplete({
  62 + source: '/tags/autocomplete.json',
  63 + position: { of: tag_field.tagify('containerDiv') },
  64 + close: function(event, ui) { tag_field.tagify('add'); },
  65 + });
  66 +
  67 +
60 68 $('form').submit( function() {
61 69 var tag_field = $('#tag_field')
62 70 tag_field.val( tag_field.tagify('serialize') );
63 71 return true;
64 72 });
  73 +
  74 +
65 75 })
... ...
app/views/tags/autocomplete.html.haml 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +%h1 Tags#autocomplete
  2 +%p Find me in app/views/tags/autocomplete.html.haml
0 3 \ No newline at end of file
... ...
app/views/tags/index.html.haml 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +%h1 Tags#index
  2 +%p Find me in app/views/tags/index.html.haml
0 3 \ No newline at end of file
... ...
config/routes.rb
1 1 Gitlab::Application.routes.draw do
  2 + get "tags/index"
  3 + get "tags/autocomplete"
  4 +
2 5 namespace :admin do
3 6 resources :users
4 7 resources :projects
... ...
spec/requests/tags_spec.rb 0 → 100644
... ... @@ -0,0 +1,31 @@
  1 +require 'spec_helper'
  2 +
  3 +describe "Tags" do
  4 + before { login_as :user }
  5 +
  6 + # describe "GET 'tags/index'" do
  7 + # it "should be successful" do
  8 + # get 'tags/index'
  9 + # response.should be_success
  10 + # end
  11 + # end
  12 +
  13 +
  14 + describe "GET '/tags/autocomplete'" do
  15 + before do
  16 + @project = Factory :project
  17 + @project.add_access(@user, :read)
  18 + @project.tag_list = 'demo1'
  19 + @project.save
  20 + visit '/tags/autocomplete.json'
  21 + end
  22 +
  23 +
  24 + it "should contains tags" do
  25 + page.should have_content('demo1')
  26 + end
  27 +end
  28 +
  29 +
  30 +
  31 +end
... ...