Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single thumb pay slider. Fixes #334 #335

Merged
merged 2 commits into from
May 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 33 additions & 21 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 @@ -462,7 +463,6 @@ 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.init();
Expand Down Expand Up @@ -568,9 +568,9 @@ 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.start,
connect: (this.start.constructor === Array)?true:false,
behaviour: 'tap',
range: {
'min': [0, 50000],
'10%': [1000000, 100000],
Expand All @@ -583,22 +583,31 @@ window.Hasjob.PaySlider.prototype.init = function(){
})
});
this.slider.Link('lower').to($(this.minField));
this.slider.Link('upper').to($(this.maxField));
if (typeof this.maxField !== 'undefined') {
this.slider.Link('upper').to($(this.maxField));
};
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 startval = this.slider.val(), start;
if (startval.constructor === Array) {
start = [Hasjob.PaySlider.toNumeric(startval[0]), Hasjob.PaySlider.toNumeric(startval[1])];
} else {
start = Hasjob.PaySlider.toNumeric(startval);
};

this.slider.noUiSlider({
start: [start, end],
start: start,
connect: (start.constructor === Array)?true:false,
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));
if (typeof this.maxField !== 'undefined') {
this.slider.Link('upper').to($(this.maxField));
};
};

$(function() {
Expand Down Expand Up @@ -632,7 +641,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() + ' per year';
};
}
if (currencyLabel === 'Pay' && equityLabel !== '') {
payFieldLabel = 'Equity (%)';
Expand All @@ -642,7 +656,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 +693,9 @@ $(function() {
};

var paySlider = new Hasjob.PaySlider({
start: (Hasjob.Config && Hasjob.Config.pmin) || 0,
end: (Hasjob.Config && Hasjob.Config.pmax) || 10000000,
start: (Hasjob.Config && Hasjob.Config.pay) || 0,
selector: '#pay-slider',
minField: '#job-filters-pmin',
maxField: '#job-filters-pmax'
minField: '#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