Commit c8e5ea43 authored by liuzheng712's avatar liuzheng712

feat: update

parent fa8df131
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<a class="nav-link" routerLink="">Home <span class="sr-only">(current)</span></a> <a class="nav-link" routerLink="">Home <span class="sr-only">(current)</span></a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" routerLink="term">Term</a> <a class="nav-link" routerLink="control">Control</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a> <a class="nav-link disabled" href="#">Disabled</a>
......
...@@ -3,13 +3,14 @@ import {Logger} from 'angular2-logger/core'; ...@@ -3,13 +3,14 @@ import {Logger} from 'angular2-logger/core';
import {AppService, DataStore} from '../../app.service'; import {AppService, DataStore} from '../../app.service';
import {SshComponent} from '../control/ssh/ssh.component'; import {SshComponent} from '../control/ssh/ssh.component';
import {RdpComponent} from "../control/rdp/rdp.component";
@Component({ @Component({
selector: 'app-cleftbar', selector: 'app-cleftbar',
templateUrl: './cleftbar.component.html', templateUrl: './cleftbar.component.html',
styleUrls: ['./cleftbar.component.css'], styleUrls: ['./cleftbar.component.css'],
providers: [SshComponent] providers: [SshComponent, RdpComponent]
}) })
export class CleftbarComponent implements OnInit { export class CleftbarComponent implements OnInit {
...@@ -33,6 +34,7 @@ export class CleftbarComponent implements OnInit { ...@@ -33,6 +34,7 @@ export class CleftbarComponent implements OnInit {
constructor(private _appService: AppService, constructor(private _appService: AppService,
private _term: SshComponent, private _term: SshComponent,
private _rdp: RdpComponent,
private _logger: Logger) { private _logger: Logger) {
this._logger.log('nav.ts:NavComponent'); this._logger.log('nav.ts:NavComponent');
// this._appService.getnav() // this._appService.getnav()
...@@ -46,7 +48,7 @@ export class CleftbarComponent implements OnInit { ...@@ -46,7 +48,7 @@ export class CleftbarComponent implements OnInit {
if (host.type === 'ssh') { if (host.type === 'ssh') {
this._term.TerminalConnect(host.uuid); this._term.TerminalConnect(host.uuid);
} else { } else {
this._rdp.Connect()
} }
} }
......
<app-controlnav></app-controlnav> <app-controlnav></app-controlnav>
<app-ssh></app-ssh> <!--<app-ssh></app-ssh>-->
<app-rdp></app-rdp>
import {Component, OnInit} from '@angular/core'; import {Component, OnInit} from '@angular/core';
export class Term { export class Term {
nick: string;
edit: boolean;
machine: string; machine: string;
connected: boolean;
closed: boolean;
socket: any; socket: any;
term: any; term: any;
hide: boolean;
} }
export class Rdp {
machine: string;
token: string;
}
export class View {
nick: string;
type: string;
edit: boolean;
connected: boolean;
hide: boolean;
closed: boolean;
Rdp: Rdp;
Term: Term;
}
export let NavList: { export let NavList: {
term: Array<Term>; List: Array<View>;
termlist: Array<string>; Active: number;
termActive: number;
} = { } = {
term: [new Term()], List: [new View()],
termlist: [], Active: 0,
termActive: 0,
}; };
@Component({ @Component({
......
<div id="tabs"> <div id="tabs">
<ul> <ul>
<li *ngFor="let m of NavList.term;let i = index" <li *ngFor="let m of NavList.List;let i = index"
[ngClass]="{'active':i==NavList.termActive,'disconnected':!m.connected, 'hidden': m.closed != false}" [ngClass]="{'active':i==NavList.Active,'disconnected':!m.connected, 'hidden': m.closed != false}"
id="termnav-{{i}}" (click)="setActive(i)"> id="termnav-{{i}}" (click)="setActive(i)">
<span *ngIf="!m.edit" (dblclick)="m.edit=true;setActive(i)">{{m.nick}}</span> <span *ngIf="!m.edit" (dblclick)="m.edit=true;setActive(i)">{{m.nick}}</span>
<input *ngIf="m.edit" [(ngModel)]="m.nick" autofocus (blur)="m.edit=false" (keyup.enter)="m.edit=false"/> <input *ngIf="m.edit" [(ngModel)]="m.nick" autofocus (blur)="m.edit=false" (keyup.enter)="m.edit=false"/>
......
import {Component, OnInit} from '@angular/core'; import {Component, OnInit} from '@angular/core';
import {NavList} from '../control.component' import {NavList} from '../control.component'
declare let jQuery: any;
@Component({ @Component({
...@@ -18,25 +19,32 @@ export class ControlnavComponent implements OnInit { ...@@ -18,25 +19,32 @@ export class ControlnavComponent implements OnInit {
} }
static checkActive(index) { static checkActive(index) {
let len = NavList.term.length; let len = NavList.List.length;
if (len == 1) { if (len == 1) {
// 唯一一个 // 唯一一个
NavList.termActive = 0; NavList.Active = 0;
} else if (len - 1 == index) { } else if (len - 1 == index) {
// 删了最后一个 // 删了最后一个
NavList.termActive = len - 2; NavList.Active = len - 2;
} else { } else {
NavList.termActive = index; NavList.Active = index;
} }
ControlnavComponent.setActive(NavList.termActive) ControlnavComponent.setActive(NavList.Active)
} }
static setActive(index) { static setActive(index) {
for (let m in NavList.term) { for (let m in NavList.List) {
NavList.term[m].hide = true; NavList.List[m].hide = true;
}
NavList.List[index].hide = false;
NavList.Active = index;
if (NavList.List[index].type === "ssh") {
jQuery("#ssh").show();
jQuery("#rdp").hide()
} else {
jQuery("#ssh").hide();
jQuery("#rdp").show()
} }
NavList.term[index].hide = false;
NavList.termActive = index;
} }
} }
#rdp {
width: 100%;
height: 100%;
padding: 15px;
}
#rdp > div, iframe {
width: 100%;
height: 100%;
}
iframe {
border: none;
}
<p> <div id="rdp">
rdp works! <div *ngFor="let m of NavList.List;let i=index"
</p> [ngClass]="{'disconnected':!m.connected,'hidden': m.hide,'hidden':m.type!='rdp'}" id="rdp-{{i}}">
<iframe src="http://127.0.0.1:9250/?token=000"></iframe>
</div>
</div>
import { Component, OnInit } from '@angular/core'; import {Component, OnInit} from '@angular/core';
import {NavList, View, Rdp} from '../control.component';
@Component({ @Component({
selector: 'app-rdp', selector: 'app-rdp',
...@@ -6,10 +7,26 @@ import { Component, OnInit } from '@angular/core'; ...@@ -6,10 +7,26 @@ import { Component, OnInit } from '@angular/core';
styleUrls: ['./rdp.component.css'] styleUrls: ['./rdp.component.css']
}) })
export class RdpComponent implements OnInit { export class RdpComponent implements OnInit {
NavList = NavList;
constructor() { } constructor() {
}
ngOnInit() { ngOnInit() {
} }
Connect() {
let id = NavList.List.length - 1;
NavList.List[id].nick = 'localhost';
NavList.List[id].connected = true;
NavList.List[id].edit = false;
NavList.List[id].closed = false;
NavList.List[id].type = "rdp";
NavList.List[id].Rdp = new Rdp;
NavList.List[id].Rdp.token = "xxx";
NavList.List[id].Rdp.machine = "xxx"
}
} }
<div id="term"> <div id="term">
<!--<div--> <div *ngFor="let m of NavList.List;let i=index"
<!--[ngClass]="{'disconnected':!DataStore.term[0].connected, 'hidden': i!=DataStore.termActive || DataStore.term[0].closed}"--> [ngClass]="{'disconnected':!m.connected,'hidden': m.hide,'hidden':m.type!='ssh'}" id="term-{{i}}">
<!--id="term-0"></div>-->
<div *ngFor="let m of NavList.term;let i=index"
[ngClass]="{'disconnected':!m.connected,'hidden': m.hide}" id="term-{{i}}">
</div> </div>
</div> </div>
<span id="liuzheng">liuzheng</span> <span id="liuzheng">liuzheng</span>
...@@ -6,7 +6,7 @@ import {Cookie} from 'ng2-cookies/ng2-cookies'; ...@@ -6,7 +6,7 @@ import {Cookie} from 'ng2-cookies/ng2-cookies';
declare let jQuery: any; declare let jQuery: any;
declare let Terminal: any; declare let Terminal: any;
import {AppService, DataStore} from '../../../app.service'; import {AppService, DataStore} from '../../../app.service';
import {NavList, Term} from '../control.component'; import {NavList, View, Term} from '../control.component';
@Component({ @Component({
...@@ -39,46 +39,48 @@ export class SshComponent implements OnInit { ...@@ -39,46 +39,48 @@ export class SshComponent implements OnInit {
Cookie.set('rows', rows, 99, '/', document.domain); Cookie.set('rows', rows, 99, '/', document.domain);
let id = NavList.term.length - 1; let id = NavList.List.length - 1;
NavList.term[id].machine = 'localhost'; NavList.List[id].nick = 'localhost';
NavList.term[id].nick = 'localhost'; NavList.List[id].connected = true;
NavList.term[id].connected = true; NavList.List[id].edit = false;
NavList.term[id].socket = socket; NavList.List[id].closed = false;
NavList.term[id].edit = false; NavList.List[id].type = "ssh";
NavList.term[id].closed = false; NavList.List[id].Term = new Term;
NavList.term[id].term = new Terminal({ NavList.List[id].Term.machine = 'localhost';
NavList.List[id].Term.socket = socket;
NavList.List[id].Term.term = new Terminal({
cols: cols, cols: cols,
rows: rows, rows: rows,
useStyle: true, useStyle: true,
screenKeys: true, screenKeys: true,
}); });
NavList.term.push(new Term()); NavList.List.push(new View());
for (let m in NavList.term) { for (let m in NavList.List) {
NavList.term[m].hide = true; NavList.List[m].hide = true;
} }
NavList.term[id].hide = false; NavList.List[id].hide = false;
NavList.termActive = id; NavList.Active = id;
// TermStore.term[id]['term'].on('title', function (title) { // TermStore.term[id]['term'].on('title', function (title) {
// document.title = title; // document.title = title;
// }); // });
NavList.term[id].term.open(document.getElementById('term-' + id), true); NavList.List[id].Term.term.open(document.getElementById('term-' + id), true);
NavList.term[id].term.write('\x1b[31mWelcome to Jumpserver!\x1b[m\r\n'); NavList.List[id].Term.term.write('\x1b[31mWelcome to Jumpserver!\x1b[m\r\n');
socket.on('connect', function () { socket.on('connect', function () {
socket.emit('machine', uuid); socket.emit('machine', uuid);
NavList.term[id].term.on('data', function (data) { NavList.List[id].Term.term.on('data', function (data) {
socket.emit('data', data); socket.emit('data', data);
}); });
socket.on('data', function (data) { socket.on('data', function (data) {
NavList.term[id].term.write(data); NavList.List[id].Term.term.write(data);
}); });
socket.on('disconnect', function () { socket.on('disconnect', function () {
...@@ -103,10 +105,10 @@ export class SshComponent implements OnInit { ...@@ -103,10 +105,10 @@ export class SshComponent implements OnInit {
if (row < 24) row = 24; if (row < 24) row = 24;
if (cols == col && row == rows) { if (cols == col && row == rows) {
} else { } else {
for (let tid in NavList.term) { for (let tid in NavList.List) {
if (NavList.term[tid].connected) { if (NavList.List[tid].connected) {
NavList.term[tid].socket.emit('resize', [col, row]); NavList.List[tid].Term.socket.emit('resize', [col, row]);
NavList.term[tid].term.resize(col, row); NavList.List[tid].Term.term.resize(col, row);
} }
} }
Cookie.set('cols', String(col), 99, '/', document.domain); Cookie.set('cols', String(col), 99, '/', document.domain);
...@@ -118,14 +120,14 @@ export class SshComponent implements OnInit { ...@@ -118,14 +120,14 @@ export class SshComponent implements OnInit {
} }
static TerminalDisconnect(i) { static TerminalDisconnect(i) {
NavList.term[i].connected = false; NavList.List[i].connected = false;
NavList.term[i].socket.destroy(); NavList.List[i].Term.socket.destroy();
NavList.term[i].term.write('\r\n\x1b[31mBye Bye!\x1b[m\r\n'); NavList.List[i].Term.term.write('\r\n\x1b[31mBye Bye!\x1b[m\r\n');
} }
static TerminalDisconnectAll() { static TerminalDisconnectAll() {
alert("TerminalDisconnectAll"); alert("TerminalDisconnectAll");
for (let i in NavList.term) { for (let i in NavList.List) {
SshComponent.TerminalDisconnect(i); SshComponent.TerminalDisconnect(i);
// TermStore.term[i]["connected"] = false; // TermStore.term[i]["connected"] = false;
// TermStore.term[i]["socket"].destroy(); // TermStore.term[i]["socket"].destroy();
......
...@@ -3,8 +3,8 @@ import {AppService, DataStore, User} from '../app.service'; ...@@ -3,8 +3,8 @@ import {AppService, DataStore, User} from '../app.service';
@Component({ @Component({
selector: 'app-controllpage', selector: 'app-controllpage',
templateUrl: './control.component.html', templateUrl: './controlpage.component.html',
styleUrls: ['./control.component.css'], styleUrls: ['./controlpage.component.css'],
providers: [AppService] providers: [AppService]
}) })
......
...@@ -14,7 +14,7 @@ const appRoutes: Routes = [ ...@@ -14,7 +14,7 @@ const appRoutes: Routes = [
// { path: 'crisis-center', component: CrisisListComponent }, // { path: 'crisis-center', component: CrisisListComponent },
{path: 'welcome', component: IndexPageComponent}, // <-- delete this line {path: 'welcome', component: IndexPageComponent}, // <-- delete this line
{path: 'login', component: LoginComponent}, {path: 'login', component: LoginComponent},
{path: 'term', component: ControlPageComponent}, {path: 'control', component: ControlPageComponent},
{path: '', redirectTo: '/welcome', pathMatch: 'full'}, {path: '', redirectTo: '/welcome', pathMatch: 'full'},
{path: '**', component: PageNotFoundComponent} {path: '**', component: PageNotFoundComponent}
]; ];
......
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