Add DB Migration and config/settings

pull/634/head
Brice Bauer 8 months ago
parent 5e6ab2290b
commit 8fa32c6dd7

@ -332,6 +332,12 @@ func (sr *scrutinyRepository) Migrate(ctx context.Context) error {
SettingDataType: "string",
SettingValueString: "smooth",
},
{
SettingKeyName: "powered_on_hours_unit",
SettingKeyDescription: "Presentation format for device powered on time ('humanize' | 'device-hours')",
SettingDataType: "string",
SettingValueString: "humanize",
},
{
SettingKeyName: "metrics.notify_level",

@ -8,13 +8,14 @@ package models
//}
type Settings struct {
Theme string `json:"theme" mapstructure:"theme"`
Layout string `json:"layout" mapstructure:"layout"`
DashboardDisplay string `json:"dashboard_display" mapstructure:"dashboard_display"`
DashboardSort string `json:"dashboard_sort" mapstructure:"dashboard_sort"`
TemperatureUnit string `json:"temperature_unit" mapstructure:"temperature_unit"`
FileSizeSIUnits bool `json:"file_size_si_units" mapstructure:"file_size_si_units"`
LineStroke string `json:"line_stroke" mapstructure:"line_stroke"`
Theme string `json:"theme" mapstructure:"theme"`
Layout string `json:"layout" mapstructure:"layout"`
DashboardDisplay string `json:"dashboard_display" mapstructure:"dashboard_display"`
DashboardSort string `json:"dashboard_sort" mapstructure:"dashboard_sort"`
TemperatureUnit string `json:"temperature_unit" mapstructure:"temperature_unit"`
FileSizeSIUnits bool `json:"file_size_si_units" mapstructure:"file_size_si_units"`
LineStroke string `json:"line_stroke" mapstructure:"line_stroke"`
PoweredOnHoursUnit string `json:"powered_on_hours_unit" mapstructure:"powered_on_hours_unit"`
Metrics struct {
NotifyLevel int `json:"notify_level" mapstructure:"notify_level"`

@ -12,6 +12,8 @@ export type TemperatureUnit = 'celsius' | 'fahrenheit'
export type LineStroke = 'smooth' | 'straight' | 'stepline'
export type DevicePoweredOnUnit = 'humanize' | 'device_hours'
export enum MetricsNotifyLevel {
Warn = 1,
@ -47,6 +49,8 @@ export interface AppConfig {
file_size_si_units?: boolean;
powered_on_hours_unit?: DevicePoweredOnUnit;
line_stroke?: LineStroke;
// Settings from Scrutiny API
@ -77,6 +81,7 @@ export const appConfig: AppConfig = {
temperature_unit: 'celsius',
file_size_si_units: false,
powered_on_hours_unit: 'humanize',
line_stroke: 'smooth',

@ -54,6 +54,14 @@
</div>
<div class="flex flex-col mt-5 gt-md:flex-row">
<mat-form-field class="flex-auto gt-xs:pr-3 gt-md:pr-3">
<mat-label>Powered On Format</mat-label>
<mat-select [(ngModel)]="poweredOnHoursUnit">
<mat-option value="humanize">Humanize</mat-option>
<mat-option value="device_hours">Device Hours</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field class="flex-auto gt-xs:pr-3 gt-md:pr-3">
<mat-label>Line stroke</mat-label>
<mat-select [(ngModel)]="lineStroke">

@ -7,7 +7,8 @@ import {
MetricsStatusThreshold,
TemperatureUnit,
LineStroke,
Theme
Theme,
DevicePoweredOnUnit
} from 'app/core/config/app.config';
import {ScrutinyConfigService} from 'app/core/config/scrutiny-config.service';
import {Subject} from 'rxjs';
@ -24,6 +25,7 @@ export class DashboardSettingsComponent implements OnInit {
dashboardSort: string;
temperatureUnit: string;
fileSizeSIUnits: boolean;
poweredOnHoursUnit: string;
lineStroke: string;
theme: string;
statusThreshold: number;
@ -51,6 +53,7 @@ export class DashboardSettingsComponent implements OnInit {
this.dashboardSort = config.dashboard_sort;
this.temperatureUnit = config.temperature_unit;
this.fileSizeSIUnits = config.file_size_si_units;
this.poweredOnHoursUnit = config.powered_on_hours_unit;
this.lineStroke = config.line_stroke;
this.theme = config.theme;
@ -68,6 +71,7 @@ export class DashboardSettingsComponent implements OnInit {
dashboard_sort: this.dashboardSort as DashboardSort,
temperature_unit: this.temperatureUnit as TemperatureUnit,
file_size_si_units: this.fileSizeSIUnits,
powered_on_hours_unit: this.poweredOnHoursUnit as DevicePoweredOnUnit,
line_stroke: this.lineStroke as LineStroke,
theme: this.theme as Theme,
metrics: {

Loading…
Cancel
Save