Commit 69751aac32f505a87a40af638dbf14f69f85315e

Authored by Dmitriy Zaporozhets
1 parent 663dd6fa

Refactoring event views

app/helpers/events_helper.rb
@@ -19,4 +19,18 @@ module EventsHelper @@ -19,4 +19,18 @@ module EventsHelper
19 19
20 [event.action_name, target].join(" ") 20 [event.action_name, target].join(" ")
21 end 21 end
  22 +
  23 + def event_image event
  24 + event_image_path = if event.push?
  25 + "event_push.png"
  26 + elsif event.merged?
  27 + "event_mr_merged.png"
  28 + end
  29 +
  30 + return nil unless event_image_path
  31 +
  32 + content_tag :div, class: 'event_icon' do
  33 + image_tag event_image_path
  34 + end
  35 + end
22 end 36 end
app/views/events/_event.html.haml
1 - if event.allowed? 1 - if event.allowed?
2 %div.event-item 2 %div.event-item
  3 + = event_image(event)
  4 + = image_tag gravatar_icon(event.author_email), class: "avatar"
  5 +
3 - if event.push? 6 - if event.push?
4 - = render "events/event_push", event: event 7 + = render "events/event/push", event: event
5 - else 8 - else
6 - = render "events/event_common", event: event 9 + = render "events/event/common", event: event
7 10
  11 + .clearfix
8 %span.cgray.right 12 %span.cgray.right
9 = time_ago_in_words(event.created_at) 13 = time_ago_in_words(event.created_at)
10 ago. 14 ago.
app/views/events/_event_common.html.haml
@@ -1,8 +0,0 @@ @@ -1,8 +0,0 @@
1 -= image_tag gravatar_icon(event.author_email), class: "avatar"  
2 -.event-title  
3 - %span.author_name= link_to_author event  
4 - %span.event_label{class: event.action_name}= event_action_name(event)  
5 - = link_to [event.project, event.target] do  
6 - %strong= truncate event.target_title  
7 - at  
8 - = link_to_project event.project  
app/views/events/_event_push.html.haml
@@ -1,27 +0,0 @@ @@ -1,27 +0,0 @@
1 -%div  
2 - .event_icon= image_tag "event_push.png"  
3 - = image_tag gravatar_icon(event.author_email), class: "avatar"  
4 -  
5 - .event-title  
6 - %span.author_name= link_to_author event  
7 - %span.event_label.pushed #{event.push_action_name} #{event.ref_type}  
8 - = link_to project_commits_path(event.project, event.ref_name) do  
9 - %strong= event.ref_name  
10 - at  
11 - %strong= link_to event.project.name, event.project  
12 -  
13 - - if event.push_with_commits?  
14 - - project = event.project  
15 - .event-body  
16 - %ul.unstyled.event_commits  
17 - - few_commits = event.commits[0...2]  
18 - - few_commits.each do |commit|  
19 - = render "events/commit", commit: commit, project: project  
20 -  
21 - - if event.commits_count > 1  
22 - %li.commits-stat  
23 - - if event.commits_count > 2  
24 - %span ... and #{event.commits_count - 2} more commits.  
25 - = link_to project_compare_path(event.project, from: event.parent_commit.id, to: event.last_commit.id) do  
26 - %strong Compare → #{event.parent_commit.id[0..7]}...#{event.last_commit.id[0..7]}  
27 - .clearfix  
app/views/events/event/_common.html.haml 0 → 100644
@@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
  1 +.event-title
  2 + %span.author_name= link_to_author event
  3 + %span.event_label{class: event.action_name}= event_action_name(event)
  4 + = link_to [event.project, event.target] do
  5 + %strong= truncate event.target_title
  6 + at
  7 + = link_to_project event.project
app/views/events/event/_push.html.haml 0 → 100644
@@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
  1 +.event-title
  2 + %span.author_name= link_to_author event
  3 + %span.event_label.pushed #{event.push_action_name} #{event.ref_type}
  4 + = link_to project_commits_path(event.project, event.ref_name) do
  5 + %strong= event.ref_name
  6 + at
  7 + %strong= link_to event.project.name, event.project
  8 +
  9 +- if event.push_with_commits?
  10 + - project = event.project
  11 + .event-body
  12 + %ul.unstyled.event_commits
  13 + - few_commits = event.commits[0...2]
  14 + - few_commits.each do |commit|
  15 + = render "events/commit", commit: commit, project: project
  16 +
  17 + - if event.commits_count > 1
  18 + %li.commits-stat
  19 + - if event.commits_count > 2
  20 + %span ... and #{event.commits_count - 2} more commits.
  21 + = link_to project_compare_path(event.project, from: event.parent_commit.id, to: event.last_commit.id) do
  22 + %strong Compare → #{event.parent_commit.id[0..7]}...#{event.last_commit.id[0..7]}