From 456b0c40cbeab7ad8daa6df117f3f9f5140d6a8b Mon Sep 17 00:00:00 2001 From: "Deng, Qian" Date: Mon, 23 Apr 2018 19:58:22 +0800 Subject: [PATCH] Fix bug on search result ui Fix issue #3852, After global search result returned if you research another item, the content will not refresh. --- .../list-repository-ro.component.ts | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/ui_ng/src/app/shared/list-repository-ro/list-repository-ro.component.ts b/src/ui_ng/src/app/shared/list-repository-ro/list-repository-ro.component.ts index 2a714f94c..476e72834 100644 --- a/src/ui_ng/src/app/shared/list-repository-ro/list-repository-ro.component.ts +++ b/src/ui_ng/src/app/shared/list-repository-ro/list-repository-ro.component.ts @@ -11,8 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core'; -import { Router, NavigationExtras } from '@angular/router'; +import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy, ChangeDetectorRef, OnInit } from '@angular/core'; +import { Router, NavigationExtras, NavigationEnd } from '@angular/router'; import { Repository } from 'harbor-ui'; import { State } from 'clarity-angular'; @@ -23,19 +23,33 @@ import { SearchTriggerService } from '../../base/global-search/search-trigger.se templateUrl: 'list-repository-ro.component.html', changeDetection: ChangeDetectionStrategy.OnPush }) -export class ListRepositoryROComponent { +export class ListRepositoryROComponent implements OnInit { @Input() projectId: number; @Input() repositories: Repository[]; @Output() paginate = new EventEmitter(); - + constructor( private router: Router, private searchTrigger: SearchTriggerService, private ref: ChangeDetectorRef) { - let hnd = setInterval(()=>ref.markForCheck(), 100); - setTimeout(()=>clearInterval(hnd), 1000); + this.router.routeReuseStrategy.shouldReuseRoute = function(){ + return false; + }; + this.router.events.subscribe((evt) => { + if (evt instanceof NavigationEnd) { + // trick the Router into believing it's last link wasn't previously loaded + this.router.navigated = false; + // if you need to scroll back to top, here is the right place + window.scrollTo(0, 0); + } + }); + } + + ngOnInit(): void { + let hnd = setInterval(() => this.ref.markForCheck(), 100); + setTimeout(() => clearInterval(hnd), 1000); } refresh(state: State) {