-
Notifications
You must be signed in to change notification settings - Fork 13
/
bda.scheduler.js
executable file
·133 lines (109 loc) · 3.71 KB
/
bda.scheduler.js
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
jQuery(document).ready(function() {
"use strict";
(function($) {
var BDA_SCHEDULER = {
initialized: false,
SCHEDULED_JOBS_SELECTOR: 'h2:contains("Scheduled jobs")',
isSchedulerPage: function() {
return $(BDA_SCHEDULER.SCHEDULED_JOBS_SELECTOR).length > 0;
},
init: function() {
console.time("bdaScheduler");
var $title = $(BDA_SCHEDULER.SCHEDULED_JOBS_SELECTOR);
BDA_SCHEDULER.$table = $title.next().children('table:first');
var $container = $('<div id="timeline-wrapper"></div>');
$container.append($('<button>Show Timeline</button>').on('click', function() {
if (!BDA_SCHEDULER.initialized) {
BDA_SCHEDULER.build();
}
BDA_SCHEDULER.$timeline.slideToggle();
}));
BDA_SCHEDULER.$timeline = $('<div id="timeline" style="display:none;"></div>');
$container.append(BDA_SCHEDULER.$timeline);
$title.after($container);
BDA_SCHEDULER.$table.addClass("tablesorter")
.removeAttr("border")
.removeAttr("cellpadding").prepend("<thead class='thead' />");
// Put first tr into a thead tag
BDA_SCHEDULER.$table.find("tr:eq(0)").appendTo(".thead");
// Replace td by th
$('.thead td').each(function() {
var $this = $(this);
$this.replaceWith('<th class="' + this.className + '">' + $this.text() + '</th>');
});
BDA_SCHEDULER.$table.tablesorter({
'theme': 'blue',
'widgets': ["zebra"],
'widgetOptions': {
zebra: ["normal-row", "alt-row"]
}
});
console.timeEnd("bdaScheduler");
},
build: function() {
BDA_SCHEDULER.initialized = true;
var $tr, $tdList, dst, dateString;
var dataArray = [];
//extract the data
BDA_SCHEDULER.$table.find('tr').each(function(idx, child) {
//after header and 1 blank row
$tr = $(child);
$tdList = $tr.find('td');
if (idx > 1 && $tdList.length > 0) {
dst = $tdList.eq(7).text();
//next
dateString = $tdList.eq(4).text();
if (!isNull(dst) && dateString != "not yet run") {
dataArray.push({
id: 'n' + idx,
content: dst,
start: Date(dateString)
});
}
//previous
dateString = $tdList.eq(3).text();
if (!isNull(dst) && dateString != "not yet run") {
dataArray.push({
id: 'p' + idx,
content: dst,
start: Date(dateString)
});
}
}
});
// DOM element where the Timeline will be attached
var container = document.getElementById('timeline');
// Create a DataSet (allows two way data-binding)
var items = new vis.DataSet(dataArray);
// Configuration for the Timeline
var now = Date.now();
var options = {
height: '80%',
moment: function(date) {
return vis.moment(date).utc();
},
type: 'point',
selectable: false,
clickToUse: true,
orientation: {
axis: 'both'
},
start: now - 1000 * 3600,
end: now + 1000 * 3600 * 12,
dataAttributes: 'all'
};
// Create a Timeline
var timeline = new vis.Timeline(container, items, options);
},
};
// Reference to BDA
var BDA;
// Jquery plugin creation
$.fn.bdaScheduler = function() {
//init here
if (BDA_SCHEDULER.isSchedulerPage()) {
BDA_SCHEDULER.init();
}
};
})(jQuery);
});