0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 var appLimit = -1;
0019
0020 function setAppLimit(val) {
0021 appLimit = val;
0022 }
0023
0024 function makeIdNumeric(id) {
0025 var strs = id.split("_");
0026 if (strs.length < 3) {
0027 return id;
0028 }
0029 var appSeqNum = strs[2];
0030 var resl = strs[0] + "_" + strs[1] + "_";
0031 var diff = 10 - appSeqNum.length;
0032 while (diff > 0) {
0033 resl += "0";
0034 diff--;
0035 }
0036 resl += appSeqNum;
0037 return resl;
0038 }
0039
0040 function getParameterByName(name, searchString) {
0041 var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
0042 results = regex.exec(searchString);
0043 return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
0044 }
0045
0046 function removeColumnByName(columns, columnName) {
0047 return columns.filter(function(col) {return col.name != columnName})
0048 }
0049
0050 function getColumnIndex(columns, columnName) {
0051 for(var i = 0; i < columns.length; i++) {
0052 if (columns[i].name == columnName)
0053 return i;
0054 }
0055 return -1;
0056 }
0057
0058 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
0059 "title-numeric-pre": function ( a ) {
0060 var x = a.match(/title="*(-?[0-9\.]+)/)[1];
0061 return parseFloat( x );
0062 },
0063
0064 "title-numeric-asc": function ( a, b ) {
0065 return ((a < b) ? -1 : ((a > b) ? 1 : 0));
0066 },
0067
0068 "title-numeric-desc": function ( a, b ) {
0069 return ((a < b) ? 1 : ((a > b) ? -1 : 0));
0070 }
0071 } );
0072
0073 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
0074 "appid-numeric-pre": function ( a ) {
0075 var x = a.match(/title="*(-?[0-9a-zA-Z\-\_]+)/)[1];
0076 return makeIdNumeric(x);
0077 },
0078
0079 "appid-numeric-asc": function ( a, b ) {
0080 return ((a < b) ? -1 : ((a > b) ? 1 : 0));
0081 },
0082
0083 "appid-numeric-desc": function ( a, b ) {
0084 return ((a < b) ? 1 : ((a > b) ? -1 : 0));
0085 }
0086 } );
0087
0088 jQuery.extend( jQuery.fn.dataTableExt.ofnSearch, {
0089 "appid-numeric": function ( a ) {
0090 return a.replace(/[\r\n]/g, " ").replace(/<.*?>/g, "");
0091 }
0092 } );
0093
0094 $(document).ajaxStop($.unblockUI);
0095 $(document).ajaxStart(function(){
0096 $.blockUI({ message: '<h3>Loading history summary...</h3>'});
0097 });
0098
0099 $(document).ready(function() {
0100 $.extend( $.fn.dataTable.defaults, {
0101 stateSave: true,
0102 lengthMenu: [[20,40,60,100,-1], [20, 40, 60, 100, "All"]],
0103 pageLength: 20
0104 });
0105
0106 var historySummary = $("#history-summary");
0107 var searchString = window.location.search;
0108 var requestedIncomplete = getParameterByName("showIncomplete", searchString);
0109 requestedIncomplete = (requestedIncomplete == "true" ? true : false);
0110
0111 var appParams = {
0112 limit: appLimit,
0113 status: (requestedIncomplete ? "running" : "completed")
0114 };
0115
0116 $.getJSON(uiRoot + "/api/v1/applications", appParams, function(response,status,jqXHR) {
0117 var array = [];
0118 var hasMultipleAttempts = false;
0119 for (var i in response) {
0120 var app = response[i];
0121 if (app["attempts"][0]["completed"] == requestedIncomplete) {
0122 continue;
0123 }
0124 var version = "Unknown"
0125 if (app["attempts"].length > 0) {
0126 version = app["attempts"][0]["appSparkVersion"]
0127 }
0128 var id = app["id"];
0129 var name = app["name"];
0130 if (app["attempts"].length > 1) {
0131 hasMultipleAttempts = true;
0132 }
0133 var num = app["attempts"].length;
0134 for (var j in app["attempts"]) {
0135 var attempt = app["attempts"][j];
0136 attempt["startTime"] = formatTimeMillis(attempt["startTimeEpoch"]);
0137 attempt["endTime"] = formatTimeMillis(attempt["endTimeEpoch"]);
0138 attempt["lastUpdated"] = formatTimeMillis(attempt["lastUpdatedEpoch"]);
0139 attempt["log"] = uiRoot + "/api/v1/applications/" + id + "/" +
0140 (attempt.hasOwnProperty("attemptId") ? attempt["attemptId"] + "/" : "") + "logs";
0141 attempt["durationMillisec"] = attempt["duration"];
0142 attempt["duration"] = formatDuration(attempt["duration"]);
0143 var app_clone = {"id" : id, "name" : name, "version": version, "num" : num, "attempts" : [attempt]};
0144 array.push(app_clone);
0145 }
0146 }
0147 if(array.length < 20) {
0148 $.fn.dataTable.defaults.paging = false;
0149 }
0150
0151 var data = {
0152 "uiroot": uiRoot,
0153 "applications": array,
0154 "hasMultipleAttempts": hasMultipleAttempts,
0155 "showCompletedColumns": !requestedIncomplete,
0156 };
0157
0158 $.get(uiRoot + "/static/historypage-template.html", function(template) {
0159 var sibling = historySummary.prev();
0160 historySummary.detach();
0161 var apps = $(Mustache.render($(template).filter("#history-summary-template").html(),data));
0162 var attemptIdColumnName = 'attemptId';
0163 var startedColumnName = 'started';
0164 var completedColumnName = 'completed';
0165 var durationColumnName = 'duration';
0166 var conf = {
0167 "columns": [
0168 {name: 'version'},
0169 {name: 'appId', type: "appid-numeric"},
0170 {name: 'appName'},
0171 {name: attemptIdColumnName},
0172 {name: startedColumnName},
0173 {name: completedColumnName},
0174 {name: durationColumnName, type: "title-numeric"},
0175 {name: 'user'},
0176 {name: 'lastUpdated'},
0177 {name: 'eventLog'},
0178 ],
0179 "autoWidth": false,
0180 "deferRender": true
0181 };
0182
0183 if (hasMultipleAttempts) {
0184 conf.rowsGroup = [
0185 'appId:name',
0186 'version:name',
0187 'appName:name'
0188 ];
0189 } else {
0190 conf.columns = removeColumnByName(conf.columns, attemptIdColumnName);
0191 }
0192
0193 var defaultSortColumn = completedColumnName;
0194 if (requestedIncomplete) {
0195 defaultSortColumn = startedColumnName;
0196 conf.columns = removeColumnByName(conf.columns, completedColumnName);
0197 conf.columns = removeColumnByName(conf.columns, durationColumnName);
0198 }
0199 conf.order = [[ getColumnIndex(conf.columns, defaultSortColumn), "desc" ]];
0200 conf.columnDefs = [
0201 {"searchable": false, "targets": [getColumnIndex(conf.columns, durationColumnName)]}
0202 ];
0203 historySummary.append(apps);
0204 apps.DataTable(conf);
0205 sibling.after(historySummary);
0206 $('#history-summary [data-toggle="tooltip"]').tooltip();
0207 });
0208 });
0209 });