From d1f5ebd54693b94201d5a7edfc48f3e7a025124b Mon Sep 17 00:00:00 2001 From: Nikolaos Stefanou Date: Wed, 11 Mar 2020 20:37:17 +0000 Subject: [PATCH] Have multiple recent connections in history instead of just one --- .../src/components/sshModal.component.pug | 29 ++++++++++--------- .../src/components/sshModal.component.ts | 22 +++++++++----- terminus-ssh/src/config.ts | 1 + 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/terminus-ssh/src/components/sshModal.component.pug b/terminus-ssh/src/components/sshModal.component.pug index f1d97ae6..e5c2b2a5 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 388e982f..0d862841 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 d32160df..e4963cbb 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: { }, }, -- GitLab