From 00dc34e1929e914d1f4f194888d9d94e513fdaa5 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 2 Apr 2012 00:24:45 +0300 Subject: [PATCH] Events improved & refactored. Dashboard pollished --- app/assets/stylesheets/common.scss | 17 ++++++++++++----- app/models/event.rb | 45 +++++++++++++++++++-------------------------- app/models/event/push_trait.rb | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/views/dashboard/_projects_feed.html.haml | 16 +++++++++------- app/views/dashboard/index.html.haml | 4 ++-- app/views/events/_event.html.haml | 12 ++++-------- app/views/events/_event_changed_issue.html.haml | 15 --------------- app/views/events/_event_changed_merge_request.html.haml | 20 -------------------- app/views/events/_event_issue.html.haml | 11 +++++++++++ app/views/events/_event_merge_request.html.haml | 16 ++++++++++++++++ app/views/events/_event_new_issue.html.haml | 11 ----------- app/views/events/_event_new_merge_request.html.haml | 16 ---------------- app/views/events/_event_push.html.haml | 57 ++++++++++++++++++++------------------------------------- 13 files changed, 160 insertions(+), 147 deletions(-) create mode 100644 app/models/event/push_trait.rb delete mode 100644 app/views/events/_event_changed_issue.html.haml delete mode 100644 app/views/events/_event_changed_merge_request.html.haml create mode 100644 app/views/events/_event_issue.html.haml create mode 100644 app/views/events/_event_merge_request.html.haml delete mode 100644 app/views/events/_event_new_issue.html.haml delete mode 100644 app/views/events/_event_new_merge_request.html.haml diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss index 823ba8e..8243bf9 100644 --- a/app/assets/stylesheets/common.scss +++ b/app/assets/stylesheets/common.scss @@ -67,6 +67,12 @@ a:focus { } } +.event_label { + background: #FCEEC1; + padding:0 2px; + font-family: monospace; +} + .tabs > li > a, .pills > li > a { color:$style_color; } @@ -126,6 +132,9 @@ a:focus { .ipadded { padding:20px !important; } +.lborder { + border-left:1px solid #eee; +} .no-borders { border:none; } @@ -872,10 +881,9 @@ p.time { border:none; padding:0px 5px; - &:hover { - background:$hover; - //border-left:4px solid $styled_border_color; - h4 { + .project_link { + color:#888; + &:hover { color:#111; .ico.project { background-position:-209px -21px; @@ -1077,7 +1085,6 @@ p.time { } .arrow{ - float: right; background: #E3E5EA; padding: 5px; margin-top:5px; diff --git a/app/models/event.rb b/app/models/event.rb index adc558b..74525c1 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -9,6 +9,8 @@ class Event < ActiveRecord::Base Commented = 6 Merged = 7 + does "event/push" + belongs_to :project belongs_to :target, :polymorphic => true @@ -30,14 +32,17 @@ class Event < ActiveRecord::Base # - new issue # - merge request def allowed? - push? || new_issue? || new_merge_request? || - changed_merge_request? || changed_issue? + push? || issue? || merge_request? end def push? action == self.class::Pushed end + def merged? + action == self.class::Merged + end + def closed? action == self.class::Closed end @@ -46,28 +51,12 @@ class Event < ActiveRecord::Base action == self.class::Reopened end - def new_tag? - data[:ref]["refs/tags"] - end - - def new_branch? - data[:before] =~ /^00000/ - end - - def commit_from - data[:before] - end - - def commit_to - data[:after] + def issue? + target_type == "Issue" end - def branch_name - @branch_name ||= data[:ref].gsub("refs/heads/", "") - end - - def tag_name - @tag_name ||= data[:ref].gsub("refs/tags/", "") + def merge_request? + target_type == "MergeRequest" end def new_issue? @@ -101,10 +90,14 @@ class Event < ActiveRecord::Base def author @author ||= User.find(author_id) end - - def commits - @commits ||= data[:commits].map do |commit| - project.commit(commit[:id]) + + def action_name + if closed? + "closed" + elsif merged? + "merged" + else + "opened" end end diff --git a/app/models/event/push_trait.rb b/app/models/event/push_trait.rb new file mode 100644 index 0000000..7ed0c28 --- /dev/null +++ b/app/models/event/push_trait.rb @@ -0,0 +1,67 @@ +module Event::PushTrait + as_trait do + def tag? + data[:ref]["refs/tags"] + end + + def new_branch? + data[:before] =~ /^00000/ + end + + def new_ref? + data[:before] =~ /^00000/ + end + + def rm_ref? + data[:after] =~ /^00000/ + end + + def md_ref? + !(rm_ref? || new_ref?) + end + + def commit_from + data[:before] + end + + def commit_to + data[:after] + end + + def ref_name + if tag? + tag_name + else + branch_name + end + end + + def branch_name + @branch_name ||= data[:ref].gsub("refs/heads/", "") + end + + def tag_name + @tag_name ||= data[:ref].gsub("refs/tags/", "") + end + + def commits + @commits ||= data[:commits].map do |commit| + project.commit(commit[:id]) + end + end + + def ref_type + tag? ? "tag" : "branch" + end + + def push_action_name + if new_ref? + "pushed new" + elsif rm_ref? + "removed #{ref_type}" + else + "pushed to" + end + end + end +end diff --git a/app/views/dashboard/_projects_feed.html.haml b/app/views/dashboard/_projects_feed.html.haml index e3f61e6..b41b1e5 100644 --- a/app/views/dashboard/_projects_feed.html.haml +++ b/app/views/dashboard/_projects_feed.html.haml @@ -1,11 +1,13 @@ - projects.first(5).each do |project| %div.dash_project_item - = link_to project do - %h4 + %h4 + = link_to project, :class => "project_link" do %span.ico.project - = truncate project.name, :length => 30 + = truncate project.name, :length => 24 + %small + last activity at + = project.last_activity_date.stamp("Aug 25, 2011") + + .right %small - last activity at - = project.last_activity_date.stamp("Aug 25, 2011") - %span.right.arrow - → + %strong= link_to "Browse Code ยป", tree_project_ref_path(project, project.root_ref), :class => "vlink" diff --git a/app/views/dashboard/index.html.haml b/app/views/dashboard/index.html.haml index 3bd411d..d25c756 100644 --- a/app/views/dashboard/index.html.haml +++ b/app/views/dashboard/index.html.haml @@ -21,8 +21,8 @@ .dashboard_block .row .span4.right - %div.borders.ipadded - %h1 + %div.lborder.ipadded + %h3 = pluralize current_user.projects.count, "project", "projects" - if current_user.can_create_project? %hr diff --git a/app/views/events/_event.html.haml b/app/views/events/_event.html.haml index f091fff..ed45e27 100644 --- a/app/views/events/_event.html.haml +++ b/app/views/events/_event.html.haml @@ -1,12 +1,8 @@ - if event.allowed? .event_feed - - if event.new_issue? - = render "events/event_new_issue", :event => event - - elsif event.new_merge_request? - = render "events/event_new_merge_request", :event => event - - elsif event.changed_merge_request? - = render "events/event_changed_merge_request", :event => event - - elsif event.changed_issue? - = render "events/event_changed_issue", :event => event + - if event.issue? + = render "events/event_issue", :event => event + - elsif event.merge_request? + = render "events/event_merge_request", :event => event - elsif event.push? = render "events/event_push", :event => event diff --git a/app/views/events/_event_changed_issue.html.haml b/app/views/events/_event_changed_issue.html.haml deleted file mode 100644 index 4f5d78a..0000000 --- a/app/views/events/_event_changed_issue.html.haml +++ /dev/null @@ -1,15 +0,0 @@ -= image_tag gravatar_icon(event.author_email), :class => "avatar" -%strong #{event.author_name} -%span.label.important - - if event.closed? - closed - - else - reopened - issue -= link_to project_issue_path(event.project, event.issue) do - %strong= truncate event.issue_title -at -%strong= link_to event.project.name, event.project -%span.cgray - = time_ago_in_words(event.created_at) - ago. diff --git a/app/views/events/_event_changed_merge_request.html.haml b/app/views/events/_event_changed_merge_request.html.haml deleted file mode 100644 index 1a4da6c..0000000 --- a/app/views/events/_event_changed_merge_request.html.haml +++ /dev/null @@ -1,20 +0,0 @@ -= image_tag gravatar_icon(event.author_email), :class => "avatar" -%strong #{event.author_name} -%span.label.important - - if event.closed? - closed - - else - reopened - merge request -= link_to project_merge_request_path(event.project, event.merge_request) do - %strong= truncate event.merge_request_title -at -%strong= link_to event.project.name, event.project -%span.cgray - = time_ago_in_words(event.created_at) - ago. -%br -%span.label= event.merge_request.source_branch -→ -%span.label= event.merge_request.target_branch - diff --git a/app/views/events/_event_issue.html.haml b/app/views/events/_event_issue.html.haml new file mode 100644 index 0000000..f527cb2 --- /dev/null +++ b/app/views/events/_event_issue.html.haml @@ -0,0 +1,11 @@ += image_tag gravatar_icon(event.author_email), :class => "avatar" +%strong #{event.author_name} +%span.event_label= event.action_name + issue += link_to project_issue_path(event.project, event.issue) do + %strong= truncate event.issue_title +at +%strong= link_to event.project.name, event.project +%span.cgray + = time_ago_in_words(event.created_at) + ago. diff --git a/app/views/events/_event_merge_request.html.haml b/app/views/events/_event_merge_request.html.haml new file mode 100644 index 0000000..ecb0e9f --- /dev/null +++ b/app/views/events/_event_merge_request.html.haml @@ -0,0 +1,16 @@ += image_tag gravatar_icon(event.author_email), :class => "avatar" +%strong #{event.author_name} +%span.event_label= event.action_name + merge request += link_to project_merge_request_path(event.project, event.merge_request) do + %strong= truncate event.merge_request_title +at +%strong= link_to event.project.name, event.project +%span.cgray + = time_ago_in_words(event.created_at) + ago. +%br +%span= event.merge_request.source_branch +→ +%span= event.merge_request.target_branch + diff --git a/app/views/events/_event_new_issue.html.haml b/app/views/events/_event_new_issue.html.haml deleted file mode 100644 index 3d38d84..0000000 --- a/app/views/events/_event_new_issue.html.haml +++ /dev/null @@ -1,11 +0,0 @@ -= image_tag gravatar_icon(event.author_email), :class => "avatar" -%strong #{event.author_name} -%span.label.success created - new issue -= link_to project_issue_path(event.project, event.issue) do - %strong= truncate event.issue_title -at -%strong= link_to event.project.name, event.project -%span.cgray - = time_ago_in_words(event.created_at) - ago. diff --git a/app/views/events/_event_new_merge_request.html.haml b/app/views/events/_event_new_merge_request.html.haml deleted file mode 100644 index ecb8671..0000000 --- a/app/views/events/_event_new_merge_request.html.haml +++ /dev/null @@ -1,16 +0,0 @@ -= image_tag gravatar_icon(event.author_email), :class => "avatar" -%strong #{event.author_name} -%span.label.success requested - merge -= link_to project_merge_request_path(event.project, event.merge_request) do - %strong= truncate event.merge_request_title -at -%strong= link_to event.project.name, event.project -%span.cgray - = time_ago_in_words(event.created_at) - ago. -%br -%span.label= event.merge_request.source_branch -→ -%span.label= event.merge_request.target_branch - diff --git a/app/views/events/_event_push.html.haml b/app/views/events/_event_push.html.haml index b24d297..fb4ffc5 100644 --- a/app/views/events/_event_push.html.haml +++ b/app/views/events/_event_push.html.haml @@ -1,45 +1,28 @@ -- if event.new_branch? || event.new_tag? +%div = image_tag gravatar_icon(event.author_email), :class => "avatar" %strong #{event.author_name} - %span.label.pushed pushed -  new - - if event.new_tag? - tag - = link_to project_commits_path(event.project, :ref => event.tag_name) do - %strong= event.tag_name - - else - branch - = link_to project_commits_path(event.project, :ref => event.branch_name) do - %strong= event.branch_name + %span.event_label= event.push_action_name + = link_to project_commits_path(event.project, :ref => event.ref_name) do + %strong= event.ref_name at %strong= link_to event.project.name, event.project %span.cgray = time_ago_in_words(event.created_at) ago. -- else - = image_tag gravatar_icon(event.author_email), :class => "avatar" - %strong #{event.author_name} - %span.label.pushed pushed -  to - = link_to project_commits_path(event.project, :ref => event.branch_name) do - %strong= event.branch_name - at - %strong= link_to event.project.name, event.project - %span.cgray - = time_ago_in_words(event.created_at) - ago. - - if event.commits.count > 1 - = link_to compare_project_commits_path(event.project, :from => event.commits.first.prev_commit_id, :to => event.commits.last.id) do - %strong #{event.commits.first.commit.id[0..7]}...#{event.commits.last.id[0..7]} - - project = event.project - %ul.unstyled.event_commits - - if event.commits.size > 3 - - event.commits[0...2].each do |commit| - = render "events/commit", :commit => commit, :project => project - %li - %br - \... and #{event.commits.size - 2} more commits - - else - - event.commits.each do |commit| - = render "events/commit", :commit => commit, :project => project + + - if event.md_ref? + - if event.commits.count > 1 + = link_to compare_project_commits_path(event.project, :from => event.commits.first.prev_commit_id, :to => event.commits.last.id) do + %strong #{event.commits.first.commit.id[0..7]}...#{event.commits.last.id[0..7]} + - project = event.project + %ul.unstyled.event_commits + - if event.commits.size > 3 + - event.commits[0...2].each do |commit| + = render "events/commit", :commit => commit, :project => project + %li + %br + \... and #{event.commits.size - 2} more commits + - else + - event.commits.each do |commit| + = render "events/commit", :commit => commit, :project => project -- libgit2 0.21.2