blob: 74ceb3de80648ae6da63aaa182c9bffaa33318a3 [file] [log] [blame]
/********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
import {Pipe, PipeTransform} from "@angular/core";
import {IStatementTableEntry} from "../../../shared/layout/statement-table/model";
import {IStatementEntityWithTasks} from "../../../store/statements/model";
import {arrayJoin} from "../../../util/store";
@Pipe({name: "getDashboardEntries"})
export class GetDashboardEntriesPipe implements PipeTransform {
public transform(value: IStatementEntityWithTasks[], editedByMe?: boolean): IStatementTableEntry[] {
return arrayJoin(value)
.filter((statement) => statement?.info?.id != null)
.filter((statement) => !editedByMe || statement.editedByMe)
.map((statement) => {
const {
mandatoryContributionsCount,
mandatoryDepartmentsCount,
optionalForMyDepartment,
completedForMyDepartment,
tasks,
info
} = statement;
const contributionStatus: string = Number.isFinite(mandatoryDepartmentsCount) ?
`${Number.isFinite(mandatoryContributionsCount) ? mandatoryContributionsCount : 0}/${mandatoryDepartmentsCount}` :
"-";
const contributionStatusForMyDepartment: boolean = completedForMyDepartment ?
true :
(optionalForMyDepartment ? null : false);
const {name, taskDefinitionKey} = {...arrayJoin(tasks)[0]};
return {
...info,
contributionStatus,
contributionStatusForMyDepartment,
currentTaskName: name == null ? taskDefinitionKey : name
};
});
}
}