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 @@
background-size: 33px 63px;
}
}
<div id="sidebar">
<app-search></app-search>
<ul class="filetree">
<li *ngFor="let hostGroup of HostGroups">
<input type="checkbox" id="level1-1">
<label for="level1-1">{{hostGroup.name}}</label>
<li *ngFor="let hostGroup of HostGroups; let i = index ">
<input type="checkbox" id="hostgroup-{{i}}">
<label for="hostgroup-{{i}}">{{hostGroup.name}}</label>
<ul>
<li *ngFor="let host of hostGroup.children" (click)="Connect(host)">{{host.name}}</li>
</ul>
......
......@@ -14,11 +14,12 @@ import {AppService, DataStore, HttpService} from '../../app.service';
import {SshComponent} from '../control/ssh/ssh.component';
import {RdpComponent} from "../control/rdp/rdp.component";
declare let layer: any;
declare let jQuery: any;
export class HostGroup {
name: string;
id: string;
id: number;
children: Array<Host>;
}
......@@ -26,8 +27,6 @@ export class Host {
name: string;
uuid: string;
type: string;
token: string;
machine: string;
}
@Component({
......@@ -68,14 +67,45 @@ export class CleftbarComponent implements OnInit {
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') {
jQuery("app-ssh").show();
jQuery("app-rdp").hide();
this._term.TerminalConnect(host);
this._term.TerminalConnect(host, username);
} else {
jQuery("app-ssh").hide();
jQuery("app-rdp").show();
this._rdp.Connect(host);
this._rdp.Connect(host, username);
}
}
......
......@@ -24,7 +24,7 @@ export class RdpComponent implements OnInit {
ngOnInit() {
}
Connect(host) {
Connect(host, username) {
let id = NavList.List.length - 1;
let canvas = Mstsc.$("canvas-" + id);
......@@ -39,7 +39,7 @@ export class RdpComponent implements OnInit {
NavList.List[id].type = "rdp";
NavList.List[id].Rdp = new Rdp;
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.connect(host.token, "rdp/socket.io");
......@@ -60,7 +60,8 @@ export class RdpComponent implements OnInit {
// document.getElementById("templatesrc").remove();
}
static DisconnectAll(){
static DisconnectAll() {
}
......
......@@ -32,7 +32,7 @@ export class SshComponent implements OnInit {
ngOnInit() {
}
TerminalConnect(host) {
TerminalConnect(host,username) {
let socket = io.connect();
let cols = '80';
let rows = '24';
......@@ -53,7 +53,7 @@ export class SshComponent implements OnInit {
NavList.List[id].closed = false;
NavList.List[id].type = "ssh";
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.term = new Terminal({
cols: cols,
......
......@@ -33,6 +33,7 @@ import {SshComponent} from './ControlPage/control/ssh/ssh.component';
import {ControlPageComponent} from './ControlPage/controlpage.component';
import {IndexPageComponent} from './IndexPage/index-page.component';
import { NotFoundComponent } from './BasicPage/not-found/not-found.component';
import { PopupComponent } from './BasicPage/popup/popup.component';
@NgModule({
......@@ -57,7 +58,8 @@ import { NotFoundComponent } from './BasicPage/not-found/not-found.component';
ControlnavComponent,
ControlPageComponent,
IndexPageComponent,
NotFoundComponent
NotFoundComponent,
PopupComponent
// HeroListComponent,
// CrisisListComponent,
],
......
......@@ -5,8 +5,9 @@
* @date 2017-11-07
* @author liuzheng <liuzheng712@gmail.com>
*/
import {Injectable} from '@angular/core';
import {Injectable, OnInit} from '@angular/core';
import {Http, RequestOptionsArgs, Headers} from '@angular/http';
import {Router} from '@angular/router';
import {Cookie} from 'ng2-cookies/ng2-cookies';
import {Logger} from 'angular2-logger/core';
import 'rxjs/add/operator/map';
......@@ -15,7 +16,7 @@ import 'rxjs/add/operator/catch';
declare let jQuery: any;
// declare var Clipboard: any;
import * as io from 'socket.io-client';
import {Router} from '@angular/router';
import {environment} from '../environments/environment';
export class Group {
id: number;
......@@ -97,6 +98,12 @@ export let Browser: {
vendor: navigator.vendor,
};
export class wsEvent {
event: string;
data: any;
}
@Injectable()
export class HttpService {
headers = new Headers();
......@@ -171,7 +178,7 @@ export class HttpService {
}
@Injectable()
export class AppService {
export class AppService implements OnInit {
// user:User = user ;
searchrequest: any;
......@@ -196,22 +203,13 @@ export class AppService {
// this._logger.level = parseInt(Cookie.getCookie('loglevel'));
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();
}
ngOnInit() {
}
checklogin() {
this._logger.log('service.ts:AppService,checklogin');
......@@ -263,7 +261,6 @@ export class AppService {
}
browser() {
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