diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb new file mode 100644 index 00000000..6ec3226a --- /dev/null +++ b/app/controllers/tags_controller.rb @@ -0,0 +1,15 @@ +class TagsController < ApplicationController + def index + end + + def autocomplete + tags = Project.tag_counts.limit 8 + tags = tags.where('name like ?', "%#{params[:term]}%") unless params[:term].blank? + tags = tags.map {|t| t.name} + + respond_to do |format| + format.json { render json: tags} + end + end + +end diff --git a/app/views/projects/_form.html.haml b/app/views/projects/_form.html.haml index 605a2f45..059ee40c 100644 --- a/app/views/projects/_form.html.haml +++ b/app/views/projects/_form.html.haml @@ -57,9 +57,19 @@ $(function(){ var tag_field = $('#tag_field').tagify(); + + tag_field.tagify('inputField').autocomplete({ + source: '/tags/autocomplete.json', + position: { of: tag_field.tagify('containerDiv') }, + close: function(event, ui) { tag_field.tagify('add'); }, + }); + + $('form').submit( function() { var tag_field = $('#tag_field') tag_field.val( tag_field.tagify('serialize') ); return true; }); + + }) diff --git a/app/views/tags/autocomplete.html.haml b/app/views/tags/autocomplete.html.haml new file mode 100644 index 00000000..e5c86e7e --- /dev/null +++ b/app/views/tags/autocomplete.html.haml @@ -0,0 +1,2 @@ +%h1 Tags#autocomplete +%p Find me in app/views/tags/autocomplete.html.haml \ No newline at end of file diff --git a/app/views/tags/index.html.haml b/app/views/tags/index.html.haml new file mode 100644 index 00000000..7bf17b5e --- /dev/null +++ b/app/views/tags/index.html.haml @@ -0,0 +1,2 @@ +%h1 Tags#index +%p Find me in app/views/tags/index.html.haml \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index d45c32bd..c6b2d8b1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,7 @@ Gitlab::Application.routes.draw do + get "tags/index" + get "tags/autocomplete" + namespace :admin do resources :users resources :projects diff --git a/spec/requests/tags_spec.rb b/spec/requests/tags_spec.rb new file mode 100644 index 00000000..43d7a0ff --- /dev/null +++ b/spec/requests/tags_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe "Tags" do + before { login_as :user } + + # describe "GET 'tags/index'" do + # it "should be successful" do + # get 'tags/index' + # response.should be_success + # end + # end + + + describe "GET '/tags/autocomplete'" do + before do + @project = Factory :project + @project.add_access(@user, :read) + @project.tag_list = 'demo1' + @project.save + visit '/tags/autocomplete.json' + end + + + it "should contains tags" do + page.should have_content('demo1') + end +end + + + +end