Add board action service for versions

pull/7278/head
Henriette Dinger 6 years ago
parent ef99288c7f
commit 27ffd06446
  1. 2
      frontend/src/app/modules/boards/board/board-actions/status-action.service.ts
  2. 95
      frontend/src/app/modules/boards/board/board-actions/version-action.service.ts
  3. 4
      frontend/src/app/modules/boards/openproject-boards.module.ts
  4. 3
      frontend/src/app/modules/common/path-helper/apiv3/apiv3-paths.ts
  5. 54
      frontend/src/app/modules/hal/dm-services/version-dm.service.ts
  6. 2
      frontend/src/app/modules/hal/openproject-hal.module.ts
  7. 33
      frontend/src/app/modules/hal/resources/version-resource.ts

@ -13,8 +13,6 @@ import {FilterOperator} from "core-components/api/api-v3/api-v3-filter-builder";
@Injectable()
export class BoardStatusActionService implements BoardActionService {
private readonly v3 = this.pathHelper.api.v3;
constructor(protected pathHelper:PathHelperService,
protected boardListService:BoardListsService,
protected I18n:I18nService,

@ -0,0 +1,95 @@
import {Injectable} from "@angular/core";
import {BoardListsService} from "core-app/modules/boards/board/board-list/board-lists.service";
import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";
import {Board} from "core-app/modules/boards/board/board";
import {QueryResource} from "core-app/modules/hal/resources/query-resource";
import {BoardActionService} from "core-app/modules/boards/board/board-actions/board-action.service";
import {HalResource} from "core-app/modules/hal/resources/hal-resource";
import {I18nService} from "core-app/modules/common/i18n/i18n.service";
import {FilterOperator} from "core-components/api/api-v3/api-v3-filter-builder";
import {VersionResource} from "core-app/modules/hal/resources/version-resource";
import {VersionDmService} from "core-app/modules/hal/dm-services/version-dm.service";
@Injectable()
export class BoardVersionActionService implements BoardActionService {
constructor(protected pathHelper:PathHelperService,
protected boardListService:BoardListsService,
protected I18n:I18nService,
protected versionDm:VersionDmService) {
}
public get localizedName() {
return this.I18n.t('js.work_packages.properties.version');
}
/**
* Returns the current filter value if any
* @param query
* @returns /api/v3/versions/:id if a version filter exists
*/
public getFilterValue(query:QueryResource):string|undefined {
const filter = _.find(query.filters, filter => filter.id === 'version');
if (filter) {
const value = filter.values[0] as string|HalResource;
return (value instanceof HalResource) ? value.href! : value;
}
return;
}
public addActionQueries(board:Board):Promise<Board> {
return this.getVersions()
.then((results) =>
Promise.all<unknown>(
results.map((version:VersionResource) => {
if (version.isDefault) {
return this.addActionQuery(board, version);
}
return Promise.resolve(board);
})
)
.then(() => board)
);
}
public addActionQuery(board:Board, value:HalResource):Promise<Board> {
let params:any = {
name: value.name,
};
let filter = { version: {
operator: '=' as FilterOperator,
values: [value.id]
}};
return this.boardListService.addQuery(board, params, [filter]);
}
/**
* Return available versions for new lists, given the list of active
* queries in the board.
*
* @param board The board we're looking at
* @param queries The active set of queries
*/
public getAvailableValues(board:Board, queries:QueryResource[]):Promise<HalResource[]> {
const active = new Set(
queries.map(query => this.getFilterValue(query))
);
return this.getVersions()
.then(results =>
results.filter(version => !active.has(version.href!))
);
}
private getVersions():Promise<VersionResource[]> {
return this.versionDm
.list()
.then(collection => collection.elements);
}
}

@ -45,6 +45,7 @@ import {BoardsMenuComponent} from "core-app/modules/boards/boards-sidebar/boards
import {BoardDmService} from "core-app/modules/boards/board/board-dm.service";
import {NewBoardModalComponent} from "core-app/modules/boards/new-board-modal/new-board-modal.component";
import {BoardStatusActionService} from "core-app/modules/boards/board/board-actions/status-action.service";
import {BoardVersionActionService} from "core-app/modules/boards/board/board-actions/version-action.service";
import {BoardActionsRegistryService} from "core-app/modules/boards/board/board-actions/board-actions-registry.service";
import {AddListModalComponent} from "core-app/modules/boards/board/add-list-modal/add-list-modal.component";
import {BoardHighlightingTabComponent} from "core-app/modules/boards/board/configuration-modal/tabs/highlighting-tab.component";
@ -106,8 +107,10 @@ export function registerBoardsModule(injector:Injector) {
// Register action services
const registry = injector.get(BoardActionsRegistryService);
const statusAction = injector.get(BoardStatusActionService);
const versionAction = injector.get(BoardVersionActionService);
registry.add('status', statusAction);
registry.add('version', versionAction);
};
}
@ -131,6 +134,7 @@ export function registerBoardsModule(injector:Injector) {
BoardConfigurationService,
BoardActionsRegistryService,
BoardStatusActionService,
BoardVersionActionService,
{
provide: APP_INITIALIZER,
useFactory: registerBoardsModule,

@ -72,6 +72,9 @@ export class ApiV3Paths {
// /api/v3/types
public readonly types = new Apiv3TypesPaths(this.apiV3Base);
// /api/v3/versions
public readonly versions = new SimpleResourceCollection(this.apiV3Base, 'versions');
// /api/v3/work_packages
public readonly work_packages = new ApiV3WorkPackagesPaths(this.apiV3Base);

@ -0,0 +1,54 @@
//-- 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 {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';
import {Injectable} from '@angular/core';
import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';
import {VersionResource} from "core-app/modules/hal/resources/version-resource";
import {CollectionResource} from "core-app/modules/hal/resources/collection-resource";
@Injectable()
export class VersionDmService {
constructor(protected halResourceService:HalResourceService,
protected pathHelper:PathHelperService) {
}
public one(id:number):Promise<VersionResource> {
return this.halResourceService
.get<VersionResource>(this.pathHelper.api.v3.versions.id(id).toString())
.toPromise();
}
public list():Promise<CollectionResource<VersionResource>> {
return this.halResourceService
.get<CollectionResource<VersionResource>>(this.pathHelper.api.v3.versions.toString())
.toPromise();
}
}

@ -50,6 +50,7 @@ import {TimeEntryDmService} from './dm-services/time-entry-dm.service';
import {CommonModule} from "@angular/common";
import {NewsDmService} from './dm-services/news-dm.service';
import {StatusDmService} from "core-app/modules/hal/dm-services/status-dm.service";
import {VersionDmService} from "core-app/modules/hal/dm-services/version-dm.service";
@NgModule({
imports: [
@ -76,6 +77,7 @@ import {StatusDmService} from "core-app/modules/hal/dm-services/status-dm.servic
TypeDmService,
UserDmService,
StatusDmService,
VersionDmService,
]
})
export class OpenprojectHalModule { }

@ -0,0 +1,33 @@
//-- 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 'core-app/modules/hal/resources/hal-resource';
export class VersionResource extends HalResource {
}
Loading…
Cancel
Save