Skip to content

Commit

Permalink
Use single thumb for pay range slider, for #334. Breaks job posting f…
Browse files Browse the repository at this point in the history
…orm.
  • Loading branch information
jace committed May 3, 2016
1 parent b6a9c6d commit 62fd657
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 40 deletions.
50 changes: 24 additions & 26 deletions hasjob/static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ window.Hasjob.Filters = {
selectedCategories: window.Hasjob.Config.selectedCategories,
selectedQuery: window.Hasjob.Config.selectedQuery,
selectedCurrency: window.Hasjob.Config.selectedCurrency,
pmin: window.Hasjob.Config.pmin,
pmax: window.Hasjob.Config.pmax,
pay: window.Hasjob.Config.pay,
equity: window.Hasjob.Config.equity,
sidebarOn: false
},
Expand Down Expand Up @@ -421,12 +420,15 @@ window.Hasjob.Filters = {
}
currencyVal = formParams[fpIndex].value;
}
// format pmin and pmax based on currency value
if (formParams[fpIndex].name === 'pmin' || formParams[fpIndex].name === 'pmax') {
// format pay based on currency value
if (formParams[fpIndex].name === 'pay') {
if (currencyVal === '') {
formParams[fpIndex].value = '';
} else {
formParams[fpIndex].value = Hasjob.PaySlider.toNumeric(formParams[fpIndex].value);
if (formParams[fpIndex].value === '0') {
formParams[fpIndex].value = '';
}
}
}
// remove empty values
Expand All @@ -447,8 +449,7 @@ window.Hasjob.Filters = {
selectedCategories: window.Hasjob.Config.selectedCategories,
selectedQuery: window.Hasjob.Config.selectedQuery,
selectedCurrency: window.Hasjob.Config.selectedCurrency,
pmin: window.Hasjob.Config.pmin,
pmax: window.Hasjob.Config.pmax,
pay: window.Hasjob.Config.pay,
equity: window.Hasjob.Config.equity
}).then(function() {
$('#job-filters-location').multiselect('rebuild');
Expand All @@ -461,10 +462,8 @@ window.Hasjob.Filters = {
window.Hasjob.PaySlider = function(options){
this.selector = options.selector;
this.slider = null;
this.start = options.start;
this.end = options.end;
this.minField = options.minField;
this.maxField = options.maxField;
this.pay = options.pay;
this.payField = options.payField;
this.init();
};

Expand Down Expand Up @@ -568,9 +567,8 @@ window.Hasjob.PaySlider.range = function(currency){

window.Hasjob.PaySlider.prototype.init = function(){
this.slider = $(this.selector).noUiSlider({
start: [this.start, this.end],
connect: true,
behaviour: "tap",
start: this.pay,
behaviour: 'tap',
range: {
'min': [0, 50000],
'10%': [1000000, 100000],
Expand All @@ -582,23 +580,20 @@ window.Hasjob.PaySlider.prototype.init = function(){
prefix: '¤'
})
});
this.slider.Link('lower').to($(this.minField));
this.slider.Link('upper').to($(this.maxField));
this.slider.Link('lower').to($(this.payField));
return this;
};

window.Hasjob.PaySlider.prototype.resetSlider = function(currency) {
var start = Hasjob.PaySlider.toNumeric(this.slider.val()[0]),
end = Hasjob.PaySlider.toNumeric(this.slider.val()[1]);
var pay = Hasjob.PaySlider.toNumeric(this.slider.val());

this.slider.noUiSlider({
start: [start, end],
start: pay,
range: Hasjob.PaySlider.range(window.Hasjob.Currency.prefix(currency)),
format: Hasjob.Currency.wNumbFormat(currency)
}, true);

this.slider.Link('lower').to($(this.minField));
this.slider.Link('upper').to($(this.maxField));
this.slider.Link('lower').to($(this.payField));
};

$(function() {
Expand Down Expand Up @@ -632,7 +627,12 @@ $(function() {
if (getCurrencyVal().toLowerCase() === 'na'){
currencyLabel = 'Pay';
} else {
currencyLabel = $('#job-filters-pmin').val() + ' - ' + $('#job-filters-pmax').val();
var payVal = Hasjob.PaySlider.toNumeric($('#job-filters-payval').val());
if (payVal === '0') {
currencyLabel = 'Pay ' + getCurrencyVal();
} else {
currencyLabel = $('#job-filters-payval').val();
};
}
if (currencyLabel === 'Pay' && equityLabel !== '') {
payFieldLabel = 'Equity (%)';
Expand All @@ -642,7 +642,7 @@ $(function() {
$('#job-filters-pay-text').html(payFieldLabel);
};

$('#job-filters-equity').on('change', function(){
$('#job-filters-equity').on('change', function() {
setPayTextField();
});

Expand Down Expand Up @@ -679,11 +679,9 @@ $(function() {
};

var paySlider = new Hasjob.PaySlider({
start: (Hasjob.Config && Hasjob.Config.pmin) || 0,
end: (Hasjob.Config && Hasjob.Config.pmax) || 10000000,
pay: (Hasjob.Config && Hasjob.Config.pay) || 0,
selector: '#pay-slider',
minField: '#job-filters-pmin',
maxField: '#job-filters-pmax'
payField: '#job-filters-payval'
});

$('#pay-slider').on('slide', function(){
Expand Down
3 changes: 1 addition & 2 deletions hasjob/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ <h2>What these jobs pay per annum</h2>
//For setting the pay slider
window.Hasjob.PayFilterParameters = {
'currency': {{ request.args.get('currency') | tojson }},
'pmin': {{ request.args.get('pmin') | tojson }},
'pmax': {{ request.args.get('pmax') | tojson }}
'pay': {{ request.args.get('pay') | tojson }},
};
$('textarea').autosize();
$("#newpost_details").hide().removeClass('jshidden');
Expand Down
3 changes: 1 addition & 2 deletions hasjob/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ <h1><a href="{{ url_for('index') }}">
</li>
<li class="pay-filter-slider">
<div>
<input type="hidden" name="pmin" id="job-filters-pmin">
<input type="hidden" name="pmax" id="job-filters-pmax">
<input type="hidden" name="pay" id="job-filters-payval">
<div id="pay-slider"></div>
</div>
</li>
Expand Down
3 changes: 1 addition & 2 deletions hasjob/templates/macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@ <h1 itemprop="name">{{ headline or post.headline }}</h1>
window.Hasjob.Config.selectedCategories = {{request.args.getlist('c') | tojson}};
window.Hasjob.Config.selectedQuery = {{request.args.getlist('q') | tojson}};
window.Hasjob.Config.selectedCurrency = {{request.args.get('currency') | tojson}};
window.Hasjob.Config.pmin = {{request.args.get('pmin') | tojson}};
window.Hasjob.Config.pmax = {{request.args.get('pmax') | tojson}};
window.Hasjob.Config.pay = {{request.args.get('pay') | tojson}};
window.Hasjob.Config.equity = {{request.args.get('equity') | tojson}};
</script>
{%- endwith %}
Expand Down
3 changes: 1 addition & 2 deletions hasjob/templates/postjob.html
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ <h2>Next, tell us about your organization</h2>
});

var cashslider = new Hasjob.PaySlider({
start: {{ (form.job_pay_cash_min.data or 0)|tojson }},
end: {{ (form.job_pay_cash_max.data or 10000000)|tojson }},
start: [{{ (form.job_pay_cash_min.data or 0)|tojson }}, {{ (form.job_pay_cash_max.data or 10000000)|tojson }}],
selector: "#cashslider",
minField: '#job_pay_cash_min',
maxField: '#job_pay_cash_max'
Expand Down
19 changes: 13 additions & 6 deletions hasjob/views/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,21 @@ def index(basequery=None, md5sum=None, tag=None, domain=None, location=None, tit
# Only works as a positive filter: you can't search for jobs that DON'T pay in equity
data_filters['equity'] = True
basequery = basequery.filter(JobPost.pay_equity_min != None) # NOQA
if 'pmin' in request.args and 'pmax' in request.args:
f_min = string_to_number(request.args['pmin'])
f_max = string_to_number(request.args['pmax'])
if f_min is not None and f_max is not None:
data_filters['pay_min'] = f_min
data_filters['pay_max'] = f_max
if 'pay' in request.args or ('pmin' in request.args and 'pmax' in request.args):
if 'pay' in request.args:
f_pay = string_to_number(request.args['pay'])
f_min = int(f_pay * 0.90)
f_max = int(f_pay * 1.30)
else:
# Legacy URL with min/max values
f_min = string_to_number(request.args['pmin'])
f_max = string_to_number(request.args['pmax'])
f_pay = f_min # Use min for pay now
if f_pay is not None and f_min is not None and f_max is not None:
data_filters['pay'] = f_pay
basequery = basequery.filter(JobPost.pay_cash_min < f_max, JobPost.pay_cash_max >= f_min)
else:
f_pay = None
f_min = None
f_max = None

Expand Down

0 comments on commit 62fd657

Please sign in to comment.