parent
ef99288c7f
commit
27ffd06446
@ -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); |
||||
} |
||||
} |
@ -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(); |
||||
} |
||||
|
||||
|
||||
} |
@ -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…
Reference in new issue