Have multiple recent connections in history instead of just one

This commit is contained in:
Nikolaos Stefanou 2020-03-11 20:37:17 +00:00
parent 2773c61677
commit d1f5ebd546
No known key found for this signature in database
GPG Key ID: 904BA59F31C48FB6
3 changed files with 31 additions and 21 deletions

View File

@ -1,22 +1,25 @@
.modal-body
input.form-control(
type='text',
[(ngModel)]='quickTarget',
autofocus,
placeholder='Quick connect: [user@]host[:port]',
type='text',
[(ngModel)]='quickTarget',
autofocus,
placeholder='Quick connect: [user@]host[:port]',
(ngModelChange)='refresh()',
(keyup.enter)='quickConnect()'
)
.list-group.mt-3(*ngIf='lastConnection')
a.list-group-item.list-group-item-action.d-flex.align-items-center((click)='connect(lastConnection)')
.list-group.mt-3(*ngIf='recentConnections')
a.list-group-item.list-group-item-action.d-flex.align-items-center(
*ngFor='let connection of recentConnections',
(click)='connect(connection)'
)
i.fas.fa-fw.fa-history
.mr-auto {{lastConnection.name}}
button.btn.btn-outline-danger.btn-sm((click)='clearLastConnection(); $event.stopPropagation()')
.mr-auto {{connection.name}}
button.btn.btn-outline-danger.btn-sm((click)='clearConnection(connection); $event.stopPropagation()')
i.fas.fa-trash
.list-group.mt-3.connections-list(*ngIf='childGroups.length')
ng-container(*ngFor='let group of childGroups')
ng-container(*ngFor='let group of childGroups')
.list-group-item.list-group-item-action.d-flex.align-items-center(
(click)='groupCollapsed[group.name] = !groupCollapsed[group.name]'
)
@ -25,8 +28,8 @@
.ml-2 {{group.name || "Ungrouped"}}
ng-container(*ngIf='!groupCollapsed[group.name]')
.list-group-item.list-group-item-action.pl-5.d-flex.align-items-center(
*ngFor='let connection of group.connections',
*ngFor='let connection of group.connections',
(click)='connect(connection)'
)
)
.mr-2 {{connection.name}}
.text-muted {{connection.host}}

View File

@ -16,7 +16,7 @@ export class SSHModalComponent {
connections: SSHConnection[]
childFolders: SSHConnectionGroup[]
quickTarget: string
lastConnection: SSHConnection|null = null
recentConnections: SSHConnection[]
childGroups: SSHConnectionGroup[]
groupCollapsed: {[id: string]: boolean} = {}
@ -30,9 +30,7 @@ export class SSHModalComponent {
ngOnInit () {
this.connections = this.config.store.ssh.connections
if (window.localStorage.lastConnection) {
this.lastConnection = JSON.parse(window.localStorage.lastConnection)
}
this.recentConnections = this.config.store.ssh.recentConnections
this.refresh()
}
@ -55,13 +53,21 @@ export class SSHModalComponent {
user,
port,
}
window.localStorage.lastConnection = JSON.stringify(connection)
this.recentConnections.unshift(connection)
if (this.recentConnections.length > 5) {
this.recentConnections.pop()
}
this.config.store.ssh.recentConnections = this.recentConnections
this.config.save()
this.connect(connection)
}
clearLastConnection () {
window.localStorage.lastConnection = null
this.lastConnection = null
clearConnection (connection) {
this.recentConnections = this.recentConnections.filter(function (el) {
return el === connection
})
this.config.store.ssh.recentConnections = this.recentConnections
this.config.save()
}
async connect (connection: SSHConnection) {

View File

@ -5,6 +5,7 @@ export class SSHConfigProvider extends ConfigProvider {
defaults = {
ssh: {
connections: [],
recentConnections: [],
options: {
},
},