next-ucap-messenger/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-side.component.ts

153 lines
4.2 KiB
TypeScript
Raw Normal View History

import { UserSelectDialogType } from './../../../types/userselect.dialog.type';
import { Component, OnInit } from '@angular/core';
import { NGXLogger } from 'ngx-logger';
import { ucapAnimations, DialogService } from '@ucap-webmessenger/ui';
import {
CreateChatDialogComponent,
CreateChatDialogData,
CreateChatDialogResult
2019-10-17 00:18:55 +00:00
} from '@app/layouts/messenger/dialogs/chat/create-chat.dialog.component';
import { Observable } from 'rxjs';
import { Store, select } from '@ngrx/store';
import * as AppStore from '@app/store';
import * as ChatStore from '@app/store/messenger/chat';
import { UserInfo } from '@ucap-webmessenger/protocol-sync';
import {
UserInfoSS,
UserInfoF,
UserInfoDN
} from '@ucap-webmessenger/protocol-query';
import { BuiltinType } from '@angular/compiler';
@Component({
2019-09-26 02:11:22 +00:00
selector: 'app-layout-messenger-left-side',
templateUrl: './left-side.component.html',
styleUrls: ['./left-side.component.scss'],
animations: ucapAnimations
})
2019-09-26 02:11:22 +00:00
export class LeftSideComponent implements OnInit {
badgeChatUnReadCount$: Observable<number>;
/** 조직도에서 부서원 선택 */
selectedUserList: (UserInfo | UserInfoSS | UserInfoF | UserInfoDN)[] = [];
2019-10-30 09:18:35 +00:00
/** FAB */
fabButtons: { icon: string; tooltip?: string; divisionType?: string }[];
2019-10-30 09:18:35 +00:00
constructor(
private store: Store<any>,
private dialogService: DialogService,
private logger: NGXLogger
) {}
ngOnInit() {
this.badgeChatUnReadCount$ = this.store.pipe(
select(AppStore.MessengerSelector.SyncSelector.selectChatUnreadCount)
);
2019-10-30 09:18:35 +00:00
this.fabButtons = [
2019-11-01 06:53:54 +00:00
{
icon: 'timer',
tooltip: 'New Timer Chat',
divisionType: 'NEW_TIMER_CHAT'
},
2019-10-30 09:18:35 +00:00
{
icon: 'chat',
tooltip: 'New Chat',
divisionType: 'NEW_CHAT'
2019-10-30 09:18:35 +00:00
}
];
}
2019-10-31 06:05:59 +00:00
async onClickNewChat(type: string = 'NORMAL') {
const result = await this.dialogService.open<
CreateChatDialogComponent,
CreateChatDialogData,
CreateChatDialogResult
>(CreateChatDialogComponent, {
width: '600px',
data: {
type: UserSelectDialogType.NewChat,
2019-10-31 06:05:59 +00:00
title: type === 'TIMER' ? 'New Timer Chat' : 'New Chat'
}
});
if (!!result && !!result.choice && result.choice) {
if (!!result.selectedUserList && result.selectedUserList.length > 0) {
const userSeqs: number[] = [];
result.selectedUserList.map(user => userSeqs.push(user.seq));
2019-10-31 06:05:59 +00:00
if (type === 'NORMAL') {
this.store.dispatch(ChatStore.openRoom({ userSeqList: userSeqs }));
} else if (type === 'TIMER') {
this.store.dispatch(
ChatStore.openRoom({ userSeqList: userSeqs, isTimeRoom: true })
);
}
}
}
}
onCheckAllUser(params: {
isChecked: boolean;
userInfos: (UserInfo | UserInfoSS | UserInfoF | UserInfoDN)[];
}) {
params.userInfos.forEach(userInfo => {
if (params.isChecked) {
if (
this.selectedUserList.filter(user => user.seq === userInfo.seq)
.length === 0
) {
this.selectedUserList = [...this.selectedUserList, userInfo];
}
} else {
this.selectedUserList = this.selectedUserList.filter(
user => user.seq !== userInfo.seq
);
}
});
}
/** 조직도>부서원 :: 리스트의 checkbox 의 이벤트를 받아 선택된 유저리스트를 수집. */
onCheckUser(params: {
isChecked: boolean;
userInfo: UserInfo | UserInfoSS | UserInfoF | UserInfoDN;
}) {
if (params.isChecked) {
if (
params.userInfo &&
this.selectedUserList.filter(user => user.seq === params.userInfo.seq)
.length === 0
) {
this.selectedUserList = [...this.selectedUserList, params.userInfo];
}
} else {
this.selectedUserList = this.selectedUserList.filter(
user => user.seq !== params.userInfo.seq
);
}
}
2019-10-30 09:18:35 +00:00
/** FAB */
onClickFab(params: { btn: any }) {
const btn = params.btn as {
icon: string;
tooltip?: string;
divisionType?: string;
};
switch (btn.divisionType) {
case 'NEW_CHAT':
{
2019-10-31 06:05:59 +00:00
this.onClickNewChat('NORMAL');
}
break;
case 'NEW_TIMER_CHAT':
{
2019-10-31 06:05:59 +00:00
this.onClickNewChat('TIMER');
}
break;
}
2019-10-30 09:18:35 +00:00
}
}