From 73f39095e6e08d38fdbd07a81125ac99b758d26e Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Thu, 24 Apr 2014 11:08:42 -0700 Subject: [PATCH] Upgraded table sorter. --- app/styles/employers.sass | 9 ++- app/templates/employers.jade | 10 ++-- app/views/employers_view.coffee | 100 ++++++++++++++++++++++++++++---- server/commons/Handler.coffee | 2 +- 4 files changed, 103 insertions(+), 18 deletions(-) diff --git a/app/styles/employers.sass b/app/styles/employers.sass index 6e64b44a0..d0da4c1b2 100644 --- a/app/styles/employers.sass +++ b/app/styles/employers.sass @@ -11,7 +11,7 @@ &:first-child // Make sure that "Developer #56" doesn't wrap onto second row min-width: 110px - + .tablesorter-headerAsc background-color: #cfc @@ -27,3 +27,10 @@ margin: 2px 0 display: inline-block text-transform: lowercase + + td:nth-child(3) select + min-width: 100px + td:nth-child(6) select + min-width: 50px + td:nth-child(7) select + min-width: 100px diff --git a/app/templates/employers.jade b/app/templates/employers.jade index bfb2ca051..2903a0ee2 100644 --- a/app/templates/employers.jade +++ b/app/templates/employers.jade @@ -27,8 +27,8 @@ block content th(data-i18n="employers.candidate_years_experience") Yrs Exp th(data-i18n="employers.candidate_last_updated") Last Updated if me.isAdmin() - th ✓? - th ಥ_ಥ + th Us? + th Them? tbody for candidate, index in candidates @@ -53,13 +53,13 @@ block content code= skill span td= profile.experience - td= moment(profile.updated).fromNow() + td(data-profile-age=(new Date() - new Date(profile.updated)) / 86400 / 1000)= moment(profile.updated).fromNow() if me.isAdmin() if candidate.get('jobProfileApproved') td ✓ else td ✗ if profile.active - td ᶘ ᵒᴥᵒᶅ + td ✓ else - td ⨂_⨂ \ No newline at end of file + td ✗ \ No newline at end of file diff --git a/app/views/employers_view.coffee b/app/views/employers_view.coffee index cdbf8f074..3160c350b 100644 --- a/app/views/employers_view.coffee +++ b/app/views/employers_view.coffee @@ -56,27 +56,105 @@ module.exports = class EmployersView extends View even: "" # odd row zebra striping odd: "" # even row zebra striping + + # e = exact text from cell + # n = normalized value returned by the column parser + # f = search filter input value + # i = column index + # $r = ??? + filterSelectExactMatch = (e, n, f, i, $r) -> e is f + # call the tablesorter plugin and apply the uitheme widget - @$el.find(".tablesorter").tablesorter( + @$el.find(".tablesorter").tablesorter theme: "bootstrap" widthFixed: true headerTemplate: "{content} {icon}" + textSorter: + 6: (a, b, direction, column, table) -> + days = [] + for s in [a, b] + n = parseInt s + n = 0 unless _.isNumber n + for [duration, factor] in [ + [/second/i, 1 / (86400 * 1000)] + [/minute/i, 1 / 1440] + [/hour/i, 1 / 24] + [/week/i, 7] + [/month/i, 30.42] + [/year/i, 365.2425] + ] + if duration.test s + n *= factor + break + if /^in /i.test s + n *= -1 + days.push n + days[0] - days[1] + sortList: [[6, 0]] # widget code contained in the jquery.tablesorter.widgets.js file # use the zebra stripe widget if you plan on hiding any rows (filter widget) - widgets: [ - "uitheme" - "zebra" - ] + widgets: ["uitheme", "zebra", "filter"] widgetOptions: # using the default zebra striping class name, so it actually isn't included in the theme variable above # this is ONLY needed for bootstrap theming if you are using the filter widget, because rows are hidden - zebra: [ - "even" - "odd" - ] - # reset filters button + zebra: ["even", "odd"] + + # extra css class applied to the table row containing the filters & the inputs within that row + filter_cssFilter: "" + + # If there are child rows in the table (rows with class name from "cssChildRow" option) + # and this option is true and a match is found anywhere in the child row, then it will make that row + # visible; default is false + filter_childRows: false + + # if true, filters are collapsed initially, but can be revealed by hovering over the grey bar immediately + # below the header row. Additionally, tabbing through the document will open the filter row when an input gets focus + filter_hideFilters: false + + # Set this option to false to make the searches case sensitive + filter_ignoreCase: true + + # jQuery selector string of an element used to reset the filters filter_reset: ".reset" - ) + + # Use the $.tablesorter.storage utility to save the most recent filters + filter_saveFilters: true + + # Delay in milliseconds before the filter widget starts searching; This option prevents searching for + # every character while typing and should make searching large tables faster. + filter_searchDelay: 150 + + # Set this option to true to use the filter to find text from the start of the column + # So typing in "a" will find "albert" but not "frank", both have a's; default is false + filter_startsWith: false + + filter_functions: + 2: + "Full-time": filterSelectExactMatch + "Part-time": filterSelectExactMatch + "Contracting": filterSelectExactMatch + "Remote": filterSelectExactMatch + "Internship": filterSelectExactMatch + 5: + "0-1": (e, n, f, i, $r) -> n <= 1 + "2-5": (e, n, f, i, $r) -> 2 <= n <= 5 + "6+": (e, n, f, i, $r) -> 6 <= n + 6: + "Last day": (e, n, f, i, $r) -> + days = parseFloat $($r.find('td')[i]).data('profile-age') + days <= 1 + "Last week": (e, n, f, i, $r) -> + days = parseFloat $($r.find('td')[i]).data('profile-age') + days <= 7 + "Last 4 weeks": (e, n, f, i, $r) -> + days = parseFloat $($r.find('td')[i]).data('profile-age') + days <= 28 + 7: + "✓": filterSelectExactMatch + "✗": filterSelectExactMatch + 8: + "✓": filterSelectExactMatch + "✗": filterSelectExactMatch onCandidateClicked: (e) -> id = $(e.target).closest('tr').data('candidate-id') diff --git a/server/commons/Handler.coffee b/server/commons/Handler.coffee index 9c6b165e0..851dd4268 100644 --- a/server/commons/Handler.coffee +++ b/server/commons/Handler.coffee @@ -332,7 +332,7 @@ module.exports = class Handler res = tv4.validateMultiple(input, @jsonSchema) res - @isID: (id) -> _.isString(id) and id.length is 24 and id.match(/[a-z0-9]/gi)?.length is 24 + @isID: (id) -> _.isString(id) and id.length is 24 and id.match(/[a-f0-9]/gi)?.length is 24 getDocumentForIdOrSlug: (idOrSlug, done) -> idOrSlug = idOrSlug+''