-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SHIBUI-814 Integrated with rest endpoint for messages
- Loading branch information
Showing
12 changed files
with
266 additions
and
9 deletions.
There are no files selected for viewing
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,11 @@ | ||
action.dashboard=Dashboard (en-US) | ||
action.logout=Logout | ||
action.add-new=Add New | ||
action.clear=Clear | ||
|
||
label.metadata-sources=Metadata Sources | ||
label.metadata-source=Metadata Source | ||
label.metadata-providers=Metadata Providers | ||
label.metadata-provider=Metadata Provider | ||
label.source-management=Source Management | ||
label.search-files=Search Files |
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 |
---|---|---|
@@ -1 +1,11 @@ | ||
a.sample.message=This is a sample message. | ||
action.dashboard=Dashboard (en) | ||
action.logout=Logout | ||
action.add-new=Add New | ||
action.clear=Clear | ||
|
||
label.metadata-sources=Metadata Sources | ||
label.metadata-source=Metadata Source | ||
label.metadata-providers=Metadata Providers | ||
label.metadata-provider=Metadata Provider | ||
label.source-management=Source Management | ||
label.search-files=Search Files |
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
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
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,39 @@ | ||
import { Action } from '@ngrx/store'; | ||
|
||
export enum MessagesActionTypes { | ||
MESSAGES_LOAD_REQUEST = '[Messages] Load REQUEST', | ||
MESSAGES_LOAD_SUCCESS = '[Messages] Load SUCCESS', | ||
MESSAGES_LOAD_ERROR = '[Messages] Load ERROR', | ||
|
||
SET_LANGUAGE = '[Messages] Set Language' | ||
} | ||
|
||
export class MessagesLoadRequestAction implements Action { | ||
readonly type = MessagesActionTypes.MESSAGES_LOAD_REQUEST; | ||
|
||
constructor() { } | ||
} | ||
|
||
export class MessagesLoadSuccessAction implements Action { | ||
readonly type = MessagesActionTypes.MESSAGES_LOAD_SUCCESS; | ||
|
||
constructor(public payload: any) { } | ||
} | ||
|
||
export class MessagesLoadErrorAction implements Action { | ||
readonly type = MessagesActionTypes.MESSAGES_LOAD_ERROR; | ||
|
||
constructor(public payload: { message: string, type: string }) { } | ||
} | ||
|
||
export class SetLanguage implements Action { | ||
readonly type = MessagesActionTypes.SET_LANGUAGE; | ||
|
||
constructor(public payload: string) {} | ||
} | ||
|
||
export type Actions = | ||
| MessagesLoadRequestAction | ||
| MessagesLoadSuccessAction | ||
| MessagesLoadErrorAction | ||
| SetLanguage; |
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
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,45 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Effect, Actions, ofType } from '@ngrx/effects'; | ||
|
||
import { of } from 'rxjs'; | ||
import { map, catchError, switchMap, withLatestFrom } from 'rxjs/operators'; | ||
|
||
import { | ||
MessagesActionTypes, | ||
MessagesLoadErrorAction, | ||
MessagesLoadRequestAction, | ||
MessagesLoadSuccessAction, | ||
SetLanguage | ||
} from '../action/message.action'; | ||
import { I18nService } from '../service/i18n.service'; | ||
import * as fromCore from '../reducer'; | ||
import { Store } from '@ngrx/store'; | ||
|
||
@Injectable() | ||
export class MessageEffects { | ||
|
||
@Effect() | ||
loadMessages$ = this.actions$.pipe( | ||
ofType<MessagesLoadRequestAction>(MessagesActionTypes.MESSAGES_LOAD_REQUEST), | ||
withLatestFrom(this.store.select(fromCore.getLanguage)), | ||
switchMap(([action, lang]) => { | ||
return this.i18nService.get(lang) | ||
.pipe( | ||
map(u => new MessagesLoadSuccessAction({ ...u })), | ||
catchError(error => of(new MessagesLoadErrorAction(error))) | ||
); | ||
}) | ||
); | ||
@Effect() | ||
setLanguage$ = this.actions$.pipe( | ||
ofType<SetLanguage>(MessagesActionTypes.SET_LANGUAGE), | ||
map(action => action.payload), | ||
map(language => new MessagesLoadRequestAction()) | ||
); | ||
|
||
constructor( | ||
private i18nService: I18nService, | ||
private actions$: Actions, | ||
private store: Store<fromCore.State> | ||
) { } | ||
} |
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
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
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,60 @@ | ||
import { | ||
MessagesActionTypes, | ||
Actions, | ||
|
||
} from '../action/message.action'; | ||
|
||
export interface MessageState { | ||
fetching: boolean; | ||
messages: any; | ||
error: any; | ||
language: string; | ||
} | ||
|
||
export const initialState: MessageState = { | ||
fetching: false, | ||
messages: null, | ||
error: null, | ||
language: 'en' | ||
}; | ||
|
||
export function reducer(state = initialState, action: Actions): MessageState { | ||
switch (action.type) { | ||
case MessagesActionTypes.MESSAGES_LOAD_REQUEST: { | ||
return { | ||
...state, | ||
fetching: true | ||
}; | ||
} | ||
case MessagesActionTypes.MESSAGES_LOAD_SUCCESS: { | ||
return { | ||
...state, | ||
fetching: false, | ||
messages: action.payload | ||
}; | ||
} | ||
case MessagesActionTypes.MESSAGES_LOAD_ERROR: { | ||
return { | ||
...state, | ||
fetching: false, | ||
messages: null, | ||
error: action.payload | ||
}; | ||
} | ||
case MessagesActionTypes.SET_LANGUAGE: { | ||
return { | ||
...state, | ||
language: action.payload | ||
}; | ||
} | ||
default: { | ||
return state; | ||
} | ||
} | ||
} | ||
|
||
|
||
export const getMessages = (state: MessageState) => state.messages; | ||
export const getLanguage = (state: MessageState) => state.language; | ||
export const getError = (state: MessageState) => state.error; | ||
export const isFetching = (state: MessageState) => state.fetching; |
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,31 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
import { HttpClient, HttpParams } from '@angular/common/http'; | ||
import { NavigatorService } from './navigator.service'; | ||
import { getCurrentLanguage } from '../../shared/util'; | ||
|
||
@Injectable() | ||
export class I18nService { | ||
|
||
readonly path = '/messages'; | ||
readonly base = '/api'; | ||
|
||
constructor( | ||
private http: HttpClient, | ||
private navigator: NavigatorService | ||
) {} | ||
|
||
get(language: string = null): Observable<any> { | ||
let params: HttpParams = new HttpParams(); | ||
if (!!language) { | ||
params = params.set('lang', language); | ||
} | ||
return this.http.get(`${ this.base }${this.path}`, { | ||
params | ||
}); | ||
} | ||
|
||
getCurrentLanguage(): string { | ||
return getCurrentLanguage(this.navigator.native); | ||
} | ||
} |
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