Correctly return HAL resources in from/to links

pull/4962/head
Oliver Günther 8 years ago
parent f601721deb
commit ff9c22771f
No known key found for this signature in database
GPG Key ID: 88872239EB414F99
  1. 8
      frontend/app/components/api/api-v3/hal-resource-types/hal-resource-types.config.ts
  2. 53
      frontend/app/components/api/api-v3/hal-resources/relation-resource.service.ts
  3. 6
      frontend/app/components/wp-relations/wp-relation-row/wp-relation-row.template.html
  4. 10
      frontend/app/components/wp-relations/wp-relations.service.ts
  5. 12
      lib/api/v3/relations/relation_representer.rb

@ -36,6 +36,7 @@ function halResourceTypesConfig(halResourceTypes:HalResourceTypesService) {
attrTypes: {
parent: 'WorkPackage',
children: 'WorkPackage',
relations: 'Relation',
}
},
Activity: {
@ -47,6 +48,13 @@ function halResourceTypesConfig(halResourceTypes:HalResourceTypesService) {
'Activity::Revision': {
user: 'User'
},
Relation: {
className: 'RelationResource',
attrTypes: {
from: 'WorkPackage',
to: 'WorkPackage'
}
},
Error: 'ErrorResource',
User: 'UserResource',
Collection: 'CollectionResource'

@ -0,0 +1,53 @@
//-- 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.
//++
import {HalResource} from './hal-resource.service';
import {opApiModule} from "../../../../angular-modules";
import {WorkPackageResource} from './work-package-resource.service';
export class RelationResource extends HalResource {
// Properties
public id:number;
public description:string|null;
public name:string;
public type:string;
// Links
public to:WorkPackageResource;
public from:WorkPackageResource;
public updateImmediately:HalResource;
public delete:HalResource;
}
function relationResource() {
return RelationResource;
}
opApiModule.factory('RelationResource', relationResource);

@ -4,13 +4,13 @@
<div class="grid-block hierarchy-item">
<div class="grid-content medium-3 collapse" aria-hidden="true">
{{ $ctrl.relationType }}
{{ $ctrl.relation.type }}
</div>
<div class="grid-content medium-5 collapse" wp-single-relation
ng-if="$ctrl.relatedWorkPackage">
<a href="{{ singleRelationCtrl.workPackagePath($ctrl.relatedWorkPackage.id) }}"
aria-label="{{ $ctrl.relationType + ' ' + singleRelationCtrl.getFullIdentifier($ctrl.relatedWorkPackage, true) }}">
aria-label="{{ $ctrl.relation.type + ' ' + singleRelationCtrl.getFullIdentifier($ctrl.relatedWorkPackage, true) }}">
{{ singleRelationCtrl.getFullIdentifier($ctrl.relatedWorkPackage, true) }}
</a>
</div>
@ -23,7 +23,7 @@
<div class="grid-content medium-1 collapse wp-relations-controls-section">
<accessible-by-keyboard ng-show="$ctrl.showRelationControls"
ng-if="$ctrl.relation.remove"
ng-if="$ctrl.relation.delete"
execute="$ctrl.removeRelation($ctrl.relation)"
aria-hidden="false"
class="-shown-in-accessibility-mode">

@ -36,13 +36,17 @@ export class WorkPackageRelationsService {
protected wpCacheService:WorkPackageCacheService,
protected wpNotificationsService:WorkPackageNotificationService,
protected I18n:op.I18n,
protected PathHelper,
protected NotificationsService) {
}
public addCommonRelation(workPackage, relationType, relatedWpId) {
const params = {
to_id: relatedWpId,
relation_type: relationType
_links: {
from: { href: workPackage.href },
to: { href: this.PathHelper.apiV3WorkPackagePath(relatedWpId) }
},
type: relationType
};
return workPackage.addRelation(params);
@ -61,7 +65,7 @@ export class WorkPackageRelationsService {
}
public removeCommonRelation(relation) {
return relation.remove();
return relation.delete();
}
public getTranslatedRelationTitle(relationTypeName:string) {

@ -156,11 +156,19 @@ module API
end
def from
represented.from
represent_work_package(represented.from)
end
def to
represented.to
represent_work_package(represented.to)
end
def represent_work_package(wp)
::API::V3::WorkPackages::WorkPackageRepresenter.create(
wp,
current_user: current_user,
embed_links: false
)
end
end
end

Loading…
Cancel
Save