* upgrade preparation fixes * remove fdescribe * update browserlist config * ng8 * ngrx 8 * ng9 * ngrx 9 * remove entryComponents * unit tests * ng 10 * latest ADF * fix unit tests * fix lint * update deps and travis * code fixes * upgrade webdriver * cleanup libs * fix test * update test * Use browserTarget as target for lite-serve * Use the update webdriver with CI condition * Use version console.log('load', path * Fix path sh * Try to use remote env * Add the . to export variabled * Use hardcoded chrome version * Remove the run remote * Avoid to use the escape * Skip flaky e2e and raise issue ACA-3615 * SKip failing e2e * Skip flaky e2e and raise issue ACA-3615 * Fix close app toolbar menu and preconditions + tests of mark-favorite.test.ts Personal Files section * Fix mark-favorite tests * Fix ext-header test * Fix new-menu tests * Fix lint * no message * Fix viewer tests Co-authored-by: maurizio vitale <maurizio.vitale@alfresco.com> Co-authored-by: Cristina Jalba <cristina.jalba@ness.com>
6.2 KiB
Title
Title |
---|
Tutorials |
Tutorials
Below are some short tutorials that cover common tasks.
Custom route with parameters
In this tutorial, we are going to implement the following features:
- Update the Trashcan component to receive and log route parameters.
- Create a new route that points to the Trashcan component and uses the main layout.
- Create an action reference that allows redirecting to the new route.
- Create a button in the New menu that invokes an action.
Update src/app/components/trashcan/trashcan.component.ts
and append the following code to the ngOnInit
body:
import { ActivatedRoute, Params } from '@angular/router';
@Component({...})
export class TrashcanComponent {
constructor(
// ...
private route: ActivatedRoute
) {}
ngOnInit() {
// ...
this.route.params.subscribe(({ nodeId }: Params) => {
console.log('node: ', nodeId);
});
}
}
The code above logs the current route parameters to the browser console and is proof the integration works as expected.
Next, add a new route definition as in the example below:
{
"$schema": "../../../extension.schema.json",
"$version": "1.0.0",
"$name": "plugin1",
"routes": [
{
"id": "custom.routes.trashcan",
"path": "ext/trashcan/:nodeId",
"component": "your.component.id",
"layout": "app.layout.main",
"auth": ["app.auth"]
}
]
}
The template above creates a new route reference with the id custom.routes.trashcan
that points to the ext/trashcan/
route and accepts the nodeId
parameter.
Also, we are going to use the default application layout (app.layout.main
)
and authentication guards (app.auth
).
Next, create an action reference for the NAVIGATE_ROUTE
application action
and pass route parameters: /ext/trashcan
for the path, and 10
for the nodeId
value.
{
"$schema": "../../../extension.schema.json",
"$version": "1.0.0",
"$name": "plugin1",
"routes": [...],
"actions": [
{
"id": "custom.actions.trashcan",
"type": "NAVIGATE_ROUTE",
"payload": "$(['/ext/trashcan', '10'])"
}
]
}
Finally, declare a new menu item for the NEW
button and use the custom.actions.trashcan
action created above.
{
"$schema": "../../../extension.schema.json",
"$version": "1.0.0",
"$name": "plugin1",
"routes": [...],
"actions": [...],
"features": {
"create": [
{
"id": "custom.create.trashcan",
"type": "default",
"icon": "build",
"title": "Custom trashcan route",
"actions": {
"click": "custom.actions.trashcan"
}
}
]
}
}
Now, if you run the application, you should see a new menu item called "Custom Trashcan Route" in the "NEW" dropdown.
Upon clicking this item you should navigate to the /ext/trashcan/10
route containing a Trashcan component.
Check the browser console output and ensure you have the following output:
node: 10
You have successfully created a new menu button that invokes your custom action and redirects you to the extra application route.
Dialog actions
In this tutorial, we are going to create an action that invokes a custom material dialog.
Please read more details on Dialog components here: Dialog Overview
Create a dialog
ng g component dialogs/my-extension-dialog --module=app
Update my-extension-dialog.component.ts
:
import { Component } from '@angular/core';
import { MatDialogRef } from '@angular/material/dialog';
@Component({
selector: 'aca-my-extension-dialog',
templateUrl: './my-extension-dialog.component.html',
styleUrls: ['./my-extension-dialog.component.scss']
})
export class MyExtensionDialogComponent {
constructor(public dialogRef: MatDialogRef<MyExtensionDialogComponent>) {}
}
Update my-extension-dialog.component.html
:
<h2 mat-dialog-title>Delete all</h2>
<mat-dialog-content>Are you sure?</mat-dialog-content>
<mat-dialog-actions>
<button mat-button mat-dialog-close>No</button>
<!-- The mat-dialog-close directive optionally accepts a value as a result for the dialog. -->
<button mat-button [mat-dialog-close]="true">Yes</button>
</mat-dialog-actions>
Create an action
Append the following code to the src/app/store/actions/app.actions.ts
:
export const SHOW_MY_DIALOG = 'SHOW_MY_DIALOG';
export class ShowMydDialogAction implements Action {
readonly type = SHOW_MY_DIALOG;
}
See also:
Create an effect
Update src/app/store/effects/app.effects.ts
:
import { ShowMydDialogAction, SHOW_MY_DIALOG } from '../actions/app.actions';
@Injectable()
export class AppEffects {
constructor(...) {}
@Effect({ dispatch: false })
showMyDialog$ = this.actions$.pipe(
ofType<ShowMydDialogAction>(SHOW_MY_DIALOG),
map(() => {})
);
// ...
}
See also:
Update to raise a dialog
import { MatDialog } from '@angular/material/dialog';
import { MyExtensionDialogComponent } from '../../dialogs/my-extension-dialog/my-extension-dialog.component';
@Injectable()
export class AppEffects {
constructor(
...,
private dialog: MatDialog
) {}
@Effect({ dispatch: false })
showMyDialog$ = this.actions$.pipe(
ofType<ShowMydDialogAction>(SHOW_MY_DIALOG),
map(() => {
this.dialog.open(MyExtensionDialogComponent)
})
);
...
}
Register a toolbar action
Update the src/assets/app.extensions.json
file, and insert a new entry to the features.toolbar
section:
{
...,
"features": {
"toolbar": [
{
"id": "my.custom.toolbar.button",
"order": 10,
"title": "Custom action",
"icon": "extension",
"actions": {
"click": "SHOW_MY_DIALOG"
}
}
]
}
}
Now, once you run the application, you should see an extra button that invokes your dialog on every click.