social_stream-base 0.9.5 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/app/assets/images/mini-loading.gif +0 -0
  2. data/app/assets/javascripts/preloader.js +6 -0
  3. data/app/assets/javascripts/search.js.erb +1 -0
  4. data/app/assets/stylesheets/search.css +10 -3
  5. data/app/controllers/contacts_controller.rb +17 -9
  6. data/app/controllers/search_controller.rb +33 -33
  7. data/app/helpers/contacts_helper.rb +7 -3
  8. data/app/helpers/search_helper.rb +7 -1
  9. data/app/models/contact.rb +7 -4
  10. data/app/models/relation/single.rb +1 -1
  11. data/app/views/avatars/index.html.erb +1 -1
  12. data/app/views/search/_focus_search.html.erb +3 -2
  13. data/app/views/search/_form.html.erb +27 -5
  14. data/app/views/search/_index.html.erb +1 -1
  15. data/app/views/search/index.js.erb +25 -0
  16. data/config/locales/en.yml +7 -1
  17. data/lib/generators/social_stream/base/templates/sphinx.yml +3 -3
  18. data/lib/social_stream/base/version.rb +1 -1
  19. data/lib/social_stream/migrations/components.rb +19 -0
  20. data/lib/tasks/db/populate.rake +13 -5
  21. data/spec/controllers/comments_controller_spec.rb +1 -1
  22. data/spec/controllers/contacts_controller_spec.rb +24 -1
  23. data/spec/controllers/frontpage_controller_spec.rb +1 -1
  24. data/spec/controllers/groups_controller_spec.rb +1 -1
  25. data/spec/controllers/home_controller_spec.rb +1 -1
  26. data/spec/controllers/likes_controller_spec.rb +1 -1
  27. data/spec/controllers/notifications_controller_spec.rb +2 -2
  28. data/spec/controllers/permissions_controller_spec.rb +1 -1
  29. data/spec/controllers/posts_controller_spec.rb +1 -1
  30. data/spec/controllers/profiles_controller_spec.rb +1 -1
  31. data/spec/controllers/relation_customs_controller_spec.rb +1 -1
  32. data/spec/controllers/representations_spec.rb +1 -1
  33. data/spec/controllers/settings_controller_spec.rb +2 -2
  34. data/spec/controllers/subjects_controller.rb +1 -1
  35. data/spec/controllers/users_controller_spec.rb +1 -1
  36. data/spec/integration/navigation_spec.rb +1 -1
  37. data/spec/models/activity_authorization_spec.rb +1 -1
  38. data/spec/models/activity_spec.rb +1 -1
  39. data/spec/models/actor_spec.rb +1 -1
  40. data/spec/models/contact_spec.rb +1 -1
  41. data/spec/models/group_spec.rb +1 -1
  42. data/spec/models/like_spec.rb +1 -1
  43. data/spec/models/post_spec.rb +1 -1
  44. data/spec/models/profile_spec.rb +1 -1
  45. data/spec/models/relation_spec.rb +1 -1
  46. data/spec/models/tie_spec.rb +1 -1
  47. data/spec/models/user_spec.rb +1 -1
  48. data/vendor/assets/javascripts/jquery.validate.js +1112 -1078
  49. data/vendor/assets/javascripts/jquery.validate.old.js +1132 -0
  50. metadata +9 -5
  51. data/.travis.yml +0 -4
Binary file
@@ -0,0 +1,6 @@
1
+ $.preloadImages = function() {
2
+ for (var i = 0; i<arguments.length; i++) {
3
+ img = new Image();
4
+ img.src = arguments[i];
5
+ }
6
+ }
@@ -1,5 +1,6 @@
1
1
  // index
2
2
  //= require ajax.paginate
3
+ //= require jquery.validate
3
4
 
4
5
  $(document).ready(function(){
5
6
  $("#global_search_input").Watermark("<%= I18n.t('search.write') %>");
@@ -101,6 +101,9 @@
101
101
  width: 100%;
102
102
  }
103
103
  /********************************* Global ******************/
104
+ #global_search_input.searching {
105
+ background: url('mini-loading.gif') 5px 50% no-repeat white;
106
+ }
104
107
  .search_row {
105
108
  text-align: center;
106
109
  }
@@ -133,6 +136,10 @@
133
136
  #search_results .subject_search_results .title {
134
137
  width: 260px;
135
138
  }
139
+ /********************************* Form and errors *********/
140
+ #search_form .error {
141
+ display: none;
142
+ }
136
143
  /********************************* Focus options ***********/
137
144
  #focus_options ul {
138
145
  list-style: none;
@@ -146,14 +153,14 @@
146
153
  background: #CFDEFF;
147
154
  color: #2A3890;
148
155
  }
149
- #focus_options ul li a:hover{
156
+ #focus_options ul li a:hover {
150
157
  text-decoration: none;
151
158
  }
152
- #focus_options ul li span{
159
+ #focus_options ul li span {
153
160
  padding: 5px 10px;
154
161
  background-color: #E1EEF5;
155
162
  }
156
- #focus_options ul li span.selected{
163
+ #focus_options ul li span.selected {
157
164
  border: solid 1px #2A3890;
158
165
  }
159
166
  /******************** Search css END ***********************/
@@ -1,5 +1,7 @@
1
1
  class ContactsController < ApplicationController
2
2
  before_filter :authenticate_user!
3
+ before_filter :exclude_reflexive, :except => [ :index, :pending ]
4
+
3
5
  def index
4
6
  if params[:pending].present?
5
7
  pending
@@ -20,15 +22,14 @@ class ContactsController < ApplicationController
20
22
  end
21
23
 
22
24
  def edit
23
- @contact = current_subject.sent_contacts.find params[:id]
24
25
  end
25
26
 
26
27
  def update
27
- @contact = current_subject.sent_contacts.find params[:id]
28
-
29
- # This should be in the model
30
- if params[:contact][:relation_ids].present?
31
- params[:contact][:relation_ids].delete("gotcha")
28
+ # FIXME: This should be in the model
29
+ if params[:contact][:relation_ids].present? &&
30
+ params[:contact][:relation_ids].delete("gotcha") &&
31
+ params[:contact][:relation_ids].blank?
32
+ params[:contact][:relation_ids] << @contact.sender.relation_public.id
32
33
  end
33
34
 
34
35
  if @contact.update_attributes(params[:contact])
@@ -39,8 +40,6 @@ class ContactsController < ApplicationController
39
40
  end
40
41
 
41
42
  def destroy
42
- @contact = current_subject.sent_contacts.find params[:id]
43
-
44
43
  @contact.relation_ids = [current_subject.relation_reject.id]
45
44
 
46
45
  respond_to do |format|
@@ -49,7 +48,6 @@ class ContactsController < ApplicationController
49
48
  end
50
49
 
51
50
  def pending
52
-
53
51
  @contacts = current_subject.pending_contacts
54
52
 
55
53
  respond_to do |format|
@@ -58,4 +56,14 @@ class ContactsController < ApplicationController
58
56
  format.json { render :text => @contacts.map{ |c| { 'key' => c.receiver_id.to_s, 'value' => self.class.helpers.truncate_name(c.receiver.name) } }.to_json }
59
57
  end
60
58
  end
59
+
60
+ private
61
+
62
+ def exclude_reflexive
63
+ @contact = current_subject.sent_contacts.find params[:id]
64
+
65
+ if @contact.reflexive?
66
+ redirect_to home_path
67
+ end
68
+ end
61
69
  end
@@ -3,23 +3,22 @@ class SearchController < ApplicationController
3
3
 
4
4
  #before_filter :authenticate_user! #??
5
5
 
6
- FOCUS_SEARCH_PER_PAGE = 10
6
+ FOCUS_SEARCH_PER_PAGE=16
7
+ MIN_QUERY=2
7
8
  def index
8
- if params[:search_query].blank?
9
+ @search_class_sym = params[:focus].singularize.to_sym unless params[:focus].blank?
10
+ if params[:search_query].blank? or too_short_query
9
11
  @search_result = nil_search
10
- @search_class_sym = params[:focus].singularize.to_sym unless params[:focus].blank?
11
12
  else
12
- search_query = get_search_query params[:search_query]
13
13
  if params[:mode].eql? "header_search"
14
- @search_result = header_search search_query
14
+ @search_result = header_search
15
15
  render :partial => "header_search", :locals => {:search_result => @search_result}
16
16
  return
17
17
  else
18
18
  if params[:focus].present?
19
- @search_result = focus_search params[:focus], search_query, params[:page].present? ? params[:page].to_i : 1
20
- @search_class_sym = params[:focus].singularize.to_sym
19
+ @search_result = focus_search
21
20
  else
22
- @search_result = global_search search_query
21
+ @search_result = global_search
23
22
  end
24
23
  end
25
24
  end
@@ -27,55 +26,56 @@ class SearchController < ApplicationController
27
26
 
28
27
  private
29
28
 
30
- def get_search_query bare_query
29
+ def too_short_query
30
+ bare_query = strip_tags(params[:search_query]) unless bare_query.html_safe?
31
+ return bare_query.strip.size < MIN_QUERY
32
+ end
33
+
34
+ def get_search_query
31
35
  search_query = ""
32
- bare_query = strip_tags(bare_query) unless bare_query.html_safe?
36
+ bare_query = strip_tags(params[:search_query]) unless bare_query.html_safe?
33
37
  search_query_words = bare_query.strip.split
34
38
  search_query_words.each_index do |i|
35
39
  search_query+= search_query_words[i] + " " if i < (search_query_words.size - 1)
36
40
  search_query+= "*" + search_query_words[i] + "* " if i == (search_query_words.size - 1)
37
41
  end
38
- return search_query.strip
42
+ return search_query.strip
39
43
  end
40
44
 
41
- def global_search query
42
- return search query, 10
45
+ def global_search
46
+ return search 6
43
47
  end
44
48
 
45
- def header_search query
46
- return search query, 3
49
+ def header_search
50
+ return search 3
47
51
  end
48
52
 
49
- def search query, max_results
53
+ def search max_results
50
54
  result = Hash.new
51
- total = 0
52
55
  total_shown = 0
53
56
  SocialStream.subjects.each do |subject_sym|
54
- result.update({subject_sym => ThinkingSphinx.search(query, :page => 1, :per_page => max_results, :classes => [subject_sym.to_s.classify.constantize])})
55
- result.update({(subject_sym.to_s+"_total").to_sym => ThinkingSphinx.count(query, :classes => [subject_sym.to_s.classify.constantize])})
56
- total+=ThinkingSphinx.count(query, :classes => [subject_sym.to_s.classify.constantize])
57
+ result.update({subject_sym => ThinkingSphinx.search(get_search_query, :classes => [subject_sym.to_s.classify.constantize]).page(1).per(max_results)})
58
+ result.update({(subject_sym.to_s+"_total").to_sym => ThinkingSphinx.count(get_search_query, :classes => [subject_sym.to_s.classify.constantize])})
57
59
  end
58
- result.update({:total => total})
59
- result.update({:total_shown => total_shown})
60
60
  return result
61
61
  end
62
62
 
63
- def focus_search string_class, query, page
64
- string_class = string_class.singularize
63
+ def focus_search
64
+ string_class = params[:focus].singularize
65
65
  search_class = string_class.classify.constantize
66
- result = Hash.new
67
- result.update({string_class.to_sym => ThinkingSphinx.search(query, :page => page, :per_page => FOCUS_SEARCH_PER_PAGE, :classes => [search_class])})
68
- result.update({(string_class+"_total").to_sym => ThinkingSphinx.count(query, :classes => [search_class])})
69
- return result
66
+ return ThinkingSphinx.search(get_search_query, :classes => [search_class]).page(params[:page]).per(FOCUS_SEARCH_PER_PAGE)
70
67
  end
71
68
 
72
69
  def nil_search
73
- result = Hash.new
74
- SocialStream.subjects.each do |subject_sym|
75
- result.update({subject_sym => []})
76
- result.update({(subject_sym.to_s+"_total").to_sym => 0})
70
+ if params[:focus].present?
71
+ result = []
72
+ else
73
+ result = Hash.new
74
+ SocialStream.subjects.each do |subject_sym|
75
+ result.update({subject_sym => []})
76
+ result.update({(subject_sym.to_s+"_total").to_sym => 0})
77
+ end
77
78
  end
78
- result.update({:total => 0})
79
79
  return result
80
80
  end
81
81
  end
@@ -4,9 +4,13 @@ module ContactsHelper
4
4
  end
5
5
 
6
6
  def contact_link(c)
7
- link_to c.status,
8
- edit_contact_path(c),
9
- :title => t("contact.#{ c.action }.title", :name => c.receiver.name)
7
+ if c.reflexive?
8
+ t('subject.this_is_you')
9
+ else
10
+ link_to c.status,
11
+ edit_contact_path(c),
12
+ :title => t("contact.#{ c.action }.title", :name => c.receiver.name)
13
+ end
10
14
 
11
15
  end
12
16
 
@@ -7,6 +7,12 @@ module SearchHelper
7
7
 
8
8
  def focus_search_link text, search_class, query
9
9
  search_class = search_class.to_s if search_class.is_a? Class or search_class.is_a? Symbol
10
- link_to text, search_path(:focus => search_class.downcase.pluralize, :search_query => query )
10
+ link_to text, search_path(:focus => search_class.downcase.pluralize, :search_query => query ), :remote => true
11
+ end
12
+
13
+ def too_short_query?
14
+ return true if params[:search_query].blank?
15
+ bare_query = strip_tags(params[:search_query]) unless bare_query.html_safe?
16
+ return bare_query.strip.size < SearchController::MIN_QUERY
11
17
  end
12
18
  end
@@ -125,14 +125,17 @@ class Contact < ActiveRecord::Base
125
125
  if ties_count > 0 && relations.where(:type => ['Relation::Custom', 'Relation::Public']).any?
126
126
  'edit'
127
127
  else
128
- 'new'
128
+ replied? ? 'reply' : 'new'
129
129
  end
130
130
  end
131
131
 
132
132
  def status
133
- established? ?
134
- ties.includes(:relation).map(&:relation_name).join(", ") :
135
- I18n.t("contact.new.link")
133
+ case action
134
+ when 'edit'
135
+ ties.includes(:relation).map(&:relation_name).join(", ")
136
+ else
137
+ I18n.t("contact.#{ action }.link")
138
+ end
136
139
  end
137
140
 
138
141
  private
@@ -17,6 +17,6 @@ class Relation::Single < Relation
17
17
 
18
18
  # The name of public relation
19
19
  def name
20
- I18n.t("relation_#{ self.class.name }.name")
20
+ I18n.t("relation_#{ self.class.name.split("::").last.underscore }.name")
21
21
  end
22
22
  end
@@ -9,7 +9,7 @@
9
9
  <%= javascript_include_tag 'avatars.js' %>
10
10
 
11
11
  <%= stylesheet_link_tag "jquery.Jcrop", :media => "screen, projection" %>
12
- <%= stylesheet_link_tag "avatars", :media => "screen, projection" %><br/>
12
+ <%= stylesheet_link_tag "avatars", :media => "screen, projection" %>
13
13
  <%= stylesheet_link_tag "jquery.fileupload-ui", :media => "screen, projection" %>
14
14
  <% end %>
15
15
 
@@ -2,14 +2,14 @@
2
2
  <%= @search_class_sym.to_s.capitalize.pluralize %>
3
3
  </div>
4
4
  <br class="clearfloat" />
5
- <% if @search_result[@search_class_sym].empty? %>
5
+ <% if @search_result.empty? %>
6
6
  <div class="subject_with_details">
7
7
  <%= I18n.t('search.no_subject_found', :subject => @search_class_sym.to_s) %>
8
8
  </div>
9
9
  <% else %>
10
10
  <% total = 0 %>
11
11
  <div class="subject_search_results block left">
12
- <% @search_result[@search_class_sym].each do |subject|%>
12
+ <% @search_result.each do |subject|%>
13
13
  <%= subject_with_details subject %>
14
14
  <% total+=1 %>
15
15
  <% if (total%(SearchController::FOCUS_SEARCH_PER_PAGE/2)==0) %>
@@ -18,4 +18,5 @@
18
18
  <% end %>
19
19
  <% end %>
20
20
  </div>
21
+ <%= paginate @search_result %>
21
22
  <% end %>
@@ -1,17 +1,18 @@
1
- <div id="search_form">
2
- <form action="<%= search_path %>" method="get">
1
+ <div>
2
+ <form action="<%= search_path %>" method="get" data-remote="true" id="search_form">
3
3
  <div class="block">
4
+ <div class="error" id="too_short_error" <%= too_short_query? ? 'style=display:block;' : '' %>><%= t('search.at_least') %></div>
4
5
  <%= hidden_field_tag :focus, params[:focus] %>
5
6
  <div class="form_row search_row">
6
7
  <%= text_field_tag :search_query, params[:search_query].present? ? params[:search_query] : nil ,:autocomplete => :off, :id => :global_search_input %>
7
8
  </div>
8
9
  <div id="focus_options" class="form_row search_row">
9
10
  <ul>
10
- <li><%= link_to content_tag(:span,t('search.show_all'),:class => params[:focus].blank? ? 'selected' : ''), search_path, :search_query => params[:search_query] %></li>
11
+ <li><%= link_to content_tag(:span,t('search.show_all'),:class => params[:focus].blank? ? 'global selected' : 'global'), search_path(:search_query => params[:search_query]), :remote => true %></li>
11
12
  <% SocialStream.subjects.each do |subject| %>
12
13
  <% selected_class = (params[:focus].present? and params[:focus].pluralize.downcase.eql?(subject.to_s.pluralize.downcase)) ? 'selected' : ''%>
13
14
  <li><%= focus_search_link content_tag(:span, subject.to_s.pluralize.capitalize,
14
- :class => selected_class),
15
+ :class => selected_class + " " + subject.to_s.pluralize.downcase),
15
16
  subject.to_s.classify.constantize,
16
17
  params[:search_query] %></li>
17
18
  <% end %>
@@ -19,4 +20,25 @@
19
20
  </div>
20
21
  </div>
21
22
  </form>
22
- </div>
23
+ </div>
24
+
25
+ <%= javascript_tag do %>
26
+ $(document).ready(function() {
27
+ $.preloadImages ("assets/mini-loading.gif");
28
+
29
+ $('#search_form').submit(function() {
30
+ query = $('#global_search_input').val();
31
+ if((query=="")||(query.length < 2)||(query=="<%= t('search.write') %>")){
32
+ $('#too_short_error').show();
33
+ $('#global_search_input').removeClass("searching");
34
+ $('#global_search_input').blur();
35
+ $('#global_search_input').focus();
36
+ return false;
37
+ }else{
38
+ $('#global_search_input').addClass("searching");
39
+ $('#global_search_input').blur();
40
+ }
41
+ return true;
42
+ });
43
+ });
44
+ <% end %>
@@ -1,7 +1,7 @@
1
1
  <%= location(link_to(t('search.global.name')))%>
2
2
  <br class="clearfloat" />
3
3
  <div class="space_center"></div>
4
- <h2><%= t('search.searching', :query => truncate(params[:search_query],:length => 45)) %></h2>
4
+ <h2><%= t('search.name') %></h2>
5
5
  <div class="space_center"></div>
6
6
  <%= render :partial => 'form' %>
7
7
  <div class="space_center"></div>
@@ -0,0 +1,25 @@
1
+ //if ($('#global_search_input').val()=="<%= params[:search_query]%>"){
2
+
3
+ $('#search_results').html("<% unless params[:focus].present? %><%= escape_javascript render :partial => 'global_search' %><% else %><%= escape_javascript render :partial => 'focus_search' %><% end %>");
4
+
5
+ $('#focus_options ul li a span').removeClass('selected');
6
+
7
+ <% if params[:focus].present? %>
8
+ $('#focus_options ul li a span.<%= params[:focus].pluralize.downcase %>').addClass('selected');
9
+ <% else %>
10
+ $('#focus_options ul li a span.global').addClass('selected');
11
+ <% end %>
12
+
13
+ $('title').text('<%= t('search.name')%> <%= escape_javascript(params[:search_query].present? ? ": #{params[:search_query]}" : "")%>');
14
+
15
+ <% if too_short_query? %>
16
+ $('#too_short_error').show();
17
+ <% else %>
18
+ $('#too_short_error').hide();
19
+ <% end %>
20
+
21
+ $('#global_search_input').removeClass("searching");
22
+
23
+ /*}else{
24
+ alert("ignored <%= params[:search_query]%>");
25
+ }*/
@@ -94,7 +94,7 @@ en:
94
94
  current: "Current"
95
95
  edit:
96
96
  title: "Edit contact to %{name}"
97
- submit: "Edit Contact"
97
+ submit: "Edit contact"
98
98
  graph:
99
99
  one: "Graph"
100
100
  empty: "We're sorry but you don't have any contacts yet. You can try the search box to look for somebody!"
@@ -115,6 +115,10 @@ en:
115
115
  relation:
116
116
  one: "Contact type"
117
117
  new: "New type"
118
+ reply:
119
+ link: "+ Reply contact"
120
+ title: "Reply contact request to %{name}"
121
+ submit: "Reply contact"
118
122
  suggestion:
119
123
  one: "Suggestion"
120
124
  other: "Suggestions"
@@ -368,6 +372,8 @@ en:
368
372
  sign_out: "Sign out"
369
373
  sign_up: "Sign up"
370
374
  socialstream: "SocialStream"
375
+ subject:
376
+ this_is_you: "This is you!"
371
377
  sure: "Are you sure?"
372
378
  time:
373
379
  ago: "%{time} ago"
@@ -1,9 +1,9 @@
1
1
  development:
2
2
  enable_star: 1
3
- min_infix_len: 2
3
+ min_infix_len: 1
4
4
  test:
5
5
  enable_star: 1
6
- min_infix_len: 2
6
+ min_infix_len: 1
7
7
  production:
8
8
  enable_star: 1
9
- min_infix_len: 2
9
+ min_infix_len: 1