From 87802c8ba1acae5370c18ad6e64e518a8409a658 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Fri, 8 May 2015 15:47:30 +0500 Subject: [PATCH] activity feed: show a "pull request" instead a "issue"; small refactoring --- .../controllers/activity_controller.js.coffee | 22 +++++++++++-------- .../javascripts/angularjs/locales.js.erb | 6 ++++- .../build_list_notification.html.haml | 2 +- .../git_new_push_notification.html.haml | 3 ++- .../new_comment_notification.html.haml | 4 ++-- .../new_issue_notification.html.haml | 6 +++-- app/views/home/_activity_tabsets.html.slim | 2 +- app/views/home/activity.json.jbuilder | 2 +- .../_git_new_push_notification.json.jbuilder | 5 +++-- .../_new_comment_notification.json.jbuilder | 10 ++++++++- .../_new_issue_notification.json.jbuilder | 11 +++++++++- 11 files changed, 51 insertions(+), 22 deletions(-) diff --git a/app/assets/javascripts/angularjs/controllers/activity_controller.js.coffee b/app/assets/javascripts/angularjs/controllers/activity_controller.js.coffee index 07a0280c8..ba808c83c 100644 --- a/app/assets/javascripts/angularjs/controllers/activity_controller.js.coffee +++ b/app/assets/javascripts/angularjs/controllers/activity_controller.js.coffee @@ -4,6 +4,15 @@ ActivityController = ($scope, $http, $timeout, $q, $filter, $location, ActivityF return vm.tracker_tab if kind is 'tracker' return vm.pull_requests_tab if kind is 'pull_requests' + calculateChangeDate = (feed)-> + prev_date = null + _.each(feed, (event)-> + cur_date = $filter('amDateFormat')(event.date, 'll') + event.is_date_changed = cur_date isnt prev_date + prev_date = cur_date + ) + + vm = this @@ -111,14 +120,6 @@ ActivityController = ($scope, $http, $timeout, $q, $filter, $location, ActivityF vm.getCurActivity = ()-> vm.current_activity_tab[vm.current_activity_tab.filter] - vm.needShowTimeLabel = (index)-> - feed = vm.getCurActivity().feed - return false unless feed - - cur_date = $filter('amDateFormat')(feed[index].date, 'll') - prev_date = index is 0 or $filter('amDateFormat')(feed[index-1].date, 'll') - return cur_date isnt prev_date - vm.getTemplate = (content)-> content.kind + '.html' @@ -149,8 +150,11 @@ ActivityController = ($scope, $http, $timeout, $q, $filter, $location, ActivityF path = Routes.own_activity_path(options) $http.get(path).then (res)-> - vm.getCurActivity().feed = res.data.feed + feed = res.data.feed + vm.getCurActivity().feed = feed vm.getCurActivity().next_page_link = res.data.next_page_link + calculateChangeDate(feed) + true vm.setIssuesFilter = (kind, issues_filter)-> filter = getIssuesTab(kind).filter diff --git a/app/assets/javascripts/angularjs/locales.js.erb b/app/assets/javascripts/angularjs/locales.js.erb index da555bc61..922e5639a 100644 --- a/app/assets/javascripts/angularjs/locales.js.erb +++ b/app/assets/javascripts/angularjs/locales.js.erb @@ -27,12 +27,14 @@ var _locales = { 'pull_requests.filter.created': '<%= I18n.t('layout.pull_requests.created') %>', 'notification.new_comment.title': 'добавил новый комментарий к задаче ', + 'notification.new_pull_comment.title': 'добавил новый комментарий к пул реквесту ', 'notification.new_commit_comment.title': 'добавил новый комментарий к коммиту ', 'notification.push.delete_branch': 'удалил ветку ', 'notification.push.create_branch': 'создал новую ветку ', 'notification.push.update_branch': 'внес изменения в ветку ', 'notification.in_project': ' в проекте ', - 'notification.new_issue': 'добавил новую задачу', + 'notification.new_issue': 'добавил новую задачу ', + 'notification.new_pull': 'добавил новый пул реквест ', 'notification.new_user.title': 'Здравствуйте, ', 'notification.new_user.content': 'Спасибо за вашу регистрацию!', 'notification.wiki.new_commit': 'обновил ', @@ -73,12 +75,14 @@ var _locales = { 'pull_requests.filter.created': '<%= I18n.t('layout.pull_requests.created') %>', 'notification.new_comment.title': 'added a new comment in issue ', + 'notification.new_pull_comment.title': 'added a new comment in pull request ', 'notification.new_commit_comment.title': 'added a new comment in commit ', 'notification.push.delete_branch': 'deleted a branch ', 'notification.push.create_branch': 'created a new branch ', 'notification.push.update_branch': 'pushed to branch ', 'notification.in_project': ' in project ', 'notification.new_issue': 'added a new issue ', + 'notification.new_pull': 'added a new pull request ', 'notification.new_user.title': 'Hello, ', 'notification.new_user.content': 'Thank you for your registration!', 'notification.wiki.new_commit': 'has been updated ', diff --git a/app/assets/javascripts/angularjs/templates/build_list_notification.html.haml b/app/assets/javascripts/angularjs/templates/build_list_notification.html.haml index 5fa491c82..7a61cf295 100644 --- a/app/assets/javascripts/angularjs/templates/build_list_notification.html.haml +++ b/app/assets/javascripts/angularjs/templates/build_list_notification.html.haml @@ -13,6 +13,6 @@ %p {{'notification.build_list' | i18n}} %a{ 'ng-href' => "{{item.build_list.link}}" } {{item.build_list.id}} - {{ item.branch_name + ('notification.in_project' | i18n)}} + {{'notification.in_project' | i18n}} %a{ 'ng-href' => "{{item.project_link}}" } {{item.project_name_with_owner}} {{item.build_list.status_message}} diff --git a/app/assets/javascripts/angularjs/templates/git_new_push_notification.html.haml b/app/assets/javascripts/angularjs/templates/git_new_push_notification.html.haml index 4fbe4767f..93f31590e 100644 --- a/app/assets/javascripts/angularjs/templates/git_new_push_notification.html.haml +++ b/app/assets/javascripts/angularjs/templates/git_new_push_notification.html.haml @@ -12,7 +12,8 @@ .timeline-body %p {{'notification.push.' + item.change_type + '_branch' | i18n}} - {{ item.branch_name + ('notification.in_project' | i18n)}} + %a{ 'ng-href' => "{{item.branch_link}}" } {{item.branch_name}} + {{'notification.in_project' | i18n}} %a{ 'ng-href' => "{{item.project_link}}" } {{item.project_name_with_owner}} .timeline-footer diff --git a/app/assets/javascripts/angularjs/templates/new_comment_notification.html.haml b/app/assets/javascripts/angularjs/templates/new_comment_notification.html.haml index 7b3091857..fab1088c9 100644 --- a/app/assets/javascripts/angularjs/templates/new_comment_notification.html.haml +++ b/app/assets/javascripts/angularjs/templates/new_comment_notification.html.haml @@ -11,7 +11,8 @@ .clearfix .timeline-body %p - {{'notification.new_comment.title' | i18n}} + %span{'ng-show' => 'item.issue.is_pull'} {{'notification.new_pull_comment.title' | i18n}} + %span{'ng-show' => '!item.issue.is_pull'} {{'notification.new_comment.title' | i18n}} %a{ 'ng-href' => "{{item.issue.link}}" } {{item.issue.title}} %blockquote{ 'ng-bind-html' => "item.body" } @@ -19,4 +20,3 @@ .timeline-footer %a.btn.btn-primary.btn-xs{ 'ng-href' => "{{item.issue.link + '#comment' + item.issue.read_more}}" } {{'read_more' | i18n}} - {{item.kind}} diff --git a/app/assets/javascripts/angularjs/templates/new_issue_notification.html.haml b/app/assets/javascripts/angularjs/templates/new_issue_notification.html.haml index 6154e78c8..2ef27d5af 100644 --- a/app/assets/javascripts/angularjs/templates/new_issue_notification.html.haml +++ b/app/assets/javascripts/angularjs/templates/new_issue_notification.html.haml @@ -11,6 +11,8 @@ .clearfix .timeline-body %p - {{('notification.new_issue' | i18n) + ('notification.in_project' | i18n)}} + %span{'ng-show' => 'item.issue.is_pull'} {{'notification.new_pull' | i18n}} + %span{'ng-show' => '!item.issue.is_pull'} {{'notification.new_issue' | i18n}} + {{'notification.in_project' | i18n}} %a{ 'ng-href' => "{{item.project_link}}" } {{item.project_name_with_owner}} - %a{ 'ng-href' => "{{item.issue.link}}" } {{item.issue.title}} \ No newline at end of file + %a{ 'ng-href' => "{{item.issue.link}}" } {{item.issue.title}} diff --git a/app/views/home/_activity_tabsets.html.slim b/app/views/home/_activity_tabsets.html.slim index e207308fc..52ab273cb 100644 --- a/app/views/home/_activity_tabsets.html.slim +++ b/app/views/home/_activity_tabsets.html.slim @@ -7,7 +7,7 @@ tabset ul.timeline / timeline time label li.time-label ng-repeat-start= 'item in actCtrl.getCurActivity().feed' - span ng-show= "actCtrl.needShowTimeLabel($index)" + span ng-show= "item.is_date_changed" | {{item.date | amDateFormat:'ll'}} / timeline item li ng-include= "actCtrl.getTemplate(item)" diff --git a/app/views/home/activity.json.jbuilder b/app/views/home/activity.json.jbuilder index 0841693c9..048229a85 100644 --- a/app/views/home/activity.json.jbuilder +++ b/app/views/home/activity.json.jbuilder @@ -19,7 +19,7 @@ json.feed do end if user project_name_with_owner = "#{item.project_owner}/#{item.project_name}" - @project = Project.find_by_owner_and_name(item.data[:project_owner], item.data[:project_name]) + @project = Project.find_by_owner_and_name(project_name_with_owner) json.project_name_with_owner project_name_with_owner json.partial! item.partial, item: item, project_name_with_owner: project_name_with_owner diff --git a/app/views/home/partials/_git_new_push_notification.json.jbuilder b/app/views/home/partials/_git_new_push_notification.json.jbuilder index 6ec994efb..06e936b83 100644 --- a/app/views/home/partials/_git_new_push_notification.json.jbuilder +++ b/app/views/home/partials/_git_new_push_notification.json.jbuilder @@ -1,6 +1,7 @@ -json.change_type item.data[:change_type] +json.change_type item.data[:change_type] json.project_link project_path(project_name_with_owner) -json.branch_name item.data[:branch_name] +json.branch_name item.data[:branch_name] +json.branch_link ref_path(@project, item.data[:branch_name]) json.last_commits do json.array! item.data[:last_commits] do |commit| diff --git a/app/views/home/partials/_new_comment_notification.json.jbuilder b/app/views/home/partials/_new_comment_notification.json.jbuilder index 541d1134f..33b71a07e 100644 --- a/app/views/home/partials/_new_comment_notification.json.jbuilder +++ b/app/views/home/partials/_new_comment_notification.json.jbuilder @@ -1,5 +1,13 @@ json.issue do - json.link project_issue_path(project_name_with_owner, item.data[:issue_serial_id]) if item.data[:issue_serial_id].present? + if item.data[:issue_serial_id].present? + is_pull = @project.issues.where(serial_id: item.data[:issue_serial_id]).joins(:pull_request).exists? + json.is_pull is_pull + if is_pull + json.link project_pull_request_path(project_name_with_owner, item.data[:issue_serial_id]) + else + json.link project_issue_path(project_name_with_owner, item.data[:issue_serial_id]) + end + end json.title short_message(item.data[:issue_title], 50) json.read_more item.data[:comment_id] end diff --git a/app/views/home/partials/_new_issue_notification.json.jbuilder b/app/views/home/partials/_new_issue_notification.json.jbuilder index 4558d2b8f..7e80813f7 100644 --- a/app/views/home/partials/_new_issue_notification.json.jbuilder +++ b/app/views/home/partials/_new_issue_notification.json.jbuilder @@ -1,5 +1,14 @@ json.project_link project_path(project_name_with_owner) json.issue do json.title item.data[:issue_title] - json.link project_issue_path(project_name_with_owner, item.data[:issue_serial_id]) if item.data[:issue_serial_id].present? + + if item.data[:issue_serial_id].present? + is_pull = @project.issues.where(serial_id: item.data[:issue_serial_id]).joins(:pull_request).exists? + json.is_pull is_pull + if is_pull + json.link project_pull_request_path(project_name_with_owner, item.data[:issue_serial_id]) + else + json.link project_issue_path(project_name_with_owner, item.data[:issue_serial_id]) + end + end end