2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 import { Component, EventEmitter, Input, Output } from "@angular/core";
21 import { ArtifactModel } from "app/models";
22 import { TranslateService } from '../../../shared/translator/translate.service';
23 import { SdcUiServices } from 'onap-ui-angular';
26 selector: 'upload-artifact',
31 [clickable]="!disabled"
33 [testId]="testId" mode="info"
34 (click)="fileUpload.click()"
40 style="display: none;"
42 (change)="onFileSelect($event)"
43 [accept]="extensionsWithDot"
47 export class UploadArtifactComponent {
49 @Input() extensions: string;
50 @Input() artifact: ArtifactModel;
51 @Input() isInstance: boolean;
52 @Input() uploadIconClass: string;
53 @Input() componentType: string;
54 @Input() componentId: string;
55 @Input() testId: string;
56 @Input() disabled: boolean;
57 @Output("onFileUpload") onFileUpload: EventEmitter<any> = new EventEmitter<any>();
59 public extensionsWithDot: string;
60 public iconType:string = "upload-o";
63 private modalService: SdcUiServices.ModalService,
64 private translateService: TranslateService) {
69 this.extensionsWithDot = this.getExtensionsWithDot(this.extensions);
72 public getExtensionsWithDot(extensions:string):string {
73 extensions = extensions || '';
74 return extensions.split(',')
75 .map(ext => '.' + ext.toString())
79 public onFileSelect(event) {
80 const file = event.target.files[0];
81 if (file && file.name) {
82 const fileExtension: string = file.name.split('.').pop();
83 if (this.extensionsWithDot.includes(fileExtension.toLowerCase())) {
84 this.onFileUpload.emit(file);
86 const title: string = this.translateService.translate('NEW_SERVICE_RESOURCE_ERROR_VALID_TOSCA_EXTENSIONS_TITLE');
87 const message: string = this.translateService.translate('NEW_SERVICE_RESOURCE_ERROR_VALID_TOSCA_EXTENSIONS', {extensions: this.extensionsWithDot});
88 this.modalService.openWarningModal(title, message, 'error-invalid-tosca-ext');