UNPKG

@c8y/ngx-components

Version:

Angular modules for Cumulocity IoT applications

467 lines (446 loc) 25.2 kB
import * as i0 from '@angular/core'; import { Injectable, NgModule } from '@angular/core'; import * as i1 from '@c8y/ngx-components'; import { toObservable, NavigatorNode, gettext, hookNavigator, hookTab, ConditionalTabsOutletComponent, CoreModule, ProviderConfigurationModule, hookPatternMessages } from '@c8y/ngx-components'; import { map } from 'rxjs/operators'; import * as i1$1 from '@angular/router'; import { RouterModule } from '@angular/router'; import { get } from 'lodash-es'; class AbstractConnectivityTabFactory { constructor(router, guard) { this.router = router; this.guard = guard; } get() { return this.router.url.match(/connectivitySettings/g) ? this.tab() : []; } tab() { return toObservable(this.guard.canActivate(this.router.routerState.snapshot.root, this.router.routerState.snapshot)).pipe(map(canActivate => (canActivate ? this.config() : null))); } } class AbstractConnectivityNodeFactory { constructor(tabFactory) { this.tabFactory = tabFactory; this.connectivityNode = new NavigatorNode({ parent: gettext('Settings'), label: gettext('Connectivity'), path: 'connectivitySettings', icon: 'plug', preventDuplicates: true }); } get() { return toObservable(this.tabFactory.tab()).pipe(map(tab => { return !!tab ? [this.connectivityNode] : []; })); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: AbstractConnectivityNodeFactory, deps: [{ token: AbstractConnectivityTabFactory }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: AbstractConnectivityNodeFactory }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: AbstractConnectivityNodeFactory, decorators: [{ type: Injectable }], ctorParameters: () => [{ type: AbstractConnectivityTabFactory }] }); class ActilityGuard { static { this.applicationName = 'actility'; } constructor(appState) { this.appState = appState; } canActivate() { if (this.showActilityProvider === undefined) { this.showActilityProvider = this.appState.isApplicationAvailable(ActilityGuard.applicationName); } return this.showActilityProvider; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: ActilityGuard, deps: [{ token: i1.AppStateService }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: ActilityGuard }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: ActilityGuard, decorators: [{ type: Injectable }], ctorParameters: () => [{ type: i1.AppStateService }] }); class ActilityTabFactory extends AbstractConnectivityTabFactory { constructor(router, guard) { super(router, guard); this.router = router; this.guard = guard; this.tabConfig = { label: gettext('Actility'), path: '/connectivitySettings/multiple_lns_connectors_actility', icon: 'wall-socket' }; } config() { return this.tabConfig; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: ActilityTabFactory, deps: [{ token: i1$1.Router }, { token: ActilityGuard }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: ActilityTabFactory, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: ActilityTabFactory, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }], ctorParameters: () => [{ type: i1$1.Router }, { type: ActilityGuard }] }); class ActilityNodeFactory extends AbstractConnectivityNodeFactory { constructor(tabFactory) { super(tabFactory); this.tabFactory = tabFactory; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: ActilityNodeFactory, deps: [{ token: ActilityTabFactory }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: ActilityNodeFactory, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: ActilityNodeFactory, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }], ctorParameters: () => [{ type: ActilityTabFactory }] }); class ActilityModule { static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: ActilityModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.14", ngImport: i0, type: ActilityModule }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: ActilityModule, providers: [ActilityGuard, hookNavigator(ActilityNodeFactory), hookTab(ActilityTabFactory)] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: ActilityModule, decorators: [{ type: NgModule, args: [{ providers: [ActilityGuard, hookNavigator(ActilityNodeFactory), hookTab(ActilityTabFactory)] }] }] }); class LoriotGuard { static { this.applicationName = 'loriot'; } constructor(appState) { this.appState = appState; } canActivate() { if (this.showLoriotProvider === undefined) { this.showLoriotProvider = this.appState.isApplicationAvailable(LoriotGuard.applicationName); } return this.showLoriotProvider; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: LoriotGuard, deps: [{ token: i1.AppStateService }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: LoriotGuard }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: LoriotGuard, decorators: [{ type: Injectable }], ctorParameters: () => [{ type: i1.AppStateService }] }); class LoriotTabFactory extends AbstractConnectivityTabFactory { constructor(router, guard) { super(router, guard); this.router = router; this.guard = guard; this.tabConfig = { label: 'LORIOT', path: '/connectivitySettings/multiple_lns_connectors_loriot', icon: 'wall-socket' }; } config() { return this.tabConfig; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: LoriotTabFactory, deps: [{ token: i1$1.Router }, { token: LoriotGuard }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: LoriotTabFactory, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: LoriotTabFactory, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }], ctorParameters: () => [{ type: i1$1.Router }, { type: LoriotGuard }] }); class LoriotNodeFactory extends AbstractConnectivityNodeFactory { constructor(tabFactory) { super(tabFactory); this.tabFactory = tabFactory; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: LoriotNodeFactory, deps: [{ token: LoriotTabFactory }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: LoriotNodeFactory, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: LoriotNodeFactory, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }], ctorParameters: () => [{ type: LoriotTabFactory }] }); class LoriotModule { static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: LoriotModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.14", ngImport: i0, type: LoriotModule }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: LoriotModule, providers: [LoriotGuard, hookNavigator(LoriotNodeFactory), hookTab(LoriotTabFactory)] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: LoriotModule, decorators: [{ type: NgModule, args: [{ providers: [LoriotGuard, hookNavigator(LoriotNodeFactory), hookTab(LoriotTabFactory)] }] }] }); class SigfoxGuard { static { this.applicationName = 'sigfox-agent'; } constructor(appState) { this.appState = appState; } canActivate() { if (this.showSigfoxProvider === undefined) { this.showSigfoxProvider = this.appState.isApplicationAvailable(SigfoxGuard.applicationName); } return this.showSigfoxProvider; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: SigfoxGuard, deps: [{ token: i1.AppStateService }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: SigfoxGuard }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: SigfoxGuard, decorators: [{ type: Injectable }], ctorParameters: () => [{ type: i1.AppStateService }] }); class SigfoxTabFactory extends AbstractConnectivityTabFactory { constructor(router, guard) { super(router, guard); this.router = router; this.guard = guard; this.tabConfig = { label: gettext('Sigfox'), path: '/connectivitySettings/multiple_lns_connectors_sigfox', icon: 'wall-socket' }; } config() { return this.tabConfig; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: SigfoxTabFactory, deps: [{ token: i1$1.Router }, { token: SigfoxGuard }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: SigfoxTabFactory, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: SigfoxTabFactory, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }], ctorParameters: () => [{ type: i1$1.Router }, { type: SigfoxGuard }] }); class SigfoxNodeFactory extends AbstractConnectivityNodeFactory { constructor(tabFactory) { super(tabFactory); this.tabFactory = tabFactory; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: SigfoxNodeFactory, deps: [{ token: SigfoxTabFactory }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: SigfoxNodeFactory, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: SigfoxNodeFactory, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }], ctorParameters: () => [{ type: SigfoxTabFactory }] }); class SigfoxModule { static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: SigfoxModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.14", ngImport: i0, type: SigfoxModule }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: SigfoxModule, providers: [SigfoxGuard, hookNavigator(SigfoxNodeFactory), hookTab(SigfoxTabFactory)] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: SigfoxModule, decorators: [{ type: NgModule, args: [{ providers: [SigfoxGuard, hookNavigator(SigfoxNodeFactory), hookTab(SigfoxTabFactory)] }] }] }); const connectivityRoutes = [ { path: 'connectivitySettings', component: ConditionalTabsOutletComponent } ]; class ConnectivityModule { static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: ConnectivityModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.14", ngImport: i0, type: ConnectivityModule, imports: [CoreModule, ActilityModule, SigfoxModule, LoriotModule, i1$1.RouterModule] }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: ConnectivityModule, imports: [CoreModule, ActilityModule, SigfoxModule, LoriotModule, RouterModule.forChild(connectivityRoutes)] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: ConnectivityModule, decorators: [{ type: NgModule, args: [{ imports: [ CoreModule, ActilityModule, SigfoxModule, LoriotModule, RouterModule.forChild(connectivityRoutes) ] }] }] }); class SimGuard { static { this.applicationName = 'connectivity'; } constructor(permissions, appState) { this.permissions = permissions; this.appState = appState; } canActivate() { if (this.showSimProvider === undefined) { const hasRole = Promise.resolve(this.permissions.hasRole('ROLE_CONNECTIVITY_READ')); this.showSimProvider = hasRole.then((hasPermissions) => hasPermissions && this.appState.isApplicationAvailable(SimGuard.applicationName)); } return this.showSimProvider; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: SimGuard, deps: [{ token: i1.Permissions }, { token: i1.AppStateService }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: SimGuard }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: SimGuard, decorators: [{ type: Injectable }], ctorParameters: () => [{ type: i1.Permissions }, { type: i1.AppStateService }] }); const MESSAGES_CONNECTIVITY_SIM = { '^Cache duration$': { gettext: gettext('Cache duration') }, '^Sets the duration how long information from the provider may be cached in seconds$': { gettext: gettext('Sets the duration in seconds how long the information from the provider may be cached.') }, '^Certificate$': { gettext: gettext('Certificate') }, '^Certificate file$': { gettext: gettext('Certificate file') }, '^API URL$': { gettext: gettext('API URL') }, '^Sim source$': { gettext: gettext('SIM source') }, '^source$': { gettext: gettext('source') }, '^Password$': { gettext: gettext('Password') }, '^Trust store password$': { gettext: gettext('Trust store password') }, '^Trust store type$': { gettext: gettext('Trust store type') }, '^License key$': { gettext: gettext('License key') }, '^Username$': { gettext: gettext('Username') } }; async function encodeFiles(model, fields) { const result = { ...model }; const fileFields = (get(fields, '[0].fieldGroup') || []).filter((field) => { return field.type === 'file' && field.templateOptions.contentEncoding === 'base64'; }); for (const fileField of fileFields) { const files = model[fileField.key]; if (files && Array.isArray(files) && files.length) { if (fileField.templateOptions.maxAllowedFiles === 1) { result[fileField.key] = (await files[0].readAsDataURL()).replace(/data:\S+;base64,/gi, ''); } else { const encodedFileContent = []; for (const file of files) { encodedFileContent.push((await file.readAsDataURL()).replace(/data:\S+;base64,/gi, '')); } result[fileField.key] = encodedFileContent; } } else if (typeof files === 'string' || files instanceof String) { result[fileField.key] = files; } } return result; } class SimModule { static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: SimModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.14", ngImport: i0, type: SimModule, imports: [i1.ProviderConfigurationModule] }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: SimModule, providers: [SimGuard, hookPatternMessages(MESSAGES_CONNECTIVITY_SIM)], imports: [ProviderConfigurationModule.config([ { navigation: { label: gettext('Connectivity'), path: 'connectivitySettings', icon: 'plug', parent: gettext('Settings'), priority: 1000, preventDuplicates: true }, tab: { path: 'sim_provider_settings', label: 'SIM provider settings', icon: 'mobile', canActivate: [SimGuard] }, layout: { pageTitle: gettext('Connectivity'), cardTitle: gettext('Settings'), description: gettext(`In order to see the 'Connectivity' tab in device details, the user needs to have 'Read' permission for 'Connectivity'. To change SIM card status and send text messages, the user needs to have 'Admin' permission for 'Connectivity'.`), providerName: gettext('Provider'), providerNamePlaceholder: gettext('Select or type to filter providers'), providerNameNoMatchesHint: gettext('Select one of the existing providers.'), deleteRoles: ['ROLE_CONNECTIVITY_ADMIN'], deleteBtnLabel: gettext('Delete'), saveRoles: ['ROLE_CONNECTIVITY_ADMIN'], saveBtnLabel: gettext('Save'), beforeSaveHook: encodeFiles, configurationUpdatedSuccessMsg: gettext('Settings updated.'), deleteConfigurationModalTitle: gettext('Delete settings'), deleteConfigurationModalBody: gettext(`You are about to delete SIM provider settings. Do you want to proceed?`), deleteConfigurationModalOkBtnLabel: gettext('Delete'), configurationDeletedSuccessMsg: gettext('Settings deleted.') }, endpoint: { definitionsEndpoint: { baseUrl: 'service/connectivity/metadata', listUrl: 'definitions' }, configurationEndpoint: { baseUrl: 'service/connectivity/metadata', listUrl: 'sim/provider' } } } ])] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: SimModule, decorators: [{ type: NgModule, args: [{ providers: [SimGuard, hookPatternMessages(MESSAGES_CONNECTIVITY_SIM)], imports: [ ProviderConfigurationModule.config([ { navigation: { label: gettext('Connectivity'), path: 'connectivitySettings', icon: 'plug', parent: gettext('Settings'), priority: 1000, preventDuplicates: true }, tab: { path: 'sim_provider_settings', label: 'SIM provider settings', icon: 'mobile', canActivate: [SimGuard] }, layout: { pageTitle: gettext('Connectivity'), cardTitle: gettext('Settings'), description: gettext(`In order to see the 'Connectivity' tab in device details, the user needs to have 'Read' permission for 'Connectivity'. To change SIM card status and send text messages, the user needs to have 'Admin' permission for 'Connectivity'.`), providerName: gettext('Provider'), providerNamePlaceholder: gettext('Select or type to filter providers'), providerNameNoMatchesHint: gettext('Select one of the existing providers.'), deleteRoles: ['ROLE_CONNECTIVITY_ADMIN'], deleteBtnLabel: gettext('Delete'), saveRoles: ['ROLE_CONNECTIVITY_ADMIN'], saveBtnLabel: gettext('Save'), beforeSaveHook: encodeFiles, configurationUpdatedSuccessMsg: gettext('Settings updated.'), deleteConfigurationModalTitle: gettext('Delete settings'), deleteConfigurationModalBody: gettext(`You are about to delete SIM provider settings. Do you want to proceed?`), deleteConfigurationModalOkBtnLabel: gettext('Delete'), configurationDeletedSuccessMsg: gettext('Settings deleted.') }, endpoint: { definitionsEndpoint: { baseUrl: 'service/connectivity/metadata', listUrl: 'definitions' }, configurationEndpoint: { baseUrl: 'service/connectivity/metadata', listUrl: 'sim/provider' } } } ]) ] }] }] }); /** * Generated bundle index. Do not edit. */ export { AbstractConnectivityNodeFactory, AbstractConnectivityTabFactory, ActilityGuard, ActilityModule, ActilityNodeFactory, ActilityTabFactory, ConnectivityModule, LoriotGuard, LoriotModule, LoriotNodeFactory, LoriotTabFactory, SigfoxGuard, SigfoxModule, SigfoxNodeFactory, SigfoxTabFactory, SimGuard, SimModule, encodeFiles }; //# sourceMappingURL=c8y-ngx-components-connectivity.mjs.map