MVC 5 Ajax + bootstrap+ handle bar 例: 实现service 状态
2024-08-24 02:03:41
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; }
}
最新文章
- ZOJ 3699 Dakar Rally
- poj1988_Cube Stacking
- C语言标准定义的32个关键字
- Keepalived安装配置
- 用jstl截取字符串
- UVA-10652 (凸包)
- IIC,RS485,RS232各种协议手册更新中
- jQuery选择器大全(48个代码片段+21幅图演示)
- (转)Mysql数据库读写分离配置
- 查看db2表空间使用率
- 【面试】足够应付面试的Spring事务源码阅读梳理(建议珍藏)
- jQuery入门基础(动画效果)
- 存根类(stub) 是什么意思?有什么作用?(转)
- CentOS7下安装NVIDIA独立显卡驱动出现X service error问题解决方法
- JS省市区联动效果
- 怎么部署 .NET Core Web项目 到linux
- 如何安全的下载Devcon.exe文件
- Python3.x(windows系统)安装requests库
- .Net Core + DDD基础分层 + 项目基本框架 + 个人总结
- Qt编译目录下exe文件执行报错问题的解决办法
热门文章
- SQLServer 复制中移除和加入公布而不初始化全部项目
- Android开发系列(二十二):AdapterViewFlipper的功能和使用方法
- solr4.9r+ Eclipse 4.3+ tomcat 7.5 +winds7(二)
- CSDN博客的一些问题(友好的吐槽)--后记,有一点点改进
- delphi 发送消息控制滚动条
- Learning Cocos2d-x for WP8(9)——Sprite到哪,我做主
- MVC的DependencyResolver组件
- Uva11464 开关问题
- python之字符串的分割和拼接
- It&#39;s only too late if you decide it is. Get busy living, or get busy dying(转)