mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
* remove product key flow from setup * feat: backend turned off encryption + new Id + no package id * implement new encryption scheme in FE * decode response string * crypto not working * update setup wizard closes #1762 * feat: Get the encryption key * fix: Get to recovery * remove old code * fix build * fix: Install works for now * fix bug in config for adding new list items * dismiss action modal on success * clear button in config * wip: Currently broken in avahi mdns * include headers with req/res and refactor patchDB init and usage * fix: Can now run in the main * flatline on failed init * update patch DB * add last-wifi-region to data model even though not used by FE * chore: Fix the start. * wip: Fix wrong order for getting hostname before sql has been created * fix edge case where union keys displayed as new when not new * fix: Can start * last backup color, markdown links always new tab, fix bug with login * refactor to remove WithRevision * resolve circular dep issue * update submodule * fix patch-db * update patchDB * update patch again * escape error * decodeuricomponent * increase proxy buffer size * increase proxy buffer size * fix nginx Co-authored-by: BluJ <mogulslayer@gmail.com> Co-authored-by: BluJ <dragondef@gmail.com> Co-authored-by: Aiden McClelland <me@drbonez.dev>
181 lines
4.7 KiB
TypeScript
181 lines
4.7 KiB
TypeScript
import { Component } from '@angular/core'
|
|
import { ApiService } from 'src/app/services/api/embassy-api.service'
|
|
import {
|
|
ServerNotifications,
|
|
NotificationLevel,
|
|
ServerNotification,
|
|
} from 'src/app/services/api/api.types'
|
|
import {
|
|
AlertController,
|
|
LoadingController,
|
|
ModalController,
|
|
} from '@ionic/angular'
|
|
import { ActivatedRoute } from '@angular/router'
|
|
import { ErrorToastService } from '@start9labs/shared'
|
|
import { BackupReportPage } from 'src/app/modals/backup-report/backup-report.page'
|
|
import { PatchDB } from 'patch-db-client'
|
|
import { DataModel } from 'src/app/services/patch-db/data-model'
|
|
|
|
@Component({
|
|
selector: 'notifications',
|
|
templateUrl: 'notifications.page.html',
|
|
styleUrls: ['notifications.page.scss'],
|
|
})
|
|
export class NotificationsPage {
|
|
loading = true
|
|
notifications: ServerNotifications = []
|
|
beforeCursor?: number
|
|
needInfinite = false
|
|
fromToast = false
|
|
readonly perPage = 40
|
|
readonly packageData$ = this.patch.watch$('package-data')
|
|
|
|
constructor(
|
|
private readonly embassyApi: ApiService,
|
|
private readonly alertCtrl: AlertController,
|
|
private readonly loadingCtrl: LoadingController,
|
|
private readonly modalCtrl: ModalController,
|
|
private readonly errToast: ErrorToastService,
|
|
private readonly route: ActivatedRoute,
|
|
private readonly patch: PatchDB<DataModel>,
|
|
) {}
|
|
|
|
async ngOnInit() {
|
|
this.fromToast = !!this.route.snapshot.queryParamMap.get('toast')
|
|
this.notifications = await this.getNotifications()
|
|
this.loading = false
|
|
}
|
|
|
|
async doInfinite(e: any) {
|
|
const notifications = await this.getNotifications()
|
|
this.notifications = this.notifications.concat(notifications)
|
|
e.target.complete()
|
|
}
|
|
|
|
async getNotifications(): Promise<ServerNotifications> {
|
|
try {
|
|
const notifications = await this.embassyApi.getNotifications({
|
|
before: this.beforeCursor,
|
|
limit: this.perPage,
|
|
})
|
|
|
|
if (!notifications) return []
|
|
|
|
this.beforeCursor = notifications[notifications.length - 1]?.id
|
|
this.needInfinite = notifications.length >= this.perPage
|
|
|
|
return notifications
|
|
} catch (e: any) {
|
|
this.errToast.present(e)
|
|
}
|
|
|
|
return []
|
|
}
|
|
|
|
async delete(id: number, index: number): Promise<void> {
|
|
const loader = await this.loadingCtrl.create({
|
|
message: 'Deleting...',
|
|
})
|
|
await loader.present()
|
|
|
|
try {
|
|
await this.embassyApi.deleteNotification({ id })
|
|
this.notifications.splice(index, 1)
|
|
this.beforeCursor = this.notifications[this.notifications.length - 1]?.id
|
|
} catch (e: any) {
|
|
this.errToast.present(e)
|
|
} finally {
|
|
loader.dismiss()
|
|
}
|
|
}
|
|
|
|
async presentAlertDeleteAll() {
|
|
const alert = await this.alertCtrl.create({
|
|
backdropDismiss: false,
|
|
header: 'Delete All?',
|
|
message: 'Are you sure you want to delete all notifications?',
|
|
buttons: [
|
|
{
|
|
text: 'Cancel',
|
|
role: 'cancel',
|
|
},
|
|
{
|
|
text: 'Delete',
|
|
handler: () => {
|
|
this.deleteAll()
|
|
},
|
|
cssClass: 'enter-click',
|
|
},
|
|
],
|
|
})
|
|
await alert.present()
|
|
}
|
|
|
|
async viewBackupReport(notification: ServerNotification<1>) {
|
|
const modal = await this.modalCtrl.create({
|
|
component: BackupReportPage,
|
|
componentProps: {
|
|
report: notification.data,
|
|
timestamp: notification['created-at'],
|
|
},
|
|
})
|
|
await modal.present()
|
|
}
|
|
|
|
async viewFullMessage(header: string, message: string) {
|
|
const alert = await this.alertCtrl.create({
|
|
header,
|
|
message,
|
|
cssClass: 'notification-detail-alert',
|
|
buttons: [
|
|
{
|
|
text: `OK`,
|
|
handler: () => {
|
|
alert.dismiss()
|
|
},
|
|
cssClass: 'enter-click',
|
|
},
|
|
],
|
|
})
|
|
await alert.present()
|
|
}
|
|
|
|
truncate(message: string): string {
|
|
return message.length <= 240 ? message : '...' + message.substr(-240)
|
|
}
|
|
|
|
getColor({ level }: ServerNotification<number>): string {
|
|
switch (level) {
|
|
case NotificationLevel.Info:
|
|
return 'primary'
|
|
case NotificationLevel.Success:
|
|
return 'success'
|
|
case NotificationLevel.Warning:
|
|
return 'warning'
|
|
case NotificationLevel.Error:
|
|
return 'danger'
|
|
default:
|
|
return ''
|
|
}
|
|
}
|
|
|
|
private async deleteAll(): Promise<void> {
|
|
const loader = await this.loadingCtrl.create({
|
|
message: 'Deleting...',
|
|
})
|
|
await loader.present()
|
|
|
|
try {
|
|
await this.embassyApi.deleteAllNotifications({
|
|
before: this.notifications[0].id + 1,
|
|
})
|
|
this.notifications = []
|
|
this.beforeCursor = undefined
|
|
} catch (e: any) {
|
|
this.errToast.present(e)
|
|
} finally {
|
|
loader.dismiss()
|
|
}
|
|
}
|
|
}
|