MVC 5 Ajax + bootstrap+ handle bar 例: 實現service 狀態,mvcbootstrap

來源:互聯網
上載者:User

MVC 5 Ajax + bootstrap+ handle bar 例: 實現service 狀態,mvcbootstrap
Js Script 


<script src="../../Scripts/handlebars-v1.3.0.js"></script> <script id="service-status-details-template" type="text/x-handlebars-template">        {{#each values}}        <div class="top-buffer-10">            <div class="pull-left">{{ServiceName}}</div>            <span style="margin-left: 15px;"> </span>            <div class="pull-right">                <span class="service-details-time">{{TimeDurationAgo}} AGO</span>                {{#if IsUp}}                <span class="glyphicon glyphicon-ok-sign" style="color: #5cb85c;"></span>                {{else}}                <span class="glyphicon glyphicon-exclamation-sign" style="color: #ff4f28;"></span>                {{/if}}            </div>        </div>        {{/each}}    </script>    <div style="z-index: 10;display: none;" id="service-status-details">    </div>    <a id="service-status" style="margin-left: 30%;" data-placement="bottom" href="#"></a>    <script>        var serviceStatusUrl = '@Url.Action("GetMonitoringServicesStatus")';        $(document).ready(function () {            $("#service-status").popover(            {                html: true,                content: function () {                    return $('#service-status-details').html();                }            });            refreshServiceStatus();            //window.setInterval(refreshServiceStatus, 5 * 60 * 1000 /*frequency set to 5 mins*/);        });        function refreshServiceStatus() { /*should be change to set interval*/            $.ajax({                type: 'POST',                url: serviceStatusUrl, /*this value is set in _monitoringServices.cshtml */                success: function (data) {                    applyToJsTemplate("service-status-details", "service-status-details-template", data);                    if (!data.isOk) {                        $("#service-status").attr("class", "btn glyphicon glyphicon-exclamation-sign");                        $("#service-status").css("color", "#ff4f28");                    } else {                        $("#service-status").attr("class", "btn glyphicon glyphicon-ok-sign");                        $("#service-status").css("color", "#5cb85c");                    }                },                dataType: "json"            });        }        function applyToJsTemplate(layoutId, templateId, data) {            $("#" + layoutId).html(Handlebars.compile($("#" + templateId).html())(data));        }    </script>



Css 


<style>        .popover-content {        background-color: #dadada;    }    .service-details-time {        color: #adadad;    }    .service-details-name {        color: #5d5d5d;    }    .popover {        max-width: 100%;    }    </style>



C# 


  public JsonResult GetMonitoringServicesStatus()        {            if (DateTime.Now.Second % 2 == 0)            {                var serviceList = Builder<MonitoringServicesModel>.CreateListOfSize(5)                    .TheFirst(1).With(m => m.ServiceName, "Active Directory").With(m => m.IsUp, false).With(m => m.TimeDurationAgo, "11 MINS")                    .TheNext(1).With(m => m.ServiceName, "aZure.Microsoft.com").With(m => m.IsUp, true).With(m => m.TimeDurationAgo, "5 MINS")                    .TheNext(1).With(m => m.ServiceName, "aZure Preview Portal").With(m => m.IsUp, false).With(m => m.TimeDurationAgo, "16 MINS")                    .TheNext(1).With(m => m.ServiceName, "Management Portal").With(m => m.IsUp, false).With(m => m.TimeDurationAgo, "31 MINS")                    .TheNext(1).With(m => m.ServiceName, "Network Infrastructure").With(m => m.IsUp, true).With(m => m.TimeDurationAgo, "1 MINS")                    .Build();                var allUp = serviceList.All(s => s.IsUp);                return Json(new { isOk = allUp, values = serviceList }, JsonRequestBehavior.AllowGet);            }            else            {                var serviceList = Builder<MonitoringServicesModel>.CreateListOfSize(5)                   .TheFirst(1).With(m => m.ServiceName, "Active Directory").With(m => m.IsUp, true).With(m => m.TimeDurationAgo, "1 MINS")                   .TheNext(1).With(m => m.ServiceName, "aZure.Microsoft.com").With(m => m.IsUp, true).With(m => m.TimeDurationAgo, "26 MINS")                   .TheNext(1).With(m => m.ServiceName, "aZure Preview Portal").With(m => m.IsUp, true).With(m => m.TimeDurationAgo, "16 MINS")                   .TheNext(1).With(m => m.ServiceName, "Management Portal").With(m => m.IsUp, true).With(m => m.TimeDurationAgo, "5 SECONDS")                   .TheNext(1).With(m => m.ServiceName, "Network Infrastructure").With(m => m.IsUp, true).With(m => m.TimeDurationAgo, "1 MINS")                   .Build();                var allUp = serviceList.All(s => s.IsUp);                return Json(new { isOk = allUp, values = serviceList }, JsonRequestBehavior.AllowGet);            }        }  public class MonitoringServicesModel    {        public string ServiceName { get; set; }        public string TimeDurationAgo { get; set; }        public bool IsUp { get; set; }    }




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.