Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closes #2340 and #2431, fixes bug with select all for backup #2780

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component } from '@angular/core'
import { ModalController } from '@ionic/angular'
import { map, take } from 'rxjs/operators'
import { map } from 'rxjs/operators'
import { DataModel } from 'src/app/services/patch-db/data-model'
import { PatchDB } from 'patch-db-client'
import { firstValueFrom } from 'rxjs'
Expand All @@ -13,7 +13,7 @@ import { getManifest } from 'src/app/util/get-package-data'
})
export class BackupSelectPage {
hasSelection = false
selectAll = false
selectAll = true
pkgs: {
id: string
title: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<ion-content>
<div style="padding: 48px">
<ng-container *ngIf="!restarted; else refresh">
<h1
class="ion-text-center"
style="padding-bottom: 36px; font-size: calc(2vw + 14px)"
>
StartOS - Diagnostic Mode
</h1>
<div class="ion-text-center" style="padding-bottom: 36px">
<h1 style="font-size: calc(2vw + 14px)">StartOS - Diagnostic Mode</h1>
<p>StartOS version: {{ config.version }}</p>
</div>

<ng-container *ngIf="error">
<h2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component } from '@angular/core'
import { AlertController } from '@ionic/angular'
import { LoadingService } from '@start9labs/shared'
import { ApiService } from 'src/app/services/api/embassy-api.service'
import { ConfigService } from 'src/app/services/config.service'

@Component({
selector: 'diagnostic-home',
Expand All @@ -22,6 +23,7 @@ export class HomePage {
private readonly loader: LoadingService,
private readonly api: ApiService,
private readonly alertCtrl: AlertController,
readonly config: ConfigService,
) {}

async ngOnInit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
<ion-back-button defaultHref="/"></ion-back-button>
</ion-buttons>
<ion-title>Logs</ion-title>
<ion-button
slot="end"
class="ion-padding-end"
fill="clear"
strong
(click)="download()"
>
Download
<ion-icon slot="end" name="download-outline"></ion-icon>
</ion-button>
</ion-toolbar>
</ion-header>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { Component, ViewChild } from '@angular/core'
import { IonContent } from '@ionic/angular'
import { ErrorService, toLocalIsoString } from '@start9labs/shared'
import {
DownloadHTMLService,
ErrorService,
LoadingService,
Log,
toLocalIsoString,
} from '@start9labs/shared'
import { ApiService } from 'src/app/services/api/embassy-api.service'

var Convert = require('ansi-to-html')
Expand All @@ -24,6 +30,8 @@ export class LogsPage {
constructor(
private readonly api: ApiService,
private readonly errorService: ErrorService,
private readonly loader: LoadingService,
private readonly downloadHtml: DownloadHTMLService,
) {}

async ngOnInit() {
Expand All @@ -47,6 +55,30 @@ export class LogsPage {
e.target.complete()
}

async download() {
const loader = this.loader.open('Processing 10,000 logs...').subscribe()

try {
const { entries } = await this.api.diagnosticGetLogs({
before: true,
limit: 10000,
})

const styles = {
'background-color': '#222428',
color: '#e0e0e0',
'font-family': 'monospace',
}
const html = this.convertToAnsi(entries)

this.downloadHtml.download('diagnostic-logs.html', html, styles)
} catch (e: any) {
this.errorService.handleError(e)
} finally {
loader.unsubscribe()
}
}

private async getLogs() {
try {
const { startCursor, entries } = await this.api.diagnosticGetLogs({
Expand Down Expand Up @@ -92,4 +124,15 @@ export class LogsPage {
this.errorService.handleError(e)
}
}

private convertToAnsi(entries: Log[]) {
return entries
.map(
entry =>
`<span style="color: #FFF; font-weight: bold;">${toLocalIsoString(
new Date(entry.timestamp),
)}</span>&nbsp;&nbsp;${convert.toHtml(entry.message)}`,
)
.join('<br />')
}
}