-
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 4 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 |
---|---|---|
|
@@ -4,6 +4,7 @@ import {Component, Inject, Optional} from '@angular/core'; | |
import {LanguageIconsService} from './language-icons.service'; | ||
import {AbstractBaseDataFieldComponent} from "../base-component/abstract-base-data-field.component"; | ||
import {DATA_FIELD_PORTAL_DATA, DataFieldPortalData} from "../models/data-field-portal-data-injection-token"; | ||
import {NAE_SAVE_DATA_INFORM} from "../models/save-data-inform-token"; | ||
|
||
|
||
@Component({ | ||
|
@@ -15,8 +16,9 @@ export abstract class AbstractI18nErrorsComponent extends AbstractBaseDataFieldC | |
|
||
protected constructor(protected languageIconsService: LanguageIconsService, | ||
protected _translate: TranslateService, | ||
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<I18nField>) { | ||
super(dataFieldPortalData); | ||
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<I18nField>, | ||
@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. I believe the default value (even if it doesn't work) should be provided only at the class that introduces the dependency ( 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. Corrected. |
||
super(dataFieldPortalData, _saveDataInform); | ||
} | ||
|
||
getErrorMessage() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import {Component, Inject, Input, Optional} from '@angular/core'; | |
import {AbstractDataFieldComponent} from '../models/abstract-data-field-component'; | ||
import {NAE_INFORM_ABOUT_INVALID_DATA} from '../models/invalid-data-policy-token'; | ||
import {I18nField} from './models/i18n-field'; | ||
import {NAE_SAVE_DATA_INFORM} from '../models/save-data-inform-token'; | ||
|
||
/** | ||
* @deprecated | ||
|
@@ -14,7 +15,8 @@ export abstract class AbstractI18nFieldComponent extends AbstractDataFieldCompon | |
|
||
@Input() dataField: I18nField; | ||
|
||
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 = 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 |
---|---|---|
|
@@ -8,6 +8,7 @@ import {AbstractI18nErrorsComponent} from '../abstract-i18n-errors.component'; | |
import {LanguageIcons} from '../models/language-icons'; | ||
import {I18nFieldTranslations} from '../models/i18n-field-value'; | ||
import {DATA_FIELD_PORTAL_DATA, DataFieldPortalData} from "../../models/data-field-portal-data-injection-token"; | ||
import {NAE_SAVE_DATA_INFORM} from "../../models/save-data-inform-token"; | ||
|
||
@Component({ | ||
selector: 'ncc-abstract-i18n-text-field', | ||
|
@@ -34,8 +35,9 @@ export abstract class AbstractI18nTextFieldComponent extends AbstractI18nErrorsC | |
protected constructor(protected languageIconsService: LanguageIconsService, | ||
protected _translateService: TranslateService, | ||
protected _domSanitizer: DomSanitizer, | ||
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<I18nField>) { | ||
super(languageIconsService, _translateService, dataFieldPortalData); | ||
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<I18nField>, | ||
@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(languageIconsService, _translateService, dataFieldPortalData, _saveDataInform); | ||
this.selectedLanguage = this._translateService.currentLang; | ||
this.languageKeys = Object.keys(this.languageIconsService.languageIcons); | ||
} | ||
|
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'; | ||
|
||
/** | ||
* @deprecated as of v6.4.0 | ||
|
@@ -25,8 +26,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 {TranslateService} from '@ngx-translate/core'; | |
import {Component, Inject, Optional} from '@angular/core'; | ||
import {AbstractBaseDataFieldComponent} from "../base-component/abstract-base-data-field.component"; | ||
import {DATA_FIELD_PORTAL_DATA, DataFieldPortalData} from "../models/data-field-portal-data-injection-token"; | ||
import {NAE_SAVE_DATA_INFORM} from "../models/save-data-inform-token"; | ||
|
||
@Component({ | ||
selector: 'ncc-abstract-number-errors-field', | ||
|
@@ -11,8 +12,9 @@ import {DATA_FIELD_PORTAL_DATA, DataFieldPortalData} from "../models/data-field- | |
export abstract class AbstractNumberErrorsComponent extends AbstractBaseDataFieldComponent<NumberField>{ | ||
|
||
protected constructor(protected _translate: TranslateService, | ||
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<NumberField>) { | ||
super(dataFieldPortalData); | ||
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<NumberField>, | ||
@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 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. Corrected in all cases. |
||
super(dataFieldPortalData, _saveDataInform); | ||
} | ||
|
||
getErrorMessage() { | ||
|
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'; | ||
|
||
/** | ||
* @deprecated | ||
|
@@ -16,8 +17,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 |
---|---|---|
|
@@ -4,6 +4,7 @@ import {CurrencyPipe, getCurrencySymbol} from '@angular/common'; | |
import {AbstractNumberErrorsComponent} from '../abstract-number-errors.component'; | ||
import {DATA_FIELD_PORTAL_DATA, DataFieldPortalData} from "../../models/data-field-portal-data-injection-token"; | ||
import {NumberField} from "../models/number-field"; | ||
import {NAE_SAVE_DATA_INFORM} from "../../models/save-data-inform-token"; | ||
|
||
@Component({ | ||
selector: 'ncc-abstract-currency-field', | ||
|
@@ -18,8 +19,9 @@ export abstract class AbstractCurrencyNumberFieldComponent extends AbstractNumbe | |
public readonly WHITESPACE = ' '; | ||
|
||
protected constructor(protected _currencyPipe: CurrencyPipe, translateService: TranslateService, | ||
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<NumberField>) { | ||
super(translateService, dataFieldPortalData); | ||
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<NumberField>, | ||
@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(translateService, dataFieldPortalData, _saveDataInform); | ||
} | ||
|
||
ngAfterViewInit() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import {DecimalPipe} from "@angular/common"; | |
import {TranslateService} from "@ngx-translate/core"; | ||
import {DATA_FIELD_PORTAL_DATA, DataFieldPortalData} from "../../models/data-field-portal-data-injection-token"; | ||
import {NumberField} from "../models/number-field"; | ||
import {NAE_SAVE_DATA_INFORM} from "../../models/save-data-inform-token"; | ||
|
||
@Component({ | ||
selector: 'ncc-abstract-number-decimal-field', | ||
|
@@ -19,8 +20,9 @@ export abstract class AbstractNumberDecimalFieldComponent extends AbstractNumber | |
|
||
protected constructor(protected _decimalPipe: DecimalPipe, | ||
_translate: TranslateService, | ||
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<NumberField>) { | ||
super(_translate, dataFieldPortalData); | ||
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<NumberField>, | ||
@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(_translate, dataFieldPortalData, _saveDataInform); | ||
} | ||
|
||
ngAfterViewInit() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import {AbstractNumberErrorsComponent} from '../abstract-number-errors.component | |
import {Component, Inject, Optional} from '@angular/core'; | ||
import {DATA_FIELD_PORTAL_DATA, DataFieldPortalData} from "../../models/data-field-portal-data-injection-token"; | ||
import {NumberField} from "../models/number-field"; | ||
import {NAE_SAVE_DATA_INFORM} from "../../models/save-data-inform-token"; | ||
|
||
@Component({ | ||
selector: 'ncc-abstract-number-default-field', | ||
|
@@ -11,7 +12,8 @@ import {NumberField} from "../models/number-field"; | |
export abstract class AbstractDefaultNumberFieldComponent extends AbstractNumberErrorsComponent { | ||
|
||
protected constructor(translateService: TranslateService, | ||
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<NumberField>) { | ||
super(translateService, dataFieldPortalData); | ||
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<NumberField>, | ||
@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(translateService, dataFieldPortalData, _saveDataInform); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import {CustomCard} from '../../dashboard/cards/model/custom-dashboard-model/cus | |
import {Subscription} from 'rxjs'; | ||
import {TranslateService} from '@ngx-translate/core'; | ||
import {DATA_FIELD_PORTAL_DATA, DataFieldPortalData} from "../models/data-field-portal-data-injection-token"; | ||
import {NAE_SAVE_DATA_INFORM} from "../models/save-data-inform-token"; | ||
|
||
@Component({ | ||
selector: 'ncc-abstract-dashboard-text-field', | ||
|
@@ -16,8 +17,9 @@ export abstract class AbstractDashboardTextFieldComponent extends AbstractTextEr | |
protected _sub: Subscription; | ||
|
||
protected constructor(translate: TranslateService, | ||
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<TextField>) { | ||
super(translate, dataFieldPortalData); | ||
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<TextField>, | ||
@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(translate, dataFieldPortalData, _saveDataInform); | ||
} | ||
|
||
ngOnInit(): void { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import {TextAreaField} from './models/text-area-field'; | |
import {Component, Inject, Optional} from "@angular/core"; | ||
import {DATA_FIELD_PORTAL_DATA, DataFieldPortalData} from "../models/data-field-portal-data-injection-token"; | ||
import {AbstractBaseDataFieldComponent} from "../base-component/abstract-base-data-field.component"; | ||
import {NAE_SAVE_DATA_INFORM} from "../models/save-data-inform-token"; | ||
|
||
@Component({ | ||
selector: 'ncc-text-errors', | ||
|
@@ -13,8 +14,9 @@ import {AbstractBaseDataFieldComponent} from "../base-component/abstract-base-da | |
export abstract class AbstractTextErrorsComponent<T extends TextField> extends AbstractBaseDataFieldComponent<T>{ | ||
|
||
protected constructor(protected _translate: TranslateService, | ||
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<T>) { | ||
super(dataFieldPortalData); | ||
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<T>, | ||
@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(dataFieldPortalData, _saveDataInform); | ||
} | ||
|
||
protected buildErrorMessage(textField: TextField | TextAreaField, formControlRef: FormControl) { | ||
|
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ import {FilterType} from '../../../filter/models/filter-type'; | |
import {AbstractDashboardTextFieldComponent} from '../abstract-dashboard-text-field.component'; | ||
import {DATA_FIELD_PORTAL_DATA, DataFieldPortalData} from "../../models/data-field-portal-data-injection-token"; | ||
import {TextField} from "../models/text-field"; | ||
import {NAE_SAVE_DATA_INFORM} from "../../models/save-data-inform-token"; | ||
|
||
@Component({ | ||
selector: 'ncc-abstract-dashboard-bar-chart-text-field', | ||
|
@@ -14,8 +15,9 @@ import {TextField} from "../models/text-field"; | |
export abstract class AbstractDashboardBarChartTextFieldComponent extends AbstractDashboardTextFieldComponent { | ||
|
||
protected constructor(translate: TranslateService, | ||
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<TextField>) { | ||
super(translate, dataFieldPortalData); | ||
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<TextField>, | ||
@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(translate, dataFieldPortalData, _saveDataInform); | ||
} | ||
|
||
protected createCard(textFieldValue: string): CustomCard { | ||
|
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.
as far as I know, setting default value for an
@Optional
injector does not work as desired.null
is a falsy value, so it still works as intended.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.
Yes, if there is no such injection token provided, it will be considered as null, which will indicate falsy value, but I think, the default value is used because of without that it would be needed to add the
@Optional() @Inject(NAE_SAVE_DATA_INFORM) _saveDataInform: boolean
to constructors of every subclass ofAbstractBaseDataFieldComponent