Commit 907384a3 authored by ibuler's avatar ibuler

[Update] 避免搜索多次

parent 45a66fab
import {Component, Input, OnInit, OnDestroy, ElementRef, ViewChild} from '@angular/core'; import {Component, Input, OnInit, OnDestroy, ElementRef, ViewChild} from '@angular/core';
import {MatDialog} from '@angular/material'; import {MatDialog} from '@angular/material';
import {BehaviorSubject} from 'rxjs'; import {BehaviorSubject, Subject} from 'rxjs';
import {takeUntil} from 'rxjs/operators';
import {ActivatedRoute} from '@angular/router'; import {ActivatedRoute} from '@angular/router';
import {AppService, HttpService, LogService, NavService, SettingService, TreeFilterService} from '@app/services'; import {AppService, HttpService, LogService, NavService, SettingService, TreeFilterService} from '@app/services';
...@@ -44,6 +45,7 @@ export class ElementAssetTreeComponent implements OnInit, OnDestroy { ...@@ -44,6 +45,7 @@ export class ElementAssetTreeComponent implements OnInit, OnDestroy {
hasLoginTo = false; hasLoginTo = false;
treeFilterSubscription: any; treeFilterSubscription: any;
isLoadTreeAsync: boolean; isLoadTreeAsync: boolean;
filterAssetCancel$: Subject<boolean> = new Subject();
constructor(private _appSvc: AppService, constructor(private _appSvc: AppService,
private _treeFilterSvc: TreeFilterService, private _treeFilterSvc: TreeFilterService,
...@@ -330,12 +332,18 @@ export class ElementAssetTreeComponent implements OnInit, OnDestroy { ...@@ -330,12 +332,18 @@ export class ElementAssetTreeComponent implements OnInit, OnDestroy {
} }
return; return;
} }
this._http.getMyGrantedAssets(keyword).subscribe(nodes => { this.filterAssetCancel$.next(true);
this._http.getMyGrantedAssets(keyword)
.pipe(takeUntil(this.filterAssetCancel$))
.subscribe(nodes => {
const treeNodes = this.assetsTree.getNodes(); const treeNodes = this.assetsTree.getNodes();
if (treeNodes.length !== 0) { if (treeNodes.length !== 0) {
this.assetsTree.hideNode(treeNodes[0]); this.assetsTree.hideNode(treeNodes[0]);
} }
const newNode = {id: 'search', name: translate('Search'), isParent: true, open: true, zAsync: true}; let name = translate('Search');
const assetsAmount = nodes.length;
name = `${name} (${assetsAmount})`;
const newNode = {id: 'search', name: name, isParent: true, open: true, zAsync: true};
const parentNode = this.assetsTree.addNodes(null, newNode)[0]; const parentNode = this.assetsTree.addNodes(null, newNode)[0];
parentNode.zAsync = true; parentNode.zAsync = true;
this.assetsTree.addNodes(parentNode, nodes); this.assetsTree.addNodes(parentNode, nodes);
......
...@@ -40,10 +40,9 @@ export class ElementConnectComponent implements OnInit, OnDestroy { ...@@ -40,10 +40,9 @@ export class ElementConnectComponent implements OnInit, OnDestroy {
} }
} }
}); });
this.activatedRoute.queryParams.subscribe(params => { const loginTo = this._appSvc.getQueryString('login_to');
const login_to = params['login_to']; if (loginTo && !this.hasLoginTo) {
if (login_to && !this.hasLoginTo) { this._http.filterMyGrantedAssetsById(loginTo).subscribe(
this._http.filterMyGrantedAssetsById(login_to).subscribe(
nodes => { nodes => {
if (nodes.length === 1) { if (nodes.length === 1) {
this.hasLoginTo = true; this.hasLoginTo = true;
...@@ -52,7 +51,7 @@ export class ElementConnectComponent implements OnInit, OnDestroy { ...@@ -52,7 +51,7 @@ export class ElementConnectComponent implements OnInit, OnDestroy {
} }
} }
); );
this._http.getMyGrantedRemoteApps(login_to).subscribe( this._http.getMyGrantedRemoteApps(loginTo).subscribe(
nodes => { nodes => {
if (nodes.length === 1) { if (nodes.length === 1) {
this.hasLoginTo = true; this.hasLoginTo = true;
...@@ -62,7 +61,6 @@ export class ElementConnectComponent implements OnInit, OnDestroy { ...@@ -62,7 +61,6 @@ export class ElementConnectComponent implements OnInit, OnDestroy {
} }
); );
} }
});
} }
ngOnDestroy(): void { ngOnDestroy(): void {
connectEvt.unsubscribe(); connectEvt.unsubscribe();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment