Commit 514ea590 authored by Tifenn Guillas's avatar Tifenn Guillas
Browse files

Display navifation option depending on instance config => DONE

parent 7eece4bd
Pipeline #3139 canceled with stages
in 1 minute and 19 seconds
......@@ -12,17 +12,17 @@
<span class="fas fa-home"></span> Home
</a>
</li>
<li class="nav-item">
<li *ngIf="isSearchAllowed()" class="nav-item">
<a class="nav-link" routerLink="/search" routerLinkActive="active">
<span class="fas fa-search"></span> Search
</a>
</li>
<li class="nav-item">
<li *ngIf="isSearchMultipleAllowed()" class="nav-item">
<a class="nav-link" routerLink="/search-multiple" routerLinkActive="active">
<span class="fas fa-search-plus"></span> Search multiple
</a>
</li>
<li class="nav-item">
<li *ngIf="isDocumentationAllowed()" class="nav-item">
<a class="nav-link" routerLink="/documentation" routerLinkActive="active">
<span class="fas fa-question"></span> Documentation
</a>
......@@ -79,17 +79,17 @@
<span class="fas fa-home fa-fw"></span> Home
</a>
</li>
<li role="menuitem">
<li *ngIf="isSearchAllowed()" role="menuitem">
<a class="dropdown-item" routerLink="/search">
<span class="fas fa-search fa-fw"></span> Search
</a>
</li>
<li role="menuitem">
<li *ngIf="isSearchMultipleAllowed()" role="menuitem">
<a class="dropdown-item" routerLink="/search-multiple">
<span class="fas fa-search-plus fa-fw"></span> Search multiple
</a>
</li>
<li role="menuitem">
<li *ngIf="isDocumentationAllowed()" role="menuitem">
<a class="dropdown-item" routerLink="/documentation">
<span class="fas fa-question fa-fw"></span> Documentation
</a>
......
import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy } from '@angular/core';
import { LoginToken } from '../../login/store/model';
import { Instance } from '../../metamodel/model';
import { environment } from '../../../environments/environment'
@Component({
......@@ -12,9 +13,31 @@ import { environment } from '../../../environments/environment'
export class NavComponent {
@Input() isAuthenticated: boolean;
@Input() loginToken: LoginToken;
@Input() instance: Instance;
@Output() logout: EventEmitter<any> = new EventEmitter();
baseHref: string = environment.baseHref;
isSearchAllowed(): boolean {
if (this.instance && this.instance.config.search) {
return this.instance.config.search;
}
return false;
}
isSearchMultipleAllowed(): boolean {
if (this.instance && this.instance.config.search_multiple) {
return this.instance.config.search_multiple;
}
return false;
}
isDocumentationAllowed(): boolean {
if (this.instance && this.instance.config.documentation) {
return this.instance.config.documentation;
}
return false;
}
emitLogout() {
this.logout.emit();
}
......
<header>
<app-nav [isAuthenticated]="isAuthenticated | async" [loginToken]="loginToken | async" (logout)="logout()">
<app-nav
[isAuthenticated]="isAuthenticated | async"
[loginToken]="loginToken | async"
[instance]="instance | async"
(logout)="logout()">
</app-nav>
</header>
<main role="main" class="container-fluid pb-4">
......
......@@ -3,12 +3,21 @@ import { Component, ViewEncapsulation, OnInit } from '@angular/core';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs';
import * as loginReducer from '../../login/store/login.reducer';
import * as fromLogin from '../../login/store/login.reducer';
import * as loginActions from '../../login/store/login.action';
import * as loginSelector from '../../login/store/login.selector';
import { LoginToken } from '../../login/store/model';
import * as fromMetamodel from '../../metamodel/reducers';
import * as instanceActions from '../../metamodel/action/instance.action';
import * as metamodelSelector from '../../metamodel/selectors';
import { Instance } from '../../metamodel/model';
import { VERSIONS } from '../../../settings/settings';
interface StoreState {
login: fromLogin.State;
metamodel: fromMetamodel.State;
}
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
......@@ -20,14 +29,17 @@ export class AppComponent implements OnInit {
year = (new Date()).getFullYear();
isAuthenticated: Observable<boolean>;
loginToken: Observable<LoginToken>;
instance: Observable<Instance>;
constructor(private store: Store<loginReducer.State>) {
constructor(private store: Store<StoreState>) {
this.isAuthenticated = store.select(loginSelector.isAuthenticated);
this.loginToken = store.select(loginSelector.getLoginToken);
this.instance = store.select(metamodelSelector.getInstance);
}
ngOnInit() {
this.store.dispatch(new loginActions.LoginLocalStorageAction());
this.store.dispatch(new instanceActions.LoadInstanceMetaAction());
}
logout(): void {
......
import { Action } from '@ngrx/store';
import { Instance } from '../model';
export const LOAD_INSTANCE_META = '[Instance] Load Instance Meta';
export const LOAD_INSTANCE_META_SUCCESS = '[Instance] Load Instance Meta Success';
export const LOAD_INSTANCE_META_FAIL = '[Instance] Load Instance Meta Fail';
export class LoadInstanceMetaAction implements Action {
readonly type = LOAD_INSTANCE_META;
constructor(public payload: {} = null) { }
}
export class LoadInstanceMetaSuccessAction implements Action {
readonly type = LOAD_INSTANCE_META_SUCCESS;
constructor(public payload: Instance) { }
}
export class LoadInstanceMetaFailAction implements Action {
readonly type = LOAD_INSTANCE_META_FAIL;
constructor(public payload: {} = null) { }
}
export type Actions
= LoadInstanceMetaAction
| LoadInstanceMetaSuccessAction
| LoadInstanceMetaFailAction;
import { AttributeEffects } from './attribute.effects';
import { InstanceEffects } from './instance.effects';
import { DatasetEffects } from './dataset.effects';
import { AttributeEffects } from './attribute.effects';
import { CriteriaEffects } from './criteria.effects';
import { OutputEffects } from './output.effects';
export const effects = [
AttributeEffects,
InstanceEffects,
DatasetEffects,
AttributeEffects,
CriteriaEffects,
OutputEffects
];
import { Injectable } from '@angular/core';
import { ToastrService } from 'ngx-toastr';
import { Effect, Actions, ofType } from '@ngrx/effects';
import { of } from 'rxjs';
import { switchMap, map, catchError, tap } from 'rxjs/operators';
import { Instance } from '../model';
import * as instanceActions from '../action/instance.action';
import { InstanceService } from '../services/instance.service';
@Injectable()
export class InstanceEffects {
constructor(
private actions$: Actions,
private instanceService: InstanceService,
private toastr: ToastrService
) { }
@Effect()
loadInstanceMetaAction$ = this.actions$.pipe(
ofType(instanceActions.LOAD_INSTANCE_META),
switchMap(_ =>
this.instanceService.retrieveInstanceMeta().pipe(
map((instanceMeta: Instance) =>
new instanceActions.LoadInstanceMetaSuccessAction(instanceMeta)),
catchError(() => of(new instanceActions.LoadInstanceMetaFailAction()))
)
)
);
@Effect({ dispatch: false })
loadInstanceMetaFailedAction$ = this.actions$.pipe(
ofType(instanceActions.LOAD_INSTANCE_META_FAIL),
tap(_ => this.toastr.error('Loading Failed!', 'Instance meta loading failed'))
);
}
export * from './instance.model';
export * from './family.model';
export * from './category.model';
export * from './dataset.model';
......
export interface Instance {
name: string;
label: string;
client_url: string;
nb_dataset_families: number;
nb_datasets: number;
config: {
search: boolean;
search_multiple: boolean;
documentation: boolean;
};
}
import { combineReducers, createFeatureSelector } from '@ngrx/store';
import * as attribute from './attribute.reducer';
import * as instance from './instance.reducer';
import * as dataset from './dataset.reducer';
import * as attribute from './attribute.reducer';
import * as criteria from './criteria.reducer';
import * as output from './output.reducer';
export interface State {
attribute: attribute.State;
instance: instance.State;
dataset: dataset.State;
attribute: attribute.State;
criteria: criteria.State;
output: output.State;
}
const reducers = {
attribute: attribute.reducer,
instance: instance.reducer,
dataset: dataset.reducer,
attribute: attribute.reducer,
criteria: criteria.reducer,
output: output.reducer
};
......
import * as actions from '../action/instance.action';
import { Instance } from '../model';
export interface State {
instance: Instance;
}
export const initialState: State = {
instance: null
};
export function reducer(state: State = initialState, action: actions.Actions): State {
switch (action.type) {
// case actions.LOAD_DATASET_SEARCH_META_WIP:
// return {
// ...state,
// datasetSearchMetaIsLoading: true
// };
case actions.LOAD_INSTANCE_META_SUCCESS:
return {
...state,
instance: action.payload
};
// case actions.LOAD_DATASET_SEARCH_META_FAIL:
// return {
// ...state,
// datasetSearchMetaIsLoading: false
// };
default:
return state;
}
}
// export const getDatasetSearchMetaIsLoading = (state: State) => state.datasetSearchMetaIsLoading;
// export const getDatasetSearchMetaIsLoaded = (state: State) => state.datasetSearchMetaIsLoaded;
export const getInstance = (state: State) => state.instance;
export * from './attribute.selector';
export * from './instance.selector';
export * from './dataset.selector';
export * from './attribute.selector';
export * from './criteria.selector';
export * from './output.selector';
import { createSelector } from '@ngrx/store';
import * as metamodel from '../reducers';
import * as instance from '../reducers/instance.reducer';
export const getInstanceState = createSelector(
metamodel.getMetamodelState,
(state: metamodel.State) => state.instance
);
// export const getInstanceMetaIsLoading = createSelector(
// getDatasetState,
// dataset.getDatasetSearchMetaIsLoading
// );
//
// export const getDatasetSearchMetaIsLoaded = createSelector(
// getDatasetState,
// dataset.getDatasetSearchMetaIsLoaded
// );
export const getInstance = createSelector(
getInstanceState,
instance.getInstance
);
import { AttributeService } from './attribute.service';
import { InstanceService } from './instance.service';
import { DatasetService } from './dataset.service';
import { AttributeService } from './attribute.service';
import { CriteriaService } from './criteria.service';
import { OutputService } from './output.service';
export const services = [
AttributeService,
InstanceService,
DatasetService,
AttributeService,
CriteriaService,
OutputService
];
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Instance } from '../model';
import { environment } from '../../../environments/environment';
@Injectable()
export class InstanceService {
private API_PATH: string = environment.apiUrl;
private instanceName: string = environment.instanceName;
constructor(private http: HttpClient) { }
retrieveInstanceMeta() {
return this.http.get<Instance>(this.API_PATH + '/instance/' + this.instanceName);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment