From f100c4ebbe0e9bbf3d335c1760f9f7e12949599f Mon Sep 17 00:00:00 2001 From: Michael Schmatz Date: Mon, 21 Jul 2014 16:10:02 -0700 Subject: [PATCH] Add filter alerts to employer page --- app/schemas/models/user.coffee | 2 +- app/styles/employers.sass | 10 ++++++- app/templates/employers.jade | 10 ++++++- app/views/EmployersView.coffee | 47 ++++++++++++++++++++++++++++++-- server/users/user_handler.coffee | 2 +- 5 files changed, 64 insertions(+), 7 deletions(-) diff --git a/app/schemas/models/user.coffee b/app/schemas/models/user.coffee index 4796157f8..47a164b5c 100644 --- a/app/schemas/models/user.coffee +++ b/app/schemas/models/user.coffee @@ -181,7 +181,7 @@ _.extend UserSchema.properties, }, c.object({ title: 'Saved filter set' description: 'A saved filter set' - required: ['phoneScreenFilter','schoolFilter','locationFilter','roleFilter','seniorityFilter','visa','filterActive'] + required: ['phoneScreenFilter','schoolFilter','locationFilter','roleFilter','seniorityFilter','visa'] }, { phoneScreenFilter: title: 'Phone screen filter values' diff --git a/app/styles/employers.sass b/app/styles/employers.sass index 32c1d1de3..bc0fb4d21 100644 --- a/app/styles/employers.sass +++ b/app/styles/employers.sass @@ -63,7 +63,15 @@ cursor: pointer input 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 vertical-align: text-bottom margin-left: 10px diff --git a/app/templates/employers.jade b/app/templates/employers.jade index cc07bc618..bb689fa0d 100644 --- a/app/templates/employers.jade +++ b/app/templates/employers.jade @@ -90,7 +90,15 @@ block content p#results | #{numberOfCandidates} 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") if candidates.length diff --git a/app/views/EmployersView.coffee b/app/views/EmployersView.coffee index 9bbfa1ef6..57ca3c78f 100644 --- a/app/views/EmployersView.coffee +++ b/app/views/EmployersView.coffee @@ -20,15 +20,16 @@ module.exports = class EmployersView extends RootView template: template events: - 'click tbody tr': 'onCandidateClicked' + 'click #candidate-table': 'onCandidateClicked' 'click #logout-link': 'logoutAccount' 'change #filters input': 'onFilterChanged' - 'click #filter-button': 'applyFilters' 'change #select_all_checkbox': 'handleSelectAllChange' 'click .get-started-button': 'openSignupModal' 'click .navbar-brand': 'restoreBodyColor' 'click #login-link': 'onClickAuthbutton' 'click #filter-link': 'swapFolderIcon' + 'click #create-alert-button': 'createFilterAlert' + 'click .deletion-col': 'deleteFilterAlert' constructor: (options) -> super options @@ -39,6 +40,7 @@ module.exports = class EmployersView extends RootView afterRender: -> super() @sortTable() if @candidates.models.length + @renderSavedFilters() afterInsert: -> super() @@ -128,7 +130,46 @@ module.exports = class EmployersView extends RootView return (_.filter candidates, (c) -> c.get('jobProfile').curated?[filterName] is filterValue).length else 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("""#{@generateFilterAlertDescription(filter)} """) + + + 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: => candidates = _.filter @candidates.models, (c) -> c.get('jobProfile').active return _.filter candidates, (c) -> c.get('jobProfileApproved') diff --git a/server/users/user_handler.coffee b/server/users/user_handler.coffee index fbd13ec19..4a6e85320 100644 --- a/server/users/user_handler.coffee +++ b/server/users/user_handler.coffee @@ -29,7 +29,7 @@ UserHandler = class UserHandler extends Handler 'name', 'photoURL', 'password', 'anonymous', 'wizardColor1', 'volume', 'firstName', 'lastName', 'gender', 'facebookID', 'gplusID', 'emails', 'testGroupNumber', 'music', 'hourOfCode', 'hourOfCodeComplete', 'preferredLanguage', - 'wizard', 'aceConfig', 'autocastDelay', 'lastLevel', 'jobProfile' + 'wizard', 'aceConfig', 'autocastDelay', 'lastLevel', 'jobProfile', 'savedEmployerFilterAlerts' ] getEditableProperties: (req, document) ->