diff --git a/app/assets/stylesheets/sections/events.scss b/app/assets/stylesheets/sections/events.scss index 28551d9a..71042644 100644 --- a/app/assets/stylesheets/sections/events.scss +++ b/app/assets/stylesheets/sections/events.scss @@ -31,7 +31,6 @@ * */ .event-item { - min-height: 40px; border-bottom: 1px solid #eee; .event-title { color: #333; @@ -50,14 +49,18 @@ } } .avatar { - width: 32px; + position: relative; + top: -3px; } .event_icon { + position: relative; float: right; border: 1px solid #EEE; padding: 5px; @include border-radius(5px); background: #F9F9F9; + margin-left: 10px; + top: -6px; img { width: 20px; } @@ -71,7 +74,7 @@ } } - padding: 15px 5px; + padding: 16px 5px; &:last-child { border:none } .wll:hover { background:none } diff --git a/app/controllers/milestones_controller.rb b/app/controllers/milestones_controller.rb index 276317d1..a0c824e8 100644 --- a/app/controllers/milestones_controller.rb +++ b/app/controllers/milestones_controller.rb @@ -43,6 +43,7 @@ class MilestonesController < ProjectResourceController def create @milestone = @project.milestones.new(params[:milestone]) + @milestone.author_id_of_changes = current_user.id if @milestone.save redirect_to project_milestone_path(@project, @milestone) @@ -52,7 +53,7 @@ class MilestonesController < ProjectResourceController end def update - @milestone.update_attributes(params[:milestone]) + @milestone.update_attributes(params[:milestone].merge(author_id_of_changes: current_user.id)) respond_to do |format| format.js diff --git a/app/models/event.rb b/app/models/event.rb index 2b92783c..90376e73 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -15,6 +15,7 @@ # class Event < ActiveRecord::Base + include NoteEvent include PushEvent attr_accessible :project, :action, :data, :author_id, :project_id, @@ -58,12 +59,14 @@ class Event < ActiveRecord::Base end end - # Next events currently enabled for system - # - push - # - new issue - # - merge request - def allowed? - push? || issue? || merge_request? || membership_changed? + def proper? + if push? + true + elsif membership_changed? + true + else + (issue? || merge_request? || note? || milestone?) && target + end end def project_name @@ -94,6 +97,14 @@ class Event < ActiveRecord::Base action == self.class::Reopened end + def milestone? + target_type == "Milestone" + end + + def note? + target_type == "Note" + end + def issue? target_type == "Issue" end diff --git a/app/models/milestone.rb b/app/models/milestone.rb index e700cc2f..4be08736 100644 --- a/app/models/milestone.rb +++ b/app/models/milestone.rb @@ -13,7 +13,8 @@ # class Milestone < ActiveRecord::Base - attr_accessible :title, :description, :due_date, :closed + attr_accessible :title, :description, :due_date, :closed, :author_id_of_changes + attr_accessor :author_id_of_changes belongs_to :project has_many :issues @@ -67,4 +68,8 @@ class Milestone < ActiveRecord::Base def open? !closed end + + def author_id + author_id_of_changes + end end diff --git a/app/models/note.rb b/app/models/note.rb index da15a173..219ed9b9 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -121,4 +121,12 @@ class Note < ActiveRecord::Base def downvote? note.start_with?('-1') || note.start_with?(':-1:') end + + def noteable_type_name + if noteable_type.present? + noteable_type.downcase + else + "wall" + end + end end diff --git a/app/observers/activity_observer.rb b/app/observers/activity_observer.rb index 48351bac..c188e572 100644 --- a/app/observers/activity_observer.rb +++ b/app/observers/activity_observer.rb @@ -1,18 +1,27 @@ class ActivityObserver < ActiveRecord::Observer - observe :issue, :merge_request + observe :issue, :merge_request, :note, :milestone def after_create(record) - Event.create( - project: record.project, - target_id: record.id, - target_type: record.class.name, - action: Event.determine_action(record), - author_id: record.author_id - ) + event_author_id = record.author_id + + # Skip status notes + if record.kind_of?(Note) && record.note.include?("_Status changed to ") + return true + end + + if event_author_id + Event.create( + project: record.project, + target_id: record.id, + target_type: record.class.name, + action: Event.determine_action(record), + author_id: event_author_id + ) + end end def after_save(record) - if record.changed.include?("closed") + if record.changed.include?("closed") && record.author_id_of_changes Event.create( project: record.project, target_id: record.id, diff --git a/app/roles/note_event.rb b/app/roles/note_event.rb new file mode 100644 index 00000000..cc6d7338 --- /dev/null +++ b/app/roles/note_event.rb @@ -0,0 +1,21 @@ +module NoteEvent + def note_commit_id + target.noteable_id + end + + def note_short_commit_id + note_commit_id[0..8] + end + + def note_commit? + target.noteable_type == "Commit" + end + + def note_target + target.noteable + end + + def note_target_id + target.noteable_id + end +end diff --git a/app/views/dashboard/index.atom.builder b/app/views/dashboard/index.atom.builder index ffa15258..2bb42a65 100644 --- a/app/views/dashboard/index.atom.builder +++ b/app/views/dashboard/index.atom.builder @@ -7,7 +7,7 @@ xml.feed "xmlns" => "http://www.w3.org/2005/Atom", "xmlns:media" => "http://sear xml.updated @events.maximum(:updated_at).strftime("%Y-%m-%dT%H:%M:%SZ") if @events.any? @events.each do |event| - if event.allowed? + if event.proper? event = EventDecorator.decorate(event) xml.entry do event_link = event.feed_url diff --git a/app/views/events/_event.html.haml b/app/views/events/_event.html.haml index 2446b764..191aed07 100644 --- a/app/views/events/_event.html.haml +++ b/app/views/events/_event.html.haml @@ -1,15 +1,15 @@ -- if event.allowed? +- if event.proper? %div.event-item - = event_image(event) + %span.cgray.right + #{time_ago_in_words(event.created_at)} ago. + = image_tag gravatar_icon(event.author_email), class: "avatar s24" - if event.push? = render "events/event/push", event: event + .clearfix + - elsif event.note? + = render "events/event/note", event: event - else = render "events/event/common", event: event - .clearfix - %span.cgray.right - = time_ago_in_words(event.created_at) - ago. - .clearfix diff --git a/app/views/events/event/_note.html.haml b/app/views/events/event/_note.html.haml new file mode 100644 index 00000000..88b8532f --- /dev/null +++ b/app/views/events/event/_note.html.haml @@ -0,0 +1,23 @@ +.event-title + %span.author_name= link_to_author event + %span.event_label commented on #{event.target.noteable_type_name} + - if event.target and event.note_target + - if event.note_commit? + = link_to event.note_short_commit_id, project_commit_path(event.project, event.note_commit_id), class: "commit_short_id" + - else + = link_to [event.project, event.note_target] do + %strong= truncate event.note_target_id + + - else + %strong (deleted) + at + - if event.project + = link_to_project event.project + - else + = event.project_name + +.event-body + %span.hint +   + %i.icon-comment + = truncate event.target.note, length: 70 diff --git a/app/views/groups/show.atom.builder b/app/views/groups/show.atom.builder index fa3bfade..9aa52ea5 100644 --- a/app/views/groups/show.atom.builder +++ b/app/views/groups/show.atom.builder @@ -7,7 +7,7 @@ xml.feed "xmlns" => "http://www.w3.org/2005/Atom", "xmlns:media" => "http://sear xml.updated @events.maximum(:updated_at).strftime("%Y-%m-%dT%H:%M:%SZ") if @events.any? @events.each do |event| - if event.allowed? + if event.proper? event = EventDecorator.decorate(event) xml.entry do event_link = event.feed_url diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index 49cb49db..82b46b68 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -59,7 +59,7 @@ describe Event do end it { @event.push?.should be_true } - it { @event.allowed?.should be_true } + it { @event.proper?.should be_true } it { @event.new_branch?.should be_true } it { @event.tag?.should be_false } it { @event.branch_name.should == "master" } diff --git a/spec/observers/activity_observer_spec.rb b/spec/observers/activity_observer_spec.rb index 0eec41f4..6af5d070 100644 --- a/spec/observers/activity_observer_spec.rb +++ b/spec/observers/activity_observer_spec.rb @@ -34,15 +34,17 @@ describe ActivityObserver do it { @event.target.should == @issue } end - #describe "Issue commented" do - #before do - #@issue = create(:issue, project: project) - #@note = create(:note, noteable: @issue, project: project) - #@event = Event.last - #end + describe "Issue commented" do + before do + Note.observers.enable :activity_observer do + @issue = create(:issue, project: project) + @note = create(:note, noteable: @issue, project: project, author: @issue.author) + @event = Event.last + end + end - #it_should_be_valid_event - #it { @event.action.should == Event::Commented } - #it { @event.target.should == @note } - #end + it_should_be_valid_event + it { @event.action.should == Event::Commented } + it { @event.target.should == @note } + end end