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; }
}

MVC 5 Ajax + bootstrap+ handle bar 例: 实现service 状态的更多相关文章

  1. 用最基本的EF+MVC+JQ+AJAX+bootstrap实现权限管理的简单实例 之登陆和操作权限

    先来一堆关于上篇文章的废话(不喜者点此隐藏) 今天把博客加了个小功能,就是点标题可以隐藏或展示相关内容,做法很傻,就是引用了bootstrap的两个css类和全部的js文件,其实这样的小功能完全应该自 ...

  2. MVC遇上bootstrap后的ajax表单模型验证

    MVC遇上bootstrap后的ajax表单验证 使用bootstrap后他由他自带的样式has-error,想要使用它就会比较麻烦,往常使用jqueyr.validate的话只有使用他自己的样式了, ...

  3. 转:MVC遇上bootstrap后的ajax表单验证

    使用bootstrap后他由他自带的样式has-error,想要使用它就会比较麻烦,往常使用jqueyr.validate的话只有使用他自己的样式了,而且有模型在使用模型验证更方便点.怎么解决呢? 当 ...

  4. Asp.Net MVC Unobtrusive Ajax

    1.   Unobtrusive JavaScript介绍 说到Unobtrusive Ajax,就要谈谈UnobtrusiveJavaScript了,所谓Unobtrusive JavaScript ...

  5. Spring Ajax一个简单样例

    配置不说了.要在前面helloworld的样例基础上弄. 相同在hello下新建ajax.jsp <%@ page language="java" contentType=& ...

  6. ASP.NET MVC 学习笔记-7.自定义配置信息 ASP.NET MVC 学习笔记-6.异步控制器 ASP.NET MVC 学习笔记-5.Controller与View的数据传递 ASP.NET MVC 学习笔记-4.ASP.NET MVC中Ajax的应用 ASP.NET MVC 学习笔记-3.面向对象设计原则

    ASP.NET MVC 学习笔记-7.自定义配置信息   ASP.NET程序中的web.config文件中,在appSettings这个配置节中能够保存一些配置,比如, 1 <appSettin ...

  7. MVC使用ajax异步刷新时怎样输出从后台中传过来的JSON数据

    前言 这几天在学习MVC使用AJAX异步刷,因为是新手.所以在js中传参数到后台以及后台返回数据到前台怎么接受,怎么前台遍历出JSON数据都开始不知道,相信新手在使用时跟我一样会遇到,这里我就和大家分 ...

  8. ASP.NET MVC 实现AJAX跨域请求方法《1》

    ASP.NET MVC 实现AJAX跨域请求的两种方法 通常发送AJAX请求都是在本域内完成的,也就是向本域内的某个URL发送请求,完成部分页面的刷新.但有的时候需要向其它域发送AJAX请求,完成数据 ...

  9. asp.net mvc 使用ajax请求 控制器 (PartialViewResult)分部的action,得到一个分部视图(PartialView)的HTML,进行渲染

    在asp.net mvc 使用ajax请求获取数据的时候,我们一般是返回json或者xml,然后解析这些数据进行渲染,这样会比较麻烦,可以请求一个 分部action,返回一个分部视图 直接可以渲染,不 ...

随机推荐

  1. 50 tips of JavaScript

    50 tips of JavaScript,这些坑你都知道吗? 1.在局部作用域中,使用var操作符定义的变量将成为定义该变量的作用域中的局部变量,省略var的会创建全局变量:在全局作用域中,不管是否 ...

  2. Oracle单表的复杂查询

    Oracle单表的复杂查询 select avg(sal),max(sal),deptnofrom empgroupby deptno; orderby deptno; 查询工资高于500或者是岗位为 ...

  3. PV FV PMT

  4. Redis11种Web应用场景

    Redis的一个非常大优点就是能够不用整个转入到这个数据库,而是能够沿用之前的MySQL等数据库,而仅在一些特定的应用场景通过Redis的特性提高效率.本文列出了11个这种Web应用场景,如显示最新的 ...

  5. Good Luck Charlie(听力恢复训练)

    系统的音标学习完毕后.在暑假进入了稍大强度的听力恢复训练.材料选择的是一部家庭情景喜剧片<Good Luck Charlie>,该剧是2010开播的.剧中运用到的大量词汇是和如今比較贴合的 ...

  6. java中final的意义

    1.如果一个数据既是static又是final,那么它会拥有一块无法改变的存储空间. 2.final data: 当final用于基本数据类型时,final让其值(value)保持不变,但是当用于ob ...

  7. app服务器

    http://heipark.iteye.com/blog/1847421http://heipark.iteye.com/blog/1847421http://wenku.baidu.com/vie ...

  8. http协议之cookie标准RFC6265介绍

      [Docs] [txt|pdf] [draft-ietf-httpst...] [Diff1] [Diff2] [Errata] PROPOSED STANDARD Errata Exist In ...

  9. 询问任意区间的min,max,gcd,lcm,sum,xor,or,and

    给我们n个数,然后有m个询问,每个询问为L,R,询问区间[L,R]的最大最小值,最小公约数,最大公约数,和,异或,或,且 这些问题通通可以用RMQ的思想来解决. 以下用xor来作为例子 设dp[i][ ...

  10. 黄聪:Microsoft Enterprise Library 5.0 系列教程(一) : Caching Application Block (初级)

    原文:黄聪:Microsoft Enterprise Library 5.0 系列教程(一) : Caching Application Block (初级) 本篇文章具体官方解释请参照以下链接: h ...