Skip to content

Commit

Permalink
added more logic popup messages geneontology/noctua-annotation-review#30
Browse files Browse the repository at this point in the history
  • Loading branch information
tmushayahama committed Jan 22, 2021
1 parent 4dd3eb0 commit c0f774a
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 82 deletions.
215 changes: 154 additions & 61 deletions src/@noctua.search/components/art-basket/art-basket.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,31 +72,18 @@ export class ArtBasketComponent implements OnInit, OnDestroy {
this._unsubscribeAll.complete();
}

selectItem(artBasketItem: ArtBasketItem) {
this.camsService.onSelectedCamChanged.next(artBasketItem.id);
const q = '#noc-review-cams-' + artBasketItem.displayId;
this.noctuaSearchMenuService.scrollTo(q);
}

remove(cam: Cam) {
cancel() {
const self = this;

const success = (done) => {
}

this.confirmDialogService.openConfirmDialog('Model Unsaved Changes',
'Please Save Changes or Undo Changes before removing it.',
success);
}

clear() {

const success = (cancel) => {
if (cancel) {
const element = document.querySelector('#noc-review-results');

if (element) {
element.scrollTop = 0;
}
this.noctuaReviewSearchService.clear();
this.camsService.clearCams();
this.noctuaReviewSearchService.clearBasket();
this.noctuaReviewSearchService.onResetReview.next(true);
}
};

Expand All @@ -105,62 +92,139 @@ export class ArtBasketComponent implements OnInit, OnDestroy {
confirmLabel: 'Yes'
};

this.confirmDialogService.openConfirmDialog('Confirm Clear Basket?',
'You are about to remove all items from the basket. All your unsaved changes will be lost.',
this.confirmDialogService.openConfirmDialog('Confirm Cancel?',
'You are about to cancel annotation review. All your unsaved changes will be lost.',
success, options);
}

backToReview() {
this.noctuaSearchMenuService.selectMiddlePanel(MiddlePanel.camsReview);
}

cancel() {
clear() {
const self = this;

const success = (cancel) => {
if (cancel) {
const element = document.querySelector('#noc-review-results');

if (element) {
element.scrollTop = 0;
}
this.noctuaReviewSearchService.clear();
this.noctuaReviewSearchService.onResetReview.next(true);
this.camsService.clearCams();
this.noctuaReviewSearchService.clearBasket();
}
};

const options = {
cancelLabel: 'No',
confirmLabel: 'Yes'
};
if (self.summary?.stats.totalChanges > 0) {
const options = {
title: 'Confirm Clear Basket?',
message: 'You are about to remove all items from the basket. All your unsaved changes will be lost. Please save changes or undo changes.',
cancelLabel: 'Go Back',
confirmLabel: 'Clear Anyway'
};

self.noctuaSearchDialogService.openCamReviewChangesDialog(success, self.summary, options)
} else {
const options = {
cancelLabel: 'No',
confirmLabel: 'Yes'
};

this.confirmDialogService.openConfirmDialog('Confirm Clear Basket?',
'You are about to remove all items from the basket. All your unsaved changes will be lost.',
success, options);
}
}

this.confirmDialogService.openConfirmDialog('Confirm Cancel?',
'You are about to cancel annotation review. All your unsaved changes will be lost.',
success, options);
close() {
this.noctuaSearchMenuService.closeLeftDrawer();
}


remove(cam: Cam) {
const self = this;
const summary = self.camsService.reviewCamChanges(cam)
const success = (ok) => {
if (ok) {
this.camsService.removeCamFromReview(cam);
this.noctuaReviewSearchService.removeFromArtBasket(cam.id);
}
}

if (summary?.stats.totalChanges > 0) {
const options = {
title: 'Removing Unsaved Model',
message: `Please save changes or undo changes before removing model. Model Name:"${cam.title}"`,
cancelLabel: 'Cancel',
confirmLabel: 'Remove Anyway'
}

self.noctuaSearchDialogService.openCamReviewChangesDialog(success, summary, options)
} else {
const options = {
cancelLabel: 'No',
confirmLabel: 'Yes'
};

this.confirmDialogService.openConfirmDialog('Removing Unsaved Model?',
`You are about to remove model from the basket. No changes were made. Model Name:"${cam.title}"`,
success, options);
}
}

resetCam(cam: Cam) {
const self = this;

self.camsService.resetCam(cam).subscribe((cams) => {
if (cams) {
self.camsService.loadCams();
self.noctuaReviewSearchService.onReplaceChanged.next(true);
self.camsService.reviewChanges();
const summary = self.camsService.reviewCamChanges(cam);

if (summary?.stats.totalChanges > 0) {

const success = (ok) => {
if (ok) {
self.camsService.resetCam(cam).subscribe((cams) => {
if (cams) {
self.camsService.loadCams();
self.noctuaReviewSearchService.onReplaceChanged.next(true);
self.camsService.reviewChanges();
}
});
}
}

const options = {
title: 'Discard Unsaved Changes',
message: `All your changes will be discarded for model. Model Name:"${cam.title}"`,
cancelLabel: 'Cancel',
confirmLabel: 'OK'
}
});

self.noctuaSearchDialogService.openCamReviewChangesDialog(success, summary, options)
}
}

resetCams() {
const self = this;

self.camsService.resetCams().subscribe((cams) => {
if (cams) {
self.camsService.loadCams();
self.noctuaReviewSearchService.onReplaceChanged.next(true);
self.camsService.reviewChanges();
if (self.summary?.stats.totalChanges > 0) {

const success = (ok) => {
if (ok) {
self.camsService.resetCams().subscribe((cams) => {
if (cams) {
self.camsService.loadCams();
self.noctuaReviewSearchService.onReplaceChanged.next(true);
self.camsService.reviewChanges();
}
});
}
}

const options = {
title: 'Discard Unsaved Changes',
message: `All your changes will be discarded.`,
cancelLabel: 'Cancel',
confirmLabel: 'OK'
}
});

self.noctuaSearchDialogService.openCamReviewChangesDialog(success, self.summary, options)
}
}

reviewChanges() {
Expand All @@ -181,22 +245,52 @@ export class ArtBasketComponent implements OnInit, OnDestroy {

}

selectItem(artBasketItem: ArtBasketItem) {
this.camsService.onSelectedCamChanged.next(artBasketItem.id);
const q = '#noc-review-cams-' + artBasketItem.displayId;
this.noctuaSearchMenuService.scrollTo(q);
}

submitChanges() {
const self = this;

this.storeModels(self.camsService.cams, true)
}

submitChange(cam: Cam) {
this.storeModels([cam])
}

const self = this;
const summary = self.camsService.reviewCamChanges(cam);

if (summary?.stats.totalChanges > 0) {
const success = (replace) => {
if (replace) {

self.camsService.storeModels([cam]).pipe(takeUntil(this._unsubscribeAll))
.subscribe(cams => {
if (!cams) {
return;
}

close() {
this.noctuaSearchMenuService.closeLeftDrawer();
self.zone.run(() => {
self.confirmDialogService.openSuccessfulSaveToast('Changes successfully saved.', 'OK');
});
});
}
};

const options = {
title: 'Save Changes?',
message: `All your changes will be saved for model. Model Name:"${cam.title}"`,
cancelLabel: 'Go Back',
confirmLabel: 'Submit'
}

self.noctuaSearchDialogService.openCamReviewChangesDialog(success, summary, options)
}
}


private storeModels(cams: Cam[], reset = false) {
const self = this;
const success = (replace) => {
Expand Down Expand Up @@ -227,17 +321,16 @@ export class ArtBasketComponent implements OnInit, OnDestroy {
}
};

const options = {
cancelLabel: 'Go Back',
confirmLabel: 'Submit'
};

if (self.summary) {
const occurrences = self.summary.stats.termsCount;
const models = self.summary.stats.camsCount;
this.confirmDialogService.openConfirmDialog('Save Changes?',
`Bulk edit ${occurrences} occurrences across ${models} models`,
success, options);
if (self.summary?.stats.totalChanges > 0) {
const options = {
title: 'Save Changes?',
message: `Bulk edit all changes`,
cancelLabel: 'Go Back',
confirmLabel: 'Submit'
}

self.noctuaSearchDialogService.openCamReviewChangesDialog(success, self.summary, options)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@
<mat-toolbar class="mat-primary m-0">
<mat-toolbar-row fxFlex fxLayout="row" fxLayoutAlign="start center">
<span class="title dialog-title">
Review Changes </span>
{{title}} </span>
<span fxFlex></span>
<button mat-stroked-button (click)="close()" class="noc-rounded-button noc-sm" aria-label="Close dialog">
<button mat-stroked-button (click)="cancel()" class="noc-rounded-button noc-sm" aria-label="Close dialog">
<mat-icon>close</mat-icon> Close
</button>
</mat-toolbar-row>
</mat-toolbar>
<div class="noc-dialog-body noc-form-section" noctuaPerfectScrollbar>
<div class="noc-stats-results" fxLayout="column" fxLayoutAlign="start center">
<div class="noc-stat-summary">
<span class="noc-number">
{{summary?.stats.totalChanges }}
</span>
changes across
<span class="noc-number">
{{summary?.stats.camsCount }} models
</span>
<div class="alert alert-warning w-100-p">
{{message}}
<div class="noc-stat-summary w-100-p">
<span class="noc-number">
{{summary?.stats.totalChanges }}
</span>
unsaved changes across
<span class="noc-number">
{{summary?.stats.camsCount }} model(s)
</span>
</div>
</div>
<table fxFlex="1 1 auto" mat-table class="noc-summary-table" [dataSource]="stats"
[@animateStagger]="{value:'50'}">
Expand Down Expand Up @@ -65,7 +68,14 @@
</div> -->
</div>
</div>
<div class="m-0 p-16 noc-dialog-footer" fxLayout="row" fxLayoutAlign="space-between center">
<button (click)='close()' type="button" mat-raised-button color="" class="mr-8">Close</button>
<div *ngIf="!readonlyDialog" class="m-0 p-16 noc-dialog-footer" fxLayout="row" fxLayoutAlign="space-between center">
<button (click)='cancel()' type="button" mat-raised-button color="" class="mr-8">
{{cancelLabel}}</button>
<button (click)="confirm()" type="button" mat-raised-button color="primary">
{{confirmLabel}}
</button>
</div>
<div *ngIf="readonlyDialog" class="m-0 p-16 noc-dialog-footer" fxLayout="row" fxLayoutAlign="space-between center">
<button (click)='cancel()' type="button" mat-raised-button color="" class="mr-8">Close</button>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export class CamsReviewChangesDialogComponent implements OnInit, OnDestroy {

summary;

public title = 'Review Changes';
public message: string;
public readonlyDialog = false;
public cancelLabel = 'Cancel'
public confirmLabel = 'Confirm'

displayedColumns = [
'category',
'count'
Expand All @@ -52,11 +58,14 @@ export class CamsReviewChangesDialogComponent implements OnInit, OnDestroy {

this._unsubscribeAll = new Subject();

this.summary = this._data.summary
if (_data.options) {
this.cancelLabel = _data.options.cancelLabel ? _data.options.cancelLabel : 'Cancel';
this.confirmLabel = _data.options.confirmLabel ? _data.options.confirmLabel : 'Confirm';
}

this.summary = this._data.summary
this.stats = this.generateStats(this.summary.stats);

console.log(this.summary);
}

ngOnInit(): void {
Expand Down Expand Up @@ -105,11 +114,11 @@ export class CamsReviewChangesDialogComponent implements OnInit, OnDestroy {
}
}

save() {
confirm() {
this._matDialogRef.close(true);
}

close() {
cancel() {
this._matDialogRef.close();
}
}
Loading

0 comments on commit c0f774a

Please sign in to comment.