Unverified Commit 7b4b6630 authored by 老广's avatar 老广 Committed by GitHub

Merge pull request #112 from jumpserver/dev_beta

[Update] 避免搜索多次
parents ec8a866f 907384a3
import {Component, Input, OnInit, OnDestroy, ElementRef, ViewChild} from '@angular/core';
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 {AppService, HttpService, LogService, NavService, SettingService, TreeFilterService} from '@app/services';
......@@ -44,6 +45,7 @@ export class ElementAssetTreeComponent implements OnInit, OnDestroy {
hasLoginTo = false;
treeFilterSubscription: any;
isLoadTreeAsync: boolean;
filterAssetCancel$: Subject<boolean> = new Subject();
constructor(private _appSvc: AppService,
private _treeFilterSvc: TreeFilterService,
......@@ -330,17 +332,23 @@ export class ElementAssetTreeComponent implements OnInit, OnDestroy {
}
return;
}
this._http.getMyGrantedAssets(keyword).subscribe(nodes => {
const treeNodes = this.assetsTree.getNodes();
if (treeNodes.length !== 0) {
this.assetsTree.hideNode(treeNodes[0]);
}
const newNode = {id: 'search', name: translate('Search'), isParent: true, open: true, zAsync: true};
const parentNode = this.assetsTree.addNodes(null, newNode)[0];
parentNode.zAsync = true;
this.assetsTree.addNodes(parentNode, nodes);
parentNode.open = true;
});
this.filterAssetCancel$.next(true);
this._http.getMyGrantedAssets(keyword)
.pipe(takeUntil(this.filterAssetCancel$))
.subscribe(nodes => {
const treeNodes = this.assetsTree.getNodes();
if (treeNodes.length !== 0) {
this.assetsTree.hideNode(treeNodes[0]);
}
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];
parentNode.zAsync = true;
this.assetsTree.addNodes(parentNode, nodes);
parentNode.open = true;
});
return;
}
......
......@@ -40,29 +40,27 @@ export class ElementConnectComponent implements OnInit, OnDestroy {
}
}
});
this.activatedRoute.queryParams.subscribe(params => {
const login_to = params['login_to'];
if (login_to && !this.hasLoginTo) {
this._http.filterMyGrantedAssetsById(login_to).subscribe(
nodes => {
if (nodes.length === 1) {
this.hasLoginTo = true;
const node = nodes[0];
this.Connect(node);
}
const loginTo = this._appSvc.getQueryString('login_to');
if (loginTo && !this.hasLoginTo) {
this._http.filterMyGrantedAssetsById(loginTo).subscribe(
nodes => {
if (nodes.length === 1) {
this.hasLoginTo = true;
const node = nodes[0];
this.Connect(node);
}
);
this._http.getMyGrantedRemoteApps(login_to).subscribe(
nodes => {
if (nodes.length === 1) {
this.hasLoginTo = true;
const node = nodes[0];
this.Connect(node);
}
}
);
this._http.getMyGrantedRemoteApps(loginTo).subscribe(
nodes => {
if (nodes.length === 1) {
this.hasLoginTo = true;
const node = nodes[0];
this.Connect(node);
}
);
}
});
}
);
}
}
ngOnDestroy(): void {
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