UNPKG

@c8y/ngx-components

Version:

Angular modules for Cumulocity IoT applications

508 lines (501 loc) 108 kB
import * as i0 from '@angular/core'; import { Component, Pipe, Input, inject, Injectable, EventEmitter, Output, ViewChild, NgModule } from '@angular/core'; import { gettext } from '@c8y/ngx-components/gettext'; import * as i1$2 from '@c8y/ngx-components'; import { C8yTranslatePipe, IconDirective, C8yTranslateDirective, FilterInputComponent, ListGroupComponent, ListItemComponent, ListItemCheckboxComponent, ListItemIconComponent, AppIconComponent, EmptyStateComponent, HumanizeAppNamePipe, GainsightService, PluginsService, AlertService, PackageType, MarkdownToHtmlPipe, ApplicationPluginStatus, BottomDrawerRef, PluginsExportScopes, TitleComponent, BreadcrumbComponent, BreadcrumbItemComponent, ActionBarItemComponent, DataGridComponent, EmptyStateContextDirective, CoreModule, hookRoute, ViewContext } from '@c8y/ngx-components'; import * as i1 from '@c8y/ngx-components/ecosystem/shared'; import { EcosystemService, PRODUCT_EXPERIENCE_ECOSYSTEM, TranslatePackageLabelPipe, defaultPackageTypes, ListFiltersComponent, ArchivedFilterComponent, PackageVersionSelectComponent, PackageChangelogComponent, SharedEcosystemModule } from '@c8y/ngx-components/ecosystem/shared'; import * as i1$3 from '@angular/router'; import { pick, uniq } from 'lodash-es'; import * as i1$1 from 'ngx-bootstrap/modal'; import { BsModalService } from 'ngx-bootstrap/modal'; import { Subject, BehaviorSubject, combineLatest, of, firstValueFrom, map as map$1 } from 'rxjs'; import { map, takeUntil, shareReplay } from 'rxjs/operators'; import * as i2 from '@angular/forms'; import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms'; import { ApplicationType } from '@c8y/client'; import { NgIf, NgFor, NgClass, AsyncPipe } from '@angular/common'; import { TranslateService } from '@ngx-translate/core'; class OnlyLatestFilterComponent { constructor(filterComponent) { this.filterComponent = filterComponent; this.filterLabel = gettext('Only latest versions'); this.onlyLatestFormControl = new FormControl(true); this.filterComponent.formGroup.controls.custom.addControl(this.filterLabel, this.onlyLatestFormControl); filterComponent.customFilters.set(this.filterLabel, (plugin, enabled) => { return !enabled || !!plugin.tags?.includes('latest'); }); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: OnlyLatestFilterComponent, deps: [{ token: i1.ListFiltersComponent }], target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.15", type: OnlyLatestFilterComponent, isStandalone: true, selector: "c8y-only-latest-filter", ngImport: i0, template: "<label class=\"c8y-switch\">\n <input\n type=\"checkbox\"\n checked=\"checked\"\n [formControl]=\"onlyLatestFormControl\"\n />\n <span></span>\n {{ 'Show only latest version of plugins' | translate }}\n</label>\n", dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i2.CheckboxControlValueAccessor, selector: "input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i2.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "pipe", type: C8yTranslatePipe, name: "translate" }] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: OnlyLatestFilterComponent, decorators: [{ type: Component, args: [{ selector: 'c8y-only-latest-filter', imports: [FormsModule, ReactiveFormsModule, C8yTranslatePipe], template: "<label class=\"c8y-switch\">\n <input\n type=\"checkbox\"\n checked=\"checked\"\n [formControl]=\"onlyLatestFormControl\"\n />\n <span></span>\n {{ 'Show only latest version of plugins' | translate }}\n</label>\n" }] }], ctorParameters: () => [{ type: i1.ListFiltersComponent }] }); class AppStatePipe { constructor(ecosystemService) { this.ecosystemService = ecosystemService; } transform(app, arg) { const appState = this.ecosystemService.getAppState(app); return appState[arg]; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: AppStatePipe, deps: [{ token: i1.EcosystemService }], target: i0.ɵɵFactoryTarget.Pipe }); } static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.3.15", ngImport: i0, type: AppStatePipe, isStandalone: true, name: "appState" }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: AppStatePipe, decorators: [{ type: Pipe, args: [{ name: 'appState', pure: true }] }], ctorParameters: () => [{ type: i1.EcosystemService }] }); class AppsToUpdateRemotesSelectComponent { constructor(bsModalRef, wizardModalService, ecosystemService) { this.bsModalRef = bsModalRef; this.wizardModalService = wizardModalService; this.ecosystemService = ecosystemService; this.destroy$ = new Subject(); this.filterTerm$ = new BehaviorSubject(''); this.filteredApps$ = new BehaviorSubject([]); this.appsToUpdateRemotes = []; this.result = new Promise((resolve, reject) => { this._update = resolve; this._cancel = reject; }); } ngOnInit() { this.filteredApps$ = combineLatest([of(this.apps), this.filterTerm$]).pipe(map(([apps, filterTerm]) => filterTerm.trim().length === 0 ? apps : apps.filter((application) => this.ecosystemService.filterContainString(application.name, filterTerm)))); this.textConfig = this.updateType === 'install' ? { header: gettext('Select applications to install the plugin to'), applyButton: gettext('Install') } : { header: gettext('Select applications to uninstall the plugin from'), applyButton: gettext('Uninstall') }; } cancel() { this.bsModalRef.hide(); this._cancel(); } setSelectedApps(selected, app) { selected ? this.appsToUpdateRemotes.push(app) : (this.appsToUpdateRemotes = this.appsToUpdateRemotes.filter(application => app.key !== application.key)); } ngOnDestroy() { this.destroy$.next(); this.destroy$.complete(); } async duplicateApp() { const wizardConfig = { headerText: gettext('Duplicate application'), headerIcon: 'c8y-copy' }; const initialState = { wizardConfig, componentInitialState: { noBackButton: true }, id: 'duplicateApplication' }; const modalOptions = { initialState }; const modalRef = this.wizardModalService.show(modalOptions); modalRef.content.onClose.pipe(takeUntil(this.destroy$)).subscribe(async () => { this.apps = await this.getOwnedHostedApps(); this.ngOnInit(); }); } async apply() { this._update(this.appsToUpdateRemotes); this.bsModalRef.hide(); } async getOwnedHostedApps() { return (await this.ecosystemService.getWebApplications()).filter(app => this.ecosystemService.isOwner(app) && app.type !== ApplicationType.EXTERNAL); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: AppsToUpdateRemotesSelectComponent, deps: [{ token: i1$1.BsModalRef }, { token: i1$2.WizardModalService }, { token: i1.EcosystemService }], target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.15", type: AppsToUpdateRemotesSelectComponent, isStandalone: true, selector: "c8y-apps-to-update-remotes-select", inputs: { apps: "apps", updateType: "updateType", pluginName: "pluginName", appsDisabled: "appsDisabled" }, ngImport: i0, template: "<div class=\"viewport-modal\">\n <div class=\"modal-header dialog-header\">\n <i [c8yIcon]=\"'c8y-modules'\"></i>\n <div class=\"modal-title h4\" id=\"modal-title\" translate>Custom applications</div>\n </div>\n <div class=\"inner-scroll\" id=\"modal-body\">\n <div class=\"p-16 text-center separator-bottom sticky-top bg-component\">\n <p class=\"text-medium\">\n {{ textConfig.header | translate }}\n </p>\n <c8y-filter (onSearch)=\"filterTerm$.next($event)\"></c8y-filter>\n </div>\n <c8y-list-group *ngIf=\"apps.length; else emptyList\">\n <c8y-li\n [ngClass]=\"{ disabled: updateType === 'install' && appsDisabled.has(app.id) }\"\n *ngFor=\"let app of filteredApps$ | async\"\n data-cy=\"apps-to-update-remotes-select--applications-list\"\n >\n <c8y-li-checkbox (onSelect)=\"setSelectedApps($event, app)\" data-cy=\"apps-to-update-remotes-select--app-checkbox\"></c8y-li-checkbox>\n <c8y-li-icon class=\"p-l-0 icon-32\">\n <c8y-app-icon\n class=\"list-group-icon\"\n [app]=\"app\"\n [contextPath]=\"app.contextPath\"\n [name]=\"app.name\"\n ></c8y-app-icon>\n </c8y-li-icon>\n <div class=\"d-flex\">\n <div class=\"p-r-8\">\n <p class=\"text-medium\" [innerText]=\"app | humanizeAppName | async\"></p>\n <p class=\"small text-muted\">{{ app.description }}</p>\n </div>\n <span class=\"label m-l-auto a-s-start\" [ngClass]=\"app | appState: 'class'\">\n {{ app | appState: 'label' | translate }}\n </span>\n </div>\n </c8y-li>\n </c8y-list-group>\n </div>\n <div class=\"modal-footer\">\n <button\n class=\"btn btn-default\"\n title=\"{{ 'Cancel' | translate }}\"\n type=\"button\"\n (click)=\"cancel()\"\n >\n {{ 'Cancel' | translate }}\n </button>\n <button\n class=\"btn btn-primary\"\n title=\"{{ textConfig.applyButton | translate }}\"\n [disabled]=\"appsToUpdateRemotes.length === 0\"\n (click)=\"apply()\"\n >\n {{ textConfig.applyButton | translate }}\n </button>\n </div>\n</div>\n<ng-template #emptyList>\n <c8y-ui-empty-state\n [icon]=\"'c8y-modules'\"\n [title]=\"'No custom applications available.' | translate\"\n *ngIf=\"updateType !== 'install'\"\n [horizontal]=\"true\"\n ></c8y-ui-empty-state>\n <ng-container *ngIf=\"updateType === 'install'\">\n <c8y-ui-empty-state\n [icon]=\"'c8y-modules'\"\n [title]=\"'No custom applications available.' | translate\"\n [subtitle]=\"'Create a custom application by duplicating an existing one.' | translate\"\n [horizontal]=\"true\"\n >\n <button\n class=\"btn btn-sm btn-default m-t-8\"\n title=\"{{ 'Duplicate' | translate }}\"\n (click)=\"duplicateApp()\"\n >\n {{ 'Duplicate' | translate }}\n </button>\n </c8y-ui-empty-state>\n </ng-container>\n</ng-template>\n", dependencies: [{ kind: "directive", type: IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "directive", type: C8yTranslateDirective, selector: "[translate],[ngx-translate]" }, { kind: "component", type: FilterInputComponent, selector: "c8y-filter", inputs: ["icon", "filterTerm"], outputs: ["onSearch"] }, { kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: ListGroupComponent, selector: "c8y-list-group" }, { kind: "directive", type: NgFor, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "component", type: ListItemComponent, selector: "c8y-list-item, c8y-li", inputs: ["active", "highlighted", "emptyActions", "dense", "collapsed", "selectable"], outputs: ["collapsedChange"] }, { kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "component", type: ListItemCheckboxComponent, selector: "c8y-list-item-checkbox, c8y-li-checkbox", inputs: ["selected", "indeterminate", "disabled", "displayAsSwitch"], outputs: ["onSelect"] }, { kind: "component", type: ListItemIconComponent, selector: "c8y-list-item-icon, c8y-li-icon", inputs: ["icon", "status"] }, { kind: "component", type: AppIconComponent, selector: "c8y-app-icon", inputs: ["contextPath", "name", "app"] }, { kind: "component", type: EmptyStateComponent, selector: "c8y-ui-empty-state", inputs: ["icon", "title", "subtitle", "horizontal"] }, { kind: "pipe", type: C8yTranslatePipe, name: "translate" }, { kind: "pipe", type: AsyncPipe, name: "async" }, { kind: "pipe", type: HumanizeAppNamePipe, name: "humanizeAppName" }, { kind: "pipe", type: AppStatePipe, name: "appState" }] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: AppsToUpdateRemotesSelectComponent, decorators: [{ type: Component, args: [{ selector: 'c8y-apps-to-update-remotes-select', imports: [ IconDirective, C8yTranslateDirective, FilterInputComponent, NgIf, ListGroupComponent, NgFor, ListItemComponent, NgClass, ListItemCheckboxComponent, ListItemIconComponent, AppIconComponent, EmptyStateComponent, C8yTranslatePipe, AsyncPipe, HumanizeAppNamePipe, AppStatePipe ], template: "<div class=\"viewport-modal\">\n <div class=\"modal-header dialog-header\">\n <i [c8yIcon]=\"'c8y-modules'\"></i>\n <div class=\"modal-title h4\" id=\"modal-title\" translate>Custom applications</div>\n </div>\n <div class=\"inner-scroll\" id=\"modal-body\">\n <div class=\"p-16 text-center separator-bottom sticky-top bg-component\">\n <p class=\"text-medium\">\n {{ textConfig.header | translate }}\n </p>\n <c8y-filter (onSearch)=\"filterTerm$.next($event)\"></c8y-filter>\n </div>\n <c8y-list-group *ngIf=\"apps.length; else emptyList\">\n <c8y-li\n [ngClass]=\"{ disabled: updateType === 'install' && appsDisabled.has(app.id) }\"\n *ngFor=\"let app of filteredApps$ | async\"\n data-cy=\"apps-to-update-remotes-select--applications-list\"\n >\n <c8y-li-checkbox (onSelect)=\"setSelectedApps($event, app)\" data-cy=\"apps-to-update-remotes-select--app-checkbox\"></c8y-li-checkbox>\n <c8y-li-icon class=\"p-l-0 icon-32\">\n <c8y-app-icon\n class=\"list-group-icon\"\n [app]=\"app\"\n [contextPath]=\"app.contextPath\"\n [name]=\"app.name\"\n ></c8y-app-icon>\n </c8y-li-icon>\n <div class=\"d-flex\">\n <div class=\"p-r-8\">\n <p class=\"text-medium\" [innerText]=\"app | humanizeAppName | async\"></p>\n <p class=\"small text-muted\">{{ app.description }}</p>\n </div>\n <span class=\"label m-l-auto a-s-start\" [ngClass]=\"app | appState: 'class'\">\n {{ app | appState: 'label' | translate }}\n </span>\n </div>\n </c8y-li>\n </c8y-list-group>\n </div>\n <div class=\"modal-footer\">\n <button\n class=\"btn btn-default\"\n title=\"{{ 'Cancel' | translate }}\"\n type=\"button\"\n (click)=\"cancel()\"\n >\n {{ 'Cancel' | translate }}\n </button>\n <button\n class=\"btn btn-primary\"\n title=\"{{ textConfig.applyButton | translate }}\"\n [disabled]=\"appsToUpdateRemotes.length === 0\"\n (click)=\"apply()\"\n >\n {{ textConfig.applyButton | translate }}\n </button>\n </div>\n</div>\n<ng-template #emptyList>\n <c8y-ui-empty-state\n [icon]=\"'c8y-modules'\"\n [title]=\"'No custom applications available.' | translate\"\n *ngIf=\"updateType !== 'install'\"\n [horizontal]=\"true\"\n ></c8y-ui-empty-state>\n <ng-container *ngIf=\"updateType === 'install'\">\n <c8y-ui-empty-state\n [icon]=\"'c8y-modules'\"\n [title]=\"'No custom applications available.' | translate\"\n [subtitle]=\"'Create a custom application by duplicating an existing one.' | translate\"\n [horizontal]=\"true\"\n >\n <button\n class=\"btn btn-sm btn-default m-t-8\"\n title=\"{{ 'Duplicate' | translate }}\"\n (click)=\"duplicateApp()\"\n >\n {{ 'Duplicate' | translate }}\n </button>\n </c8y-ui-empty-state>\n </ng-container>\n</ng-template>\n" }] }], ctorParameters: () => [{ type: i1$1.BsModalRef }, { type: i1$2.WizardModalService }, { type: i1.EcosystemService }], propDecorators: { apps: [{ type: Input }], updateType: [{ type: Input }], pluginName: [{ type: Input }], appsDisabled: [{ type: Input }] } }); class PluginListService { constructor() { this.CURRENT_LOCATION = location.href; this.updatingPluginId = { install: '', uninstall: '' }; this.appsDisabled = new Set(); this.gainsightService = inject(GainsightService); this.pluginsService = inject(PluginsService); this.alertService = inject(AlertService); this.ecosystemService = inject(EcosystemService); this.humanizeAppNamePipe = inject(HumanizeAppNamePipe); this.translateService = inject(TranslateService); this.bsModalService = inject(BsModalService); } async updateAppRemotes(plugin, updateType, pluginPackage) { this.updatingPluginId[updateType] = plugin?.id; let initialState; try { const apps = await this.getAppsForUpdate(plugin, updateType); initialState = { apps, updateType, pluginName: plugin.name, appsDisabled: this.appsDisabled }; } catch (e) { this.alertService.addServerFailure(e); this.updatingPluginId[updateType] = ''; return; } let selectedApps; try { selectedApps = await this.selectApps(initialState); if (!selectedApps) { this.updatingPluginId[updateType] = ''; return; } } catch { // unreached } if (updateType === 'install') { const isArchived = await this.ecosystemService.verifyArchived([plugin]); if (!isArchived) { this.updatingPluginId[updateType] = ''; return; } const licensesVerifiedByUser = await this.ecosystemService.verifyLicenses([plugin]); if (!licensesVerifiedByUser) { this.updatingPluginId[updateType] = ''; return; } } for (const app of selectedApps) { try { if (updateType === 'install') { const versionIsCompatible = await this.ecosystemService.verifyPluginVersionsCompatibility([plugin], app); if (!versionIsCompatible) { continue; } } await this.handleRemotesUpdate(app, plugin, updateType, pluginPackage); const humanizedAppName = await firstValueFrom(this.humanizeAppNamePipe.transform(app)); const successText = updateType === 'install' ? this.translateService.instant(gettext('Plugin installed to application "{{ appName }}".'), { appName: humanizedAppName }) : this.translateService.instant(gettext('Plugin uninstalled from application "{{ appName }}".'), { appName: humanizedAppName }); this.alertService.success(successText); this.onUpdateEventHandleGS(plugin, app, updateType); } catch (error) { this.onUpdateEventHandleGS(plugin, app, updateType, error); } } this.updatingPluginId[updateType] = ''; } async getAppsForUpdate(plugin, updateType) { let apps = (await this.ecosystemService.getWebApplications()).filter(app => this.ecosystemService.isOwner(app) && app.type !== ApplicationType.EXTERNAL); if (updateType === 'install') { this.appsDisabled.clear(); for (const app of apps) { if (this.isPluginInstalledInApp(plugin, app)) { this.appsDisabled.add(app.id); } } } if (updateType === 'uninstall') { const installedApps = []; for (const app of apps) { if (this.isPluginInstalledInApp(plugin, app)) { installedApps.push(app); } } apps = installedApps; } return apps; } onUpdateEventHandleGS(plugin, app, updateType, error) { const pluginCustomEventInfo = pick(plugin, [ 'name', 'contextPath', 'module', 'version', 'type', 'id' ]); const gsEventResult = updateType === 'install' ? PRODUCT_EXPERIENCE_ECOSYSTEM.APPLICATIONS.RESULTS.PLUGIN_INSTALLED : PRODUCT_EXPERIENCE_ECOSYSTEM.APPLICATIONS.RESULTS.PLUGIN_REMOVED; const eventData = { component: PRODUCT_EXPERIENCE_ECOSYSTEM.APPLICATIONS.COMPONENTS.PLUGIN_LIST, result: error || gsEventResult, url: this.CURRENT_LOCATION, ...pluginCustomEventInfo, targetApplicationName: app.name, targetApplicationContextPath: app.contextPath, ...(error && { error }) }; this.gainsightService.triggerEvent(PRODUCT_EXPERIENCE_ECOSYSTEM.APPLICATIONS.EVENTS.PACKAGE_PLUGINS, eventData); } isPluginInstalledInApp(plugin, app) { const appRemotes = this.pluginsService.getMFRemotes(app) || {}; for (const [remoteName, modules] of Object.entries(appRemotes)) { const pluginFromThisPackageIsInstalled = this.getPluginContextPathWithoutVersion(remoteName) === plugin.contextPath; const specificPluginModuleIsInstalled = modules.some(module => module === plugin.module); if (pluginFromThisPackageIsInstalled && specificPluginModuleIsInstalled) { return true; } } return false; } getPluginContextPathWithoutVersion(remote) { return remote.split('@')[0]; } async handleRemotesUpdate(application, plugin, updateType, pluginPackage) { try { // When remotes object is not set in the configuration object of an application. // Fallback to setInitialRemotes is triggered. const { remotes, excludedRemotes } = await (updateType === 'install' ? this.pluginsService.addRemotes(application, plugin) : this.pluginsService.removeRemotes(application, this.getAllPluginsToRemove(plugin, pluginPackage))); if (!application.config) { application.config = {}; } application.config.remotes = remotes; application.config.excludedRemotes = excludedRemotes; const actualRemotes = this.pluginsService.getMFRemotes(application); return actualRemotes; } catch (er) { if (er) { this.alertService.addServerFailure(er); } throw er; } } getAllPluginsToRemove(plugin, pluginPackage) { return pluginPackage.applicationVersions.map(av => ({ id: `${plugin.contextPath}@${av.version}/${plugin.module}`, idLatest: `${plugin.contextPath}/${plugin.module}`, module: plugin.module, path: plugin.path })); } async selectApps(initialState) { try { return await this.bsModalService.show(AppsToUpdateRemotesSelectComponent, { class: 'modal-sm', ariaDescribedby: 'modal-body', ariaLabelledBy: 'modal-title', initialState, ignoreBackdropClick: true, keyboard: false }).content.result; } catch (er) { return; } } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: PluginListService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: PluginListService, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: PluginListService, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }] }); class PluginListItemComponent { constructor(pluginService) { this.pluginService = pluginService; this.hideSource = false; this.isItemSelected = new EventEmitter(); this.packageType = PackageType.UNKNOWN; this.PACKAGE_TYPE = PackageType; } ngOnInit() { this.packageType = this.pluginService.getPackageType(this.plugin.originApp); } onChange(event) { this.plugin.selected = !this.plugin.selected; this.isItemSelected.next(event); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: PluginListItemComponent, deps: [{ token: i1$2.PluginsService }], target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.15", type: PluginListItemComponent, isStandalone: true, selector: "c8y-plugin-list-item", inputs: { plugin: "plugin", selectable: "selectable", hideSource: "hideSource" }, outputs: { isItemSelected: "isItemSelected" }, ngImport: i0, template: "<c8y-li-checkbox\n class=\"p-r-16 p-l-0\"\n (change)=\"onChange($event.target.checked)\"\n *ngIf=\"selectable\"\n [disabled]=\"plugin.installed\"\n [selected]=\"plugin.selected\"\n></c8y-li-checkbox>\n<c8y-li-icon class=\"p-l-0 text-center\">\n <i class=\"c8y-plugin-icon\">\n <span>{{ plugin.name?.substr(0, 2) }}</span>\n </i>\n</c8y-li-icon>\n<div class=\"p-relative flex-grow\">\n <div [ngClass]=\"{ 'p-r-8': selectable }\">\n <p>\n <span class=\"text-medium\">{{ plugin.name }}</span>\n <em class=\"text-muted small m-l-8\">{{ plugin.version }}</em>\n <span *ngIf=\"plugin.installed\">\n <i\n class=\"text-success\"\n [c8yIcon]=\"'check-circle'\"\n ></i>\n <em\n class=\"text-muted small\"\n translate\n >\n Installed`plugins`\n </em>\n </span>\n </p>\n <p class=\"small l-h-tight\">{{ plugin.description }}</p>\n </div>\n\n <span\n class=\"tag tag--info a-s-start m-t-8\"\n *ngIf=\"selectable && !hideSource\"\n >\n {{ plugin.contextPath }}\n </span>\n\n <span\n class=\"tag a-s-start m-t-8 m-l-4\"\n [ngClass]=\"{\n 'tag--default': packageType === PACKAGE_TYPE.COMMUNITY,\n 'tag--primary': packageType === PACKAGE_TYPE.OFFICIAL\n }\"\n >\n {{ plugin.originApp?.label || plugin.originApp?.manifest?.label | translatePackageLabel }}\n </span>\n</div>\n", dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: ListItemCheckboxComponent, selector: "c8y-list-item-checkbox, c8y-li-checkbox", inputs: ["selected", "indeterminate", "disabled", "displayAsSwitch"], outputs: ["onSelect"] }, { kind: "component", type: ListItemIconComponent, selector: "c8y-list-item-icon, c8y-li-icon", inputs: ["icon", "status"] }, { kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "directive", type: C8yTranslateDirective, selector: "[translate],[ngx-translate]" }, { kind: "pipe", type: TranslatePackageLabelPipe, name: "translatePackageLabel" }] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: PluginListItemComponent, decorators: [{ type: Component, args: [{ selector: 'c8y-plugin-list-item', imports: [ NgIf, ListItemCheckboxComponent, ListItemIconComponent, NgClass, IconDirective, C8yTranslateDirective, TranslatePackageLabelPipe ], template: "<c8y-li-checkbox\n class=\"p-r-16 p-l-0\"\n (change)=\"onChange($event.target.checked)\"\n *ngIf=\"selectable\"\n [disabled]=\"plugin.installed\"\n [selected]=\"plugin.selected\"\n></c8y-li-checkbox>\n<c8y-li-icon class=\"p-l-0 text-center\">\n <i class=\"c8y-plugin-icon\">\n <span>{{ plugin.name?.substr(0, 2) }}</span>\n </i>\n</c8y-li-icon>\n<div class=\"p-relative flex-grow\">\n <div [ngClass]=\"{ 'p-r-8': selectable }\">\n <p>\n <span class=\"text-medium\">{{ plugin.name }}</span>\n <em class=\"text-muted small m-l-8\">{{ plugin.version }}</em>\n <span *ngIf=\"plugin.installed\">\n <i\n class=\"text-success\"\n [c8yIcon]=\"'check-circle'\"\n ></i>\n <em\n class=\"text-muted small\"\n translate\n >\n Installed`plugins`\n </em>\n </span>\n </p>\n <p class=\"small l-h-tight\">{{ plugin.description }}</p>\n </div>\n\n <span\n class=\"tag tag--info a-s-start m-t-8\"\n *ngIf=\"selectable && !hideSource\"\n >\n {{ plugin.contextPath }}\n </span>\n\n <span\n class=\"tag a-s-start m-t-8 m-l-4\"\n [ngClass]=\"{\n 'tag--default': packageType === PACKAGE_TYPE.COMMUNITY,\n 'tag--primary': packageType === PACKAGE_TYPE.OFFICIAL\n }\"\n >\n {{ plugin.originApp?.label || plugin.originApp?.manifest?.label | translatePackageLabel }}\n </span>\n</div>\n" }] }], ctorParameters: () => [{ type: i1$2.PluginsService }], propDecorators: { plugin: [{ type: Input }], selectable: [{ type: Input }], hideSource: [{ type: Input }], isItemSelected: [{ type: Output }] } }); class PluginListComponent { constructor(pluginListService) { this.pluginListService = pluginListService; this.CURRENT_LOCATION = location.href; this.emptyListText = ''; this.hideSource = false; /** * Shows the install button for each plugin separately. Currently used in package-details view. */ this.installable = false; this.selectedItems = new EventEmitter(); this.showOverview = new EventEmitter(); this.selectedPlugins = {}; this.updatingPluginId = this.pluginListService.updatingPluginId; } updateSelectedItems(selected, plugin) { this.selectedPlugins[plugin.id] = selected ? plugin : undefined; const onlyInstalledPlugins = Object.values(this.selectedPlugins).filter(Boolean); this.selectedItems.emit(onlyInstalledPlugins); } showPluginOverview(plugin) { if (plugin?.id === this.selectedPlugin?.id) { return; } this.showOverview.emit(plugin); } async installPlugin(plugin) { await this.pluginListService.updateAppRemotes(plugin, 'install', this.package); } async uninstallPlugin(plugin) { await this.pluginListService.updateAppRemotes(plugin, 'uninstall', this.package); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: PluginListComponent, deps: [{ token: PluginListService }], target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.15", type: PluginListComponent, isStandalone: true, selector: "c8y-plugin-list", inputs: { plugins$: "plugins$", emptyListText: "emptyListText", selectable: "selectable", hideSource: "hideSource", installable: "installable", package: "package", selectedPlugin: "selectedPlugin" }, outputs: { selectedItems: "selectedItems", showOverview: "showOverview" }, ngImport: i0, template: "<c8y-list-group class=\"bg-inherit\">\n <ng-container *ngIf=\"(plugins$ | async)?.length !== 0; else emptyList\">\n <ng-container *ngFor=\"let plugin of plugins$ | async\">\n <c8y-li\n [ngClass]=\"{\n disabled: plugin.installed,\n selected: selectedPlugin?.id === plugin?.id\n }\"\n >\n <div class=\"d-flex fit-w\">\n <ng-container *ngIf=\"plugin.readmePath\">\n <button\n class=\"c8y-list__item__btn d-flex fit-w gap-4\"\n title=\"{{ 'Details' | translate }}\"\n (click)=\"showPluginOverview(plugin)\"\n >\n <c8y-plugin-list-item\n class=\"d-contents\"\n (isItemSelected)=\"updateSelectedItems($event, plugin)\"\n [plugin]=\"plugin\"\n [selectable]=\"selectable\"\n [hideSource]=\"hideSource\"\n ></c8y-plugin-list-item>\n <i\n class=\"icon-24 m-l-auto a-s-center\"\n c8yIcon=\"forward\"\n ></i>\n </button>\n </ng-container>\n <ng-container *ngIf=\"!plugin.readmePath\">\n <c8y-plugin-list-item\n class=\"d-contents\"\n (isItemSelected)=\"updateSelectedItems($event, plugin)\"\n [plugin]=\"plugin\"\n [selectable]=\"selectable\"\n [hideSource]=\"hideSource\"\n ></c8y-plugin-list-item>\n </ng-container>\n </div>\n <div class=\"p-l-40 m-t-4 d-flex flex-wrap gap-8\">\n <button\n class=\"btn btn-danger btn-sm\"\n title=\"{{ 'Uninstall plugin' | translate }}\"\n *ngIf=\"installable\"\n (click)=\"uninstallPlugin(plugin)\"\n [ngClass]=\"{ 'btn-pending': plugin.id === updatingPluginId.uninstall }\"\n [disabled]=\"updatingPluginId.uninstall && plugin.id === updatingPluginId.uninstall\"\n data-cy=\"plugin-list--uninstall-plugin-button\"\n translate\n >\n Uninstall plugin\n </button>\n <button\n class=\"btn btn-default btn-sm m-0\"\n title=\"{{ 'Install plugin' | translate }}\"\n *ngIf=\"installable\"\n (click)=\"installPlugin(plugin)\"\n [ngClass]=\"{ 'btn-pending': plugin.id === updatingPluginId.install }\"\n [disabled]=\"updatingPluginId.install && plugin.id === updatingPluginId.install\"\n data-cy=\"plugin-list--install-plugin-button\"\n translate\n >\n Install plugin\n </button>\n </div>\n </c8y-li>\n </ng-container>\n </ng-container>\n</c8y-list-group>\n<ng-template #emptyList>\n <c8y-ui-empty-state\n [icon]=\"'plugin'\"\n [title]=\"emptyListText | translate\"\n [horizontal]=\"true\"\n *ngIf=\"emptyListText\"\n ></c8y-ui-empty-state>\n</ng-template>\n", dependencies: [{ kind: "component", type: ListGroupComponent, selector: "c8y-list-group" }, { kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: NgFor, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "component", type: ListItemComponent, selector: "c8y-list-item, c8y-li", inputs: ["active", "highlighted", "emptyActions", "dense", "collapsed", "selectable"], outputs: ["collapsedChange"] }, { kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "component", type: PluginListItemComponent, selector: "c8y-plugin-list-item", inputs: ["plugin", "selectable", "hideSource"], outputs: ["isItemSelected"] }, { kind: "directive", type: IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "directive", type: C8yTranslateDirective, selector: "[translate],[ngx-translate]" }, { kind: "component", type: EmptyStateComponent, selector: "c8y-ui-empty-state", inputs: ["icon", "title", "subtitle", "horizontal"] }, { kind: "pipe", type: C8yTranslatePipe, name: "translate" }, { kind: "pipe", type: AsyncPipe, name: "async" }] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: PluginListComponent, decorators: [{ type: Component, args: [{ selector: 'c8y-plugin-list', imports: [ ListGroupComponent, NgIf, NgFor, ListItemComponent, NgClass, PluginListItemComponent, IconDirective, C8yTranslateDirective, EmptyStateComponent, C8yTranslatePipe, AsyncPipe ], template: "<c8y-list-group class=\"bg-inherit\">\n <ng-container *ngIf=\"(plugins$ | async)?.length !== 0; else emptyList\">\n <ng-container *ngFor=\"let plugin of plugins$ | async\">\n <c8y-li\n [ngClass]=\"{\n disabled: plugin.installed,\n selected: selectedPlugin?.id === plugin?.id\n }\"\n >\n <div class=\"d-flex fit-w\">\n <ng-container *ngIf=\"plugin.readmePath\">\n <button\n class=\"c8y-list__item__btn d-flex fit-w gap-4\"\n title=\"{{ 'Details' | translate }}\"\n (click)=\"showPluginOverview(plugin)\"\n >\n <c8y-plugin-list-item\n class=\"d-contents\"\n (isItemSelected)=\"updateSelectedItems($event, plugin)\"\n [plugin]=\"plugin\"\n [selectable]=\"selectable\"\n [hideSource]=\"hideSource\"\n ></c8y-plugin-list-item>\n <i\n class=\"icon-24 m-l-auto a-s-center\"\n c8yIcon=\"forward\"\n ></i>\n </button>\n </ng-container>\n <ng-container *ngIf=\"!plugin.readmePath\">\n <c8y-plugin-list-item\n class=\"d-contents\"\n (isItemSelected)=\"updateSelectedItems($event, plugin)\"\n [plugin]=\"plugin\"\n [selectable]=\"selectable\"\n [hideSource]=\"hideSource\"\n ></c8y-plugin-list-item>\n </ng-container>\n </div>\n <div class=\"p-l-40 m-t-4 d-flex flex-wrap gap-8\">\n <button\n class=\"btn btn-danger btn-sm\"\n title=\"{{ 'Uninstall plugin' | translate }}\"\n *ngIf=\"installable\"\n (click)=\"uninstallPlugin(plugin)\"\n [ngClass]=\"{ 'btn-pending': plugin.id === updatingPluginId.uninstall }\"\n [disabled]=\"updatingPluginId.uninstall && plugin.id === updatingPluginId.uninstall\"\n data-cy=\"plugin-list--uninstall-plugin-button\"\n translate\n >\n Uninstall plugin\n </button>\n <button\n class=\"btn btn-default btn-sm m-0\"\n title=\"{{ 'Install plugin' | translate }}\"\n *ngIf=\"installable\"\n (click)=\"installPlugin(plugin)\"\n [ngClass]=\"{ 'btn-pending': plugin.id === updatingPluginId.install }\"\n [disabled]=\"updatingPluginId.install && plugin.id === updatingPluginId.install\"\n data-cy=\"plugin-list--install-plugin-button\"\n translate\n >\n Install plugin\n </button>\n </div>\n </c8y-li>\n </ng-container>\n </ng-container>\n</c8y-list-group>\n<ng-template #emptyList>\n <c8y-ui-empty-state\n [icon]=\"'plugin'\"\n [title]=\"emptyListText | translate\"\n [horizontal]=\"true\"\n *ngIf=\"emptyListText\"\n ></c8y-ui-empty-state>\n</ng-template>\n" }] }], ctorParameters: () => [{ type: PluginListService }], propDecorators: { plugins$: [{ type: Input }], emptyListText: [{ type: Input }], selectable: [{ type: Input }], hideSource: [{ type: Input }], installable: [{ type: Input }], package: [{ type: Input }], selectedPlugin: [{ type: Input }], selectedItems: [{ type: Output }], showOverview: [{ type: Output }] } }); class InstallPluginComponent { constructor(bottomDrawerRef, ecosystemService, pluginsService) { this.bottomDrawerRef = bottomDrawerRef; this.ecosystemService = ecosystemService; this.pluginsService = pluginsService; this.filteredPlugins$ = new BehaviorSubject([]); this.selectedPlugins = []; this.packageTypes = defaultPackageTypes; this.result = new Promise((resolve, reject) => { this._install = resolve; this._cancel = reject; }); this.onlyLatestPluginVersion = true; } setFilterPipe(filterPipe) { this.filteredPlugins$ = this.plugins$.pipe(map$1(plugins => plugins.map(plugin => { plugin.filterProps = this.ecosystemService.getAppFilterProps(plugin.originApp); return plugin; })), src => filterPipe(src)); } cancel() { this.bottomDrawerRef.close(); this._cancel(); } install() { this._install(this.selectedPlugins); this.bottomDrawerRef.close(); } async showPluginOverview(plugin) { this.selectedPlugin = plugin; const baseUrl = `/apps/${plugin.id}/`; this.pluginBaseUrl = baseUrl; this.pluginMarkdown = await this.pluginsService.getReadmeFileContent(baseUrl); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: InstallPluginComponent, deps: [{ token: i1$2.BottomDrawerRef }, { token: i1.EcosystemService }, { token: i1$2.PluginsService }], target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.15", type: InstallPluginComponent, isStandalone: true, selector: "c8y-install-plugin", inputs: { plugins$: "plugins$" }, host: { classAttribute: "d-contents" }, ngImport: i0, template: " <div class=\"card-header gap-8 d-col p-l-24 p-r-24 separator-bottom flex-no-shrink\">\n <div\n class=\"card-title h4 text-center\"\n translate\n >\n Available plugins\n </div>\n <c8y-list-filters\n (filterPipeChange)=\"setFilterPipe($event)\"\n [packageTypes]=\"packageTypes\"\n >\n <c8y-archived-filter></c8y-archived-filter>\n <c8y-only-latest-filter></c8y-only-latest-filter>\n </c8y-list-filters>\n </div>\n <div class=\"d-grid grid__col--5-7--md min-height-0 flex-grow\">\n <c8y-plugin-list\n class=\"inner-scroll bg-level-1\"\n (selectedItems)=\"selectedPlugins = $event\"\n [emptyListText]=\"'No matching plugins' | translate\"\n [plugins$]=\"filteredPlugins$\"\n [selectable]=\"true\"\n [selectedPlugin]=\"selectedPlugin\"\n (showOverview)=\"showPluginOverview($event)\"\n ></c8y-plugin-list>\n <div class=\"inner-scroll bg-component\">\n <div class=\"card-header separator sticky-top bg-inherit\"\n *ngIf=\"pluginMarkdown\">\n <button\n class=\"m-l-auto btn-clean\"\n title=\"{{ 'Close' | translate }}\"\n type=\"button\"\n (click)=\"selectedPlugin = null; pluginMarkdown = null\"\n >\n <i c8yIcon=\"times\"></i>\n </button>\n </div>\n <div class=\"card-block p-l-24 p-r-24\">\n <div\n class=\"markdown-content\"\n *ngIf=\"pluginMarkdown\"\n [innerHTML]=\"pluginMarkdown | markdownToHtml: { baseUrl: pluginBaseUrl } | async\"\n ></div>\n <c8y-ui-empty-state\n [icon]=\"'user-manual'\"\n [title]=\"'No plugin selected' | translate\"\n [subtitle]=\"\n 'Select a plugin from the list to view its documentation.' | translate\"\n *ngIf=\"!pluginMarkdown\"\n [horizontal]=\"true\"\n >\n <p>\n <small >\n {{ 'Documentation availability varies by plugin.' | translate }}\n </small>\n </p>\n </c8y-ui-empty-state>\n </div>\n </div>\n </div>\n <div class=\"text-center card-footer p-24 separator\">\n <button\n class=\"btn btn-default\"\n title=\"{{ 'Cancel' | translate }}\"\n type=\"button\"\n (click)=\"cancel()\"\n data-cy=\"install-plugin--cancel-button\"\n >\n {{ 'Cancel' | translate }}\n </button>\n <button\n class=\"btn btn-primary\"\n title=\"{{ 'Install' | translate }}\"\n type=\"button\"\n (click)=\"install()\"\n [disabled]=\"selectedPlugins.length === 0\"\n data-cy=\"install-plugin--install-button\"\n >\n {{ 'Install' | translate }}\n <span\n class=\"badge\"\n *ngIf=\"selectedPlugins.length as length\"\n >\n {{ length }}\n </span>\n </button>\n </div>\n\n", dependencies: [{ kind: "directive", type: C8yTranslateDirective, selector: "[translate],[ngx-translate]" }, { kind: "component", type: ListFiltersComponent, selector: "c8y-list-filters", inputs: ["packageTypes", "packageAvailabilities", "packageContents"], outputs: ["filterPipeChange"] }, { kind: "component", type: ArchivedFilterComponent, selector: "c8y-archived-filter" }, { kind: "component", type: OnlyLatestFilterComponent, selector: "c8y-only-latest-filter" }, { kind: "component", type: PluginListComponent, selector: "c8y-plugin-list", inputs: ["plugins$", "emptyListText", "selectable", "hideSource", "installable", "package", "selectedPlugin"], outputs: ["selectedItems", "showOverview"] }, { kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "component", type: EmptyStateComponent, selector: "c8y-ui-empty-state", inputs: ["icon", "title", "subtitle", "horizontal"] }, { kind: "pipe", type: C8yTranslatePipe, name: "translate" }, { kind: "pipe", type: AsyncPipe, name: "async" }, { kind: "pipe", type: MarkdownToHtmlPipe, name: "markdownToHtml" }] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: InstallPluginComponent, decorators: [{ type: Component, args: [{ selector: 'c8y-install-plugin', host: { class: 'd-contents' }, imports: [ C8yTranslateDirective, ListFiltersComponent, ArchivedFilterComponent, OnlyLatestFilterComponent, PluginListComponent, NgIf, IconDirective, EmptyStateComponent, C8yTranslatePipe, AsyncPipe, MarkdownToHtmlPipe ], template: " <div class=\"card-header gap-8 d-col p-l-24 p-r-24 separator-bottom flex-no-shrink\">\n <div\n class=\"card-title h4 text-center\"\n translate\n >\n Available plugins\n </div>\n <c8y-list-filters\n (filterPipeChange)=\"setFilterPipe($event)\"\n [packageTypes]=\"packageTypes\"\n >\n <c8y-archived-filter></c8y-archived-filter>\n <c8y-only-latest-filter></c8y-only-latest-filter>\n </c8y-list-filters>\n </div>\n <div class=\"d-grid grid__col--5-7--md min-height-0 flex-grow\">\n <c8y-plugin-list\n class=\"inner-scroll bg-level-1\"\n (selectedItems)=\"selectedPlugins = $event\"\n [emptyListText]=\"'No matching plugins' | translate\"\n [plugins$]=\"filteredPlugins$\"\n [selectable]=\"true\"\n [selectedPlugin]=\"selectedPlugin\"\n (showOverview)=\"showPluginOverview($event)\"\n ></c8y-plugin-list>\n <div class=\"inner-scroll bg-component\">\n <div class=\"card-header separator sticky-top bg-inherit\"\n *ngIf=\"pluginMarkdown\">\n <button\n class=\"m-l-auto btn-clean\"\n title=\"{{ 'Close' | translate }}\"\n type=\"button\"\n (click)=\"selectedPlugin = null; pluginMarkdown = null\"\n >\n <i c8yIcon=\"times\"></i>\n </button>\n </div>\n <div class=\"card-block p-l-24 p-r-24\">\n <div\n class=\"markdown-content\"\n *ngIf=\"pluginMarkdown\"\n [innerHTML]=\"pluginMarkdown | markdownToHtml: { baseUrl: pluginBaseUrl } | async\"\n