Feature/shared refactor (#1176)

* refactor: move most of the shared entities to @start8labs/shared library
This commit is contained in:
Alex Inkin
2022-02-15 18:13:05 +03:00
committed by GitHub
parent 1769f7e2e6
commit 7c26b18c73
164 changed files with 2908 additions and 2860 deletions

View File

@@ -3,7 +3,7 @@ import { CommonModule } from '@angular/common'
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
import { IonicModule } from '@ionic/angular'
import { AppConfigPage } from './app-config.page'
import { SharingModule } from 'src/app/modules/sharing.module'
import { TextSpinnerComponentModule } from '@start9labs/shared'
import { FormObjectComponentModule } from 'src/app/components/form-object/form-object.component.module'
@NgModule({
@@ -12,10 +12,10 @@ import { FormObjectComponentModule } from 'src/app/components/form-object/form-o
CommonModule,
FormsModule,
IonicModule,
SharingModule,
TextSpinnerComponentModule,
FormObjectComponentModule,
ReactiveFormsModule,
],
exports: [AppConfigPage],
})
export class AppConfigPageModule { }
export class AppConfigPageModule {}

View File

@@ -7,7 +7,7 @@ import {
IonicSafeString,
} from '@ionic/angular'
import { ApiService } from 'src/app/services/api/embassy-api.service'
import { DependentInfo, isEmptyObject, isObject } from 'src/app/util/misc.util'
import { DependentInfo, isEmptyObject, isObject } from '@start9labs/shared'
import { wizardModal } from 'src/app/components/install-wizard/install-wizard.component'
import { WizardBaker } from 'src/app/components/install-wizard/prebaked-wizards'
import { ConfigSpec } from 'src/app/pkg-config/config-types'

View File

@@ -1,9 +1,13 @@
import { Component, Input } from '@angular/core'
import { LoadingController, ModalController, IonicSafeString } from '@ionic/angular'
import {
LoadingController,
ModalController,
IonicSafeString,
} from '@ionic/angular'
import { BackupInfo, PackageBackupInfo } from 'src/app/services/api/api.types'
import { ApiService } from 'src/app/services/api/embassy-api.service'
import { ConfigService } from 'src/app/services/config.service'
import { Emver } from 'src/app/services/emver.service'
import { Emver } from '@start9labs/shared'
import { getErrorMessage } from 'src/app/services/error-toast.service'
import { PatchDbService } from 'src/app/services/patch-db/patch-db.service'
@@ -26,39 +30,43 @@ export class AppRecoverSelectPage {
hasSelection = false
error: string | IonicSafeString
constructor (
constructor(
private readonly modalCtrl: ModalController,
private readonly loadingCtrl: LoadingController,
private readonly embassyApi: ApiService,
private readonly config: ConfigService,
private readonly emver: Emver,
private readonly patch: PatchDbService,
) { }
) {}
ngOnInit () {
ngOnInit() {
this.options = Object.keys(this.backupInfo['package-backups']).map(id => {
return {
...this.backupInfo['package-backups'][id],
id,
checked: false,
installed: !!this.patch.getData()['package-data'][id],
'newer-eos': this.emver.compare(this.backupInfo['package-backups'][id]['os-version'], this.config.version) === 1,
'newer-eos':
this.emver.compare(
this.backupInfo['package-backups'][id]['os-version'],
this.config.version,
) === 1,
}
})
}
dismiss () {
dismiss() {
this.modalCtrl.dismiss()
}
handleChange () {
handleChange() {
this.hasSelection = this.options.some(o => o.checked)
}
async restore (): Promise<void> {
async restore(): Promise<void> {
const ids = this.options
.filter(option => !!option.checked)
.map(option => option.id)
.filter(option => !!option.checked)
.map(option => option.id)
const loader = await this.loadingCtrl.create({
spinner: 'lines',

View File

@@ -16,11 +16,9 @@ export class BackupReportPage {
color: 'dark' | 'danger' | 'success'
}
constructor (
private readonly modalCtrl: ModalController,
) { }
constructor(private readonly modalCtrl: ModalController) {}
ngOnInit () {
ngOnInit() {
if (!this.report.server.attempted) {
this.system = {
result: 'Not Attempted',
@@ -42,7 +40,7 @@ export class BackupReportPage {
}
}
async dismiss () {
async dismiss() {
return this.modalCtrl.dismiss(true)
}
}

View File

@@ -1,6 +1,6 @@
import { Component, Input } from '@angular/core'
import { ModalController } from '@ionic/angular'
import { ValueSpecListOf } from '../../pkg-config/config-types'
import { ValueSpecListOf } from 'src/app/pkg-config/config-types'
@Component({
selector: 'enum-list',
@@ -11,37 +11,37 @@ export class EnumListPage {
@Input() key: string
@Input() spec: ValueSpecListOf<'enum'>
@Input() current: string[]
options: { [option: string]: boolean } = { }
options: { [option: string]: boolean } = {}
selectAll = true
constructor (
private readonly modalCtrl: ModalController,
) { }
constructor(private readonly modalCtrl: ModalController) {}
ngOnInit () {
ngOnInit() {
for (let val of this.spec.spec.values) {
this.options[val] = this.current.includes(val)
}
}
dismiss () {
dismiss() {
this.modalCtrl.dismiss()
}
save () {
this.modalCtrl.dismiss(Object.keys(this.options).filter(key => this.options[key]))
save() {
this.modalCtrl.dismiss(
Object.keys(this.options).filter(key => this.options[key]),
)
}
toggleSelectAll () {
Object.keys(this.options).forEach(k => this.options[k] = this.selectAll)
toggleSelectAll() {
Object.keys(this.options).forEach(k => (this.options[k] = this.selectAll))
this.selectAll = !this.selectAll
}
toggleSelected (key: string) {
toggleSelected(key: string) {
this.options[key] = !this.options[key]
}
asIsOrder () {
asIsOrder() {
return 0
}
}

View File

@@ -1,7 +1,10 @@
import { Component, Input } from '@angular/core'
import { FormGroup } from '@angular/forms'
import { ModalController } from '@ionic/angular'
import { convertValuesRecursive, FormService } from 'src/app/services/form.service'
import {
convertValuesRecursive,
FormService,
} from 'src/app/services/form.service'
import { ConfigSpec } from 'src/app/pkg-config/config-types'
export interface ActionButton {
@@ -19,16 +22,16 @@ export class GenericFormPage {
@Input() title: string
@Input() spec: ConfigSpec
@Input() buttons: ActionButton[]
@Input() initialValue: object = { }
@Input() initialValue: object = {}
submitBtn: ActionButton
formGroup: FormGroup
constructor (
constructor(
private readonly modalCtrl: ModalController,
private readonly formService: FormService,
) { }
) {}
ngOnInit () {
ngOnInit() {
this.formGroup = this.formService.createForm(this.spec, this.initialValue)
this.submitBtn = this.buttons.find(btn => btn.isSubmit) || {
text: '',
@@ -36,16 +39,18 @@ export class GenericFormPage {
}
}
async dismiss (): Promise<void> {
async dismiss(): Promise<void> {
this.modalCtrl.dismiss()
}
async handleClick (handler: ActionButton['handler']): Promise<void> {
async handleClick(handler: ActionButton['handler']): Promise<void> {
convertValuesRecursive(this.spec, this.formGroup)
if (this.formGroup.invalid) {
this.formGroup.markAllAsTouched()
document.getElementsByClassName('validation-error')[0].parentElement.parentElement.scrollIntoView({ behavior: 'smooth' })
document
.getElementsByClassName('validation-error')[0]
.parentElement.parentElement.scrollIntoView({ behavior: 'smooth' })
return
}

View File

@@ -3,7 +3,7 @@ import { CommonModule } from '@angular/common'
import { GenericInputComponent } from './generic-input.component'
import { IonicModule } from '@ionic/angular'
import { RouterModule } from '@angular/router'
import { SharingModule } from 'src/app/modules/sharing.module'
import { SharedPipesModule } from '@start9labs/shared'
import { FormsModule } from '@angular/forms'
@NgModule({
@@ -13,8 +13,8 @@ import { FormsModule } from '@angular/forms'
IonicModule,
FormsModule,
RouterModule.forChild([]),
SharingModule,
SharedPipesModule,
],
exports: [GenericInputComponent],
})
export class GenericInputComponentModule { }
export class GenericInputComponentModule {}

View File

@@ -2,15 +2,19 @@ import { NgModule } from '@angular/core'
import { CommonModule } from '@angular/common'
import { IonicModule } from '@ionic/angular'
import { MarkdownPage } from './markdown.page'
import { SharingModule } from 'src/app/modules/sharing.module'
import {
MarkdownPipeModule,
TextSpinnerComponentModule,
} from '@start9labs/shared'
@NgModule({
declarations: [MarkdownPage],
imports: [
CommonModule,
IonicModule,
SharingModule,
MarkdownPipeModule,
TextSpinnerComponentModule,
],
exports: [MarkdownPage],
})
export class MarkdownPageModule { }
export class MarkdownPageModule {}

View File

@@ -2,17 +2,12 @@ import { NgModule } from '@angular/core'
import { CommonModule } from '@angular/common'
import { IonicModule } from '@ionic/angular'
import { OSWelcomePage } from './os-welcome.page'
import { SharingModule } from 'src/app/modules/sharing.module'
import { SharedPipesModule } from '@start9labs/shared'
import { FormsModule } from '@angular/forms'
@NgModule({
declarations: [OSWelcomePage],
imports: [
CommonModule,
IonicModule,
FormsModule,
SharingModule,
],
imports: [CommonModule, IonicModule, FormsModule, SharedPipesModule],
exports: [OSWelcomePage],
})
export class OSWelcomePageModule { }
export class OSWelcomePageModule {}