Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: standalone mode #614

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b27bf05
feat: initial version of standalone mode
bastianjakobi Nov 19, 2024
376a1b3
feat: initial version of standalone mode
bastianjakobi Nov 19, 2024
107aa14
fix: fix linter
bastianjakobi Nov 19, 2024
300e06b
fix: add graceful fallback for empty env.json load
bastianjakobi Dec 3, 2024
5aa5d9e
feat: move translation loaders to angular-integration-interface, impr…
bastianjakobi Dec 5, 2024
ccebe33
Merge branch 'main' into feat/standalone-mode
bastianjakobi Dec 5, 2024
fa79ade
feat: ensure unique translations in new create-translate-loader
bastianjakobi Dec 6, 2024
755b7b3
feat: migrate standalone shell to a module containing shell-viewport …
bastianjakobi Dec 6, 2024
2bec04c
fix: fix CI
bastianjakobi Dec 6, 2024
6f78745
fix: disable oneCXShellLayout by default in standalone-shell
bastianjakobi Dec 6, 2024
070a8d0
fix: fix ci
bastianjakobi Dec 6, 2024
060680a
refactor: provide PIA TRANSLATION_PATH from within PIA
bastianjakobi Dec 9, 2024
b6d9087
refactor: provide TRANSLATION_PATH from within angular accelerator
bastianjakobi Dec 9, 2024
03f24ed
feat: inject translation paths in libs and remove dependency between …
bastianjakobi Dec 9, 2024
c5bfde4
refactor: move permission checker utils to angular-integration-interf…
bastianjakobi Dec 9, 2024
abf8485
refactor: remove dependency between shell-core and angular-accelerator
bastianjakobi Dec 9, 2024
c714f39
refactor: move utils to new lib, fix peer deps and peer dep linting
bastianjakobi Dec 19, 2024
d47d890
fix: fix storybook imports
bastianjakobi Dec 19, 2024
d177a04
Merge branch 'main' into feat/standalone-mode
bastianjakobi Dec 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion libs/angular-accelerator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@
"@angular/platform-browser": "^18.0.5",
"@angular/router": "^18.0.5",
"@ngx-translate/core": "^15.0.0",
"@ngx-translate/http-loader": "^8.0.0",
"@ngneat/until-destroy": "^10.0.0",
"@onecx/integration-interface": "^5.29.0",
"@onecx/accelerator": "^5.29.0",
"@onecx/angular-integration-interface": "^5.29.0",
"@onecx/angular-remote-components": "^5.29.0",
"@onecx/angular-testing": "^5.29.0",
"@onecx/angular-utils": "^5.29.0",
"chart.js": "^4.4.3",
"d3-scale-chromatic": "^3.1.0",
"rxjs": "~7.8.1",
"primeng": "^17.18.6"
"primeng": "^17.18.6",
"@storybook/angular": "^8.3.2"
},
"dependencies": {},
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion libs/angular-accelerator/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"lintFilePatterns": [
"libs/angular-accelerator/**/*.ts",
"libs/angular-accelerator/**/*.html",
"libx/angular-accelerator/package.json"
"libs/angular-accelerator/package.json"
]
}
},
Expand Down
3 changes: 3 additions & 0 deletions libs/angular-accelerator/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// injection tokens + related utilities
export * from './lib/injection-tokens/has-permission-checker'

// directives
export * from './lib/directives/if-permission.directive'
export * from './lib/directives/if-breakpoint.directive'
Expand Down
52 changes: 49 additions & 3 deletions libs/angular-accelerator/src/lib/angular-accelerator.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { CommonModule } from '@angular/common'
import { APP_INITIALIZER, LOCALE_ID, NgModule } from '@angular/core'
import {
APP_INITIALIZER,
Injector,
LOCALE_ID,
NgModule,
Optional,
Provider,
SkipSelf,
StaticProvider,
} from '@angular/core'
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
import { RouterModule } from '@angular/router'
import { MissingTranslationHandler, MissingTranslationHandlerParams, TranslateModule } from '@ngx-translate/core'
Expand All @@ -24,7 +33,8 @@ import { DataLoadingErrorComponent } from './components/data-loading-error/data-
import { SearchHeaderComponent } from './components/search-header/search-header.component'
import { AdvancedDirective } from './directives/advanced.directive'
import { IfBreakpointDirective } from './directives/if-breakpoint.directive'
import { HAS_PERMISSION_CHECKER, IfPermissionDirective } from './directives/if-permission.directive'
import { IfPermissionDirective } from './directives/if-permission.directive'
import { HAS_PERMISSION_CHECKER, HasPermissionChecker, TRANSLATION_PATH } from '@onecx/angular-utils'
import { SrcDirective } from './directives/src.directive'
import { TooltipOnOverflowDirective } from './directives/tooltipOnOverflow.directive'
import { DynamicPipe } from './pipes/dynamic.pipe'
Expand All @@ -45,6 +55,31 @@ function appInitializer(userService: UserService) {
}
}

function hasPermissionCheckerFactory(parentInjector: Injector, hasPermissionChecker: HasPermissionChecker) {
if (!hasPermissionChecker) {
const hasUserService = !!parentInjector.get(UserService, null)
const injectorConfig: {
providers: Array<Provider | StaticProvider>
parent?: Injector
name?: string
} = {
providers: [
{
provide: HAS_PERMISSION_CHECKER,
useExisting: UserService,
},
],
parent: parentInjector,
}
if (!hasUserService) {
injectorConfig.providers.push(UserService)
}
const injector = Injector.create(injectorConfig)
hasPermissionChecker = injector.get(HAS_PERMISSION_CHECKER)
}
return hasPermissionChecker
}

Comment on lines +58 to +82
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we test this?

@NgModule({
imports: [
CommonModule,
Expand Down Expand Up @@ -86,14 +121,25 @@ function appInitializer(userService: UserService) {
},
{
provide: HAS_PERMISSION_CHECKER,
useExisting: UserService,
useFactory: hasPermissionCheckerFactory,
deps: [Injector, [new Optional(), new SkipSelf(), HAS_PERMISSION_CHECKER]],
},
{
provide: APP_INITIALIZER,
useFactory: appInitializer,
deps: [UserService],
multi: true,
},
{
provide: TRANSLATION_PATH,
useValue: './onecx-angular-accelerator/assets/i18n/',
multi: true
},
{
provide: TRANSLATION_PATH,
useValue: './onecx-angular-accelerator/assets/i18n/primeng/',
multi: true
},
AppConfigService,
],
exports: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import { UserService } from '@onecx/angular-integration-interface'
import { MockUserService } from '@onecx/angular-integration-interface/mocks'
import { StorybookTranslateModule } from './../../storybook-translate.module'
import { DataListGridComponent } from './data-list-grid.component'
import { HAS_PERMISSION_CHECKER, IfPermissionDirective } from '../../directives/if-permission.directive'
import { IfPermissionDirective } from '../../directives/if-permission.directive'
import { TooltipOnOverflowDirective } from '../../directives/tooltipOnOverflow.directive'
import { MockAuthModule } from '../../mock-auth/mock-auth.module'
import { HAS_PERMISSION_CHECKER } from '@onecx/angular-utils'

const DataListGridComponentSBConfig: Meta<DataListGridComponent> = {
title: 'Components/DataListGridComponent',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import { MockUserService } from '@onecx/angular-integration-interface/mocks'
import { DataTableComponent } from './data-table.component'
import { StorybookTranslateModule } from './../../storybook-translate.module'
import { MockAuthModule } from '../../mock-auth/mock-auth.module'
import { HAS_PERMISSION_CHECKER, IfPermissionDirective } from '../../directives/if-permission.directive'
import { IfPermissionDirective } from '../../directives/if-permission.directive'
import { ColumnType } from '../../model/column-type.model'
import { MenuModule } from 'primeng/menu'
import { DynamicLocaleId } from '../../utils/dynamic-locale-id'
import { CheckboxModule } from 'primeng/checkbox'
import { FormsModule } from '@angular/forms'
import { HAS_PERMISSION_CHECKER } from '@onecx/angular-utils'

type DataTableInputTypes = Pick<DataTableComponent, 'rows' | 'columns' | 'emptyResultsMessage' | 'selectedRows'>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
Directive,
ElementRef,
Inject,
InjectionToken,
Input,
OnInit,
Optional,
Expand All @@ -11,21 +10,7 @@ import {
ViewContainerRef,
} from '@angular/core'
import { UserService } from '@onecx/angular-integration-interface'

export interface HasPermissionChecker {
hasPermission(permissionKey: string): boolean
}

/**
* This checker always returns true, basically disabling the permission system on the UI side
*/
export class AlwaysGrantPermissionChecker implements HasPermissionChecker {
hasPermission(_permissionKey: string): boolean {
return true
}
}

export const HAS_PERMISSION_CHECKER = new InjectionToken<HasPermissionChecker>('hasPermission')
import { HAS_PERMISSION_CHECKER, HasPermissionChecker } from '@onecx/angular-utils'

@Directive({ selector: '[ocxIfPermission], [ocxIfNotPermission]' })
export class IfPermissionDirective implements OnInit {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @deprecated Please import from `@onecx/angular-utils` instead.
*/
export { HasPermissionChecker } from '@onecx/angular-utils'

/**
* This checker always returns true, basically disabling the permission system on the UI side
* @deprecated Please import from `@onecx/angular-utils` instead.
*/
export { AlwaysGrantPermissionChecker } from '@onecx/angular-utils'

/**
* @deprecated Please import from `@onecx/angular-utils` instead.
*/
export { HAS_PERMISSION_CHECKER } from '@onecx/angular-utils'
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ declare global {
}
}

/**
* @deprecated Please import from `@onecx/angular-utils` instead.
*/
@Injectable({ providedIn: 'root' })
export class TranslationCacheService implements OnDestroy {
private translationTopic$ = new TranslationCacheTopic()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { TranslateLoader } from '@ngx-translate/core'
import { defaultIfEmpty, first, mergeMap, Observable, of, tap } from 'rxjs'

/**
* @deprecated Please import from `@onecx/angular-utils` instead.
*/
export class AsyncTranslateLoader implements TranslateLoader {
static lastTimerId = 0
timerId = AsyncTranslateLoader.lastTimerId++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { TranslateHttpLoader } from '@ngx-translate/http-loader'
import { Observable } from 'rxjs'
import { TranslationCacheService } from '../services/translation-cache.service'

/**
* @deprecated Please import from `@onecx/angular-utils` instead.
*/
export class CachingTranslateLoader implements TranslateLoader {
private translateLoader: TranslateHttpLoader

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { TranslateCombinedLoader } from './translate.combined.loader'

let lastTranslateLoaderTimerId = 0

/**
* @deprecated Please import from `@onecx/angular-utils` instead.
*/
export function createTranslateLoader(
http: HttpClient,
appStateService: AppStateService,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { TranslateLoader } from '@ngx-translate/core'
import { Observable, catchError, forkJoin, map, of } from 'rxjs'

/**
* @deprecated Please import from `@onecx/angular-utils` instead.
*/
export class TranslateCombinedLoader implements TranslateLoader {
private _loaders: TranslateLoader[]
constructor(...loaders: TranslateLoader[]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ export class ConfigurationService implements OnDestroy {

loadConfigPromise
.then(async (config) => {
if (config) {
await this.config$.publish({ ...this.defaultConfig, ...config }).then(() => {
resolve(true)
})
}
await this.config$.publish({ ...this.defaultConfig, ...(config ?? {}) }).then(() => {
resolve(true)
})
})
.catch((e) => {
console.log(`Failed to load env configuration`)
Expand Down
3 changes: 2 additions & 1 deletion libs/angular-testing/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"options": {
"lintFilePatterns": [
"libs/angular-testing/**/*.ts",
"libs/angular-testing/**/*.html"
"libs/angular-testing/**/*.html",
"libs/angular-testing/package.json"
]
}
},
Expand Down
40 changes: 40 additions & 0 deletions libs/angular-utils/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts"],
"extends": ["plugin:@nx/angular", "plugin:@angular-eslint/template/process-inline-templates"],
"rules": {
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "lib",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "ocx",
"style": "kebab-case"
}
]
}
},
{
"files": ["*.html"],
"extends": ["plugin:@nx/angular-template"],
"rules": {}
},
{
"files": ["*.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": "error"
}
}
]
}
Loading
Loading