From 6417d713119fc0d392c1048f5187d7b43ff3a45f Mon Sep 17 00:00:00 2001 From: Aram Akhavan Date: Fri, 24 Nov 2023 19:17:06 -0800 Subject: [PATCH] Add a setting for repeating notifications or not --- .../scrutiny_repository_migrations.go | 20 +++++++++++++++++-- webapp/backend/pkg/models/settings.go | 7 ++++--- .../src/app/core/config/app.config.ts | 4 +++- .../dashboard-settings.component.html | 10 ++++++++++ .../dashboard-settings.component.ts | 5 ++++- 5 files changed, 39 insertions(+), 7 deletions(-) diff --git a/webapp/backend/pkg/database/scrutiny_repository_migrations.go b/webapp/backend/pkg/database/scrutiny_repository_migrations.go index 542677f..e1b948b 100644 --- a/webapp/backend/pkg/database/scrutiny_repository_migrations.go +++ b/webapp/backend/pkg/database/scrutiny_repository_migrations.go @@ -4,6 +4,9 @@ import ( "context" "errors" "fmt" + "strconv" + "time" + "github.com/analogj/scrutiny/webapp/backend/pkg" "github.com/analogj/scrutiny/webapp/backend/pkg/database/migrations/m20201107210306" "github.com/analogj/scrutiny/webapp/backend/pkg/database/migrations/m20220503120000" @@ -17,8 +20,6 @@ import ( "github.com/influxdata/influxdb-client-go/v2/api/http" log "github.com/sirupsen/logrus" "gorm.io/gorm" - "strconv" - "time" ) //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -369,6 +370,21 @@ func (sr *scrutinyRepository) Migrate(ctx context.Context) error { return tx.Create(&defaultSettings).Error }, }, + { + ID: "m20231123123300", // add repeat_notifications setting. + Migrate: func(tx *gorm.DB) error { + //add repeat_notifications setting default. + var defaultSettings = []m20220716214900.Setting{ + { + SettingKeyName: "metrics.repeat_notifications", + SettingKeyDescription: "Whether to repeat all notifications or just when values change (true | false)", + SettingDataType: "bool", + SettingValueBool: true, + }, + } + return tx.Create(&defaultSettings).Error + }, + }, }) if err := m.Migrate(); err != nil { diff --git a/webapp/backend/pkg/models/settings.go b/webapp/backend/pkg/models/settings.go index f5564ef..e564301 100644 --- a/webapp/backend/pkg/models/settings.go +++ b/webapp/backend/pkg/models/settings.go @@ -17,8 +17,9 @@ type Settings struct { LineStroke string `json:"line_stroke" mapstructure:"line_stroke"` Metrics struct { - NotifyLevel int `json:"notify_level" mapstructure:"notify_level"` - StatusFilterAttributes int `json:"status_filter_attributes" mapstructure:"status_filter_attributes"` - StatusThreshold int `json:"status_threshold" mapstructure:"status_threshold"` + NotifyLevel int `json:"notify_level" mapstructure:"notify_level"` + StatusFilterAttributes int `json:"status_filter_attributes" mapstructure:"status_filter_attributes"` + StatusThreshold int `json:"status_threshold" mapstructure:"status_threshold"` + RepeatNotifications bool `json:"repeat_notifications" mapstructure:"repeat_notifications"` } `json:"metrics" mapstructure:"metrics"` } diff --git a/webapp/frontend/src/app/core/config/app.config.ts b/webapp/frontend/src/app/core/config/app.config.ts index c48d25a..1b6dfe3 100644 --- a/webapp/frontend/src/app/core/config/app.config.ts +++ b/webapp/frontend/src/app/core/config/app.config.ts @@ -55,6 +55,7 @@ export interface AppConfig { notify_level?: MetricsNotifyLevel status_filter_attributes?: MetricsStatusFilterAttributes status_threshold?: MetricsStatusThreshold + repeat_notifications?: boolean } } @@ -82,7 +83,8 @@ export const appConfig: AppConfig = { metrics: { notify_level: MetricsNotifyLevel.Fail, status_filter_attributes: MetricsStatusFilterAttributes.All, - status_threshold: MetricsStatusThreshold.Both + status_threshold: MetricsStatusThreshold.Both, + repeat_notifications: true } }; diff --git a/webapp/frontend/src/app/layout/common/dashboard-settings/dashboard-settings.component.html b/webapp/frontend/src/app/layout/common/dashboard-settings/dashboard-settings.component.html index 69ebd76..0eb9a03 100644 --- a/webapp/frontend/src/app/layout/common/dashboard-settings/dashboard-settings.component.html +++ b/webapp/frontend/src/app/layout/common/dashboard-settings/dashboard-settings.component.html @@ -84,6 +84,16 @@ + +
+ + Repeat Notifications + + Always + Only when the value has changed + + +
diff --git a/webapp/frontend/src/app/layout/common/dashboard-settings/dashboard-settings.component.ts b/webapp/frontend/src/app/layout/common/dashboard-settings/dashboard-settings.component.ts index ea2acce..94f262f 100644 --- a/webapp/frontend/src/app/layout/common/dashboard-settings/dashboard-settings.component.ts +++ b/webapp/frontend/src/app/layout/common/dashboard-settings/dashboard-settings.component.ts @@ -28,6 +28,7 @@ export class DashboardSettingsComponent implements OnInit { theme: string; statusThreshold: number; statusFilterAttributes: number; + repeatNotifications: boolean; // Private private _unsubscribeAll: Subject; @@ -55,6 +56,7 @@ export class DashboardSettingsComponent implements OnInit { this.statusFilterAttributes = config.metrics.status_filter_attributes; this.statusThreshold = config.metrics.status_threshold; + this.repeatNotifications = config.metrics.repeat_notifications; }); @@ -70,7 +72,8 @@ export class DashboardSettingsComponent implements OnInit { theme: this.theme as Theme, metrics: { status_filter_attributes: this.statusFilterAttributes as MetricsStatusFilterAttributes, - status_threshold: this.statusThreshold as MetricsStatusThreshold + status_threshold: this.statusThreshold as MetricsStatusThreshold, + repeat_notifications: this.repeatNotifications } } this._configService.config = newSettings