UNPKG

@c8y/ngx-components

Version:

Angular modules for Cumulocity IoT applications

563 lines (554 loc) 45.1 kB
import * as i0 from '@angular/core'; import { Injectable, Component, NgModule } from '@angular/core'; import * as i1$1 from '@angular/forms'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import * as i2 from '@c8y/ngx-components'; import { TitleComponent, BreadcrumbComponent, BreadcrumbItemComponent, C8yTranslateDirective, RequiredInputPlaceholderDirective, LoadingComponent, EmptyStateComponent, AppIconComponent, C8yTranslatePipe, HumanizeAppNamePipe, NavigatorNode, CoreModule, hookNavigator, hookRoute } from '@c8y/ngx-components'; import { gettext } from '@c8y/ngx-components/gettext'; import { sortBy, isUndefined } from 'lodash-es'; import { debounceTime, take } from 'rxjs/operators'; import * as i1 from '@c8y/client'; import { ApplicationType } from '@c8y/client'; import { NgIf, NgFor, NgClass, AsyncPipe } from '@angular/common'; /** The context for evaluating default subscriptions configuration */ var DefaultSubscriptionsContext; (function (DefaultSubscriptionsContext) { /** Current tenant context (only current tenant options are taken into account). */ DefaultSubscriptionsContext[DefaultSubscriptionsContext["CURRENT_TENANT"] = 0] = "CURRENT_TENANT"; /** Parent tenant context (only parent tenant options are taken into account). */ DefaultSubscriptionsContext[DefaultSubscriptionsContext["PARENT_TENANT"] = 1] = "PARENT_TENANT"; })(DefaultSubscriptionsContext || (DefaultSubscriptionsContext = {})); class DefaultSubscriptionsService { constructor(applicationService, tenantService, tenantOptionsService, humanizeAppNamePipe) { this.applicationService = applicationService; this.tenantService = tenantService; this.tenantOptionsService = tenantOptionsService; this.humanizeAppNamePipe = humanizeAppNamePipe; } /** * Gets the list of applications which can be used in default subscriptions, i.e.: * - current tenant's all own applications, * - inherited applications, which do not have the same names as current tenant's own apps. * The list is sorted alphabetically by humanized app name and contains up to 2000 items. * @returns The list of applications, which can be used in default subscriptions. */ async getSubscribableTenantApps() { const currentTenant = (await this.tenantService.current()).data; const allApps = (await this.applicationService.listByTenant(null, { pageSize: 2000 })).data; const ownApps = allApps.filter(app => app.owner.tenant.id === currentTenant.name); const inheritedApps = allApps.filter(app => app.owner.tenant.id !== currentTenant.name); const filteredApps = [...ownApps]; inheritedApps.forEach(inheritedApp => { if (!filteredApps.some(filteredApp => filteredApp.name === inheritedApp.name)) { filteredApps.push(inheritedApp); } }); const filteredAppsWithHumanizedNames = await Promise.all(filteredApps.map(async (app) => { const humanizedName = await this.humanizeAppNamePipe .transform(app.name) .pipe(debounceTime(250), take(1)) .toPromise(); return { app, humanizedName }; })); const sortedAppsWithHumanizedNames = sortBy(filteredAppsWithHumanizedNames, ['humanizedName']); const sortedApps = sortedAppsWithHumanizedNames.map(({ app }) => app); return sortedApps; } /** * Gets the default subscriptions configuration inherited from parent tenant. * @returns The default subscriptions object with settings from parent tenant. */ async getDefaultSubscriptionsEvaluatedFromParentTenant() { return this.getDefaultSubscriptions(DefaultSubscriptionsContext.PARENT_TENANT); } /** * Gets the default subscriptions configuration from the current tenant. * @returns The default subscriptions object with settings from the current tenant. */ async getDefaultSubscriptionsFromCurrentTenant() { return this.getDefaultSubscriptions(DefaultSubscriptionsContext.CURRENT_TENANT); } /** * Saves given default subscriptions configuration to the current tenant * (either sets, updates, or deletes corresponding tenant options). * @param defaultSubscriptions The default subscriptions configuration to be saved. */ async saveDefaultSubscriptionsToCurrentTenant(defaultSubscriptions) { await this.saveOnCreationSubscriptions(defaultSubscriptions); await this.saveOnUpgradeSubscriptions(defaultSubscriptions); } /** * Gets default subscriptions in the context of current or parent tenant. * @param contextTenant Tells whether to use current or parent tenant as context. */ async getDefaultSubscriptions(contextTenant) { let tenantOptionsParams; let overridable; switch (contextTenant) { case DefaultSubscriptionsContext.CURRENT_TENANT: tenantOptionsParams = { evaluate: 'current' }; overridable = true; break; case DefaultSubscriptionsContext.PARENT_TENANT: tenantOptionsParams = { evaluate: 'inherited' }; overridable = false; break; } const { onCreationApps, onCreationMicroservices, onUpgradeAppsEnabled, onUpgradeApps, onUpgradeMicroservicesEnabled, onUpgradeMicroservices } = await this.getTenantOptions(tenantOptionsParams); const onCreationSubscriptions = this.namesToPartialApps({ appsNamesStr: onCreationApps, microservicesNamesStr: onCreationMicroservices }); const onUpgradeAppsDefault = overridable ? null : onCreationApps; const onUpgradeMicroservicesDefault = overridable ? null : onCreationMicroservices; const onUpgradeSubscriptions = this.namesToPartialApps({ appsNamesStr: onUpgradeAppsEnabled ? onUpgradeApps : onUpgradeAppsDefault, microservicesNamesStr: onUpgradeMicroservicesEnabled ? onUpgradeMicroservices : onUpgradeMicroservicesDefault }); const defaultSubscriptions = { onCreationSubscriptions, onUpgradeSubscriptions }; if (overridable) { defaultSubscriptions.overrideOnCreationSubscriptions = onCreationApps !== null || onCreationMicroservices !== null; defaultSubscriptions.overrideOnUpgradeSubscriptions = onUpgradeAppsEnabled || onUpgradeMicroservicesEnabled; } return defaultSubscriptions; } async getTenantOptions(params = {}) { return { onCreationApps: await this.getTenantOption({ category: 'configuration', key: 'default.tenant.applications' }, null, params), onCreationMicroservices: await this.getTenantOption({ category: 'configuration', key: 'default.tenant.microservices' }, null, params), onUpgradeAppsEnabled: await this.getTenantOption({ category: 'configuration', key: 'on-update.tenant.applications.enabled' }, false, params), onUpgradeApps: await this.getTenantOption({ category: 'configuration', key: 'on-update.tenant.applications' }, null, params), onUpgradeMicroservicesEnabled: await this.getTenantOption({ category: 'configuration', key: 'on-update.tenant.microservices.enabled' }, false, params), onUpgradeMicroservices: await this.getTenantOption({ category: 'configuration', key: 'on-update.tenant.microservices' }, null, params) }; } async saveOnCreationSubscriptions(defaultSubscriptions) { if (defaultSubscriptions.overrideOnCreationSubscriptions) { await this.setTenantOption({ category: 'configuration', key: 'default.tenant.applications', value: this.partialAppsListToAppsNames(defaultSubscriptions.onCreationSubscriptions) }); await this.setTenantOption({ category: 'configuration', key: 'default.tenant.microservices', value: this.partialAppsToMicroservicesNames(defaultSubscriptions.onCreationSubscriptions) }); } else { await this.unsetTenantOption({ category: 'configuration', key: 'default.tenant.applications' }); await this.unsetTenantOption({ category: 'configuration', key: 'default.tenant.microservices' }); } } async saveOnUpgradeSubscriptions(defaultSubscriptions) { if (defaultSubscriptions.overrideOnUpgradeSubscriptions) { await this.setTenantOption({ category: 'configuration', key: 'on-update.tenant.applications.enabled', value: 'true' }); await this.setTenantOption({ category: 'configuration', key: 'on-update.tenant.microservices.enabled', value: 'true' }); await this.setTenantOption({ category: 'configuration', key: 'on-update.tenant.applications', value: this.partialAppsListToAppsNames(defaultSubscriptions.onUpgradeSubscriptions) }); await this.setTenantOption({ category: 'configuration', key: 'on-update.tenant.microservices', value: this.partialAppsToMicroservicesNames(defaultSubscriptions.onUpgradeSubscriptions) }); } else { await this.unsetTenantOption({ category: 'configuration', key: 'on-update.tenant.applications.enabled' }); await this.unsetTenantOption({ category: 'configuration', key: 'on-update.tenant.microservices.enabled' }); await this.unsetTenantOption({ category: 'configuration', key: 'on-update.tenant.applications' }); await this.unsetTenantOption({ category: 'configuration', key: 'on-update.tenant.microservices' }); } } async getTenantOption(option, defaultValue = null, params = {}) { let value; try { value = (await this.tenantOptionsService.detail(option, params)).data.value; value = JSON.parse(value); } catch (ex) { value = !isUndefined(value) ? value : defaultValue; } return value; } async setTenantOption(option) { return this.tenantOptionsService.update(option); } async unsetTenantOption(option) { try { await this.tenantOptionsService.delete(option); } catch (ex) { if (!ex || !ex.res || ex.res.status !== 404) { throw ex; } } } namesToPartialApps({ appsNamesStr, microservicesNamesStr }) { if (appsNamesStr === null && microservicesNamesStr === null) { return null; } return [ ...(appsNamesStr || '') .split(',') .filter(name => name.length) .map(name => ({ name: name.trim() })), ...(microservicesNamesStr || '') .split(',') .filter(name => name.length) .map(name => ({ name: name.trim(), type: ApplicationType.MICROSERVICE })) ]; } partialAppsListToAppsNames(apps) { return apps .filter(app => app.type !== ApplicationType.MICROSERVICE) .map(app => app.name) .join(','); } partialAppsToMicroservicesNames(apps) { return apps .filter(app => app.type === ApplicationType.MICROSERVICE) .map(app => app.name) .join(','); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: DefaultSubscriptionsService, deps: [{ token: i1.ApplicationService }, { token: i1.TenantService }, { token: i1.TenantOptionsService }, { token: i2.HumanizeAppNamePipe }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: DefaultSubscriptionsService }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: DefaultSubscriptionsService, decorators: [{ type: Injectable }], ctorParameters: () => [{ type: i1.ApplicationService }, { type: i1.TenantService }, { type: i1.TenantOptionsService }, { type: i2.HumanizeAppNamePipe }] }); /** * The component shows the main view for managing default subscriptions configuration. */ class DefaultSubscriptionsComponent { constructor(fb, defaultSubscriptionsService, alertService) { this.fb = fb; this.defaultSubscriptionsService = defaultSubscriptionsService; this.alertService = alertService; /** Hint text for disabled checkboxes. */ this.disabledCheckboxHint = gettext('Select "Override inherited" to enable.'); } /** Initializes the loading of the form and the current settings. */ async ngOnInit() { this.loading = true; await this.initForm(); await this.loadDefaultSubscriptions(); this.loading = false; } /** Loads the list of apps, builds the form and hooks value change events for override switches. */ async initForm() { this.form = this.fb.group({ overrideOnCreationSubscriptions: [''], overrideOnUpgradeSubscriptions: [''], appRows: this.fb.array([]) }); const apps = await this.defaultSubscriptionsService.getSubscribableTenantApps(); const appRows = this.form.controls.appRows; apps.forEach(app => { appRows.push(this.fb.group({ app: [app], subscribedOnCreation: [''], subscribedOnUpgrade: [''] })); }); this.form .get('overrideOnCreationSubscriptions') .valueChanges.subscribe(value => this.onOverrideOnCreationSubscriptionsChange(value)); this.form .get('overrideOnUpgradeSubscriptions') .valueChanges.subscribe(value => this.onOverrideOnUpgradeSubscriptionsChange(value)); } /** * Checks if given application row should be displayed. * The row is displayed when any of its checkboxes is selected or any of the lists is being overridden. */ shouldShowAppRow(appRowRawValue) { const { subscribedOnCreation, subscribedOnUpgrade } = appRowRawValue; const { overrideOnCreationSubscriptions, overrideOnUpgradeSubscriptions } = this.form.value; return (subscribedOnCreation || subscribedOnUpgrade || overrideOnCreationSubscriptions || overrideOnUpgradeSubscriptions); } /** Checks if there are no application rows to be displayed. */ isEmptyView() { return !this.form .getRawValue() .appRows.some(appRowRawValue => this.shouldShowAppRow(appRowRawValue)); } /** * Checks if given application is subscribed (present in the given list of applications). * @param app Application object to check. * @param subscribedApps The list of application objects to check against. * @returns True, if the application is present in the list. */ isSubscribed(app, subscribedApps) { return subscribedApps && subscribedApps.some(subscribedApp => subscribedApp.name === app.name); } /** Saves the current value of form object to backend. */ async save() { try { const defaultSubscriptions = this.getDefaultSubscriptionsForSave(); await this.defaultSubscriptionsService.saveDefaultSubscriptionsToCurrentTenant(defaultSubscriptions); this.alertService.success(gettext('Saved.')); } catch (ex) { this.alertService.addServerFailure(ex); } } onOverrideOnCreationSubscriptionsChange(overrideOnCreationSubscriptions) { if (overrideOnCreationSubscriptions) { this.enableSubscribeOnCreationCheckboxes(); return; } this.disableSubscribeOnCreationCheckboxes(); this.restoreSubscribeOnCreationFromParent(); } enableSubscribeOnCreationCheckboxes() { const appRowsControls = this.form.controls.appRows.controls; appRowsControls.forEach(appRowControl => { appRowControl.get('subscribedOnCreation').enable({ emitEvent: false }); }); } disableSubscribeOnCreationCheckboxes() { const appRowsControls = this.form.controls.appRows.controls; appRowsControls.forEach(appRowControl => { appRowControl.get('subscribedOnCreation').disable({ emitEvent: false }); }); } restoreSubscribeOnCreationFromParent() { const appRowsControls = this.form.controls.appRows.controls; appRowsControls.forEach(appRowControl => { appRowControl.patchValue({ subscribedOnCreation: this.isSubscribed(appRowControl.value.app, this.parentDefaultSubscriptions.onCreationSubscriptions) }); }); } onOverrideOnUpgradeSubscriptionsChange(overrideOnUpgradeSubscriptions) { if (overrideOnUpgradeSubscriptions) { this.enableSubscribeOnUpgradeCheckboxes(); return; } this.disableSubscribeOnUpgradeCheckboxes(); this.restoreSubscribeOnUpgradeFromParent(); } enableSubscribeOnUpgradeCheckboxes() { const appRowsControls = this.form.controls.appRows.controls; appRowsControls.forEach(appRowControl => { appRowControl.get('subscribedOnUpgrade').enable({ emitEvent: false }); }); } disableSubscribeOnUpgradeCheckboxes() { const appRowsControls = this.form.controls.appRows.controls; appRowsControls.forEach(appRowControl => { appRowControl.get('subscribedOnUpgrade').disable({ emitEvent: false }); }); } restoreSubscribeOnUpgradeFromParent() { const appRowsControls = this.form.controls.appRows.controls; appRowsControls.forEach(appRowControl => { appRowControl.patchValue({ subscribedOnUpgrade: this.isSubscribed(appRowControl.value.app, this.parentDefaultSubscriptions.onUpgradeSubscriptions) }); }); } async loadDefaultSubscriptions() { this.parentDefaultSubscriptions = await this.defaultSubscriptionsService.getDefaultSubscriptionsEvaluatedFromParentTenant(); this.currentDefaultSubscriptions = await this.defaultSubscriptionsService.getDefaultSubscriptionsFromCurrentTenant(); const { overrideOnCreationSubscriptions, overrideOnUpgradeSubscriptions } = this.currentDefaultSubscriptions; const onCreationSubscriptions = overrideOnCreationSubscriptions ? this.currentDefaultSubscriptions.onCreationSubscriptions : this.parentDefaultSubscriptions.onCreationSubscriptions; const onUpgradeSubscriptions = overrideOnUpgradeSubscriptions ? this.currentDefaultSubscriptions.onUpgradeSubscriptions : this.parentDefaultSubscriptions.onUpgradeSubscriptions; this.form.patchValue({ overrideOnCreationSubscriptions, overrideOnUpgradeSubscriptions }); this.form.controls.appRows.controls.forEach(appRowControl => { appRowControl.patchValue({ subscribedOnCreation: this.isSubscribed(appRowControl.value.app, onCreationSubscriptions), subscribedOnUpgrade: this.isSubscribed(appRowControl.value.app, onUpgradeSubscriptions) }); }); } getDefaultSubscriptionsForSave() { const { value } = this.form; return { overrideOnCreationSubscriptions: value.overrideOnCreationSubscriptions, onCreationSubscriptions: value.overrideOnCreationSubscriptions ? value.appRows.filter(app => app.subscribedOnCreation).map(app => app.app) : null, overrideOnUpgradeSubscriptions: value.overrideOnUpgradeSubscriptions, onUpgradeSubscriptions: value.overrideOnUpgradeSubscriptions ? value.appRows.filter(app => app.subscribedOnUpgrade).map(app => app.app) : null }; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: DefaultSubscriptionsComponent, deps: [{ token: i1$1.FormBuilder }, { token: DefaultSubscriptionsService }, { token: i2.AlertService }], target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.15", type: DefaultSubscriptionsComponent, isStandalone: true, selector: "c8y-default-subscriptions", ngImport: i0, template: "<c8y-title>{{ 'Default subscriptions' | translate }}</c8y-title>\n\n<c8y-breadcrumb>\n <c8y-breadcrumb-item [label]=\"'Ecosystem' | translate\" [icon]=\"'c8y-atom'\"></c8y-breadcrumb-item>\n <c8y-breadcrumb-item\n [label]=\"'Default subscriptions' | translate\"\n [icon]=\"'c8y-atom'\"\n ></c8y-breadcrumb-item>\n</c8y-breadcrumb>\n\n<form [formGroup]=\"form\" (ngSubmit)=\"save()\">\n <div class=\"card card--fullpage col-lg-max\">\n <div class=\"card-header separator\">\n <div class=\"card-title\" translate>Applications</div>\n </div>\n <div class=\"inner-scroll\">\n <div class=\"sticky-top separator-bottom\">\n <div class=\"d-flex\">\n <div class=\"col-sm-6 col-xs-6 p-24 p-t-16 p-l-xs-16\">\n <p translate>\n Configure default subscriptions in the platform, both for tenant creation and for\n platform upgrade. To display a full list of available applications, override inherited\n settings.\n </p>\n </div>\n <div class=\"col-sm-6 col-xs-6 bg-level-1 p-16 text-center separator-bottom\">\n <div class=\"row\">\n <div class=\"col-sm-6 col-xs-6\">\n <p><strong translate>Subscribed on tenant creation</strong></p>\n <div>\n <label class=\"c8y-switch\" title=\"{{ 'Override inherited' | translate }}\">\n <input type=\"checkbox\" formControlName=\"overrideOnCreationSubscriptions\" />\n <span></span>\n <span>\n {{ 'Override inherited' | translate }}\n </span>\n </label>\n </div>\n </div>\n <div class=\"col-sm-6 col-xs-6\">\n <p><strong translate>Subscribed on platform upgrade</strong></p>\n <div>\n <label class=\"c8y-switch\" title=\"{{ 'Override inherited' | translate }}\">\n <input type=\"checkbox\" formControlName=\"overrideOnUpgradeSubscriptions\" />\n <span></span>\n <span>\n {{ 'Override inherited' | translate }}\n </span>\n </label>\n </div>\n </div>\n </div>\n </div>\n </div>\n </div>\n <div class=\"card-block\" *ngIf=\"loading\"></div>\n <div class=\"card-block card-block d-flex a-i-center j-c-center d-col\" *ngIf=\"loading\">\n <c8y-loading></c8y-loading>\n </div>\n <div class=\"card-block\" *ngIf=\"loading\"></div>\n\n <ng-container formArrayName=\"appRows\">\n <div class=\"bg-level-1\" *ngIf=\"!loading && isEmptyView()\"></div>\n <div class=\"card-block bg-level-0\" *ngIf=\"!loading && isEmptyView()\">\n <c8y-ui-empty-state\n [icon]=\"'c8y-c8y-data'\"\n [title]=\"'No application subscriptions yet.' | translate\"\n [subtitle]=\"\n 'Select &quot;Override inherited&quot; to define the list of subscribed applications.'\n | translate\n \"\n ></c8y-ui-empty-state>\n </div>\n <div class=\"bg-level-1\" *ngIf=\"!loading && isEmptyView()\"></div>\n\n <div *ngFor=\"let appRowControl of form.get('appRows')['controls']; let i = index\">\n <ng-container\n *ngIf=\"shouldShowAppRow(appRowControl.getRawValue())\"\n formArrayName=\"{{ i }}\"\n >\n <div class=\"d-flex a-i-stretch\">\n <div class=\"col-sm-6 col-xs-6 separator-bottom\">\n <div class=\"c8y-list__item__block\">\n <div class=\"c8y-list__item__appicon\">\n <c8y-app-icon\n [app]=\"appRowControl.value.app\"\n [name]=\"appRowControl.value.app.name\"\n [contextPath]=\"appRowControl.value.app.contextPath\"\n ></c8y-app-icon>\n </div>\n <div class=\"c8y-list__item__body\" data-cy=\"defaultSubscriptionForm--c8y-list_item\">\n <div class=\"content-flex-30\">\n <div class=\"col-6\">\n <p\n class=\"text-truncate\"\n title=\"{{ appRowControl.value.app | humanizeAppName | async }}\"\n >\n {{ appRowControl.value.app | humanizeAppName | async }}\n </p>\n <small class=\"text-muted\">{{ appRowControl.value.app.contextPath }}</small>\n </div>\n <div class=\"col-6 text-right-sm\">\n <p>\n <span class=\"text-label-small m-r-4\" translate>Tenant ID</span>\n {{ appRowControl.value.app.owner.tenant.id }}\n </p>\n <!-- TODO: uncomment when company name is available\n <p>\n <span class=\"text-label-small m-r-4\" translate>Company</span>\n <small class=\"text-muted\">company name</small>\n </p> -->\n </div>\n </div>\n </div>\n </div>\n </div>\n\n <div\n class=\"col-sm-3 col-xs-3 bg-level-1 separator-bottom d-flex j-c-center a-i-center\"\n >\n <label\n class=\"c8y-checkbox\"\n [ngClass]=\"{ disabled: appRowControl.controls.subscribedOnCreation.disabled }\"\n >\n <input type=\"checkbox\" formControlName=\"subscribedOnCreation\" />\n <span *ngIf=\"!appRowControl.controls.subscribedOnCreation.disabled\"></span>\n <span\n *ngIf=\"appRowControl.controls.subscribedOnCreation.disabled\"\n title=\"{{ disabledCheckboxHint | translate }}\"\n ></span>\n <span class=\"sr-only\">{{ 'Subscribed on tenant creation' | translate }}</span>\n </label>\n </div>\n\n <div\n class=\"col-sm-3 col-xs-3 bg-level-1 separator-bottom d-flex j-c-center a-i-center\"\n >\n <label\n class=\"c8y-checkbox\"\n [ngClass]=\"{ disabled: appRowControl.controls.subscribedOnUpgrade.disabled }\"\n >\n <input type=\"checkbox\" formControlName=\"subscribedOnUpgrade\" />\n <span *ngIf=\"!appRowControl.controls.subscribedOnUpgrade.disabled\"></span>\n <span\n *ngIf=\"appRowControl.controls.subscribedOnUpgrade.disabled\"\n title=\"{{ disabledCheckboxHint | translate }}\"\n ></span>\n <span class=\"sr-only\">{{ 'Subscribed on platform upgrade' | translate }}</span>\n </label>\n </div>\n </div>\n </ng-container>\n </div>\n </ng-container>\n </div>\n <div class=\"card-footer separator\">\n <button\n class=\"btn btn-primary\"\n type=\"submit\"\n title=\"{{ 'Save default subscriptions' | translate }}\"\n [disabled]=\"form.invalid || form.pristine\"\n >\n {{ 'Save' | translate }}\n </button>\n </div>\n </div>\n</form>\n", dependencies: [{ kind: "component", type: TitleComponent, selector: "c8y-title", inputs: ["pageTitleUpdate"] }, { kind: "component", type: BreadcrumbComponent, selector: "c8y-breadcrumb" }, { kind: "component", type: BreadcrumbItemComponent, selector: "c8y-breadcrumb-item", inputs: ["icon", "translate", "label", "path", "injector"] }, { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1$1NgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i1$1.CheckboxControlValueAccessor, selector: "input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]" }, { kind: "directive", type: i1$1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1$1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1$1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i1$1.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }, { kind: "directive", type: i1$1.FormArrayName, selector: "[formArrayName]", inputs: ["formArrayName"] }, { kind: "directive", type: C8yTranslateDirective, selector: "[translate],[ngx-translate]" }, { kind: "directive", type: RequiredInputPlaceholderDirective, selector: "input[required], input[formControlName]" }, { kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: LoadingComponent, selector: "c8y-loading", inputs: ["layout", "progress", "message"] }, { kind: "component", type: EmptyStateComponent, selector: "c8y-ui-empty-state", inputs: ["icon", "title", "subtitle", "horizontal"] }, { kind: "directive", type: NgFor, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "component", type: AppIconComponent, selector: "c8y-app-icon", inputs: ["contextPath", "name", "app"] }, { kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "pipe", type: C8yTranslatePipe, name: "translate" }, { kind: "pipe", type: AsyncPipe, name: "async" }, { kind: "pipe", type: HumanizeAppNamePipe, name: "humanizeAppName" }] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: DefaultSubscriptionsComponent, decorators: [{ type: Component, args: [{ selector: 'c8y-default-subscriptions', imports: [ TitleComponent, BreadcrumbComponent, BreadcrumbItemComponent, FormsModule, ReactiveFormsModule, C8yTranslateDirective, RequiredInputPlaceholderDirective, NgIf, LoadingComponent, EmptyStateComponent, NgFor, AppIconComponent, NgClass, C8yTranslatePipe, AsyncPipe, HumanizeAppNamePipe ], template: "<c8y-title>{{ 'Default subscriptions' | translate }}</c8y-title>\n\n<c8y-breadcrumb>\n <c8y-breadcrumb-item [label]=\"'Ecosystem' | translate\" [icon]=\"'c8y-atom'\"></c8y-breadcrumb-item>\n <c8y-breadcrumb-item\n [label]=\"'Default subscriptions' | translate\"\n [icon]=\"'c8y-atom'\"\n ></c8y-breadcrumb-item>\n</c8y-breadcrumb>\n\n<form [formGroup]=\"form\" (ngSubmit)=\"save()\">\n <div class=\"card card--fullpage col-lg-max\">\n <div class=\"card-header separator\">\n <div class=\"card-title\" translate>Applications</div>\n </div>\n <div class=\"inner-scroll\">\n <div class=\"sticky-top separator-bottom\">\n <div class=\"d-flex\">\n <div class=\"col-sm-6 col-xs-6 p-24 p-t-16 p-l-xs-16\">\n <p translate>\n Configure default subscriptions in the platform, both for tenant creation and for\n platform upgrade. To display a full list of available applications, override inherited\n settings.\n </p>\n </div>\n <div class=\"col-sm-6 col-xs-6 bg-level-1 p-16 text-center separator-bottom\">\n <div class=\"row\">\n <div class=\"col-sm-6 col-xs-6\">\n <p><strong translate>Subscribed on tenant creation</strong></p>\n <div>\n <label class=\"c8y-switch\" title=\"{{ 'Override inherited' | translate }}\">\n <input type=\"checkbox\" formControlName=\"overrideOnCreationSubscriptions\" />\n <span></span>\n <span>\n {{ 'Override inherited' | translate }}\n </span>\n </label>\n </div>\n </div>\n <div class=\"col-sm-6 col-xs-6\">\n <p><strong translate>Subscribed on platform upgrade</strong></p>\n <div>\n <label class=\"c8y-switch\" title=\"{{ 'Override inherited' | translate }}\">\n <input type=\"checkbox\" formControlName=\"overrideOnUpgradeSubscriptions\" />\n <span></span>\n <span>\n {{ 'Override inherited' | translate }}\n </span>\n </label>\n </div>\n </div>\n </div>\n </div>\n </div>\n </div>\n <div class=\"card-block\" *ngIf=\"loading\"></div>\n <div class=\"card-block card-block d-flex a-i-center j-c-center d-col\" *ngIf=\"loading\">\n <c8y-loading></c8y-loading>\n </div>\n <div class=\"card-block\" *ngIf=\"loading\"></div>\n\n <ng-container formArrayName=\"appRows\">\n <div class=\"bg-level-1\" *ngIf=\"!loading && isEmptyView()\"></div>\n <div class=\"card-block bg-level-0\" *ngIf=\"!loading && isEmptyView()\">\n <c8y-ui-empty-state\n [icon]=\"'c8y-c8y-data'\"\n [title]=\"'No application subscriptions yet.' | translate\"\n [subtitle]=\"\n 'Select &quot;Override inherited&quot; to define the list of subscribed applications.'\n | translate\n \"\n ></c8y-ui-empty-state>\n </div>\n <div class=\"bg-level-1\" *ngIf=\"!loading && isEmptyView()\"></div>\n\n <div *ngFor=\"let appRowControl of form.get('appRows')['controls']; let i = index\">\n <ng-container\n *ngIf=\"shouldShowAppRow(appRowControl.getRawValue())\"\n formArrayName=\"{{ i }}\"\n >\n <div class=\"d-flex a-i-stretch\">\n <div class=\"col-sm-6 col-xs-6 separator-bottom\">\n <div class=\"c8y-list__item__block\">\n <div class=\"c8y-list__item__appicon\">\n <c8y-app-icon\n [app]=\"appRowControl.value.app\"\n [name]=\"appRowControl.value.app.name\"\n [contextPath]=\"appRowControl.value.app.contextPath\"\n ></c8y-app-icon>\n </div>\n <div class=\"c8y-list__item__body\" data-cy=\"defaultSubscriptionForm--c8y-list_item\">\n <div class=\"content-flex-30\">\n <div class=\"col-6\">\n <p\n class=\"text-truncate\"\n title=\"{{ appRowControl.value.app | humanizeAppName | async }}\"\n >\n {{ appRowControl.value.app | humanizeAppName | async }}\n </p>\n <small class=\"text-muted\">{{ appRowControl.value.app.contextPath }}</small>\n </div>\n <div class=\"col-6 text-right-sm\">\n <p>\n <span class=\"text-label-small m-r-4\" translate>Tenant ID</span>\n {{ appRowControl.value.app.owner.tenant.id }}\n </p>\n <!-- TODO: uncomment when company name is available\n <p>\n <span class=\"text-label-small m-r-4\" translate>Company</span>\n <small class=\"text-muted\">company name</small>\n </p> -->\n </div>\n </div>\n </div>\n </div>\n </div>\n\n <div\n class=\"col-sm-3 col-xs-3 bg-level-1 separator-bottom d-flex j-c-center a-i-center\"\n >\n <label\n class=\"c8y-checkbox\"\n [ngClass]=\"{ disabled: appRowControl.controls.subscribedOnCreation.disabled }\"\n >\n <input type=\"checkbox\" formControlName=\"subscribedOnCreation\" />\n <span *ngIf=\"!appRowControl.controls.subscribedOnCreation.disabled\"></span>\n <span\n *ngIf=\"appRowControl.controls.subscribedOnCreation.disabled\"\n title=\"{{ disabledCheckboxHint | translate }}\"\n ></span>\n <span class=\"sr-only\">{{ 'Subscribed on tenant creation' | translate }}</span>\n </label>\n </div>\n\n <div\n class=\"col-sm-3 col-xs-3 bg-level-1 separator-bottom d-flex j-c-center a-i-center\"\n >\n <label\n class=\"c8y-checkbox\"\n [ngClass]=\"{ disabled: appRowControl.controls.subscribedOnUpgrade.disabled }\"\n >\n <input type=\"checkbox\" formControlName=\"subscribedOnUpgrade\" />\n <span *ngIf=\"!appRowControl.controls.subscribedOnUpgrade.disabled\"></span>\n <span\n *ngIf=\"appRowControl.controls.subscribedOnUpgrade.disabled\"\n title=\"{{ disabledCheckboxHint | translate }}\"\n ></span>\n <span class=\"sr-only\">{{ 'Subscribed on platform upgrade' | translate }}</span>\n </label>\n </div>\n </div>\n </ng-container>\n </div>\n </ng-container>\n </div>\n <div class=\"card-footer separator\">\n <button\n class=\"btn btn-primary\"\n type=\"submit\"\n title=\"{{ 'Save default subscriptions' | translate }}\"\n [disabled]=\"form.invalid || form.pristine\"\n >\n {{ 'Save' | translate }}\n </button>\n </div>\n </div>\n</form>\n" }] }], ctorParameters: () => [{ type: i1$1.FormBuilder }, { type: DefaultSubscriptionsService }, { type: i2.AlertService }] }); class DefaultSubscriptionsGuard { constructor(tenantUiService) { this.tenantUiService = tenantUiService; } /** * Checks if default subscriptions feature should be active, * i.e. whether the current tenant is the management or an enterprise tenant. * **Note: the check is executed only once in the runtime.** * * @returns True, if the feature should be active. */ async canActivate() { if (this.active === undefined) { this.active = (await this.tenantUiService.isManagementTenant()) || (await this.tenantUiService.isEnterpriseTenant()); } return this.active; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: DefaultSubscriptionsGuard, deps: [{ token: i2.TenantUiService }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: DefaultSubscriptionsGuard }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: DefaultSubscriptionsGuard, decorators: [{ type: Injectable }], ctorParameters: () => [{ type: i2.TenantUiService }] }); class DefaultSubscriptionsNavigationFactory { constructor(defaultSubscriptionsGuard) { this.defaultSubscriptionsGuard = defaultSubscriptionsGuard; this.navNode = new NavigatorNode({ label: gettext('Default subscriptions'), path: '/default-subscriptions', icon: 'c8y-c8y-data', parent: gettext('Ecosystem'), priority: 100 }); } /** Returns the navigation node if the feature is active. */ async get() { if (await this.defaultSubscriptionsGuard.canActivate()) { return this.navNode; } } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: DefaultSubscriptionsNavigationFactory, deps: [{ token: DefaultSubscriptionsGuard }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: DefaultSubscriptionsNavigationFactory }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: DefaultSubscriptionsNavigationFactory, decorators: [{ type: Injectable }], ctorParameters: () => [{ type: DefaultSubscriptionsGuard }] }); class DefaultSubscriptionsModule { static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: DefaultSubscriptionsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.15", ngImport: i0, type: DefaultSubscriptionsModule, imports: [CoreModule, ReactiveFormsModule, DefaultSubscriptionsComponent], exports: [DefaultSubscriptionsComponent] }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: DefaultSubscriptionsModule, providers: [ DefaultSubscriptionsService, DefaultSubscriptionsGuard, hookNavigator(DefaultSubscriptionsNavigationFactory), hookRoute({ path: 'default-subscriptions', component: DefaultSubscriptionsComponent, canActivate: [DefaultSubscriptionsGuard] }) ], imports: [CoreModule, ReactiveFormsModule, DefaultSubscriptionsComponent] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: DefaultSubscriptionsModule, decorators: [{ type: NgModule, args: [{ imports: [CoreModule, ReactiveFormsModule, DefaultSubscriptionsComponent], exports: [DefaultSubscriptionsComponent], providers: [ DefaultSubscriptionsService, DefaultSubscriptionsGuard, hookNavigator(DefaultSubscriptionsNavigationFactory), hookRoute({ path: 'default-subscriptions', component: DefaultSubscriptionsComponent, canActivate: [DefaultSubscriptionsGuard] }) ] }] }] }); /** * Generated bundle index. Do not edit. */ export { DefaultSubscriptionsComponent, DefaultSubscriptionsContext, DefaultSubscriptionsModule, DefaultSubscriptionsService }; //# sourceMappingURL=c8y-ngx-components-default-subscriptions.mjs.map