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

@ -8,11 +8,14 @@
(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')

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: {
},
},