1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
|
var DashboardICT = function () {
var chartObjs;
var plotsSelected;
var plotControlCallbacks = {};
var plotControlHtmlFrags = {};
var addDroppableItem = function () {
$(".column.sortable").droppable({
accept: ".draggableItems",
drop: function (event, ui) {
//var dropLocation = $( ".plotsWrapper" );
var plotTypeId = $(ui.draggable).attr("id");
/* if($("#" + chartObjs[plotTypeId].placeholderId).length >0){
alert("Plot already exits!");
return;
} */
addDraggablePortlet(this, plotTypeId);
}
});
}
var addDraggablePortlet = function (droppableItem, plotTypeId) {
if (!chartObjs[plotTypeId].chartType || chartObjs[plotTypeId].chartType != "prototype") {
$("div#" + plotTypeId).remove();
}
var portletId = chartObjs[plotTypeId].typeId;
var portletLabel = chartObjs[plotTypeId].plotLabel;
var placeholderId = chartObjs[plotTypeId].placeholderId;
if ($("div[id^=" + placeholderId + "]").length > 0) {
var placeholderIdCount = $("div[id^=" + placeholderId + "]").length;
placeholderId = placeholderId + "_" + placeholderIdCount;
}
var plotCallback = eval(chartObjs[plotTypeId].plotCallbackName);
var plotSize = "size11";
if (chartObjs[plotTypeId].plotSize) {
plotSize = chartObjs[plotTypeId].plotSize;
}
plotSize = "";
var faceboxDivIndex = $("a[rel=facebox]").length + 1;
var portletHtml = '<div id="' + portletId + '" class="portlet portlet-sortable light bg-inverse ' + plotSize + '" style="position: relative;">' +
'<div class="portletLabel">' + portletLabel + '</div>' +
'<a href="#faceboxDiv_' + faceboxDivIndex + '" rel="facebox" class="expandLink"><img src="/ngict/iui/component/ict/ict-dashboard/images/zoom.png" /></a>' +
'<div class="removeflot"></div>' +
//'<a href="#faceboxDiv_' + faceboxDivIndex + '" rel="facebox">' +
'<div id="faceboxDiv_' + faceboxDivIndex + '" flot_id="' + placeholderId + '" class="flot-placeholder-wrapper-portlet">' +
'<div id="' + placeholderId + '" class="flot-placeholder"></div>' +
'</div>' +
//'</a>' +
'</div>';
if (chartObjs[plotTypeId].plotControlCallback) {
portletHtml = '<div id="' + portletId + '" class="portlet portlet-sortable light bg-inverse ' + plotSize + '" style="position: relative;">' +
'<div class="portletLabel">' + portletLabel + '</div>' +
'<div class="removeflot"></div>' +
plotControlHtmlFrags[plotTypeId] +
//'<a href="#faceboxDiv_' + faceboxDivIndex + '" rel="facebox">' +
'<div id="faceboxDiv_' + faceboxDivIndex + '" flot_id="' + placeholderId + '" class="flot-placeholder-wrapper-portlet">' +
'<div id="' + placeholderId + '" class="flot-placeholder flot-placeholder-high"></div>' +
'</div>' +
//'</a>' +
'</div>';
}
if (chartObjs[plotTypeId].htmlSrc) {
portletHtml = '<div id="' + portletId + '" class="portlet portlet-sortable light bg-inverse ' + plotSize + '" style="position: relative;">' +
'<div class="portletLabel">' + portletLabel + '</div>' +
'<a href="#faceboxDiv_' + faceboxDivIndex + '" rel="facebox" class="expandLink"><img src="/ngict/iui/component/ict/ict-dashboard/images/zoom.png" /></a>' +
'<div class="removeflot"></div>' +
'<div id="htmlFrag" ></div>' +
/* '<div ms-include-src="' + chartObjs[plotTypeId].htmlSrc + '"></div>' + */
//'<a href="#faceboxDiv_' + faceboxDivIndex + '" rel="facebox">' +
'<div id="faceboxDiv_' + faceboxDivIndex + '" flot_id="' + placeholderId + '" class="flot-placeholder-wrapper-portlet">' +
'<div id="' + placeholderId + '" class="flot-placeholder flot-placeholder-high"></div>' +
'</div>' +
//'</a>' +
'</div>';
}
//插入图例
//$(droppableItem).before(portletHtml);
$(droppableItem).prepend(portletHtml);
//$( ".plotsWrapper" ).append(portletHtml);
if (chartObjs[plotTypeId].htmlSrc) {
$.ajax({
async: false,
"dataType": "html",
"type": "GET",
"url": chartObjs[plotTypeId].htmlSrc,
"data": null,
"success": function (html, textStatus, jqXHR) {
$("div#htmlFrag").html(html);
},
"error": function () {
alert("Communication error!");
}
});
}
//添加图例控制回调
if (chartObjs[plotTypeId].plotControlCallback) {
plotControlCallbacks[plotTypeId](plotCallback, placeholderId);
}
var args = [placeholderId];
if (chartObjs[plotTypeId].arguments) {
var argsArray = chartObjs[plotTypeId].arguments.split(",");
args = args.concat(argsArray);
}
//plotCallback(placeholderId);
plotCallback.apply(null, args);
$.facebox.flotRedrawCallbackObjs[placeholderId] = {
callback: plotCallback,
arguments: args
}
//调整放大后的宽度
var portlet = $("#" + portletId + ".portlet");
if ($(portlet).parent().hasClass("col-md-6")) {
$("div.flot-placeholder-wrapper-portlet", portlet).addClass("flot-placeholder-wrapper-portlet-wide");
} else {
$("div.flot-placeholder-wrapper-portlet", portlet).removeClass("flot-placeholder-wrapper-portlet-wide");
}
//添加点击范围
/* var graphToExpand = $("div#" + placeholderId + " > svg > g")[0];
$(graphToExpand).attr("id", "graphToExpand_" + placeholderId);
var gNode = d3.select("g#graphToExpand_" + placeholderId);
gNode.attr("href", "#faceboxDiv_" + faceboxDivIndex);
gNode.attr("rel", "facebox"); */
$.facebox.settings.closeImage = '/web/newict/framework/thirdparty/facebox/closelabel.png';
$.facebox.settings.loadingImage = '/web/newict/framework/thirdparty/facebox/loading.gif';
$('a[rel*=facebox]').facebox();
addDroppableItem();
}
var restoreDragItems = function (chartId) {
if (!chartObjs[chartId].chartType || chartObjs[chartId].chartType != "prototype") {
var plotItemsSelectionDiv = $(".plotItemsSelectionWrapper");
if ($("div#" + chartId, plotItemsSelectionDiv).length == 0) {
var chartSelectHtml =
'<div id="' + chartObjs[chartId].typeId + '" class="draggableItems">' +
'<img width="100%" height="100%" src="' + chartObjs[chartId].imageURL + '">' +
'<div class="dragItemLabel">' + chartObjs[chartId].plotLabel + '</div>' +
'</div>';
$(plotItemsSelectionDiv).append(chartSelectHtml);
$(".draggableItems").draggable({
//containment:"body",
revert: false,
appendTo: "div.plotsWrapper",
scroll: false,
zIndex: 9999,
helper: "clone",
opacity: 0.75
});
}
}
}
var jsonTransformFromBackend = function (json) {
var charts = json;
var obj = {};
obj.chartTypes = {};
for (var i = 0; i < charts.length; i++) {
obj.chartTypes[charts[i].id] = charts[i];
obj.chartTypes[charts[i].id].typeId = charts[i].id;
}
//obj.initPlots = ["ictCPULineC3", "currentAlarm"];
return obj;
}
function sleep(numberMillis) {
var now = new Date();
var exitTime = now.getTime() + numberMillis;
while (true) {
now = new Date();
if (now.getTime() > exitTime)
return;
}
}
return {
init: function (restPath, dashboardDivId, dashboardHtmlPath) {
if (dashboardDivId && dashboardHtmlPath) {
$.ajax({
async: false,
"dataType": "html",
"type": "GET",
"url": dashboardHtmlPath,
"data": null,
"success": function (html, textStatus, jqXHR) {
$('div#' + dashboardDivId).html(html);
},
"error": function () {
alert("Communication error!");
}
});
}
//sleep(500);
$.ajax({
async: false,
"type": "GET",
url: "/ngict/rest/dashboard/charts",
dataType: "json",
"success": function (res, textStatus, jqXHR) {
res = jsonTransformFromBackend(res);
var plotItemsSelectionDiv = $(".plotItemsSelectionWrapper");
//初始化左边的图列类型列表
chartObjs = res.chartTypes;
var chartSelectHtml = "";
for (var chartObj in chartObjs) {
chartSelectHtml =
'<div id="' + chartObjs[chartObj].typeId + '" class="draggableItems">' +
'<img width="100%" height="100%" src="' + chartObjs[chartObj].imageURL + '">' +
'<div class="dragItemLabel">' + chartObjs[chartObj].plotLabel + '</div>' +
'</div>';
$(plotItemsSelectionDiv).append(chartSelectHtml);
}
//初始化已选图例
//plotsSelected = res.initPlots;
},
"error": function () {
alert("Config file load error!");
}
});
PortletDraggable.init();
//Portlet
$(".draggableItems").draggable({
//containment:"body",
revert: false,
appendTo: "div.plotsWrapper",
scroll: false,
zIndex: 9999,
helper: "clone",
opacity: 0.75
});
$("#deleteIcon").droppable({
accept: ".portlet",
drop: function () {
if ($("#deleteIcon .top").hasClass("deleteIconHidden")) {
//$( "#droppableItem" ).removeClass("droppedOver");
var portletRemoveId = $(".ui-sortable-helper").attr("id");
if (portletRemoveId != "droppable") {
$("#" + portletRemoveId).remove();
restoreDragItems(portletRemoveId);
}
}
},
tolerance: "touch",
over: function (event, ui) {
//$( "#droppableItem" ).addClass("droppedOver");
}
});
addDroppableItem();
$(".sidebar-toggler").click(function () {
$("#cf5 img.top").toggleClass("scale");
$("#cf5 img.bottom").toggleClass("rotate");
$(".plotsWrapper").toggleClass("dashboardExpand", 300, "linear");
$(".plotItemsSelectionWrapper").toggleClass("sideBarClose", 300, "linear");
setTimeout(function () {
var charts = $.facebox.charts;
for (var chart in charts) {
charts[chart].resize();
}
DashboardICT.removeYaxisScale();
}, 300);
});
$('.plotItemsSelectionWrapper').slimScroll({
position: 'right',
distance: '-2px',
//width: '177px',
width: '158px',
//height:'630px',
//color:'rgb(100, 150, 240)',
color: "#F1F3FA",
//railColor: '#fff',
//railOpacity: 0.3,
railOpacity: 0,
railVisible: true,
allowPageScroll: true
});
$('.slimScrollDiv').css({
'float': 'left',
'margin-right': '-100%',
//'margin-top': '10px',
//'padding-left': '5px'
});
$("#deleteIcon").click(function () {
if ($("#deleteIcon .bottom").hasClass("deleteIconHidden")) {
$("#deleteIcon .top").addClass("deleteIconHidden", 500);
$("#deleteIcon .bottom").removeClass("deleteIconHidden", 500);
//添加删除小图标
$(".removeflot").addClass("removeIcon");
$(".removeflot.removeIcon").click(function () {
var placeholderId = $(".flot-placeholder", $(this).parent()).attr("id");
if ($.facebox.intervals[placeholderId]) {
clearInterval($.facebox.intervals[placeholderId]);
}
$(this).parent().remove();
if ($(".flot-placeholder").length == 0) {
$("#deleteIcon").click();
}
//恢复左侧列表
var chartId = $(this).parent().attr("id");
restoreDragItems(chartId);
});
} else {
$("#deleteIcon .top").removeClass("deleteIconHidden", 500);
$("#deleteIcon .bottom").addClass("deleteIconHidden", 500);
//去掉删除小图标
$(".removeflot.removeIcon").removeClass("removeIcon");
}
});
/*
$(window).unload(function(){
var savedPlots = DashboardICT.saveSelectedPlots();
//alert("Goodbye!" + savedPlots);
});
if ($.cookie && $.cookie('dashboard_selected')){
plotsSelected = $.cookie('dashboard_selected').split(",");
}
*/
$.ajax({
async: false,
"type": "GET",
url: "/ngict/rest/dashboard/initcharts",
dataType: "json",
"success": function (res, textStatus, jqXHR) {
//初始化已选图例
plotsSelected = res;
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus);
}
});
//初始化已选图例
if (plotsSelected && plotsSelected.length > 0) {
for (var i = 0; i < plotsSelected.length; i++) {
/* var portlets = $(".portlet-sortable");
var maxIndex = portlets.length -1;
addDraggablePortlet(portlets[maxIndex], plotsSelected[i]); */
addDraggablePortlet($(".column.sortable")[i % 3], plotsSelected[i]);
}
}
//$( ".sidebar-toggler" ).click();
$("#cf5 img.top").addClass("scale");
$("#cf5 img.bottom").addClass("rotate");
$(".plotsWrapper").addClass("dashboardExpand");
$(".plotItemsSelectionWrapper").addClass("sideBarClose");
$('.slimScrollBar').hide();
window.onresize = function () {
DashboardICT.removeYaxisScale();
}
},
saveSelectedPlots: function () {
var placeholders = [];
var plots = $(".flot-placeholder");
$.each(plots, function (index, plot) {
placeholders.push($(plot).attr('id'));
});
plotsSelected = [];
for (var chartObj in chartObjs) {
if (jQuery.inArray(chartObjs[chartObj].placeholderId, placeholders) > -1) {
plotsSelected.push(chartObj);
}
}
if ($.cookie) {
$.cookie('dashboard_selected', plotsSelected);
}
return plotsSelected;
},
addPlotControlCallbacks: function (plotId, callback) {
plotControlCallbacks[plotId] = callback;
},
addPlotControlHtmlFrags: function (plotId, htmlFrag) {
plotControlHtmlFrags[plotId] = htmlFrag;
},
graphChangeToExpand: function (placeholderId) {
var graphToExpand = $("div#" + placeholderId + " > svg > g")[0];
$(graphToExpand).attr("id", "graphToExpand_" + placeholderId);
var faceboxDivId = $($("div[flot_id=" + placeholderId + "]")[0]).attr("id");
var gNode = d3.select("g#graphToExpand_" + placeholderId);
gNode.attr("href", "#" + faceboxDivId);
gNode.attr("rel", "facebox");
$('g[rel*=facebox]').facebox();
},
setGraphChangeToExpand: function (placeholderId, callbackObj) {
$.facebox.flotRedrawCallbackObjs[placeholderId] = callbackObj;
},
registerChartsToReDraw: function (placeholderId, chartObj) {
$.facebox.charts[placeholderId] = chartObj;
},
registerIntervalsToClear: function (placeholderId, intervalId) {
$.facebox.intervals[placeholderId] = intervalId;
},
graphIsExpanded: function (placeholderId) {
return $.facebox.isExpand(placeholderId);
},
removeYaxisScale: function () {
var lines = d3.selectAll(".c3-axis.c3-axis-y").selectAll(".tick line");
$(lines).each(function () {
$(this).attr("x2", "0");
});
}
}
}();
|