Skip to content

Commit

Permalink
Use localStorage to remember the user's actions and replay them when …
Browse files Browse the repository at this point in the history
…loading the page
  • Loading branch information
zsxwing committed Jul 17, 2015
1 parent 894a342 commit b123f67
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,63 @@
* to be registered after the page loads. */
$(function() {
$("span.expand-additional-metrics").click(function(){
var status = window.localStorage.getItem("expand-additional-metrics") == "true";
status = !status;

// Expand the list of additional metrics.
var additionalMetricsDiv = $(this).parent().find('.additional-metrics');
$(additionalMetricsDiv).toggleClass('collapsed');

// Switch the class of the arrow from open to closed.
$(this).find('.expand-additional-metrics-arrow').toggleClass('arrow-open');
$(this).find('.expand-additional-metrics-arrow').toggleClass('arrow-closed');

window.localStorage.setItem("expand-additional-metrics", "" + status);
});

if (window.localStorage.getItem("expand-additional-metrics") == "true") {
// Set it to false so that the click function can revert it
window.localStorage.setItem("expand-additional-metrics", "false");
$("span.expand-additional-metrics").trigger("click");
}

stripeSummaryTable();

$('input[type="checkbox"]').click(function() {
var column = "table ." + $(this).attr("name");
var name = $(this).attr("name")
var column = "table ." + name;
var status = window.localStorage.getItem(name) == "true";
status = !status;
$(column).toggle();
stripeSummaryTable();
window.localStorage.setItem(name, "" + status);
});

$("#select-all-metrics").click(function() {
var status = window.localStorage.getItem("select-all-metrics") == "true";
status = !status;
if (this.checked) {
// Toggle all un-checked options.
$('input[type="checkbox"]:not(:checked)').trigger('click');
} else {
// Toggle all checked options.
$('input[type="checkbox"]:checked').trigger('click');
}
window.localStorage.setItem("select-all-metrics", "" + status);
});

if (window.localStorage.getItem("select-all-metrics") == "true") {
$("#select-all-metrics").attr('checked', status);
}

$("span.additional-metric-title").parent().find('input[type="checkbox"]').each(function() {
var name = $(this).attr("name")
// If name is undefined, then skip it because it's the "select-all-metrics" checkbox
if (name && window.localStorage.getItem(name) == "true") {
// Set it to false so that the click function can revert it
window.localStorage.setItem(name, "false");
$(this).trigger("click")
}
});

// Trigger a click on the checkbox if a user clicks the label next to it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ var StagePageVizConstants = {
* This is the narrow interface called from the Scala UI code.
*/
function toggleDagViz(forJob) {
var status = window.localStorage.getItem("expand-dag-viz-arrow-" + forJob) == "true";
status = !status;

var arrowSelector = ".expand-dag-viz-arrow";
$(arrowSelector).toggleClass('arrow-closed');
$(arrowSelector).toggleClass('arrow-open');
Expand All @@ -93,8 +96,24 @@ function toggleDagViz(forJob) {
// Save the graph for later so we don't have to render it again
graphContainer().style("display", "none");
}

window.localStorage.setItem("expand-dag-viz-arrow-" + forJob, "" + status);
}

$(function (){
if (window.localStorage.getItem("expand-dag-viz-arrow-false") == "true") {
// Set it to false so that the click function can revert it
window.localStorage.setItem("expand-dag-viz-arrow-false", "false");
toggleDagViz(false);
}

if (window.localStorage.getItem("expand-dag-viz-arrow-true") == "true") {
// Set it to false so that the click function can revert it
window.localStorage.setItem("expand-dag-viz-arrow-true", "false");
toggleDagViz(true);
}
});

/*
* Render the RDD DAG visualization.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,27 @@ function drawApplicationTimeline(groupArray, eventObjArray, startTime) {
setupJobEventAction();

$("span.expand-application-timeline").click(function() {
var status = window.localStorage.getItem("expand-application-timeline") == "true";
status = !status;

$("#application-timeline").toggleClass('collapsed');

// Switch the class of the arrow from open to closed.
$(this).find('.expand-application-timeline-arrow').toggleClass('arrow-open');
$(this).find('.expand-application-timeline-arrow').toggleClass('arrow-closed');

window.localStorage.setItem("expand-application-timeline", "" + status);
});
}

$(function (){
if (window.localStorage.getItem("expand-application-timeline") == "true") {
// Set it to false so that the click function can revert it
window.localStorage.setItem("expand-application-timeline", "false");
$("span.expand-application-timeline").trigger('click');
}
});

function drawJobTimeline(groupArray, eventObjArray, startTime) {
var groups = new vis.DataSet(groupArray);
var items = new vis.DataSet(eventObjArray);
Expand Down Expand Up @@ -125,14 +138,27 @@ function drawJobTimeline(groupArray, eventObjArray, startTime) {
setupStageEventAction();

$("span.expand-job-timeline").click(function() {
var status = window.localStorage.getItem("expand-job-timeline") == "true";
status = !status;

$("#job-timeline").toggleClass('collapsed');

// Switch the class of the arrow from open to closed.
$(this).find('.expand-job-timeline-arrow').toggleClass('arrow-open');
$(this).find('.expand-job-timeline-arrow').toggleClass('arrow-closed');

window.localStorage.setItem("expand-job-timeline", "" + status);
});
}

$(function (){
if (window.localStorage.getItem("expand-job-timeline") == "true") {
// Set it to false so that the click function can revert it
window.localStorage.setItem("expand-job-timeline", "false");
$("span.expand-job-timeline").trigger('click');
}
});

function drawTaskAssignmentTimeline(groupArray, eventObjArray, minLaunchTime, maxFinishTime) {
var groups = new vis.DataSet(groupArray);
var items = new vis.DataSet(eventObjArray);
Expand Down Expand Up @@ -176,14 +202,27 @@ function drawTaskAssignmentTimeline(groupArray, eventObjArray, minLaunchTime, ma
setupZoomable("#task-assignment-timeline-zoom-lock", taskTimeline);

$("span.expand-task-assignment-timeline").click(function() {
var status = window.localStorage.getItem("expand-task-assignment-timeline") == "true";
status = !status;

$("#task-assignment-timeline").toggleClass("collapsed");

// Switch the class of the arrow from open to closed.
$(this).find(".expand-task-assignment-timeline-arrow").toggleClass("arrow-open");
$(this).find(".expand-task-assignment-timeline-arrow").toggleClass("arrow-closed");

window.localStorage.setItem("expand-task-assignment-timeline", "" + status);
});
}

$(function (){
if (window.localStorage.getItem("expand-task-assignment-timeline") == "true") {
// Set it to false so that the click function can revert it
window.localStorage.setItem("expand-task-assignment-timeline", "false");
$("span.expand-task-assignment-timeline").trigger('click');
}
});

function setupExecutorEventAction() {
$(".item.box.executor").each(function () {
$(this).hover(
Expand Down

0 comments on commit b123f67

Please sign in to comment.