replace from ImageComponent to ImageDirective

This commit is contained in:
병준 박 2019-10-25 13:04:21 +09:00
parent 1f60c57239
commit c3fc458b0c
11 changed files with 137 additions and 148 deletions

View File

@ -40,7 +40,7 @@
#chatContextMenuTrigger="matMenuTrigger" #chatContextMenuTrigger="matMenuTrigger"
[matMenuTriggerFor]="chatContextMenu" [matMenuTriggerFor]="chatContextMenu"
></div> ></div>
<mat-menu #chatContextMenu="matMenu" [overlapTrigger]="false"> <mat-menu #chatContextMenu="matMenu" [hasBackdrop]="false">
<ng-template matMenuContent let-roomInfo="roomInfo"> <ng-template matMenuContent let-roomInfo="roomInfo">
<button mat-menu-item (click)="onSelectedRoom(roomInfo)"> <button mat-menu-item (click)="onSelectedRoom(roomInfo)">
대화방 열기 대화방 열기

View File

@ -26,7 +26,7 @@
#groupMenu="matMenu" #groupMenu="matMenu"
xPosition="after" xPosition="after"
yPosition="below" yPosition="below"
[overlapTrigger]="false" [hasBackdrop]="false"
> >
<button mat-menu-item (click)="onClickGroupMenu('GROUP_NEW')"> <button mat-menu-item (click)="onClickGroupMenu('GROUP_NEW')">
<mat-icon>group_add</mat-icon> <mat-icon>group_add</mat-icon>
@ -92,7 +92,7 @@
#profileContextMenuTrigger="matMenuTrigger" #profileContextMenuTrigger="matMenuTrigger"
[matMenuTriggerFor]="profileContextMenu" [matMenuTriggerFor]="profileContextMenu"
></div> ></div>
<mat-menu #profileContextMenu="matMenu" [overlapTrigger]="false"> <mat-menu #profileContextMenu="matMenu" [hasBackdrop]="false">
<ng-template matMenuContent let-userInfo="userInfo"> <ng-template matMenuContent let-userInfo="userInfo">
<button <button
mat-menu-item mat-menu-item
@ -155,7 +155,7 @@
#groupContextMenuTrigger="matMenuTrigger" #groupContextMenuTrigger="matMenuTrigger"
[matMenuTriggerFor]="groupContextMenu" [matMenuTriggerFor]="groupContextMenu"
></div> ></div>
<mat-menu #groupContextMenu="matMenu" [overlapTrigger]="false"> <mat-menu #groupContextMenu="matMenu" [hasBackdrop]="false">
<ng-template matMenuContent let-group="group"> <ng-template matMenuContent let-group="group">
<button mat-menu-item (click)="onClickGroupContextMenu('CHAT', group)"> <button mat-menu-item (click)="onClickGroupContextMenu('CHAT', group)">
그룹 대화하기 그룹 대화하기

View File

@ -41,7 +41,7 @@
<mat-icon>more_vert</mat-icon> <mat-icon>more_vert</mat-icon>
</button> </button>
<mat-menu #contactMenu="matMenu"> <mat-menu #contactMenu="matMenu" [hasBackdrop]="false">
<button mat-menu-item (click)="onClickContextMenu('CLOSE_ROOM')"> <button mat-menu-item (click)="onClickContextMenu('CLOSE_ROOM')">
방닫기 방닫기
</button> </button>
@ -113,7 +113,7 @@
#messageContextMenuTrigger="matMenuTrigger" #messageContextMenuTrigger="matMenuTrigger"
[matMenuTriggerFor]="messageContextMenu" [matMenuTriggerFor]="messageContextMenu"
></div> ></div>
<mat-menu #messageContextMenu="matMenu" [overlapTrigger]="false"> <mat-menu #messageContextMenu="matMenu" [hasBackdrop]="false">
<ng-template matMenuContent let-message="message" let-loginRes="loginRes"> <ng-template matMenuContent let-message="message" let-loginRes="loginRes">
<ng-container *ngIf="!isRecalledMessage(message.type)"> <ng-container *ngIf="!isRecalledMessage(message.type)">
<button <button

View File

@ -8,7 +8,6 @@
contact: message.senderSeq !== loginRes.userSeq contact: message.senderSeq !== loginRes.userSeq
}" }"
> >
<ucap-chat-message-box-date-splitter <ucap-chat-message-box-date-splitter
*ngIf="getDateSplitter(i)" *ngIf="getDateSplitter(i)"
class="date-splitter" class="date-splitter"
@ -50,7 +49,10 @@
</ng-container> </ng-container>
</ng-template> </ng-template>
<ng-template #contents> <ng-template #contents>
<div *ngIf="getUserProfile(message.senderSeq) != ''" class="profile-img"> <div
*ngIf="getUserProfile(message.senderSeq) != ''"
class="profile-img"
>
<!-- <img <!-- <img
class="avatar" class="avatar"
style="width: 50px; height: 50px;" style="width: 50px; height: 50px;"
@ -64,13 +66,21 @@
| async | async
" "
/> --> /> -->
<ucap-ui-imaage <img
class="avatar"
style="width: 50px; height: 50px;"
ucapUiImage
[base]="profileImageRoot"
[path]="getUserProfile(message.senderSeq)"
[default]="'assets/images/img_nophoto_50.png'"
/>
<!-- <ucap-ui-imaage
[style]="'width: 50px; height: 50px;'" [style]="'width: 50px; height: 50px;'"
[imageClass]="'avatar'" [imageClass]="'avatar'"
[base]="profileImageRoot" [base]="profileImageRoot"
[path]="getUserProfile(message.senderSeq)" [path]="getUserProfile(message.senderSeq)"
[default]="'assets/images/img_nophoto_50.png'" [default]="'assets/images/img_nophoto_50.png'"
></ucap-ui-imaage> ></ucap-ui-imaage> -->
</div> </div>
<div class="message-main"> <div class="message-main">

View File

@ -21,13 +21,20 @@
| async | async
" "
/> --> /> -->
<img
class="thumbnail"
ucapUiImage
[base]="profileImageRoot"
[path]="userInfo.profileImageFile"
[default]="'assets/images/img_nophoto_50.png'"
/>
<ucap-ui-imaage <!-- <ucap-ui-imaage
[imageClass]="'thumbnail'" [imageClass]="'thumbnail'"
[base]="profileImageRoot" [base]="profileImageRoot"
[path]="userInfo.profileImageFile" [path]="userInfo.profileImageFile"
[default]="'assets/images/img_nophoto_50.png'" [default]="'assets/images/img_nophoto_50.png'"
></ucap-ui-imaage> ></ucap-ui-imaage> -->
</dt> </dt>
<dd class="info"> <dd class="info">
<div class="detail"> <div class="detail">
@ -46,8 +53,7 @@
> >
{{ userInfo.intro }} {{ userInfo.intro }}
</div> </div>
--> --></dd>
</dd>
</dl> </dl>
<mat-checkbox <mat-checkbox
*ngIf="checkable" *ngIf="checkable"

View File

@ -2,12 +2,19 @@
<dl class="item-default"> <dl class="item-default">
<dt> <dt>
<!-- <img class="thumbnail" /> --> <!-- <img class="thumbnail" /> -->
<ucap-ui-imaage <img
class="thumbnail"
ucapUiImage
[base]="sessionVerinfo.profileRoot"
[path]="imagePath"
[default]="defaultPath"
/>
<!-- <ucap-ui-imaage
[imageClass]="'thumbnail'" [imageClass]="'thumbnail'"
[base]="sessionVerinfo.profileRoot" [base]="sessionVerinfo.profileRoot"
[path]="imagePath" [path]="imagePath"
[default]="defaultPath" [default]="defaultPath"
></ucap-ui-imaage> ></ucap-ui-imaage> -->
</dt> </dt>
<dd class="info"> <dd class="info">
<div class="detail"> <div class="detail">

View File

@ -1,24 +0,0 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ImageComponent } from './image.component';
describe('UI::ImageComponent', () => {
let component: ImageComponent;
let fixture: ComponentFixture<ImageComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ImageComponent]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ImageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,94 +0,0 @@
import { Component, OnInit, Input, ElementRef } from '@angular/core';
import { DomSanitizer, SafeStyle } from '@angular/platform-browser';
import { NGXLogger } from 'ngx-logger';
import { ucapAnimations } from '../animations';
@Component({
selector: 'ucap-ui-imaage',
template: `
<img #imageElement [src]="imageSrc" [style]="baseStyle" [class]="classes" />
`,
animations: ucapAnimations
})
export class ImageComponent implements OnInit {
@Input()
base: string;
@Input()
path: string;
@Input()
validation = true;
@Input()
default: string;
@Input()
set style(style: string) {
this.logger.debug('style', style);
this.baseStyle = style;
}
@Input()
set imageClass(classes: string) {
// if (classes && classes.length) {
// classes.split(' ').forEach((className: string) => {
// this.classList[className] = true;
// });
// this.elementRef.nativeElement.className = '';
// }
this.classes = classes;
}
baseStyle: SafeStyle;
imageSrc: string;
// classList: { [key: string]: boolean } = {};
classes: string;
constructor(
private elementRef: ElementRef<HTMLElement>,
private domSanitizer: DomSanitizer,
private logger: NGXLogger
) {
this.imageSrc = null;
}
ngOnInit() {
if (this.validation) {
if (
!this.base ||
'' === this.base.trim() ||
!this.path ||
'' === this.path.trim()
) {
this.imageSrc = this.default;
}
}
if (!this.imageSrc) {
this.imageSrc = this.default;
const imageUrl = `${this.base}${this.path}`;
const image = new Image();
image.onload = () => {
if ('naturalHeight' in image) {
if (image.naturalHeight + image.naturalWidth === 0) {
image.onerror('naturalHeight');
return;
}
}
if (image.width + image.height === 0) {
image.onerror('width');
return;
}
this.imageSrc = image.src;
};
image.onerror = () => {
this.imageSrc = this.default;
};
image.src = imageUrl;
}
}
}

View File

@ -0,0 +1,83 @@
import {
Directive,
ElementRef,
EventEmitter,
Output,
Input,
AfterViewInit,
OnInit,
HostListener
} from '@angular/core';
import { NGXLogger } from 'ngx-logger';
@Directive({
selector: 'img[ucapUiImage]'
})
export class ImageDirective implements OnInit, AfterViewInit {
@Input()
base: string;
@Input()
path: string;
@Input()
validation = true;
@Input()
default: string;
@Output()
loaded = new EventEmitter<string>();
imageSrc: string;
constructor(
private elementRef: ElementRef<HTMLImageElement>,
private logger: NGXLogger
) {}
ngOnInit(): void {
if (this.validation) {
if (
!this.base ||
'' === this.base.trim() ||
!this.path ||
'' === this.path.trim()
) {
this.imageSrc = this.default;
}
}
}
ngAfterViewInit(): void {
if (this.imageSrc === this.default) {
this.elementRef.nativeElement.src = this.default;
this.loaded.emit(this.elementRef.nativeElement.src);
} else {
this.elementRef.nativeElement.src = this.default;
const imageUrl = `${this.base}${this.path}`;
const image = new Image();
image.onload = () => {
if ('naturalHeight' in image) {
if (image.naturalHeight + image.naturalWidth === 0) {
image.onerror('naturalHeight');
return;
}
}
if (image.width + image.height === 0) {
image.onerror('width');
return;
}
this.elementRef.nativeElement.src = image.src;
this.loaded.emit(this.elementRef.nativeElement.src);
};
image.onerror = () => {
this.elementRef.nativeElement.src = this.default;
this.loaded.emit(this.elementRef.nativeElement.src);
};
image.src = imageUrl;
}
}
}

View File

@ -12,13 +12,24 @@ import { MatSnackBarModule } from '@angular/material/snack-bar';
import { DragDropModule } from '@angular/cdk/drag-drop'; import { DragDropModule } from '@angular/cdk/drag-drop';
import { FileUploadQueueComponent } from './components/file-upload-queue.component'; import { FileUploadQueueComponent } from './components/file-upload-queue.component';
import { ImageComponent } from './components/image.component';
const COMPONENTS = [ImageComponent, FileUploadQueueComponent];
import { BottomSheetService } from './services/bottom-sheet.service'; import { BottomSheetService } from './services/bottom-sheet.service';
import { ClipboardService } from './services/clipboard.service'; import { ClipboardService } from './services/clipboard.service';
import { DialogService } from './services/dialog.service'; import { DialogService } from './services/dialog.service';
import { SnackBarService } from './services/snack-bar.service'; import { SnackBarService } from './services/snack-bar.service';
import { FileUploadForDirective } from './directives/file-upload-for.directive';
import { ImageDirective } from './directives/image.directive';
import { AlertDialogComponent } from './dialogs/alert.dialog.component';
import { ConfirmDialogComponent } from './dialogs/confirm.dialog.component';
import { BytesPipe } from './pipes/bytes.pipe';
const COMPONENTS = [FileUploadQueueComponent];
const DIALOGS = [AlertDialogComponent, ConfirmDialogComponent];
const DIRECTIVES = [FileUploadForDirective, ImageDirective];
const PIPES = [BytesPipe];
const SERVICES = [ const SERVICES = [
BottomSheetService, BottomSheetService,
ClipboardService, ClipboardService,
@ -26,16 +37,6 @@ const SERVICES = [
SnackBarService SnackBarService
]; ];
import { FileUploadForDirective } from './directives/file-upload-for.directive';
const DIRECTIVES = [FileUploadForDirective];
import { AlertDialogComponent } from './dialogs/alert.dialog.component';
import { ConfirmDialogComponent } from './dialogs/confirm.dialog.component';
const DIALOGS = [AlertDialogComponent, ConfirmDialogComponent];
import { BytesPipe } from './pipes/bytes.pipe';
const PIPES = [BytesPipe];
@NgModule({ @NgModule({
imports: [ imports: [
CommonModule, CommonModule,

View File

@ -5,12 +5,12 @@
export * from './lib/animations'; export * from './lib/animations';
export * from './lib/components/file-upload-queue.component'; export * from './lib/components/file-upload-queue.component';
export * from './lib/components/image.component';
export * from './lib/dialogs/alert.dialog.component'; export * from './lib/dialogs/alert.dialog.component';
export * from './lib/dialogs/confirm.dialog.component'; export * from './lib/dialogs/confirm.dialog.component';
export * from './lib/directives/file-upload-for.directive'; export * from './lib/directives/file-upload-for.directive';
export * from './lib/directives/image.directive';
export * from './lib/services/bottom-sheet.service'; export * from './lib/services/bottom-sheet.service';
export * from './lib/services/clipboard.service'; export * from './lib/services/clipboard.service';