Skip to content

Commit

Permalink
[FIXED JENKINS-203] Store sortable table state into local storage.
Browse files Browse the repository at this point in the history
  • Loading branch information
ohtake authored and kohsuke committed Sep 23, 2011
1 parent 30af566 commit 675902a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -96,6 +96,9 @@ <h3><a name=v1.432>What's new in 1.432</a> <!--=DATE=--></h3>
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-10689">issue 10689</a>)
<li class=rfe>
Enabled shortcut key on script console
<li class=rfe>
Remember sortable table state into local storage
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-203">issue 203</a>)
</ul>
</div><!--=END=-->
<h3><a name=v1.431>What's new in 1.431</a> (2011/09/19)</h3>
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/lib/layout/layout.jelly
Expand Up @@ -99,7 +99,6 @@ THE SOFTWARE.

<script src="${resURL}/scripts/prototype.js" type="text/javascript"/>
<script src="${resURL}/scripts/behavior.js" type="text/javascript"/>
<script src="${resURL}/scripts/sortable.js" type="text/javascript"/>

<!-- we include our own prototype.js, so don't let stapler pull in another. -->
<st:adjunct assumes="org.kohsuke.stapler.framework.prototype.prototype"
Expand All @@ -126,6 +125,7 @@ THE SOFTWARE.
<!--l:yui module="editor" suffix="-beta" /-->

<script src="${resURL}/scripts/hudson-behavior.js" type="text/javascript"></script>
<script src="${resURL}/scripts/sortable.js" type="text/javascript"/>

<script>
crumb.init("${h.getCrumbRequestField()}", "${h.getCrumb(request)}");
Expand Down
53 changes: 53 additions & 0 deletions war/src/main/webapp/scripts/sortable.js
Expand Up @@ -62,6 +62,7 @@ function ts_makeSortable(table) {
if(initialSortDir!=arrowTable.none)
cell.firstChild.lastChild.sortdir = initialSortDir;
}
ts_loadDirection(table);
}

function ts_getInnerText(el) {
Expand Down Expand Up @@ -96,14 +97,17 @@ function extractData(x) {

var arrowTable = {
up: {
id: "up",
text: "&nbsp;&nbsp;&uarr;",
reorder: function(rows) { rows.reverse(); }
},
down: {
id: "down",
text: "&nbsp;&nbsp;&darr;",
reorder: function() {}
},
none: {
id: "none",
text: "&nbsp;&nbsp;&nbsp;"
},
lnkRef: null
Expand Down Expand Up @@ -171,6 +175,7 @@ function ts_resortTable(lnk) {
}

span.innerHTML = dir.text;
ts_saveDirection(table, column, dir);
}

function getParent(el, pTagName) {
Expand Down Expand Up @@ -228,3 +233,51 @@ function ts_sort_default(a,b) {
if (a<b) return -1;
return 1;
}

function ts_getIndexOfSortableTable(table){
var allTables = document.getElementsByTagName("TABLE");
var sortableTables = [];
for (var i=0; i<allTables.length; i++) {
if($(allTables[i]).hasClassName("sortable")){
sortableTables.push(allTables[i]);
}
}
return sortableTables.indexOf(table);
}
function ts_getStorageKey(table){
var uri = document.location;
var tableIndex = ts_getIndexOfSortableTable(table);
return "ts_direction::" + uri + "::" + tableIndex;
}
function ts_saveDirection(table, columnIndex, direction){
var key = ts_getStorageKey(table);
ts_Storage.setItem(key, columnIndex + ":" + direction.id);
}
function ts_loadDirection(table){
var key = ts_getStorageKey(table);
if(ts_Storage.hasKey(key)){
var val = ts_Storage.getItem(key);
if(val){
var vals = val.split(":");
if(vals.length == 2) {
var colIndex = parseInt(vals[0]);
var direction = arrowTable[vals[1]];
var col = table.rows[0].cells[colIndex];
var anchor = col.firstChild;
var arrow = anchor.lastChild;
arrow.sortdir = direction;
ts_resortTable(anchor);
}
}
}
}

var ts_Storage = YAHOO.util.StorageManager.get(
YAHOO.util.StorageEngineHTML5.ENGINE_NAME,
YAHOO.util.StorageManager.LOCATION_SESSION,
{
order: [
YAHOO.util.StorageEngineGears
]
}
);

0 comments on commit 675902a

Please sign in to comment.