From 04c7734dede0e3f3f613ef3e709ef20ec2fde84b Mon Sep 17 00:00:00 2001 From: Johannes Millan Date: Tue, 4 Jun 2019 23:45:44 +0200 Subject: [PATCH] fix(procrastination): work view throwing an error when navigating back to it --- .../work-view/work-view-page.component.ts | 59 +++++++++++-------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/src/app/pages/work-view/work-view-page.component.ts b/src/app/pages/work-view/work-view-page.component.ts index de8141a38f..f582acc7d7 100644 --- a/src/app/pages/work-view/work-view-page.component.ts +++ b/src/app/pages/work-view/work-view-page.component.ts @@ -1,15 +1,18 @@ -import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core'; -import { TaskService } from '../../features/tasks/task.service'; -import { expandAnimation, expandFadeAnimation } from '../../ui/animations/expand.ani'; -import { LayoutService } from '../../core-ui/layout/layout.service'; -import { DragulaService } from 'ng2-dragula'; -import { TakeABreakService } from '../../features/time-tracking/take-a-break/take-a-break.service'; -import { ActivatedRoute } from '@angular/router'; -import { from, Subscription, timer, zip } from 'rxjs'; -import { TaskWithSubTasks } from '../../features/tasks/task.model'; -import { map, switchMap } from 'rxjs/operators'; -import { fadeAnimation } from '../../ui/animations/fade.ani'; -import { PlanningModeService } from '../../features/planning-mode/planning-mode.service'; +import {ChangeDetectionStrategy, Component, OnDestroy, OnInit} from '@angular/core'; +import {TaskService} from '../../features/tasks/task.service'; +import {expandAnimation, expandFadeAnimation} from '../../ui/animations/expand.ani'; +import {LayoutService} from '../../core-ui/layout/layout.service'; +import {DragulaService} from 'ng2-dragula'; +import {TakeABreakService} from '../../features/time-tracking/take-a-break/take-a-break.service'; +import {ActivatedRoute} from '@angular/router'; +import {from, Subscription, timer, zip} from 'rxjs'; +import {TaskWithSubTasks} from '../../features/tasks/task.model'; +import {map, switchMap} from 'rxjs/operators'; +import {fadeAnimation} from '../../ui/animations/fade.ani'; +import {PlanningModeService} from '../../features/planning-mode/planning-mode.service'; + +const SUB = 'SUB'; +const PARENT = 'PARENT'; @Component({ selector: 'work-view', @@ -52,19 +55,25 @@ export class WorkViewPageComponent implements OnInit, OnDestroy { ngOnInit() { - this._dragulaService.createGroup('PARENT', { - direction: 'vertical', - moves: function (el, container, handle) { - return handle.className.indexOf && handle.className.indexOf('handle-par') > -1; - } - }); + const sub = this._dragulaService.find(SUB); + const par = this._dragulaService.find(PARENT); - this._dragulaService.createGroup('SUB', { - direction: 'vertical', - moves: function (el, container, handle) { - return handle.className.indexOf && handle.className.indexOf('handle-sub') > -1; - } - }); + if (!sub) { + this._dragulaService.createGroup(SUB, { + direction: 'vertical', + moves: function (el, container, handle) { + return handle.className.indexOf && handle.className.indexOf('handle-sub') > -1; + } + }); + } + if (!par) { + this._dragulaService.createGroup(PARENT, { + direction: 'vertical', + moves: function (el, container, handle) { + return handle.className.indexOf && handle.className.indexOf('handle-par') > -1; + } + }); + } this._subs.add(this.taskService.backlogTasks$.subscribe(tasks => this.backlogTasks = tasks)); @@ -78,8 +87,6 @@ export class WorkViewPageComponent implements OnInit, OnDestroy { ngOnDestroy() { - this._dragulaService.destroy('PARENT'); - this._dragulaService.destroy('SUB'); if (this._switchListAnimationTimeout) { window.clearTimeout(this._switchListAnimationTimeout); }