mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Cleaner activation with Angular directives
This commit is contained in:
		| @@ -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> | ||||||
|   | |||||||
| @@ -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) | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -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; | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Michael Shamoon
					Michael Shamoon