using angular for typeahead. working with fixed array but not with asyncSelected
This commit is contained in:
@ -19,9 +19,6 @@
|
||||
#= require ui-bootstrap-tpls-0.11.0
|
||||
#= require_tree ./modules
|
||||
#= require_tree ./app
|
||||
#= require typeahead.bundle-0.10.5
|
||||
#= require transfer
|
||||
|
||||
|
||||
angular.module "timeoverflow", ["ng-rails-csrf", 'ui.bootstrap']
|
||||
|
||||
|
||||
3
app/assets/javascripts/tags.js.coffee
Normal file
3
app/assets/javascripts/tags.js.coffee
Normal 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/
|
||||
@ -1,11 +0,0 @@
|
||||
jQuery ->
|
||||
$('#offer_tag_list').typeahead({
|
||||
hint: true,
|
||||
highlight: true,
|
||||
minLength: 1
|
||||
},
|
||||
{
|
||||
name: 'tags',
|
||||
displayKey: 'value',
|
||||
source: ['foo','food','four']
|
||||
});
|
||||
3
app/assets/stylesheets/tags.css.scss
Normal file
3
app/assets/stylesheets/tags.css.scss
Normal 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
app/controllers/tags_controller.rb
Normal file
10
app/controllers/tags_controller.rb
Normal file
@ -0,0 +1,10 @@
|
||||
class TagsController < ApplicationController
|
||||
respond_to :json, :html
|
||||
|
||||
def index
|
||||
|
||||
@all_tags = (Post::all_tags || [])
|
||||
respond_with @all_tags
|
||||
|
||||
end
|
||||
end
|
||||
2
app/helpers/tags_helper.rb
Normal file
2
app/helpers/tags_helper.rb
Normal file
@ -0,0 +1,2 @@
|
||||
module TagsHelper
|
||||
end
|
||||
@ -1,8 +1,35 @@
|
||||
:javascript
|
||||
angular.module('timeoverflow').controller('TypeaheadCtrl',
|
||||
function($scope, $http) {
|
||||
|
||||
$scope.selected = undefined;
|
||||
$scope.states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Dakota', 'North Carolina', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'];
|
||||
|
||||
// Any function returning a promise object can be used to load values asynchronously
|
||||
$scope.getTags = function(val) {
|
||||
|
||||
return $http.get('/tags/index').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, placeholder: 'search tag', input_html: { class: 'typeahead', autocomplete: 'on' }
|
||||
|
||||
= f.input :tag_list, as: :string, placeholder: 'search tag', input_html: { class: "form-control", "ng-controller" => "TypeaheadCtrl", "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
|
||||
|
||||
7
app/views/tags/index.html.haml
Normal file
7
app/views/tags/index.html.haml
Normal file
@ -0,0 +1,7 @@
|
||||
%h1 Tags#index
|
||||
|
||||
|
||||
- @all_tags.each do |tag|
|
||||
%h5
|
||||
= tag
|
||||
%span.glyphicon.glyphicon-tag
|
||||
@ -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
spec/controllers/tags_controller_spec.rb
Normal file
12
spec/controllers/tags_controller_spec.rb
Normal 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
spec/helpers/tags_helper_spec.rb
Normal file
15
spec/helpers/tags_helper_spec.rb
Normal 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
spec/views/tags/index.html.haml_spec.rb
Normal file
5
spec/views/tags/index.html.haml_spec.rb
Normal file
@ -0,0 +1,5 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "tags/index.html.haml" do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
1782
vendor/assets/javascripts/typeahead.bundle-0.10.5.js
vendored
1782
vendor/assets/javascripts/typeahead.bundle-0.10.5.js
vendored
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user