diff --git a/terminus-ssh/src/components/sshModal.component.pug b/terminus-ssh/src/components/sshModal.component.pug index f1d97ae6dd8e3dec1af1bf7499a982deb28ba822..e5c2b2a570cd771c28b9cae93652164e04612748 100644 --- a/terminus-ssh/src/components/sshModal.component.pug +++ b/terminus-ssh/src/components/sshModal.component.pug @@ -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}} diff --git a/terminus-ssh/src/components/sshModal.component.ts b/terminus-ssh/src/components/sshModal.component.ts index 388e982fe1fc9375e44c3e5ac1db586ae40bd3db..0d8628417b39ca5f0cd383d041fed7c4d9abf6b2 100644 --- a/terminus-ssh/src/components/sshModal.component.ts +++ b/terminus-ssh/src/components/sshModal.component.ts @@ -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) { diff --git a/terminus-ssh/src/config.ts b/terminus-ssh/src/config.ts index d32160df32a92b20f767ecbc538c0a5bfc57bb30..e4963cbb7a321439be49dd551d795b0a2fe7b6ae 100644 --- a/terminus-ssh/src/config.ts +++ b/terminus-ssh/src/config.ts @@ -5,6 +5,7 @@ export class SSHConfigProvider extends ConfigProvider { defaults = { ssh: { connections: [], + recentConnections: [], options: { }, },