Action Handling - ryanteo96/ionic-json-file-browser GitHub Wiki
As Ionic JSON File Browser provides various actions, you would need to write your own action handlers.
| Actions | Description | Argument(s) | Type |
|---|---|---|---|
| Open | Open functionality for the nodes in the tree. | node_id | string[] |
| NewFolder | Create a new folder in the tree. | parent_id folder_name |
string string |
| Rename | Rename node in the tree. | node_id new_name |
string string |
| Download | Download one/more node in the tree. | node_id | string[] |
| Upload | Upload files to the tree | parent_id | string |
| Delete | Delete one/more node in the tree. | node_id | string[] |
| Properties | Properties of one/more nodes in the tree. | node_id | string[] |
We would need to import several modules and also creating a handler module.
app.module.ts:
import { HandlerModule } from './handler.module';
import { OpenHandler } from './open.handler';
@NgModule({
imports: [
...
HandlerModule.forRoot([OpenHandler]),
...
]
})handler.module.ts:
import { NgModule, ModuleWithProviders, APP_INITIALIZER } from '@angular/core';
import { NgxsModule } from '@ngxs/store';
const noopFactory = () => {
return (): Promise<void> => {
return Promise.resolve();
}
}
@NgModule({
imports:[
NgxsModule,
]
})
export class HandlerModule {
static forRoot(handlers: any[] = []): ModuleWithProviders {
return {
ngModule: HandlerModule,
providers: [
...handlers,
{
provide: APP_INITIALIZER,
multi: true,
useFactory: noopFactory,
deps: handlers
}
]
};
}
}open.handler.ts:
import { Injectable } from '@angular/core';
import { Actions, ofActionSuccessful } from '@ngxs/store';
import { Open } from 'ionic-json-file-browser';
@Injectable()
export class OpenHandler {
constructor(private actions$: Actions) {
console.log('open handler created');
this.actions$.pipe(
ofActionSuccessful(Open)
).subscribe(({ node_id }) => {
// substitute this with your own implementation
console.log('Open handled via OpenHandler');
console.log(node_id);
})
}
}