2 * Copyright 2016-2017, CMCC Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 function html_encode(str) {
19 if (str.length == 0)return "";
20 s = str.replace(/&/g, "&"); //1
21 s = s.replace(/</g, "<");
22 s = s.replace(/>/g, ">");
23 s = s.replace(/ /g, " ");
24 s = s.replace(/\'/g, "'");
25 s = s.replace(/\"/g, """);
26 s = s.replace(/\n/g, "<br>");
29 pmUtil.indexOperate = function (obj) {
32 aIndex.id=obj.aData.id;
33 aIndex.name=obj.aData.indexName;
34 aIndex.dataType=obj.aData.indexDataType;
35 aIndex.indexDes=obj.aData.indexDes;
36 aIndex.strExpression=obj.aData.strExpression;
37 aIndex.resourceType=obj.aData.resourceType;
38 aIndex.moType=obj.aData.moType;
39 var index = html_encode(JSON.stringify(aIndex));
40 var indexId = obj.aData.id;
41 var innerHtml = "<div class='table-btn'><span class='modify_user'><a class=\"btn-xs grey btn-editable\" href='#' onclick=\"pmUtil.modifyIndex('"+index+"')\"><i class=\"ict-modify\"></i>" + $.i18n.prop('com_zte_ums_ict_pm_action_modify') +
42 "</a></span><span><a href='#' class=\"btn-xs grey btn-editable\" onclick=\"pmUtil.deleteIndex('" +
43 indexId + "','"+obj.aData.moType.id+"')\"><i class=\"ict-delete\"></i>" + $.i18n.prop('com_zte_ums_ict_pm_action_delete') + "</a></span></div>";
47 pmUtil.dataTypeRender = function (obj) {
48 var record = obj.aData;
49 obj.aData.indexDataType=obj.aData.dataType;
50 var innerHtml = "<span>"+$.i18n.prop(record.dataType)+"</span>"
53 pmUtil.indexNameLink = function (obj) {
54 var index = html_encode(JSON.stringify(obj.aData));
55 obj.aData.indexName=obj.aData.name;
56 return "<a id='indexName' href='#' onclick=\"pmUtil.queryIndex('"+index+"')\">" + obj.aData.name + "</a>";
58 pmUtil.queryIndex=function(index){
60 newIndexWizard(commonUtil.strToJson(index),"query");
61 pm.index.vm.title="查看指标";
62 $(".form-group").attr("disabled",true);
63 pm.index.vm.viewVisible=false;
64 pm.index.vm.rtnVisible=true;
65 pm.index.vm.indexVisible=true;
67 pmUtil.addIndex=function(){
70 pm.index.vm.title="新建指标";
71 pm.index.vm.viewVisible=false;
72 pm.index.vm. indexVisible=true;
74 pmUtil.modifyIndex=function(index){
76 newIndexWizard(commonUtil.strToJson(index));
77 pm.index.vm.title="修改指标";
78 pm.index.vm.viewVisible=false;
79 pm.index.vm.indexVisible=true;
81 pmUtil.deleteIndex=function(indexId,moTypeId){
82 bootbox.confirm($.i18n.prop('com_zte_ums_ict_sm_confirmToDeleteIndex'), function (result) {
91 "url": "/api/umcpm/v1/motype/"+moTypeId+"/indexes",
92 "data" : JSON.stringify(del),
93 "contentType": 'application/json; charset=utf-8',
94 "success": function (res, textStatus, jqXHR) {
95 window.location.href="./indexView.html";
97 "error": function () {
104 pmUtil.idLink = function (obj) {
105 var record = obj.aData;
106 var thresholdId = new String(record.id);
107 return "<a href='#' onclick=\"pm.threshold.vm.queryThreshold('" + thresholdId + "')\">" + thresholdId + "</a>";
110 pmUtil.congfirmDel = function (obj) {
111 bootbox.confirm($.i18n.prop('com_zte_ums_ict_sm_confirmToDeleteThreshold'), function (result) {
113 pm.threshold.vm.deleteThreshold(obj);
118 pmUtil.allOperate = function (obj) {
120 var record = obj.aData;
121 var thresholdId = record.id;
122 //此时的id字段已经被渲染成html片段,如<a href="#" onclick="pm.threshold.vm.queryThreshold('10001')">10001</a>需要提取id
123 thresholdId = thresholdId.substring(thresholdId.indexOf("('") + 2, thresholdId.indexOf("')"));
127 innerHtml = "<div class='table-btn'><span class='modify_user'><a class=\"btn-xs grey btn-editable\" href='#' onclick=\"pm.threshold.vm.modifyThreshold('" +
128 thresholdId + "')\"><i class=\"ict-modify\"></i>" + $.i18n.prop('com_zte_ums_ict_pm_action_modify') +
129 "</a></span><span><a href='#' class=\"btn-xs grey btn-editable\" onclick=\"pmUtil.congfirmDel('" +
130 thresholdId + "')\"><i class=\"ict-delete\"></i>" + $.i18n.prop('com_zte_ums_ict_pm_action_delete') + "</a></span></div>";
136 pmUtil.getUrlParam=function(name){
137 var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
138 var search =decodeURIComponent(location.search.substring(1)); //decodeURIComponent() 函数可对 encodeURIComponent() 函数编码的 URI 进行解码。
139 var r =search.match(reg); //匹配目标参数
140 if (r != null) return unescape(r[2]); //unescape() 函数可对通过 escape() 编码的字符串进行解码。
145 pmUtil.addMeatask = function() {
147 pm.meatask.vm.pageTitle="新建任务";
148 pm.meatask.vm.viewVisible=false;
149 pm.meatask.vm.createMeataskVisible=true;
150 pm.meatask.vm.queryMeataskVisible=false;
153 pmUtil.meataskOperate = function (obj) {
154 var record = obj.aData;
155 var meataskId = record.id;
156 //此时的id字段已经被渲染成html片段,如<a href="#" onclick="pm.threshold.vm.queryThreshold('10001')">10001</a>需要提取id
157 meataskId = meataskId.substring(meataskId.indexOf("('") + 2, meataskId.indexOf("')"));
163 "<div class=\"table-btn\">",
164 "<span class=\"modify_user\">",
165 "<a class=\"btn-xs grey btn-editable\" href=\"#\" onclick=\"pmUtil.queryMeatask('" + meataskId +
166 "')\"><i class=\"ict-Magnifier\"></i>",
167 $.i18n.prop('com_zte_ums_ict_pm_action_query'),
170 "<span class=\"modify_user\">",
171 "<a class=\"btn-xs grey btn-editable\" href=\"#\" onclick=\"pmUtil.modifyMeatask('" + meataskId + "'," + obj.iDataRow +
172 ")\"><i class=\"ict-modify\"></i>",
173 $.i18n.prop('com_zte_ums_ict_pm_action_modify'),
177 "<a href=\"#\" class=\"btn-xs grey btn-editable\" onclick=\"pmUtil.deleteMeatask('" + meataskId + "'," + obj.iDataRow +
178 ")\"><i class=\"ict-delete\"></i>",
179 $.i18n.prop('com_zte_ums_ict_pm_action_delete'),
187 pmUtil.getActiveStatus = function(obj) {
188 var meataskId = obj.aData.id;
189 meataskId = meataskId.substring(meataskId.indexOf("('") + 2, meataskId.indexOf("')"));
190 var activeStatus = obj.aData.activeStatus;
194 if(activeStatus == 0){
195 prefixStr = "<a href='#' class=\"label label-sm label-danger\" onclick=\"pm.meatask.vm.changeActiveStatus('";
196 suffixStr = ")\">暂停</a>";
198 prefixStr = "<a href='#' class=\"label label-sm label-info\" onclick = \"pm.meatask.vm.changeActiveStatus('";
199 suffixStr = ")\">激活</a>";
202 var innerHtml = prefixStr + meataskId + "'," + activeStatus + "," + obj.iDataRow + suffixStr;
207 pmUtil.granularityRender = function(obj) {
208 var data = obj.aData;
209 switch(data.granularity){
220 pmUtil.queryMeatask = function(meataskId) {
221 queryMeataskWizard("queryID");
222 pm.meatask.vm.pageTitle="查询任务";
223 pm.meatask.vm.viewVisible=false;
224 pm.meatask.vm.createMeataskVisible=false;
225 pm.meatask.vm.queryMeataskVisible=true;
227 $("#queryMeataskSubmit").click(function() {
228 pm.meatask.vm.$showResultTable();
232 pmUtil.meataskIdLink = function(obj) {
233 var meatskId = obj.aData.id;
234 return "<a href='#' onclick=\"pmUtil.viewMeataskById('" + meatskId + "')\">" + meatskId + "</a>";
237 pmUtil.viewMeataskById = function(meatskId) {
238 newMeataskWizard(meatskId);
239 pm.meatask.vm.pageTitle="查看任务";
240 pm.meatask.vm.viewVisible=false;
241 pm.meatask.vm.createMeataskVisible=true;
242 pm.meatask.vm.queryMeataskVisible=false;
245 pmUtil.timeRender = function( obj ){
246 var time=obj.aData[obj.mDataProp];
248 var date = new Date(obj.aData[obj.mDataProp]);
249 return commonUtil.parseDate(date , 'yyyy-MM-dd hh:mm:ss');
253 pmUtil.deleteMeatask=function(meataskId, row){
254 bootbox.confirm("确认删除此任务吗?", function (result) {
256 $("#ict_meatask_table_div tr:eq("+(row+1)+")").attr('style', 'display:none;');
261 pmUtil.modifyMeatask = function(meataskId, row) {
262 modifyMeataskWizard("modifyID");
263 pm.meatask.vm.pageTitle="修改任务";
264 pm.meatask.vm.viewVisible=false;
265 pm.meatask.vm.createMeataskVisible=true;
266 pm.meatask.vm.queryMeataskVisible=false;
269 pmUtil.randomCPU = function() {
270 var percent = Math.random()*100;
271 percent = Math.round(percent);
272 return percent + "%";
275 pmUtil.calculateTime = function(obj) {
276 var data = obj.aData;
277 var time = data.beginTime + data.granularity;
280 var date = new Date(data.granularity * 1000 + obj.aData[obj.mDataProp]);
281 return commonUtil.parseDate(date , 'yyyy-MM-dd hh:mm:ss');
285 pmUtil.queryMeatask = function(meataskId) {
286 pm.meatask.vm.pageTitle="查询任务";
287 pm.meatask.vm.viewVisible=false;
288 pm.meatask.vm.createMeataskVisible=false;
289 pm.meatask.vm.queryMeataskVisible=true;
292 pmUtil.setDateRange = function (dataRangeId, vm) {
296 //var month = $.i18n.prop('ngict-iui-dateRange-month');
300 //startDate: moment().subtract(179, 'days'),
304 startDate : "2015-12-31",
306 endDate : "2016-2017-12-31",
308 //format: 'YYYY-MM-DD',
309 format : 'YYYY-MM-DD h:mm A',
315 showWeekNumbers : false,
318 timePickerIncrement : 5,
326 applyLabel : $.i18n.prop('ngict-iui-dateRange-applyLabel'),
328 cancelLabel : $.i18n.prop('ngict-iui-dateRange-cancelLabel'),
330 fromLabel : $.i18n.prop('ngict-iui-dateRange-fromLabel'),
332 toLabel : $.i18n.prop('ngict-iui-dateRange-toLabel'),
334 customRangeLabel : $.i18n.prop('ngict-iui-dateRange-customRangeLabel'),
338 $.i18n.prop('ngict-iui-dateRange-Sunday'),
340 $.i18n.prop('ngict-iui-dateRange-Monday'),
342 $.i18n.prop('ngict-iui-dateRange-Tuesday'),
344 $.i18n.prop('ngict-iui-dateRange-Wednesday'),
346 $.i18n.prop('ngict-iui-dateRange-Thursday'),
348 $.i18n.prop('ngict-iui-dateRange-Friday'),
350 $.i18n.prop('ngict-iui-dateRange-Saturday')],
352 //monthNames : ['1' + month, '2' + month, '3' + month, '4' + month, '5' + month, '6' + month, '7' + month, '8' + month, '9' + month, '10' + month, '11' + month, '12' + month],
354 //months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
356 monthNames: [$.i18n.prop('ngict-iui-dateRange-Jan'),
357 $.i18n.prop('ngict-iui-dateRange-Feb'),
358 $.i18n.prop('ngict-iui-dateRange-Mar'),
359 $.i18n.prop('ngict-iui-dateRange-Apr'),
360 $.i18n.prop('ngict-iui-dateRange-May'),
361 $.i18n.prop('ngict-iui-dateRange-Jun'),
362 $.i18n.prop('ngict-iui-dateRange-Jul'),
363 $.i18n.prop('ngict-iui-dateRange-Aug'),
364 $.i18n.prop('ngict-iui-dateRange-Sep'),
365 $.i18n.prop('ngict-iui-dateRange-Oct'),
366 $.i18n.prop('ngict-iui-dateRange-Nov'),
367 $.i18n.prop('ngict-iui-dateRange-Dec')],
376 $('input[id="' + dataRangeId + '"]').bind('apply.daterangepicker', function () {
382 pmUtil.setTime($(this));
385 //$(this).attr("data-original-title", $(this).val());
389 $('input[id="' + dataRangeId + '"]').daterangepicker(optionSet1);
393 //daterangepicker设置时间
394 pmUtil.setTime = function setTime($obj) {
396 //var title = $obj.attr('dtitle');
398 var arr = $obj.val().split(' - ');
404 var beginTime = new Date(arr[0].replace(/-/g, "/")).getTime();
406 var endTime = new Date(arr[1].replace(/-/g, "/")).getTime();
408 pm.query.vmPmQuery.beginTime = beginTime;
410 pm.query.vmPmQuery.endTime = endTime;
416 pmUtil.formatTime = function formatTime(ms) {
417 var date = new Date(ms);
418 return date.format("yyyy-MM-dd hh:mm:ss");
423 Date.prototype.format = function (format) {
427 * format="yyyy-MM-dd hh:mm:ss";
433 "M+" : this.getMonth() + 1,
435 "d+" : this.getDate(),
437 "h+" : this.getHours(),
439 "m+" : this.getMinutes(),
441 "s+" : this.getSeconds(),
443 "q+" : Math.floor((this.getMonth() + 3) / 3),
445 "S" : this.getMilliseconds()
449 if (/(y+)/.test(format)) {
451 format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4
453 - RegExp.$1.length));
459 if (new RegExp("(" + k + ")").test(format)) {
461 format = format.replace(RegExp.$1, RegExp.$1.length == 1
465 : ("00" + o[k]).substr(("" + o[k]).length));