diff --git a/.gitignore b/.gitignore index 44e45ee..8cfa088 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,5 @@ pickle-email-*.html .env .DS_Store .idea/ +sgemset + diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index 6782669..57c205b 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -20,7 +20,6 @@ #= require_tree ./modules #= require_tree ./app - angular.module "timeoverflow", ["ng-rails-csrf", 'ui.bootstrap'] $(document).on 'click', 'a[data-popup]', (event) -> @@ -44,4 +43,3 @@ $(document).on "click", ".leave-post", (event) -> id = $(event.target).closest("li.post").attr("data-post-id") userId = $(event.target).closest("li.post").attr("data-user-id") $.ajax("/user/#{userId}/joined/#{id}", type: "DELETE") - diff --git a/app/assets/javascripts/tags.js b/app/assets/javascripts/tags.js new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/tags.js @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/tags.css.scss b/app/assets/stylesheets/tags.css.scss new file mode 100644 index 0000000..997822f --- /dev/null +++ b/app/assets/stylesheets/tags.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Tags controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb new file mode 100644 index 0000000..872b347 --- /dev/null +++ b/app/controllers/tags_controller.rb @@ -0,0 +1,10 @@ +class TagsController < ApplicationController + respond_to :json, :html + + def index + + @all_tags = Post::find_like_tag(params[:term]) + respond_with @all_tags + + end +end diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb new file mode 100644 index 0000000..23450bc --- /dev/null +++ b/app/helpers/tags_helper.rb @@ -0,0 +1,2 @@ +module TagsHelper +end diff --git a/app/models/concerns/taggable.rb b/app/models/concerns/taggable.rb index eabf6c5..9ba93f6 100644 --- a/app/models/concerns/taggable.rb +++ b/app/models/concerns/taggable.rb @@ -27,6 +27,12 @@ module Taggable Hash[all_tags.group_by(&:to_s).values.map {|v| [v.first, v.size]}.sort] end + def find_like_tag(pattern) + + all_tags.uniq.select{|t| t=~ /#{pattern}/} + + end + end end diff --git a/app/views/inquiries/edit.html.haml b/app/views/inquiries/edit.html.haml index 0fe80fb..8c4cdfd 100644 --- a/app/views/inquiries/edit.html.haml +++ b/app/views/inquiries/edit.html.haml @@ -4,3 +4,6 @@ = t ".edit" = render partial: 'shared/post_form', locals: {post: @inquiry} + +:javascript + $("#inquiry_tag_list").tagsManager(); diff --git a/app/views/inquiries/new.html.haml b/app/views/inquiries/new.html.haml index 9f7a150..b72a723 100644 --- a/app/views/inquiries/new.html.haml +++ b/app/views/inquiries/new.html.haml @@ -1,3 +1,7 @@ %h1= t "helpers.submit.create", model: @inquiry.class.model_name.human = render partial: 'shared/post_form', locals: { post: @inquiry } + +:javascript + $("#inquiry_tag_list").tagsManager(); + diff --git a/app/views/offers/edit.html.haml b/app/views/offers/edit.html.haml index e6c39cf..e5d8e17 100644 --- a/app/views/offers/edit.html.haml +++ b/app/views/offers/edit.html.haml @@ -4,3 +4,7 @@ = t ".edit" = render partial: 'shared/post_form', locals: {post: @offer} + +:javascript + $("#offer_tag_list").tagsManager(); + diff --git a/app/views/offers/new.html.haml b/app/views/offers/new.html.haml index 30864de..3462354 100644 --- a/app/views/offers/new.html.haml +++ b/app/views/offers/new.html.haml @@ -1,3 +1,6 @@ %h1= t "helpers.submit.create", model: @offer.class.model_name.human = render partial: 'shared/post_form', locals: {post: @offer} + +:javascript + $("#offer_tag_list").tagsManager(); diff --git a/app/views/shared/_post_form.html.haml b/app/views/shared/_post_form.html.haml index 1ce9086..7299e04 100644 --- a/app/views/shared/_post_form.html.haml +++ b/app/views/shared/_post_form.html.haml @@ -1,14 +1,39 @@ +:javascript + angular.module('timeoverflow').controller('TagTypeaheadCtrl', + function($scope, $http) { + + $scope.selected = undefined; + + // Any function returning a promise object can be used to load values asynchronously + $scope.getTags = function(val) { + + return $http.get('/tags/index', { + params: { + term: val + } + }).then(function(res){ + + var tags = []; + + angular.forEach(res.data, function(item){ + tags.push(item); + }); + + return tags; + + }); + }; + }); + = simple_form_for(post) do |f| = f.input :title = f.input :description = f.association :category - = f.input :tag_list, as: :string + + = f.input :tag_list, as: :string, :placeholder => t('application.tips.entertag'), input_html: { class: "form-control", "ng-controller" => "TagTypeaheadCtrl", "ng-model" => "asyncSelected", "typeahead" => "tag for tag in getTags($viewValue) | filter:$viewValue | limitTo:8" , "typeahead-loading" => "loadingTags"} + %i{"ng-show" => "loadingTags", :class => "glyphicon glyphicon-refresh"} - if current_user.manages? current_organization = f.association :user, collection: current_organization.users = f.hidden_field :publisher_id, value: current_user.id = f.button :submit - -:javascript - $("#offer_tag_list").tagsManager(); - diff --git a/app/views/tags/index.html.haml b/app/views/tags/index.html.haml new file mode 100644 index 0000000..e0c179e --- /dev/null +++ b/app/views/tags/index.html.haml @@ -0,0 +1,7 @@ +%h1 Tags#index + + +- @all_tags.each do |tag| + %h5 + = tag + %span.glyphicon.glyphicon-tag diff --git a/config/locales/es.yml b/config/locales/es.yml index cf0f543..e698bc3 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -97,7 +97,9 @@ es: categories: Servicios organizations: Organizaciones statistics: Estadísticas - + tips: + entertag: Entre etiquetas separadas por comas + # views/users/index... users: diff --git a/config/routes.rb b/config/routes.rb index d3d30f9..9192616 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ Timeoverflow::Application.routes.draw do + get 'tags/index' + devise_for :users ActiveAdmin.routes(self) @@ -46,4 +48,6 @@ Timeoverflow::Application.routes.draw do post :accept end + resource :tags, only: [:index] + end diff --git a/spec/controllers/tags_controller_spec.rb b/spec/controllers/tags_controller_spec.rb new file mode 100644 index 0000000..abeaffc --- /dev/null +++ b/spec/controllers/tags_controller_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe TagsController do + + describe "GET 'index'" do + it "returns http success" do + get 'index' + response.should be_success + end + end + +end diff --git a/spec/helpers/tags_helper_spec.rb b/spec/helpers/tags_helper_spec.rb new file mode 100644 index 0000000..e68a43b --- /dev/null +++ b/spec/helpers/tags_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the TagsHelper. For example: +# +# describe TagsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +describe TagsHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/tags/index.html.haml_spec.rb b/spec/views/tags/index.html.haml_spec.rb new file mode 100644 index 0000000..9765386 --- /dev/null +++ b/spec/views/tags/index.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "tags/index.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end