-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate my changes to a possible solution (#1714)
- Loading branch information
Showing
16 changed files
with
331 additions
and
148 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
...rt-angular/projects/client-support-angular/src/lib/component/luigi.preload.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<p>NG Luigi Library Demo Component</p> | ||
|
||
<p> | ||
This is a demo component; in Luigi it is a | ||
<a | ||
href="https://docs.luigi-project.io/docs/navigation-parameters-reference/?section=virtualtree" | ||
>virtual tree</a | ||
>. | ||
<br /> | ||
If you want to configure an Angular Component to be called in virtual tree, | ||
you must use this route configuration: | ||
<br /> | ||
<br /> | ||
<code>{{ routeExampleVirtual }}</code> | ||
</p> | ||
<br /> | ||
|
||
<p> | ||
If you want to configure an Angular Component to be just created once (like a | ||
singleton( you can use this configuration: | ||
<br /> | ||
<br /> | ||
<code>{{ routeExampleReuse }}</code> | ||
</p> |
13 changes: 6 additions & 7 deletions
13
...angular/src/lib/preload.component.spec.ts → ...component/luigi.preload.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...port-angular/projects/client-support-angular/src/lib/component/luigi.preload.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'lib-client-support-angular', | ||
templateUrl: './luigi.preload.component.html', | ||
styles: [] | ||
}) | ||
export class LuigiPreloadComponent implements OnInit { | ||
constructor() {} | ||
routeExampleVirtual: string = | ||
" {path: 'ng-luigi-demo', component: NgLuigiDemoComponent, data: {fromVirtualTreeRoot: true}}"; | ||
routeExampleReuse: string = | ||
" {path: 'ng-luigi-demo', component: NgLuigiDemoComponent, data: {reuse: true}}"; | ||
ngOnInit(): void {} | ||
} |
59 changes: 0 additions & 59 deletions
59
...ent-support-angular/projects/client-support-angular/src/lib/luigi-auto-routing.service.ts
This file was deleted.
Oops, something went wrong.
56 changes: 0 additions & 56 deletions
56
...t/client-support-angular/projects/client-support-angular/src/lib/luigi-context.service.ts
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
...t-support-angular/projects/client-support-angular/src/lib/luigi.angular.support.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { RouteReuseStrategy, RouterModule, Routes } from '@angular/router'; | ||
import { LuigiReuseStrategy } from './route/luigiReuseStrategy'; | ||
import { LuigiPreloadComponent } from './component/luigi.preload.component'; | ||
import { LuigiContextService } from './service/luigi-context-service'; | ||
import { LuigiContextServiceImpl } from './service/luigi-context.service.impl'; | ||
import { LuigiAutoRoutingService } from './service/luigi-auto-routing.service'; | ||
|
||
export const staticRoutes: Routes = [ | ||
/** here an example if you want to specify that this component is a virtualThree element in Luigi Core navigation*/ | ||
{ | ||
path: 'luigi-client-support-preload', | ||
component: LuigiPreloadComponent, | ||
data: { fromVirtualTreeRoot: true } | ||
}, | ||
/** here an example if you want to specify that this component it is a luigi component and u want to change the navigation in Luigi core*/ | ||
{ | ||
path: 'luigi-client-support-preload', | ||
component: LuigiPreloadComponent, | ||
data: { luigiRoute: '/home/reload' } | ||
}, | ||
/** here an example if you want to reuse the component and not recreating every time you navigate to it (a singleton Component) */ | ||
{ | ||
path: 'luigi-client-support-preload=component', | ||
component: LuigiPreloadComponent, | ||
data: { reuse: true } | ||
} | ||
]; | ||
|
||
@NgModule({ | ||
declarations: [LuigiPreloadComponent], | ||
imports: [RouterModule.forChild(staticRoutes)], | ||
providers: [ | ||
{ | ||
provide: LuigiContextService, | ||
useClass: LuigiContextServiceImpl | ||
}, | ||
{ | ||
provide: RouteReuseStrategy, | ||
useClass: LuigiReuseStrategy | ||
} | ||
], | ||
exports: [LuigiPreloadComponent] | ||
}) | ||
export class LuigiAngularSupportModule { | ||
constructor( | ||
navigation: LuigiAutoRoutingService, | ||
context: LuigiContextService | ||
) {} | ||
} |
19 changes: 0 additions & 19 deletions
19
...pport/client-support-angular/projects/client-support-angular/src/lib/preload.component.ts
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
...ojects/client-support-angular/src/lib/route/luigi-activated-route-snapshot-helper.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { LuigiActivatedRouteSnapshotHelper } from './luigi-activated-route-snapshot-helper'; | ||
|
||
describe('NgLuigiActivatedRouteSnapshotService', () => { | ||
it('should create an instance', () => { | ||
expect(new LuigiActivatedRouteSnapshotHelper()).toBeTruthy(); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
...ar/projects/client-support-angular/src/lib/route/luigi-activated-route-snapshot-helper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { ActivatedRouteSnapshot } from '@angular/router'; | ||
|
||
export class LuigiActivatedRouteSnapshotHelper { | ||
private static _current: ActivatedRouteSnapshot; | ||
|
||
static getCurrent(): ActivatedRouteSnapshot { | ||
return this._current; | ||
} | ||
|
||
static setCurrent(current: ActivatedRouteSnapshot) { | ||
this._current = current; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...lient-support-angular/projects/client-support-angular/src/lib/route/luigiReuseStrategy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { | ||
RouteReuseStrategy, | ||
ActivatedRouteSnapshot, | ||
DetachedRouteHandle | ||
} from '@angular/router'; | ||
import { LuigiActivatedRouteSnapshotHelper } from './luigi-activated-route-snapshot-helper'; | ||
|
||
export class LuigiReuseStrategy implements RouteReuseStrategy { | ||
private handlers: { [key: string]: DetachedRouteHandle } = {}; | ||
|
||
shouldDetach(route: ActivatedRouteSnapshot): boolean { | ||
if (!route.routeConfig || route.routeConfig.loadChildren) { | ||
return false; | ||
} | ||
let shouldReuse = false; | ||
console.debug('checking if this route should be re used or not', route); | ||
if (route.routeConfig.data) { | ||
route.routeConfig.data.reuse | ||
? (shouldReuse = true) | ||
: (shouldReuse = false); | ||
} | ||
|
||
return shouldReuse; | ||
} | ||
|
||
store(route: ActivatedRouteSnapshot, handler: DetachedRouteHandle): void { | ||
console.debug('storing handler'); | ||
if (handler) { | ||
this.handlers[this.getUrl(route)] = handler; | ||
} | ||
} | ||
|
||
shouldAttach(route: ActivatedRouteSnapshot): boolean { | ||
console.debug('checking if it should be re attached'); | ||
return !!this.handlers[this.getUrl(route)]; | ||
} | ||
|
||
retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle { | ||
LuigiActivatedRouteSnapshotHelper.setCurrent(route); | ||
if (!route.routeConfig || route.routeConfig.loadChildren) { | ||
return null; | ||
} | ||
|
||
return this.handlers[this.getUrl(route)]; | ||
} | ||
|
||
shouldReuseRoute( | ||
future: ActivatedRouteSnapshot, | ||
current: ActivatedRouteSnapshot | ||
): boolean { | ||
let reUseUrl = false; | ||
if (future.routeConfig) { | ||
if (future.routeConfig.data) { | ||
reUseUrl = future.routeConfig.data.reuse; | ||
} | ||
} | ||
const defaultReuse = future.routeConfig === current.routeConfig; | ||
//return reUseUrl || defaultReuse; | ||
return defaultReuse; | ||
} | ||
|
||
getUrl(route: ActivatedRouteSnapshot): string { | ||
if (route.routeConfig) { | ||
const url = route.routeConfig.path; | ||
console.debug('returning url', url); | ||
return url; | ||
} | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.