-
Notifications
You must be signed in to change notification settings - Fork 4
[NAE-1907] - Prompt user before leaving/reloading site when data does not need to be saved #208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release/6.4.0
Are you sure you want to change the base?
Changes from 2 commits
c1440cf
f505217
a53cd20
29baa10
36d78d8
5c84d5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import {DataField} from './abstract-data-field'; | ||
import {FormControl} from '@angular/forms'; | ||
import {Component, Inject, Input, OnDestroy, OnInit, Optional} from '@angular/core'; | ||
import {Component, HostListener, Inject, Input, OnDestroy, OnInit, Optional} from '@angular/core'; | ||
import {NAE_INFORM_ABOUT_INVALID_DATA} from './invalid-data-policy-token'; | ||
import {NAE_SAVE_DATA_INFORM} from './save-data-inform-token'; | ||
|
||
/** | ||
* Holds the common functionality for all DataFieldComponents. | ||
|
@@ -24,8 +25,19 @@ export abstract class AbstractDataFieldComponent implements OnInit, OnDestroy { | |
*/ | ||
protected _formControl: FormControl; | ||
|
||
protected constructor(@Optional() @Inject(NAE_INFORM_ABOUT_INVALID_DATA) protected _informAboutInvalidData: boolean | null) { | ||
this._formControl = new FormControl('', { updateOn: 'blur' }); | ||
@HostListener('window:beforeunload', ['$event']) | ||
beforeUnloadEventHandler(event) { | ||
if (this._saveDataInform && this.dataField.isFocused()) { | ||
this.dataField.unsetFocus(); | ||
(document.activeElement as HTMLElement).blur(); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
protected constructor(@Optional() @Inject(NAE_INFORM_ABOUT_INVALID_DATA) protected _informAboutInvalidData: boolean | null, | ||
@Optional() @Inject(NAE_SAVE_DATA_INFORM) protected _saveDataInform: boolean | null = false) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. default value doesn't work |
||
this._formControl = new FormControl('', {updateOn: 'blur'}); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {InjectionToken} from '@angular/core'; | ||
|
||
/** | ||
* Whether invalid data values should be sent to backend or not. Invalid data is NOT set to backend by default. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bad doc |
||
* You can use this InjectionToken to override this behavior in a specific application scope. | ||
* | ||
* This token is ultimately injected by individual data fields, so this option can be in theory applied at a very low level of granularity. | ||
* The library implementation doesn't allow access to such low level components, so a custom implementation is necessary to provide this | ||
* token at such low level. Applying the token to individual task views is achievable with the default implementation. | ||
*/ | ||
export const NAE_SAVE_DATA_INFORM = new InjectionToken<boolean>('NaeSaveDataInform'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import {NumberField} from './models/number-field'; | |
import {AbstractDataFieldComponent} from '../models/abstract-data-field-component'; | ||
import {TranslateService} from '@ngx-translate/core'; | ||
import {NAE_INFORM_ABOUT_INVALID_DATA} from '../models/invalid-data-policy-token'; | ||
import {NAE_SAVE_DATA_INFORM} from '../models/save-data-inform-token'; | ||
|
||
@Component({ | ||
selector: 'ncc-abstract-number-field', | ||
|
@@ -13,8 +14,9 @@ export abstract class AbstractNumberFieldComponent extends AbstractDataFieldComp | |
@Input() public dataField: NumberField; | ||
|
||
protected constructor(protected _translate: TranslateService, | ||
@Optional() @Inject(NAE_INFORM_ABOUT_INVALID_DATA) informAboutInvalidData: boolean | null) { | ||
super(informAboutInvalidData); | ||
@Optional() @Inject(NAE_INFORM_ABOUT_INVALID_DATA) informAboutInvalidData: boolean | null, | ||
@Optional() @Inject(NAE_SAVE_DATA_INFORM) saveDataInform: boolean | null = false) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. default value in inheritance chain |
||
super(informAboutInvalidData, saveDataInform); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import {Component, Inject, Input, Optional} from '@angular/core'; | |
import {TextField} from './models/text-field'; | ||
import {AbstractDataFieldComponent} from '../models/abstract-data-field-component'; | ||
import {NAE_INFORM_ABOUT_INVALID_DATA} from '../models/invalid-data-policy-token'; | ||
import {NAE_SAVE_DATA_INFORM} from '../models/save-data-inform-token'; | ||
|
||
@Component({ | ||
selector: 'ncc-abstract-text-field', | ||
|
@@ -11,7 +12,8 @@ export abstract class AbstractTextFieldComponent extends AbstractDataFieldCompon | |
|
||
@Input() dataField: TextField; | ||
|
||
protected constructor(@Optional() @Inject(NAE_INFORM_ABOUT_INVALID_DATA) informAboutInvalidData: boolean | null) { | ||
super(informAboutInvalidData); | ||
protected constructor(@Optional() @Inject(NAE_INFORM_ABOUT_INVALID_DATA) informAboutInvalidData: boolean | null, | ||
@Optional() @Inject(NAE_SAVE_DATA_INFORM) saveDataInform: boolean | null = false) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. default value in inheritance chain |
||
super(informAboutInvalidData, saveDataInform); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,8 @@ | |
[placeholder]="textI18nField.placeholder ? textI18nField.placeholder : ''" | ||
[required]="textI18nField.behavior.required" | ||
[(ngModel)]="currentValue[selectedLanguage]" | ||
(blur)="setSelectedValue()"> | ||
(focusout)="setSelectedValue(); textI18nField.unsetFocus()" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider to use dedicated function for multiple functions call on output event. |
||
(focusin)="textI18nField.setFocus()"> | ||
<button mat-icon-button (click)="toggleFilled()" | ||
[matTooltip]="(filledShown ? 'dataField.i18n.hideTranslations' : 'dataField.i18n.showTranslations') | translate"> | ||
<mat-icon color="warn">{{filledShown ? 'arrow_drop_up' : 'arrow_drop_down'}}</mat-icon> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,9 @@ | |
[placeholder]="numberField.placeholder" | ||
[required]="numberField.behavior.required" | ||
(focusout)="onFocusOut($event)" | ||
(focusin)="onFocusIn()"> | ||
(focusin)="onFocusIn()" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. working correctly ? because there are assigned two different functions two times, isn't it better to assigned it like (focusin)="onFocusIn();numberField.setFocus()" ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider to use dedicated function for multiple functions call on output event. |
||
(focusout)="numberField.unsetFocus()" | ||
(focusin)="numberField.setFocus()"> | ||
<mat-hint>{{numberField.description}}</mat-hint> | ||
<mat-error *ngIf="numberField.isInvalid(formControlRef)">{{getErrorMessage()}}</mat-error> | ||
</mat-form-field> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,8 @@ export class EasymdeWrapperComponent implements OnDestroy, AfterViewInit, Contro | |
this._easyMDE = new EasyMDE(this.options); | ||
this._easyMDE.value(this.textAreaField.value); | ||
this._easyMDE.codemirror.on('change', this._onChange); | ||
this._easyMDE.codemirror.on('focus', () => this.textAreaField.setFocus()); | ||
this._easyMDE.codemirror.on('blur', () => this.textAreaField.unsetFocus()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it was tested ? is it working ? |
||
this.formControlRef.valueChanges.subscribe(value => { | ||
if (this._easyMDE) { | ||
if (!this._fromEditor) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
import {Component, Inject, Optional} from '@angular/core'; | ||
import {AbstractTextFieldComponent, NAE_INFORM_ABOUT_INVALID_DATA, TextFieldComponent as TextFieldComponentEnum} from '@netgrif/components-core'; | ||
import { | ||
AbstractTextFieldComponent, | ||
NAE_INFORM_ABOUT_INVALID_DATA, | ||
NAE_SAVE_DATA_INFORM, | ||
TextFieldComponent as TextFieldComponentEnum | ||
} from '@netgrif/components-core'; | ||
|
||
@Component({ | ||
selector: 'nc-text-field', | ||
|
@@ -10,7 +15,8 @@ export class TextFieldComponent extends AbstractTextFieldComponent { | |
|
||
textFieldComponentEnum = TextFieldComponentEnum; | ||
|
||
constructor(@Optional() @Inject(NAE_INFORM_ABOUT_INVALID_DATA) informAboutInvalidData: boolean | null) { | ||
super(informAboutInvalidData); | ||
constructor(@Optional() @Inject(NAE_INFORM_ABOUT_INVALID_DATA) informAboutInvalidData: boolean | null, | ||
@Optional() @Inject(NAE_SAVE_DATA_INFORM) saveDataInform: boolean | null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. default value in inheritance chain |
||
super(informAboutInvalidData, saveDataInform); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default value in inheritance chain