Merge pull request #1369 from codecombat/master

Add filter alerts to employer page
This commit is contained in:
Michael Schmatz 2014-07-21 16:11:09 -07:00
commit a1e6cf1d65
5 changed files with 64 additions and 7 deletions

View file

@ -181,7 +181,7 @@ _.extend UserSchema.properties,
}, c.object({ }, c.object({
title: 'Saved filter set' title: 'Saved filter set'
description: 'A saved filter set' description: 'A saved filter set'
required: ['phoneScreenFilter','schoolFilter','locationFilter','roleFilter','seniorityFilter','visa','filterActive'] required: ['phoneScreenFilter','schoolFilter','locationFilter','roleFilter','seniorityFilter','visa']
}, { }, {
phoneScreenFilter: phoneScreenFilter:
title: 'Phone screen filter values' title: 'Phone screen filter values'

View file

@ -63,7 +63,15 @@
cursor: pointer cursor: pointer
input input
margin-right: 5px margin-right: 5px
#saved-filter-table
display: none
width: 100%
tbody
tr:nth-child(even)
background-color: #CBCBCB
margin-bottom: 20px
.deletion-row
text-align: center
.get-started-button .get-started-button
vertical-align: text-bottom vertical-align: text-bottom
margin-left: 10px margin-left: 10px

View file

@ -90,7 +90,15 @@ block content
p#results p#results
| #{numberOfCandidates} | #{numberOfCandidates}
span(data-i18n="employers.results") results span(data-i18n="employers.results") results
//button.btn#create-alert-button Create Alert h4#filter-alerts-heading Filter Email Alerts
p Get an email whenever a candidate meeting certain criteria enters the system.
table#saved-filter-table
thead
tr
th Filters
th Remove
tbody
button.btn#create-alert-button Create Alert with Current Filters
#candidates-column(class=fullProfiles ? "full-profiles col-md-9" : "teaser-profiles col-md-12") #candidates-column(class=fullProfiles ? "full-profiles col-md-9" : "teaser-profiles col-md-12")
if candidates.length if candidates.length

View file

@ -20,15 +20,16 @@ module.exports = class EmployersView extends RootView
template: template template: template
events: events:
'click tbody tr': 'onCandidateClicked' 'click #candidate-table': 'onCandidateClicked'
'click #logout-link': 'logoutAccount' 'click #logout-link': 'logoutAccount'
'change #filters input': 'onFilterChanged' 'change #filters input': 'onFilterChanged'
'click #filter-button': 'applyFilters'
'change #select_all_checkbox': 'handleSelectAllChange' 'change #select_all_checkbox': 'handleSelectAllChange'
'click .get-started-button': 'openSignupModal' 'click .get-started-button': 'openSignupModal'
'click .navbar-brand': 'restoreBodyColor' 'click .navbar-brand': 'restoreBodyColor'
'click #login-link': 'onClickAuthbutton' 'click #login-link': 'onClickAuthbutton'
'click #filter-link': 'swapFolderIcon' 'click #filter-link': 'swapFolderIcon'
'click #create-alert-button': 'createFilterAlert'
'click .deletion-col': 'deleteFilterAlert'
constructor: (options) -> constructor: (options) ->
super options super options
@ -39,6 +40,7 @@ module.exports = class EmployersView extends RootView
afterRender: -> afterRender: ->
super() super()
@sortTable() if @candidates.models.length @sortTable() if @candidates.models.length
@renderSavedFilters()
afterInsert: -> afterInsert: ->
super() super()
@ -128,7 +130,46 @@ module.exports = class EmployersView extends RootView
return (_.filter candidates, (c) -> c.get('jobProfile').curated?[filterName] is filterValue).length return (_.filter candidates, (c) -> c.get('jobProfile').curated?[filterName] is filterValue).length
else else
return Math.floor(Math.random() * 500) return Math.floor(Math.random() * 500)
createFilterAlert: ->
currentFilterSet = _.cloneDeep @filters
currentSavedFilters = _.cloneDeep me.get('savedEmployerFilterAlerts') ? []
currentSavedFilters.push currentFilterSet
@patchEmployerFilterAlerts currentSavedFilters, @renderSavedFilters
deleteFilterAlert: (e) ->
index = $(e.target).closest('tbody tr').data('filter-index')
currentSavedFilters = me.get('savedEmployerFilterAlerts')
currentSavedFilters.splice(index,1)
@patchEmployerFilterAlerts currentSavedFilters, @renderSavedFilters
patchEmployerFilterAlerts: (newFilters, cb) ->
me.set('savedEmployerFilterAlerts',newFilters)
unless me.isValid()
alert("There was an error setting the filter(me.isValid() returned false.) Reverting! Please notify team@codecombat.com.")
me.set 'savedEmployerFilterAlerts', me.previous('savedEmployerFilterAlerts')
else
triggerErrorAlert = -> alert("There was an error saving your filter alert! Please notify team@codecombat.com.")
res = me.save {"savedEmployerFilterAlerts": newFilters}, {patch: true, success: cb, error: triggerErrorAlert}
renderSavedFilters: =>
savedFilters = me.get('savedEmployerFilterAlerts')
unless savedFilters?.length then return $("#saved-filter-table").hide()
$("#saved-filter-table").show()
$("#saved-filter-table").find("tbody tr").remove()
for filter, index in savedFilters
$("#saved-filter-table tbody").append("""<tr data-filter-index="#{index}"><td>#{@generateFilterAlertDescription(filter)}</td><td class="deletion-col"><a>✗</a></td></tr> """)
generateFilterAlertDescription: (filter) =>
descriptionString = ""
for key in _.keys(filter).sort()
value = filter[key]
if key is "filterActive" or _.without(@defaultFilters[key],value...).length is 0 then continue
if descriptionString.length then descriptionString += ", "
descriptionString += value.join(", ")
if descriptionString.length is 0 then descriptionString = "Any new candidate"
return descriptionString
getActiveAndApprovedCandidates: => getActiveAndApprovedCandidates: =>
candidates = _.filter @candidates.models, (c) -> c.get('jobProfile').active candidates = _.filter @candidates.models, (c) -> c.get('jobProfile').active
return _.filter candidates, (c) -> c.get('jobProfileApproved') return _.filter candidates, (c) -> c.get('jobProfileApproved')

View file

@ -29,7 +29,7 @@ UserHandler = class UserHandler extends Handler
'name', 'photoURL', 'password', 'anonymous', 'wizardColor1', 'volume', 'name', 'photoURL', 'password', 'anonymous', 'wizardColor1', 'volume',
'firstName', 'lastName', 'gender', 'facebookID', 'gplusID', 'emails', 'firstName', 'lastName', 'gender', 'facebookID', 'gplusID', 'emails',
'testGroupNumber', 'music', 'hourOfCode', 'hourOfCodeComplete', 'preferredLanguage', 'testGroupNumber', 'music', 'hourOfCode', 'hourOfCodeComplete', 'preferredLanguage',
'wizard', 'aceConfig', 'autocastDelay', 'lastLevel', 'jobProfile' 'wizard', 'aceConfig', 'autocastDelay', 'lastLevel', 'jobProfile', 'savedEmployerFilterAlerts'
] ]
getEditableProperties: (req, document) -> getEditableProperties: (req, document) ->