social_stream 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,11 +4,11 @@ class LikesController < ApplicationController
4
4
 
5
5
  # POST /activities/1/like.js
6
6
  def create
7
- @like = activity!.children.new :verb => "like"
7
+ @like = activity!.children.new :verb => "like",
8
+ :_tie => tie!
8
9
 
9
10
  respond_to do |format|
10
11
  if @like.save
11
- tie!.activities << @like
12
12
  format.js
13
13
  else
14
14
  format.js
@@ -25,11 +25,14 @@ class UsersController < ApplicationController
25
25
  respond_to do |format|
26
26
  if @user.update_attributes(params[:user])
27
27
  #format.html { redirect_to(@user, :notice => 'User was successfully updated.') }
28
- format.html { render :action => "edit", :notice => 'User was successfully updated.' }
28
+ #format.html { render :action => "edit", :notice => 'User was successfully updated.' }
29
+ format.html { render :partial => "right_show", :notice => 'User was successfully updated.' }
29
30
  format.xml { head :ok }
31
+ format.js
30
32
  else
31
33
  format.html { render :action => "edit" }
32
34
  format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
35
+ format.js
33
36
  end
34
37
  end
35
38
  end
@@ -12,18 +12,16 @@ class Activity < ActiveRecord::Base
12
12
 
13
13
  belongs_to :activity_verb
14
14
 
15
- belongs_to :tie,
16
- :include => [ :sender ]
17
-
18
- has_one :sender,
19
- :through => :tie
20
- has_one :receiver,
21
- :through => :tie
22
- has_one :relation,
23
- :through => :tie
24
-
25
- delegate :sender_subject,
26
- :receiver_subject,
15
+ has_many :tie_activities, :dependent => :destroy
16
+ has_many :ties, :through => :tie_activities
17
+
18
+ has_one :tie,
19
+ :through => :tie_activities,
20
+ :conditions => { 'tie_activities.original' => true },
21
+ :include => [ :sender ]
22
+
23
+ delegate :sender, :receiver, :relation,
24
+ :sender_subject, :receiver_subject,
27
25
  :to => :tie
28
26
 
29
27
  has_many :activity_object_activities,
@@ -34,10 +32,15 @@ class Activity < ActiveRecord::Base
34
32
  scope :wall, lambda { |ties|
35
33
  select("DISTINCT activities.*").
36
34
  roots.
37
- where(:tie_id => ties).
35
+ joins(:tie_activities).
36
+ where('tie_activities.tie_id' => ties).
38
37
  order("created_at desc")
39
38
  }
40
39
 
40
+ # After an activity is created, it is associated to ties
41
+ attr_accessor :_tie
42
+ after_create :assign_to_ties
43
+
41
44
  # The name of the verb of this activity
42
45
  def verb
43
46
  activity_verb.name
@@ -59,7 +62,7 @@ class Activity < ActiveRecord::Base
59
62
  end
60
63
 
61
64
  def liked_by(user) #:nodoc:
62
- likes.includes(:tie) & Tie.sent_by(user)
65
+ likes.joins(:ties).where('tie_activities.original' => true) & Tie.sent_by(user)
63
66
  end
64
67
 
65
68
  # Does user like this activity?
@@ -72,4 +75,13 @@ class Activity < ActiveRecord::Base
72
75
  activity_objects.first.try(:object)
73
76
  end
74
77
 
78
+ private
79
+
80
+ def assign_to_ties
81
+ original = tie_activities.create!(:tie => _tie)
82
+ _tie.activity_receivers.each do |t|
83
+ tie_activities.create!(:tie => t,
84
+ :original => false)
85
+ end
86
+ end
75
87
  end
data/app/models/tie.rb CHANGED
@@ -41,7 +41,8 @@ class Tie < ActiveRecord::Base
41
41
 
42
42
  belongs_to :relation
43
43
 
44
- has_many :activities
44
+ has_many :tie_activities, :dependent => :destroy
45
+ has_many :activities, :through => :tie_activities
45
46
 
46
47
  scope :recent, order("#{ quoted_table_name }.created_at DESC")
47
48
 
@@ -68,7 +69,7 @@ class Tie < ActiveRecord::Base
68
69
  scope :inverse, lambda { |t|
69
70
  sent_by(t.receiver).
70
71
  received_by(t.sender).
71
- where(:relation_id => t.relation.inverse_id)
72
+ where(:relation_id => t.relation.inverse.try(:id))
72
73
  }
73
74
 
74
75
  validates_presence_of :sender_id, :receiver_id, :relation_id
@@ -121,6 +122,10 @@ class Tie < ActiveRecord::Base
121
122
  Tie.inverse(self).first
122
123
  end
123
124
 
125
+ def activity_receivers
126
+ Array(inverse)
127
+ end
128
+
124
129
  # = Access Control
125
130
  #
126
131
  # Access control enforcement in ties come from the permissions assigned to other ties through relations.
@@ -0,0 +1,4 @@
1
+ class TieActivity < ActiveRecord::Base
2
+ belongs_to :activity
3
+ belongs_to :tie
4
+ end
data/app/models/user.rb CHANGED
@@ -2,7 +2,8 @@ require 'devise/orm/active_record'
2
2
 
3
3
  class User < ActiveRecord::Base
4
4
  devise *SocialStream.devise_modules
5
- has_one :profile
5
+
6
+ has_one :profile, :dependent => :destroy
6
7
  accepts_nested_attributes_for :profile
7
8
 
8
9
  # Setup accessible (or protected) attributes for your model
@@ -26,9 +27,9 @@ class User < ActiveRecord::Base
26
27
 
27
28
 
28
29
  def age
29
- return nil if self.birthday.blank?
30
+ return nil if profile.birthday.blank?
30
31
  now = Time.now.utc.to_date
31
- now.year - self.birthday.year - (self.birthday.to_date.change(:year => now.year) > now ? 1 : 0)
32
+ now.year - profile.birthday.year - (profile.birthday.to_date.change(:year => now.year) > now ? 1 : 0)
32
33
  end
33
34
 
34
35
  after_create :create_profile
@@ -10,7 +10,7 @@
10
10
  <div id="map_location" class="content_size">
11
11
  Your are here ><img src="images/btn/btn_browse.png" class="btn_config"%> <%=t('browse')%>: <span id="name_group"><%= t('group.other')%></span>
12
12
  </div>
13
- <div id="by_options" class="content_size"><%=link_to ( t('user.by'),users_path )%> </div>
13
+ <div id="by_options" class="content_size"><%= link_to(t('user.by'), users_path) %> </div>
14
14
  <br class="clearfloat" />
15
15
  <div class="space_center">
16
16
  </div>
@@ -18,15 +18,13 @@
18
18
  <%= stylesheet_link_tag "carousel", :media => "screen, projection" %>
19
19
  <%= stylesheet_link_tag "smoothness/jquery-ui-1.8.4.custom", :media => "screen, projection" %>
20
20
  <%= stylesheet_link_tag "ui.dropdownchecklist", :media => "screen, projection" %>
21
- <!-- datepicker css -->
22
- <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
23
- <%= stylesheet_link_tag "edit_user", :media => "screen, projection" %>
24
-
21
+ <%= stylesheet_link_tag "jquery-ui.css", :media => "screen, projection" %>
25
22
 
23
+ <%= stylesheet_link_tag "edit_user", :media => "screen, projection" %>
26
24
  <%= javascript_include_tag :defaults %>
27
25
 
28
26
  <%= javascript_include_tag 'jquery', 'jquery-ui.min', 'jquery.livequery',
29
- 'jquery.boxy', 'menu','ui.dropdownchecklist' %>
27
+ 'jquery.boxy', 'menu','ui.dropdownchecklist','jquery.form', 'jquery.validate' %>
30
28
 
31
29
 
32
30
  <% if protect_against_forgery? %>
@@ -46,6 +44,13 @@
46
44
  <%= render :partial => "layouts/header" %>
47
45
  <div id="wrapper_body">
48
46
  <div id="content">
47
+
48
+ <% flash.each do |name, msg| %>
49
+ <div id="<%= name %>">
50
+ <%= msg %>
51
+ </div>
52
+ <% end %>
53
+
49
54
  <%= yield %>
50
55
  </div>
51
56
  <div id="middle">
@@ -21,7 +21,7 @@
21
21
  <div class="banner_busqueda">
22
22
  <div id="espacio_busqueda">
23
23
  <% flash.each do |name, msg| %>
24
- <div class="<%= name %>">
24
+ <div id="<%= name %>">
25
25
  <%= msg %>
26
26
  </div>
27
27
  <% end %>
@@ -1,7 +1,7 @@
1
1
  <div class="dialog_add_tie" id="new_tie">
2
2
  <div class="content_add_user" >
3
3
  <div class="tie_logo">
4
- <%= link_to image_tag(@tie.receiver_subject.logo.url(tie),
4
+ <%= link_to image_tag(@tie.receiver_subject.logo.url(:profile),
5
5
  :size => "100x100",
6
6
  :alt => @tie.receiver_subject.name),
7
7
  @tie.receiver_subject %>
@@ -28,7 +28,7 @@
28
28
  BirthDay:
29
29
  </div>
30
30
  <div class="info_right">
31
- <%=h @user.birthday.to_s() %>
31
+ <%=h @user.profile.birthday.to_s() %>
32
32
  </div>
33
33
  </div>
34
34
  <div class="info_post">
@@ -78,6 +78,14 @@
78
78
  <a href="<%=h @user.profile.website %>"><%=h @user.profile.website %></a>
79
79
  </div>
80
80
  </div>
81
+ <div class="info_post">
82
+ <div>
83
+ E-mail
84
+ </div>
85
+ <div class="contact_link">
86
+ <%=h @user.email %>
87
+ </div>
88
+ </div>
81
89
  </div>
82
90
  </div>
83
91
  </div>
@@ -6,8 +6,9 @@
6
6
  <%= render :partial => 'middle_show' %>
7
7
  <% end %>
8
8
 
9
+
9
10
 
10
- <%= form_for(@user) do |f| %>
11
+ <%= form_for(@user, :remote => true) do |f| %>
11
12
  <% if @user.errors.any? %>
12
13
  <div id="error_explanation">
13
14
  <h2><%= pluralize(@user.errors.count, "error") %>prohibited this user from being saved:</h2>
@@ -29,7 +30,10 @@
29
30
  $("#personal_info").addClass('section_normal');
30
31
  $("#contacts").addClass('section_normal');
31
32
  $(".space_profile").addClass('section_normal');
32
- });
33
+
34
+ $("#edit_user_1").validate();
35
+
36
+ });
33
37
  </script>
34
38
  <div class="field">
35
39
  <% if !params[:section].present? or params[:section].eql?("about_me") %>
@@ -39,28 +43,31 @@
39
43
  <br/>
40
44
  <%= f.label :name %>
41
45
  <br/>
42
- <%= f.text_field :name %>
46
+
47
+ <%= f.text_field :name, :class => "required" %>
48
+
43
49
  <br/>
44
50
  <script type="text/javascript">
45
51
 
46
52
  $(function() {
47
- $( "#user_birthday" ).datepicker({ yearRange: '1900:<%= Time.now.utc.to_date.year%>',
53
+ $( "#user_profile_attributes_birthday" ).datepicker({ yearRange: '1900:<%= Time.now.utc.to_date.year%>',
48
54
  changeYear: true, maxDate: '+0d', defaultDate: '-30y'});
49
55
 
50
56
  $("#personal_info").removeClass('section_normal');
51
57
  $("#personal_info").addClass('section_highlight');
52
- });
58
+
59
+ });
53
60
 
54
61
  </script>
55
-
62
+ <%= f.fields_for :profile do |profile_form| %>
56
63
  <div class="editField">
57
- <%= f.label :birthday %>
64
+ <%= profile_form.label :birthday %>
58
65
  <br/>
59
66
  </div>
60
- <%= f.text_field :birthday %>
67
+ <%= profile_form.text_field :birthday , :class => "date" %>
61
68
  <br/>
62
69
 
63
- <%= f.fields_for :profile do |profile_form| %>
70
+
64
71
  <div class="editField">
65
72
  <%= profile_form.label :organization %>
66
73
  <br/>
@@ -83,7 +90,7 @@
83
90
  <%= profile_form.label "About me" %>
84
91
  <br/>
85
92
  </div>
86
- <%= profile_form.text_area :description, :rows =>6 %>
93
+ <%= profile_form.text_area :description, :rows =>6, :maxlength => 400 %>
87
94
  <br/>
88
95
  <br/>
89
96
  <% end %>
@@ -107,19 +114,19 @@
107
114
  <%= profile_form.label :phone %>
108
115
  <br/>
109
116
  </div>
110
- <%= profile_form.text_field :phone %>
117
+ <%= profile_form.text_field :phone, :class => "digits" %>
111
118
  <br/>
112
119
  <div class="editField">
113
120
  <%= profile_form.label :mobile %>
114
121
  <br/>
115
122
  </div>
116
- <%= profile_form.text_field :mobile %>
123
+ <%= profile_form.text_field :mobile, :class => "digits" %>
117
124
  <br/>
118
125
  <div class="editField">
119
126
  <%= profile_form.label :fax %>
120
127
  <br/>
121
128
  </div>
122
- <%= profile_form.text_field :fax %>
129
+ <%= profile_form.text_field :fax, :class => "digits" %>
123
130
  <br/>
124
131
  <div class="editField">
125
132
  <%= profile_form.label :address %>
@@ -131,7 +138,7 @@
131
138
  <%= profile_form.label :website %>
132
139
  <br/>
133
140
  </div>
134
- <%= profile_form.text_field :website %>
141
+ <%= profile_form.text_field :website, :class => "url" %>
135
142
  <br/>
136
143
  <br/>
137
144
  <% end %>
@@ -151,7 +158,7 @@
151
158
  </div>
152
159
  <%= f.fields_for :profile do |profile_form| %>
153
160
  <br/>
154
- <%= profile_form.text_area :experience, :rows =>6 %>
161
+ <%= profile_form.text_area :experience, :rows =>6, :maxlength => 500 %>
155
162
  <br/>
156
163
  <br/>
157
164
  <% end %>
@@ -0,0 +1,20 @@
1
+
2
+ <% if @user.valid? %>
3
+
4
+
5
+ if ($("#notice").length == 0){
6
+
7
+ $("#content").prepend('<div id="notice"></div>');
8
+
9
+ }
10
+ $("#notice").html("<h2>Form Submitted!</h2>");
11
+
12
+ $("#middleContent").replaceWith("<%= escape_javascript(render(:partial => 'middle_show'))%>");
13
+
14
+ <% else %>
15
+
16
+ $("#flash_error").html("<h2>Fail!</h2>");
17
+
18
+ <% end %>
19
+
20
+
data/bin/social_stream ADDED
@@ -0,0 +1,57 @@
1
+ #!/bin/bash
2
+ #Social_stream complete install
3
+ #Arguments:
4
+ #$1 --> Name of the folder to create the social_stream project
5
+ EXPECTED_ARGS=1
6
+
7
+ if [ $# -ne $EXPECTED_ARGS ]
8
+ then
9
+ echo "Usage: `basename $0` path/to/your/application"
10
+ exit 1
11
+ fi
12
+
13
+
14
+ #Linux packages
15
+ echo 'Installing Linux packages'
16
+ PACKAGES_COMMON='ruby ruby-dev rdoc irb libopenssl-ruby wget make curl aspell-es aspell-en libxml2-dev libxslt-dev libmagickcore-dev libmagickwand-dev libsqlite3-dev libmysqlclient-dev mysql-server rake'
17
+ PACKAGES_PRODUCTION='awstats logrotate nfs-common'
18
+ sudo apt-get install $PACKAGES_COMMON
19
+ sudo apt-get install $PACKAGES_PRODUCTION
20
+ echo 'Done'
21
+
22
+ #Rubygems
23
+ RUBY_GEMS_VERSION='1.3.7'
24
+ RUBY_GEMS_PACKAGE="rubygems-"${RUBY_GEMS_VERSION}".tgz"
25
+ RUBY_GEMS_DOWNLOAD="http://rubyforge.org/frs/download.php/70696/"${RUBY_GEMS_PACKAGE}
26
+
27
+ echo 'Installing Rubygems $RUBY_GEMS_VERSION'
28
+
29
+ cd /tmp && wget $RUBY_GEMS_DOWNLOAD
30
+ cd /tmp && tar zxf $RUBY_GEMS_PACKAGE
31
+ cd /tmp/rubygems-$RUBY_GEMS_VERSION && sudo /usr/bin/ruby setup.rb
32
+
33
+ sudo ln -s /usr/bin/gem1.8 /usr/bin/gem
34
+ echo 'Done'
35
+
36
+ #Gems
37
+ echo 'Installing Initial Gems'
38
+ sudo gem install rails
39
+ sudo gem install bundler
40
+ echo 'Done'
41
+
42
+ #Social Stream
43
+ echo 'Creating and Setting up your Social Stream basic application'
44
+ export PATH=$PATH:/var/lib/gems/1.8/bin
45
+ echo 'Creating rails project'
46
+ rails new $1
47
+ cd $1
48
+ echo 'gem "social_stream"' >> Gemfile
49
+ echo 'Updating bundle'
50
+ bundle update
51
+ echo 'Setting up the application'
52
+ rails generate social_stream:install -y
53
+ rake db:migrate
54
+ rake db:seed
55
+ echo 'Done'
56
+
57
+ echo 'Instalation complete. Run "rails server" in the application folder to start the server'
@@ -2,14 +2,12 @@ class CreateSocialStream < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table "activities", :force => true do |t|
4
4
  t.integer "activity_verb_id"
5
- t.integer "tie_id"
6
5
  t.datetime "created_at"
7
6
  t.datetime "updated_at"
8
7
  t.string "ancestry"
9
8
  end
10
9
 
11
10
  add_index "activities", "activity_verb_id"
12
- add_index "activities", "tie_id"
13
11
 
14
12
  create_table "activity_object_activities", :force => true do |t|
15
13
  t.integer "activity_id"
@@ -99,6 +97,7 @@ class CreateSocialStream < ActiveRecord::Migration
99
97
 
100
98
  create_table "profiles", :force => true do |t|
101
99
  t.integer "user_id"
100
+ t.date "birthday"
102
101
  t.datetime "created_at"
103
102
  t.datetime "updated_at"
104
103
  t.string "organization", :limit => 45
@@ -161,6 +160,17 @@ class CreateSocialStream < ActiveRecord::Migration
161
160
  add_index "tags_activity_objects", "activity_object_id"
162
161
  add_index "tags_activity_objects", "tag_id"
163
162
 
163
+ create_table "tie_activities", :force => true do |t|
164
+ t.integer "tie_id"
165
+ t.integer "activity_id"
166
+ t.boolean "read"
167
+ t.boolean "deleted"
168
+ t.boolean "original", :default => true
169
+ end
170
+
171
+ add_index "tie_activities", "tie_id"
172
+ add_index "tie_activities", "activity_id"
173
+
164
174
  create_table "ties", :force => true do |t|
165
175
  t.integer "sender_id"
166
176
  t.integer "receiver_id"
@@ -198,7 +208,6 @@ class CreateSocialStream < ActiveRecord::Migration
198
208
  # add_index :users, :unlock_token, :unique => true
199
209
 
200
210
  add_foreign_key "activities", "activity_verbs", :name => "index_activities_on_activity_verb_id"
201
- add_foreign_key "activities", "ties", :name => "index_activities_on_tie_id"
202
211
 
203
212
  add_foreign_key "activity_object_activities", "activities", :name => "index_activity_object_activities_on_activity_id"
204
213
  add_foreign_key "activity_object_activities", "activity_objects", :name => "activity_object_activities_on_activity_object_id"
@@ -219,6 +228,9 @@ class CreateSocialStream < ActiveRecord::Migration
219
228
  add_foreign_key "tags_activity_objects", "activity_objects", :name => "tags_activity_objects_on_activity_object_id"
220
229
  add_foreign_key "tags_activity_objects", "tags", :name => "tags_activity_objects_on_tag_id"
221
230
 
231
+ add_foreign_key "tie_activities", "ties", :name => "tie_activities_on_tie_id"
232
+ add_foreign_key "tie_activities", "activities", :name => "tie_activities_on_activity_id"
233
+
222
234
  add_foreign_key "ties", "actors", :name => "ties_on_receiver_id", :column => "receiver_id"
223
235
  add_foreign_key "ties", "actors", :name => "ties_on_relation_id", :column => "sender_id"
224
236
  add_foreign_key "ties", "relations", :name => "ties_on_sender_id"
@@ -227,13 +239,43 @@ class CreateSocialStream < ActiveRecord::Migration
227
239
  end
228
240
 
229
241
  def self.down
242
+ remove_foreign_key "activities", :name => "index_activities_on_activity_verb_id"
243
+
244
+ remove_foreign_key "activity_object_activities", :name => "index_activity_object_activities_on_activity_id"
245
+ remove_foreign_key "activity_object_activities", :name => "activity_object_activities_on_activity_object_id"
246
+
247
+ remove_foreign_key "actors", :name => "actors_on_activity_object_id"
248
+
249
+ remove_foreign_key "comments", :name => "comments_on_activity_object_id"
250
+
251
+ remove_foreign_key "groups", :name => "groups_on_actor_id"
252
+
253
+ remove_foreign_key "posts", :name => "posts_on_activity_object_id"
254
+
255
+ remove_foreign_key "profiles", :name => "profiles_on_user_id"
256
+
257
+ remove_foreign_key "relation_permissions", :name => "relation_permissions_on_relation_id"
258
+ remove_foreign_key "relation_permissions", :name => "relation_permissions_on_permission_id"
259
+
260
+ remove_foreign_key "tags_activity_objects", :name => "tags_activity_objects_on_activity_object_id"
261
+ remove_foreign_key "tags_activity_objects", :name => "tags_activity_objects_on_tag_id"
262
+
263
+ remove_foreign_key "tie_activities", :name => "tie_activities_on_tie_id"
264
+ remove_foreign_key "tie_activities", :name => "tie_activities_on_activity_id"
265
+
266
+ remove_foreign_key "ties", :name => "ties_on_receiver_id", :column => "receiver_id"
267
+ remove_foreign_key "ties", :name => "ties_on_relation_id", :column => "sender_id"
268
+ remove_foreign_key "ties", :name => "ties_on_sender_id"
269
+
270
+ remove_foreign_key "users", :name => "users_on_actor_id"
271
+
230
272
  drop_table :activities
231
273
  drop_table :activity_object_activities
232
274
  drop_table :activity_objects
233
275
  drop_table :activity_verbs
234
276
  drop_table :actors
235
277
  drop_table :comments
236
- drop_table :group
278
+ drop_table :groups
237
279
  drop_table :permissions
238
280
  drop_table :posts
239
281
  drop_table :private_messages