Skip to content

Commit

Permalink
Merge pull request #813 from liimaorg/development
Browse files Browse the repository at this point in the history
  • Loading branch information
StephGit authored Dec 19, 2024
2 parents 94c9568 + 64ef8f5 commit 5a7e875
Show file tree
Hide file tree
Showing 522 changed files with 8,398 additions and 18,443 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: test and build

on:
push:
branches: [ master ]
branches: [ master, development ]
pull_request:
branches: [ master ]
branches: [ master, development ]

jobs:
build_and_test:
Expand Down
4 changes: 2 additions & 2 deletions AMW_angular/io/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
"error",
{
"type": "attribute",
"prefix": "amw",
"prefix": "app",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "amw",
"prefix": "app",
"style": "kebab-case"
}
]
Expand Down
8 changes: 1 addition & 7 deletions AMW_angular/io/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@
}
],
"styles": ["src/styles.scss", "./node_modules/bootstrap-icons/font/bootstrap-icons.scss"],
"scripts": [
"node_modules/codemirror/lib/codemirror.js",
"node_modules/codemirror/addon/mode/simple.js",
"node_modules/codemirror/addon/dialog/dialog.js",
"node_modules/codemirror/addon/search/searchcursor.js",
"node_modules/codemirror/addon/search/search.js"
],
"scripts": [],
"extractLicenses": false,
"sourceMap": true,
"optimization": true,
Expand Down
27 changes: 13 additions & 14 deletions AMW_angular/io/coding-guidelines.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Coding Guidelines


## Inject() over Constructor-Injections

Use `inject()` instead of constuctor-injection to make the code more explicit and obvious.
Use `inject()` instead of constructor-injection to make the code more explicit and obvious.

```typescript
// use
Expand All @@ -16,47 +15,48 @@ constructor(
```

## RxJS

Leverage RxJS for API calls, web sockets, and complex data flows, especially when handling multiple asynchronous events. Combine with Signals to simplify component state management.

## Signals

Use signals for changing values in Components
Use Signals for changing values in Components

### Signal from Observable

#### GET

Make API-requests with observables and expose the state as a signal:
Make API-requests with observables and expose the state as a Signal:

```typescript
// retrive data from API using RxJS
// retrieve data from API using RxJS
private users$ = this.http.get<User[]>(this.userUrl);

// expose as signal
// expose as Signal
users = toSignal(this.users$, { initialValue: [] as User[]});
```

The observable `users$` is just used to pass the state to the _readonly_ signal `users`. (The signals created from an observable are always _readonly_!)
The observable `users$` is just used to pass the state to the _readonly_ Signal `users`. (The Signals created from an observable are always _readonly_!)
No need for unsubscription - this is handled by `toSignal()` automatically.

Use the signal in the component not in the template. (Separation of concerns)
Use the Signal in the component not in the template. (Separation of concerns)

#### POST / DELETE etc.

To update data in a signal you have to create a WritableSignal:
To update data in a Signal you have to create a WritableSignal:

```typescript
// WritableSignal
users = signal<Tag[]>([]);
// retrive data from API using RxJS and write it in the WritableSignal
// retrieve data from API using RxJS and write it in the WritableSignal
private users$ = this.http.get<User[]>(this.userUrl).pipe(tap((users) => this.users.set(users)));
// only used to automatically un-/subscribe to the observable
readOnlyUsers = toSignal(this.users$, { initialValue: [] as User[]});
```

## Auth Service

The frontend provides a singelton auth-service which holds all restrictions for the current user.
The frontend provides a singelton auth-service which holds all restrictions for the current user.

After injecting the service in your component you can get Permissions/Actions depending on your needs:

Expand All @@ -67,10 +67,9 @@ authService = inject(AuthService);
// get actions for a specific permission
const actions = this.authService.getActionsForPermission('MY_PERMISSION');

// verify role in an action and set signal
// verify role in an action and set Signal
this.canCreate.set(actions.some(isAllowed('CREATE')));

// or directly set signal based on a concret permission and action value
// or directly set Signal based on a concrete permission and action value
this.canViewSettings.set(this.authService.hasPermission('SETTINGS', 'READ'));

```
Loading

0 comments on commit 5a7e875

Please sign in to comment.