Ver código fonte

Alarm configuration and display of alarm groups

Lukas Angerer 5 anos atrás
pai
commit
34fd625b5f

+ 15 - 0
CronAlarm/Config/AlertConfig.cs

@@ -0,0 +1,15 @@
+using Microsoft.Extensions.Configuration;
+
+namespace CronAlarm.Config
+{
+    public class AlertConfig
+    {
+        public Alerts Alerts { get; }
+
+        public AlertConfig(IConfiguration config)
+        {
+            Alerts = new Alerts();
+            config.GetSection("Alerts").Bind(Alerts);
+        }
+    }
+}

+ 10 - 0
CronAlarm/Config/AlertGroup.cs

@@ -0,0 +1,10 @@
+using System.Collections.Generic;
+
+namespace CronAlarm.Config
+{
+    public class AlertGroup
+    {
+        public string Name { get; set; }
+        public IList<AlertOption> Options { get; set; } = new List<AlertOption>();
+    }
+}

+ 16 - 0
CronAlarm/Config/AlertOption.cs

@@ -0,0 +1,16 @@
+namespace CronAlarm.Config
+{
+    public class AlertOption
+    {
+        private static int Index = 0;
+
+        public AlertOption()
+        {
+            Id = ++Index;
+        }
+
+        public int Id { get; }
+        public string Label { get; set; }
+        public string Pattern { get; set; }
+    }
+}

+ 10 - 0
CronAlarm/Config/Alerts.cs

@@ -0,0 +1,10 @@
+using System.Collections.Generic;
+
+namespace CronAlarm.Config
+{
+    public class Alerts
+    {
+        public string Command { get; set; }
+        public IList<AlertGroup> Groups { get; set; } = new List<AlertGroup>();
+    }
+}

+ 22 - 2
CronAlarm/Pages/Index.razor

@@ -1,5 +1,25 @@
 @page "/"
 
-<h1>Hello, world!</h1>
+<h1>Alerts</h1>
 
-Welcome to your new app.
+<div class="container">
+    @foreach (var group in Config.Alerts.Groups)
+    {
+        <div class="row">
+            <div class="col-12">
+                @group.Name
+                <div class="list-group">
+                    @foreach (var option in group.Options)
+                    {
+                        <button type="button" class="list-group-item list-group-item-action" @onclick="SelectOption">
+                            @option.Label
+                        </button>
+                    }
+                </div>
+            </div>
+        </div>
+    }
+    <div>
+        <button class="btn btn-primary" @onclick="Save">Save</button> <button class="btn btn-secondary" @onclick="Reset">Reset</button>
+    </div>
+</div>

+ 30 - 0
CronAlarm/Pages/Index.razor.cs

@@ -0,0 +1,30 @@
+using CronAlarm.Config;
+using Microsoft.AspNetCore.Components;
+using Microsoft.Extensions.Configuration;
+
+namespace CronAlarm.Pages
+{
+    public partial class Index : IComponent
+    {
+        [Inject]
+        private AlertConfig Config { get; set; }
+
+        public Index()
+        {
+            var foo = 42;
+        }
+
+        private void SelectOption()
+        { }
+
+        private void Save()
+        {
+
+        }
+
+        private void Reset()
+        {
+
+        }
+    }
+}

+ 49 - 1
CronAlarm/appsettings.json

@@ -6,5 +6,53 @@
       "Microsoft.Hosting.Lifetime": "Information"
     }
   },
-  "AllowedHosts": "*"
+  "AllowedHosts": "*",
+  "Alerts": {
+    "Command": "/home/pi/mpc-alarm-cron.sh",
+    "Groups": [
+      {
+        "Name": "Weekdays",
+        "Options": [
+          {
+            "Label": "06:20 - Work",
+            "Pattern": "20 06 * * MON-FRI"
+          },
+          {
+            "Label": "08:30 - Holidays",
+            "Pattern": "30 08 * * MON-FRI"
+          },
+          {
+            "Label": "09:00 - Sleeping In",
+            "Pattern": "00 09 * * MON-FRI"
+          }
+        ]
+      },
+      {
+        "Name": "Saturday",
+        "Options": [
+          {
+            "Label": "08:20 - Long-Jog",
+            "Pattern": "20 08 * * SAT"
+          },
+          {
+            "Label": "08:00 - Long-Jog (early)",
+            "Pattern": "00 08 * * SAT"
+          },
+          {
+            "Label": "07:40 - Long-Jog (very early)",
+            "Pattern": "40 07 * * SAT"
+          }
+        ]
+      },
+      {
+        "Name": "Sunday",
+        "Options": [
+          {
+            "Label": "09:00 - Lazy",
+            "Pattern": "00 09 * * SUN"
+          }
+        ]
+      }
+    ]
+  }
 }