bug fixed

This commit is contained in:
병준 박 2019-11-05 14:55:17 +09:00
parent f382696838
commit bf9c7f80bf
9 changed files with 87 additions and 21 deletions

View File

@ -13,11 +13,14 @@ export class FileUploadItem {
this.file = file; this.file = file;
} }
static fromFiles(files: File[]): FileUploadItem[] { static fromFiles(files: FileList): FileUploadItem[] {
const fileItems: FileUploadItem[] = []; const fileItems: FileUploadItem[] = [];
for (const file of files) {
fileItems.push(new FileUploadItem(file)); // tslint:disable-next-line: prefer-for-of
for (let i = 0; i < files.length; i++) {
fileItems.push(new FileUploadItem(files[i]));
} }
return fileItems; return fileItems;
} }

View File

@ -142,8 +142,15 @@ export class CommonApiService {
); );
} }
public acceptableExtensionForFileTalk(extension: string): boolean { public acceptableExtensionForFileTalk(extensions: string[]): boolean {
return -1 !== this.moduleConfig.acceptableFileExtensions.indexOf(extension); for (const extension of extensions) {
if (
-1 === this.moduleConfig.acceptableFileExtensions.indexOf(extension)
) {
return false;
}
}
return true;
} }
public fileTalkShare( public fileTalkShare(

View File

@ -113,6 +113,7 @@
<div class="file-drop-zone-container"> <div class="file-drop-zone-container">
<ucap-file-upload-queue <ucap-file-upload-queue
#fileUploadQueue #fileUploadQueue
[dropZoneIncludeParent]="true"
class="file-drop-zone" class="file-drop-zone"
></ucap-file-upload-queue> ></ucap-file-upload-queue>
</div> </div>

View File

@ -386,6 +386,11 @@ export class MessagesComponent implements OnInit, OnDestroy, AfterViewInit {
onFileSelected(fileUploadItems: FileUploadItem[]) { onFileSelected(fileUploadItems: FileUploadItem[]) {
this.logger.debug('onFileSelected', fileUploadItems); this.logger.debug('onFileSelected', fileUploadItems);
const info = {
senderSeq: this.loginRes.userSeq,
roomSeq: this.roomInfo.roomSeq
};
const allObservables: Observable<FileTalkSaveResponse>[] = []; const allObservables: Observable<FileTalkSaveResponse>[] = [];
for (const fileUploadItem of fileUploadItems) { for (const fileUploadItem of fileUploadItems) {
@ -424,9 +429,9 @@ export class MessagesComponent implements OnInit, OnDestroy, AfterViewInit {
for (const res of resList) { for (const res of resList) {
this.store.dispatch( this.store.dispatch(
EventStore.send({ EventStore.send({
senderSeq: this.loginRes.userSeq, senderSeq: info.senderSeq,
req: { req: {
roomSeq: this.roomInfo.roomSeq, roomSeq: info.roomSeq,
eventType: EventType.File, eventType: EventType.File,
sentMessage: res.returnJson sentMessage: res.returnJson
} }
@ -434,7 +439,9 @@ export class MessagesComponent implements OnInit, OnDestroy, AfterViewInit {
); );
} }
}, },
error => {}, error => {
this.logger.debug('onFileSelected error', error);
},
() => { () => {
this.fileUploadQueue.onUploadComplete(); this.fileUploadQueue.onUploadComplete();
} }

View File

@ -0,0 +1,16 @@
const regFileExtension = /(?:\.([^.]+))?$/;
export class FileUtil {
static getExtension(fileName: string): string | undefined {
return regFileExtension.exec(fileName)[1];
}
static getExtensions(fileList: FileList): string[] {
const extensions: string[] = [];
// tslint:disable-next-line: prefer-for-of
for (let i = 0; i < fileList.length; i++) {
extensions.push(FileUtil.getExtension(fileList[i].name));
}
return extensions;
}
}

View File

@ -20,4 +20,5 @@ export * from './lib/types/status-code.type';
export * from './lib/types/status-type.type'; export * from './lib/types/status-type.type';
export * from './lib/types/video-conference-type.type'; export * from './lib/types/video-conference-type.type';
export * from './lib/utils/file.util';
export * from './lib/utils/string.util'; export * from './lib/utils/string.util';

View File

@ -55,17 +55,16 @@ export class FormComponent implements OnInit {
} }
onChangeFileInput() { onChangeFileInput() {
const files: File[] = []; const fileUploadItems = FileUploadItem.fromFiles(
for (let i = 0; i < this.fileInput.nativeElement.files.length; i++) { this.fileInput.nativeElement.files
files.push(this.fileInput.nativeElement.files.item(i)); );
}
const fileUploadItems = FileUploadItem.fromFiles(files);
if (!!this.fileUploadQueue) { if (!!this.fileUploadQueue) {
this.fileUploadQueue.onFileSelected(fileUploadItems); this.fileUploadQueue.onFileSelected(fileUploadItems);
} }
this.sendFiles.emit(fileUploadItems); this.sendFiles.emit(fileUploadItems);
this.fileInput.nativeElement.value = '';
} }
} }

View File

@ -17,6 +17,9 @@ import { FileUploadItem } from '@ucap-webmessenger/api-common';
styleUrls: ['./file-upload-queue.component.scss'] styleUrls: ['./file-upload-queue.component.scss']
}) })
export class FileUploadQueueComponent implements OnInit, AfterViewInit { export class FileUploadQueueComponent implements OnInit, AfterViewInit {
@Input()
dropZoneIncludeParent = false;
fileUploadItems: FileUploadItem[]; fileUploadItems: FileUploadItem[];
uploadItems: DataTransferItem[]; uploadItems: DataTransferItem[];
@ -90,11 +93,17 @@ export class FileUploadQueueComponent implements OnInit, AfterViewInit {
private changeStyleDisplay(show: boolean): void { private changeStyleDisplay(show: boolean): void {
if (show || (!!this.fileUploadItems && 0 < this.fileUploadItems.length)) { if (show || (!!this.fileUploadItems && 0 < this.fileUploadItems.length)) {
this.elementRef.nativeElement.parentElement.style.display = ''; if (this.dropZoneIncludeParent) {
// this.elementRef.nativeElement.style.display = ''; this.elementRef.nativeElement.parentElement.style.display = '';
} else {
this.elementRef.nativeElement.style.display = '';
}
} else { } else {
this.elementRef.nativeElement.parentElement.style.display = 'none'; if (this.dropZoneIncludeParent) {
// this.elementRef.nativeElement.style.display = 'none'; this.elementRef.nativeElement.parentElement.style.display = 'none';
} else {
this.elementRef.nativeElement.style.display = 'none';
}
} }
} }

View File

@ -10,7 +10,11 @@ import {
import { NGXLogger } from 'ngx-logger'; import { NGXLogger } from 'ngx-logger';
import { FileUploadQueueComponent } from '../components/file-upload-queue.component'; import { FileUploadQueueComponent } from '../components/file-upload-queue.component';
import { FileUploadItem } from '@ucap-webmessenger/api-common'; import {
FileUploadItem,
CommonApiService
} from '@ucap-webmessenger/api-common';
import { FileUtil } from '@ucap-webmessenger/core';
@Directive({ @Directive({
selector: 'input[ucapFileUploadFor], div[ucapFileUploadFor]' selector: 'input[ucapFileUploadFor], div[ucapFileUploadFor]'
@ -33,7 +37,11 @@ export class FileUploadForDirective implements AfterViewInit {
dragOver = false; dragOver = false;
constructor(private elementRef: ElementRef, private logger: NGXLogger) {} constructor(
private commonApiService: CommonApiService,
private elementRef: ElementRef,
private logger: NGXLogger
) {}
ngAfterViewInit(): void {} ngAfterViewInit(): void {}
@ -93,7 +101,22 @@ export class FileUploadForDirective implements AfterViewInit {
if (!this.isFileDrag(event.dataTransfer)) { if (!this.isFileDrag(event.dataTransfer)) {
return; return;
} }
const files = event.dataTransfer.files; const files: FileList = event.dataTransfer.files;
if (
!this.commonApiService.acceptableExtensionForFileTalk(
FileUtil.getExtensions(files)
)
) {
this.logger.debug('window:drop not acceptable');
if (!!this.fileUploadQueue) {
this.fileUploadQueue.onDragLeave();
}
this.elementRef.nativeElement.value = '';
this.dragOver = false;
return;
}
const fileUploadItems = FileUploadItem.fromFiles(files); const fileUploadItems = FileUploadItem.fromFiles(files);
this.fileSelected.emit(fileUploadItems); this.fileSelected.emit(fileUploadItems);
event.preventDefault(); event.preventDefault();