social_stream 0.9.6 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,21 +3,18 @@ class ContactsController < ApplicationController
3
3
  before_filter :exclude_reflexive, :except => [ :index, :pending ]
4
4
 
5
5
  def index
6
- if params[:pending].present?
7
- pending
8
- return
9
- end
10
6
  @contacts =
11
- Contact.sent_by(current_subject).
12
- joins(:receiver).merge(Actor.alphabetic).
13
- merge(Actor.letter(params[:letter])).
14
- merge(Actor.name_search(params[:search])).
15
- active
7
+ Contact.sent_by(current_subject).
8
+ joins(:receiver).merge(Actor.alphabetic).
9
+ merge(Actor.letter(params[:letter])).
10
+ merge(Actor.name_search(params[:search])).
11
+ related_by_param(params[:relation]).
12
+ active
16
13
 
17
14
  respond_to do |format|
18
15
  format.html { @contacts = @contacts.page(params[:page]).per(10) }
19
16
  format.js { @contacts = @contacts.page(params[:page]).per(10) }
20
- format.json { render :text => @contacts.map{ |c| { 'key' => c.receiver_id.to_s, 'value' => self.class.helpers.truncate_name(c.receiver.name) } }.to_json }
17
+ format.json { render :text => to_json(@contacts) }
21
18
  end
22
19
  end
23
20
 
@@ -51,9 +48,14 @@ class ContactsController < ApplicationController
51
48
  @contacts = current_subject.pending_contacts
52
49
 
53
50
  respond_to do |format|
54
- format.html { @contacts = Kaminari.paginate_array(@contacts).page(params[:page]).per(10) }
55
- format.js { @contacts = Kaminari.paginate_array(@contacts).page(params[:page]).per(10) }
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 }
51
+ format.html {
52
+ @contacts = Kaminari.paginate_array(@contacts).page(params[:page]).per(10)
53
+ render :action => :index
54
+ }
55
+ format.js {
56
+ @contacts = Kaminari.paginate_array(@contacts).page(params[:page]).per(10)
57
+ render :action => :index
58
+ }
57
59
  end
58
60
  end
59
61
 
@@ -66,4 +68,23 @@ class ContactsController < ApplicationController
66
68
  redirect_to home_path
67
69
  end
68
70
  end
71
+
72
+ def to_json(contacts)
73
+ contacts.map{ |c|
74
+ if params[:form].present?
75
+ {
76
+ 'key' => c.receiver_id.to_s,
77
+ 'value' => self.class.helpers.truncate_name(c.receiver.name)
78
+ }
79
+ else
80
+ {
81
+ 'name' => c.receiver.name,
82
+ 'url' => polymorphic_url(c.receiver_subject),
83
+ 'image' => {
84
+ 'url' => root_url + c.receiver.logo.url
85
+ }
86
+ }
87
+ end
88
+ }.to_json
89
+ end
69
90
  end
@@ -57,6 +57,12 @@ class Contact < ActiveRecord::Base
57
57
  joins("LEFT JOIN contacts AS inverse_contacts ON inverse_contacts.id = contacts.inverse_id").
58
58
  where(arel_table[:inverse_id].eq(nil).or(arel_table.alias("inverse_contacts")[:ties_count].eq(0)))
59
59
 
60
+ scope :related_by_param, lambda { |p|
61
+ if p.present?
62
+ joins(:ties).merge(Tie.where(:relation_id => p))
63
+ end
64
+ }
65
+
60
66
 
61
67
  validates_presence_of :sender_id, :receiver_id
62
68
  validates_uniqueness_of :sender_id, :scope => :receiver_id
@@ -3,7 +3,7 @@ require 'devise/orm/active_record'
3
3
  class User < ActiveRecord::Base
4
4
  include SocialStream::Models::Subject
5
5
 
6
- has_many :authentications
6
+ has_many :authentications, :dependent => :destroy
7
7
  devise *SocialStream.devise_modules
8
8
 
9
9
  # Setup accessible (or protected) attributes for your model
@@ -9,7 +9,7 @@
9
9
  <div class="content">
10
10
  <%= render current_subject.pending_contacts.shuffle.first(2) %>
11
11
  <div class="row more_pending">
12
- <%= link_to t('contact.pending.all_n', :count => current_subject.pending_contacts_count), contacts_path(:pending=>true)%>
12
+ <%= link_to t('contact.pending.all_n', :count => current_subject.pending_contacts_count), pending_contacts_path %>
13
13
  </div>
14
14
  <div class="space_center">
15
15
  </div>
@@ -3,7 +3,7 @@
3
3
  $(".new_group").validate();
4
4
  });
5
5
  $("#group__participants").fcbkcomplete({
6
- json_url: "<%= contacts_path(:format => :json) %>",
6
+ json_url: "<%= contacts_path(:form => true, :format => :json) %>",
7
7
  cache: true,
8
8
  filter_hide: true,
9
9
  newel: false,
@@ -15,7 +15,7 @@
15
15
  <% content_for :javascript do %>
16
16
 
17
17
  var recipients = $("#_recipients").fcbkcomplete({
18
- json_url: "<%= contacts_path(:format => :json) %>",
18
+ json_url: "<%= contacts_path(:form => true, :format => :json) %>",
19
19
  cache: true,
20
20
  filter_hide: true,
21
21
  newel: false,
@@ -9,7 +9,7 @@ $("#content").html("<%= escape_javascript(render :partial => 'new') %>");
9
9
 
10
10
 
11
11
  var recipients = $("#_recipients").fcbkcomplete({
12
- json_url: "<%= contacts_path(:format => :json) %>",
12
+ json_url: "<%= contacts_path(:form => true, :format => :json) %>",
13
13
  cache: true,
14
14
  filter_hide: true,
15
15
  newel: false,
@@ -1,4 +1,3 @@
1
- <div>
2
1
  <form action="<%= search_path %>" method="get" data-remote="true" id="search_form">
3
2
  <div class="block">
4
3
  <div class="error" id="too_short_error" <%= too_short_query? ? 'style=display:block;' : '' %>><%= t('search.at_least') %></div>
@@ -20,7 +19,6 @@
20
19
  </div>
21
20
  </div>
22
21
  </form>
23
- </div>
24
22
 
25
23
  <%= javascript_tag do %>
26
24
  $(document).ready(function() {
@@ -3,7 +3,9 @@
3
3
  <div class="space_center"></div>
4
4
  <h2><%= t('search.name') %></h2>
5
5
  <div class="space_center"></div>
6
+ <div id="search_form_div">
6
7
  <%= render :partial => 'form' %>
8
+ </div>
7
9
  <div class="space_center"></div>
8
10
  <div class="space_center"></div>
9
11
  <div id="search_results" class="block">
@@ -1,6 +1,5 @@
1
- //if ($('#global_search_input').val()=="<%= params[:search_query]%>"){
2
-
3
1
  $('#search_results').html("<% unless params[:focus].present? %><%= escape_javascript render :partial => 'global_search' %><% else %><%= escape_javascript render :partial => 'focus_search' %><% end %>");
2
+ $('#search_form_div').html("<%= escape_javascript render :partial => 'form' %>");
4
3
 
5
4
  $('#focus_options ul li a span').removeClass('selected');
6
5
 
@@ -19,7 +18,3 @@
19
18
  <% end %>
20
19
 
21
20
  $('#global_search_input').removeClass("searching");
22
-
23
- /*}else{
24
- alert("ignored <%= params[:search_query]%>");
25
- }*/
@@ -19,6 +19,9 @@ Rails.application.routes.draw do
19
19
  match 'api/user/:id' => 'api#users'
20
20
  match 'api/me' => 'api#users'
21
21
  match 'api/me/home/' => 'api#activity_atom_feed', :format => 'atom', :as => :api_my_home
22
+ match 'api/me/contacts' => 'contacts#index', :format => 'json'
23
+ match 'api/subjects/:s/contacts' => 'contacts#index', :format => 'json'
24
+ match 'api/user/:id/public' => 'api#activity_atom_feed', :format => 'atom'
22
25
  match 'api/user/:id/public' => 'api#activity_atom_feed', :format => 'atom'
23
26
  ##/API##
24
27
 
@@ -34,7 +37,11 @@ Rails.application.routes.draw do
34
37
  end
35
38
  end
36
39
 
37
- resources :contacts
40
+ resources :contacts do
41
+ collection do
42
+ get 'pending'
43
+ end
44
+ end
38
45
 
39
46
  namespace "relation" do
40
47
  resources :customs
@@ -1,5 +1,5 @@
1
1
  module SocialStream
2
2
  module Base
3
- VERSION = "0.9.9".freeze
3
+ VERSION = "0.9.10".freeze
4
4
  end
5
5
  end
@@ -38,7 +38,7 @@ module SocialStream
38
38
  :items => [
39
39
  {:key => :invitations, :name => image_tag("btn/btn_friend.png")+t('contact.current'), :url => contacts_path},
40
40
  {:key => :contacts_graph, :name => image_tag("btn/btn_friend.png")+t('contact.graph.one'), :url => ties_path},
41
- {:key => :invitations, :name => image_tag("btn/btn_friend.png")+t('contact.pending.other'), :url => contacts_path(:pending=>true)},
41
+ {:key => :invitations, :name => image_tag("btn/btn_friend.png")+t('contact.pending.other'), :url => pending_contacts_path},
42
42
  {:key => :invitations, :name => image_tag("btn/btn_invitation.png")+t('invitation.toolbar'), :url => new_invitation_path}
43
43
  ]
44
44
  }
@@ -34,4 +34,20 @@ describe Contact do
34
34
  @contact.sender.pending_contacts.should_not include(@contact)
35
35
  end
36
36
  end
37
+
38
+ context "a pair" do
39
+ before do
40
+ @friend = Factory(:friend)
41
+ @sender = @friend.sender
42
+ @acquaintance = Factory(:acquaintance,
43
+ :contact => Factory(:contact,
44
+ :sender => @sender))
45
+ end
46
+
47
+ it "should scope friend" do
48
+ Contact.sent_by(@sender).count.should eq(2)
49
+ Contact.sent_by(@sender).related_by_param(nil).count.should eq(2)
50
+ Contact.sent_by(@sender).related_by_param(@friend.relation_id).count.should eq(1)
51
+ end
52
+ end
37
53
  end
@@ -1,3 +1,3 @@
1
1
  module SocialStream
2
- VERSION = "0.9.6".freeze
2
+ VERSION = "0.9.7".freeze
3
3
  end
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.files = `git ls-files`.split("\n")
12
12
 
13
13
  # Gem dependencies
14
- s.add_runtime_dependency('social_stream-base', '~> 0.9.9')
14
+ s.add_runtime_dependency('social_stream-base', '~> 0.9.10')
15
15
  s.add_runtime_dependency('social_stream-documents', '~> 0.2.8')
16
16
 
17
17
  # Development Gem dependencies
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_stream
3
3
  version: !ruby/object:Gem::Version
4
- hash: 55
4
+ hash: 53
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 6
10
- version: 0.9.6
9
+ - 7
10
+ version: 0.9.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - GING - DIT - UPM
@@ -27,12 +27,12 @@ dependencies:
27
27
  requirements:
28
28
  - - ~>
29
29
  - !ruby/object:Gem::Version
30
- hash: 41
30
+ hash: 47
31
31
  segments:
32
32
  - 0
33
33
  - 9
34
- - 9
35
- version: 0.9.9
34
+ - 10
35
+ version: 0.9.10
36
36
  type: :runtime
37
37
  version_requirements: *id001
38
38
  - !ruby/object:Gem::Dependency