diff options
Diffstat (limited to 'bitbake/lib')
| -rw-r--r-- | bitbake/lib/toaster/toastergui/static/js/table.js | 78 |
1 files changed, 60 insertions, 18 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/table.js b/bitbake/lib/toaster/toastergui/static/js/table.js index 7b55102546..176ce579fb 100644 --- a/bitbake/lib/toaster/toastergui/static/js/table.js +++ b/bitbake/lib/toaster/toastergui/static/js/table.js | |||
| @@ -15,6 +15,7 @@ function tableInit(ctx){ | |||
| 15 | orderby : null, | 15 | orderby : null, |
| 16 | filter : null, | 16 | filter : null, |
| 17 | search : null, | 17 | search : null, |
| 18 | default_orderby: null, | ||
| 18 | }; | 19 | }; |
| 19 | 20 | ||
| 20 | var defaultHiddenCols = []; | 21 | var defaultHiddenCols = []; |
| @@ -192,6 +193,8 @@ function tableInit(ctx){ | |||
| 192 | tableHeadRow.html(""); | 193 | tableHeadRow.html(""); |
| 193 | editColMenu.html(""); | 194 | editColMenu.html(""); |
| 194 | 195 | ||
| 196 | tableParams.default_orderby = tableData.default_orderby; | ||
| 197 | |||
| 195 | if (!tableParams.orderby && tableData.default_orderby){ | 198 | if (!tableParams.orderby && tableData.default_orderby){ |
| 196 | tableParams.orderby = tableData.default_orderby; | 199 | tableParams.orderby = tableData.default_orderby; |
| 197 | } | 200 | } |
| @@ -217,6 +220,7 @@ function tableInit(ctx){ | |||
| 217 | var title = $('<a href=\"#\" ></a>'); | 220 | var title = $('<a href=\"#\" ></a>'); |
| 218 | 221 | ||
| 219 | title.data('field-name', col.field_name); | 222 | title.data('field-name', col.field_name); |
| 223 | title.attr('data-sort-field', col.field_name); | ||
| 220 | title.text(col.title); | 224 | title.text(col.title); |
| 221 | title.click(sortColumnClicked); | 225 | title.click(sortColumnClicked); |
| 222 | 226 | ||
| @@ -344,31 +348,67 @@ function tableInit(ctx){ | |||
| 344 | } | 348 | } |
| 345 | } | 349 | } |
| 346 | 350 | ||
| 347 | function sortColumnClicked(e){ | 351 | /* Apply an ordering to the current table. |
| 348 | e.preventDefault(); | 352 | * |
| 353 | * 1. Find the column heading matching the sortSpecifier | ||
| 354 | * 2. Set its up/down arrow and add .sorted | ||
| 355 | * | ||
| 356 | * orderby: e.g. "-started_on", "completed_on" | ||
| 357 | * colHeading: column heading element to activate (by showing the caret | ||
| 358 | * up/down, depending on sort order); if not set, the correct column | ||
| 359 | * heading is selected from the DOM using orderby as a key | ||
| 360 | */ | ||
| 361 | function applyOrderby(orderby, colHeading) { | ||
| 362 | if (!orderby) { | ||
| 363 | return; | ||
| 364 | } | ||
| 349 | 365 | ||
| 350 | /* We only have one sort at a time so remove any existing sort indicators */ | 366 | // We only have one sort at a time so remove existing sort indicators |
| 351 | $("#"+ctx.tableName+" th .icon-caret-down").hide(); | 367 | $("#" + ctx.tableName + " th .icon-caret-down").hide(); |
| 352 | $("#"+ctx.tableName+" th .icon-caret-up").hide(); | 368 | $("#" + ctx.tableName + " th .icon-caret-up").hide(); |
| 353 | $("#"+ctx.tableName+" th a").removeClass("sorted"); | 369 | $("#" + ctx.tableName + " th a").removeClass("sorted"); |
| 354 | 370 | ||
| 355 | var fieldName = $(this).data('field-name'); | 371 | // normalise the orderby so we can use it to find the link we want |
| 372 | // to style | ||
| 373 | var fieldName = orderby; | ||
| 374 | if (fieldName.indexOf('-') === 0) { | ||
| 375 | fieldName = fieldName.slice(1); | ||
| 376 | } | ||
| 356 | 377 | ||
| 357 | /* if we're already sorted sort the other way */ | 378 | // find the table header element which corresponds to the sort field |
| 358 | if (tableParams.orderby === fieldName && | 379 | // (if we don't already have it) |
| 359 | tableParams.orderby.indexOf('-') === -1) { | 380 | if (!colHeading) { |
| 360 | tableParams.orderby = '-' + $(this).data('field-name'); | 381 | colHeading = $('[data-sort-field="' + fieldName + '"]'); |
| 361 | $(this).parent().children('.icon-caret-up').show(); | ||
| 362 | } else { | ||
| 363 | tableParams.orderby = $(this).data('field-name'); | ||
| 364 | $(this).parent().children('.icon-caret-down').show(); | ||
| 365 | } | 382 | } |
| 366 | 383 | ||
| 367 | $(this).addClass("sorted"); | 384 | colHeading.addClass("sorted"); |
| 385 | |||
| 386 | var parent = colHeading.parent(); | ||
| 368 | 387 | ||
| 388 | if (orderby.indexOf('-') === 0) { | ||
| 389 | parent.children('.icon-caret-up').show(); | ||
| 390 | } | ||
| 391 | else { | ||
| 392 | parent.children('.icon-caret-down').show(); | ||
| 393 | } | ||
| 394 | |||
| 395 | tableParams.orderby = orderby; | ||
| 369 | loadData(tableParams); | 396 | loadData(tableParams); |
| 370 | } | 397 | } |
| 371 | 398 | ||
| 399 | function sortColumnClicked(e){ | ||
| 400 | e.preventDefault(); | ||
| 401 | |||
| 402 | /* if we're already sorted sort the other way */ | ||
| 403 | var orderby = $(this).data('field-name'); | ||
| 404 | if (tableParams.orderby === orderby && | ||
| 405 | tableParams.orderby.indexOf('-') === -1) { | ||
| 406 | orderby = '-' + orderby; | ||
| 407 | } | ||
| 408 | |||
| 409 | applyOrderby(orderby, $(this)); | ||
| 410 | } | ||
| 411 | |||
| 372 | function pageButtonClicked(e) { | 412 | function pageButtonClicked(e) { |
| 373 | tableParams.page = Number($(this).text()); | 413 | tableParams.page = Number($(this).text()); |
| 374 | loadData(tableParams); | 414 | loadData(tableParams); |
| @@ -385,11 +425,13 @@ function tableInit(ctx){ | |||
| 385 | table.find("."+col).show(); | 425 | table.find("."+col).show(); |
| 386 | } else { | 426 | } else { |
| 387 | table.find("."+col).hide(); | 427 | table.find("."+col).hide(); |
| 388 | /* If we're ordered by the column we're hiding remove the order by */ | 428 | // If we're ordered by the column we're hiding remove the order by |
| 429 | // and apply the default one instead | ||
| 389 | if (col === tableParams.orderby || | 430 | if (col === tableParams.orderby || |
| 390 | '-' + col === tableParams.orderby){ | 431 | '-' + col === tableParams.orderby){ |
| 391 | tableParams.orderby = null; | 432 | tableParams.orderby = null; |
| 392 | $("#"+ctx.tableName +" .default-orderby").click(); | 433 | |
| 434 | applyOrderby(tableParams.default_orderby); | ||
| 393 | } | 435 | } |
| 394 | } | 436 | } |
| 395 | 437 | ||
