Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
61b4782
Add ESLint support.
sarutak Apr 21, 2021
e2fcd9e
Add a newline at the end of .gitignore.
sarutak Apr 21, 2021
990e538
Modify .rat-exclude.
sarutak Apr 22, 2021
d6eb61a
Add docs/js for a lint target.
sarutak Apr 25, 2021
c1afc31
npm install -> npm ci to avoid package-lock.json being changed.
sarutak May 6, 2021
d858aa8
Upgrade eslint.
sarutak May 6, 2021
e459d90
Add switch-case rule.
sarutak May 6, 2021
1ad98a5
Fix style for webui.js.
sarutak May 6, 2021
feb6d76
Disable indentation rule for member expressions.
sarutak May 6, 2021
0a1a461
Fix style for utils.js.
sarutak May 6, 2021
71ea913
Fix style for timeline-view.js.
sarutak May 6, 2021
5ec9eea
Fix style for table.js.
sarutak May 6, 2021
701514a
Fix style for structured-streaming-page.js.
sarutak May 6, 2021
5b18e69
Fix style for streaming-page.js.
sarutak May 6, 2021
1d209ca
Add ignored argument rule.
sarutak May 6, 2021
4c8cb17
Fix style for stagepage.js.
sarutak May 6, 2021
4884b8e
Fix style for spark-dag-viz.js.
sarutak May 6, 2021
da34039
Fix style for log-view.js.
sarutak May 6, 2021
896b475
Modify indentation in eslint.json.
sarutak May 6, 2021
e8170eb
Fix style for initialize-tooltips.js.
sarutak May 6, 2021
e3847db
Fix style for historypage.js.
sarutak May 6, 2021
b129c4e
Fix style for historypage-common.js.
sarutak May 6, 2021
d174384
Fix style for executorspage.js.
sarutak May 6, 2021
1d67631
Revert "Fix style for stagepage.js."
sarutak May 6, 2021
82a9947
Merge branch 'master' of https://github.com/apache/spark into introdu…
sarutak May 6, 2021
5bda9fc
Fix style for stagepage.js.
sarutak May 6, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix style for utils.js.
  • Loading branch information
sarutak committed May 6, 2021
commit 0a1a46144e45bb2ba944b10646020f5d178d3bf8
161 changes: 86 additions & 75 deletions core/src/main/resources/org/apache/spark/ui/static/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,46 @@
* limitations under the License.
*/

/* global $, uiRoot */
/* eslint-disable no-unused-vars */
// this function works exactly the same as UIUtils.formatDuration
function formatDuration(milliseconds) {
if (milliseconds < 100) {
return parseInt(milliseconds).toFixed(1) + " ms";
}
var seconds = milliseconds * 1.0 / 1000;
if (seconds < 1) {
return seconds.toFixed(1) + " s";
}
if (seconds < 60) {
return seconds.toFixed(0) + " s";
}
var minutes = seconds / 60;
if (minutes < 10) {
return minutes.toFixed(1) + " min";
} else if (minutes < 60) {
return minutes.toFixed(0) + " min";
}
var hours = minutes / 60;
return hours.toFixed(1) + " h";
if (milliseconds < 100) {
return parseInt(milliseconds).toFixed(1) + " ms";
}
var seconds = milliseconds * 1.0 / 1000;
if (seconds < 1) {
return seconds.toFixed(1) + " s";
}
if (seconds < 60) {
return seconds.toFixed(0) + " s";
}
var minutes = seconds / 60;
if (minutes < 10) {
return minutes.toFixed(1) + " min";
} else if (minutes < 60) {
return minutes.toFixed(0) + " min";
}
var hours = minutes / 60;
return hours.toFixed(1) + " h";
}

function formatBytes(bytes, type) {
if (type !== 'display') return bytes;
if (bytes <= 0) return '0.0 B';
var k = 1024;
var dm = 1;
var sizes = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
var i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
if (type !== 'display') return bytes;
if (bytes <= 0) return '0.0 B';
var k = 1024;
var dm = 1;
var sizes = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
var i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}
/* eslint-enable no-unused-vars */

function padZeroes(num) {
return ("0" + num).slice(-2);
}

/* eslint-disable no-unused-vars */
function formatTimeMillis(timeMillis) {
if (timeMillis <= 0) {
return "-";
Expand All @@ -59,16 +63,18 @@ function formatTimeMillis(timeMillis) {
return formatDateString(dt);
}
}
/* eslint-enable no-unused-vars */

function formatDateString(dt) {
return dt.getFullYear() + "-" +
padZeroes(dt.getMonth() + 1) + "-" +
padZeroes(dt.getDate()) + " " +
padZeroes(dt.getHours()) + ":" +
padZeroes(dt.getMinutes()) + ":" +
padZeroes(dt.getSeconds());
return dt.getFullYear() + "-" +
padZeroes(dt.getMonth() + 1) + "-" +
padZeroes(dt.getDate()) + " " +
padZeroes(dt.getHours()) + ":" +
padZeroes(dt.getMinutes()) + ":" +
padZeroes(dt.getSeconds());
}

/* eslint-disable no-unused-vars */
function getTimeZone() {
try {
return Intl.DateTimeFormat().resolvedOptions().timeZone;
Expand All @@ -92,14 +98,15 @@ function formatLogsCells(execLogs, type) {
function getStandAloneAppId(cb) {
var words = document.baseURI.split('/');
var ind = words.indexOf("proxy");
var appId;
if (ind > 0) {
var appId = words[ind + 1];
appId = words[ind + 1];
cb(appId);
return;
}
ind = words.indexOf("history");
if (ind > 0) {
var appId = words[ind + 1];
appId = words[ind + 1];
cb(appId);
return;
}
Expand All @@ -119,7 +126,7 @@ function getStandAloneAppId(cb) {
// It will convert the string into integer for correct ordering
function ConvertDurationString(data) {
data = data.toString();
var units = data.replace(/[\d\.]/g, '' )
var units = data.replace(/[\d.]/g, '' )
.replace(' ', '')
.toLowerCase();
var multiplier = 1;
Expand All @@ -143,13 +150,14 @@ function ConvertDurationString(data) {
function createTemplateURI(appId, templateName) {
var words = document.baseURI.split('/');
var ind = words.indexOf("proxy");
var baseURI;
if (ind > 0) {
var baseURI = words.slice(0, ind + 1).join('/') + '/' + appId + '/static/' + templateName + '-template.html';
baseURI = words.slice(0, ind + 1).join('/') + '/' + appId + '/static/' + templateName + '-template.html';
return baseURI;
}
ind = words.indexOf("history");
if(ind > 0) {
var baseURI = words.slice(0, ind).join('/') + '/static/' + templateName + '-template.html';
baseURI = words.slice(0, ind).join('/') + '/static/' + templateName + '-template.html';
return baseURI;
}
return uiRoot + "/static/" + templateName + "-template.html";
Expand All @@ -159,7 +167,7 @@ function setDataTableDefaults() {
$.extend($.fn.dataTable.defaults, {
stateSave: true,
stateSaveParams: function(_, data) {
data.search.search = "";
data.search.search = "";
},
lengthMenu: [[20, 40, 60, 100, -1], [20, 40, 60, 100, "All"]],
pageLength: 20
Expand All @@ -169,51 +177,54 @@ function setDataTableDefaults() {
function formatDate(date) {
if (date <= 0) return "-";
else {
var dt = new Date(date.replace("GMT", "Z"));
return formatDateString(dt);
var dt = new Date(date.replace("GMT", "Z"));
return formatDateString(dt);
}
}

function createRESTEndPointForExecutorsPage(appId) {
var words = document.baseURI.split('/');
var ind = words.indexOf("proxy");
if (ind > 0) {
var appId = words[ind + 1];
var newBaseURI = words.slice(0, ind + 2).join('/');
return newBaseURI + "/api/v1/applications/" + appId + "/allexecutors";
}
ind = words.indexOf("history");
if (ind > 0) {
var appId = words[ind + 1];
var attemptId = words[ind + 2];
var newBaseURI = words.slice(0, ind).join('/');
if (isNaN(attemptId)) {
return newBaseURI + "/api/v1/applications/" + appId + "/allexecutors";
} else {
return newBaseURI + "/api/v1/applications/" + appId + "/" + attemptId + "/allexecutors";
}
var words = document.baseURI.split('/');
var ind = words.indexOf("proxy");
var newBaseURI;
if (ind > 0) {
appId = words[ind + 1];
newBaseURI = words.slice(0, ind + 2).join('/');
return newBaseURI + "/api/v1/applications/" + appId + "/allexecutors";
}
ind = words.indexOf("history");
if (ind > 0) {
appId = words[ind + 1];
var attemptId = words[ind + 2];
newBaseURI = words.slice(0, ind).join('/');
if (isNaN(attemptId)) {
return newBaseURI + "/api/v1/applications/" + appId + "/allexecutors";
} else {
return newBaseURI + "/api/v1/applications/" + appId + "/" + attemptId + "/allexecutors";
}
return uiRoot + "/api/v1/applications/" + appId + "/allexecutors";
}
return uiRoot + "/api/v1/applications/" + appId + "/allexecutors";
}

function createRESTEndPointForMiscellaneousProcess(appId) {
var words = document.baseURI.split('/');
var ind = words.indexOf("proxy");
if (ind > 0) {
var appId = words[ind + 1];
var newBaseURI = words.slice(0, ind + 2).join('/');
return newBaseURI + "/api/v1/applications/" + appId + "/allmiscellaneousprocess";
}
ind = words.indexOf("history");
if (ind > 0) {
var appId = words[ind + 1];
var attemptId = words[ind + 2];
var newBaseURI = words.slice(0, ind).join('/');
if (isNaN(attemptId)) {
return newBaseURI + "/api/v1/applications/" + appId + "/allmiscellaneousprocess";
} else {
return newBaseURI + "/api/v1/applications/" + appId + "/" + attemptId + "/allmiscellaneousprocess";
}
var words = document.baseURI.split('/');
var ind = words.indexOf("proxy");
var newBaseURI;
if (ind > 0) {
appId = words[ind + 1];
newBaseURI = words.slice(0, ind + 2).join('/');
return newBaseURI + "/api/v1/applications/" + appId + "/allmiscellaneousprocess";
}
ind = words.indexOf("history");
if (ind > 0) {
appId = words[ind + 1];
var attemptId = words[ind + 2];
newBaseURI = words.slice(0, ind).join('/');
if (isNaN(attemptId)) {
return newBaseURI + "/api/v1/applications/" + appId + "/allmiscellaneousprocess";
} else {
return newBaseURI + "/api/v1/applications/" + appId + "/" + attemptId + "/allmiscellaneousprocess";
}
return uiRoot + "/api/v1/applications/" + appId + "/allmiscellaneousprocess";
}
return uiRoot + "/api/v1/applications/" + appId + "/allmiscellaneousprocess";
}
/* eslint-enable no-unused-vars */