From 836139c54b106047b67caa7172ac1084b75da0c4 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Thu, 17 Apr 2014 22:49:51 +0600 Subject: [PATCH] [#369] activity filters --- .../controllers/activity_controller.js | 41 +++--- app/views/home/_commits_list.json.haml | 11 -- app/views/home/activity.html.haml | 7 +- app/views/home/activity.json.jbuilder | 119 +++++++++--------- 4 files changed, 93 insertions(+), 85 deletions(-) delete mode 100644 app/views/home/_commits_list.json.haml diff --git a/app/assets/javascripts/angular-new/controllers/activity_controller.js b/app/assets/javascripts/angular-new/controllers/activity_controller.js index c11bda635..5e466bd07 100644 --- a/app/assets/javascripts/angular-new/controllers/activity_controller.js +++ b/app/assets/javascripts/angular-new/controllers/activity_controller.js @@ -1,25 +1,17 @@ RosaABF.controller('ActivityCtrl', ['$scope', '$http', '$timeout', '$q', '$filter', function($scope, $http, $timeout, $q, $filter) { - $scope.activity_tab = { title: 'activity_menu.activity_feed', content: [] , isLoaded: false , active: true }; - $scope.tracker_tab = { title: 'activity_menu.tracker', content: [] , isLoaded: false , active: false }; - $scope.pull_requests_tab = { title: 'activity_menu.pull_requests', content: [] , isLoaded: false , active: false }; - - var today = moment().startOf('day'); - // $scope.activity_tab.content = [{date: today, kind:'new_comment_notification'}, - // {date: today, kind:'git_new_push_notification'}, - // {date: moment().add('days', 1), kind:'build_list_notification'}]; + $scope.activity_tab = { title: 'activity_menu.activity_feed', active: true, filter: 'all', + all: {}, code: {}, tracker: {}, build: {}, wiki: {} }; + $scope.tracker_tab = { title: 'activity_menu.tracker', content: [] , active: false }; + $scope.pull_requests_tab = { title: 'activity_menu.pull_requests', content: [] , active: false }; $scope.getContent=function(tab){ var cur_tab = $scope.$eval(tab+'_tab'); - /* see if we have data already */ - if(cur_tab.isLoaded){ - return; - } - /* or make request for data */ + /* make request for data */ var path = Routes.root_path({ filter: cur_tab.filter, format: 'json' }); $http.get(path).then(function(res){ - cur_tab.content=res.data; - cur_tab.isLoaded=true; + cur_tab[cur_tab.filter].feed = res.data.feed; + cur_tab[cur_tab.filter].next_page_link = res.data.next_page_link; }); } @@ -45,9 +37,13 @@ RosaABF.controller('ActivityCtrl', ['$scope', '$http', '$timeout', '$q', '$filte return template; } + $scope.getCurActivity = function() { + return $scope.activity_tab[$scope.activity_tab.filter]; + }; + $scope.needShowTimeLabel = function(index) { - var cur_date = $filter('amDateFormat')($scope.activity_tab.content[index].date, 'll'); - var prev_date = index == 0 || $filter('amDateFormat')($scope.activity_tab.content[index-1].date, 'll'); + var cur_date = $filter('amDateFormat')($scope.getCurActivity().feed[index].date, 'll'); + var prev_date = index == 0 || $filter('amDateFormat')($scope.getCurActivity().feed[index-1].date, 'll'); return cur_date !== prev_date; }; @@ -60,4 +56,15 @@ RosaABF.controller('ActivityCtrl', ['$scope', '$http', '$timeout', '$q', '$filte return content.kind + '.html'; }; + $scope.load_more = function() { + var cur_tab = $scope.getCurActivity(); + var path = cur_tab.next_page_link; + if(!path) { + return; + }; + $http.get(path).then(function(res){ + cur_tab.feed.push.apply(cur_tab.feed, res.data.feed); + cur_tab.next_page_link = res.data.next_page_link; + }); + }; }]); diff --git a/app/views/home/_commits_list.json.haml b/app/views/home/_commits_list.json.haml deleted file mode 100644 index 793adb187..000000000 --- a/app/views/home/_commits_list.json.haml +++ /dev/null @@ -1,11 +0,0 @@ -.row - - item.data[:last_commits].each do |commit| - .col-sm-3.col-md-2= link_to shortest_hash_id(commit[0]), commit_path(project_name_with_owner, commit[0]) - .col-sm-8.col-md-9= truncate(commit[1], length: 70, omission: '…') - .clearfix --#%br -- if item.data[:other_commits].present? - %br - =link_to t('notifications.bodies.more_commits', count: item.data[:other_commits_count], - commits: commits_pluralize(item.data[:other_commits_count])), - diff_path(project_name_with_owner, diff: item.data[:other_commits]) diff --git a/app/views/home/activity.html.haml b/app/views/home/activity.html.haml index b89e1f62e..4254e31f3 100644 --- a/app/views/home/activity.html.haml +++ b/app/views/home/activity.html.haml @@ -39,7 +39,7 @@ .col-md-12.col-sm-12 %ul.timeline / timeline time label - %li.time-label{ 'ng-repeat-start' => 'item in activity_tab.content' } + %li.time-label{ 'ng-repeat-start' => 'item in getCurActivity().feed' } %span{ 'ng-show' => "needShowTimeLabel($index)", 'ng-cloak' => true } {{item.date | amDateFormat:'ll'}} / timeline item @@ -47,3 +47,8 @@ .hide{ 'ng-repeat-end' => true } %li %i.img-circle.bg-primary.fa.fa-clock-o + %hr + %btn.center-block.btn.btn-primary{ 'ng-show' => 'getCurActivity().next_page_link', + 'ng-click' => "load_more()", 'ng-cloak' => true } + = t('layout.activity_feed.load_messages') + {{activity_tab.content.next_page_link}} diff --git a/app/views/home/activity.json.jbuilder b/app/views/home/activity.json.jbuilder index f0b3884b3..7f9ea729a 100644 --- a/app/views/home/activity.json.jbuilder +++ b/app/views/home/activity.json.jbuilder @@ -1,63 +1,70 @@ -json.array!(@activity_feeds) do |item| - #json.cache! item, expires_in: 10.minutes do - json.date item.created_at - json.kind item.kind - user = get_user_from_activity_item(item) - json.user do - json.link user_path(user) if user.persisted? - json.image avatar_url(user, :small) if user.persisted? - json.uname (user.fullname || user.email) - end if user +if @activity_feeds.next_page + json.next_page_link root_path(filter: @filter, page: @activity_feeds.next_page, format: :json) +end - project_name_with_owner = "#{item.data[:project_owner]}/#{item.data[:project_name]}" - @project = Project.find_by_owner_and_name(item.data[:project_owner], item.data[:project_name]) +json.feed do + json.array!(@activity_feeds) do |item| + #json.cache! item, expires_in: 10.minutes do + json.date item.created_at + json.kind item.kind + user = get_user_from_activity_item(item) + json.user do + json.link user_path(user) if user.persisted? + json.image avatar_url(user, :small) if user.persisted? + json.uname (user.fullname || user.email) + end if user - json.project_name_with_owner project_name_with_owner + project_name_with_owner = "#{item.data[:project_owner]}/#{item.data[:project_name]}" + @project = Project.find_by_owner_and_name(item.data[:project_owner], item.data[:project_name]) - case item.kind - when 'new_comment_notification' - json.issue do - json.link project_issue_path(project_name_with_owner, item.data[:issue_serial_id]) if item.data[:issue_serial_id].present? - json.title short_message(item.data[:issue_title], 50) - json.read_more item.data[:comment_id] - end - json.body markdown(short_message(item.data[:comment_body], 100)) + json.project_name_with_owner project_name_with_owner - when 'git_new_push_notification' - json.change_type item.data[:change_type] - json.project_link project_path(project_name_with_owner) - json.branch_name item.data[:branch_name] - - json.last_commits do - json.array! item.data[:last_commits] do |commit| - json.hash shortest_hash_id(commit[0]) - json.message markdown(short_message(commit[1], 70)) - json.commit_path commit_path(project_name_with_owner, commit[0]) + case item.kind + when 'new_comment_notification' + json.issue do + json.link project_issue_path(project_name_with_owner, item.data[:issue_serial_id]) if item.data[:issue_serial_id].present? + json.title short_message(item.data[:issue_title], 50) + json.read_more item.data[:comment_id] end - end - if item.data[:other_commits].present? - json.other_commits t('notifications.bodies.more_commits', count: item.data[:other_commits_count], commits: commits_pluralize(item.data[:other_commits_count])) - json.other_commits_path diff_path(project_name_with_owner, diff: item.data[:other_commits]) + json.body markdown(short_message(item.data[:comment_body], 100)) + + when 'git_new_push_notification' + json.change_type item.data[:change_type] + json.project_link project_path(project_name_with_owner) + json.branch_name item.data[:branch_name] + + json.last_commits do + json.array! item.data[:last_commits] do |commit| + json.hash shortest_hash_id(commit[0]) + json.message markdown(short_message(commit[1], 70)) + json.commit_path commit_path(project_name_with_owner, commit[0]) + end + end + if item.data[:other_commits].present? + json.other_commits t('notifications.bodies.more_commits', count: item.data[:other_commits_count], commits: commits_pluralize(item.data[:other_commits_count])) + json.other_commits_path diff_path(project_name_with_owner, diff: item.data[:other_commits]) + end + + when 'git_delete_branch_notification' + json.branch_name item.data[:branch_name] + json.project_link project_path(project_name_with_owner) + + when 'new_issue_notification' + 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? + end + + when 'new_user_notification' + json.user_name item.data[:user_name] + + when 'wiki_new_commit_notification' + json.wiki_link history_project_wiki_index_path(project_name_with_owner) + json.project_link project_path(project_name_with_owner) end - when 'git_delete_branch_notification' - json.branch_name item.data[:branch_name] - json.project_link project_path(project_name_with_owner) - - when 'new_issue_notification' - 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? - end - - when 'new_user_notification' - json.user_name item.data[:user_name] - - when 'wiki_new_commit_notification' - json.wiki_link history_project_wiki_index_path(project_name_with_owner) - json.project_link project_path(project_name_with_owner) - end - json.id item.id - #end -end \ No newline at end of file + json.id item.id + #end + end +end