Merge pull request #48 from danielmacho72/tag-management

Tag management phase 1
This commit is contained in:
Saverio Trioni
2014-10-16 11:39:44 +02:00
18 changed files with 116 additions and 8 deletions
+2
View File
@@ -35,3 +35,5 @@ pickle-email-*.html
.env
.DS_Store
.idea/
sgemset
@@ -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")
+3
View File
@@ -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/
+3
View File
@@ -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/
+10
View File
@@ -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
+2
View File
@@ -0,0 +1,2 @@
module TagsHelper
end
+6
View File
@@ -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
+3
View File
@@ -4,3 +4,6 @@
= t ".edit"
= render partial: 'shared/post_form', locals: {post: @inquiry}
:javascript
$("#inquiry_tag_list").tagsManager();
+4
View File
@@ -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();
+4
View File
@@ -4,3 +4,7 @@
= t ".edit"
= render partial: 'shared/post_form', locals: {post: @offer}
:javascript
$("#offer_tag_list").tagsManager();
+3
View File
@@ -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();
+30 -5
View File
@@ -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();
+7
View File
@@ -0,0 +1,7 @@
%h1 Tags#index
- @all_tags.each do |tag|
%h5
= tag
%span.glyphicon.glyphicon-tag
+3 -1
View File
@@ -97,7 +97,9 @@ es:
categories: Servicios
organizations: Organizaciones
statistics: Estadísticas
tips:
entertag: Entre etiquetas separadas por comas
# views/users/index...
users:
+4
View File
@@ -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
+12
View File
@@ -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
+15
View File
@@ -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
+5
View File
@@ -0,0 +1,5 @@
require 'spec_helper'
describe "tags/index.html.haml" do
pending "add some examples to (or delete) #{__FILE__}"
end