From 9b6a97fc64d3a934bc169a577a2bc6feeb90ef08 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Thu, 2 Feb 2017 22:21:47 +0200 Subject: [PATCH] Fix latest empty menu-items not getting active (#194) --- lib/services/menu.service.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/services/menu.service.ts b/lib/services/menu.service.ts index 7cda8567..c6c279c3 100644 --- a/lib/services/menu.service.ts +++ b/lib/services/menu.service.ts @@ -52,6 +52,7 @@ export class MenuService { private _flatItems: MenuItem[]; private _hashSubscription: Subscription; private _scrollSubscription: Subscription; + private _progressSubscription: Subscription; private _tagsWithMethods: any; constructor( @@ -71,6 +72,12 @@ export class MenuService { this._hashSubscription = this.hash.value.subscribe((hash) => { this.onHashChange(hash); }); + + this._progressSubscription = this.tasks.loadProgress.subscribe(progress => { + if (progress === 100) { + this.makeSureLastItemsEnabled(); + } + }); } get flatItems():MenuItem[] { @@ -88,7 +95,7 @@ export class MenuService { idx = item.parent.flatIdx; } - // check if previous items can be enabled + // check if previous itemsĀ§ can be enabled let prevItem = this.flatItems[idx -= 1]; while(prevItem && (!prevItem.metadata || !prevItem.items)) { prevItem.ready = true; @@ -98,6 +105,15 @@ export class MenuService { this.changed.next(); } + makeSureLastItemsEnabled() { + let lastIdx = this.flatItems.length - 1; + let item = this.flatItems[lastIdx] + while(item && (!item.metadata || !item.items)) { + item.ready = true; + item = this.flatItems[lastIdx -= 1]; + } + } + onScroll(isScrolledDown) { let stable = false; while(!stable) {