예제 #1
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
        }
예제 #2
0
        public ChannelProgrammPage(ChannelProgramData channelProgram, ChannelPage parentChannelPage, bool isMasterChannel) : base("div")
        {
            const int labelSize = 235;

            _channelProgram    = channelProgram;
            _parentChannelPage = parentChannelPage;

            #region Initialize Grid

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

            #endregion Initialize Grid

            #region TextInputGroup ProgrammName

            _programmNameInputGroup = new TextInputGroup("ProgrammName", "N/A", labelSize, centeredText: true);
            _programmNameInputGroup.AddStyling(StylingOption.MarginBottom, 2);
            _programmNameInputGroup.TextInput.Value = channelProgram.Name;
            _deleteProgrammButton        = new MyOoui.HtmlElements.Button(StylingColor.Danger, asOutline: true, text: "Programm Löschen", fontAwesomeIcon: "trash");
            _deleteProgrammButton.Click += DeleteProgrammButtonOnClick;
            _programmNameInputGroup.AddFormElement(_deleteProgrammButton);
            grid.AddRow().AppendCollum(_programmNameInputGroup);

            #endregion TextInputGroup ProgrammName

            #region InputGroup > TwoStateButtonGroup ProgrammStatus

            MultiInputGroup programmEnabledMultiInputGroup = new MultiInputGroup();
            programmEnabledMultiInputGroup.AppendLabel("Programmstatus", labelSize);
            programmEnabledMultiInputGroup.AddStyling(StylingOption.MarginBottom, 2);
            _programmEnabled = programmEnabledMultiInputGroup.AppendCustomElement(new TwoStateButtonGroup("Aktiv", "Inaktiv", channelProgram.Enabled, !channelProgram.Enabled), false);
            grid.AddRow().AppendCollum(programmEnabledMultiInputGroup, autoSize: true);

            #endregion InputGroup > TwoStateButtonGroup ProgrammStatus

            #region TextInputGroup StartZeit

            _startTimeInputGroup = new TextInputGroup("StartZeit", "N/A", labelSize, "", "Das angegebene Zeitformat passt nicht. Bitte Zeiten im Format  hh:mm:ss  angeben.");
            _startTimeInputGroup.AddStyling(StylingOption.MarginBottom, 2);
            _startTimeInputGroup.TextInput.Value = channelProgram.StartTime.ToString();
            grid.AddRow().AppendCollum(_startTimeInputGroup);

            #endregion TextInputGroup StartZeit

            #region TextInputGroup Dauer

            _durationInputGroup = new TextInputGroup("Dauer", "N/A", labelSize, "", "Das angegebene Zeitformat passt nicht. Bitte Zeiten im Format  hh:mm:ss  angeben.");
            _durationInputGroup.AddStyling(StylingOption.MarginBottom, 2);
            _durationInputGroup.TextInput.Value = channelProgram.Duration.ToString();
            grid.AddRow().AppendCollum(_durationInputGroup);

            #endregion TextInputGroup Dauer

            #region Row Declaration

            Row downRow = new Row();
            grid.AddRow().AppendCollum(downRow);
            Row weekDaysRow = new Row();
            downRow.AppendCollum(weekDaysRow, sizing: 4);
            Row otherRow = new Row();
            downRow.AppendCollum(otherRow, sizing: 8);

            #endregion Row Declaration

            #region Weekdays

            _weekdaysMoMiFrRadioButtonLabeledInputGroup = new RadioButtonLabeledInputGroup(GetCheckedWeekdays(channelProgram.ChoosenWeekdays) == 1, "Mo, Mi, Fr");
            //_weekdaysMoMiFrRadioButtonLabeledInputGroup.AddStyling(StylingOption.MarginBottom, 2);
            _weekdaysMoMiFrRadioButtonLabeledInputGroup.AddStyling(StylingOption.MarginLeft, 2);
            weekDaysRow.AppendCollum(_weekdaysMoMiFrRadioButtonLabeledInputGroup);
            weekDaysRow.AddNewLine();

            _weekdaysDiDoRadioButtonLabeledInputGroup = new RadioButtonLabeledInputGroup(GetCheckedWeekdays(channelProgram.ChoosenWeekdays) == 2, "Di, Do", _weekdaysMoMiFrRadioButtonLabeledInputGroup.RadioButtonGroupName);
            //_weekdaysDiDoRadioButtonLabeledInputGroup.AddStyling(StylingOption.MarginBottom, 2);
            _weekdaysDiDoRadioButtonLabeledInputGroup.AddStyling(StylingOption.MarginLeft, 2);
            weekDaysRow.AppendCollum(_weekdaysDiDoRadioButtonLabeledInputGroup);
            weekDaysRow.AddNewLine();

            _weekdaysSaSoRadioButtonLabeledInputGroup = new RadioButtonLabeledInputGroup(GetCheckedWeekdays(channelProgram.ChoosenWeekdays) == 3, "Sa, So", _weekdaysMoMiFrRadioButtonLabeledInputGroup.RadioButtonGroupName);
            //_weekdaysSaSoRadioButtonLabeledInputGroup.AddStyling(StylingOption.MarginBottom, 2);
            _weekdaysSaSoRadioButtonLabeledInputGroup.AddStyling(StylingOption.MarginLeft, 2);
            weekDaysRow.AppendCollum(_weekdaysSaSoRadioButtonLabeledInputGroup);
            weekDaysRow.AddNewLine();

            _weekdaysChoosenToggleButtonGroup = new ToggleButtonGroup(StylingColor.Primary, StylingColor.Secondary);
            _weekdaysChoosenToggleButtonGroup.AddToggleButton("Mo", (channelProgram.ChoosenWeekdays & ChannelProgramData.Weekdays.Montag) == ChannelProgramData.Weekdays.Montag);
            _weekdaysChoosenToggleButtonGroup.AddToggleButton("Di", (channelProgram.ChoosenWeekdays & ChannelProgramData.Weekdays.Dienstag) == ChannelProgramData.Weekdays.Dienstag);
            _weekdaysChoosenToggleButtonGroup.AddToggleButton("Mi", (channelProgram.ChoosenWeekdays & ChannelProgramData.Weekdays.Mittwoch) == ChannelProgramData.Weekdays.Mittwoch);
            _weekdaysChoosenToggleButtonGroup.AddToggleButton("Do", (channelProgram.ChoosenWeekdays & ChannelProgramData.Weekdays.Donnerstag) == ChannelProgramData.Weekdays.Donnerstag);
            _weekdaysChoosenToggleButtonGroup.AddToggleButton("Fr", (channelProgram.ChoosenWeekdays & ChannelProgramData.Weekdays.Freitag) == ChannelProgramData.Weekdays.Freitag);
            _weekdaysChoosenToggleButtonGroup.AddToggleButton("Sa", (channelProgram.ChoosenWeekdays & ChannelProgramData.Weekdays.Samstag) == ChannelProgramData.Weekdays.Samstag);
            _weekdaysChoosenToggleButtonGroup.AddToggleButton("So", (channelProgram.ChoosenWeekdays & ChannelProgramData.Weekdays.Sonntag) == ChannelProgramData.Weekdays.Sonntag);
            _weekDaysChoosenRadioButtonInputGroup = new RadioButtonInputGroup(GetCheckedWeekdays(channelProgram.ChoosenWeekdays) == 4, _weekdaysChoosenToggleButtonGroup, _weekdaysMoMiFrRadioButtonLabeledInputGroup.RadioButtonGroupName, false);
            _weekDaysChoosenRadioButtonInputGroup.AddStyling(StylingOption.MarginLeft, 2);
            grid.AddRow().AppendCollum(_weekDaysChoosenRadioButtonInputGroup, autoSize: true);

            #endregion Weekdays

            #region InputGroup > TwoStateButtonGroup WetterInfos

            MultiInputGroup weatherEnabledMultiInputGroup = new MultiInputGroup();
            weatherEnabledMultiInputGroup.AppendLabel("WetterInfos verwenden", labelSize);
            weatherEnabledMultiInputGroup.AddStyling(StylingOption.MarginBottom, 2);
            _weatherInfo = weatherEnabledMultiInputGroup.AppendCustomElement(new TwoStateButtonGroup("Aktiv", "Inaktiv", channelProgram.ActivateWeatherInfo, !channelProgram.ActivateWeatherInfo), false);
            otherRow.AppendCollum(weatherEnabledMultiInputGroup, autoSize: true);

            #endregion InputGroup > TwoStateButtonGroup WetterInfos

            otherRow.AddNewLine();

            #region InputGroup > TwoStateButtonGroup Master Kanal

            MultiInputGroup activateMasterMultiInputGroup = new MultiInputGroup();
            activateMasterMultiInputGroup.AppendLabel("Master Kanal auch Einschalten", labelSize);
            _activateMasterChannel = activateMasterMultiInputGroup.AppendCustomElement(new TwoStateButtonGroup("Aktiv", "Inaktiv", channelProgram.EnableMasterChannel, !channelProgram.EnableMasterChannel), false);
            otherRow.AppendCollum(activateMasterMultiInputGroup, autoSize: true);

            #endregion InputGroup > TwoStateButtonGroup Master Kanal

            #region TextAreaInputGroup Notizen

            _descriptionInputGroup = new TextAreaInputGroup("Notizen", "", labelSize);
            _descriptionInputGroup.AddStyling(StylingOption.MarginBottom, 2);
            _descriptionInputGroup.AddStyling(StylingOption.MarginTop, 2);
            _descriptionInputGroup.TextArea.Value = channelProgram.Description;
            grid.AddRow().AppendCollum(_descriptionInputGroup);

            #endregion TextAreaInputGroup Notizen

            if (isMasterChannel)
            {
                _activateMasterChannel.IsDisabled = true;
            }
        }