Skip to content

Commit

Permalink
[desktop]: Improve DropdownOptions pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagohm committed Jun 13, 2024
1 parent 14e0d9f commit 142bcad
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 37 deletions.
38 changes: 20 additions & 18 deletions desktop/src/app/settings/settings.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AfterViewInit, Component, HostListener, OnDestroy } from '@angular/core'
import { LocationDialog } from '../../shared/dialogs/location/location.dialog'
import { DropdownOptionsPipe } from '../../shared/pipes/dropdown-options'
import { ElectronService } from '../../shared/services/electron.service'
import { PreferenceService } from '../../shared/services/preference.service'
import { PrimeService } from '../../shared/services/prime.service'
Expand Down Expand Up @@ -52,21 +53,22 @@ export class SettingsComponent implements AfterViewInit, OnDestroy {
private preference: PreferenceService,
private electron: ElectronService,
private prime: PrimeService,
private dropdownOptions: DropdownOptionsPipe,
) {
app.title = 'Settings'

this.locations = preference.locations.get()
this.location = preference.selectedLocation.get(this.locations[0])

this.plateSolvers.set('ASTAP', preference.plateSolverRequest('ASTAP').get())
this.plateSolvers.set('ASTROMETRY_NET_ONLINE', preference.plateSolverRequest('ASTROMETRY_NET_ONLINE').get())
this.plateSolvers.set('SIRIL', preference.plateSolverRequest('SIRIL').get())

this.starDetectors.set('ASTAP', preference.starDetectionRequest('ASTAP').get())
this.starDetectors.set('PIXINSIGHT', preference.starDetectionRequest('PIXINSIGHT').get())

this.liveStackers.set('SIRIL', preference.liveStackingRequest('SIRIL').get())
this.liveStackers.set('PIXINSIGHT', preference.liveStackingRequest('PIXINSIGHT').get())
for (const type of dropdownOptions.transform('PLATE_SOLVER')) {
this.plateSolvers.set(type, preference.plateSolverRequest(type).get())
}
for (const type of dropdownOptions.transform('STAR_DETECTOR')) {
this.starDetectors.set(type, preference.starDetectionRequest(type).get())
}
for (const type of dropdownOptions.transform('LIVE_STACKER')) {
this.liveStackers.set(type, preference.liveStackingRequest(type).get())
}
}

async ngAfterViewInit() { }
Expand Down Expand Up @@ -129,14 +131,14 @@ export class SettingsComponent implements AfterViewInit, OnDestroy {
}

save() {
this.preference.plateSolverRequest('ASTAP').set(this.plateSolvers.get('ASTAP'))
this.preference.plateSolverRequest('ASTROMETRY_NET_ONLINE').set(this.plateSolvers.get('ASTROMETRY_NET_ONLINE'))
this.preference.plateSolverRequest('SIRIL').set(this.plateSolvers.get('SIRIL'))

this.preference.starDetectionRequest('ASTAP').set(this.starDetectors.get('ASTAP'))
this.preference.starDetectionRequest('PIXINSIGHT').set(this.starDetectors.get('PIXINSIGHT'))

this.preference.liveStackingRequest('SIRIL').set(this.liveStackers.get('SIRIL'))
this.preference.liveStackingRequest('PIXINSIGHT').set(this.liveStackers.get('PIXINSIGHT'))
for (const type of this.dropdownOptions.transform('PLATE_SOLVER')) {
this.preference.plateSolverRequest(type).set(this.plateSolvers.get(type))
}
for (const type of this.dropdownOptions.transform('STAR_DETECTOR')) {
this.preference.starDetectionRequest(type).set(this.starDetectors.get(type))
}
for (const type of this.dropdownOptions.transform('LIVE_STACKER')) {
this.preference.liveStackingRequest(type).set(this.liveStackers.get(type))
}
}
}
45 changes: 26 additions & 19 deletions desktop/src/shared/pipes/dropdown-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,39 @@ import { Pipe, PipeTransform } from '@angular/core'
import { AutoFocusFittingMode, BacklashCompensationMode } from '../types/autofocus.type'
import { LiveStackerType } from '../types/camera.types'
import { Bitpix, ImageChannel, ImageFormat, SCNRProtectionMethod } from '../types/image.types'
import { PlateSolverType, StarDetectorType } from '../types/settings.types'
import { MountRemoteControlType } from '../types/mount.types'
import { PlateSolverType, StarDetectorType } from '../types/settings.types'

export type DropdownOptionType = 'STAR_DETECTOR' | 'PLATE_SOLVER' | 'LIVE_STACKER'
| 'AUTO_FOCUS_FITTING_MODE' | 'AUTO_FOCUS_BACKLASH_COMPENSATION_MODE' | 'SCNR_PROTECTION_METHOD'
| 'IMAGE_FORMAT' | 'IMAGE_BITPIX' | 'IMAGE_CHANNEL' | 'MOUNT_REMOTE_CONTROL_TYPE'

export type DropdownOptionReturnType = StarDetectorType[] | PlateSolverType[] | LiveStackerType[]
| AutoFocusFittingMode[] | BacklashCompensationMode[] | SCNRProtectionMethod[]
| ImageFormat[] | Bitpix[] | ImageChannel[] | MountRemoteControlType[]
export type DropdownOptions = {
'STAR_DETECTOR': StarDetectorType[]
'PLATE_SOLVER': PlateSolverType[]
'LIVE_STACKER': LiveStackerType[]
'AUTO_FOCUS_FITTING_MODE': AutoFocusFittingMode[]
'AUTO_FOCUS_BACKLASH_COMPENSATION_MODE': BacklashCompensationMode[]
'SCNR_PROTECTION_METHOD': SCNRProtectionMethod[]
'IMAGE_FORMAT': ImageFormat[]
'IMAGE_BITPIX': Bitpix[]
'IMAGE_CHANNEL': ImageChannel[]
'MOUNT_REMOTE_CONTROL_TYPE': MountRemoteControlType[]
}

@Pipe({ name: 'dropdownOptions' })
export class DropdownOptionsPipe implements PipeTransform {

transform(type: DropdownOptionType): DropdownOptionReturnType | undefined {
transform<K extends keyof DropdownOptions>(type: K): DropdownOptions[K] {
switch (type) {
case 'STAR_DETECTOR': return ['ASTAP', 'PIXINSIGHT']
case 'PLATE_SOLVER': return ['ASTAP', 'ASTROMETRY_NET_ONLINE', 'SIRIL']
case 'AUTO_FOCUS_FITTING_MODE': return ['TRENDLINES', 'PARABOLIC', 'TREND_PARABOLIC', 'HYPERBOLIC', 'TREND_HYPERBOLIC']
case 'AUTO_FOCUS_BACKLASH_COMPENSATION_MODE': return ['NONE', 'ABSOLUTE', 'OVERSHOOT']
case 'LIVE_STACKER': return ['SIRIL', 'PIXINSIGHT']
case 'SCNR_PROTECTION_METHOD': return ['MAXIMUM_MASK', 'ADDITIVE_MASK', 'AVERAGE_NEUTRAL', 'MAXIMUM_NEUTRAL', 'MINIMUM_NEUTRAL']
case 'IMAGE_FORMAT': return ['FITS', 'XISF', 'PNG', 'JPG']
case 'IMAGE_BITPIX': return ['BYTE', 'SHORT', 'INTEGER', 'FLOAT', 'DOUBLE']
case 'IMAGE_CHANNEL': return ['RED', 'GREEN', 'BLUE', 'GRAY']
case 'MOUNT_REMOTE_CONTROL_TYPE': return ['LX200', 'STELLARIUM']
case 'STAR_DETECTOR': return ['ASTAP', 'PIXINSIGHT'] as DropdownOptions[K]
case 'PLATE_SOLVER': return ['ASTAP', 'ASTROMETRY_NET_ONLINE', 'SIRIL'] as DropdownOptions[K]
case 'AUTO_FOCUS_FITTING_MODE': return ['TRENDLINES', 'PARABOLIC', 'TREND_PARABOLIC', 'HYPERBOLIC', 'TREND_HYPERBOLIC'] as DropdownOptions[K]
case 'AUTO_FOCUS_BACKLASH_COMPENSATION_MODE': return ['NONE', 'ABSOLUTE', 'OVERSHOOT'] as DropdownOptions[K]
case 'LIVE_STACKER': return ['SIRIL', 'PIXINSIGHT'] as DropdownOptions[K]
case 'SCNR_PROTECTION_METHOD': return ['MAXIMUM_MASK', 'ADDITIVE_MASK', 'AVERAGE_NEUTRAL', 'MAXIMUM_NEUTRAL', 'MINIMUM_NEUTRAL'] as DropdownOptions[K]
case 'IMAGE_FORMAT': return ['FITS', 'XISF', 'PNG', 'JPG'] as DropdownOptions[K]
case 'IMAGE_BITPIX': return ['BYTE', 'SHORT', 'INTEGER', 'FLOAT', 'DOUBLE'] as DropdownOptions[K]
case 'IMAGE_CHANNEL': return ['RED', 'GREEN', 'BLUE', 'GRAY'] as DropdownOptions[K]
case 'MOUNT_REMOTE_CONTROL_TYPE': return ['LX200', 'STELLARIUM'] as DropdownOptions[K]
}

return []
}
}

0 comments on commit 142bcad

Please sign in to comment.