blob: ed5bef22073f99bc3d9bb2184bc10251c50a5bae [file] [log] [blame]
/********************************************************************************
* Copyright (c) 2015-2018 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 v. 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 { TranslateService } from '@ngx-translate/core';
import { Observable, of } from 'rxjs';
import { Attribute, MDMLink, ContextGroup } from '../navigator/node';
@Pipe({name: 'attributeValue'})
export class AttributeValuePipe implements PipeTransform {
constructor(private translateService: TranslateService) {}
transform(attr: Attribute, contextGroup?: ContextGroup) {
let display = new Observable<string>();
if (attr != undefined && attr.value != undefined) {
const value = contextGroup != undefined ? attr.value[contextGroup] : attr.value;
if (value != undefined) {
switch (attr.dataType) {
case 'FILE_LINK':
const link: MDMLink = Object.assign(new MDMLink(), value);
display = of(link.getFileName());
break;
case 'FILE_LINK_SEQUENCE':
const links = value as MDMLink[];
if (links != undefined) {
switch (links.length) {
case 0:
display = this.translateService.get('navigator.attribute-value.msg-no-files-attached');
break;
case 1:
display = this.translateService.get('navigator.attribute-value.msg-one-file-attached');
break;
default:
display = this.translateService.get('navigator.attribute-value.msg-x-files-attached', {numberOfFiles: links.length});
}
}
break;
default:
display = of(value);
}
}
}
return display;
}
}