Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fix parsing of NaN resizer values

Oliver Günther1a0720ba8d5c
diff --git a/frontend/src/app/components/resizer/wp-resizer.component.ts b/frontend/src/app/components/resizer/wp-resizer.component.ts
index 05a235f25a0..8af020d3cbf 100644
--- a/frontend/src/app/components/resizer/wp-resizer.component.ts
+++ b/frontend/src/app/components/resizer/wp-resizer.component.ts
@@ -63,9 +63,8 @@ export class WpResizerDirective implements OnInit, OnDestroy {
this.resizingElement = <HTMLElement>document.getElementsByClassName(this.elementClass)[0];
// Get initial width from local storage and apply
- let localStorageValue = window.OpenProject.guardedLocalStorage(this.localStorageKey);
- this.elementFlex = localStorageValue ? parseInt(localStorageValue,
- 10) : this.resizingElement.offsetWidth;
+ let localStorageValue = this.parseLocalStorageValue();
+ this.elementFlex = localStorageValue || this.resizingElement.offsetWidth;
// ToDo:
// Rename variables to width
@@ -136,9 +135,9 @@ export class WpResizerDirective implements OnInit, OnDestroy {
@HostListener('window:touchend', ['$event'])
private handleTouchEnd(e:MouseEvent) {
window.removeEventListener('touchmove', this.mouseMoveHandler);
- let localStorageValue = window.OpenProject.guardedLocalStorage(this.localStorageKey);
+ let localStorageValue = this.parseLocalStorageValue();
if (localStorageValue) {
- this.elementFlex = parseInt(localStorageValue, 10);
+ this.elementFlex = localStorageValue;
}
}
@@ -157,9 +156,9 @@ export class WpResizerDirective implements OnInit, OnDestroy {
// Take care at the end that the elementFlex-Value is the same as the actual value
// When the mouseup is outside the container these values will differ
// which will cause problems at the next movement start
- let localStorageValue = window.OpenProject.guardedLocalStorage(this.localStorageKey);
+ let localStorageValue = this.parseLocalStorageValue();
if (localStorageValue) {
- this.elementFlex = parseInt(localStorageValue, 10);
+ this.elementFlex = localStorageValue;
}
this.moving = false;
@@ -171,6 +170,17 @@ export class WpResizerDirective implements OnInit, OnDestroy {
return false;
}
+ private parseLocalStorageValue():number|undefined {
+ let localStorageValue = window.OpenProject.guardedLocalStorage(this.localStorageKey);
+ let number = parseInt(localStorageValue || '', 10);
+
+ if (typeof number === 'number' && number !== NaN) {
+ return number;
+ }
+
+ return undefined;
+ }
+
private resizeElement(element:HTMLElement, e:MouseEvent) {
e.preventDefault();
e.stopPropagation();