Extract code to ActivityPanelController

Copy pasta buster
pull/3913/head
Alex Dik 9 years ago
parent aded24d3e1
commit 1198c2bfd1
  1. 55
      frontend/app/components/routes/controllers/work-package-details.controller.js
  2. 54
      frontend/app/components/routes/controllers/work-package-show.controller.js
  3. 78
      frontend/app/components/wp-panels/activity-panel/activity-panel.controller.js
  4. 3
      frontend/app/components/wp-panels/activity-panel/activity-panel.directive.js

@ -31,8 +31,8 @@ angular
.controller('WorkPackageDetailsController', WorkPackageDetailsController); .controller('WorkPackageDetailsController', WorkPackageDetailsController);
function WorkPackageDetailsController($scope, $state, latestTab, workPackage, I18n, RELATION_TYPES, function WorkPackageDetailsController($scope, $state, latestTab, workPackage, I18n, RELATION_TYPES,
RELATION_IDENTIFIERS, $q, $rootScope, $filter, WorkPackagesHelper, PathHelper, UsersHelper, RELATION_IDENTIFIERS, $q, $rootScope, WorkPackagesHelper, PathHelper, UsersHelper,
ConfigurationService, WorkPackageService, ActivityService, CommonRelationsHandler, WorkPackageService, CommonRelationsHandler,
ChildrenRelationsHandler, ParentRelationsHandler, NotificationsService) { ChildrenRelationsHandler, ParentRelationsHandler, NotificationsService) {
$scope.$on('$stateChangeSuccess', function(event, toState){ $scope.$on('$stateChangeSuccess', function(event, toState){
@ -86,11 +86,6 @@ function WorkPackageDetailsController($scope, $state, latestTab, workPackage, I1
var projectId = workPackage.embedded.project.props.id; var projectId = workPackage.embedded.project.props.id;
$scope.autocompletePath = PathHelper.staticWorkPackagesAutocompletePath(projectId); $scope.autocompletePath = PathHelper.staticWorkPackagesAutocompletePath(projectId);
// activities and latest activities
$scope.activitiesSortedInDescendingOrder = ConfigurationService.commentsSortedInDescendingOrder();
$scope.activities = [];
aggregateActivities($scope.workPackage);
// watchers // watchers
if(workPackage.links.watchers) { if(workPackage.links.watchers) {
$scope.watchers = workPackage.embedded.watchers.embedded.elements; $scope.watchers = workPackage.embedded.watchers.embedded.elements;
@ -143,52 +138,6 @@ function WorkPackageDetailsController($scope, $state, latestTab, workPackage, I1
return !!($scope.workPackage && $scope.workPackage.embedded.watchers !== undefined); return !!($scope.workPackage && $scope.workPackage.embedded.watchers !== undefined);
}; };
$scope.isInitialActivity = ActivityService.isInitialActivity;
function aggregateActivities(workPackage) {
// Do not yet add any intermittent result to the scope,
// as we will get an inconsistent activity view
// As we may not what activities will be added at a given time,
// let them be aggregated asynchronously.
var aggregated = [],
totalActivities = 0;
var aggregate = function(success, activity) {
if (success === true) {
aggregated = aggregated.concat(activity);
}
if (++totalActivities === 2) {
$scope.activities = $filter('orderBy')(aggregated,
'props.createdAt',
$scope.activitiesSortedInDescendingOrder
);
}
};
addDisplayedActivities(workPackage, aggregate);
addDisplayedRevisions(workPackage, aggregate);
}
function addDisplayedActivities(workPackage, aggregate) {
var activities = workPackage.embedded.activities.embedded.elements;
aggregate(true, activities);
}
function addDisplayedRevisions(workPackage, aggregate) {
var linkedRevisions = workPackage.links.revisions;
if (linkedRevisions === undefined) {
return aggregate();
}
linkedRevisions
.fetch()
.then(function(data) {
aggregate(true, data.embedded.elements);
}, aggregate);
}
// toggles // toggles

@ -31,8 +31,8 @@ angular
.controller('WorkPackageShowController', WorkPackageShowController); .controller('WorkPackageShowController', WorkPackageShowController);
function WorkPackageShowController($scope, $rootScope, $state, latestTab, workPackage, I18n, function WorkPackageShowController($scope, $rootScope, $state, latestTab, workPackage, I18n,
RELATION_TYPES, RELATION_IDENTIFIERS, $filter, $q, WorkPackagesHelper, PathHelper, UsersHelper, RELATION_TYPES, RELATION_IDENTIFIERS, $q, WorkPackagesHelper, PathHelper, UsersHelper,
ConfigurationService, WorkPackageService, ActivityService, CommonRelationsHandler, WorkPackageService, CommonRelationsHandler,
ChildrenRelationsHandler, ParentRelationsHandler, WorkPackagesOverviewService, ChildrenRelationsHandler, ParentRelationsHandler, WorkPackagesOverviewService,
WorkPackageFieldService, EditableFieldsState, WorkPackagesDisplayHelper, NotificationsService, WorkPackageFieldService, EditableFieldsState, WorkPackagesDisplayHelper, NotificationsService,
WorkPackageAuthorization, PERMITTED_MORE_MENU_ACTIONS, HookService, $window, WorkPackageAuthorization, PERMITTED_MORE_MENU_ACTIONS, HookService, $window,
@ -145,50 +145,6 @@ function WorkPackageShowController($scope, $rootScope, $state, latestTab, workPa
$scope.outputMessage = outputMessage; // expose to child controllers $scope.outputMessage = outputMessage; // expose to child controllers
$scope.outputError = outputError; // expose to child controllers $scope.outputError = outputError; // expose to child controllers
function aggregateActivities(workPackage) {
// Do not yet add any intermittent result to the scope,
// as we will get an inconsistent activity view
// As we may not what activities will be added at a given time,
// let them be aggregated asynchronously.
var aggregated = [],
totalActivities = 0;
var aggregate = function(success, activity) {
if (success === true) {
aggregated = aggregated.concat(activity);
}
if (++totalActivities === 2) {
$scope.activities = $filter('orderBy')(aggregated,
'props.createdAt',
$scope.activitiesSortedInDescendingOrder
);
}
};
addDisplayedActivities(workPackage, aggregate);
addDisplayedRevisions(workPackage, aggregate);
}
function addDisplayedActivities(workPackage, aggregate) {
var activities = workPackage.embedded.activities.embedded.elements;
aggregate(true, activities);
}
function addDisplayedRevisions(workPackage, aggregate) {
var linkedRevisions = workPackage.links.revisions;
if (linkedRevisions === undefined) {
return aggregate();
}
linkedRevisions
.fetch()
.then(function(data) {
aggregate(true, data.embedded.elements);
}, aggregate);
}
function setWorkPackageScopeProperties(workPackage){ function setWorkPackageScopeProperties(workPackage){
$scope.workPackage = workPackage; $scope.workPackage = workPackage;
@ -200,10 +156,6 @@ function WorkPackageShowController($scope, $rootScope, $state, latestTab, workPa
var projectId = workPackage.embedded.project.props.id; var projectId = workPackage.embedded.project.props.id;
$scope.autocompletePath = PathHelper.staticWorkPackagesAutocompletePath(projectId); $scope.autocompletePath = PathHelper.staticWorkPackagesAutocompletePath(projectId);
// activities and latest activities
$scope.activitiesSortedInDescendingOrder = ConfigurationService.commentsSortedInDescendingOrder();
$scope.activities = [];
aggregateActivities($scope.workPackage);
// watchers // watchers
if(workPackage.links.watchers) { if(workPackage.links.watchers) {
@ -264,8 +216,6 @@ function WorkPackageShowController($scope, $rootScope, $state, latestTab, workPa
return !!($scope.workPackage && $scope.workPackage.embedded.watchers !== undefined); return !!($scope.workPackage && $scope.workPackage.embedded.watchers !== undefined);
}; };
$scope.isInitialActivity = ActivityService.isInitialActivity;
// toggles // toggles
$scope.toggleStates = { $scope.toggleStates = {

@ -0,0 +1,78 @@
// -- copyright
// OpenProject is a project management system.
// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License version 3.
//
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
// Copyright (C) 2006-2013 Jean-Philippe Lang
// Copyright (C) 2010-2013 the ChiliProject Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// See doc/COPYRIGHT.rdoc for more details.
// ++
angular
.module('openproject.workPackages.controllers')
.controller('ActivityPanelController', ActivityPanelController);
function ActivityPanelController($filter, $scope, ConfigurationService, ActivityService){
$scope.isInitialActivity = ActivityService.isInitialActivity;
$scope.activitiesSortedInDescendingOrder = ConfigurationService.commentsSortedInDescendingOrder();
$scope.activities = [];
aggregateActivities($scope.workPackage);
function aggregateActivities(workPackage) {
var aggregated = [],
totalActivities = 0;
var aggregate = function(success, activity) {
if (success === true) {
aggregated = aggregated.concat(activity);
}
if (++totalActivities === 2) {
$scope.activities = $filter('orderBy')(
aggregated, 'props.createdAt', $scope.activitiesSortedInDescendingOrder
);
}
};
addDisplayedActivities(workPackage, aggregate);
addDisplayedRevisions(workPackage, aggregate);
}
function addDisplayedActivities(workPackage, aggregate) {
var activities = workPackage.embedded.activities.embedded.elements;
aggregate(true, activities);
}
function addDisplayedRevisions(workPackage, aggregate) {
var linkedRevisions = workPackage.links.revisions;
if (linkedRevisions === undefined) {
return aggregate();
}
linkedRevisions.fetch().then(function(data) {
aggregate(true, data.embedded.elements);
}, aggregate);
}
}

@ -33,7 +33,8 @@ angular
function activityPanel(){ function activityPanel(){
return { return {
restrict: 'E', restrict: 'E',
templateUrl: '/components/wp-panels/activity-panel/activity-panel.directive.html',
templateUrl: '/components/wp-panels/activity-panel/activity-panel.directive.html' controller: 'ActivityPanelController'
}; };
} }

Loading…
Cancel
Save