Commit 68d4a13301685de7bd15c9e2a9d1fe2875257f02

New message added
Moved journals from a model subdir as was causing issue

Commit diff

app/controllers/activities_controller.rb

 
1010 else
1111 @messages = Message.find_by_project(@project.id, 40)
1212 end
13 render :action => "ac_index"
13 render :action => "ac_project_index"
1414 end
1515
16 def create
17 @message = Message.new(params[:message])
18 @message.user_id = current_user.id
19 @message.project_id = @project.id
20 if @message.save
21 Journal.create(@message, request.env["REMOTE_ADDR"], @project.id, current_user.id).to_s
22 redirect_to project_activities_path(@project.slug)
23 else
24 #FIXME this is wrong I think
25 flash[:error] = 'Error.'
26 render :action => 'ac_project_new'
27 end
28 end
1629
1730end
toggle raw diff

app/models/change.rb

 
1class Change < ActiveRecord::Base
2end
toggle raw diff

app/models/changed_boolean.rb

 
1class ChangedBoolean < ActiveRecord::Base
2end
toggle raw diff

app/models/changed_datetime.rb

 
1class ChangedDatetime < ActiveRecord::Base
2end
toggle raw diff

app/models/changed_enum.rb

 
1class ChangedEnum < ActiveRecord::Base
2end
toggle raw diff

app/models/changed_float.rb

 
1class ChangedFloat < ActiveRecord::Base
2end
toggle raw diff

app/models/changed_integer.rb

 
1class ChangedInteger < ActiveRecord::Base
2end
toggle raw diff

app/models/changed_string.rb

 
1class ChangedString < ActiveRecord::Base
2end
toggle raw diff

app/models/changed_text.rb

 
1class ChangedText < ActiveRecord::Base
2end
toggle raw diff

app/models/journal.rb

 
1#
2# Journal records changes to a model
3#
4# You call it when create a new wiki or article etc.
5# You call it when you update a model
6# It records the differences
7#
8# You can then view the change history of a ticket etc.
9#
10class Journal < ActiveRecord::Base
11
12 #
13 # Create journal entry
14 # model: @wiki | @article etc.
15 # ip: IP address
16 # user_id: user id of changer
17 #
18 def self.create (model, ip, project_id, user_id)
19 # record that something has happened
20 journal = Journal.new
21 journal.action = :create
22 journal.model_type = model.class.to_s
23 journal.row_id = model.id
24 journal.ip = ip
25 journal.user_id = user_id
26 #TODO check saves okay
27 journal.save
28 #
29 for column in model.class.columns
30 #filter columns we don't want to track
31 case column.name
32 when "created_at", "updated_at", "views", "id"
33 else
34 change = Change.new
35 change.journal_id = journal.id
36 change.model_column = column.name
37 change.datatype = column.class
38 #
39 case column.type
40 when :integer
41 c = ChangedInteger.new
42 when :float
43 c = ChangedFloat.new
44 when :string
45 c = ChangedString.new
46 when :text
47 c = ChangedText.new
48 when :boolean
49 c = ChangedBoolean.new
50 when :datetime, :date, :time
51 c = ChangedDatetime.new
52 when :enum
53 c = ChangedEnum.new
54 else
55 #TODO raise some unknown type exception
56 end
57 #
58 c.data = model[column.name]
59 #TODO check saves okay
60 c.save
61 change.data_id = c.id
62 #TODO check saves okay
63 change.save
64 end
65 end
66
67 #TODO check error
68 e = Event.new
69 e.project_id = project_id if project_id
70 e.user_id = user_id if user_id
71 e.entry_type = :journal
72 e.entry_id = journal.id
73 e.save
74 end
75
76 #
77 # Update journal entry
78 # model: @wiki | @article etc.
79 # ip: IP address
80 # user_id: user id of changer
81 #
82 def self.update (original_model, updated_model, ip, project_id, user_id)
83
84 # record that something has happened
85 journal = Journal.new
86 journal.action = :update
87 journal.model_type = updated_model.type.to_s
88 journal.row_id = updated_model.id
89 journal.ip = ip
90 journal.user_id = user_id
91 #TODO check saves okay
92 journal.save
93 #
94 s = ""
95 for column in updated_model.type.columns
96 #s << original_model[column.name].to_s << "/" + updated_model[column.name].to_s << "</br>"
97 if original_model[column.name] != updated_model[column.name]
98 #filter columns we don't want to track
99 case column.name
100 when "created_at", "updated_at", "views", "id"
101 else
102 change = Change.new
103 change.journal_id = journal.id
104 change.model_column = column.name
105 change.datatype = column.type
106 #
107 case column.type
108 when :integer
109 c = ChangedInteger.new
110 when :float
111 c = ChangedFloat.new
112 when :string
113 c = ChangedString.new
114 when :text
115 c = ChangedText.new
116 when :boolean
117 c = ChangedBoolean.new
118 when :datetime, :date, :time
119 c = ChangedDatetime.new
120 when :enum
121 c = ChangedEnum.new
122 else
123 #TODO raise some unknown type exception
124 end
125 #
126 c.data = updated_model[column.name]
127 #TODO check saves okay
128 c.save
129 change.data_id = c.id
130 #TODO check saves okay
131 change.save
132 end
133 end
134 end
135
136 #TODO insert an event
137 e = Event.new
138 e.project_id = project_id if project_id
139 e.user_id = user_id if user_id
140 e.entry_type = :journal
141 e.entry_id = journal.id
142 e.save
143
144 end
145
146end
147
148
149
toggle raw diff

app/models/journal/change.rb

 
0class Change < ActiveRecord::Base
1end
toggle raw diff

app/models/journal/changed_boolean.rb

 
0class ChangedBoolean < ActiveRecord::Base
1end
toggle raw diff

app/models/journal/changed_datetime.rb

 
0class ChangedDatetime < ActiveRecord::Base
1end
toggle raw diff

app/models/journal/changed_enum.rb

 
0class ChangedEnum < ActiveRecord::Base
1end
toggle raw diff

app/models/journal/changed_float.rb

 
0class ChangedFloat < ActiveRecord::Base
1end
toggle raw diff

app/models/journal/changed_integer.rb

 
0class ChangedInteger < ActiveRecord::Base
1end
toggle raw diff

app/models/journal/changed_string.rb

 
0class ChangedString < ActiveRecord::Base
1end
toggle raw diff

app/models/journal/changed_text.rb

 
0class ChangedText < ActiveRecord::Base
1end
toggle raw diff

app/models/journal/journal.rb

 
0#
1# Journal records changes to a model
2#
3# You call it when create a new wiki or article etc.
4# You call it when you update a model
5# It records the differences
6#
7# You can then view the change history of a ticket etc.
8#
9class Journal < ActiveRecord::Base
10
11 #
12 # Create journal entry
13 # model: @wiki | @article etc.
14 # ip: IP address
15 # user_id: user id of changer
16 #
17 def self.create (model, ip, project_id, user_id)
18 # record that something has happened
19 journal = Journal.new
20 journal.action = :create
21 journal.model_type = model.type.to_s
22 journal.row_id = model.id
23 journal.ip = ip
24 journal.user_id = user_id
25 #TODO check saves okay
26 journal.save
27 #
28 for column in model.type.columns
29 #filter columns we don't want to track
30 case column.name
31 when "created_at", "updated_at", "views", "id"
32 else
33 change = Change.new
34 change.journal_id = journal.id
35 change.model_column = column.name
36 change.datatype = column.type
37 #
38 case column.type
39 when :integer
40 c = ChangedInteger.new
41 when :float
42 c = ChangedFloat.new
43 when :string
44 c = ChangedString.new
45 when :text
46 c = ChangedText.new
47 when :boolean
48 c = ChangedBoolean.new
49 when :datetime, :date, :time
50 c = ChangedDatetime.new
51 when :enum
52 c = ChangedEnum.new
53 else
54 #TODO raise some unknown type exception
55 end
56 #
57 c.data = model[column.name]
58 #TODO check saves okay
59 c.save
60 change.data_id = c.id
61 #TODO check saves okay
62 change.save
63 end
64 end
65
66 #TODO check error
67 e = Event.new
68 e.project_id = project_id if project_id
69 e.user_id = user_id if user_id
70 e.entry_type = :journal
71 e.entry_id = journal.id
72 e.save
73 end
74
75 #
76 # Update journal entry
77 # model: @wiki | @article etc.
78 # ip: IP address
79 # user_id: user id of changer
80 #
81 def self.update (original_model, updated_model, ip, project_id, user_id)
82
83 # record that something has happened
84 journal = Journal.new
85 journal.action = :update
86 journal.model_type = updated_model.type.to_s
87 journal.row_id = updated_model.id
88 journal.ip = ip
89 journal.user_id = user_id
90 #TODO check saves okay
91 journal.save
92 #
93 s = ""
94 for column in updated_model.type.columns
95 #s << original_model[column.name].to_s << "/" + updated_model[column.name].to_s << "</br>"
96 if original_model[column.name] != updated_model[column.name]
97 #filter columns we don't want to track
98 case column.name
99 when "created_at", "updated_at", "views", "id"
100 else
101 change = Change.new
102 change.journal_id = journal.id
103 change.model_column = column.name
104 change.datatype = column.type
105 #
106 case column.type
107 when :integer
108 c = ChangedInteger.new
109 when :float
110 c = ChangedFloat.new
111 when :string
112 c = ChangedString.new
113 when :text
114 c = ChangedText.new
115 when :boolean
116 c = ChangedBoolean.new
117 when :datetime, :date, :time
118 c = ChangedDatetime.new
119 when :enum
120 c = ChangedEnum.new
121 else
122 #TODO raise some unknown type exception
123 end
124 #
125 c.data = updated_model[column.name]
126 #TODO check saves okay
127 c.save
128 change.data_id = c.id
129 #TODO check saves okay
130 change.save
131 end
132 end
133 end
134
135 #TODO insert an event
136 e = Event.new
137 e.project_id = project_id if project_id
138 e.user_id = user_id if user_id
139 e.entry_type = :journal
140 e.entry_id = journal.id
141 e.save
142
143 end
144
145end
146
147
148
toggle raw diff

app/models/project.rb

 
222222 def self.list_for_user(user)
223223 if user != nil then
224224 list = ""
225 projects = Member.find_by_user(user)
225 projects = Member.find_by_user(user.id)
226226 if projects.size > 0 then
227227 start = true
228228 for project in projects
toggle raw diff

app/views/activities/_ac_right_actionbox_post_message.html.erb

 
1<% form_for :message, :url => root_path, :html => {:method => :put, :name => 'postmessage', :id => 'input'} do |f| -%>
1
2<% form_for :message, :url => project_activities_path(@project.slug), :method => :post, :html => {:name => 'postmessage', :id => 'input'} do |f| -%>
23
34 <h2>Post Message</h2>
45
1010 <p>
1111 <a href="javascript:document.postmessage.submit();" class='function'>Update</a>
1212 </p>
13
1413
1514<% end -%>
toggle raw diff

app/views/activities/ac_index.html.erb

 
0<%= render :partial => "projects/ac_project_header", :locals => { :tab => PRJ_TAB_ACTIVITIES,
1 :subtab => PRJ_TAB_SUBTAB_NONE,
2 :project => @project,
3 :pagetitle => @title } %>
4
5<% if @is_member && @members.size > 1 %>
6<div id='projectmembers'>
7<ul>
8<% @members.each do |m| %>
9 <% if m.user != current_user %>
10 <li><%= m.user.fullname %></li>
11 <% end %>
12<% end %>
13</ul>
14</div>
15<% end %>
16
17<%= div_formattedtext_open %>
18
19<ul>
20<% @messages.each do |m| %>
21 <li>
22 <% unless @is_member %>
23 <strong><%= m.user.fullname %></strong>
24 <% end %>
25 <%= m.activity %>
26 <small>(<%= time_ago_in_words(m.created_at) %>)</small>
27 </li>
28<% end %>
29</ul>
30
31<%= div_formattedtext_close %>
32
33<%= render :partial => "projects/ac_project_footer" %>
toggle raw diff

app/views/activities/ac_project_index.html.erb

 
1<%= render :partial => "projects/ac_project_header", :locals => { :tab => PRJ_TAB_ACTIVITIES,
2 :subtab => PRJ_TAB_SUBTAB_NONE,
3 :project => @project,
4 :pagetitle => @title } %>
5
6<% if @is_member && @members.size > 1 %>
7<div id='projectmembers'>
8<ul>
9<% @members.each do |m| %>
10 <% if m.user != current_user %>
11 <li><%= m.user.fullname %></li>
12 <% end %>
13<% end %>
14</ul>
15</div>
16<% end %>
17
18<%= div_formattedtext_open %>
19
20<ul>
21<% @messages.each do |m| %>
22 <li>
23 <% unless @is_member %>
24 <strong><%= m.user.fullname %></strong>
25 <% end %>
26 <%= m.activity %>
27 <small>(<%= time_ago_in_words(m.created_at) %>)</small>
28 </li>
29<% end %>
30</ul>
31
32<%= div_formattedtext_close %>
33
34<%= render :partial => "projects/ac_project_footer" %>
toggle raw diff

config/environment.rb

 
6262 #Add model subdirectories
6363 config.load_paths += %W[
6464 #{RAILS_ROOT}/app/models/
65 #{RAILS_ROOT}/app/models/event
66 #{RAILS_ROOT}/app/models/journal
67 #{RAILS_ROOT}/app/models/user
68 #{RAILS_ROOT}/app/models/git
65 #{RAILS_ROOT}/app/models/event/
66 #{RAILS_ROOT}/app/models/user/
67 #{RAILS_ROOT}/app/models/git/
6968 ]
7069
7170end
toggle raw diff