refactoring

This commit is contained in:
병준 박 2019-11-07 13:48:25 +09:00
parent bb4cdfab26
commit 6297a0b2c3
20 changed files with 203 additions and 219 deletions

View File

@ -22,7 +22,18 @@ const fileTalkDownloadEncodeMap = {
attachmentsSeq: 'p_att_seq'
};
export const encodeFileTalkDownload: APIFormDataEncoder<
export const encodeFileTalkDownload: APIEncoder<FileTalkDownloadRequest> = (
req: FileTalkDownloadRequest
) => {
const extraParams: any = {};
extraParams.userSeq = String(req.userSeq);
extraParams.attachmentsSeq = String(req.attachmentsSeq);
return ParameterUtil.encode(fileTalkDownloadEncodeMap, req, extraParams);
};
export const encodeFormDataFileTalkDownload: APIFormDataEncoder<
FileTalkDownloadRequest
> = (req: FileTalkDownloadRequest) => {
const extraParams: any = {};

View File

@ -19,7 +19,8 @@ import {
} from '../apis/file-profile-save';
import {
FileTalkDownloadRequest,
encodeFileTalkDownload
encodeFileTalkDownload,
encodeFormDataFileTalkDownload
} from '../apis/file-talk-download';
import {
FileTalkSaveRequest,
@ -96,6 +97,24 @@ export class CommonApiService {
.pipe(map(res => decodeFileProfileSave(res)));
}
public urlForFileTalkDownload(
req: FileTalkDownloadRequest,
fileTalkDownloadUrl?: string
): string {
const httpReq = new HttpRequest(
'GET',
!!fileTalkDownloadUrl
? fileTalkDownloadUrl
: this.moduleConfig.urls.fileTalkDownload,
{},
{
params: encodeFileTalkDownload(req)
}
);
return httpReq.urlWithParams;
}
public fileTalkDownload(
req: FileTalkDownloadRequest,
fileTalkDownloadUrl?: string
@ -105,7 +124,7 @@ export class CommonApiService {
!!fileTalkDownloadUrl
? fileTalkDownloadUrl
: this.moduleConfig.urls.fileTalkDownload,
encodeFileTalkDownload(req),
encodeFormDataFileTalkDownload(req),
{ reportProgress: true, responseType: 'blob' }
);

View File

@ -2,7 +2,8 @@ import {
APIRequest,
APIResponse,
APIEncoder,
APIDecoder
APIDecoder,
ParameterUtil
} from '@ucap-webmessenger/api';
export interface CheckUserInfoExRequest extends APIRequest {
@ -15,14 +16,16 @@ export interface CheckUserInfoExResponse extends APIResponse {
userId?: string;
}
const checkUserInfoExEncodeMap = {
userId: 'p_user_id',
companyCode: 'p_comp_code',
userSession: 'p_user_session'
};
export const encodeCheckUserInfoEx: APIEncoder<CheckUserInfoExRequest> = (
req: CheckUserInfoExRequest
) => {
return {
p_user_id: req.userId,
p_comp_code: req.companyCode,
p_user_session: req.userSession
};
return ParameterUtil.encode(checkUserInfoExEncodeMap, req);
};
export const decodeCheckUserInfoEx: APIDecoder<CheckUserInfoExResponse> = (

View File

@ -3,7 +3,8 @@ import {
APIRequest,
APIResponse,
APIEncoder,
APIDecoder
APIDecoder,
ParameterUtil
} from '@ucap-webmessenger/api';
import { Company } from '../models/company';
@ -19,16 +20,22 @@ export interface CompanyListResponse extends APIResponse {
companyList?: Company[];
}
const companyListEncodeMap = {
userSeq: 'p_user_seq',
appType: 'p_app_type',
deviceType: 'p_device_type',
token: 'p_token',
companyGroupCode: 'p_comp_group_code'
};
export const encodeCompanyList: APIEncoder<CompanyListRequest> = (
req: CompanyListRequest
) => {
return {
p_user_seq: String(req.userSeq),
p_app_type: req.appType,
p_device_type: req.deviceType,
p_token: req.token,
p_comp_group_code: req.companyGroupCode
};
const extraParams: any = {};
extraParams.userSeq = String(req.userSeq);
return ParameterUtil.encode(companyListEncodeMap, req, extraParams);
};
export const decodeCompanyList: APIDecoder<CompanyListResponse> = (

View File

@ -3,7 +3,8 @@ import {
APIRequest,
APIResponse,
APIEncoder,
APIDecoder
APIDecoder,
ParameterUtil
} from '@ucap-webmessenger/api';
export interface TokenUpdateRequest extends APIRequest {
@ -17,16 +18,22 @@ export interface TokenUpdateRequest extends APIRequest {
// tslint:disable-next-line: no-empty-interface
export interface TokenUpdateResponse extends APIResponse {}
const tokenUpdateEncodeMap = {
userSeq: 'p_user_seq',
deviceType: 'p_device_type',
token: 'p_token',
mobilePid: 'p_mobile_pid',
pushType: 'p_push_type'
};
export const encodeTokenUpdate: APIEncoder<TokenUpdateRequest> = (
req: TokenUpdateRequest
) => {
return {
p_user_seq: String(req.userSeq),
p_device_type: req.deviceType,
p_token: req.token,
p_mobile_pid: req.mobilePid,
p_push_type: req.pushType
};
const extraParams: any = {};
extraParams.userSeq = String(req.userSeq);
return ParameterUtil.encode(tokenUpdateEncodeMap, req, extraParams);
};
export const decodeTokenUpdate: APIDecoder<TokenUpdateResponse> = (

View File

@ -3,7 +3,8 @@ import {
APIRequest,
APIResponse,
APIEncoder,
APIDecoder
APIDecoder,
ParameterUtil
} from '@ucap-webmessenger/api';
export interface UrlInfoRequest extends APIRequest {
@ -25,12 +26,14 @@ export interface UrlInfoResponse extends APIResponse {
synapViewUrl?: string;
}
const urlInfoEncodeMap = {
deviceType: 'p_device_type'
};
export const encodeUrlInfo: APIEncoder<UrlInfoRequest> = (
req: UrlInfoRequest
) => {
return {
p_device_type: req.deviceType
};
return ParameterUtil.encode(urlInfoEncodeMap, req);
};
export const decodeUrlInfo: APIDecoder<UrlInfoResponse> = (res: any) => {

View File

@ -12,13 +12,7 @@ export interface APIResponse {
errorMessage: string;
}
export type APIEncoder<REQ> = (
req: REQ
) =>
| HttpParams
| {
[param: string]: string | string[];
};
export type APIEncoder<REQ> = (req: REQ) => HttpParams;
export type APIFormDataEncoder<REQ> = (req: REQ) => FormData;

View File

@ -1,6 +1,6 @@
export type Parameter = {
[param: string]: string | string[];
} | null;
import { HttpParams } from '@angular/common/http';
export type Parameter = HttpParams | null;
export class ParameterUtil {
public static encode(
@ -8,7 +8,7 @@ export class ParameterUtil {
param: {},
extraParam?: {}
): Parameter {
const parameter: Parameter = {};
let parameter: HttpParams = new HttpParams();
Object.keys(parameterMap).map(key => {
if (!param.hasOwnProperty(key)) {
@ -23,11 +23,15 @@ export class ParameterUtil {
}
if (!!v) {
parameter[parameterMap[key]] = v;
if (parameter.has(parameterMap[key])) {
parameter = parameter.append(parameterMap[key], v);
} else {
parameter = parameter.set(parameterMap[key], v);
}
}
});
return 0 === Object.keys(parameter).length ? null : parameter;
return parameter;
}
public static encodeFormData(

View File

@ -3,7 +3,7 @@ import { HttpParams } from '@angular/common/http';
export class UrlUtil {
public static format(href: string, param: Parameter): string {
const params = new HttpParams({ fromObject: param }).toString();
const params = param.toString();
if (params.length === 0) {
return href;

View File

@ -4,6 +4,7 @@ import { CommonModule } from '@angular/common';
import { FlexLayoutModule } from '@angular/flex-layout';
import { MatIconModule } from '@angular/material/icon';
import { MatProgressBarModule } from '@angular/material/progress-bar';
import { MatToolbarModule } from '@angular/material/toolbar';
import { UCapUiModule } from '@ucap-webmessenger/ui';
@ -16,6 +17,7 @@ import { DIALOGS } from './dialogs';
CommonModule,
FlexLayoutModule,
MatIconModule,
MatProgressBarModule,
MatToolbarModule,
UCapUiModule
],

View File

@ -1,9 +1,11 @@
<mat-progress-bar
*ngIf="fileDownloadItem && fileDownloadItem.downloadingProgress$"
mode="determinate"
[value]="fileDownloadItem.downloadingProgress$ | async"
></mat-progress-bar>
<ucap-file-viewer
[fileInfo]="fileInfo"
[downloadUrl]="downloadUrl"
[userSeq]="userSeq"
[deviceType]="deviceType"
[token]="token"
(download)="onDownload($event)"
[fileDownloadUrl]="fileDownloadUrl"
(download)="onDownload()"
(closed)="onClosedViewer()"
></ucap-file-viewer>

View File

@ -9,10 +9,14 @@ import {
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
import { NGXLogger } from 'ngx-logger';
import { FileEventJson } from '@ucap-webmessenger/protocol-event';
import { DeviceType, FileUtil } from '@ucap-webmessenger/core';
import { DeviceType, FileUtil, MimeUtil } from '@ucap-webmessenger/core';
import { NativeService, UCAP_NATIVE_SERVICE } from '@ucap-webmessenger/native';
import { take } from 'rxjs/operators';
import { take, map, finalize, tap } from 'rxjs/operators';
import { SnackBarService } from '@ucap-webmessenger/ui';
import {
FileDownloadItem,
CommonApiService
} from '@ucap-webmessenger/api-common';
export interface FileViewerDialogData {
fileInfo: FileEventJson;
@ -36,6 +40,10 @@ export class FileViewerDialogComponent implements OnInit, OnDestroy {
deviceType: DeviceType;
token: string;
fileDownloadItem: FileDownloadItem;
fileDownloadUrl: string;
constructor(
public dialogRef: MatDialogRef<
FileViewerDialogData,
@ -44,6 +52,7 @@ export class FileViewerDialogComponent implements OnInit, OnDestroy {
@Inject(MAT_DIALOG_DATA) public data: FileViewerDialogData,
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService,
private snackBarService: SnackBarService,
private commonApiService: CommonApiService,
private logger: NGXLogger
) {
this.fileInfo = data.fileInfo;
@ -51,13 +60,44 @@ export class FileViewerDialogComponent implements OnInit, OnDestroy {
this.userSeq = data.userSeq;
this.deviceType = data.deviceType;
this.token = data.token;
this.fileDownloadUrl = this.commonApiService.urlForFileTalkDownload(
{
userSeq: this.userSeq,
deviceType: this.deviceType,
token: this.token,
attachmentsSeq: this.fileInfo.attachmentSeq
},
this.downloadUrl
);
}
ngOnInit() {}
ngOnDestroy(): void {}
onDownload(blob: Blob): void {
onDownload(): void {
this.fileDownloadItem = new FileDownloadItem();
this.commonApiService
.fileTalkDownload(
{
userSeq: this.userSeq,
deviceType: this.deviceType,
token: this.token,
attachmentsSeq: this.fileInfo.attachmentSeq,
fileDownloadItem: this.fileDownloadItem
},
this.downloadUrl
)
.pipe(
take(1),
map(async rawBlob => {
const blob = rawBlob.slice(
0,
rawBlob.size,
MimeUtil.getMimeFromExtension(this.fileInfo.fileExt)
);
FileUtil.fromBlobToBuffer(blob)
.then(buffer => {
this.nativeService
@ -81,6 +121,12 @@ export class FileViewerDialogComponent implements OnInit, OnDestroy {
.catch(reason => {
this.logger.error('download', reason);
});
}),
finalize(() => {
this.fileDownloadItem = undefined;
})
)
.subscribe();
}
onClosedViewer(): void {

View File

@ -5,51 +5,36 @@
<ucap-document-viewer
*ngSwitchCase="FileViewerType.Document"
[fileInfo]="fileInfo"
[downloadUrl]="downloadUrl"
[userSeq]="userSeq"
[deviceType]="deviceType"
[token]="token"
(download)="onDownload($event)"
[fileDownloadUrl]="fileDownloadUrl"
(download)="onDownload()"
(closed)="onClosedViewer()"
></ucap-document-viewer>
<ucap-image-viewer
*ngSwitchCase="FileViewerType.Image"
[fileInfo]="fileInfo"
[downloadUrl]="downloadUrl"
[userSeq]="userSeq"
[deviceType]="deviceType"
[token]="token"
(download)="onDownload($event)"
[fileDownloadUrl]="fileDownloadUrl"
(download)="onDownload()"
(closed)="onClosedViewer()"
></ucap-image-viewer>
<ucap-sound-viewer
*ngSwitchCase="FileViewerType.Sound"
[fileInfo]="fileInfo"
[downloadUrl]="downloadUrl"
[userSeq]="userSeq"
[deviceType]="deviceType"
[token]="token"
(download)="onDownload($event)"
[fileDownloadUrl]="fileDownloadUrl"
(download)="onDownload()"
(closed)="onClosedViewer()"
></ucap-sound-viewer>
<ucap-video-viewer
*ngSwitchCase="FileViewerType.Video"
[fileInfo]="fileInfo"
[downloadUrl]="downloadUrl"
[userSeq]="userSeq"
[deviceType]="deviceType"
[token]="token"
(download)="onDownload($event)"
[fileDownloadUrl]="fileDownloadUrl"
(download)="onDownload()"
(closed)="onClosedViewer()"
></ucap-video-viewer>
<ucap-binary-viewer
*ngSwitchDefault
[fileInfo]="fileInfo"
[downloadUrl]="downloadUrl"
[userSeq]="userSeq"
[deviceType]="deviceType"
[token]="token"
(download)="onDownload($event)"
[fileDownloadUrl]="fileDownloadUrl"
(download)="onDownload()"
(closed)="onClosedViewer()"
></ucap-binary-viewer>
</div>

View File

@ -1,9 +1,8 @@
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { ucapAnimations } from '../animations';
import { Info, FileEventJson } from '@ucap-webmessenger/protocol-event';
import { FileEventJson } from '@ucap-webmessenger/protocol-event';
import { FileViewerType } from '../types/file-viewer.type';
import { FileType } from '@ucap-webmessenger/protocol-file';
import { DeviceType } from '@ucap-webmessenger/core';
@Component({
selector: 'ucap-file-viewer',
@ -16,19 +15,10 @@ export class FileViewerComponent implements OnInit {
fileInfo: FileEventJson;
@Input()
downloadUrl: string;
@Input()
userSeq: number;
@Input()
deviceType: DeviceType;
@Input()
token: string;
fileDownloadUrl: string;
@Output()
download = new EventEmitter<Blob>();
download = new EventEmitter<void>();
@Output()
closed = new EventEmitter<void>();
@ -51,8 +41,8 @@ export class FileViewerComponent implements OnInit {
return FileViewerType.Binary;
}
}
onDownload(blob: Blob): void {
this.download.emit(blob);
onDownload(): void {
this.download.emit();
}
onClosedViewer(): void {

View File

@ -14,19 +14,10 @@ export class BinaryViewerComponent implements OnInit {
fileInfo: FileEventJson;
@Input()
downloadUrl: string;
@Input()
userSeq: number;
@Input()
deviceType: DeviceType;
@Input()
token: string;
fileDownloadUrl: string;
@Output()
download = new EventEmitter<Blob>();
download = new EventEmitter<void>();
@Output()
closed = new EventEmitter<void>();

View File

@ -14,19 +14,10 @@ export class DocumentViewerComponent implements OnInit {
fileInfo: FileEventJson;
@Input()
downloadUrl: string;
@Input()
userSeq: number;
@Input()
deviceType: DeviceType;
@Input()
token: string;
fileDownloadUrl: string;
@Output()
download = new EventEmitter<Blob>();
download = new EventEmitter<void>();
@Output()
closed = new EventEmitter<void>();

View File

@ -51,11 +51,6 @@
Close
</button>
</mat-toolbar>
<mat-progress-bar
*ngIf="fileDownloadItem.downloadingProgress$ && !imageSrc"
mode="determinate"
[value]="fileDownloadItem.downloadingProgress$ | async"
></mat-progress-bar>
<div class="ucap-image-viewer-body">
<div
class="ucap-image-viewer-image-wrapper"
@ -64,7 +59,7 @@
fxFlexFill
fxLayoutAlign="center center"
>
<img *ngIf="imageSrc" [src]="imageSrc" />
<img *ngIf="fileDownloadUrl" [src]="fileDownloadUrl" />
</div>
</div>
</div>

View File

@ -1,13 +1,8 @@
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { ucapAnimations } from '../../animations';
import { FileEventJson } from '@ucap-webmessenger/protocol-event';
import { DeviceType, FileUtil, MimeUtil } from '@ucap-webmessenger/core';
import {
CommonApiService,
FileDownloadItem
} from '@ucap-webmessenger/api-common';
import { take, map } from 'rxjs/operators';
import { DomSanitizer } from '@angular/platform-browser';
import { DeviceType } from '@ucap-webmessenger/core';
import { CommonApiService } from '@ucap-webmessenger/api-common';
@Component({
selector: 'ucap-image-viewer',
@ -20,63 +15,20 @@ export class ImageViewerComponent implements OnInit {
fileInfo: FileEventJson;
@Input()
downloadUrl: string;
@Input()
userSeq: number;
@Input()
deviceType: DeviceType;
@Input()
token: string;
fileDownloadUrl: string;
@Output()
closed = new EventEmitter<void>();
@Output()
download = new EventEmitter<Blob>();
download = new EventEmitter<void>();
blob: Blob;
imageSrc: string | ArrayBuffer;
constructor() {}
fileDownloadItem: FileDownloadItem;
constructor(
private domSanitizer: DomSanitizer,
private commonApiService: CommonApiService
) {
this.fileDownloadItem = new FileDownloadItem();
}
ngOnInit() {
this.commonApiService
.fileTalkDownload(
{
userSeq: this.userSeq,
deviceType: this.deviceType,
token: this.token,
attachmentsSeq: this.fileInfo.attachmentSeq,
fileDownloadItem: this.fileDownloadItem
},
this.downloadUrl
)
.pipe(
take(1),
map(async blob => {
this.blob = blob.slice(
0,
blob.size,
MimeUtil.getMimeFromExtension(this.fileInfo.fileExt)
);
this.imageSrc = await FileUtil.fromBlobToDataUrl(this.blob);
})
)
.subscribe();
}
ngOnInit() {}
onClickDownload(): void {
this.download.emit(this.blob);
this.download.emit();
}
onClickClose(): void {

View File

@ -14,19 +14,10 @@ export class SoundViewerComponent implements OnInit {
fileInfo: FileEventJson;
@Input()
downloadUrl: string;
@Input()
userSeq: number;
@Input()
deviceType: DeviceType;
@Input()
token: string;
fileDownloadUrl: string;
@Output()
download = new EventEmitter<Blob>();
download = new EventEmitter<void>();
@Output()
closed = new EventEmitter<void>();

View File

@ -14,19 +14,10 @@ export class VideoViewerComponent implements OnInit {
fileInfo: FileEventJson;
@Input()
downloadUrl: string;
@Input()
userSeq: number;
@Input()
deviceType: DeviceType;
@Input()
token: string;
fileDownloadUrl: string;
@Output()
download = new EventEmitter<Blob>();
download = new EventEmitter<void>();
@Output()
closed = new EventEmitter<void>();