public static StringBuilder CreateSensor(string formattedPath, SensorViewModel sensor)
        {
            var result = new StringBuilder(1 << 5);

            string name = formattedPath;

            result.Append("<div class='accordion-item'>")
            .Append($"<h2 class='accordion-header' id='heading_{name}'>");

            var time = (DateTime.UtcNow - sensor.Time);

            if (sensor.SensorType == SensorType.FileSensorBytes)
            {
                //header
                string fileName = GetFileNameString(sensor.StringValue);

                //button
                result.Append($"<button id='{name}' class='accordion-button' style='display: none' type='button' data-bs-toggle='collapse'")
                .Append($"data-bs-target='#collapse_{name}' aria-expanded='true' aria-controls='collapse_{name}'>")
                .Append($"<div><div class='row'><div class='col-md-auto'>{sensor.Name}</div>")
                .Append($"<div class='col'>{sensor.StringValue}</div></div></div></button></h2>");
                //body
                result.Append($"<div id='collapse_{name}' class='accordion-collapse' ")
                .Append($"aria-labelledby='heading_{name}' data-bs-parent='#sensorData_{formattedPath}'>")
                .Append("<div class='accordion-body'>");

                result.Append("<div style='width: 100%'><div class='row justify-content-between'><div class='col-md-auto'>")
                .Append($"<li id='status_{name}' class='fas fa-circle sensor-icon-with-margin ")
                .Append($"{ViewHelper.GetStatusHeaderColorClass(sensor.Status)}' title='Status: {sensor.Status}'></li>");

                result.Append($"<span id='validation_{name}'>");
                if (!string.IsNullOrEmpty(sensor.ValidationError))
                {
                    result.Append(CreateValidationErrorIcon(sensor.ValidationError, name));
                }
                result.Append("</span>");

                result.Append($"{sensor.Name}</div><input id='sensor_type_{name}' value='{(int)sensor.SensorType}' ")
                .Append($"style='display: none' /><div class='col-md-auto time-ago-div' id='update_{name}' ")
                .Append($"style='margin-right: 10px'>updated {GetTimeAgo(time)}</div></div>{sensor.ShortStringValue}</div>")
                .Append($"<div class='row'><div class='col-md-auto'><button id='button_view_{name}' ")
                .Append("class='button-view-file-sensor btn btn-secondary' title='View'>")
                .Append($"<i class='fas fa-eye'></i></button></div><div class='col'><input style='display: none;'")
                .Append($" id='fileType_{name}' value='{fileName}'><button id='button_download_{name}'")
                .Append(" class='button-download-file-sensor-value btn btn-secondary'")
                .Append(" title='Download'><i class='fas fa-file-download'></i></button></div></div>");


                result.Append("</div></div></div>");

                return(result);
            }

            result.Append($"<button id='{name}' class='accordion-button collapsed' type='button' data-bs-toggle='collapse'")
            .Append($"data-bs-target='#collapse_{name}' aria-expanded='false' aria-controls='collapse_{name}'>")
            .Append("<div style='width: 100%'><div class='row justify-content-between'>")
            .Append($"<div class='col-md-auto'><li id='status_{name}' class='fas fa-circle sensor-icon-with-margin ")
            .Append($"{ViewHelper.GetStatusHeaderColorClass(sensor.Status)}' title='Status: {sensor.Status}'></li>");

            result.Append($"<span id='validation_{name}'>");
            if (!string.IsNullOrEmpty(sensor.ValidationError))
            {
                result.Append(CreateValidationErrorIcon(sensor.ValidationError, name));
            }
            result.Append("</span>");

            result.Append($"{sensor.Name}</div><div class='col-md-auto'>")
            .Append($"<input id='sensor_type_{name}' value='{(int)sensor.SensorType}' style='display: none' />")
            .Append($"<div id='update_{name}' class='time-ago-div' style='margin-right: 10px'>updated {GetTimeAgo(time)}</div></div></div>")
            .Append($"<div id='value_{name}'>{sensor.ShortStringValue}</div></div></button></h2>");

            result.Append($"<div id='collapse_{name}' class='accordion-collapse collapse'")
            .Append($"aria-labelledby='heading_{name}' data-bs-parent='#sensorData_{formattedPath}'>")
            .Append($"<div class='accordion-body'><input style='display: none' id='listId_{name}' value='{formattedPath}'/>")
            .Append("<div class='mb-3 row'><div>")
            .Append(CreateRadioButton(name, "hour", "1H"))
            .Append(CreateRadioButton(name, "day", "1D"))
            .Append(CreateRadioButton(name, "three_days", "3D"))
            .Append(CreateRadioButton(name, "week", "1W"))
            .Append(CreateRadioButton(name, "month", "1M"))
            .Append(CreateRadioButton(name, "all", "All"))
            .Append(CreateActionsList(name)).Append("</div>");

            result.Append("<div style='margin-top: 15px'>");
            result.Append(GetNoDataDivForSensor(name));
            result.Append($"<div id='history_{name}'>");
            result.Append(IsPlottingSupported(sensor.SensorType)
                            ? GetNavTabsForHistory(name)
                            : GetValuesDivForHistory(name));

            result.Append("</div></div></div></div></div></div>");

            return(result);
        }
Exemplo n.º 2
0
        public static StringBuilder CreateSensor(string formattedPath, SensorViewModel sensor)
        {
            StringBuilder result = new StringBuilder();
            string        name   = sensor.Name.Replace(' ', '-');

            result.Append("<div class='accordion-item'>" +
                          $"<h2 class='accordion-header' id='heading_{formattedPath}_{name}'>");

            var time = (DateTime.UtcNow - sensor.Time);

            if (sensor.SensorType == SensorType.FileSensor || sensor.SensorType == SensorType.FileSensorBytes)
            {
                //header
                string fileName = GetFileNameString(sensor.StringValue);

                //button
                result.Append($"<button id='{formattedPath}_{name}' class='accordion-button' style='display: none' type='button' data-bs-toggle='collapse'" +
                              $"data-bs-target='#collapse_{formattedPath}_{name}' aria-expanded='true' aria-controls='collapse_{formattedPath}_{name}'>" +
                              "<div>" +
                              $"<div class='row'><div class='col-md-auto'>{sensor.Name}</div>" +
                              $"<div class='col'>{sensor.StringValue}</div></div></div></button></h2>");
                //body
                result.Append($"<div id='collapse_{formattedPath}_{name}' class='accordion-collapse' " +
                              $"aria-labelledby='heading_{formattedPath}_{name}' data-bs-parent='#list_{formattedPath}'>" +
                              "<div class='accordion-body'>");

                result.Append("<div style='width: 100%'>" +
                              "<div class='row justify-content-between'><div class='col-md-auto'>" +
                              $"<li id='status_{formattedPath}_{name}' class='fas fa-circle sensor-icon-with-margin " +
                              $"{ViewHelper.GetStatusHeaderColorClass(sensor.Status)}' title='Status: {sensor.Status}'></li>{sensor.Name}</div>" +
                              $"<div class='col-md-auto time-ago-div' id='update_{formattedPath}_{name}' style='margin-right: 10px'>updated {GetTimeAgo(time)}</div></div>" +
                              $"{sensor.ShortStringValue}</div>" +
                              "<div class='row'><div class='col-md-auto'>" +
                              $"<button id='button_view_{formattedPath}_{name}_{fileName}' " +
                              "class='button-view-file-sensor btn btn-secondary' title='View'>" +
                              "<i class='fas fa-eye'></i></button></div>" +
                              "<div class='col'>" +
                              $"<button id='button_download_{formattedPath}_{name}_{fileName}'" +
                              " class='button-download-file-sensor-value btn btn-secondary'" +
                              " title='Download'><i class='fas fa-file-download'></i></button></div></div>");


                result.Append("</div></div></div>");

                return(result);
            }

            result.Append($"<button id='{formattedPath}_{name}' class='accordion-button collapsed' type='button' data-bs-toggle='collapse'" +
                          $"data-bs-target='#collapse_{formattedPath}_{name}' aria-expanded='false' aria-controls='collapse_{formattedPath}_{name}'>" +
                          "<div style='width: 100%'>" +
                          "<div class='row justify-content-between'>" +
                          $"<div class='col-md-auto'><li id='status_{formattedPath}_{name}' class='fas fa-circle sensor-icon-with-margin " +
                          $"{ViewHelper.GetStatusHeaderColorClass(sensor.Status)}' title='Status: {sensor.Status}'></li>" +
                          $"{sensor.Name}</div><div class='col-md-auto'>" +
                          $"<input id='sensor_type_{formattedPath}_{name}' value='{(int)sensor.SensorType}' style='display: none' />" +
                          $"<div id='update_{formattedPath}_{name}' class='time-ago-div' style='margin-right: 10px'>updated {GetTimeAgo(time)}</div></div></div>" +
                          $"<div id='value_{formattedPath}_{name}'>{sensor.ShortStringValue}</div></div></button></h2>");

            result.Append($"<div id='collapse_{formattedPath}_{name}' class='accordion-collapse collapse'" +
                          $"aria-labelledby='heading_{formattedPath}_{name}' data-bs-parent='#list_{formattedPath}'>" +
                          "<div class='accordion-body'>" +
                          "<div class='mb-3 row'>" +
                          $"<label for='inputCount_{formattedPath}_{name}' class='col-sm-2 col-form-label'>Total Count</label>" +
                          "<div class='col-sm-3'>" +
                          $"<input type='number' class='form-control' id='inputCount_{formattedPath}_{name}' value='10' min='10'></div>" +
                          "<div class='col-sm-1'>" +
                          $"<button id='reload_{formattedPath}_{name}' type='button' class='btn btn-secondary'>" +
                          "<i class='fas fa-redo-alt'></i></button>" +
                          $"<input style='display: none' id='listId_{formattedPath}_{name}' value='{formattedPath}'/></div>");

            result.Append("<div style='margin-top: 15px'>");
            result.Append(isPlottingSupported(sensor.SensorType)
                            ? GetNavTabsForHistory(formattedPath, name)
                            : GetValuesDivForHistory(formattedPath, name));

            result.Append("</div></div></div></div></div>");

            return(result);
        }