[#369] activity filters

This commit is contained in:
Alexander Machehin 2014-04-17 22:49:51 +06:00
parent 1aceaff1b8
commit 836139c54b
4 changed files with 93 additions and 85 deletions

View File

@ -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;
});
};
}]);

View File

@ -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])

View File

@ -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}}

View File

@ -1,4 +1,9 @@
json.array!(@activity_feeds) do |item|
if @activity_feeds.next_page
json.next_page_link root_path(filter: @filter, page: @activity_feeds.next_page, format: :json)
end
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
@ -58,6 +63,8 @@ json.array!(@activity_feeds) do |item|
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
end