mirror of
https://github.com/eugeny/tabby
synced 2025-12-15 12:15:44 +00:00
added SSH connection manager (fixes #220)
This commit is contained in:
60
terminus-ssh/src/components/sshModal.component.ts
Normal file
60
terminus-ssh/src/components/sshModal.component.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { Component } from '@angular/core'
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
|
||||
import { ConfigService, AppService } from 'terminus-core'
|
||||
import { SettingsTabComponent } from 'terminus-settings'
|
||||
import { SSHService } from '../services/ssh.service'
|
||||
import { SSHConnection } from '../api'
|
||||
|
||||
@Component({
|
||||
template: require('./sshModal.component.pug'),
|
||||
//styles: [require('./sshModal.component.scss')],
|
||||
})
|
||||
export class SSHModalComponent {
|
||||
connections: SSHConnection[]
|
||||
quickTarget: string
|
||||
lastConnection: SSHConnection
|
||||
|
||||
constructor (
|
||||
public modalInstance: NgbActiveModal,
|
||||
private config: ConfigService,
|
||||
private ssh: SSHService,
|
||||
private app: AppService,
|
||||
) { }
|
||||
|
||||
ngOnInit () {
|
||||
this.connections = this.config.store.ssh.connections
|
||||
if (window.localStorage.lastConnection) {
|
||||
this.lastConnection = JSON.parse(window.localStorage.lastConnection)
|
||||
}
|
||||
}
|
||||
|
||||
quickConnect () {
|
||||
let user = 'root'
|
||||
let host = this.quickTarget
|
||||
if (host.includes('@')) {
|
||||
[user, host] = host.split('@')
|
||||
}
|
||||
let connection: SSHConnection = {
|
||||
name: this.quickTarget,
|
||||
host, user,
|
||||
}
|
||||
window.localStorage.lastConnection = JSON.stringify(connection)
|
||||
this.connect(connection)
|
||||
}
|
||||
|
||||
connect (connection: SSHConnection) {
|
||||
this.close()
|
||||
this.ssh.connect(connection).catch(error => {
|
||||
alert(`Could not connect: ${error}`)
|
||||
})
|
||||
}
|
||||
|
||||
manageConnections () {
|
||||
this.close()
|
||||
this.app.openNewTab(SettingsTabComponent, { activeTab: 'ssh' })
|
||||
}
|
||||
|
||||
close () {
|
||||
this.modalInstance.close()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user