1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
/**
* Created by rc2122 on 6/3/2018.
*/
import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
import * as _ from 'lodash';
import { SdcUiServices } from 'onap-ui-angular';
import { ComponentMetadata, IComponentMetadata } from '../../../../models/component-metadata';
import { IUserProperties } from '../../../../models/user';
import { Resource } from '../../../../models/components/resource';
import { ComponentType } from '../../../../utils/constants';
import { CacheService } from '../../../services/cache.service';
import { FileUtilsService } from '../../../services/file-utils.service';
import { OnboardingService } from '../../../services/onboarding.service';
import { TranslateService } from '../../../shared/translator/translate.service';
export interface ImportVSPdata {
componentCsar: Resource;
previousComponent?: Resource;
type: string;
actionType: ImportVSPActionType;
}
export enum ImportVSPActionType {
IMPORT_VSP,
UPDATE_VSP
}
// tslint:disable-next-line:interface-name
export interface IPoint {
x: number;
y: number;
}
@Component({
selector: 'onboarding-modal',
templateUrl: './onboarding-modal.component.html',
styleUrls: ['onboarding-modal.component.less', '../../../../../assets/styles/table-style.less']
})
export class OnboardingModalComponent implements OnInit {
@Input() currentCsarUUID: string;
@Input() currentCsarVersion: string;
@ViewChild('componentsMetadataTable') table: any;
@Output() closeModalEvent: EventEmitter<ImportVSPdata> = new EventEmitter<ImportVSPdata>();
private columns = [
{name: 'Name', prop: 'name', flexGrow: 22},
{name: 'Vendor', prop: 'vendorName', flexGrow: 26},
{name: 'Category', prop: 'categories', flexGrow: 33},
{name: 'Version', prop: 'csarVersion', flexGrow: 10},
{name: 'Type', prop: 'resourceType', flexGrow: 10},
{name: '#', prop: '', flexGrow: 20}
];
private componentsMetadataList: IComponentMetadata[] = [];
private temp: IComponentMetadata[] = [];
private componentFromServer: ComponentMetadata;
private isCsarComponentExists: boolean = false;
private selectedComponent: ComponentMetadata;
private isLoading: boolean;
private user: IUserProperties;
constructor(private onBoardingService: OnboardingService,
private translateService: TranslateService,
private cacheService: CacheService,
private fileUtilsService: FileUtilsService,
private popoverService: SdcUiServices.PopoverService,
private loaderService: SdcUiServices.LoaderService) {
}
public ngOnInit(): void {
this.initOnboardingComponentsList();
this.user = this.cacheService.get('user');
}
initMaxVersionOfItemsInList = (onboardingResponse: IComponentMetadata[]): void => {
// Get only the latest version of each item
this.componentsMetadataList = [];
// group all items according to packageId
const groupByPackageIdItems = _.groupBy(onboardingResponse, 'packageId');
// Loop on all the groups and push to componentsMetadataList the max version for each package
_.each(groupByPackageIdItems, (items: any): void => {
let maxItem: any = items[0];
items.forEach((item) => {
if (parseFloat(maxItem.csarVersion) < parseFloat(item.csarVersion)) {
maxItem = item;
}
});
if (maxItem) {
this.componentsMetadataList.push(maxItem);
}
});
}
onSelectComponent({selected}) {
this.table.rowDetail.collapseAllRows();
if (selected[0] === this.selectedComponent) {
this.selectedComponent = undefined;
this.componentFromServer = undefined;
this.table.rowDetail.toggleExpandRow(null);
return;
}
this.isLoading = true;
this.componentFromServer = undefined;
this.selectedComponent = selected[0];
this.onBoardingService.getComponentFromCsarUuid(this.selectedComponent.csarUUID).subscribe(
(componentFromServer: ComponentMetadata) => {
this.isLoading = false;
if (componentFromServer) {
this.componentFromServer = componentFromServer;
this.populateRowDetails(true);
} else {
this.populateRowDetails(false);
}
}, (error) => {
this.isLoading = false;
this.populateRowDetails(false);
});
}
populateRowDetails(isCsarComponentExists: boolean) {
this.isCsarComponentExists = isCsarComponentExists;
this.table.rowDetail.toggleExpandRow(this.selectedComponent);
}
importOrUpdateCsar = (): void => {
const selectedComponentConverted: Resource = this.onBoardingService.convertMetaDataToComponent(this.selectedComponent);
const componentFromServerConverted = this.componentFromServer ?
this.onBoardingService.convertMetaDataToComponent(this.componentFromServer) : undefined;
const importVSPdata: ImportVSPdata = {
componentCsar: selectedComponentConverted,
previousComponent: componentFromServerConverted,
type: ComponentType.RESOURCE.toLowerCase(),
actionType: this.isCsarComponentExists ? ImportVSPActionType.UPDATE_VSP : ImportVSPActionType.IMPORT_VSP
};
this.closeModalEvent.emit(importVSPdata);
}
downloadCsar = (packageId: string): void => {
this.isLoading = true;
this.onBoardingService.downloadOnboardingCsar(packageId).subscribe(
(file: any): void => {
this.isLoading = false;
if (file.body) {
this.fileUtilsService.downloadFile(new Blob([file.body],
{type: 'application/octet-stream'}), packageId + '.csar');
}
}, (): void => {
this.isLoading = false;
}
);
}
updateFilter(event) {
const val = event.target.value.toLowerCase();
// filter our data
const temp = this.temp.filter((componentMetadata: ComponentMetadata) => {
return !val ||
(componentMetadata.name && componentMetadata.name.toLowerCase().indexOf(val) !== -1) ||
(componentMetadata.vendorName && componentMetadata.vendorName.toLowerCase().indexOf(val) !== -1) ||
(componentMetadata.categories[0] && componentMetadata.categories[0].name.toLowerCase().indexOf(val) !== -1) ||
(componentMetadata.categories[0] && componentMetadata.categories[0].subcategories[0] && componentMetadata.categories[0].subcategories[0].name.toLowerCase().indexOf(val) !== -1) ||
(componentMetadata.csarVersion && componentMetadata.csarVersion.toLowerCase().indexOf(val) !== -1) ||
(componentMetadata.description && componentMetadata.description.toLowerCase().indexOf(val) !== -1);
});
// update the rows
this.componentsMetadataList = temp;
}
checkNotCertified = (): boolean => {
return this.componentFromServer && this.componentFromServer.lifecycleState === 'NOT_CERTIFIED_CHECKOUT' &&
this.componentFromServer.lastUpdaterUserId !== this.user.userId;
}
openPopover = ($event: any, popoverContent): void => {
this.popoverService.createPopOver('', this.translateService.translate(popoverContent), {
x: $event.pageX,
y: $event.pageY
}, 'bottom');
}
private initOnboardingComponentsList = (): void => {
this.loaderService.activate();
this.onBoardingService.getOnboardingComponents().subscribe(
(onboardingResponse: IComponentMetadata[]) => {
this.loaderService.deactivate();
if (this.currentCsarUUID) {
onboardingResponse = _.filter(onboardingResponse, (input): boolean => {
return (input as ComponentMetadata).csarUUID === this.currentCsarUUID;
});
}
this.initMaxVersionOfItemsInList(onboardingResponse);
this.temp = [...this.componentsMetadataList];
}, (error) => {
this.loaderService.deactivate();
}
);
}
}
|