From 83755e93dc86485378e3cc92dd2a6944dc43d699 Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Thu, 23 Jun 2022 16:59:13 -0600 Subject: [PATCH] kill all sessions and remove ripple effect (#1567) * button to kill all sessions, session sorting, remove ripple effect from buttons * pr cleanup Co-authored-by: Matt Hill Co-authored-by: Lucy Cifferello <12953208+elvece@users.noreply.github.com> --- .../marketplaces/marketplaces.page.html | 5 +- .../server-show/server-show.page.ts | 2 +- .../server-routes/sessions/sessions.page.html | 97 +++++++++++++------ .../server-routes/sessions/sessions.page.ts | 71 +++++++++++--- .../server-routes/ssh-keys/ssh-keys.page.html | 51 +++++++--- .../pages/server-routes/wifi/wifi.page.html | 6 +- frontend/projects/ui/src/styles.scss | 1 + 7 files changed, 168 insertions(+), 65 deletions(-) diff --git a/frontend/projects/ui/src/app/pages/server-routes/marketplaces/marketplaces.page.html b/frontend/projects/ui/src/app/pages/server-routes/marketplaces/marketplaces.page.html index 1f2996e59..309f31554 100644 --- a/frontend/projects/ui/src/app/pages/server-routes/marketplaces/marketplaces.page.html +++ b/frontend/projects/ui/src/app/pages/server-routes/marketplaces/marketplaces.page.html @@ -11,7 +11,7 @@ Saved Marketplaces - + Add alt marketplace @@ -37,9 +37,6 @@

{{ mp.name }}

{{ mp.url }}

- - Selected -
diff --git a/frontend/projects/ui/src/app/pages/server-routes/server-show/server-show.page.ts b/frontend/projects/ui/src/app/pages/server-routes/server-show/server-show.page.ts index 44b706f54..e76e0eb1e 100644 --- a/frontend/projects/ui/src/app/pages/server-routes/server-show/server-show.page.ts +++ b/frontend/projects/ui/src/app/pages/server-routes/server-show/server-show.page.ts @@ -328,7 +328,7 @@ export class ServerShowPage { }, { title: 'Sideload Service', - description: `Manually install any service package`, + description: `Manually install a service`, icon: 'push-outline', action: () => this.navCtrl.navigateForward(['sideload'], { diff --git a/frontend/projects/ui/src/app/pages/server-routes/sessions/sessions.page.html b/frontend/projects/ui/src/app/pages/server-routes/sessions/sessions.page.html index b518bb5de..a206f5871 100644 --- a/frontend/projects/ui/src/app/pages/server-routes/sessions/sessions.page.html +++ b/frontend/projects/ui/src/app/pages/server-routes/sessions/sessions.page.html @@ -8,22 +8,33 @@ - -
+
{{ entry }} - - - + + + - - - + + + - +
@@ -31,35 +42,61 @@ - - This Session - - + Current Session + + -

{{ getPlatformName(current.metadata.platforms) }}

-

Last Active: {{ current['last-active'] | date : 'medium' }}

-

{{ current['user-agent'] }}

+

{{ getPlatformName(currentSession.metadata.platforms) }}

+

+ Last Active: {{ currentSession['last-active'] | date : 'medium' }} +

+

{{ currentSession['user-agent'] }}

- Other Sessions -
- + Other Sessions + - + Kill All + + +
+ + -

{{ getPlatformName(session.value.metadata.platforms) }}

-

Last Active: {{ session.value['last-active'] | date : 'medium' }}

-

{{ session.value['user-agent'] }}

+

{{ getPlatformName(session.metadata.platforms) }}

+

Last Active: {{ session['last-active'] | date : 'medium' }}

+

{{ session['user-agent'] }}

- - - Kill + +
+ + +

You are not logged in anywhere else

+
+
- - \ No newline at end of file + diff --git a/frontend/projects/ui/src/app/pages/server-routes/sessions/sessions.page.ts b/frontend/projects/ui/src/app/pages/server-routes/sessions/sessions.page.ts index f59e3ed51..6a5834648 100644 --- a/frontend/projects/ui/src/app/pages/server-routes/sessions/sessions.page.ts +++ b/frontend/projects/ui/src/app/pages/server-routes/sessions/sessions.page.ts @@ -1,8 +1,12 @@ import { Component } from '@angular/core' -import { AlertController, LoadingController } from '@ionic/angular' +import { + AlertController, + IonicSafeString, + LoadingController, +} from '@ionic/angular' import { ErrorToastService } from '@start9labs/shared' import { ApiService } from 'src/app/services/api/embassy-api.service' -import { PlatformType, RR } from 'src/app/services/api/api.types' +import { PlatformType, Session } from 'src/app/services/api/api.types' @Component({ selector: 'sessions', @@ -11,7 +15,8 @@ import { PlatformType, RR } from 'src/app/services/api/api.types' }) export class SessionsPage { loading = true - sessionInfo: RR.GetSessionsRes + currentSession: Session + otherSessions: SessionWithId[] = [] constructor( private readonly loadingCtrl: LoadingController, @@ -22,7 +27,22 @@ export class SessionsPage { async ngOnInit() { try { - this.sessionInfo = await this.embassyApi.getSessions({}) + const sessionInfo = await this.embassyApi.getSessions({}) + this.currentSession = sessionInfo.sessions[sessionInfo.current] + delete sessionInfo.sessions[sessionInfo.current] + this.otherSessions = Object.entries(sessionInfo.sessions) + .map(([id, session]) => { + return { + id, + ...session, + } + }) + .sort((a, b) => { + return ( + new Date(b['last-active']).valueOf() - + new Date(a['last-active']).valueOf() + ) + }) } catch (e: any) { this.errToast.present(e) } finally { @@ -30,19 +50,21 @@ export class SessionsPage { } } - async presentAlertKill(id: string) { + async presentAlertKillAll() { const alert = await this.alertCtrl.create({ - header: 'Caution', - message: `Are you sure you want to kill this session?`, + header: 'Confirm', + message: new IonicSafeString( + `Kill all sessions?

Note: you will not be logged out of your current session on this device.`, + ), buttons: [ { text: 'Cancel', role: 'cancel', }, { - text: 'Kill', + text: 'Kill All', handler: () => { - this.kill(id) + this.kill(this.otherSessions.map(s => s.id)) }, cssClass: 'enter-click', }, @@ -51,15 +73,36 @@ export class SessionsPage { await alert.present() } - async kill(id: string): Promise { + async presentAlertKill(id: string) { + const alert = await this.alertCtrl.create({ + header: 'Confirm', + message: `Kill this session?`, + buttons: [ + { + text: 'Cancel', + role: 'cancel', + }, + { + text: 'Kill', + handler: () => { + this.kill([id]) + }, + cssClass: 'enter-click', + }, + ], + }) + await alert.present() + } + + async kill(ids: string[]): Promise { const loader = await this.loadingCtrl.create({ message: 'Killing session...', }) await loader.present() try { - await this.embassyApi.killSessions({ ids: [id] }) - delete this.sessionInfo.sessions[id] + await this.embassyApi.killSessions({ ids }) + this.otherSessions = this.otherSessions.filter(s => !ids.includes(s.id)) } catch (e: any) { this.errToast.present(e) } finally { @@ -99,3 +142,7 @@ export class SessionsPage { return 0 } } + +interface SessionWithId extends Session { + id: string +} diff --git a/frontend/projects/ui/src/app/pages/server-routes/ssh-keys/ssh-keys.page.html b/frontend/projects/ui/src/app/pages/server-routes/ssh-keys/ssh-keys.page.html index 66d17fffa..35751ea61 100644 --- a/frontend/projects/ui/src/app/pages/server-routes/ssh-keys/ssh-keys.page.html +++ b/frontend/projects/ui/src/app/pages/server-routes/ssh-keys/ssh-keys.page.html @@ -9,13 +9,15 @@ -

- Adding SSH keys to your Embassy is useful for command line access, as well as for debugging purposes. - View instructions + Adding SSH keys to your Embassy is useful for command line access, as + well as for debugging purposes. + View instructions

@@ -23,23 +25,37 @@ Saved Keys - - Add new key + + + Add new key + - - + + - - - + + + - + @@ -53,13 +69,16 @@

{{ ssh['created-at'] | date: 'short' }}

{{ ssh.alg }} {{ ssh.fingerprint }}

- + Remove
- - + - - \ No newline at end of file + diff --git a/frontend/projects/ui/src/app/pages/server-routes/wifi/wifi.page.html b/frontend/projects/ui/src/app/pages/server-routes/wifi/wifi.page.html index 6cbea6b0a..3fb4fc887 100644 --- a/frontend/projects/ui/src/app/pages/server-routes/wifi/wifi.page.html +++ b/frontend/projects/ui/src/app/pages/server-routes/wifi/wifi.page.html @@ -163,8 +163,10 @@ - - Join other network + + + Join another network + diff --git a/frontend/projects/ui/src/styles.scss b/frontend/projects/ui/src/styles.scss index 21bafae43..db31afd59 100644 --- a/frontend/projects/ui/src/styles.scss +++ b/frontend/projects/ui/src/styles.scss @@ -247,6 +247,7 @@ ion-item-divider { ion-item { border-radius: 6px; + --ripple-color: transparent; } ion-label {