mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
backend integration
This commit is contained in:
committed by
Aiden McClelland
parent
064c905bd3
commit
4b2a032ae0
@@ -1,7 +1,7 @@
|
|||||||
import { Component, Input, ViewChild } from '@angular/core'
|
import { Component, Input, ViewChild } from '@angular/core'
|
||||||
import { IonContent } from '@ionic/angular'
|
import { IonContent } from '@ionic/angular'
|
||||||
import { ErrorToastService } from 'src/app/services/error-toast.service'
|
import { ErrorToastService } from 'src/app/services/error-toast.service'
|
||||||
import { Log } from 'src/app/services/api/api.types'
|
import { RR } from 'src/app/services/api/api.types'
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'logs',
|
selector: 'logs',
|
||||||
@@ -10,13 +10,13 @@ import { Log } from 'src/app/services/api/api.types'
|
|||||||
})
|
})
|
||||||
export class LogsPage {
|
export class LogsPage {
|
||||||
@ViewChild(IonContent) private content: IonContent
|
@ViewChild(IonContent) private content: IonContent
|
||||||
@Input() fetchLogs: (params: { before?: string, after?: string, limit: number }) => Promise<Log[]>
|
@Input() fetchLogs: (params: { before_flag?: boolean, limit?: number, cursor?: string }) => Promise<RR.LogsRes>
|
||||||
loading = true
|
loading = true
|
||||||
loadingMore = false
|
loadingMore = false
|
||||||
logs: string
|
logs: string
|
||||||
needInfinite = true
|
needInfinite = true
|
||||||
before: string
|
startCursor: string
|
||||||
after: string
|
endCursor: string
|
||||||
limit = 200
|
limit = 200
|
||||||
scrollToBottomButton = false
|
scrollToBottomButton = false
|
||||||
isOnBottom = true
|
isOnBottom = true
|
||||||
@@ -31,16 +31,22 @@ export class LogsPage {
|
|||||||
|
|
||||||
async fetch (isBefore: boolean = true) {
|
async fetch (isBefore: boolean = true) {
|
||||||
try {
|
try {
|
||||||
const logs = await this.fetchLogs({
|
const cursor = isBefore ? this.startCursor : this.endCursor
|
||||||
before: isBefore ? this.before : undefined,
|
const logsRes = await this.fetchLogs({
|
||||||
after: !isBefore ? this.after : undefined,
|
cursor,
|
||||||
|
before_flag: !!cursor ? isBefore : undefined,
|
||||||
limit: this.limit,
|
limit: this.limit,
|
||||||
})
|
})
|
||||||
this.before = logs[0]?.timestamp
|
|
||||||
this.after = logs[logs.length - 1]?.timestamp
|
if (isBefore && logsRes.startCursor) {
|
||||||
|
this.startCursor = logsRes.startCursor
|
||||||
|
}
|
||||||
|
if (!isBefore && logsRes.endCursor) {
|
||||||
|
this.endCursor = logsRes.endCursor
|
||||||
|
}
|
||||||
this.loading = false
|
this.loading = false
|
||||||
|
|
||||||
return logs
|
return logsRes.logs
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.errToast.present(e)
|
this.errToast.present(e)
|
||||||
}
|
}
|
||||||
@@ -50,8 +56,6 @@ export class LogsPage {
|
|||||||
try {
|
try {
|
||||||
// get logs
|
// get logs
|
||||||
const logs = await this.fetch()
|
const logs = await this.fetch()
|
||||||
this.before = logs[0].timestamp
|
|
||||||
|
|
||||||
const container = document.getElementById('container')
|
const container = document.getElementById('container')
|
||||||
const beforeContainerHeight = container.scrollHeight
|
const beforeContainerHeight = container.scrollHeight
|
||||||
const newLogs = document.getElementById('template').cloneNode(true) as HTMLElement
|
const newLogs = document.getElementById('template').cloneNode(true) as HTMLElement
|
||||||
|
|||||||
@@ -17,12 +17,12 @@ export class AppLogsPage {
|
|||||||
) { }
|
) { }
|
||||||
|
|
||||||
fetchFetchLogs (): Function {
|
fetchFetchLogs (): Function {
|
||||||
return async (params: { after?: string, before?: string, limit: number }) => {
|
return async (params: { before_flag?: boolean, limit?: number, cursor?: string }) => {
|
||||||
const pkgId = this.pkgId
|
const pkgId = this.pkgId
|
||||||
return this.embassyApi.getPackageLogs({
|
return this.embassyApi.getPackageLogs({
|
||||||
id: pkgId,
|
id: pkgId,
|
||||||
after: params.after,
|
before_flag: params.before_flag,
|
||||||
before: params.before,
|
cursor: params.cursor,
|
||||||
limit: params.limit,
|
limit: params.limit,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ export class ServerLogsPage {
|
|||||||
) { }
|
) { }
|
||||||
|
|
||||||
fetchFetchLogs (): Function {
|
fetchFetchLogs (): Function {
|
||||||
return async (params: { before?: string, after?: string, limit: number }) => {
|
return async (params: { before_flag?: boolean, limit?: number, cursor?: string }) => {
|
||||||
return this.embassyApi.getServerLogs({
|
return this.embassyApi.getServerLogs({
|
||||||
after: params.after,
|
before_flag: params.before_flag,
|
||||||
before: params.before,
|
cursor: params.cursor,
|
||||||
limit: params.limit,
|
limit: params.limit,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { DependencyErrorType, DockerIoFormat, Manifest, PackageDataEntry, PackageMainStatus, PackageState } from 'src/app/services/patch-db/data-model'
|
import { DependencyErrorType, DockerIoFormat, Manifest, PackageDataEntry, PackageMainStatus, PackageState } from 'src/app/services/patch-db/data-model'
|
||||||
import { MarketplacePkg, Metric, NotificationLevel, RR, ServerNotifications } from './api.types'
|
import { Log, MarketplacePkg, Metric, NotificationLevel, RR, ServerNotifications } from './api.types'
|
||||||
|
|
||||||
export module Mock {
|
export module Mock {
|
||||||
|
|
||||||
@@ -782,7 +782,7 @@ export module Mock {
|
|||||||
return metr
|
return metr
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ServerLogs: RR.GetServerLogsRes = [
|
export const ServerLogs: Log[] = [
|
||||||
{
|
{
|
||||||
timestamp: '2019-12-26T14:20:30.872Z',
|
timestamp: '2019-12-26T14:20:30.872Z',
|
||||||
log: '****** START *****',
|
log: '****** START *****',
|
||||||
@@ -797,7 +797,7 @@ export module Mock {
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
export const PackageLogs: RR.GetPackageLogsRes = [
|
export const PackageLogs: Log[] = [
|
||||||
{
|
{
|
||||||
timestamp: '2019-12-26T14:20:30.872Z',
|
timestamp: '2019-12-26T14:20:30.872Z',
|
||||||
log: '****** START *****',
|
log: '****** START *****',
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ export module RR {
|
|||||||
export type SetShareStatsReq = WithExpire<{ value: any }> // server.config.share-stats
|
export type SetShareStatsReq = WithExpire<{ value: any }> // server.config.share-stats
|
||||||
export type SetShareStatsRes = WithRevision<null>
|
export type SetShareStatsRes = WithRevision<null>
|
||||||
|
|
||||||
export type GetServerLogsReq = { before?: string, after?: string, limit?: number } // server.logs
|
export type GetServerLogsReq = { cursor?: string, before_flag?: boolean, limit?: number }
|
||||||
export type GetServerLogsRes = Log[]
|
export type GetServerLogsRes = LogsRes
|
||||||
|
|
||||||
export type GetServerMetricsReq = { } // server.metrics
|
export type GetServerMetricsReq = { } // server.metrics
|
||||||
export type GetServerMetricsRes = Metrics
|
export type GetServerMetricsRes = Metrics
|
||||||
@@ -137,8 +137,10 @@ export module RR {
|
|||||||
export type GetPackagePropertiesReq = { id: string } // package.properties
|
export type GetPackagePropertiesReq = { id: string } // package.properties
|
||||||
export type GetPackagePropertiesRes<T extends number> = PackagePropertiesVersioned<T>
|
export type GetPackagePropertiesRes<T extends number> = PackagePropertiesVersioned<T>
|
||||||
|
|
||||||
export type GetPackageLogsReq = { id: string, limit?: number, before?: string, after?: string } // package.logs
|
export type LogsRes = { logs: Log[], startCursor?: string, endCursor?: string }
|
||||||
export type GetPackageLogsRes = Log[]
|
|
||||||
|
export type GetPackageLogsReq = { id: string, cursor?: string, before_flag?: boolean, limit?: number } // package.logs
|
||||||
|
export type GetPackageLogsRes = LogsRes
|
||||||
|
|
||||||
export type GetPackageMetricsReq = { id: string } // package.metrics
|
export type GetPackageMetricsReq = { id: string } // package.metrics
|
||||||
export type GetPackageMetricsRes = Metric
|
export type GetPackageMetricsRes = Metric
|
||||||
|
|||||||
@@ -75,12 +75,19 @@ export class MockApiService extends ApiService {
|
|||||||
|
|
||||||
async getServerLogs (params: RR.GetServerLogsReq): Promise<RR.GetServerLogsRes> {
|
async getServerLogs (params: RR.GetServerLogsReq): Promise<RR.GetServerLogsRes> {
|
||||||
await pauseFor(2000)
|
await pauseFor(2000)
|
||||||
|
let logArr
|
||||||
if (Math.random() < .2) {
|
if (Math.random() < .2) {
|
||||||
console.log('last page')
|
console.log('last page')
|
||||||
return Mock.ServerLogs
|
logArr = Mock.ServerLogs
|
||||||
|
} else {
|
||||||
|
const arrLength = params.limit ? Math.ceil(params.limit / Mock.ServerLogs.length) : 10
|
||||||
|
logArr = new Array(arrLength).fill(Mock.ServerLogs).reduce((acc, val) => acc.concat(val), [])
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
logs: logArr,
|
||||||
|
startCursor: 'startCursor',
|
||||||
|
endCursor: 'endCursor',
|
||||||
}
|
}
|
||||||
const arrLength = params.limit ? Math.ceil(params.limit / Mock.ServerLogs.length) : 10
|
|
||||||
return new Array(arrLength).fill(Mock.ServerLogs).reduce((acc, val) => acc.concat(val), [])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getServerMetrics (params: RR.GetServerMetricsReq): Promise<RR.GetServerMetricsRes> {
|
async getServerMetrics (params: RR.GetServerMetricsReq): Promise<RR.GetServerMetricsRes> {
|
||||||
@@ -315,12 +322,19 @@ export class MockApiService extends ApiService {
|
|||||||
|
|
||||||
async getPackageLogs (params: RR.GetPackageLogsReq): Promise<RR.GetPackageLogsRes> {
|
async getPackageLogs (params: RR.GetPackageLogsReq): Promise<RR.GetPackageLogsRes> {
|
||||||
await pauseFor(2000)
|
await pauseFor(2000)
|
||||||
|
let logArr
|
||||||
if (Math.random() < .2) {
|
if (Math.random() < .2) {
|
||||||
console.log('last page')
|
console.log('last page')
|
||||||
return Mock.PackageLogs
|
logArr = Mock.PackageLogs
|
||||||
|
} else {
|
||||||
|
const arrLength = params.limit ? Math.ceil(params.limit / Mock.PackageLogs.length) : 10
|
||||||
|
logArr = new Array(arrLength).fill(Mock.PackageLogs).reduce((acc, val) => acc.concat(val), [])
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
logs: logArr,
|
||||||
|
startCursor: 'startCursor',
|
||||||
|
endCursor: 'endCursor',
|
||||||
}
|
}
|
||||||
const arrLength = params.limit ? Math.ceil(params.limit / Mock.PackageLogs.length) : 10
|
|
||||||
return new Array(arrLength).fill(Mock.PackageLogs).reduce((acc, val) => acc.concat(val), [])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async installPackageRaw (params: RR.InstallPackageReq): Promise<RR.InstallPackageRes> {
|
async installPackageRaw (params: RR.InstallPackageReq): Promise<RR.InstallPackageRes> {
|
||||||
|
|||||||
Reference in New Issue
Block a user