Skip to content

Commit

Permalink
- feature a bounty section is hidden for featured bounty
Browse files Browse the repository at this point in the history
- fixed broken invite by skill button
- update bounty amount for ETC bounties
  • Loading branch information
thelostone-mc committed Dec 26, 2019
1 parent e078fe3 commit a516408
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 128 deletions.
288 changes: 171 additions & 117 deletions app/assets/v2/js/pages/change_bounty.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
function trigger_form_hooks() {
}

let usersBySkills;
let processedData;

const populateFromAPI = bounty => {
bounty.is_featured ?
$('#featuredBounty').prop('checked', true) :
Expand Down Expand Up @@ -56,7 +59,103 @@ const populateFromAPI = bounty => {
}
};

const formatUser = user => {
if (!user.text || user.children) {
return user.text;
}

const markup = `
<div class="d-flex align-items-baseline">
<div class="mr-2">
<img class="rounded-circle" src="${'/dynamic/avatar/' + user.text }" width="20" height="20"/>
</div>
<div>${user.text}</div>
</div>`;

return markup;
};

const formatUserSelection = user => {
let selected;

if (user.id) {
selected = `
<img class="rounded-circle" src="${'/dynamic/avatar/' + user.text }" width="20" height="20"/>
<span class="ml-2">${user.text}</span>`;
} else {
selected = user.text;
}

return selected;
};

const getSuggestions = () => {

let keywords = $('#keywords').val();

const settings = {
url: `/api/v0.1/get_suggested_contributors?keywords=${keywords}`,
method: 'GET',
processData: false,
dataType: 'json',
contentType: false
};

$.ajax(settings).done(function(response) {
let groups = {
'contributors': 'Recently worked with you',
'recommended_developers': 'Recommended based on skills',
'verified_developers': 'Verified contributors'
};

let options = Object.entries(response).map(([ text, children ]) => (
{ text: groups[text], children }
));

usersBySkills = [].map.call(response['recommended_developers'], function(obj) {
return obj;
});

if (keywords.length && usersBySkills.length) {
$('#invite-all-container').show();
$('.select2-add_byskill span').text(keywords.join(', '));
} else {
$('#invite-all-container').hide();
}

let generalIndex = 0;

processedData = $.map(options, function(obj) {
if (obj.children.length < 1) {
return;
}

obj.children.forEach(children => {
children.text = children.fulfiller_github_username || children.user__profile__handle;
children.id = generalIndex;
generalIndex++;
});
return obj;
});

$('#invite-contributors').select2().empty();
$('#invite-contributors.js-select2').select2({
data: processedData,
placeholder: 'Select contributors',
escapeMarkup: function(markup) {
return markup;
},
templateResult: formatUser,
templateSelection: formatUserSelection
});

}).fail(function(error) {
console.log('Could not fetch contributors', error);
});
};

$(document).ready(function() {

const bounty = document.result;
const form = $('#submitBounty');

Expand All @@ -69,7 +168,7 @@ $(document).ready(function() {
});

$('[name=project_type]').on('change', function() {
let val = $('input[name=project_type]:checked').val();
const val = $('input[name=project_type]:checked').val();

if (val !== 'traditional') {
$('#reservedFor').attr('disabled', true);
Expand All @@ -81,7 +180,7 @@ $(document).ready(function() {
}).triggerHandler('change');

$('[name=permission_type]').on('change', function() {
let val = $('input[name=permission_type]:checked').val();
const val = $('input[name=permission_type]:checked').val();

if (val === 'approval') {
$('#admin_override_suspend_auto_approval').attr('disabled', false);
Expand All @@ -91,15 +190,64 @@ $(document).ready(function() {
}
}).triggerHandler('change');

const reservedForHandle = bounty.reserved_for_user_handle;
let usdFeaturedPrice = $('.featured-price-usd').text();
let ethFeaturedPrice;

getAmountEstimate(usdFeaturedPrice, 'ETH', function(amountEstimate) {
ethFeaturedPrice = amountEstimate['value'];
$('.featured-price-eth').text(`+${amountEstimate['value']} ETH`);
});

getSuggestions();
$('#keywords').on('change', getSuggestions);

$('.select2-tag__choice').on('click', function() {
$('#invite-contributors.js-select2').data('select2').dataAdapter.select(processedData[0].children[$(this).data('id')]);
});

$('.select2-add_byskill').on('click', function(e) {
e.preventDefault();
$('#invite-contributors.js-select2').val(usersBySkills.map((item) => {
return item.id;
})).trigger('change');
});

$('.select2-clear_invites').on('click', function(e) {
e.preventDefault();
$('#invite-contributors.js-select2').val(null).trigger('change');
});

const reservedForHandle = bounty.reserved_for_user_handle ? bounty.reserved_for_user_handle : [];

userSearch('#reservedFor', false, '', reservedForHandle, true);


userSearch(
'#reservedFor', // show address
false, // theme
'', // initial data
reservedForHandle ? [reservedForHandle] : [], // allowClear
true
);
setTimeout(setUsdAmount, 1000);

$('input[name=hours]').keyup(setUsdAmount);
$('input[name=hours]').blur(setUsdAmount);
$('input[name=amount]').keyup(setUsdAmount);

$('input[name=usd_amount]').on('focusin', function() {
$('input[name=usd_amount]').attr('prev_usd_amount', $(this).val());
$('input[name=amount]').trigger('change');
});

$('input[name=usd_amount]').on('focusout', function() {
$('input[name=usd_amount]').attr('prev_usd_amount', $(this).val());
$('input[name=amount]').trigger('change');
});

$('input[name=usd_amount]').keyup(() => {
const prev_usd_amount = $('input[name=usd_amount]').attr('prev_usd_amount');
const usd_amount = $('input[name=usd_amount').val();

$('input[name=amount]').trigger('change');

if (prev_usd_amount != usd_amount) {
usdToAmount(usd_amount);
}
});

form.validate({
errorPlacement: function(error, element) {
Expand All @@ -112,7 +260,7 @@ $(document).ready(function() {
ignore: '',
messages: {
select2Start: {
required: 'Please select the right keywords.'
required: 'Please select the keyword tags for this bounty.'
}
},
submitHandler: function(form) {
Expand All @@ -131,7 +279,6 @@ $(document).ready(function() {

loading_button($('.js-submit'));

// update bounty reserved for
const reservedFor = $('.username-search').select2('data')[0];
let inviteContributors = $('#invite-contributors.js-select2').select2('data').map((user) => {
return user.user__profile__id;
Expand All @@ -145,17 +292,23 @@ $(document).ready(function() {
formData['invite'] = inviteContributors;
}

if (formData['featuredBounty'] === '1') {
if (document.result.is_featured) {
formData['is_featured'] = true;
} else if (formData['featuredBounty'] === '1') {
formData['is_featured'] = true;
formData['featuring_date'] = new Date().getTime() / 1000;
} else {
formData['is_featured'] = false;
}

const token = tokenAddressToDetails(token_address);

formData['value_in_token'] = formData['amount'] * 10 ** token.decimals;

const bountyId = document.pk;
const payload = JSON.stringify(formData);

var payFeaturedBounty = function() {
const payFeaturedBounty = function() {
indicateMetamaskPopup();
web3.eth.sendTransaction({
to: '0x00De4B13153673BCAE2616b67bf822500d325Fc3',
Expand All @@ -182,7 +335,7 @@ $(document).ready(function() {
});
};

var saveBountyChanges = function() {
const saveBountyChanges = function() {
$.post('/bounty/change/' + bountyId, payload).then(
function(result) {
inputElements.removeAttr('disabled');
Expand All @@ -202,11 +355,10 @@ $(document).ready(function() {
inputElements.removeAttr('disabled');
unloading_button($('.js-submit'));

var alertMsg = result && result.responseJSON ? result.responseJSON.error : null;
const alertMsg = result && result.responseJSON ?
result.responseJSON.error :
'Something went wrong. Please reload the page and try again.';

if (alertMsg === null) {
alertMsg = gettext('Network error. Please reload the page and try again.');
}
_alert({ message: alertMsg }, 'error');
}
);
Expand All @@ -220,102 +372,4 @@ $(document).ready(function() {
}
});

let usdFeaturedPrice = $('.featured-price-usd').text();
let ethFeaturedPrice;

getAmountEstimate(usdFeaturedPrice, 'ETH', function(amountEstimate) {
ethFeaturedPrice = amountEstimate['value'];
$('.featured-price-eth').text(`+${amountEstimate['value']} ETH`);
});

var processedData;

$('.select2-tag__choice').on('click', function() {
$('#invite-contributors.js-select2').data('select2').dataAdapter.select(processedData[0].children[$(this).data('id')]);
});

$('#keywords').select2({
tags: true
}).trigger('change');

const getSuggestions = () => {

const settings = {
url: `/api/v0.1/get_suggested_contributors?keywords=${$('#keywords').val()}`,
method: 'GET',
processData: false,
dataType: 'json',
contentType: false
};

$.ajax(settings).done(function(response) {
let groups = {
'contributors': 'Recently worked with you',
'recommended_developers': 'Recommended based on skills',
'verified_developers': 'Verified contributors'
};

let options = Object.entries(response).map(([ text, children ]) => (
{ text: groups[text], children }
));

var generalIndex = 0;

processedData = $.map(options, function(obj, index) {
if (obj.children.length < 1) {
return;
}

obj.children.forEach((children, childIndex) => {
children.text = children.fulfiller_github_username || children.user__profile__handle;
children.id = generalIndex;
generalIndex++;
});
return obj;
});

$('#invite-contributors').select2().empty();
$('#invite-contributors.js-select2').select2({
data: processedData,
placeholder: 'Select contributors',
escapeMarkup: function(markup) {
return markup;
},
templateResult: formatUser,
templateSelection: formatUserSelection
});

}).fail(function(error) {
console.log('Could not fetch contributors', error);
});
};

getSuggestions();

function formatUser(user) {
if (!user.text || user.children) {
return user.text;
}
let markup = `<div class="d-flex align-items-baseline">
<div class="mr-2">
<img class="rounded-circle" src="${'/dynamic/avatar/' + user.text }" width="20" height="20"/>
</div>
<div>${user.text}</div>
</div>`;

return markup;
}

function formatUserSelection(user) {
let selected;

if (user.id) {
selected = `
<img class="rounded-circle" src="${'/dynamic/avatar/' + user.text }" width="20" height="20"/>
<span class="ml-2">${user.text}</span>`;
} else {
selected = user.text;
}
return selected;
}
});
1 change: 0 additions & 1 deletion app/assets/v2/js/pages/new_bounty.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ $(function() {
$('input[name=usd_amount]').on('focusout', function() {
$('input[name=usd_amount]').attr('prev_usd_amount', $(this).val());
$('input[name=amount]').trigger('change');

});

$('input[name=usd_amount]').keyup(() => {
Expand Down
9 changes: 5 additions & 4 deletions app/assets/v2/js/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -1028,10 +1028,11 @@ window.addEventListener('load', function() {
setInterval(listen_for_web3_changes, 1000);
});

var setUsdAmount = function(event) {
var amount = $('input[name=amount]').val();
var denomination = $('#token option:selected').text();
var estimate = getUSDEstimate(amount, denomination, function(estimate) {
var setUsdAmount = function() {
const amount = $('input[name=amount]').val();
const denomination = $('#token option:selected').text();

getUSDEstimate(amount, denomination, function(estimate) {
if (estimate['value']) {
$('#usd-amount-wrapper').css('visibility', 'visible');
$('#usd_amount_text').css('visibility', 'visible');
Expand Down
Loading

0 comments on commit a516408

Please sign in to comment.