diff --git a/src/ui/signinBanner/signinBanner.components.ts b/src/ui/signinBanner/signinBanner.components.ts index 6accb61a3afe43e514079dd23cd33ed8908bf800..2025b38e7ce95275b8a853b2f9dee44783a93d5f 100644 --- a/src/ui/signinBanner/signinBanner.components.ts +++ b/src/ui/signinBanner/signinBanner.components.ts @@ -1,4 +1,12 @@ -import {ChangeDetectionStrategy, Component, Input, TemplateRef } from "@angular/core"; +import { + ChangeDetectionStrategy, + ChangeDetectorRef, + Component, + ElementRef, + Input, + TemplateRef, + ViewChild +} from "@angular/core"; import { MatBottomSheet, MatDialog, MatDialogRef } from "@angular/material"; import { select, Store } from "@ngrx/store"; import { Observable } from "rxjs"; @@ -21,18 +29,22 @@ export class SigninBanner { @Input() public darktheme: boolean @Input() public parcellationIsSelected: boolean + @ViewChild('takeScreenshotElement', {read: ElementRef}) takeScreenshotElement: ElementRef + public user$: Observable<IUser> public userBtnTooltip$: Observable<string> public favDataEntries$: Observable<IDataEntry[]> public pluginTooltipText: string = `Plugins and Tools` public screenshotTooltipText: string = 'Take screenshot' + public takingScreenshot: boolean = false constructor( private store$: Store<IavRootStoreInterface>, private authService: AuthService, private dialog: MatDialog, public bottomSheet: MatBottomSheet, + private changeDetectionRef: ChangeDetectorRef, ) { this.user$ = this.authService.user$ @@ -60,6 +72,11 @@ export class SigninBanner { } } + disableScreenshotTaking() { + this.takingScreenshot = false + this.changeDetectionRef.detectChanges() + } + private keyListenerConfigBase = { type: 'keydown', stop: true, diff --git a/src/ui/signinBanner/signinBanner.template.html b/src/ui/signinBanner/signinBanner.template.html index 52f5ed744aa8cafc4b54771261d9ae42ef7eb374..34dc1f4553a12d20b721a202eb9680b30e18a7d8 100644 --- a/src/ui/signinBanner/signinBanner.template.html +++ b/src/ui/signinBanner/signinBanner.template.html @@ -51,7 +51,7 @@ <mat-menu #pluginDropdownMenu> <button mat-menu-item [disabled]="!parcellationIsSelected" - (click)="takeScreenshotElement.startScreenshot()" + (click)="takingScreenshot = true;" [matTooltip]="screenshotTooltipText"> <mat-icon fontSet="fas" fontIcon="fa-camera"> </mat-icon> @@ -126,15 +126,15 @@ </mat-dialog-actions> </ng-template> -<ng-template #settingTemplate> - <h2 mat-dialog-title>Settings</h2> - <mat-dialog-content> - <!-- required to avoid showing an ugly vertical scroll bar --> - <!-- TODO investigate why, then remove the friller class --> - <config-component class="mb-4 d-block"> - </config-component> - </mat-dialog-content> -</ng-template> +<ng-template #settingTemplate> + <h2 mat-dialog-title>Settings</h2> + <mat-dialog-content> + <!-- required to avoid showing an ugly vertical scroll bar --> + <!-- TODO investigate why, then remove the friller class --> + <config-component class="mb-4 d-block"> + </config-component> + </mat-dialog-content> +</ng-template> <!-- saved dataset tmpl --> @@ -172,5 +172,8 @@ <take-screenshot #takeScreenshotElement - class="position-fixed fixed-top"> + *ngIf="takingScreenshot" + class="position-fixed fixed-top" + (screenshotTaking)="disableScreenshotTaking()" + (resetScreenshot)="$event? takingScreenshot = true : disableScreenshotTaking()"> </take-screenshot> diff --git a/src/ui/takeScreenshot/takeScreenshot.component.ts b/src/ui/takeScreenshot/takeScreenshot.component.ts index 553bbed918ddc6dcb65a82379a0dcbad0cf36469..ca8ce997233a9715eea067c2786587cf96368ed6 100644 --- a/src/ui/takeScreenshot/takeScreenshot.component.ts +++ b/src/ui/takeScreenshot/takeScreenshot.component.ts @@ -2,10 +2,10 @@ import {DOCUMENT} from "@angular/common"; import { ChangeDetectorRef, Component, - ElementRef, + ElementRef, EventEmitter, HostListener, - Inject, - OnInit, + Inject, OnDestroy, + OnInit, Output, Renderer2, TemplateRef, ViewChild, @@ -19,11 +19,21 @@ import html2canvas from "html2canvas"; styleUrls: ['./takeScreenshot.style.css'], }) -export class TakeScreenshotComponent implements OnInit { +export class TakeScreenshotComponent implements OnInit, OnDestroy { + + ngOnDestroy(): void { + if (this.resettingScreenshotTaking) this.resetScreenshot.emit(true) + this.resettingScreenshotTaking = false + } @ViewChild('screenshotPreviewCard', {read: ElementRef}) public screenshotPreviewCard: ElementRef @ViewChild('previewImageDialog', {read: TemplateRef}) public previewImageDialogTemplateRef: TemplateRef<any> + @Output() screenshotTaking: EventEmitter<boolean> = new EventEmitter<boolean>() + @Output() resetScreenshot: EventEmitter<boolean> = new EventEmitter<boolean>() + + private resettingScreenshotTaking: boolean = false + private dialogRef: MatDialogRef<any> public takingScreenshot: boolean = false @@ -67,6 +77,9 @@ export class TakeScreenshotComponent implements OnInit { public ngOnInit(): void { this.windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth this.windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight + + this.startScreenshot() + } @HostListener('window:resize', ['$event']) @@ -201,6 +214,7 @@ export class TakeScreenshotComponent implements OnInit { .then(result => { switch (result) { case 'again': { + this.restartScreenshot() this.startScreenshot() this.cdr.markForCheck() break @@ -241,12 +255,15 @@ export class TakeScreenshotComponent implements OnInit { }) } + public restartScreenshot() { + this.resettingScreenshotTaking = true + this.resetScreenshot.emit(false) + } + public cancelTakingScreenshot() { - this.takingScreenshot = false - this.previewingScreenshot = false - this.loadingScreenshot = false - this.croppedCanvas = null + this.screenshotTaking.emit(false) } + public clearStateAfterScreenshot() { this.mouseIsDown = false this.isDragging = false diff --git a/src/ui/takeScreenshot/takeScreenshot.template.html b/src/ui/takeScreenshot/takeScreenshot.template.html index 126211c98af9c64251303eaa7d833b77c9ca40e2..edbdcfa45775b870299274dc5f205b9902116a97 100644 --- a/src/ui/takeScreenshot/takeScreenshot.template.html +++ b/src/ui/takeScreenshot/takeScreenshot.template.html @@ -1,4 +1,4 @@ -<div class="screenshotContainer overflow-hidden w-100 h-100" +<div class="screenshotContainer overflow-hidden w-50 h-50" (mousemove)="move($event)" (mousedown)="mouseDown($event)" (mouseup)="mouseUp($event)"