mirror of
https://github.com/richard-loafle/fuse-angular.git
synced 2025-04-21 07:38:10 +00:00
83 lines
2.5 KiB
TypeScript
83 lines
2.5 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot } from '@angular/router';
|
|
import { Observable, throwError } from 'rxjs';
|
|
import { catchError } from 'rxjs/operators';
|
|
import { FileManagerService } from 'app/modules/admin/apps/file-manager/file-manager.service';
|
|
import { Item } from 'app/modules/admin/apps/file-manager/file-manager.types';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class FileManagerItemsResolver implements Resolve<any>
|
|
{
|
|
/**
|
|
* Constructor
|
|
*/
|
|
constructor(private _fileManagerService: FileManagerService)
|
|
{
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------------------------------
|
|
// @ Public methods
|
|
// -----------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* Resolver
|
|
*
|
|
* @param route
|
|
* @param state
|
|
*/
|
|
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Item[]>
|
|
{
|
|
return this._fileManagerService.getItems();
|
|
}
|
|
}
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class FileManagerItemResolver implements Resolve<any>
|
|
{
|
|
/**
|
|
* Constructor
|
|
*/
|
|
constructor(
|
|
private _router: Router,
|
|
private _fileManagerService: FileManagerService
|
|
)
|
|
{
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------------------------------
|
|
// @ Public methods
|
|
// -----------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* Resolver
|
|
*
|
|
* @param route
|
|
* @param state
|
|
*/
|
|
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Item>
|
|
{
|
|
return this._fileManagerService.getItemById(route.paramMap.get('id'))
|
|
.pipe(
|
|
// Error here means the requested task is not available
|
|
catchError((error) => {
|
|
|
|
// Log the error
|
|
console.error(error);
|
|
|
|
// Get the parent url
|
|
const parentUrl = state.url.split('/').slice(0, -1).join('/');
|
|
|
|
// Navigate to there
|
|
this._router.navigateByUrl(parentUrl);
|
|
|
|
// Throw an error
|
|
return throwError(error);
|
|
})
|
|
);
|
|
}
|
|
}
|