Skip to content

Commit

Permalink
Add ability to filter columns in ls thing browsers
Browse files Browse the repository at this point in the history
Fixes #842
  • Loading branch information
brianbolt committed Dec 29, 2021
1 parent 21335b5 commit cc60f99
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 3 deletions.
71 changes: 70 additions & 1 deletion modules/Components/src/client/ACASThingBrowser.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ class ACASThingBrowserRowSummaryController extends Backbone.View
class ThingSummaryTableController extends Backbone.View
initialize: (options)->
@configs = options.configs
@columnFilters = options.columnFilters

selectedRowChanged: (row) =>
@trigger "selectedRowUpdated", row
Expand All @@ -218,6 +219,13 @@ class ThingSummaryTableController extends Backbone.View
for config in @configs
@$(".bv_firstRow").append("<th style=\"width: 125px;\">#{config.name}</th>")

# Add empty tr in thead for filter use
if @columnFilters? && @columnFilters
for config in @configs
# Remove space from key name
filterClass = "bv_filter_" + config.key.replace(/\s/g, '')
@$(".bv_colFilters").append("<th style=\"width: 125px;\" class=\"bv_thingBrowserFilter "+filterClass+"\"></th>")

if @collection.models.length is 0
@$(".bv_noMatchingThingsFoundMessage").removeClass "hide"
# display message indicating no results were found
Expand All @@ -230,9 +238,68 @@ class ThingSummaryTableController extends Backbone.View
prsc.on "gotClick", @selectedRowChanged
@$("tbody").append prsc.render().el

@$("table").dataTable oLanguage:
$.fn.dataTableExt.oApi.fnGetColumnData = (oSettings, iColumn, bUnique, bFiltered, bIgnoreEmpty) ->
# check that we have a column id
if typeof iColumn == 'undefined'
return new Array
# by default we only want unique data
if typeof bUnique == 'undefined'
bUnique = true
# by default we do want to only look at filtered data
if typeof bFiltered == 'undefined'
bFiltered = true
# by default we do not want to include empty values
if typeof bIgnoreEmpty == 'undefined'
bIgnoreEmpty = true
# list of rows which we're going to loop through
aiRows = undefined
# use only filtered rows
if bFiltered == true
aiRows = oSettings.aiDisplay
else
aiRows = oSettings.aiDisplayMaster
# all row numbers
# set up data array
asResultData = new Array
i = 0
c = aiRows.length
while i < c
iRow = aiRows[i]
aData = @fnGetData(iRow)
sValue = aData[iColumn]
# ignore empty values?
if bIgnoreEmpty == true and sValue.length == 0
i++
continue
else if bUnique == true and jQuery.inArray(sValue, asResultData) > -1
i++
continue
else
asResultData.push sValue
i++
asResultData

fnCreateSelect = (aData) ->
r = '<select><option value=""></option>'
i = undefined
iLen = aData.length
i = 0
while i < iLen
r += '<option value="' + aData[i] + '">' + aData[i] + '</option>'
i++
r + '</select>'

oTable = @$("table").dataTable oLanguage:
sSearch: "Filter results: " #rename summary table's search bar

if @columnFilters? && @columnFilters
this.$('thead tr.bv_colFilters th').each (i) ->
@innerHTML = fnCreateSelect(oTable.fnGetColumnData(i))
$('select', this).change ->
oTable.fnFilter $(this).val(), i
return
return

@


Expand All @@ -246,6 +313,7 @@ class ACASThingBrowserController extends Backbone.View
initialize: (options)->
thingModel = new @modelClass
@configs = @configs
@columnFilters = @columnFilters
templateVariables =
thingName: thingModel.getThingKindDisplayName()
template = _.template($("#ThingBrowserView").html())
Expand Down Expand Up @@ -278,6 +346,7 @@ class ACASThingBrowserController extends Backbone.View
@thingSummaryTable = new ThingSummaryTableController
collection: new thingCollection things
configs: @configs
columnFilters: @columnFilters

@thingSummaryTable.on "selectedRowUpdated", @selectedThingUpdated
$(".bv_thingTableController").html @thingSummaryTable.render().el
Expand Down
6 changes: 4 additions & 2 deletions modules/Components/src/client/ACASThingBrowserView.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
<script type="text/template" id="ThingSummaryTableView" xmlns="http://www.w3.org/1999/html">
<table class="table table-bordered table-striped table-hover" style="margin: 0px; padding: 0px; border: 0px; width: 100%; ">
<thead style="">
<tr class = "bv_firstRow">
</tr>
<tr class="bv_colFilters">
</tr>
<tr class = "bv_firstRow">
</tr>
</thead>
<tbody style="">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ window.ModuleMenusConfiguration =
isHeader: false, menuName: "Example Thing"
mainControllerClassName: "ExampleThingController"
autoLaunchName:"example_thing"
,
isHeader: false, menuName: "Example Thing Browser"
mainControllerClassName: "ExampleThingBrowserController"
autoLaunchName:"example_thing_browser"
,
isHeader: true
menuName: "Search and Edit"
Expand Down
24 changes: 24 additions & 0 deletions modules/ServerAPI/src/client/ExampleThing.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -523,3 +523,27 @@ class ExampleTableAuditController extends AbstractThingFormController
@model.prepareToSave()
@model.reformatBeforeSaving()
@model.save()


class ExampleThingBrowserController extends ACASThingBrowserController
controllerClass: ExampleThingController
modelClass: ExampleThingParent
columnFilters: true
configs: [
name: "Code Name"
key: "codeName"
,
name: "Name"
key: "example thing name"
,
name: "Scientist"
key: "scientist"
,
name: "Recorded By"
key: "recordedBy"
,
name: "Recorded Date"
key: "recordedDate"
formatter: UtilityFunctions::convertMSToYMDDate
]

12 changes: 12 additions & 0 deletions modules/ServerAPI/src/client/ExampleThing.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.bv_thingTableController .bv_thingBrowserFilter select {
width: 100px;
}
.bv_thingTableController .bv_filter_codeName select {
width: 300px !important;
}
.bv_thingTableController .bv_filter_recordedBy select {
width: 80px !important;
}
.bv_thingTableController .bv_filter_recordedDate select {
width: 80px !important;
}

0 comments on commit cc60f99

Please sign in to comment.