Merge pull request #6660 from opf/fix/faster_types_fetch

fetch only the project's type instead of the whole form

[ci skip]
pull/6664/head
Oliver Günther 6 years ago committed by GitHub
commit 7f95e7ecc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      frontend/src/app/components/op-context-menu/handlers/op-types-context-menu.directive.ts
  2. 3
      frontend/src/app/modules/common/path-helper/apiv3/apiv3-paths.ts
  3. 3
      frontend/src/app/modules/common/path-helper/apiv3/projects/apiv3-project-paths.ts
  4. 38
      frontend/src/app/modules/common/path-helper/apiv3/types/apiv3-types-paths.ts
  5. 4
      frontend/src/app/modules/hal/dm-services/type-dm.service.ts

@ -36,6 +36,7 @@ import {OpContextMenuTrigger} from "core-components/op-context-menu/handlers/op-
import {TypeResource} from 'core-app/modules/hal/resources/type-resource';
import {CollectionResource} from 'core-app/modules/hal/resources/collection-resource';
import {IWorkPackageCreateServiceToken} from "core-components/wp-new/wp-create.service.interface";
import {TypeDmService} from "core-app/modules/hal/dm-services/type-dm.service";
@Directive({
selector: '[opTypesCreateDropdown]'
@ -50,8 +51,7 @@ export class OpTypesContextMenuDirective extends OpContextMenuTrigger {
constructor(readonly elementRef:ElementRef,
readonly opContextMenu:OPContextMenuService,
readonly $state:StateService,
@Inject(IWorkPackageCreateServiceToken) protected wpCreate:WorkPackageCreateService) {
readonly typeDmService:TypeDmService) {
super(elementRef, opContextMenu);
}
@ -67,10 +67,9 @@ export class OpTypesContextMenuDirective extends OpContextMenuTrigger {
this.stateName = 'work-packages.new';
}
this.loadingPromise = this.wpCreate.getEmptyForm(this.projectIdentifier)
.then((form:any) => {
return this.buildItems(form.schema.type.allowedValues);
});
this.loadingPromise = this.typeDmService
.loadAll(this.projectIdentifier)
.then(types => this.buildItems(types));
}
protected open(evt:Event) {
@ -100,7 +99,7 @@ export class OpTypesContextMenuDirective extends OpContextMenuTrigger {
};
}
private buildItems(types:CollectionResource<TypeResource>) {
private buildItems(types:TypeResource[]) {
this.items = types.map((type:TypeResource) => {
return {
disabled: false,

@ -36,6 +36,7 @@ import {
import {Apiv3QueriesPaths} from 'core-app/modules/common/path-helper/apiv3/queries/apiv3-queries-paths';
import {Apiv3ProjectPaths} from 'core-app/modules/common/path-helper/apiv3/projects/apiv3-project-paths';
import {ApiV3FilterBuilder} from "core-components/api/api-v3/api-v3-filter-builder";
import {Apiv3TypesPaths} from "core-app/modules/common/path-helper/apiv3/types/apiv3-types-paths";
export class ApiV3Paths {
// Base path
@ -60,7 +61,7 @@ export class ApiV3Paths {
public readonly priorities = new SimpleResourceCollection(this.apiV3Base, 'priorities');
// /api/v3/types
public readonly types = new SimpleResourceCollection(this.apiV3Base, 'types');
public readonly types = new Apiv3TypesPaths(this.apiV3Base);
// /api/v3/work_packages
public readonly work_packages = new ApiV3WorkPackagesPaths(this.apiV3Base);

@ -28,6 +28,7 @@
import {SimpleResource} from 'core-app/modules/common/path-helper/apiv3/path-resources';
import {Apiv3QueriesPaths} from 'core-app/modules/common/path-helper/apiv3/queries/apiv3-queries-paths';
import {Apiv3TypesPaths} from "core-app/modules/common/path-helper/apiv3/types/apiv3-types-paths";
export class Apiv3ProjectPaths extends SimpleResource {
// Base path
@ -39,6 +40,8 @@ export class Apiv3ProjectPaths extends SimpleResource {
public readonly queries = new Apiv3QueriesPaths(this.path);
public readonly types = new Apiv3TypesPaths(this.path);
public readonly work_packages = {
form: new SimpleResource(this.path, 'work_packages/form')
};

@ -0,0 +1,38 @@
// -- 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 {
SimpleResourceCollection
} from 'core-app/modules/common/path-helper/apiv3/path-resources';
import {Apiv3QueryPaths} from 'core-app/modules/common/path-helper/apiv3/queries/apiv3-query-paths';
export class Apiv3TypesPaths extends SimpleResourceCollection<Apiv3QueryPaths> {
constructor(basePath:string) {
super(basePath, 'types');
}
}

@ -41,8 +41,8 @@ export class TypeDmService {
protected pathHelper:PathHelperService) {
}
public loadAll():Promise<TypeResource[]> {
const typeUrl = this.pathHelper.api.v3.types.toString();
public loadAll(projectIdentifier:string|undefined):Promise<TypeResource[]> {
const typeUrl = this.pathHelper.api.v3.withOptionalProject(projectIdentifier).types.toString();
return this.halResourceService
.get<CollectionResource<TypeResource>>(typeUrl)

Loading…
Cancel
Save