From 7c9e032a5f8095dcec7c7e570b998b8c58b3dcb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Tue, 28 Jun 2016 12:59:17 +0200 Subject: [PATCH] Remove props usage --- .../hal-resources/user-resource.service.ts | 5 +- .../wp-details/wp-details.controller.ts | 4 + .../routing/wp-details/wp.list.details.html | 10 +- .../routing/wp-show/wp-show.controller.ts | 103 ++++++++---------- .../wp-watcher-button.directive.js | 6 +- .../wp-activity/activity-entry.directive.js | 4 +- .../wp-details-toolbar.directive.ts | 6 +- .../overview-panel.directive.html | 4 +- .../watchers-panel.controller.js | 4 +- .../watchers-panel/wp-watchers.service.js | 34 ++---- .../wp-parent-relation-group.service.ts | 14 ++- .../wp-relations/wp-relations.directive.ts | 4 +- frontend/app/services/project-service.js | 2 +- .../activities/activity-link-directive.js | 2 +- .../activities/user-activity-directive.js | 8 +- .../work-package-attachments-directive.js | 2 +- .../models/work-package-authorization.js | 14 +-- .../work-package-attachments-service.js | 8 +- 18 files changed, 109 insertions(+), 125 deletions(-) diff --git a/frontend/app/components/api/api-v3/hal-resources/user-resource.service.ts b/frontend/app/components/api/api-v3/hal-resources/user-resource.service.ts index ac184fc35f..c4d396339d 100644 --- a/frontend/app/components/api/api-v3/hal-resources/user-resource.service.ts +++ b/frontend/app/components/api/api-v3/hal-resources/user-resource.service.ts @@ -52,10 +52,13 @@ export class UserResource extends HalResource { return ['active', 'registered']; } + public get showUserPath() { + return this.showUser.$link.href; + } + public get isActive() { return UserResource.active_user_statuses.indexOf(this.status) >= 0; } -}, } function userResource() { diff --git a/frontend/app/components/routing/wp-details/wp-details.controller.ts b/frontend/app/components/routing/wp-details/wp-details.controller.ts index b8d71f4c58..e580cc5de7 100644 --- a/frontend/app/components/routing/wp-details/wp-details.controller.ts +++ b/frontend/app/components/routing/wp-details/wp-details.controller.ts @@ -68,6 +68,10 @@ function WorkPackageDetailsController($scope, $rootScope.$emit('workPackagesRefreshInBackground'); }; + $scope.canViewWorkPackageWatchers = function() { + return !!($scope.workPackageResource && $scope.workPackageResource.watchers !== undefined); + }; + function getFocusAnchorLabel(tab, workPackage) { var tabLabel = I18n.t('js.work_packages.tabs.' + tab), params = { diff --git a/frontend/app/components/routing/wp-details/wp.list.details.html b/frontend/app/components/routing/wp-details/wp.list.details.html index b5a360bfe2..a90cfa70be 100644 --- a/frontend/app/components/routing/wp-details/wp.list.details.html +++ b/frontend/app/components/routing/wp-details/wp.list.details.html @@ -19,11 +19,7 @@ ui-sref-active="selected"> - -
  • - -
  • -
  • @@ -40,8 +36,8 @@ -
    - +
    + { $scope.workPackageResource = wp; wp.schema.$load(); - }); - // Listen to the event globally, as listeners are not necessarily - // in the child scope - var refreshRequiredFunction = $rootScope.$on('workPackageRefreshRequired', function() { - refreshWorkPackage(); - }); - $scope.$on('$destroy', refreshRequiredFunction); + // Listen to the event globally, as listeners are not necessarily + // in the child scope + var refreshRequiredFunction = $rootScope.$on('workPackageRefreshRequired', function() { + wpCacheService.updateWorkPackage($scope.workPackageResource); + }); + $scope.$on('$destroy', refreshRequiredFunction); + + AuthorisationService.initModelAuth('work_package', $scope.workPackageResource); + + var authorization = new WorkPackageAuthorization($scope.workPackageResource); + $scope.permittedActions = angular.extend(getPermittedActions(authorization, PERMITTED_MORE_MENU_ACTIONS), + getPermittedPluginActions(authorization)); + $scope.actionsAvailable = Object.keys($scope.permittedActions).length > 0; + + // END stuff copied from details toolbar directive... - AuthorisationService.initModelAuth('work_package', workPackage.links); + $scope.I18n = I18n; + $scope.$parent.preselectedWorkPackageId = $scope.workPackageResource.id; + $scope.maxDescriptionLength = 800; + $scope.projectIdentifier = $scope.workPackageResource.project.identifier; + + // initialization + setWorkPackageScopeProperties($scope.workPackageResource); + + }); - // initialization - setWorkPackageScopeProperties(workPackage); // stuff copied from details toolbar directive... function getPermittedActions(authorization, permittedMoreMenuActions) { @@ -100,7 +113,7 @@ function WorkPackageShowController($scope, return augmentedPluginActions; } function deleteSelectedWorkPackage() { - var promise = WorkPackageService.performBulkDelete([$scope.workPackage.props.id], true); + var promise = WorkPackageService.performBulkDelete([$scope.workPackageResource.id], true); promise.success(function() { $state.go('work-packages.list', {projectPath: $scope.projectIdentifier}); @@ -116,26 +129,6 @@ function WorkPackageShowController($scope, break; } }; - var authorization = new WorkPackageAuthorization($scope.workPackage); - $scope.permittedActions = angular.extend(getPermittedActions(authorization, PERMITTED_MORE_MENU_ACTIONS), - getPermittedPluginActions(authorization)); - $scope.actionsAvailable = Object.keys($scope.permittedActions).length > 0; - - // END stuff copied from details toolbar directive... - - $scope.I18n = I18n; - $scope.$parent.preselectedWorkPackageId = $scope.workPackage.props.id; - $scope.maxDescriptionLength = 800; - $scope.projectIdentifier = $scope.workPackage.embedded.project.props.identifier; - - - function refreshWorkPackage() { - WorkPackageService.getWorkPackage($scope.workPackage.props.id) - .then(function(workPackage) { - setWorkPackageScopeProperties(workPackage); - $scope.$broadcast('workPackageRefreshed'); - }); - } function outputMessage(message, isError) { $scope.$emit('flashMessage', { @@ -153,39 +146,36 @@ function WorkPackageShowController($scope, function setWorkPackageScopeProperties(workPackage){ - $scope.workPackage = workPackage; - $scope.isWatched = workPackage.links.hasOwnProperty('unwatch'); - $scope.displayWatchButton = workPackage.links.hasOwnProperty('unwatch') || - workPackage.links.hasOwnProperty('watch'); + $scope.isWatched = workPackage.hasOwnProperty('unwatch'); + $scope.displayWatchButton = workPackage.hasOwnProperty('unwatch') || + workPackage.hasOwnProperty('watch'); // watchers - if(workPackage.links.watchers) { - $scope.watchers = workPackage.embedded.watchers.embedded.elements; + if(workPackage.watchers) { + $scope.watchers = workPackage.watchers.elements; } - $scope.showStaticPagePath = PathHelper.workPackagePath($scope.workPackage.props.id); + $scope.showStaticPagePath = PathHelper.workPackagePath($scope.workPackageResource.id); // Type - $scope.type = workPackage.embedded.type; + $scope.type = workPackage.type; // Author - $scope.author = workPackage.embedded.author; - $scope.authorPath = PathHelper.userPath($scope.author.props.id); + $scope.author = workPackage.author; + $scope.authorPath = $scope.author.showUserPath; $scope.authorActive = $scope.author.isActive; // Attachments - $scope.attachments = workPackage.embedded.attachments.embedded.elements; - } + $scope.attachments = workPackage.attachments.elements; - $scope.toggleWatch = function() { - // Toggle early to avoid delay. - $scope.isWatched = !$scope.isWatched; - WorkPackageService.toggleWatch($scope.workPackage) - .then(function() { refreshWorkPackage() }, outputError); - }; + $scope.focusAnchorLabel = getFocusAnchorLabel( + $state.current.url.replace(/\//, ''), + $scope.workPackageResource + ); + } $scope.canViewWorkPackageWatchers = function() { - return !!($scope.workPackage && $scope.workPackage.embedded.watchers !== undefined); + return !!($scope.workPackageResource && $scope.workPackageResource.watchers !== undefined); }; // toggles @@ -199,17 +189,12 @@ function WorkPackageShowController($scope, var tabLabel = I18n.t('js.work_packages.tabs.' + tab), params = { tab: tabLabel, - type: workPackage.embedded.type.props.name, - subject: workPackage.props.subject + type: workPackage.type.name, + subject: workPackage.subject }; return I18n.t('js.label_work_package_details_you_are_here', params); } - - $scope.focusAnchorLabel = getFocusAnchorLabel( - $state.current.url.replace(/\//, ''), - $scope.workPackage - ); } angular diff --git a/frontend/app/components/work-packages/wp-watcher-button/wp-watcher-button.directive.js b/frontend/app/components/work-packages/wp-watcher-button/wp-watcher-button.directive.js index d279b53953..04f59a35cf 100644 --- a/frontend/app/components/work-packages/wp-watcher-button/wp-watcher-button.directive.js +++ b/frontend/app/components/work-packages/wp-watcher-button/wp-watcher-button.directive.js @@ -51,9 +51,9 @@ function WorkPackageWatcherButtonController($rootScope, WorkPackageService) { var vm = this, workPackage = vm.workPackage; - vm.isWatched = workPackage.links.hasOwnProperty('unwatch'); - vm.displayWatchButton = workPackage.links.hasOwnProperty('unwatch') || - workPackage.links.hasOwnProperty('watch'); + vm.isWatched = workPackage.hasOwnProperty('unwatch'); + vm.displayWatchButton = workPackage.hasOwnProperty('unwatch') || + workPackage.hasOwnProperty('watch'); vm.toggleWatch = function() { diff --git a/frontend/app/components/wp-activity/activity-entry.directive.js b/frontend/app/components/wp-activity/activity-entry.directive.js index 5d281c1993..48208173ad 100644 --- a/frontend/app/components/wp-activity/activity-entry.directive.js +++ b/frontend/app/components/wp-activity/activity-entry.directive.js @@ -45,10 +45,10 @@ function activityEntry(PathHelper) { }, link: function(scope) { - var projectId = scope.workPackage.project.props.id; + var projectId = scope.workPackage.project.id; scope.autocompletePath = PathHelper.workPackageJsonAutoCompletePath(projectId); - scope.activityType = scope.activity.props._type; + scope.activityType = scope.activity._type; scope.activityLabel = I18n.t('js.label_activity_no', { activityNo: scope.activityNo }); } }; diff --git a/frontend/app/components/wp-details/wp-details-toolbar.directive.ts b/frontend/app/components/wp-details/wp-details-toolbar.directive.ts index e43235a5e8..55452d061a 100644 --- a/frontend/app/components/wp-details/wp-details-toolbar.directive.ts +++ b/frontend/app/components/wp-details/wp-details-toolbar.directive.ts @@ -85,8 +85,8 @@ function wpDetailsToolbar( link: function(scope, attr, element) { var authorization = new WorkPackageAuthorization(scope.workPackage); - scope.displayWatchButton = scope.workPackage.links.hasOwnProperty('unwatch') || - scope.workPackage.links.hasOwnProperty('watch'); + scope.displayWatchButton = scope.workPackage.hasOwnProperty('unwatch') || + scope.workPackage.hasOwnProperty('watch'); scope.I18n = I18n; scope.permittedActions = angular.extend(getPermittedActions(authorization, PERMITTED_MORE_MENU_ACTIONS), @@ -107,7 +107,7 @@ function wpDetailsToolbar( scope.wpEditModeState = wpEditModeState; function deleteSelectedWorkPackage() { - var workPackageDeletionId = scope.workPackage.props.id; + var workPackageDeletionId = scope.workPackage.id; var promise = WorkPackageService.performBulkDelete([workPackageDeletionId], true); promise.success(function() { diff --git a/frontend/app/components/wp-panels/overview-panel/overview-panel.directive.html b/frontend/app/components/wp-panels/overview-panel/overview-panel.directive.html index 9f1fea9ef7..a055f79801 100644 --- a/frontend/app/components/wp-panels/overview-panel/overview-panel.directive.html +++ b/frontend/app/components/wp-panels/overview-panel/overview-panel.directive.html @@ -1,11 +1,11 @@ -
    +

    {{ vm.I18n.t('js.label_latest_activity') }}

    - +
    diff --git a/frontend/app/components/wp-panels/watchers-panel/watchers-panel.controller.js b/frontend/app/components/wp-panels/watchers-panel/watchers-panel.controller.js index 77c8bd0ba2..5130bbe00b 100644 --- a/frontend/app/components/wp-panels/watchers-panel/watchers-panel.controller.js +++ b/frontend/app/components/wp-panels/watchers-panel/watchers-panel.controller.js @@ -36,8 +36,8 @@ function WatchersPanelController($scope, wpWatchers) { var fetchWatchers = function(loading) { vm.error = false; vm.loading = angular.isUndefined(loading); - vm.allowedToAdd = !!vm.workPackage.links.addWatcher; - vm.allowedToRemove = !!vm.workPackage.links.removeWatcher; + vm.allowedToAdd = !!vm.workPackage.addWatcher; + vm.allowedToRemove = !!vm.workPackage.removeWatcher; wpWatchers.forWorkPackage(vm.workPackage).then(function(users) { vm.watching = users.watching; diff --git a/frontend/app/components/wp-panels/watchers-panel/wp-watchers.service.js b/frontend/app/components/wp-panels/watchers-panel/wp-watchers.service.js index 0d84e1a5cd..9086951ef8 100644 --- a/frontend/app/components/wp-panels/watchers-panel/wp-watchers.service.js +++ b/frontend/app/components/wp-panels/watchers-panel/wp-watchers.service.js @@ -32,28 +32,18 @@ angular function wpWatchers($http, $q) { - var getWatchers = function(path) { - return function() { - var watchers = $q.defer(); - - $http.get(path).success(function(data) { - watchers.resolve(data._embedded.elements); - - }).error(function(err) { - watchers.reject(err); - }); - - return watchers.promise; - }; + var getWatchers = function(link) { + return link.$load().then(function(resource) { + return resource.elements; + }); }; var watching = function(workPackage) { - var path = workPackage.links.watchers.url(); - return getWatchers(path)(); + return getWatchers(workPackage.watchers); }; var available = function(workPackage) { - var link = workPackage.links.availableWatchers; + var link = workPackage.availableWatchers; // If the user has the permission to view watchers, but not // add them, this link will not be available. @@ -61,7 +51,7 @@ function wpWatchers($http, $q) { return $q.when([]); } - return getWatchers(link.url())(); + return getWatchers(link); }; var all = function(workPackage) { @@ -86,9 +76,9 @@ function wpWatchers($http, $q) { var add = function(workPackage, watcher) { var added = $q.defer(), - path = workPackage.links.addWatcher.props.href, - method = workPackage.links.addWatcher.props.method, - payload = { user: { href: watcher._links.self.href } }; + path = workPackage.addWatcher.$link.href, + method = workPackage.addWatcher.$link.method, + payload = { user: { href: watcher.href } }; $http[method](path, payload).then(function() { added.resolve(watcher); @@ -102,8 +92,8 @@ function wpWatchers($http, $q) { var remove = function(workPackage, watcher) { var removed = $q.defer(), - path = workPackage.links.removeWatcher.props.href, - method = workPackage.links.removeWatcher.props.method; + path = workPackage.removeWatcher.$link.href, + method = workPackage.removeWatcher.$link.method; path = path.replace(/\{user\_id\}/, watcher.id); diff --git a/frontend/app/components/wp-relations/wp-relation-group/wp-parent-relation-group.service.ts b/frontend/app/components/wp-relations/wp-relation-group/wp-parent-relation-group.service.ts index 6a3aaca2f9..96e4330edf 100644 --- a/frontend/app/components/wp-relations/wp-relation-group/wp-parent-relation-group.service.ts +++ b/frontend/app/components/wp-relations/wp-relation-group/wp-parent-relation-group.service.ts @@ -36,6 +36,7 @@ import { import {WorkPackageNotificationService} from "../../wp-edit/wp-notification.service"; import {ErrorResource} from "../../api/api-v3/hal-resources/error-resource.service"; +var $q:ng.IQService; var HalResource; var PathHelper:any; var wpCacheService:WorkPackageCacheService; @@ -82,10 +83,11 @@ export class WorkPackageParentRelationGroup extends WorkPackageRelationGroup { return wpCacheService.updateWorkPackage(wp); }) .catch(error => { - if (!(error.data instanceof ErrorResource)) { - return wpNotificationsService.showGeneralError(); + if (error.data instanceof ErrorResource) { + wpNotificationsService.showError(error.data, this.workPackage); + } else { + wpNotificationsService.showGeneralError(); } - wpNotificationsService.showError(error.data, this.workPackage); }); } @@ -98,10 +100,12 @@ export class WorkPackageParentRelationGroup extends WorkPackageRelationGroup { } function wpParentRelationGroupService(...args) { - [HalResource, PathHelper, wpCacheService, wpNotificationsService] = args; + [$q, HalResource, PathHelper, wpCacheService, wpNotificationsService] = args; return WorkPackageParentRelationGroup; } -wpParentRelationGroupService.$inject = ['HalResource', 'PathHelper', 'wpCacheService', 'wpNotificationsService']; +wpParentRelationGroupService.$inject = [ + '$q', 'HalResource', 'PathHelper', 'wpCacheService', 'wpNotificationsService' +]; wpTabsModule.factory('WorkPackageParentRelationGroup', wpParentRelationGroupService); diff --git a/frontend/app/components/wp-relations/wp-relations.directive.ts b/frontend/app/components/wp-relations/wp-relations.directive.ts index 009334bd6d..3e28547b2b 100644 --- a/frontend/app/components/wp-relations/wp-relations.directive.ts +++ b/frontend/app/components/wp-relations/wp-relations.directive.ts @@ -79,7 +79,9 @@ export class WorkPackageRelationsController { this.wpToAddId = null; this.handleSuccess(-1); }) - .catch(error => error.data.showErrorNotification()); + .catch(error => { + error.data.showErrorNotification(); + }); } public canRemoveRelation(relation?):boolean { diff --git a/frontend/app/services/project-service.js b/frontend/app/services/project-service.js index c6fa5b9bb8..ab02e7a1cd 100644 --- a/frontend/app/services/project-service.js +++ b/frontend/app/services/project-service.js @@ -81,7 +81,7 @@ module.exports = function($http, PathHelper, apiV3) { }, getWorkPackageProject: function(workPackage) { - return ProjectService.doQuery(workPackage.links.project.props.href); + return ProjectService.doQuery(workPackage.project.$link.href); }, doQuery: function(url, params) { diff --git a/frontend/app/work_packages/activities/activity-link-directive.js b/frontend/app/work_packages/activities/activity-link-directive.js index 8ed72bb450..c0439e4bba 100644 --- a/frontend/app/work_packages/activities/activity-link-directive.js +++ b/frontend/app/work_packages/activities/activity-link-directive.js @@ -9,7 +9,7 @@ module.exports = function() { onFocus: '&' }, link: function(scope) { - scope.workPackageId = scope.workPackage.props.id; + scope.workPackageId = scope.workPackage.id; scope.activityHtmlId = 'activity-' + scope.activityNo; } }; diff --git a/frontend/app/work_packages/activities/user-activity-directive.js b/frontend/app/work_packages/activities/user-activity-directive.js index a2cbe6c1ad..33ac1d9b82 100644 --- a/frontend/app/work_packages/activities/user-activity-directive.js +++ b/frontend/app/work_packages/activities/user-activity-directive.js @@ -81,7 +81,7 @@ module.exports = function($uiViewScroll, scope.userLabel = I18n.t('js.label_author', { user: scope.userName }); }); - scope.postedComment = $sce.trustAsHtml(scope.activity.props.comment.html); + scope.postedComment = $sce.trustAsHtml(scope.activity.comment.html); if(scope.postedComment) { scope.activityLabelWithComment = I18n.t('js.label_activity_with_comment_no', { activityNo: scope.activityNo @@ -89,7 +89,7 @@ module.exports = function($uiViewScroll, } scope.details = []; - angular.forEach(scope.activity.props.details, function(detail) { + angular.forEach(scope.activity.details, function(detail) { this.push($sce.trustAsHtml(detail.html)); }, scope.details); @@ -100,7 +100,7 @@ module.exports = function($uiViewScroll, }); scope.editComment = function() { - scope.activity.editedComment = scope.activity.props.comment.raw; + scope.activity.editedComment = scope.activity.comment.raw; scope.inEdit = true; }; @@ -111,7 +111,7 @@ module.exports = function($uiViewScroll, scope.quoteComment = function() { scope.$emit( 'workPackage.comment.quoteThis', - quotedText(scope.activity.props.comment.raw) + quotedText(scope.activity.comment.raw) ); }; diff --git a/frontend/app/work_packages/directives/work-package-attachments-directive.js b/frontend/app/work_packages/directives/work-package-attachments-directive.js index 50535b3f05..fb02444096 100644 --- a/frontend/app/work_packages/directives/work-package-attachments-directive.js +++ b/frontend/app/work_packages/directives/work-package-attachments-directive.js @@ -70,7 +70,7 @@ module.exports = function( scope.rejectedFiles = []; scope.size = ConversionService.fileSize; - scope.hasRightToUpload = !!(workPackage.links.addAttachment || workPackage.isNew); + scope.hasRightToUpload = !!(workPackage.addAttachment || workPackage.isNew); var currentlyRemoving = []; scope.remove = function(file) { diff --git a/frontend/app/work_packages/models/work-package-authorization.js b/frontend/app/work_packages/models/work-package-authorization.js index 26409b46c7..559f1846c1 100644 --- a/frontend/app/work_packages/models/work-package-authorization.js +++ b/frontend/app/work_packages/models/work-package-authorization.js @@ -31,8 +31,8 @@ module.exports = function(ProjectService, $state, PathHelper) { var WorkPackageAuthorization = function (workPackage) { this.workPackage = workPackage; - if (angular.isDefined(this.workPackage.embedded.project)) { - this.project = workPackage.embedded.project; + if (angular.isDefined(this.workPackage.project)) { + this.project = workPackage.project; } else { this.project = ProjectService.getWorkPackageProject(this.workPackage).then(function(project) { @@ -41,19 +41,19 @@ module.exports = function(ProjectService, $state, PathHelper) { } this.allActions = { - workPackage: this.workPackage.links, - project: this.project.links + workPackage: this.workPackage, + project: this.project }; }; WorkPackageAuthorization.prototype = { copyLink: function() { if ($state.current.name.indexOf('work-packages.show') === 0){ - return PathHelper.workPackageCopyPath(this.workPackage.props.id); + return PathHelper.workPackageCopyPath(this.workPackage.id); } else if ($state.current.name.indexOf('work-packages.list.details') === 0) { - return PathHelper.workPackageDetailsCopyPath(this.project.props.identifier, - this.workPackage.props.id); + return PathHelper.workPackageDetailsCopyPath(this.project.identifier, + this.workPackage.id); } }, linkForAction: function(action) { diff --git a/frontend/app/work_packages/services/work-package-attachments-service.js b/frontend/app/work_packages/services/work-package-attachments-service.js index c76303c06a..22f6b44b0a 100644 --- a/frontend/app/work_packages/services/work-package-attachments-service.js +++ b/frontend/app/work_packages/services/work-package-attachments-service.js @@ -29,7 +29,7 @@ module.exports = function(Upload, PathHelper, I18n, NotificationsService, $q, $timeout, $http) { 'use strict'; var upload = function(workPackage, files) { - var uploadPath = workPackage.links.addAttachment.url(); + var uploadPath = workPackage.addAttachment.$link.href; // for file in files build some promises, create a notification per WP, // notify the noticiation (wat?) about progress var uploads = _.map(files, function(file) { @@ -48,8 +48,8 @@ module.exports = function(Upload, PathHelper, I18n, NotificationsService, $q, $t // notify the user var message = I18n.t('js.label_upload_notification', { - id: workPackage.props.id, - subject: workPackage.props.subject + id: workPackage.id, + subject: workPackage.subject }); var notification = NotificationsService.addWorkPackageUpload(message, uploads); @@ -65,7 +65,7 @@ module.exports = function(Upload, PathHelper, I18n, NotificationsService, $q, $t return allUploadsDone.promise; }, load = function(workPackage, reload) { - var path = workPackage.links.attachments.url(), + var path = workPackage.attachments.$link.href, attachments = $q.defer(); $http.get(path, { cache: !reload }).success(function(response) { attachments.resolve(response._embedded.elements);