Commit c1b5702e authored by liuzheng712's avatar liuzheng712

feat: update connect with coco in /api/hostlist

parent f9f842f0
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { PopupComponent } from './popup.component';
describe('PopupComponent', () => {
let component: PopupComponent;
let fixture: ComponentFixture<PopupComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ PopupComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(PopupComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should be created', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-popup',
templateUrl: './popup.component.html',
styleUrls: ['./popup.component.css']
})
export class PopupComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
...@@ -58,4 +58,3 @@ ...@@ -58,4 +58,3 @@
background-size: 33px 63px; background-size: 33px 63px;
} }
} }
<div id="sidebar"> <div id="sidebar">
<app-search></app-search> <app-search></app-search>
<ul class="filetree"> <ul class="filetree">
<li *ngFor="let hostGroup of HostGroups"> <li *ngFor="let hostGroup of HostGroups; let i = index ">
<input type="checkbox" id="level1-1"> <input type="checkbox" id="hostgroup-{{i}}">
<label for="level1-1">{{hostGroup.name}}</label> <label for="hostgroup-{{i}}">{{hostGroup.name}}</label>
<ul> <ul>
<li *ngFor="let host of hostGroup.children" (click)="Connect(host)">{{host.name}}</li> <li *ngFor="let host of hostGroup.children" (click)="Connect(host)">{{host.name}}</li>
</ul> </ul>
......
...@@ -14,11 +14,12 @@ import {AppService, DataStore, HttpService} from '../../app.service'; ...@@ -14,11 +14,12 @@ import {AppService, DataStore, HttpService} from '../../app.service';
import {SshComponent} from '../control/ssh/ssh.component'; import {SshComponent} from '../control/ssh/ssh.component';
import {RdpComponent} from "../control/rdp/rdp.component"; import {RdpComponent} from "../control/rdp/rdp.component";
declare let layer: any;
declare let jQuery: any; declare let jQuery: any;
export class HostGroup { export class HostGroup {
name: string; name: string;
id: string; id: number;
children: Array<Host>; children: Array<Host>;
} }
...@@ -26,8 +27,6 @@ export class Host { ...@@ -26,8 +27,6 @@ export class Host {
name: string; name: string;
uuid: string; uuid: string;
type: string; type: string;
token: string;
machine: string;
} }
@Component({ @Component({
...@@ -68,14 +67,45 @@ export class CleftbarComponent implements OnInit { ...@@ -68,14 +67,45 @@ export class CleftbarComponent implements OnInit {
Connect(host) { Connect(host) {
console.log(host);
let username: string;
if (host.users.length > 1) {
let options = "";
for (let u of host.users) {
options += "<option value='" + u + "'>" + u + "</option>"
}
layer.open({
title: 'Please Choose a User',
scrollbar: false,
moveOut: true,
moveType: 1,
btn: ["确定", "取消"],
content: "<select id='selectuser'>" + options + "</select>",
yes: function (index, layero) {
username = jQuery("#selectuser").val();
layer.close(index);
},
btn2: function (index, layero) {
},
cancel: function () {
//右上角关闭回调
//return false 开启该代码可禁止点击该按钮关闭
}
});
} else if (host.users.length === 1) {
username = host.users[0]
}
if (username === "") {
return
}
if (host.type === 'ssh') { if (host.type === 'ssh') {
jQuery("app-ssh").show(); jQuery("app-ssh").show();
jQuery("app-rdp").hide(); jQuery("app-rdp").hide();
this._term.TerminalConnect(host); this._term.TerminalConnect(host, username);
} else { } else {
jQuery("app-ssh").hide(); jQuery("app-ssh").hide();
jQuery("app-rdp").show(); jQuery("app-rdp").show();
this._rdp.Connect(host); this._rdp.Connect(host, username);
} }
} }
......
...@@ -24,7 +24,7 @@ export class RdpComponent implements OnInit { ...@@ -24,7 +24,7 @@ export class RdpComponent implements OnInit {
ngOnInit() { ngOnInit() {
} }
Connect(host) { Connect(host, username) {
let id = NavList.List.length - 1; let id = NavList.List.length - 1;
let canvas = Mstsc.$("canvas-" + id); let canvas = Mstsc.$("canvas-" + id);
...@@ -39,7 +39,7 @@ export class RdpComponent implements OnInit { ...@@ -39,7 +39,7 @@ export class RdpComponent implements OnInit {
NavList.List[id].type = "rdp"; NavList.List[id].type = "rdp";
NavList.List[id].Rdp = new Rdp; NavList.List[id].Rdp = new Rdp;
NavList.List[id].Rdp.token = host.token; NavList.List[id].Rdp.token = host.token;
NavList.List[id].Rdp.machine = host.machine; NavList.List[id].Rdp.machine = host.uuid;
NavList.List[id].Rdp.client = Mstsc.client.create(Mstsc.$("canvas-" + id)); NavList.List[id].Rdp.client = Mstsc.client.create(Mstsc.$("canvas-" + id));
NavList.List[id].Rdp.client.connect(host.token, "rdp/socket.io"); NavList.List[id].Rdp.client.connect(host.token, "rdp/socket.io");
...@@ -60,7 +60,8 @@ export class RdpComponent implements OnInit { ...@@ -60,7 +60,8 @@ export class RdpComponent implements OnInit {
// document.getElementById("templatesrc").remove(); // document.getElementById("templatesrc").remove();
} }
static DisconnectAll(){
static DisconnectAll() {
} }
......
...@@ -32,7 +32,7 @@ export class SshComponent implements OnInit { ...@@ -32,7 +32,7 @@ export class SshComponent implements OnInit {
ngOnInit() { ngOnInit() {
} }
TerminalConnect(host) { TerminalConnect(host,username) {
let socket = io.connect(); let socket = io.connect();
let cols = '80'; let cols = '80';
let rows = '24'; let rows = '24';
...@@ -53,7 +53,7 @@ export class SshComponent implements OnInit { ...@@ -53,7 +53,7 @@ export class SshComponent implements OnInit {
NavList.List[id].closed = false; NavList.List[id].closed = false;
NavList.List[id].type = "ssh"; NavList.List[id].type = "ssh";
NavList.List[id].Term = new Term; NavList.List[id].Term = new Term;
NavList.List[id].Term.machine = 'localhost'; NavList.List[id].Term.machine = host.uuid;
NavList.List[id].Term.socket = socket; NavList.List[id].Term.socket = socket;
NavList.List[id].Term.term = new Terminal({ NavList.List[id].Term.term = new Terminal({
cols: cols, cols: cols,
......
...@@ -33,6 +33,7 @@ import {SshComponent} from './ControlPage/control/ssh/ssh.component'; ...@@ -33,6 +33,7 @@ import {SshComponent} from './ControlPage/control/ssh/ssh.component';
import {ControlPageComponent} from './ControlPage/controlpage.component'; import {ControlPageComponent} from './ControlPage/controlpage.component';
import {IndexPageComponent} from './IndexPage/index-page.component'; import {IndexPageComponent} from './IndexPage/index-page.component';
import { NotFoundComponent } from './BasicPage/not-found/not-found.component'; import { NotFoundComponent } from './BasicPage/not-found/not-found.component';
import { PopupComponent } from './BasicPage/popup/popup.component';
@NgModule({ @NgModule({
...@@ -57,7 +58,8 @@ import { NotFoundComponent } from './BasicPage/not-found/not-found.component'; ...@@ -57,7 +58,8 @@ import { NotFoundComponent } from './BasicPage/not-found/not-found.component';
ControlnavComponent, ControlnavComponent,
ControlPageComponent, ControlPageComponent,
IndexPageComponent, IndexPageComponent,
NotFoundComponent NotFoundComponent,
PopupComponent
// HeroListComponent, // HeroListComponent,
// CrisisListComponent, // CrisisListComponent,
], ],
......
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
* @date 2017-11-07 * @date 2017-11-07
* @author liuzheng <liuzheng712@gmail.com> * @author liuzheng <liuzheng712@gmail.com>
*/ */
import {Injectable} from '@angular/core'; import {Injectable, OnInit} from '@angular/core';
import {Http, RequestOptionsArgs, Headers} from '@angular/http'; import {Http, RequestOptionsArgs, Headers} from '@angular/http';
import {Router} from '@angular/router';
import {Cookie} from 'ng2-cookies/ng2-cookies'; import {Cookie} from 'ng2-cookies/ng2-cookies';
import {Logger} from 'angular2-logger/core'; import {Logger} from 'angular2-logger/core';
import 'rxjs/add/operator/map'; import 'rxjs/add/operator/map';
...@@ -15,7 +16,7 @@ import 'rxjs/add/operator/catch'; ...@@ -15,7 +16,7 @@ import 'rxjs/add/operator/catch';
declare let jQuery: any; declare let jQuery: any;
// declare var Clipboard: any; // declare var Clipboard: any;
import * as io from 'socket.io-client'; import * as io from 'socket.io-client';
import {Router} from '@angular/router'; import {environment} from '../environments/environment';
export class Group { export class Group {
id: number; id: number;
...@@ -97,6 +98,12 @@ export let Browser: { ...@@ -97,6 +98,12 @@ export let Browser: {
vendor: navigator.vendor, vendor: navigator.vendor,
}; };
export class wsEvent {
event: string;
data: any;
}
@Injectable() @Injectable()
export class HttpService { export class HttpService {
headers = new Headers(); headers = new Headers();
...@@ -171,7 +178,7 @@ export class HttpService { ...@@ -171,7 +178,7 @@ export class HttpService {
} }
@Injectable() @Injectable()
export class AppService { export class AppService implements OnInit {
// user:User = user ; // user:User = user ;
searchrequest: any; searchrequest: any;
...@@ -196,22 +203,13 @@ export class AppService { ...@@ -196,22 +203,13 @@ export class AppService {
// this._logger.level = parseInt(Cookie.getCookie('loglevel')); // this._logger.level = parseInt(Cookie.getCookie('loglevel'));
this._logger.level = 0; this._logger.level = 0;
} }
DataStore.socket.on('connect', function () {
console.log('DatsStore socket connected');
DataStore.socket.on('nav', function (data) {
DataStore.Nav = JSON.parse(data);
});
DataStore.socket.on('leftbar', function (data) {
});
// DataStore.socket.on('popup', function (data) {
// layer.msg(data);
// });
// DataStore.socket.emit('api', 'all');
});
this.checklogin(); this.checklogin();
} }
ngOnInit() {
}
checklogin() { checklogin() {
this._logger.log('service.ts:AppService,checklogin'); this._logger.log('service.ts:AppService,checklogin');
...@@ -263,7 +261,6 @@ export class AppService { ...@@ -263,7 +261,6 @@ export class AppService {
} }
browser() { browser() {
this._http.post('/api/browser', JSON.stringify(Browser)).map(res => res.json()).subscribe() this._http.post('/api/browser', JSON.stringify(Browser)).map(res => res.json()).subscribe()
} }
......
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