Add a setting for repeating notifications or not

pull/547/head
Aram Akhavan 1 year ago
parent 3285eb659f
commit 6417d71311

@ -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 {

@ -20,5 +20,6 @@ type Settings 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"`
RepeatNotifications bool `json:"repeat_notifications" mapstructure:"repeat_notifications"`
} `json:"metrics" mapstructure:"metrics"`
}

@ -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
}
};

@ -84,6 +84,16 @@
</mat-select>
</mat-form-field>
</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>Repeat Notifications</mat-label>
<mat-select [(ngModel)]=repeatNotifications>
<mat-option [value]=true>Always</mat-option>
<mat-option [value]=false>Only when the value has changed</mat-option>
</mat-select>
</mat-form-field>
</div>
</div>
</mat-dialog-content>

@ -28,6 +28,7 @@ export class DashboardSettingsComponent implements OnInit {
theme: string;
statusThreshold: number;
statusFilterAttributes: number;
repeatNotifications: boolean;
// Private
private _unsubscribeAll: Subject<void>;
@ -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

Loading…
Cancel
Save