Skip to content

stable -> master #5324

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

Merged
merged 46 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
22640e1
profile: fix leaderboard link
thelostone-mc Oct 4, 2019
62f2a90
a lot of new background/musiccs
owocki Oct 6, 2019
d383d24
Merge branch 'stable' of github.com:gitcoinco/web into stable
owocki Oct 6, 2019
875658c
newsletter 2019-10-12
ryan-shea Oct 11, 2019
ed94ab4
fix newsletter typo
danlipert Oct 11, 2019
dcfd929
a few small updates to gitcoin quests; since ppl are starting to play…
owocki Oct 11, 2019
6e3b6b0
announce web3 world
owocki Oct 11, 2019
f6ea443
makes leaderboard on quests purdy-er before launch monday
owocki Oct 13, 2019
65c10f9
one small change
owocki Oct 13, 2019
4633bc6
point awards
owocki Oct 13, 2019
1174e7b
adds point history
owocki Oct 13, 2019
ae6df38
messed up link
owocki Oct 13, 2019
4987296
fix for https://sentry.io/organizations/gitcoin/issues/1126203495
owocki Oct 14, 2019
9c6cf93
fixes https://sentry.io/organizations/gitcoin/issues/1239290401/
owocki Oct 14, 2019
ee0fb60
fix for https://gitcoincore.slack.com/archives/CAXQ7PT60/p15708247520…
owocki Oct 14, 2019
ba1411b
kudos transactions were duplicated
owocki Oct 14, 2019
c4cbf61
fix for https://github.com/gitcoinco/web/issues/5280
owocki Oct 14, 2019
9a3a64c
top bar fixes
owocki Oct 14, 2019
4cf4029
adds hackathons to nav/products page
owocki Oct 14, 2019
718403e
leaderboard now has a podium on it; and a few other fixes
owocki Oct 14, 2019
74f5536
moves email preferred address thing to bottom bc ppl were complaining…
owocki Oct 14, 2019
011cd23
always scroll all the way to the right of the heatmap
owocki Oct 14, 2019
ca65379
refactor of quests such that individual quest types are now possible
owocki Oct 15, 2019
752a6c6
fizz buzz (just kidding; updating the products page
owocki Oct 15, 2019
e75f68d
fizz buzz (just kidding; updating the products page
owocki Oct 15, 2019
fee1bc3
rezied logos in nav
thelostone-mc Oct 15, 2019
7e72213
compressing svgs
thelostone-mc Oct 15, 2019
fd651cc
remove humanize
thelostone-mc Oct 15, 2019
88f4bc0
Merge pull request #5320 from gitcoinco/kevin/hackathosn-nav
thelostone-mc Oct 15, 2019
c07af81
fixes bad 'earnings' value
owocki Oct 15, 2019
5d951a1
migrates existing quiz to its on encapsulated style
owocki Oct 15, 2019
abf354d
factors away commonalities between helpers in example/base quests
owocki Oct 15, 2019
ef9dfea
enables new quest_type for gitcoin quests
owocki Oct 15, 2019
73690c3
make fix
owocki Oct 15, 2019
0b81f02
several performance fixes for gitcoin quests
owocki Oct 15, 2019
30d9581
2nd times a charm
owocki Oct 15, 2019
e2f58c4
small cleanup fix
owocki Oct 15, 2019
371eb11
fixes kudos uploader https://gitcoincore.slack.com/archives/CAXCZR8K0…
owocki Oct 15, 2019
e74085a
adds the ability for ANYONE to submit a quest
owocki Oct 16, 2019
9afa741
a few small profile fixes
owocki Oct 16, 2019
5325632
a few more profile usefulness tweaks
owocki Oct 16, 2019
b95fb5e
dont show star ratings for orgs
owocki Oct 16, 2019
ab710fa
index page fix
owocki Oct 16, 2019
5c2b0e8
fixes art URL
owocki Oct 16, 2019
7dc6d4c
fixes kudos for alex so he can mint/sync kudos without engineering
owocki Oct 16, 2019
fce8e6c
resolve conflicts + create migrations
thelostone-mc Oct 16, 2019
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
Prev Previous commit
Next Next commit
refactor of quests such that individual quest types are now possible
  • Loading branch information
owocki committed Oct 15, 2019
commit ca653797421d97eced8c81b77462d9cdbf892330
12 changes: 12 additions & 0 deletions app/assets/v2/css/quests.css
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,9 @@ body.back3 .tl{
}
}
@media (max-width: 1028px) {
body.quest_battle{
background-size: 200% !important;
}
#leaderboard_hero{
background-size: 130%;
}
Expand All @@ -770,6 +773,9 @@ body.back3 .tl{
}
}
@media (max-width: 900px) {
body.quest_battle{
background-size: 250% !important;
}
#leaderboard_hero .inner_row {
width: 32%;
height: 350px;
Expand Down Expand Up @@ -811,6 +817,9 @@ body.back3 .tl{
}
}
@media (max-width: 768px) {
body.quest_battle{
background-size: 350% !important;
}
.hide_on_mobile{
display: none;
}
Expand Down Expand Up @@ -876,6 +885,9 @@ body.back3 .tl{

}
@media (max-width: 550px) {
body.quest_battle{
background-size: 400% !important;
}
.back_gradient {
background-size: 100% 600px !important;
}
Expand Down
20 changes: 20 additions & 0 deletions app/assets/v2/js/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ $(document).ready(function() {
});
}

// makes the reflink sticky
if (getParam('cb')) {
var cb = getParam('cb');
// only if user is not logged in tho

if (cb.indexOf('ref') != -1 && !document.contxt.github_handle) {
localStorage.setItem('cb', cb);
}
}

// if there exists a sticky reflink but the user navigated away from the link in the course of logging in...
if (localStorage.getItem('cb') && document.contxt.github_handle && !getParam('cb')) {
var this_url = new URL(document.location.href);

this_url.searchParams.append('cb', localStorage.getItem('cb'));
this_url.search = this_url.search.replace('%3A', ':');
localStorage.setItem('cb', '');
document.location.href = this_url;
}

var force_no_www = function() {
if (document.location.href.indexOf('https://www.gitcoin.co') != -1) {
var new_url = document.location.href.replace('www.gitcoin.co', 'gitcoin.co');
Expand Down
2 changes: 1 addition & 1 deletion app/assets/v2/js/pages/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ $(document).ready(function() {
}
$(e.currentTarget).toggleClass('turn');
});
$('#heatmap_parent').animate({ scrollLeft: "+=1000px" }, "fast");
$('#heatmap_parent').animate({ scrollLeft: '+=1000px' }, 'fast');
setupTabs('#activity-tabs');

const tabSection = document.querySelector('#activity-tabs-sections');
Expand Down
42 changes: 42 additions & 0 deletions app/assets/v2/js/pages/quests.index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

$(document).ready(function() {

$('#reflink').click(function() {
$(this).focus();
$(this).select();
document.execCommand('copy');
$(this).after('<div class=after_copy>Copied to clipboard</div>');
setTimeout(function() {
$('.after_copy').remove();
}, 500);
});

$('.demo').click(function(e) {
e.preventDefault();
$(this).fadeOut(function() {
$('.demo').fadeIn();
var src = $('.demo').attr('src') + '?';

$('.demo').attr('src', src);
});
});

$('#tabs a').click(function(e) {
e.preventDefault();
var target = $(this).data('href');

$('.difficulty_tab').addClass('hidden');
$('.nav-link').removeClass('active');
$(this).addClass('active');
$('.difficulty_tab.' + target).removeClass('hidden');
});

$('.quest-card.available').click(function(e) {
e.preventDefault();
document.location.href = $(this).find('a').attr('href');
});
$('.quest-card.available').mouseover(function(e) {
random_attn_effect($(this).find('.btn'));
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -310,63 +310,6 @@ $(document).ready(function() {
}
}, 100);

$('#reflink').click(function() {
$(this).focus();
$(this).select();
document.execCommand('copy');
$(this).after('<div class=after_copy>Copied to clipboard</div>');
setTimeout(function() {
$('.after_copy').remove();
}, 500);
});

$('.demo').click(function(e) {
e.preventDefault();
$(this).fadeOut(function() {
$('.demo').fadeIn();
var src = $('.demo').attr('src') + '?';

$('.demo').attr('src', src);
});
});

$('#tabs a').click(function(e) {
e.preventDefault();
var target = $(this).data('href');

$('.difficulty_tab').addClass('hidden');
$('.nav-link').removeClass('active');
$(this).addClass('active');
$('.difficulty_tab.' + target).removeClass('hidden');
});

$('.quest-card.available').click(function(e) {
e.preventDefault();
document.location.href = $(this).find('a').attr('href');
});
$('.quest-card.available').mouseover(function(e) {
random_attn_effect($(this).find('.btn'));
});

// makes the reflink sticky
if (getParam('cb')) {
var cb = getParam('cb');
// only if user is not logged in tho

if (cb.indexOf('ref') != -1 && !document.contxt.github_handle) {
localStorage.setItem('cb', cb);
}
}
// if there exists a sticky reflink but the user navigated away from the link in the course of logging in...
if (localStorage.getItem('cb') && document.contxt.github_handle && !getParam('cb')) {
var url = new URL(document.location.href);

url.searchParams.append('cb', localStorage.getItem('cb'));
url.search = url.search.replace('%3A', ':');
localStorage.setItem('cb', '');
document.location.href = url;
}

if ($('#protagonist').length) {
var preload_assets = async function() {
var items = [ 'stage_4', 'question_number_1', 'question_number_2' ];
Expand Down Expand Up @@ -395,4 +338,5 @@ $(document).ready(function() {
if (document.quest) {
start_quest();
}

});
2 changes: 1 addition & 1 deletion app/quests/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class QuestAdmin(admin.ModelAdmin):
raw_id_fields = ['kudos_reward', 'unlocked_by']
raw_id_fields = ['kudos_reward', 'unlocked_by', 'creator']
ordering = ['-id']
list_display = ['created_on', '__str__']

Expand Down
188 changes: 188 additions & 0 deletions app/quests/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@

import logging
import random

from django.conf import settings
from django.db.models import Count
from django.shortcuts import redirect, render
from django.utils import timezone

from dashboard.models import Activity
from inbox.utils import send_notification_to_user
from kudos.models import BulkTransferCoupon, BulkTransferRedemption, Token
from kudos.views import get_profile
from quests.models import Quest, QuestAttempt, QuestPointAward

logger = logging.getLogger(__name__)

max_ref_depth = 4

def record_quest_activity(quest, associated_profile, event_name, override_created=None):
"""
Creates activity feeds from people doing quests.
"""

kwargs = {
'created_on': timezone.now() if not override_created else override_created,
'activity_type': event_name,
'profile': associated_profile,
'metadata': {
'quest_url': quest.url,
'quest_title': quest.title,
'quest_reward': quest.enemy_img_url if quest.enemy_img_url else None,
}
}

try:
Activity.objects.create(**kwargs)
except Exception as e:
logger.exception(e)


def record_award_helper(qa, profile, layer=1):
"""
Awards point awards (and referral rewards) to a winner
"""

#max depth
if layer > max_ref_depth:
return

# record points
value = 1/(2**(layer-1))
QuestPointAward.objects.create(
questattempt=qa,
profile=profile,
value=value
)

# record kudos
if layer > 1 or settings.DEBUG:
gitcoinbot = get_profile('gitcoinbot')
quest = qa.quest
btc = BulkTransferCoupon.objects.create(
token=quest.kudos_reward,
tag='quest',
num_uses_remaining=1,
num_uses_total=1,
current_uses=0,
secret=random.randint(10**19, 10**20),
comments_to_put_in_kudos_transfer=f"Congrats on beating the '{quest.title}' Gitcoin Quest",
sender_profile=gitcoinbot,
metadata={
'recipient': profile.pk,
}
)
cta_url = btc.url
cta_text = 'Redeem Kudos'
msg_html = f"@{qa.profile.handle} just beat '{qa.quest.title}'. You earned {round(value,2)} quest points & a kudos for referring them."
send_notification_to_user(gitcoinbot.user, profile.user, cta_url, cta_text, msg_html)

# recursively record points for your referals quest
if profile.referrer:
return record_award_helper(qa, profile.referrer, layer+1)


def process_start(request, quest):
"""
Processes the start of the quest oh behalf of the user
"""
QuestAttempt.objects.create(
quest=quest,
success=False,
profile=request.user.profile,
state=0,
)
record_quest_activity(quest, request.user.profile, 'played_quest')


def process_win(request, qa):
"""
Processes the win on behalf of the user
"""
quest = qa.quest
was_already_beaten = quest.is_beaten(request.user)
first_time_beaten = not was_already_beaten
record_quest_activity(quest, request.user.profile, 'beat_quest')
btcs = BulkTransferCoupon.objects.filter(
token=quest.kudos_reward,
tag='quest',
metadata__recipient=request.user.profile.pk)
btc = None
if btcs.exists():
btc = btcs.first()
else:
btc = BulkTransferCoupon.objects.create(
token=quest.kudos_reward,
tag='quest',
num_uses_remaining=1,
num_uses_total=1,
current_uses=0,
secret=random.randint(10**19, 10**20),
comments_to_put_in_kudos_transfer=f"Congrats on beating the '{quest.title}' Gitcoin Quest",
sender_profile=get_profile('gitcoinbot'),
metadata={
'recipient': request.user.profile.pk,
},
)
prize_url = f"{btc.url}?cb=ref:{request.user.profile.ref_code}&tweet_url={settings.BASE_URL}{quest.url}&tweet=I just won a {quest.kudos_reward.humanized_name} Kudos by beating the '{quest.title} Quest' on @gitcoin quests."
qa.success = True
qa.save()
if first_time_beaten:
record_award_helper(qa, qa.profile)
return prize_url

def get_leaderboard(max_entries=25):
"""
Gets the leaderboard that will be shown on /quests landing page
"""



#setup
kudos_to_show_per_leaderboard_entry = 5
leaderboard = {}

#pull totals for each qpa
for qpa in QuestPointAward.objects.all():
key = qpa.profile.handle
if key not in leaderboard.keys():
leaderboard[key] = 0
leaderboard[key] += qpa.value
leaderboard = sorted(leaderboard.items(), key=lambda x: x[1], reverse=True)

# add kudos to each leadervoard item
return_leaderboard = []
reward_kudos = {
1: 621,
2: 618,
3: 622,
}

# assemble leaderboard
counter = 0
for ele in leaderboard:
counter += 1
btr = BulkTransferRedemption.objects.filter(coupon__tag='quest',redeemed_by__handle=ele[0]).order_by('-created_on')
kudii = list(set([(_ele.coupon.token.img_url, _ele.coupon.token.humanized_name) for _ele in btr]))[:kudos_to_show_per_leaderboard_entry]
display_pts = int(ele[1]) if not ele[1] % 1 else round(ele[1],1)
reward_kudos_pk = reward_kudos.get(counter)
reward_kudos_url = Token.objects.get(pk=reward_kudos_pk) if reward_kudos_pk else None
this_ele = [ele[0], display_pts, kudii, reward_kudos_url, counter]
return_leaderboard.append(this_ele)

# return values
leaderboard_hero = return_leaderboard
if len(leaderboard) < 3:
leaderboard_hero = []
else:
leaderboard = leaderboard[3:]
# swap locationms of 1 and 2
tmp = None
tmp = leaderboard_hero[0]
leaderboard_hero[0] = leaderboard_hero[1]
leaderboard_hero[1] = tmp
leaderboard_hero = leaderboard_hero[:3]

return_leaderboard = return_leaderboard[:max_entries]
return return_leaderboard, leaderboard_hero
Loading