From f6ac17924faa6ac0046ee71592d57cf814d2db78 Mon Sep 17 00:00:00 2001 From: leejinho Date: Thu, 9 Jan 2020 18:14:00 +0900 Subject: [PATCH] =?UTF-8?q?=ED=8C=8C=EC=9D=BC=EC=97=85=EB=A1=9C=EB=93=9C?= =?UTF-8?q?=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EC=B2=B4=ED=81=AC=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/messages.component.ts | 82 ++++++++++++++++-- .../message-write.dialog.component.html | 1 + .../message/message-write.dialog.component.ts | 25 +++++- .../src/assets/i18n/en.json | 7 +- .../src/assets/i18n/ko.json | 7 +- .../environments/environment.daesang.dev.ts | 2 + .../environments/environment.daesang.prod.ts | 2 + .../src/environments/environment.dev.ts | 2 + .../src/environments/environment.prod.ts | 2 + .../src/environments/environment.type.ts | 3 + .../src/lib/components/write.component.ts | 85 +++++++++++++++++-- 11 files changed, 198 insertions(+), 20 deletions(-) diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/messages.component.ts b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/messages.component.ts index 699bc882..764edf60 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/messages.component.ts +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/messages.component.ts @@ -584,12 +584,16 @@ export class MessagesComponent implements OnInit, OnDestroy, AfterViewInit { info.sentMessageJson || info.sentMessage ); - this.snackBarPreviewEvent = this.snackBarService.open(message, this.translateService.instant('common.messages.confirm'), { - // duration: 3000, - verticalPosition: 'bottom', - horizontalPosition: 'center', - panelClass: ['chat-snackbar-class'] - }); + this.snackBarPreviewEvent = this.snackBarService.open( + message, + this.translateService.instant('common.messages.confirm'), + { + // duration: 3000, + verticalPosition: 'bottom', + horizontalPosition: 'center', + panelClass: ['chat-snackbar-class'] + } + ); this.snackBarPreviewEvent.onAction().subscribe(() => { this.setEventMoreInit(); this.scrollToBottom(); @@ -1052,6 +1056,68 @@ export class MessagesComponent implements OnInit, OnDestroy, AfterViewInit { const allObservables: Observable[] = []; + const fileAllowSize = + !!this.sessionVerInfo && this.sessionVerInfo.fileAllowSize + ? this.sessionVerInfo.fileAllowSize + : environment.productConfig.CommonSetting.defaultFileAllowSize; + + if (fileAllowSize > 0) { + if ( + fileUploadItems.filter( + fui => fui.file.size > fileAllowSize * 1024 * 1024 + ).length + ) { + this.dialogService.open< + AlertDialogComponent, + AlertDialogData, + AlertDialogResult + >(AlertDialogComponent, { + width: '360px', + data: { + title: '', + message: this.translateService.instant( + 'common.file.errors.oversize', + { + maxSize: fileAllowSize + } + ) + } + }); + if (!!this.fileUploadQueue) { + this.fileUploadQueue.onUploadComplete(); + } + return; + } + } + + const checkExt = this.commonApiService.acceptableExtensionForFileTalk( + fileUploadItems.map(fui => FileUtil.getExtension(fui.file.name)) + ); + if (!checkExt.accept) { + if (!!this.fileUploadQueue) { + this.fileUploadQueue.onUploadComplete(); + } + + this.dialogService.open< + AlertDialogComponent, + AlertDialogData, + AlertDialogResult + >(AlertDialogComponent, { + data: { + title: 'Alert', + html: `${this.translateService.instant( + 'common.file.errors.notSupporedType' + )} ${ + checkExt.reject.length > 0 + ? '
(' + checkExt.reject.join(',') + ')' + : '' + }` + } + }); + + return; + } + for (const fileUploadItem of fileUploadItems) { let thumbnail: File; if ( @@ -1127,6 +1193,10 @@ export class MessagesComponent implements OnInit, OnDestroy, AfterViewInit { this.translateService.instant('common.file.errors.failToUpload'), this.translateService.instant('common.file.errors.label') ); + + if (!!this.fileUploadQueue) { + this.fileUploadQueue.onUploadComplete(); + } }, () => { this.fileUploadQueue.onUploadComplete(); diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/message/message-write.dialog.component.html b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/message/message-write.dialog.component.html index 67ae7415..4c7f704a 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/message/message-write.dialog.component.html +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/message/message-write.dialog.component.html @@ -11,6 +11,7 @@ [detail]="data.detail" [detailContents]="data.detailContents" [curReceiverList]="data.receiverList" + [fileAllowSize]="fileAllowSize" (send)="onSend($event)" (selectReceiver)="onSelectReceiver($event)" (cancel)="onCancel()" diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/message/message-write.dialog.component.ts b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/message/message-write.dialog.component.ts index b7cb1864..14acd2ef 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/message/message-write.dialog.component.ts +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/message/message-write.dialog.component.ts @@ -7,13 +7,11 @@ import { DetailResponse, DetailContent, MessageApiService, - DetailReceiver, MessageType } from '@ucap-webmessenger/api-message'; import { LoginResponse } from '@ucap-webmessenger/protocol-authentication'; import { NGXLogger } from 'ngx-logger'; -import { MessageStatusCode } from '@ucap-webmessenger/api'; import { WriteComponent as UCapMessageWriteComponent, Message, @@ -25,10 +23,17 @@ import { CreateChatDialogData, CreateChatDialogResult } from '../chat/create-chat.dialog.component'; -import { UserSelectDialogType, EnvironmentsInfo } from '@app/types'; +import { + UserSelectDialogType, + EnvironmentsInfo, + KEY_VER_INFO +} from '@app/types'; import { take } from 'rxjs/operators'; import { UserInfoSS } from '@ucap-webmessenger/protocol-query'; import { TranslateService } from '@ngx-translate/core'; +import { VersionInfo2Response } from '@ucap-webmessenger/api-public'; +import { SessionStorageService } from '@ucap-webmessenger/web-storage'; +import { environment } from '../../../../../environments/environment'; export interface MessageWriteDialogData { loginRes: LoginResponse; @@ -57,6 +62,10 @@ export class MessageWriteDialogComponent implements OnInit { @ViewChild('messageWrite', { static: true }) messageWrite: UCapMessageWriteComponent; + sessionVerInfo: VersionInfo2Response; + + fileAllowSize: number; + isModify = false; constructor( @@ -68,11 +77,21 @@ export class MessageWriteDialogComponent implements OnInit { private messageApiService: MessageApiService, private snackBarService: SnackBarService, private translateService: TranslateService, + private sessionStorageService: SessionStorageService, private logger: NGXLogger, private dialogService: DialogService ) {} ngOnInit(): void { + this.sessionVerInfo = this.sessionStorageService.get( + KEY_VER_INFO + ); + + this.fileAllowSize = + !!this.sessionVerInfo && this.sessionVerInfo.fileAllowSize + ? this.sessionVerInfo.fileAllowSize + : environment.productConfig.CommonSetting.defaultFileAllowSize; + if (!!this.data.detail && !!this.data.detail.msgInfo) { this.isModify = true; } diff --git a/projects/ucap-webmessenger-app/src/assets/i18n/en.json b/projects/ucap-webmessenger-app/src/assets/i18n/en.json index b77147d9..083e98b3 100644 --- a/projects/ucap-webmessenger-app/src/assets/i18n/en.json +++ b/projects/ucap-webmessenger-app/src/assets/i18n/en.json @@ -349,12 +349,13 @@ "errors": { "label": "File errors", "failToUpload": "File upload failed.", - "failToSave": "File save failed.", - "failToSaveSomeOfAll": "Some of file(s) save failed", + "failToSave": "File save failed. Please 'Save As'.", + "failToSaveSomeOfAll": "Some of file(s) save failed. Please 'Save As'.", "failToSpecifyPath": "Specifing of save path failed.", "expired": "This file has expired", "noPreview": "This file does not support preview.", - "notSupporedType": "File format is not supported." + "notSupporedType": "File format is not supported.", + "oversize": "You cannot upload files larger than {{size}} megabytes." } }, "clipboard": { diff --git a/projects/ucap-webmessenger-app/src/assets/i18n/ko.json b/projects/ucap-webmessenger-app/src/assets/i18n/ko.json index 5f0da3fd..aa3d2f2d 100644 --- a/projects/ucap-webmessenger-app/src/assets/i18n/ko.json +++ b/projects/ucap-webmessenger-app/src/assets/i18n/ko.json @@ -349,12 +349,13 @@ "errors": { "label": "파일 에러", "failToUpload": "파일 업로드에 실패하였습니다.", - "failToSave": "파일 저장에 실패하였습니다.", - "failToSaveSomeOfAll": "파일 저장 중 일부 파일이 실패하였습니다.", + "failToSave": "파일 저장에 실패하였습니다. '다른 이름으로 저장' 하십시요.", + "failToSaveSomeOfAll": "파일 저장 중 일부 파일이 실패하였습니다. '다른 이름으로 저장' 하십시요.", "failToSpecifyPath": "저장경로 지정에 실패하였습니다.", "expired": "기간이 만료된 파일입니다", "noPreview": "미리보기를 지원하지 않는 파일입니다.", - "notSupporedType": "지원하지 않는 파일형식입니다." + "notSupporedType": "지원하지 않는 파일형식입니다.", + "oversize": "{{maxSize}}MB 이상 파일을 업로드 할 수 없습니다." } }, "clipboard": { diff --git a/projects/ucap-webmessenger-app/src/environments/environment.daesang.dev.ts b/projects/ucap-webmessenger-app/src/environments/environment.daesang.dev.ts index f964d1f0..cafa3318 100644 --- a/projects/ucap-webmessenger-app/src/environments/environment.daesang.dev.ts +++ b/projects/ucap-webmessenger-app/src/environments/environment.daesang.dev.ts @@ -64,6 +64,8 @@ export const environment: Environment = { } }, CommonSetting: { + defaultFileAllowSize: 100, + editableProfileImage: false, useMyDeptGroup: true, diff --git a/projects/ucap-webmessenger-app/src/environments/environment.daesang.prod.ts b/projects/ucap-webmessenger-app/src/environments/environment.daesang.prod.ts index 1967e2ca..3fef2401 100644 --- a/projects/ucap-webmessenger-app/src/environments/environment.daesang.prod.ts +++ b/projects/ucap-webmessenger-app/src/environments/environment.daesang.prod.ts @@ -64,6 +64,8 @@ export const environment: Environment = { } }, CommonSetting: { + defaultFileAllowSize: 100, + editableProfileImage: false, useMyDeptGroup: true, diff --git a/projects/ucap-webmessenger-app/src/environments/environment.dev.ts b/projects/ucap-webmessenger-app/src/environments/environment.dev.ts index 26f38555..a2b77597 100644 --- a/projects/ucap-webmessenger-app/src/environments/environment.dev.ts +++ b/projects/ucap-webmessenger-app/src/environments/environment.dev.ts @@ -64,6 +64,8 @@ export const environment: Environment = { } }, CommonSetting: { + defaultFileAllowSize: 100, + editableProfileImage: true, useMyDeptGroup: false, diff --git a/projects/ucap-webmessenger-app/src/environments/environment.prod.ts b/projects/ucap-webmessenger-app/src/environments/environment.prod.ts index 083cd151..f28adb51 100644 --- a/projects/ucap-webmessenger-app/src/environments/environment.prod.ts +++ b/projects/ucap-webmessenger-app/src/environments/environment.prod.ts @@ -64,6 +64,8 @@ export const environment: Environment = { } }, CommonSetting: { + defaultFileAllowSize: 100, + editableProfileImage: true, useMyDeptGroup: false, diff --git a/projects/ucap-webmessenger-app/src/environments/environment.type.ts b/projects/ucap-webmessenger-app/src/environments/environment.type.ts index 68c7c595..e6f378b3 100644 --- a/projects/ucap-webmessenger-app/src/environments/environment.type.ts +++ b/projects/ucap-webmessenger-app/src/environments/environment.type.ts @@ -64,6 +64,9 @@ export interface Environment { defaultSettings: Settings; CommonSetting: { + /** 파일업로드 제한 사이즈 (mb) */ + defaultFileAllowSize: number; + /** 내 프로필 이미지 수정 가능 여부 */ editableProfileImage: boolean; diff --git a/projects/ucap-webmessenger-ui-message/src/lib/components/write.component.ts b/projects/ucap-webmessenger-ui-message/src/lib/components/write.component.ts index 1e0f69eb..06836207 100644 --- a/projects/ucap-webmessenger-ui-message/src/lib/components/write.component.ts +++ b/projects/ucap-webmessenger-ui-message/src/lib/components/write.component.ts @@ -11,7 +11,13 @@ import { Input } from '@angular/core'; -import { ucapAnimations, DialogService } from '@ucap-webmessenger/ui'; +import { + ucapAnimations, + DialogService, + AlertDialogResult, + AlertDialogComponent, + AlertDialogData +} from '@ucap-webmessenger/ui'; import { NGXLogger } from 'ngx-logger'; @@ -36,7 +42,8 @@ import { } from '../dialogs/schedule-send.dialog.component'; import { RoleCode } from '@ucap-webmessenger/protocol-authentication'; import { EmployeeType } from '@ucap-webmessenger/protocol-room'; -import { contentTracing } from 'electron'; +import { TranslateService } from '@ngx-translate/core'; +import { CommonApiService } from '@ucap-webmessenger/api-common'; const ATTR_FILE = 'UCAP_ATTR_FILE'; @@ -79,19 +86,18 @@ export class WriteComponent implements OnInit, OnDestroy, AfterViewInit { detailContents?: string; @Input() isModify = false; + @Input() + fileAllowSize: number; @Output() send = new EventEmitter(); - @Output() cancel = new EventEmitter(); - @Output() selectReceiver = new EventEmitter(); @ViewChild('editor', { static: true }) editor: ElementRef; - @ViewChild('fileInput', { static: true }) fileInput: ElementRef; @@ -106,6 +112,8 @@ export class WriteComponent implements OnInit, OnDestroy, AfterViewInit { private formBuilder: FormBuilder, private dialogService: DialogService, private changeDetectorRef: ChangeDetectorRef, + private translateService: TranslateService, + private commonApiService: CommonApiService, private logger: NGXLogger ) {} @@ -157,6 +165,10 @@ export class WriteComponent implements OnInit, OnDestroy, AfterViewInit { this.fileInput.nativeElement.onchange = async () => { const fileList: FileList = self.fileInput.nativeElement.files; + if (!this.validUploadFile(fileList)) { + return; + } + for (let i = 0; i < fileList.length; i++) { const file = fileList.item(i); @@ -179,6 +191,10 @@ export class WriteComponent implements OnInit, OnDestroy, AfterViewInit { this.fileInput.nativeElement.onchange = () => { const fileList: FileList = this.fileInput.nativeElement.files; + if (!this.validUploadFile(fileList)) { + return; + } + if (!self.attachmentList) { self.attachmentList = []; } @@ -194,6 +210,65 @@ export class WriteComponent implements OnInit, OnDestroy, AfterViewInit { }; } + validUploadFile(fileList: FileList): boolean { + let valid = true; + if (this.fileAllowSize > 0) { + for (let i = 0; i < fileList.length; i++) { + const file = fileList.item(i); + if (file.size > this.fileAllowSize * 1024 * 1024) { + valid = false; + break; + } + } + if (!valid) { + this.dialogService.open< + AlertDialogComponent, + AlertDialogData, + AlertDialogResult + >(AlertDialogComponent, { + width: '360px', + data: { + title: '', + message: this.translateService.instant( + 'common.file.errors.oversize', + { + maxSize: this.fileAllowSize + } + ) + } + }); + + return valid; + } + } + + const checkExt = this.commonApiService.acceptableExtensionForFileTalk( + FileUtil.getExtensions(fileList) + ); + if (!checkExt.accept) { + this.dialogService.open< + AlertDialogComponent, + AlertDialogData, + AlertDialogResult + >(AlertDialogComponent, { + data: { + title: 'Alert', + html: `${this.translateService.instant( + 'common.file.errors.notSupporedType' + )} ${ + checkExt.reject.length > 0 + ? '
(' + checkExt.reject.join(',') + ')' + : '' + }` + } + }); + + return valid; + } + + return valid; + } + onPasteEditor(event: ClipboardEvent) { const text = document.createTextNode( event.clipboardData.getData('text/plain')