Skip to content

Commit

Permalink
Feature/copy logs (#1491)
Browse files Browse the repository at this point in the history
* make text selectable on mobile

* make logs copyable and adjust copy format

* fix linting

* fix linting further

* linting

* add formatting to copied logs

* fix copy abstraction and add formatting for server log copy
  • Loading branch information
elvece committed Jun 19, 2022
1 parent 09922c8 commit 3cde39c
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export class SuccessPage {

async copy(address: string): Promise<void> {
const success = await this.copyToClipboard(address)
const message = success ? 'copied to clipboard!' : 'failed to copy'
const message = success
? 'Copied to clipboard!'
: 'Failed to copy to clipboard.'

const toast = await this.toastCtrl.create({
header: message,
Expand Down
27 changes: 17 additions & 10 deletions frontend/projects/shared/styles/shared.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
$wide-modal: 900px;

body {
-webkit-user-select: text;
-moz-user-select: text;
-ms-user-select: text;
user-select: text;
}

ion-input {
caret-color: gray;
}
Expand Down Expand Up @@ -73,17 +80,17 @@ ion-modal::part(content) {
}

/* Hide scrollbar for IE, Edge and Firefox */
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
/* IE and Edge */
-ms-overflow-style: none;
/* Firefox */
scrollbar-width: none;
}

.divider {
background: linear-gradient(
90deg,
var(--ion-color-light) 0,
var(--ion-color-dark) 50%,
var(--ion-color-light) 100%
);
background: linear-gradient(90deg,
var(--ion-color-light) 0,
var(--ion-color-dark) 50%,
var(--ion-color-light) 100%);
height: 1px;
}

Expand All @@ -98,5 +105,5 @@ ion-modal::part(content) {
}

.montserrat {
font-family: 'Montserrat', sans-serif!important;
}
font-family: 'Montserrat', sans-serif !important;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ import { copyToClipboard } from 'src/app/util/web.util'
export class ActionSuccessPage {
@Input() actionRes: ActionResponse

constructor (
constructor(
private readonly modalCtrl: ModalController,
private readonly toastCtrl: ToastController,
) { }
) {}

async copy (address: string) {
async copy(address: string) {
let message = ''
await copyToClipboard(address || '')
.then(success => { message = success ? 'copied to clipboard!' : 'failed to copy'})
await copyToClipboard(address || '').then(success => {
message = success
? 'Copied to clipboard!'
: 'Failed to copy to clipboard.'
})

const toast = await this.toastCtrl.create({
header: message,
Expand All @@ -29,7 +32,7 @@ export class ActionSuccessPage {
await toast.present()
}

async dismiss () {
async dismiss() {
return this.modalCtrl.dismiss()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ export class AppInterfacesItemComponent {
async copy(address: string): Promise<void> {
let message = ''
await copyToClipboard(address || '').then(success => {
message = success ? 'copied to clipboard!' : 'failed to copy'
message = success
? 'Copied to clipboard!'
: 'Failed to copy to clipboard.'
})

const toast = await this.toastCtrl.create({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
<ion-back-button [defaultHref]="'/services/' + pkgId"></ion-back-button>
</ion-buttons>
<ion-title>Logs</ion-title>
<ion-button slot="end" fill="clear" size="small" (click)="copy()">
<ion-icon slot="icon-only" name="copy-outline"></ion-icon>
</ion-button>
</ion-toolbar>
</ion-header>

<div style="height: 100%">
<logs [fetchLogs]="fetchFetchLogs()"></logs>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Component } from '@angular/core'
import { ActivatedRoute } from '@angular/router'
import { getPkgId } from '@start9labs/shared'
import { ToastController } from '@ionic/angular'
import { ApiService } from 'src/app/services/api/embassy-api.service'
import { copyToClipboard } from 'src/app/util/web.util'

@Component({
selector: 'app-logs',
Expand All @@ -17,6 +19,7 @@ export class AppLogsPage {
constructor(
private readonly route: ActivatedRoute,
private readonly embassyApi: ApiService,
private readonly toastCtrl: ToastController,
) {}

fetchFetchLogs() {
Expand All @@ -33,4 +36,22 @@ export class AppLogsPage {
})
}
}

async copy(): Promise<void> {
const logs = document
.getElementById('template')
?.cloneNode(true) as HTMLElement
const formatted = '```' + logs.innerHTML + '```'
const success = await copyToClipboard(formatted)
const message = success
? 'Copied to clipboard!'
: 'Failed to copy to clipboard.'

const toast = await this.toastCtrl.create({
header: message,
position: 'bottom',
duration: 1000,
})
await toast.present()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ export class AppPropertiesPage {
async copy(text: string): Promise<void> {
let message = ''
await copyToClipboard(text).then(success => {
message = success ? 'copied to clipboard!' : 'failed to copy'
message = success
? 'Copied to clipboard!'
: 'Failed to copy to clipboard.'
})

const toast = await this.toastCtrl.create({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<ion-back-button defaultHref="embassy"></ion-back-button>
</ion-buttons>
<ion-title>OS Logs</ion-title>
<ion-button slot="end" fill="clear" size="small" (click)="copy()">
<ion-icon slot="icon-only" name="copy-outline"></ion-icon>
</ion-button>
</ion-toolbar>
</ion-header>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Component } from '@angular/core'
import { ToastController } from '@ionic/angular'
import { ApiService } from 'src/app/services/api/embassy-api.service'
import { copyToClipboard } from 'src/app/util/web.util'

@Component({
selector: 'server-logs',
Expand All @@ -14,10 +16,15 @@ export class ServerLogsPage {

constructor(
private readonly embassyApi: ApiService,
private readonly toastCtrl: ToastController,
) { }

fetchFetchLogs() {
return async (params: { before_flag?: boolean, limit?: number, cursor?: string }) => {
return async (params: {
before_flag?: boolean
limit?: number
cursor?: string
}) => {
return this.embassyApi.getServerLogs({
before_flag: params.before_flag,
cursor: params.cursor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export class ServerSpecsPage {
async copy(address: string) {
let message = ''
await copyToClipboard(address || '').then(success => {
message = success ? 'copied to clipboard!' : 'failed to copy'
message = success
? 'Copied to clipboard!'
: 'Failed to copy to clipboard.'
})

const toast = await this.toastCtrl.create({
Expand Down

0 comments on commit 3cde39c

Please sign in to comment.