Cleaner activation with Angular directives

This commit is contained in:
Michael Shamoon 2022-03-11 14:21:18 -08:00
parent 3acc65ca0d
commit 7562636151
3 changed files with 39 additions and 40 deletions

View File

@ -3,9 +3,11 @@
<ngx-file-drop dropZoneClassName="main-dropzone" contentClassName="main-content" [disabled]="!dragDropEnabled" <ngx-file-drop dropZoneClassName="main-dropzone" contentClassName="main-content" [disabled]="!dragDropEnabled"
(onFileDrop)="dropped($event)" (onFileOver)="fileOver()" (onFileLeave)="fileLeave()"> (onFileDrop)="dropped($event)" (onFileOver)="fileOver()" (onFileLeave)="fileLeave()">
<ng-template ngx-file-drop-content-tmp> <ng-template ngx-file-drop-content-tmp>
<div class="global-dropzone-overlay"> <div class="global-dropzone-overlay fade" [class.show]="fileIsOver" [class.hide]="hidden">
<h1 class="display-6">Drop files to begin upload</h1> <h2>Drop files to begin upload</h2>
</div>
<div [class.inert]="fileIsOver">
<router-outlet></router-outlet>
</div> </div>
<router-outlet></router-outlet>
</ng-template> </ng-template>
</ngx-file-drop> </ngx-file-drop>

View File

@ -1,11 +1,5 @@
import { SettingsService, SETTINGS_KEYS } from './services/settings.service' import { SettingsService, SETTINGS_KEYS } from './services/settings.service'
import { import { Component, OnDestroy, OnInit } from '@angular/core'
Component,
OnDestroy,
OnInit,
Renderer2,
RendererFactory2,
} from '@angular/core'
import { Router } from '@angular/router' import { Router } from '@angular/router'
import { Subscription } from 'rxjs' import { Subscription } from 'rxjs'
import { ConsumerStatusService } from './services/consumer-status.service' import { ConsumerStatusService } from './services/consumer-status.service'
@ -23,22 +17,20 @@ export class AppComponent implements OnInit, OnDestroy {
successSubscription: Subscription successSubscription: Subscription
failedSubscription: Subscription failedSubscription: Subscription
private renderer: Renderer2
private fileLeaveTimeoutID: any private fileLeaveTimeoutID: any
fileIsOver: boolean = false
hidden: boolean = true
constructor( constructor(
private settings: SettingsService, private settings: SettingsService,
private consumerStatusService: ConsumerStatusService, private consumerStatusService: ConsumerStatusService,
private toastService: ToastService, private toastService: ToastService,
private router: Router, private router: Router,
private uploadDocumentsService: UploadDocumentsService, private uploadDocumentsService: UploadDocumentsService
rendererFactory: RendererFactory2
) { ) {
let anyWindow = window as any let anyWindow = window as any
anyWindow.pdfWorkerSrc = 'assets/js/pdf.worker.min.js' anyWindow.pdfWorkerSrc = 'assets/js/pdf.worker.min.js'
this.settings.updateAppearanceSettings() this.settings.updateAppearanceSettings()
this.renderer = rendererFactory.createRenderer(null, null)
} }
ngOnDestroy(): void { ngOnDestroy(): void {
@ -121,27 +113,29 @@ export class AppComponent implements OnInit, OnDestroy {
} }
public fileOver() { public fileOver() {
this.renderer.addClass( // allows transition
document.getElementsByClassName('main-content').item(0), setTimeout(() => {
'inert' this.fileIsOver = true
) }, 1)
this.hidden = false
// stop fileLeave timeout
clearTimeout(this.fileLeaveTimeoutID) clearTimeout(this.fileLeaveTimeoutID)
} }
public fileLeave() { public fileLeave(immediate: boolean = false) {
const ms = immediate ? 0 : 500
this.fileLeaveTimeoutID = setTimeout(() => { this.fileLeaveTimeoutID = setTimeout(() => {
this.renderer.removeClass( this.fileIsOver = false
document.getElementsByClassName('main-content').item(0), // await transition completed
'inert' setTimeout(() => {
) this.hidden = true
}, 1000) }, 150)
}, ms)
} }
public dropped(files: NgxFileDropEntry[]) { public dropped(files: NgxFileDropEntry[]) {
this.renderer.removeClass( this.fileLeave(true)
document.getElementsByClassName('main-content').item(0),
'inert'
)
this.uploadDocumentsService.uploadFiles(files) this.uploadDocumentsService.uploadFiles(files)
this.toastService.showInfo($localize`Initiating upload...`, 3000) this.toastService.showInfo($localize`Initiating upload...`, 3000)
} }

View File

@ -255,24 +255,27 @@ table.table {
right: 0; right: 0;
bottom: 0; bottom: 0;
left: 0; left: 0;
background-color: rgba(23, 84, 31, .7); background-color: rgba(23, 84, 31, .8);
// z-index: $zindex-modal; // 1055 z-index: 1055; // $zindex-modal
z-index: 1055;
opacity: 0;
pointer-events: none !important; pointer-events: none !important;
user-select: none !important; user-select: none !important;
text-align: center; text-align: center;
padding-top: 25%; padding-top: 25%;
transition: opacity 0.2s ease;
}
.main-dropzone.ngx-file-drop__drop-zone--over { &.show {
.global-dropzone-overlay { opacity: 1 !important;
opacity: 1; }
&.hide {
display: none;
} }
} }
.main-content.inert { .ngx-file-drop__drop-zone--over .global-dropzone-overlay {
opacity: 0;
}
.inert {
pointer-events: none !important; pointer-events: none !important;
user-select: none !important; user-select: none !important;
} }