( dom)
lookupCache allready
updatedom - , , , .
, .
Dom - , , dom , () : D, ...
, , . (var OverSpeedAlerts ..), . :
1. ,
2.
3. ( )
, , . ( dom tho), .
var io , pushServer, alertTypes, alterTypesMapping, $notifications, lookupCache;
alertTypes = {
OverSpeedAlerts: [],
OverSpeedAlertsLength: 0,
TripCancellation: [],
TripCancellationLength: 0,
GeofenceInOutAlerts: [],
GeofenceInOutAlertsLength: 0,
ScheduleOverstay: [],
ScheduleOverstayLength: 0,
UnSchduledOverstay: [],
UnSchduledOverstayLength: 0,
SkippedBusStop: [],
SkippedBusStopLength: 0,
TripDelayAlert: [],
TripDelayAlertLength: 0,
SkippedUnplannedAlert: [],
SkippedUnplannedAlertLength: 0,
DelayStartEndAlert: [],
DelayStartEndAlertLength: 0,
RouteDeviatedAlert: [],
RouteDeviatedAlertLength: 0
};
alterTypesMapping = {
'overspeed': 'OverSpeedAlerts',
'trip_cancellation': 'TripCancellation',
'Geofence-In': 'GeofenceInOutAlerts',
'Geofence-Out': 'GeofenceInOutAlerts',
'Scheduled-Overstay': 'ScheduleOverstay',
'Unscheduled-Overstay': 'UnSchduledOverstay',
'Skipped Unplanned': 'SkippedBusStop',
'Delay Start': 'TripDelayAlert',
'Delay End': 'TripDelayAlert',
'Route Deviated': 'RouteDeviatedAlert',
'Multiple Bus Entry': 'MultipleBusEntry'
};
$notifications = $('#notifications');
lookupCache = {};
function process_data (data) {
var i, l, rows, id;
rows = data.message;
l = rows.length;
$notification.html(l);
for (i=0; i<l; ++i) {
id = rows[i].alert_type + '|' + rows[i].device_id + '|' + rows[i].alert_gen_date_time;
if (!lookupCache[id]) {
lookupCache[id] = 1;
alertTypes[alterTypesMapping[rows[i].alert_type]].push(rows[i]);
}
}
updateDom();
}
function updateDom () {
var keys, i, l, html;
keys = Object.keys(alertTypes);
for (i=0, l=keys.length; i<l; ++i) {
if (keys[i].match('Length')) {
continue;
}
$('#tabs ul a[data-type="' + keys[i] + '"]').html(keys[i] + '(' + alertTypes[keys[i] + 'Length'] + ')');
html = [];
for (j=alertTypes[keys[i]].length, m=alertTypes[keys[i] + 'Length']; j>m; --j) {
html.push([
'<tr>',
'<td>',
alertTypes[keys[i]].depot_name,
'</td>',
'<td>',
alertTypes[keys[i]].route_name,
'</td>',
'<td>',
alertTypes[keys[i]].schedule_no,
'</td>',
'<td>',
alertTypes[keys[i]].trip_number,
'</td>',
'<td>',
alertTypes[keys[i]].trip_direction,
'</td>',
'<td>',
alertTypes[keys[i]].alert_sub,
'</td>',
'<td ',
'title="',
ConvertToValidTooltip(alertTypes[keys[i]].alert_msg),
'" style="text-decoration:underline;cursor:pointer;">Place mouse pointer to view message',
'</td>',
'<td>',
new Date(OverSpeedAlerts[i].alert_gen_date_time * 1000),
'</td>',
'</tr>'
].join(''));
}
alertTypes[kesy[i] + 'Length'] = alertTypes[keys[i]].length;
$('#' + keys[i] + ' tbody').prepend(html.join(''));
}
}
if (io !== undefined) {
pushServer = io.connect('http://SomeIP:3000');
pushServer.on('entrance', process_data);
}