Beispiel #1
0
        private MultiInputGroup CreateSingleBackendCollum(string name, BackendProperty backendProperty)
        {
            MultiInputGroup backendMultiInputGroup = new MultiInputGroup();

            backendMultiInputGroup.AppendLabel(name, 115 + 80);
            TwoStateButtonGroup backendEnabled = backendMultiInputGroup.AppendCustomElement(new TwoStateButtonGroup("Vom Server", "Als Debug", backendProperty.RequestDataFromBackend, !backendProperty.RequestDataFromBackend), false);
            StylableTextInput   backendPath    = backendMultiInputGroup.AppendTextInput("Pfad zur WebAPI", startText: backendProperty.DataSourcePath);

            _backendPathTextInputDictionary.Add(name, backendPath);
            backendMultiInputGroup.AppendValidation("Einstellungen OK", "Einstellungen sind nicht OK", false);
            Button backendSaveSettings = backendMultiInputGroup.AppendCustomElement(new Button(StylingColor.Success, true, text: "Speichern", fontAwesomeIcon: "save"), false);

            backendSaveSettings.Click += (sender, args) =>
            {
                backendPath.SetValidation(false, false);
                if (backendEnabled.FirstButtonActive && Uri.IsWellFormedUriString(backendPath.Value, UriKind.Absolute))
                {
                    try
                    {
                        if (JsonConvert.DeserializeObject <bool>(new HttpClient().GetAsync(backendPath.Value + "/enabled").EnsureResultSuccessStatusCode().Result.Content.ReadAsStringAsync().Result) == false)
                        {
                            //TODO: ich brauche eine Messagebox
                            backendPath.Value = "Der Server hat diese API verweigert! Pfad:" + backendPath.Value;
                            throw new Exception(backendPath.Value);
                        }
                        backendPath.SetValidation(true, false);
                        backendProperty.RequestDataFromBackend = backendEnabled.FirstButtonActive;
                        backendProperty.DataSourcePath         = backendPath.Value;
                    }
                    catch (Exception e)
                    {
                        backendPath.Value       = "Der Verbindungsversuch ist fehlgeschlagen! Pfad:" + backendPath.Value;
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine("Beim Versuch die neuen BackendEinstellungen zu Testen ist ein Fehler aufgetreten.");
                        Console.ResetColor();

                        Logging.WriteLog("System", "Warn", $"Beim Versuch die Backendeinstellungen für {name} des Servers zu validieren ist es zu folgendem Fehler gekommen:\r\n{e.Message}");

                        backendPath.SetValidation(false, true);
                        //TODO: ich brauche eine Messagebox
                    }
                }
                else if (backendEnabled.SecondButtonActive)
                {
                    backendPath.SetValidation(true, false);
                    backendProperty.RequestDataFromBackend = backendEnabled.FirstButtonActive;
                }
                else
                {
                    backendPath.SetValidation(false, true);
                }
            };
            backendMultiInputGroup.AddStyling(StylingOption.MarginBottom, 2);
            return(backendMultiInputGroup);
        }
Beispiel #2
0
        public OverrideInputGroup(int startValue, string labelText = "Dauer Relativ", int labelSizeInPx = -1, int increment = 5) : base("div")
        {
            MultiInputGroup multiInputGroup = new MultiInputGroup();

            multiInputGroup.AppendLabel(labelText, labelSizeInPx);
            OverrideTextInput             = multiInputGroup.AppendTextInput("100%", startText: startValue + "%");
            OverrideTextInput.Style.Width = 110;
            multiInputGroup.AppendValidation("", "Bitte nur ganze zahlen mit optionalem % Zeichen angeben!", false);
            Button incrementOverrideButton = new Button(StylingColor.Secondary, true, text: "+", widthInPx: 35);

            incrementOverrideButton.Click += (sender, args) =>
            {
                if (int.TryParse(OverrideTextInput.Value.Replace("%", ""), out int number))
                {
                    OverrideTextInput.Value = number + increment + "%";
                    OverrideTextInput.SetValidation(false, false);
                }
                else
                {
                    OverrideTextInput.SetValidation(false, true);
                }
            };
            multiInputGroup.AppendCustomElement(incrementOverrideButton, false);

            Button decrementOverrideButton = new Button(StylingColor.Secondary, true, text: "-", widthInPx: 35);

            decrementOverrideButton.Click += (sender, args) =>
            {
                if (int.TryParse(OverrideTextInput.Value.Replace("%", ""), out int number))
                {
                    OverrideTextInput.Value = number - increment + "%";
                    OverrideTextInput.SetValidation(false, false);
                }
                else
                {
                    OverrideTextInput.SetValidation(false, true);
                }
            };
            multiInputGroup.AppendCustomElement(decrementOverrideButton, false);

            multiInputGroup.AddStyling(StylingOption.MarginBottom, 2);
            multiInputGroup.AddStyling(StylingOption.MarginTop, 2);
            AppendChild(multiInputGroup);
        }
Beispiel #3
0
        public SettingsPage(PageStorage <SettingsData> settingsData) : base("div")
        {
            bool useSafeLoading = false;

            if (settingsData.TryLoad() == false)
            {
                settingsData.UseSafeLoading();
                useSafeLoading = true;
            }
            if (PageStorage <HumiditySensorData> .Instance.TryLoad() == false)
            {
                PageStorage <HumiditySensorData> .Instance.UseSafeLoading();

                useSafeLoading = true;
            }
            this.AddScriptDependency("/lib/bootstrap3-typeahead.min.js");
            const int labelSize = 180;

            _settingsData = settingsData;

            #region Initialize Grid

            Container wrappingContainer = new Container(this);
            Grid      grid = new Grid(wrappingContainer);

            grid.AddStyling(StylingOption.MarginRight, 2);
            grid.AddStyling(StylingOption.MarginLeft, 2);
            grid.AddStyling(StylingOption.MarginTop, 4);
            grid.AddStyling(StylingOption.MarginBottom, 2);

            #endregion Initialize Grid

            if (useSafeLoading)
            {
                grid.AddRow().AppendCollum(new Heading(3, "Wegen Verbindungsproblemem wurden keine Daten geladen!")
                {
                    Style = { Color = Color.Red }
                });
            }

            #region AutoEnabled

            MultiInputGroup autoEnabledMultiInputGroup = new MultiInputGroup();
            autoEnabledMultiInputGroup.AppendLabel("Automatik", labelSize);
            autoEnabledMultiInputGroup
            .AppendCustomElement(
                new TwoStateButtonGroup("Aktiv", "Inaktiv", settingsData.StorageData.Enabled,
                                        !settingsData.StorageData.Enabled), false).FirstButtonStateChange += (sender, args) =>
                                                                                                             settingsData.StorageData.Enabled = args.NewButtonState;
            autoEnabledMultiInputGroup.AddStyling(StylingOption.MarginBottom, 2);
            autoEnabledMultiInputGroup.AppendCustomElement(new Button(StylingColor.Danger, true, Button.ButtonSize.Normal, false, "Alle Kanäle ausschalten", fontAwesomeIcon: "stop"), false).Click += (sender, args) =>
            {
                ServerConnection.DeleteAsync("settings", "stopall");
            };
            grid.AddRow().AppendCollum(autoEnabledMultiInputGroup, autoSize: true);

            #endregion AutoEnabled

            #region WeatherEnabled

            MultiInputGroup weatherEnabledMultiInputGroup = new MultiInputGroup();
            weatherEnabledMultiInputGroup.AppendLabel("Wetterdaten verwenden", labelSize);
            weatherEnabledMultiInputGroup
            .AppendCustomElement(
                new TwoStateButtonGroup("Aktiv", "Inaktiv", settingsData.StorageData.WeatherEnabled,
                                        !settingsData.StorageData.WeatherEnabled), false).FirstButtonStateChange += (sender, args) =>
                                                                                                                    settingsData.StorageData.WeatherEnabled = args.NewButtonState;
            weatherEnabledMultiInputGroup.AddStyling(StylingOption.MarginBottom, 2);
            grid.AddRow().AppendCollum(weatherEnabledMultiInputGroup, autoSize: true);

            #endregion WeatherEnabled

            #region Location

            Row locationRow = grid.AddRow();
            locationRow.AddStyling(StylingOption.MarginBottom, 2);
            MultiInputGroup weatherLocationMultiInputGroup = new MultiInputGroup();
            weatherLocationMultiInputGroup.AppendLabel("Standort", labelSize);

            StylableTextInput weatherLocationTextInput = weatherLocationMultiInputGroup.AppendTextInput("Bitte Eintragen...", false);
            weatherLocationTextInput.Value = settingsData.StorageData.LocationFriendlyName;

            #region Hidden TextInputs

            TextInput weatherLocationChangeTextInput = new TextInput {
                IsHidden = true, Value = settingsData.StorageData.Location
            };

            locationRow.AppendChild(weatherLocationChangeTextInput);
            TextInput weatherLocationNameChangeTextInput = new TextInput {
                IsHidden = true, Value = settingsData.StorageData.LocationFriendlyName
            };

            locationRow.AppendChild(weatherLocationNameChangeTextInput);

            #endregion Hidden TextInputs

            #region Autocomplete

            weatherLocationTextInput.ActivateAutocomplete("/settings/WeatherLocations.json", new Dictionary <string, TextInput>()
            {
                { "location", weatherLocationChangeTextInput },
                { "name", weatherLocationNameChangeTextInput }
            });

            #endregion Autocomplete

            locationRow.AppendCollum(weatherLocationMultiInputGroup, autoSize: true);

            #region Save Button

            Button saveLocationButton = new Button(StylingColor.Success, true, text: "Übernehmen");
            saveLocationButton.Click += (sender, args) =>
            {
                if (weatherLocationChangeTextInput.Value == "")
                {
                    weatherLocationTextInput.SetValidation(false, true);
                }
                else
                {
                    weatherLocationTextInput.SetValidation(false, false);
                    settingsData.StorageData.Location             = weatherLocationChangeTextInput.Value;
                    settingsData.StorageData.LocationFriendlyName = weatherLocationNameChangeTextInput.Value;
                    weatherLocationTextInput.Value = settingsData.StorageData.LocationFriendlyName;
                }
            };
            locationRow.AppendCollum(saveLocationButton, autoSize: true);

            #endregion Save Button

            #endregion Location

            #region Override

            _overrideInputGroup = new OverrideInputGroup(_settingsData.StorageData.OverrideValue, labelSizeInPx: labelSize);
            grid.AddRow().AppendCollum(_overrideInputGroup, autoSize: true);

            #endregion Override

            #region Rename HumiditySensors

            Row humidityRow = grid.AddRow();
            humidityRow.AppendChild(new Heading(3, "Feuchigkeitssensoren Umbenennen"));
            humidityRow.AddNewLine();

            #region Sync Server HumidityList with Storage

            foreach (string humiditySensor in PageStorage <HumiditySensorData> .Instance.StorageData.HumiditySensors)
            {
                if (settingsData.StorageData.HumiditySensors.ContainsKey(humiditySensor) == false)
                {
                    settingsData.StorageData.HumiditySensors.Add(humiditySensor, humiditySensor);
                }
            }

            List <string> removeList = new List <string>();
            foreach ((string realSensorName, string _) in settingsData.StorageData.HumiditySensors)
            {
                if (PageStorage <HumiditySensorData> .Instance.StorageData.HumiditySensors.Contains(realSensorName) == false)
                {
                    removeList.Add(realSensorName);
                }
            }

            foreach (string s in removeList)
            {
                settingsData.StorageData.HumiditySensors.Remove(s);
            }

            #endregion Sync Server HumidityList with Storage

            _humidityDropdown = new Dropdown(new Button(StylingColor.Secondary, true, widthInPx: 150));
            humidityRow.AppendCollum(_humidityDropdown, autoSize: true);

            foreach (string humiditySensor in PageStorage <HumiditySensorData> .Instance.StorageData.HumiditySensors)
            {
                StylableAnchor stylableAnchor = _humidityDropdown.AddEntry(humiditySensor);
                stylableAnchor.Click += (sender, args) => SelectHumiditySensor(humiditySensor);
            }

            _humiditySensorTextInputGroup = new TextInputGroup("Freundlicher Name", "Bitte Eingeben!");
            humidityRow.AppendCollum(_humiditySensorTextInputGroup, autoSize: true);

            Button button = new Button(StylingColor.Success, true, text: "Übernehmen");
            button.Click += (sender, args) =>
            {
                if (_humidityDropdown.Button.Text != "")
                {
                    _settingsData.StorageData.HumiditySensors[_humidityDropdown.Button.Text] = _humiditySensorTextInputGroup.TextInput.Value;
                }
            };

            humidityRow.AppendCollum(button, autoSize: true);
            if (PageStorage <HumiditySensorData> .Instance.StorageData.HumiditySensors.Count > 0)
            {
                SelectHumiditySensor(PageStorage <HumiditySensorData> .Instance.StorageData.HumiditySensors.First());
            }
            else
            {
                humidityRow.IsHidden = true;
            }
            humidityRow.AddStyling(StylingOption.MarginBottom, 2);

            #endregion Rename HumiditySensors

            #region Backend Server Path

            grid.AddRow().AppendCollum(new Heading(3, "Backend Server Schnittstelle einstellen")
            {
                ClassName = "text-center mb-4"
            });
            Row backendServerRow = grid.AddRow();
            Row backendServerConfigurationSingeApiRow = grid.AddRow();
            Row backendServerConfigurationMultiApiRow = grid.AddRow();
            backendServerRow.AddNewLine();

            BackendData backendInstanceStorageData = PageStorage <BackendData> .Instance.StorageData;

            MultiInputGroup backendConfigurationSourceSwitchingMultiInputGroup = backendServerRow.AppendCollum(new MultiInputGroup());
            backendConfigurationSourceSwitchingMultiInputGroup.AppendLabel("Quelle Auswählen", labelSize);
            TwoStateButtonGroup backendConfigurationSourceSwitchingTwoStateButton = backendConfigurationSourceSwitchingMultiInputGroup.AppendCustomElement(new TwoStateButtonGroup("Sammelkonfiguration", "einzele Konfiguration", !backendInstanceStorageData.SingleApiConfiguration, backendInstanceStorageData.SingleApiConfiguration), false);

            void OnBackendConfigurationSourceSwitchingTwoStateButtonOnFirstButtonStateChange(object sender, ButtonChangeEventHandlerArgs args)
            {
                if (args.NewButtonState == true)
                {
                    backendServerConfigurationSingeApiRow.Style.Display = "none";
                    backendServerConfigurationMultiApiRow.Style.Display = null;
                }
                else
                {
                    backendServerConfigurationSingeApiRow.Style.Display = null;
                    backendServerConfigurationMultiApiRow.Style.Display = "none";
                }

                backendInstanceStorageData.SingleApiConfiguration = !args.NewButtonState;
            }

            backendConfigurationSourceSwitchingTwoStateButton.FirstButtonStateChange += OnBackendConfigurationSourceSwitchingTwoStateButtonOnFirstButtonStateChange;
            OnBackendConfigurationSourceSwitchingTwoStateButtonOnFirstButtonStateChange(null, new ButtonChangeEventHandlerArgs(false, !backendInstanceStorageData.SingleApiConfiguration));
            backendConfigurationSourceSwitchingMultiInputGroup.AddStyling(StylingOption.MarginBottom, 5);

            #region backendServerConfigurationSingeApiRow

            foreach ((string name, BackendProperty backedProperties) in backendInstanceStorageData.BackendProperties)
            {
                backendServerConfigurationSingeApiRow.AddNewLine();
                backendServerConfigurationSingeApiRow.AppendCollum(CreateSingleBackendCollum(name, backedProperties), autoSize: true);
            }

            backendServerConfigurationSingeApiRow.AddNewLine();
            backendServerConfigurationSingeApiRow.AddNewLine();
            backendServerConfigurationSingeApiRow.AppendCollum(new Button(StylingColor.Light, false, Button.ButtonSize.Normal, false, "Standardkonfiguration eintragen")).Click += (sender, args) =>
            {
                foreach ((string name, BackendProperty _) in backendInstanceStorageData.BackendProperties)
                {
                    if (_backendPathTextInputDictionary[name].Value == "")
                    {
                        _backendPathTextInputDictionary[name].Value = $"http://{Dns.GetHostAddresses("WebPiServer.PiWeb")[0].ToString()}:5000/api/{name}";
                    }
                }
            };

            #endregion backendServerConfigurationSingeApiRow

            #region backendServerConfigurationMultiApiRow

            backendServerConfigurationMultiApiRow.AppendCollum(CreateMultiBackendCollum(backendInstanceStorageData, out StylableTextInput backendServerConfigurationMultiApiTextInput), autoSize: true);
            backendServerConfigurationMultiApiRow.AddNewLine();
            backendServerConfigurationMultiApiRow.AppendCollum(new Button(StylingColor.Light, false, Button.ButtonSize.Normal, false, "Standardkonfiguration eintragen")).Click += (sender, args) =>
            {
                if (backendServerConfigurationMultiApiTextInput.Value == "")
                {
                    backendServerConfigurationMultiApiTextInput.Value = $"http://{Dns.GetHostAddresses("WebPiServer.PiWeb")[0].ToString()}:5000/api";
                }
            };

            #endregion backendServerConfigurationMultiApiRow

            #endregion Backend Server Path
        }
Beispiel #4
0
        public JobPage(JobEntry job, ManualPage parent) : base("div")
        {
            this._job = job;
            SetBorder(BorderKind.Rounded, StylingColor.Secondary);

            #region Initialize Grid

            Grid grid = new Grid(this);
            grid.AddStyling(StylingOption.MarginRight, 2);
            grid.AddStyling(StylingOption.MarginLeft, 2);
            grid.AddStyling(StylingOption.MarginTop, 4);
            grid.AddStyling(StylingOption.MarginBottom, 2);

            #endregion Initialize Grid

            #region JobName

            MultiInputGroup jobNameMultiInputGroup = new MultiInputGroup();
            jobNameMultiInputGroup.AppendLabel("JobName");
            StylableTextInput jobNameTextInput = jobNameMultiInputGroup.AppendTextInput("Name?", startText: job.Name);
            jobNameMultiInputGroup.AppendValidation("", "Ein Job mit diesem Namen existiert bereits", false);
            Button saveJobNameButton = jobNameMultiInputGroup.AppendCustomElement(new Button(StylingColor.Success, asOutline: true, text: "Namen übernehmen", fontAwesomeIcon: "save"), false);
            Button deleteJobButton   = jobNameMultiInputGroup.AppendCustomElement(new Button(StylingColor.Danger, asOutline: true, text: "Job Löschen", fontAwesomeIcon: "trash"), false);
            deleteJobButton.Click += (sender, args) =>
            {
                const string confirmMessage = "Wirklich Löschen";
                if (deleteJobButton.Text != confirmMessage)
                {
                    deleteJobButton.Text = confirmMessage;
                    return;
                }
                else
                {
                    PageStorage <ManualData> .Instance.StorageData.JobEntries.Remove(job);

                    parent.UpdateJobs();
                }
            };

            saveJobNameButton.Click += (sender, args) =>
            {
                if (PageStorage <ManualData> .Instance.StorageData.JobEntries.Any(entry => entry.Name == jobNameTextInput.Value))
                {
                    if (job.Name == jobNameTextInput.Value)
                    {
                        return;
                    }
                    else
                    {
                        jobNameTextInput.SetValidation(false, true);
                    }
                }
                else
                {
                    jobNameTextInput.SetValidation(true, false);
                    job.Name = jobNameTextInput.Value;
                    parent.UpdateJobs();
                }
            };
            grid.AddRow().AppendCollum(jobNameMultiInputGroup, autoSize: true);

            #endregion JobName

            #region ExecuteJob

            #region Init Container

            Container firstContainer = new Container();
            firstContainer.SetBorder(BorderKind.Rounded, StylingColor.Info);
            firstContainer.AddStyling(StylingOption.MarginTop, 3);
            firstContainer.AddStyling(StylingOption.MarginBottom, 1);
            firstContainer.AddStyling(StylingOption.PaddingTop, 3);
            firstContainer.AddStyling(StylingOption.PaddingBottom, 2);
            grid.AddRow().AppendCollum(firstContainer, autoSize: true);

            #endregion Init Container

            #region create Heading

            Heading firstHeading = new Heading(5, "Job Ausführen ...");
            firstContainer.AppendChild(firstHeading);

            #endregion create Heading

            #region Override

            OverrideInputGroup overrideInputGroup = new OverrideInputGroup(100);
            firstContainer.AppendChild(overrideInputGroup);

            #endregion Override

            #region StartButton

            Button startButton = new Button(StylingColor.Success, true, text: "Einreihen!", fontAwesomeIcon: "plus-circle", asBlock: true);
            firstContainer.AppendChild(startButton);
            startButton.Click += (o, args) =>
            {
                startButton.IsDisabled = true;
                try
                {
                    CreateJobAction(job, overrideInputGroup.Value);

                    startButton.Text = "Wurde Eingereiht";
                    Task.Run(() =>
                    {
                        System.Threading.Thread.Sleep(5000);
                        startButton.Text = "Einreihen!";
                        startButton.SetFontAwesomeIcon("plus-circle");
                        return(startButton.IsDisabled = false);
                    });
                }
                catch (Exception)
                {
                    startButton.Text = "Einreihen fehlgeschlagen";
                    throw;
                }
            };
            firstContainer.AppendChild(startButton);
            startButton.AddStyling(StylingOption.MarginBottom, 2);

            #endregion StartButton

            #endregion ExecuteJob

            grid.AddRow().AppendCollum(new Heading(4, "Batch Einträge"), autoSize: true);
            List batchEntries = grid.AddRow().AppendCollum(new List(false), autoSize: true);
            foreach (BatchEntry jobBatchEntry in job.BatchEntries)
            {
                batchEntries.AppendChild(new ListItem()
                {
                    Text = $"{jobBatchEntry.Name} {jobBatchEntry.ToString()}"
                });
            }
        }
Beispiel #5
0
        public BatchPage(BatchEntry batch, ManualPage parent) : base("div")
        {
            const int labelSize = 100;

            _batch = batch;
            SetBorder(BorderKind.Rounded, StylingColor.Secondary);

            #region Initialize Grid

            Grid grid = new Grid(this);
            grid.AddStyling(StylingOption.MarginRight, 2);
            grid.AddStyling(StylingOption.MarginLeft, 2);
            grid.AddStyling(StylingOption.MarginTop, 4);
            grid.AddStyling(StylingOption.MarginBottom, 2);

            #endregion Initialize Grid

            #region JobName

            MultiInputGroup batchNameMultiInputGroup = new MultiInputGroup();
            batchNameMultiInputGroup.AppendLabel("BatchName", labelSize);
            StylableTextInput batchNameTextInput = batchNameMultiInputGroup.AppendTextInput("Name?", startText: batch.Name);
            batchNameMultiInputGroup.AppendValidation("", "Ein Batch-Auftrag mit diesem Namen existiert bereits", false);
            batchNameMultiInputGroup.AppendCustomElement(new Button(StylingColor.Success, asOutline: true, text: "Namen übernehmen", fontAwesomeIcon: "save"), false).Click += (sender, args) =>
            {
                if (batchNameTextInput.Value == "")
                {
                    batchNameTextInput.SetValidation(false, true);
                    return;
                }
                if (PageStorage <ManualData> .Instance.StorageData.BatchEntries.Any(entry => entry.Name == batchNameTextInput.Value))
                {
                    if (batch.Name == batchNameTextInput.Value)
                    {
                        return;
                    }
                    else
                    {
                        batchNameTextInput.SetValidation(false, true);
                    }
                }
                else
                {
                    batchNameTextInput.SetValidation(true, false);
                    foreach (BatchEntry entry in PageStorage <ManualData> .Instance.StorageData.JobEntries.SelectMany(
                                 entry => entry.BatchEntries.Where(batchEntry =>
                                                                   batchEntry.Name == batch.Name && batchEntry != batch)))
                    {
                        entry.Name = batchNameTextInput.Value;
                    }
                    batch.Name = batchNameTextInput.Value;
                    parent.UpdateBatch();
                }
            };

            Button deleteJobButton = batchNameMultiInputGroup.AppendCustomElement(new Button(StylingColor.Danger, asOutline: true, text: "Batch-Auftrag Löschen", fontAwesomeIcon: "trash"), false);
            deleteJobButton.Click += (sender, args) =>
            {
                const string confirmMessage = "Wirklich Löschen";
                if (deleteJobButton.Text != confirmMessage)
                {
                    deleteJobButton.Text = confirmMessage;
                    return;
                }
                else
                {
                    PageStorage <ManualData> .Instance.StorageData.BatchEntries.Remove(batch);

                    List <JobEntry> removeList = new List <JobEntry>();

                    foreach (JobEntry entry in PageStorage <ManualData> .Instance.StorageData.JobEntries.Where(entry =>
                                                                                                               entry.BatchEntries.Any(batchEntry => batchEntry.Name == batch.Name)))
                    {
                        entry.BatchEntries.RemoveAll(batchEntry => batchEntry.Name == batch.Name);
                        if (entry.BatchEntries.Count == 0)
                        {
                            removeList.Add(entry);
                        }
                    }

                    foreach (JobEntry jobEntry in removeList)
                    {
                        PageStorage <ManualData> .Instance.StorageData.JobEntries.Remove(jobEntry);
                    }

                    parent.UpdateBatch();
                    parent.UpdateJobs();
                }
            };

            batchNameMultiInputGroup.AddStyling(StylingOption.MarginBottom, 2);
            grid.AddRow().AppendCollum(batchNameMultiInputGroup, autoSize: true);

            MultiInputGroup batchActionMultiInputGroup = new MultiInputGroup();
            batchActionMultiInputGroup.AppendLabel("Aktion", labelSize);
            batchActionMultiInputGroup.AppendLabel(batch.ToString());
            batchActionMultiInputGroup.AddStyling(StylingOption.MarginBottom, 1);
            grid.AddRow().AppendCollum(batchActionMultiInputGroup, autoSize: true);

            #endregion JobName

            #region ExecuteAction

            #region Init Container

            Container firstContainer = new Container();
            firstContainer.SetBorder(BorderKind.Rounded, StylingColor.Info);
            firstContainer.AddStyling(StylingOption.MarginTop, 3);
            firstContainer.AddStyling(StylingOption.MarginBottom, 1);
            firstContainer.AddStyling(StylingOption.PaddingTop, 3);
            firstContainer.AddStyling(StylingOption.PaddingBottom, 2);
            grid.AddRow().AppendCollum(firstContainer, autoSize: true);

            #endregion Init Container

            #region create Heading

            Heading firstHeading = new Heading(5, "Batch Ausführen ...");
            firstContainer.AppendChild(firstHeading);

            #endregion create Heading

            #region Override

            OverrideInputGroup overrideInputGroup = new OverrideInputGroup(100);
            firstContainer.AppendChild(overrideInputGroup);

            #endregion Override

            #region StartButton

            Button startButton = new Button(StylingColor.Success, true, text: "Einreihen!", fontAwesomeIcon: "plus-circle", asBlock: true);
            firstContainer.AppendChild(startButton);
            startButton.Click += (o, args) =>
            {
                startButton.IsDisabled = true;
                try
                {
                    CreateBatchAction(batch, overrideInputGroup.Value);

                    startButton.Text = "Wurde Eingereiht";
                    Task.Run(() =>
                    {
                        System.Threading.Thread.Sleep(5000);
                        startButton.Text = "Einreihen!";
                        startButton.SetFontAwesomeIcon("plus-circle");
                        return(startButton.IsDisabled = false);
                    });
                }
                catch (Exception)
                {
                    startButton.Text = "Einreihen fehlgeschlagen";
                    throw;
                }
            };
            firstContainer.AppendChild(startButton);
            startButton.AddStyling(StylingOption.MarginBottom, 2);

            #endregion StartButton

            #endregion ExecuteAction

            #region AddToJob

            #region Init Container

            Container secondContainer = new Container();
            secondContainer.SetBorder(BorderKind.Rounded, StylingColor.Info);
            secondContainer.AddStyling(StylingOption.MarginTop, 3);
            secondContainer.AddStyling(StylingOption.MarginBottom, 1);
            secondContainer.AddStyling(StylingOption.PaddingTop, 3);
            secondContainer.AddStyling(StylingOption.PaddingBottom, 2);
            grid.AddRow().AppendCollum(secondContainer, autoSize: true);

            #endregion Init Container

            #region create Heading

            Heading heading = new Heading(5, "... zu Job-Auftrag hinzufügen");
            secondContainer.AppendChild(heading);

            #endregion create Heading

            #region JobName Input

            _jobNameMultiInputGroup = new MultiInputGroup();
            _jobNameMultiInputGroup.AddStyling(StylingOption.MarginTop, 4);
            _jobNameMultiInputGroup.AppendLabel("Name für den Job-Auftrag:");
            StylableTextInput jobNameTextInput = _jobNameMultiInputGroup.AppendTextInput("Name?");
            _jobNameMultiInputGroup.AppendValidation("", "Es gibt bereits einen Job mit diesem Namen", false);
            _jobNameMultiInputGroup.IsHidden = true;
            secondContainer.AppendChild(_jobNameMultiInputGroup);

            #endregion JobName Input

            #region jobSelect

            MultiInputGroup jobSelectMultiInputGroup = new MultiInputGroup();
            jobSelectMultiInputGroup.AddStyling(StylingOption.MarginTop, 4);
            jobSelectMultiInputGroup.AppendLabel("Ziel Job:");
            _jobSelectDropdown = jobSelectMultiInputGroup.AppendCustomElement(new Dropdown(new Button(StylingColor.Secondary, true, text: "Bitte Wählen!"), DropdownDirection.DropDown), false);
            FillJobDropDown();
            jobSelectMultiInputGroup.AppendValidation("", "Dieser Batch-Auftrag ist bereits Bestandteil des Jobs", true);
            secondContainer.AppendChild(jobSelectMultiInputGroup);

            #endregion jobSelect

            #region Appent To Job or Create New

            _appendToJobButton = new Button(StylingColor.Success, true, text: "Zu Job-Auftrag hinzufügen", fontAwesomeIcon: "save", asBlock: true);
            _appendToJobButton.AddStyling(StylingOption.MarginTop, 2);
            _appendToJobButton.Click += (sender, args) =>
            {
                if (batchNameTextInput.Value == "")
                {
                    jobNameTextInput.SetValidation(false, true);
                    return;
                }
                if (_jobSelectDropdown.Button.Text == NewJobString)
                {
                    if (PageStorage <ManualData> .Instance.StorageData.JobEntries.Any(entry => entry.Name == jobNameTextInput.Value) || jobNameTextInput.Value == "")
                    {
                        // Invalid entered Name
                        jobNameTextInput.SetValidation(false, true);
                    }
                    else
                    {
                        // Create Job
                        jobNameTextInput.SetValidation(true, false);
                        PageStorage <ManualData> .Instance.StorageData.JobEntries.Add(new JobEntry(jobNameTextInput.Value, batch));

                        parent.UpdateJobs();
                        _jobNameMultiInputGroup.IsHidden = true;
                        _jobSelectDropdown.Button.Text   = jobNameTextInput.Value;

                        _appendToJobButton.IsHidden   = true;
                        _removeFromJobButton.IsHidden = false;
                    }
                }
                else
                {
                    jobNameTextInput.SetValidation(false, false);

                    // Add To Job
                    PageStorage <ManualData> .Instance.StorageData.JobEntries.First(entry => entry.Name == _jobSelectDropdown.Button.Text).BatchEntries.Add(batch);

                    parent.UpdateJobs();

                    _appendToJobButton.IsHidden   = true;
                    _removeFromJobButton.IsHidden = false;
                }
            };
            secondContainer.AppendChild(_appendToJobButton);

            #endregion Appent To Job or Create New

            #region Remove From Job

            _removeFromJobButton = new Button(StylingColor.Danger, true, text: "Aus Job löschen", fontAwesomeIcon: "trash", asBlock: true);
            _removeFromJobButton.AddStyling(StylingOption.MarginTop, 2);
            _removeFromJobButton.IsHidden = true;
            _removeFromJobButton.Click   += (sender, args) =>
            {
                if (PageStorage <ManualData> .Instance.StorageData.JobEntries.Any(entry => entry.Name == _jobSelectDropdown.Button.Text))
                {
                    JobEntry jobEntry = PageStorage <ManualData> .Instance.StorageData.JobEntries.First(entry => entry.Name == _jobSelectDropdown.Button.Text);

                    jobEntry.BatchEntries.RemoveAll(entry => entry.Name == _batch.Name);
                    if (jobEntry.BatchEntries.Count == 0)
                    {
                        PageStorage <ManualData> .Instance.StorageData.JobEntries.Remove(jobEntry);
                    }
                }
                _removeFromJobButton.IsHidden = true;
                _appendToJobButton.IsHidden   = false;
                FillJobDropDown();
                parent.UpdateJobs();
            };
            secondContainer.AppendChild(_removeFromJobButton);

            #endregion Remove From Job

            #endregion AddToJob
        }
Beispiel #6
0
        public ManualChannelPage(ChannelData channel, ManualPage parent) : base("div")
        {
            const int labelSize = 229;

            _channel = channel;
            SetBorder(BorderKind.Rounded, StylingColor.Secondary);

            #region ExecuteAction

            #region Initialize Grid

            Grid grid = new Grid(this);
            grid.AddStyling(StylingOption.MarginRight, 2);
            grid.AddStyling(StylingOption.MarginLeft, 2);
            grid.AddStyling(StylingOption.MarginTop, 4);
            grid.AddStyling(StylingOption.MarginBottom, 2);

            #endregion Initialize Grid

            #region Init Container

            Container firstContainer = new Container();
            firstContainer.SetBorder(BorderKind.Rounded, StylingColor.Info);
            firstContainer.AddStyling(StylingOption.MarginTop, 3);
            firstContainer.AddStyling(StylingOption.MarginBottom, 1);
            firstContainer.AddStyling(StylingOption.PaddingTop, 3);
            firstContainer.AddStyling(StylingOption.PaddingBottom, 2);
            grid.AddRow().AppendCollum(firstContainer, autoSize: true);

            #endregion Init Container

            #region create Heading

            Heading firstHeading = new Heading(5, "Kanal aktivieren ...");
            firstContainer.AppendChild(firstHeading);

            #endregion create Heading

            #region duration Input

            MultiInputGroup durationMultiInputGroup = new MultiInputGroup();
            durationMultiInputGroup.AppendLabel("Dauer", labelSize);
            StylableTextInput durationTextInput = durationMultiInputGroup.AppendTextInput("hh:mm:ss");
            durationTextInput.Value = "00:00:00";
            firstContainer.AppendChild(durationMultiInputGroup);
            durationMultiInputGroup.AddStyling(StylingOption.MarginBottom, 2);
            durationMultiInputGroup.AppendValidation("", "Das Format der Dauer muss hh:mm:ss sein!", true);

            #endregion duration Input

            #region Master ButtonGroup

            MultiInputGroup masterEnabledMultiInputGroup = new MultiInputGroup();
            masterEnabledMultiInputGroup.AppendLabel("Master Aktivieren", labelSize);
            TwoStateButtonGroup masterEnabledTwoStateButtonGroup = masterEnabledMultiInputGroup.AppendCustomElement(new TwoStateButtonGroup("Ja", "Nein", true, false), false);
            firstContainer.AppendChild(masterEnabledMultiInputGroup);
            masterEnabledMultiInputGroup.AddStyling(StylingOption.MarginBottom, 2);

            #endregion Master ButtonGroup

            #region StartButton

            Button startButton = new Button(StylingColor.Success, true, text: "Einreihen!", fontAwesomeIcon: "plus-circle", asBlock: true);
            firstContainer.AppendChild(startButton);
            startButton.Click += (o, args) =>
            {
                if (durationTextInput.Value.Split(':').Length != 3 || durationTextInput.Value.Split(':').Any(s => int.TryParse(s, out _) == false))
                {
                    durationTextInput.SetValidation(false, true);
                }
                else
                {
                    durationTextInput.SetValidation(true, false);
                    startButton.IsDisabled = true;
                    try
                    {
                        CreateChannelAction(channel, TimeSpan.Parse(durationTextInput.Value), masterEnabledTwoStateButtonGroup.FirstButtonActive, 100);

                        startButton.Text = "Wurde Eingereiht";
                        Task.Run(() =>
                        {
                            System.Threading.Thread.Sleep(5000);
                            startButton.Text = "Einreihen!";
                            startButton.SetFontAwesomeIcon("plus-circle");
                            return(startButton.IsDisabled = false);
                        });
                    }
                    catch (Exception)
                    {
                        startButton.Text = "Einreihen fehlgeschlagen";
                        throw;
                    }
                }
            };
            firstContainer.AppendChild(startButton);
            startButton.AddStyling(StylingOption.MarginBottom, 2);

            #endregion StartButton

            #endregion ExecuteAction

            #region AddToBatch

            #region Init Container

            Container secondContainer = new Container();
            secondContainer.SetBorder(BorderKind.Rounded, StylingColor.Info);
            secondContainer.AddStyling(StylingOption.MarginTop, 3);
            secondContainer.AddStyling(StylingOption.MarginBottom, 1);
            secondContainer.AddStyling(StylingOption.PaddingTop, 3);
            secondContainer.AddStyling(StylingOption.PaddingBottom, 2);
            grid.AddRow().AppendCollum(secondContainer, autoSize: true);

            #endregion Init Container

            #region create Heading

            Heading heading = new Heading(5, "... als Batch-Auftrag speichern");
            secondContainer.AppendChild(heading);

            #endregion create Heading

            #region batchName Input

            MultiInputGroup batchNameMultiInputGroup = new MultiInputGroup();
            batchNameMultiInputGroup.AddStyling(StylingOption.MarginTop, 4);
            batchNameMultiInputGroup.AppendLabel("Name für den Batch-Auftrag:");
            StylableTextInput batchNameTextInput = batchNameMultiInputGroup.AppendTextInput("Name?");
            batchNameMultiInputGroup.AppendValidation("", "Der Name ist bereits vergeben", true);
            secondContainer.AppendChild(batchNameMultiInputGroup);

            #endregion batchName Input

            Button appendToBatchButton = new Button(StylingColor.Success, true, text: "Als Batch-Auftrag speichern", fontAwesomeIcon: "save", asBlock: true);
            appendToBatchButton.AddStyling(StylingOption.MarginTop, 2);
            appendToBatchButton.Click += (sender, args) =>
            {
                if (batchNameTextInput.Value == "")
                {
                    batchNameTextInput.SetValidation(false, true);
                    return;
                }
                if (PageStorage <ManualData> .Instance.StorageData.BatchEntries.Any(entry => entry.Name == batchNameTextInput.Value))
                {
                    batchNameTextInput.SetValidation(false, true);
                }
                else
                {
                    batchNameTextInput.SetValidation(true, false);
                    PageStorage <ManualData> .Instance.StorageData.BatchEntries.Add(new BatchEntry(batchNameTextInput.Value, channel.ChannelId, TimeSpan.Parse(durationTextInput.Value), masterEnabledTwoStateButtonGroup.FirstButtonActive, 100));

                    parent.UpdateBatch();
                }
            };
            secondContainer.AppendChild(appendToBatchButton);

            #endregion AddToBatch
        }