update file upload
This commit is contained in:
parent
ed94373573
commit
adaccb8c73
6 changed files with 59 additions and 56 deletions
|
|
@ -1,5 +1,4 @@
|
||||||
import {
|
import {
|
||||||
AfterViewChecked,
|
|
||||||
AfterViewInit,
|
AfterViewInit,
|
||||||
Component,
|
Component,
|
||||||
ElementRef,
|
ElementRef,
|
||||||
|
|
@ -13,7 +12,6 @@ import { UserService } from '../../../service/user.service';
|
||||||
import { SingleChatComponent } from '../single-chat/single-chat.component';
|
import { SingleChatComponent } from '../single-chat/single-chat.component';
|
||||||
import { ChatMsgBoxComponent } from '../chat-msg-box/chat-msg-box.component';
|
import { ChatMsgBoxComponent } from '../chat-msg-box/chat-msg-box.component';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { DownloadFilesService } from '../../../service/files.service';
|
|
||||||
import { ChannelService } from '../../../service/channel.service';
|
import { ChannelService } from '../../../service/channel.service';
|
||||||
import { InfoComponent } from '../info/info.component';
|
import { InfoComponent } from '../info/info.component';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,12 +62,22 @@
|
||||||
[btnBgHoverColor]="'#edeefe'"
|
[btnBgHoverColor]="'#edeefe'"
|
||||||
(click)="targetChatUser($event)"
|
(click)="targetChatUser($event)"
|
||||||
></app-small-btn>
|
></app-small-btn>
|
||||||
|
<!-- Warning message -->
|
||||||
|
@if (downloadFilesService.uploadFiles.length >= 1){
|
||||||
|
<p class="warningMessage">
|
||||||
|
{{ "channel-msg-box.text0" | translate }}
|
||||||
|
</p>
|
||||||
|
} @if(fileDataError){
|
||||||
|
<p class="warningMessage">
|
||||||
|
{{ "channel-msg-box.text1" | translate }}
|
||||||
|
</p>
|
||||||
|
}
|
||||||
<div class="filteredElementWindow">
|
<div class="filteredElementWindow">
|
||||||
@if (toggleBoolean.selectUserInMsgBox) {
|
@if (toggleBoolean.selectUserInMsgBox) {
|
||||||
<div class="positionOfAllUsersInBox">
|
<div class="positionOfAllUsersInBox">
|
||||||
@for(user of userService.getFiltertUsers; track user){
|
@for(user of userService.getFiltertUsers; track user){
|
||||||
<div class="user" (click)="chooseUser(user)">
|
<div class="user" (click)="chooseUser(user)">
|
||||||
<div class="positionImgs">
|
<div class="positionImg">
|
||||||
<img src="{{ user.avatar }}" class="avatarImg" />
|
<img src="{{ user.avatar }}" class="avatarImg" />
|
||||||
<img
|
<img
|
||||||
src="./assets/img/{{
|
src="./assets/img/{{
|
||||||
|
|
@ -82,15 +92,6 @@
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
} @if(downloadFilesService.uploadFiles.length >= 1){
|
|
||||||
<p
|
|
||||||
[ngClass]="{
|
|
||||||
showWarningNotice: downloadFilesService.uploadFiles.length >= 1
|
|
||||||
}"
|
|
||||||
class="warningMessage"
|
|
||||||
>
|
|
||||||
{{ "channel-msg-box.text" | translate }}
|
|
||||||
</p>
|
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
@if(textArea == ''){
|
@if(textArea == ''){
|
||||||
|
|
@ -110,7 +111,7 @@
|
||||||
<h3 class="user2" (click)="chooseElement(i)">{{ i.name }}</h3>
|
<h3 class="user2" (click)="chooseElement(i)">{{ i.name }}</h3>
|
||||||
} }@else if (showUsers) { @for (i of userService.allUsers; track $index) {
|
} }@else if (showUsers) { @for (i of userService.allUsers; track $index) {
|
||||||
<div class="user2" (click)="chooseElement(i)">
|
<div class="user2" (click)="chooseElement(i)">
|
||||||
<div class="positionImgs2">
|
<div class="positionImg2">
|
||||||
<img src="{{ i.avatar }}" class="avatarImg2" />
|
<img src="{{ i.avatar }}" class="avatarImg2" />
|
||||||
<img
|
<img
|
||||||
src="./assets/img/{{
|
src="./assets/img/{{
|
||||||
|
|
|
||||||
|
|
@ -67,8 +67,8 @@ app-small-btn {
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
padding: 5px 10px;
|
padding: 5px 10px;
|
||||||
background-color: #eee;
|
background-color: #eee;
|
||||||
max-width: 40px;
|
width: 40px;
|
||||||
max-height: 20px;
|
height: 20px;
|
||||||
margin-right: 12px;
|
margin-right: 12px;
|
||||||
position: relative;
|
position: relative;
|
||||||
@include displayFlex();
|
@include displayFlex();
|
||||||
|
|
@ -87,7 +87,7 @@ app-emoji-picker {
|
||||||
}
|
}
|
||||||
|
|
||||||
.positionDataFromPc {
|
.positionDataFromPc {
|
||||||
margin-top: -40px;
|
margin-top: -32px;
|
||||||
display: flex;
|
display: flex;
|
||||||
width: 60px;
|
width: 60px;
|
||||||
}
|
}
|
||||||
|
|
@ -114,19 +114,6 @@ app-emoji-picker {
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
}
|
}
|
||||||
|
|
||||||
.showWarningNotice {
|
|
||||||
animation: shwoWN 0.3s ease-in-out;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes shwoWN {
|
|
||||||
from {
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
to {
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.positionOfAllUsersInBox {
|
.positionOfAllUsersInBox {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 36px;
|
bottom: 36px;
|
||||||
|
|
@ -147,22 +134,18 @@ app-emoji-picker {
|
||||||
padding: 6px;
|
padding: 6px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: 0.2s ease-in-out;
|
transition: 0.2s ease-in-out;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: #edeefe;
|
background-color: #edeefe;
|
||||||
border-radius: 25px;
|
border-radius: 25px;
|
||||||
}
|
}
|
||||||
|
.positionImg {
|
||||||
.positionImgs {
|
|
||||||
@include displayFlex($a: flex-end);
|
@include displayFlex($a: flex-end);
|
||||||
|
|
||||||
.avatarImg {
|
.avatarImg {
|
||||||
width: 40px;
|
width: 40px;
|
||||||
height: 40px;
|
height: 40px;
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.onlineIcon {
|
.onlineIcon {
|
||||||
width: 12px;
|
width: 12px;
|
||||||
height: 12px;
|
height: 12px;
|
||||||
|
|
@ -208,7 +191,7 @@ app-emoji-picker {
|
||||||
background-color: #edeefe;
|
background-color: #edeefe;
|
||||||
border-radius: 25px;
|
border-radius: 25px;
|
||||||
}
|
}
|
||||||
.positionImgs2 {
|
.positionImg2 {
|
||||||
@include displayFlex($a: flex-end);
|
@include displayFlex($a: flex-end);
|
||||||
.avatarImg2 {
|
.avatarImg2 {
|
||||||
width: 40px;
|
width: 40px;
|
||||||
|
|
|
||||||
|
|
@ -46,14 +46,15 @@ export class ChatMsgBoxComponent {
|
||||||
@ViewChild('textarea') textAreaRef!: ElementRef;
|
@ViewChild('textarea') textAreaRef!: ElementRef;
|
||||||
|
|
||||||
hasFile: boolean = false;
|
hasFile: boolean = false;
|
||||||
|
fileDataError: boolean = false;
|
||||||
currentFiles!: FileList;
|
currentFiles!: FileList;
|
||||||
files: any;
|
|
||||||
getFileIcons = [
|
getFileIcons = [
|
||||||
'./assets/img/documentIcon.svg',
|
'./assets/img/documentIcon.svg',
|
||||||
'./assets/img/imgIcon.svg',
|
'./assets/img/imgIcon.svg',
|
||||||
'./assets/img/mp3Icon.svg',
|
'./assets/img/mp3Icon.svg',
|
||||||
'./assets/img/pdfIcon.svg',
|
'./assets/img/pdfIcon.svg',
|
||||||
'./assets/img/videoIcon.svg',
|
'./assets/img/videoIcon.svg',
|
||||||
|
null,
|
||||||
];
|
];
|
||||||
textArea: string = '';
|
textArea: string = '';
|
||||||
isEmojiPickerVisible: boolean | undefined;
|
isEmojiPickerVisible: boolean | undefined;
|
||||||
|
|
@ -102,34 +103,52 @@ export class ChatMsgBoxComponent {
|
||||||
*/
|
*/
|
||||||
onFileChange(event: any) {
|
onFileChange(event: any) {
|
||||||
if (this.downloadFilesService.uploadFiles.length < 1) {
|
if (this.downloadFilesService.uploadFiles.length < 1) {
|
||||||
|
const file = event.target.files[0];
|
||||||
|
const icon = this.checkIcon({ type: file.type });
|
||||||
|
if (icon !== null) {
|
||||||
this.currentFiles = event.target.files;
|
this.currentFiles = event.target.files;
|
||||||
this.hasFile = this.currentFiles!.length > 0;
|
this.hasFile = this.currentFiles.length > 0;
|
||||||
if (this.currentFiles) {
|
if (this.currentFiles) {
|
||||||
for (let i = 0; i < this.currentFiles.length; i++) {
|
for (let i = 0; i < this.currentFiles.length; i++) {
|
||||||
const fileInfo = this.currentFiles[i];
|
const fileInfo = this.currentFiles[i];
|
||||||
this.downloadFilesService.uploadFiles.push(fileInfo);
|
this.downloadFilesService.uploadFiles.push(fileInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.fileDataError = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks the file type and returns the corresponding icon.
|
* Checks the file type and returns the corresponding icon.
|
||||||
|
* Img (1): PNG, GIF, JPG, JPEG
|
||||||
|
* Files (3): PDF
|
||||||
|
* Files (0): DOC, DOCX
|
||||||
|
* Audio (2): MP3, WAV
|
||||||
|
* Video (4): MP4, WMV, AVI
|
||||||
* @param fileInfo The file object.
|
* @param fileInfo The file object.
|
||||||
* @returns The file icon path.
|
* @returns The file icon path.
|
||||||
*/
|
*/
|
||||||
checkIcon(fileInfo: any) {
|
checkIcon(fileInfo: { type: string }) {
|
||||||
if (fileInfo.type == 'audio/mpeg') {
|
const fileTypeMap: Record<string, number> = {
|
||||||
return this.getFileIcons[2];
|
'audio/mpeg': 2,
|
||||||
} else if (fileInfo.type == 'image/jpeg') {
|
'audio/wav': 2,
|
||||||
return this.getFileIcons[1];
|
'image/jpg': 1,
|
||||||
} else if (fileInfo.type == 'application/pdf') {
|
'image/jpeg': 1,
|
||||||
return this.getFileIcons[3];
|
'image/png': 1,
|
||||||
} else if (fileInfo.type == 'video/mp4') {
|
'image/gif': 1,
|
||||||
return this.getFileIcons[4];
|
'application/pdf': 3,
|
||||||
} else {
|
'application/msword': 0,
|
||||||
return this.getFileIcons[0];
|
'application/doc': 0,
|
||||||
}
|
'application/ms-doc': 0,
|
||||||
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 0,
|
||||||
|
'video/mp4': 4,
|
||||||
|
'video/x-ms-wmv': 4,
|
||||||
|
'video/avi': 4,
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.getFileIcons[fileTypeMap[fileInfo.type] ?? 5];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,8 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
"channel-msg-box": {
|
"channel-msg-box": {
|
||||||
"text": "Die maximale Anzahl an Dateien beträgt 1.",
|
"text0": "Maximal eine Datei pro Nachricht",
|
||||||
|
"text1": "Dieses Dateiformat ist ungültig",
|
||||||
"placeholder": "Geben Sie Ihre Nachricht ein"
|
"placeholder": "Geben Sie Ihre Nachricht ein"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,8 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
"channel-msg-box": {
|
"channel-msg-box": {
|
||||||
"text": "The maximum number of files is 1.",
|
"text0": "Maximum one file per message",
|
||||||
|
"text1": "This file format is invalid",
|
||||||
"placeholder": "Enter your message"
|
"placeholder": "Enter your message"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue