Remove props usage

pull/4605/head
Oliver Günther 8 years ago
parent 9cf55f4b20
commit 7c9e032a5f
  1. 5
      frontend/app/components/api/api-v3/hal-resources/user-resource.service.ts
  2. 4
      frontend/app/components/routing/wp-details/wp-details.controller.ts
  3. 10
      frontend/app/components/routing/wp-details/wp.list.details.html
  4. 103
      frontend/app/components/routing/wp-show/wp-show.controller.ts
  5. 6
      frontend/app/components/work-packages/wp-watcher-button/wp-watcher-button.directive.js
  6. 4
      frontend/app/components/wp-activity/activity-entry.directive.js
  7. 6
      frontend/app/components/wp-details/wp-details-toolbar.directive.ts
  8. 4
      frontend/app/components/wp-panels/overview-panel/overview-panel.directive.html
  9. 4
      frontend/app/components/wp-panels/watchers-panel/watchers-panel.controller.js
  10. 34
      frontend/app/components/wp-panels/watchers-panel/wp-watchers.service.js
  11. 14
      frontend/app/components/wp-relations/wp-relation-group/wp-parent-relation-group.service.ts
  12. 4
      frontend/app/components/wp-relations/wp-relations.directive.ts
  13. 2
      frontend/app/services/project-service.js
  14. 2
      frontend/app/work_packages/activities/activity-link-directive.js
  15. 8
      frontend/app/work_packages/activities/user-activity-directive.js
  16. 2
      frontend/app/work_packages/directives/work-package-attachments-directive.js
  17. 14
      frontend/app/work_packages/models/work-package-authorization.js
  18. 8
      frontend/app/work_packages/services/work-package-attachments-service.js

@ -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() {

@ -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 = {

@ -19,11 +19,7 @@
ui-sref-active="selected">
<a href="" ng-bind="I18n.t('js.work_packages.tabs.relations')"/>
</li>
<li ng-if="!workPackage">
<span class="ui-state-disabled" ng-bind="I18n.t('js.work_packages.tabs.watchers')"/>
</li>
<li ng-if="workPackage && canViewWorkPackageWatchers()"
<li ng-if="canViewWorkPackageWatchers()"
ui-sref="work-packages.list.details.watchers({})"
ui-sref-active="selected">
<a href="" ng-bind="I18n.t('js.work_packages.tabs.watchers')"/>
@ -40,8 +36,8 @@
</div>
<div class="bottom-toolbar" ng-if="workPackage">
<wp-details-toolbar work-package='workPackage'></wp-details-toolbar>
<div class="bottom-toolbar" ng-if="workPackageResource">
<wp-details-toolbar work-package='workPackageResource'></wp-details-toolbar>
<edit-actions-bar
ng-show="wpEditModeState.active"
on-save="wpEditModeState.save()"

@ -34,7 +34,6 @@ function WorkPackageShowController($scope,
$state,
$window,
PERMITTED_MORE_MENU_ACTIONS,
workPackage,
I18n,
PathHelper,
WorkPackageService,
@ -46,23 +45,37 @@ function WorkPackageShowController($scope,
$scope.wpEditModeState = wpEditModeState;
scopedObservable($scope, wpCacheService.loadWorkPackage(workPackage.props.id))
scopedObservable($scope, wpCacheService.loadWorkPackage($state.params.workPackageId))
.subscribe((wp: WorkPackageResource) => {
$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

@ -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() {

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

@ -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() {

@ -1,11 +1,11 @@
<wp-single-view></wp-single-view>
<div class="attributes-group" ng-if="workPackage">
<div class="attributes-group" ng-if="workPackageResource">
<div class="attributes-group--header">
<div class="attributes-group--header-container">
<h3 class="attributes-group--header-text">{{ vm.I18n.t('js.label_latest_activity') }}</h3>
</div>
</div>
<activity-panel template="overview" work-package="workPackage"></activity-panel>
<activity-panel template="overview" work-package="workPackageResource"></activity-panel>
</div>

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save