Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
anis
anis-client
Commits
14c4b7e6
Commit
14c4b7e6
authored
Oct 23, 2020
by
Tifenn Guillas
Browse files
WIP: Implements navigation guard
parent
20084a95
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/app/app-routing.module.ts
View file @
14c4b7e6
import
{
NgModule
}
from
'
@angular/core
'
;
import
{
Routes
,
RouterModule
,
PreloadAllModules
}
from
'
@angular/router
'
;
import
{
NavigationGuard
}
from
'
./core/navigation.guard
'
;
import
{
NotFoundPageComponent
}
from
'
./core/containers/not-found-page.component
'
;
const
routes
:
Routes
=
[
{
path
:
''
,
redirectTo
:
'
home
'
,
pathMatch
:
'
full
'
},
{
path
:
'
search
'
,
loadChildren
:
()
=>
import
(
'
./search/search.module
'
).
then
(
m
=>
m
.
SearchModule
)
loadChildren
:
()
=>
import
(
'
./search/search.module
'
).
then
(
m
=>
m
.
SearchModule
),
canLoad
:
[
NavigationGuard
]
},
{
path
:
'
search-multiple
'
,
...
...
src/app/core/navigation.guard.spec.ts
0 → 100644
View file @
14c4b7e6
import
{
TestBed
}
from
'
@angular/core/testing
'
;
import
{
NavigationGuard
}
from
'
./navigation.guard
'
;
describe
(
'
NavigationGuardGuard
'
,
()
=>
{
let
guard
:
NavigationGuard
;
beforeEach
(()
=>
{
TestBed
.
configureTestingModule
({});
guard
=
TestBed
.
inject
(
NavigationGuard
);
});
it
(
'
should be created
'
,
()
=>
{
expect
(
guard
).
toBeTruthy
();
});
});
src/app/core/navigation.guard.ts
0 → 100644
View file @
14c4b7e6
import
{
Injectable
}
from
'
@angular/core
'
;
import
{
CanLoad
,
Route
,
UrlSegment
}
from
'
@angular/router
'
;
import
{
Observable
,
of
}
from
'
rxjs
'
;
import
{
map
,
switchMap
}
from
'
rxjs/operators
'
;
import
{
Actions
}
from
'
@ngrx/effects
'
;
import
{
SearchService
}
from
'
../search/store/search.service
'
;
import
{
ToastrService
}
from
'
ngx-toastr
'
;
import
{
Store
}
from
'
@ngrx/store
'
;
import
*
as
fromRouter
from
'
@ngrx/router-store
'
;
import
*
as
utils
from
'
../shared/utils
'
;
import
*
as
fromSearch
from
'
../search/store/search.reducer
'
;
import
*
as
fromMetamodel
from
'
../metamodel/reducers
'
;
import
*
as
fromConeSearch
from
'
../shared/cone-search/store/cone-search.reducer
'
;
import
{
Instance
}
from
'
../metamodel/model
'
;
@
Injectable
({
providedIn
:
'
root
'
})
export
class
NavigationGuard
implements
CanLoad
{
constructor
(
private
store$
:
Store
<
{
metamodel
:
fromMetamodel
.
State
}
>
)
{
}
canLoad
(
route
:
Route
,
segments
:
UrlSegment
[]):
Observable
<
boolean
>
|
Promise
<
boolean
>
|
boolean
{
// console.error(route.path);
switch
(
route
.
path
)
{
case
'
search
'
:
console
.
error
(
this
.
isSearchAllowed
());
return
this
.
isSearchAllowed
();
break
;
// default:
// return false;
}
}
waitForDataToLoad
():
Observable
<
Instance
>
{
return
this
.
store$
.
select
(
state
=>
state
.
metamodel
.
instance
.
instance
);
}
isSearchAllowed
():
Observable
<
boolean
>
{
return
this
.
waitForDataToLoad
().
pipe
(
switchMap
(
instance
=>
{
// console.error(instance.config.search);
return
of
(
instance
.
config
.
search
);
})
)
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment