refactoring of state

This commit is contained in:
병준 박 2019-10-04 13:45:02 +09:00
parent 50152c5907
commit 1f2687189a
32 changed files with 250 additions and 165 deletions

View File

@ -1 +1 @@
<ucap-organization-expansion-panel></ucap-organization-expansion-panel>
<ucap-organization-tree></ucap-organization-tree>

View File

@ -3,6 +3,8 @@ import { CommonModule } from '@angular/common';
import { FlexLayoutModule } from '@angular/flex-layout';
import { MatButtonModule } from '@angular/material/button';
import { UCapUiAccountModule } from '@ucap-webmessenger/ui-account';
import { AppAccountRoutingPageModule } from './account-routing.page.module';
@ -13,6 +15,7 @@ import { COMPONENTS } from './components';
imports: [
CommonModule,
FlexLayoutModule,
MatButtonModule,
UCapUiAccountModule,
AppAccountRoutingPageModule
],

View File

@ -1,6 +1,19 @@
<div class="login" fxLayout="column">
<div class="login-wrapper" fxLayout="column" fxLayoutAlign="center center">
<ucap-account-login [companyList]="companyList$ | async" (login)="onLogin($event)" (template)="onTemplate($event)">
<ucap-account-login
[companyList]="companyList$ | async"
(login)="onLogin($event)"
>
</ucap-account-login>
</div>
<button
mat-raised-button
color="accent"
class="submit-button"
aria-label="Template"
(click)="onClickTemplate()"
>
Template
</button>
</div>

View File

@ -52,7 +52,7 @@ export class LoginPageComponent implements OnInit {
);
}
onTemplate() {
onClickTemplate() {
this.router.navigate(['/template']);
}
}

View File

@ -1,11 +1,32 @@
<div>
<div fxLayout="column">
<button
mat-raised-button
color="accent"
class="submit-button"
aria-label="Login"
(click)="onClickLogin()"
>
Login
</button>
<h3>User-list-item</h3>
<div>
<ucap-profile-user-list-item [userInfo]="userInfo" [profileImageRoot]="profileImageRoot" [presence]='presence'>
<ucap-profile-user-list-item
[userInfo]="userInfo"
[profileImageRoot]="profileImageRoot"
[presence]="presence"
>
</ucap-profile-user-list-item>
<ucap-profile-user-list-item [userInfo]="userInfo" [profileImageRoot]="profileImageRoot">
<ucap-profile-user-list-item
[userInfo]="userInfo"
[profileImageRoot]="profileImageRoot"
>
</ucap-profile-user-list-item>
<ucap-profile-user-list-item [userInfo]="userInfo" [profileImageRoot]="profileImageRoot" [checkable]='true'>
<ucap-profile-user-list-item
[userInfo]="userInfo"
[profileImageRoot]="profileImageRoot"
[checkable]="true"
>
</ucap-profile-user-list-item>
</div>
</div>

View File

@ -8,6 +8,7 @@ import {
TerminalStatusNumber
} from '@ucap-webmessenger/protocol-status';
import { StatusCode } from '@ucap-webmessenger/core';
import { Router } from '@angular/router';
@Component({
selector: 'app-template.page',
@ -21,9 +22,13 @@ export class TemplatePageComponent implements OnInit {
presence: StatusBulkInfo = status;
constructor() {}
constructor(private router: Router) {}
ngOnInit() {}
onClickLogin() {
this.router.navigate(['/account/login']);
}
}
export const status: StatusBulkInfo = {

View File

@ -3,6 +3,8 @@ import { CommonModule } from '@angular/common';
import { FlexLayoutModule } from '@angular/flex-layout';
import { MatButtonModule } from '@angular/material/button';
import { UCapUiGroupModule } from '@ucap-webmessenger/ui-group';
import { AppTemplateRoutingPageModule } from './template-routing.page.module';
@ -15,6 +17,7 @@ import { UcapUiProfileModule } from '@ucap-webmessenger/ui-profile';
...MET_MODULES,
CommonModule,
FlexLayoutModule,
MatButtonModule,
UCapUiGroupModule,
UcapUiProfileModule,
AppTemplateRoutingPageModule

View File

@ -25,7 +25,7 @@ import {
KEY_LOGIN_INFO,
EnvironmentsInfo,
KEY_ENVIRONMENTS_INFO
} from '../types';
} from '@app/types';
import { InnerProtocolService } from '@ucap-webmessenger/protocol-inner';
import {
AuthenticationProtocolService,
@ -40,8 +40,8 @@ import { OptionProtocolService } from '@ucap-webmessenger/protocol-option';
import * as AppStore from '@app/store';
import * as VersionInfoStore from '@app/store/setting/version-info';
import * as OptionStore from '@app/store/setting/option';
import * as QueryStore from '@app/store/setting/query';
import * as OptionStore from '@app/store/messenger/option';
import * as QueryStore from '@app/store/messenger/query';
import * as SyncStore from '@app/store/messenger/sync';
@Injectable()
@ -124,7 +124,7 @@ export class AppMessengerResolver implements Resolve<void> {
);
this.store.dispatch(QueryStore.authSuccess({ res: authRes }));
this.store.dispatch(AuthenticationStore.postLogin({ loginRes }));
// this.store.dispatch(AuthenticationStore.postLogin({ loginRes }));
}),
withLatestFrom(
this.store.pipe(
@ -146,6 +146,12 @@ export class AppMessengerResolver implements Resolve<void> {
localeCode: loginInfo.localeCode
})
);
this.store.dispatch(
QueryStore.dept({
divCd: 'ORG',
companyCode: loginInfo.companyCode
})
);
}),
catchError(err => {
return throwError(err);

View File

@ -2,17 +2,23 @@ import { Type } from '@angular/core';
import { Action, combineReducers, Selector, createSelector } from '@ngrx/store';
import * as ChatStore from './chat';
import * as OptionStore from './option';
import * as QueryStore from './query';
import * as StatusStore from './status';
import * as SyncStore from './sync';
export interface State {
chat: ChatStore.State;
option: OptionStore.State;
query: QueryStore.State;
status: StatusStore.State;
sync: SyncStore.State;
}
export const effects: Type<any>[] = [
ChatStore.Effects,
OptionStore.Effects,
QueryStore.Effects,
StatusStore.Effects,
SyncStore.Effects
];
@ -20,6 +26,8 @@ export const effects: Type<any>[] = [
export function reducers(state: State | undefined, action: Action) {
return combineReducers({
chat: ChatStore.reducer,
option: OptionStore.reducer,
query: QueryStore.reducer,
status: StatusStore.reducer,
sync: SyncStore.reducer
})(state, action);
@ -33,6 +41,18 @@ export function selectors<S>(selector: Selector<any, State>) {
(state: State) => state.chat
)
),
OptionSelector: OptionStore.selectors(
createSelector(
selector,
(state: State) => state.option
)
),
QuerySelector: QueryStore.selectors(
createSelector(
selector,
(state: State) => state.query
)
),
StatusSelector: StatusStore.selectors(
createSelector(
selector,

View File

@ -8,31 +8,31 @@ import {
} from '@ucap-webmessenger/protocol-option';
export const regView = createAction(
'[Setting::Option] RegView',
'[Messenger::Option] RegView',
props<RegViewRequest>()
);
export const regViewSuccess = createAction(
'[Setting::Option] RegView Success',
'[Messenger::Option] RegView Success',
props<{ res: RegViewResponse }>()
);
export const regViewFailure = createAction(
'[Setting::Option] RegView Failure',
'[Messenger::Option] RegView Failure',
props<{ error: any }>()
);
export const regUpdate = createAction(
'[Setting::Option] RegUpdate',
'[Messenger::Option] RegUpdate',
props<RegUpdateRequest>()
);
export const regUpdateSuccess = createAction(
'[Setting::Option] RegUpdate Success',
'[Messenger::Option] RegUpdate Success',
props<{ res: RegUpdateResponse }>()
);
export const regUpdateFailure = createAction(
'[Setting::Option] RegUpdate Failure',
'[Messenger::Option] RegUpdate Failure',
props<{ error: any }>()
);

View File

@ -6,24 +6,12 @@ import { of } from 'rxjs';
import { catchError, exhaustMap, map, tap } from 'rxjs/operators';
import { regViewSuccess, regViewFailure } from './actions';
import { initSettings } from '../init';
import { OptionProtocolService } from '@ucap-webmessenger/protocol-option';
import { loginSuccess } from '@app/store/account/authentication';
@Injectable()
export class Effects {
// initSettings$ = createEffect(() =>
// this.actions$.pipe(
// ofType(loginSuccess),
// exhaustMap(() =>
// this.optionProtocolService.regView({}).pipe(
// map(res => regViewSuccess({ res })),
// catchError(error => of(regViewFailure({ error })))
// )
// )
// )
// );
constructor(
private actions$: Actions,
private optionProtocolService: OptionProtocolService

View File

@ -1,7 +1,6 @@
import { Selector, createSelector } from '@ngrx/store';
import { RegViewResponse } from '@ucap-webmessenger/protocol-option';
// tslint:disable-next-line: no-empty-interface
export interface State {
reg?: RegViewResponse;
}

View File

@ -0,0 +1,38 @@
import { createAction, props } from '@ngrx/store';
import {
AuthRequest,
AuthResponse,
DeptRequest,
DeptInfo
} from '@ucap-webmessenger/protocol-query';
export const auth = createAction(
'[Messenger::Query] Auth',
props<AuthRequest>()
);
export const authSuccess = createAction(
'[Messenger::Query] Auth Success',
props<{ res: AuthResponse }>()
);
export const authFailure = createAction(
'[Messenger::Query] Auth Failure',
props<{ error: any }>()
);
export const dept = createAction(
'[Messenger::Query] Dept',
props<DeptRequest>()
);
export const deptSuccess = createAction(
'[Messenger::Query] Dept Success',
props<{ departmentInfoList: DeptInfo[] }>()
);
export const deptFailure = createAction(
'[Messenger::Query] Dept Failure',
props<{ error: any }>()
);

View File

@ -0,0 +1,62 @@
import { Injectable } from '@angular/core';
import { Actions, ofType, createEffect } from '@ngrx/effects';
import { of } from 'rxjs';
import { catchError, map, tap, switchMap } from 'rxjs/operators';
import { dept, deptSuccess, deptFailure } from './actions';
import {
QueryProtocolService,
DeptInfo,
SSVC_TYPE_QUERY_DEPT_DATA,
SSVC_TYPE_QUERY_DEPT_RES,
DeptData
} from '@ucap-webmessenger/protocol-query';
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
import { Store } from '@ngrx/store';
@Injectable()
export class Effects {
dept$ = createEffect(
() => {
let departmentInfoList: DeptInfo[];
return this.actions$.pipe(
ofType(dept),
tap(() => {
departmentInfoList = [];
}),
switchMap(req => {
return this.queryProtocolService.dept(req).pipe(
map(res => {
switch (res.Type) {
case SSVC_TYPE_QUERY_DEPT_DATA:
departmentInfoList.push(...(res as DeptData).departmentInfos);
break;
case SSVC_TYPE_QUERY_DEPT_RES:
this.store.dispatch(
deptSuccess({
departmentInfoList
})
);
break;
}
}),
catchError(error => of(deptFailure({ error })))
);
})
);
},
{ dispatch: false }
);
constructor(
private actions$: Actions,
private store: Store<any>,
private sessionStorageService: SessionStorageService,
private queryProtocolService: QueryProtocolService
) {}
}

View File

@ -1,6 +1,6 @@
import { createReducer, on } from '@ngrx/store';
import { initialState } from './state';
import { authSuccess } from './actions';
import { authSuccess, deptSuccess } from './actions';
export const reducer = createReducer(
initialState,
@ -9,5 +9,12 @@ export const reducer = createReducer(
...state,
auth: action.res
};
}),
on(deptSuccess, (state, action) => {
return {
...state,
departmentInfoList: action.departmentInfoList
};
})
);

View File

@ -1,12 +1,15 @@
import { Selector, createSelector } from '@ngrx/store';
import { AuthResponse } from '@ucap-webmessenger/protocol-query';
import { AuthResponse, DeptInfo } from '@ucap-webmessenger/protocol-query';
export interface State {
auth?: AuthResponse;
departmentInfoList: DeptInfo[] | null;
}
export const initialState: State = {
auth: null
auth: null,
departmentInfoList: null
};
export function selectors<S>(selector: Selector<any, State>) {
@ -14,6 +17,10 @@ export function selectors<S>(selector: Selector<any, State>) {
auth: createSelector(
selector,
(state: State) => state.auth
),
departmentInfoList: createSelector(
selector,
(state: State) => state.departmentInfoList
)
};
}

View File

@ -49,7 +49,7 @@ import {
RoomUserDetailData,
RoomResponse
} from '@ucap-webmessenger/protocol-sync';
import { regViewSuccess } from '@app/store/setting/option';
import { regViewSuccess } from '@app/store/messenger/option';
import {
RoomInfo,
UserInfoShort,

View File

@ -3,23 +3,17 @@ import { Action, combineReducers, Selector, createSelector } from '@ngrx/store';
import * as CompanyStore from './company';
import * as InitStore from './init';
import * as OptionStore from './option';
import * as QueryStore from './query';
import * as VersionInfoStore from './version-info';
export interface State {
company: CompanyStore.State;
init: InitStore.State;
option: OptionStore.State;
query: QueryStore.State;
versionInfo: VersionInfoStore.State;
}
export const effects: Type<any>[] = [
CompanyStore.Effects,
InitStore.Effects,
OptionStore.Effects,
QueryStore.Effects,
VersionInfoStore.Effects
];
@ -27,8 +21,6 @@ export function reducers(state: State | undefined, action: Action) {
return combineReducers({
company: CompanyStore.reducer,
init: InitStore.reducer,
option: OptionStore.reducer,
query: QueryStore.reducer,
versionInfo: VersionInfoStore.reducer
})(state, action);
}
@ -47,18 +39,6 @@ export function selectors<S>(selector: Selector<any, State>) {
(state: State) => state.init
)
),
OptionSelector: OptionStore.selectors(
createSelector(
selector,
(state: State) => state.option
)
),
QuerySelector: QueryStore.selectors(
createSelector(
selector,
(state: State) => state.query
)
),
VersionInfoSelector: VersionInfoStore.selectors(
createSelector(
selector,

View File

@ -1,15 +0,0 @@
import { createAction, props } from '@ngrx/store';
import { AuthRequest, AuthResponse } from '@ucap-webmessenger/protocol-query';
export const auth = createAction('[Setting::Query] Auth', props<AuthRequest>());
export const authSuccess = createAction(
'[Setting::Query] Auth Success',
props<{ res: AuthResponse }>()
);
export const authFailure = createAction(
'[Setting::Query] Auth Failure',
props<{ error: any }>()
);

View File

@ -1,55 +0,0 @@
import { Injectable } from '@angular/core';
import { Actions, ofType, createEffect } from '@ngrx/effects';
import { of } from 'rxjs';
import { catchError, exhaustMap, map, tap } from 'rxjs/operators';
import { authSuccess, authFailure } from './actions';
import { initSettings } from '../init';
import {
QueryProtocolService,
AuthRequest
} from '@ucap-webmessenger/protocol-query';
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
import {
LoginInfo,
KEY_LOGIN_INFO,
EnvironmentsInfo,
KEY_ENVIRONMENTS_INFO
} from '@app/types';
import { loginSuccess } from '@app/store/account/authentication';
@Injectable()
export class Effects {
// initSettings$ = createEffect(() =>
// this.actions$.pipe(
// ofType(loginSuccess),
// map(() => {
// const loginInfo = this.sessionStorageService.get<LoginInfo>(
// KEY_LOGIN_INFO
// );
// const environmentsInfo = this.sessionStorageService.get<
// EnvironmentsInfo
// >(KEY_ENVIRONMENTS_INFO);
// return {
// deviceType: environmentsInfo.deviceType
// } as AuthRequest;
// }),
// exhaustMap(req =>
// this.queryProtocolService.auth(req).pipe(
// map(res => authSuccess({ res })),
// catchError(error => of(authFailure({ error })))
// )
// )
// )
// );
constructor(
private actions$: Actions,
private sessionStorageService: SessionStorageService,
private queryProtocolService: QueryProtocolService
) {}
}

View File

@ -5,7 +5,10 @@
<mat-form-field appearance="outline">
<mat-label>Company</mat-label>
<mat-select formControlName="companyCode" required>
<mat-option *ngFor="let company of companyList" [value]="company.companyCode">{{ company.companyName }}
<mat-option
*ngFor="let company of companyList"
[value]="company.companyCode"
>{{ company.companyName }}
</mat-option>
</mat-select>
<mat-error *ngIf="loginForm.get('companyCode').hasError('required')">
@ -32,7 +35,12 @@
</mat-error>
</mat-form-field>
<div class="remember-forgot-password" fxLayout="row" fxLayout.xs="column" fxLayoutAlign="space-between center">
<div
class="remember-forgot-password"
fxLayout="row"
fxLayout.xs="column"
fxLayoutAlign="space-between center"
>
<mat-checkbox class="remember-me" aria-label="Remember Me">
Remember Me
</mat-checkbox>
@ -42,8 +50,14 @@
</a>
</div>
<button mat-raised-button color="accent" class="submit-button" aria-label="LOG IN" [disabled]="loginForm.invalid"
(click)="onClickLogin()">
<button
mat-raised-button
color="accent"
class="submit-button"
aria-label="LOG IN"
[disabled]="loginForm.invalid"
(click)="onClickLogin()"
>
LOGIN
</button>
</form>
@ -52,9 +66,4 @@
<span class="text">Don't have an account?</span>
<a class="link">Create an account</a>
</div>
<button mat-raised-button color="accent" class="submit-button" aria-label="Template" (click)="onClickTemplate()">
Template
</button>
</div>

View File

@ -27,8 +27,6 @@ export class LoginComponent implements OnInit {
rememberMe: boolean;
notValid: () => void;
}>();
@Output()
template = new EventEmitter();
@ViewChild('loginPw', { static: true }) loginPwElementRef: ElementRef;
@ -55,8 +53,4 @@ export class LoginComponent implements OnInit {
}
});
}
onClickTemplate() {
this.template.emit();
}
}

View File

@ -1,15 +0,0 @@
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'ucap-organization-expansion-panel',
templateUrl: './expansion-panel.component.html',
styleUrls: ['./expansion-panel.component.scss']
})
export class ExpansionPanelComponent implements OnInit {
@Input()
organizationList: any[];
constructor() {}
ngOnInit() {}
}

View File

@ -1,19 +1,19 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ExpansionPanelComponent } from './expansion-panel.component';
import { TreeComponent } from './tree.component';
describe('Organization::ExpansionPanelComponent', () => {
let component: ExpansionPanelComponent;
let fixture: ComponentFixture<ExpansionPanelComponent>;
describe('Organization::TreeComponent', () => {
let component: TreeComponent;
let fixture: ComponentFixture<TreeComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ExpansionPanelComponent]
declarations: [TreeComponent]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ExpansionPanelComponent);
fixture = TestBed.createComponent(TreeComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

View File

@ -0,0 +1,15 @@
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'ucap-organization-tree',
templateUrl: './tree.component.html',
styleUrls: ['./tree.component.scss']
})
export class TreeComponent implements OnInit {
@Input()
organizationList: any[];
constructor() {}
ngOnInit() {}
}

View File

@ -4,9 +4,9 @@ import { ReactiveFormsModule } from '@angular/forms';
import { MatExpansionModule } from '@angular/material/expansion';
import { ExpansionPanelComponent } from './components/expansion-panel.component';
import { TreeComponent } from './components/tree.component';
const COMPONENTS = [ExpansionPanelComponent];
const COMPONENTS = [TreeComponent];
const SERVICES = [];
@NgModule({

View File

@ -1,6 +1,6 @@
/*
* Public API Surface of ucap-webmessenger-ui-organization
*/
export * from './lib/components/expansion-panel.component';
export * from './lib/components/tree.component';
export * from './lib/ucap-ui-organization.module';