Skip to content

Commit

Permalink
Add dashboard for sponsors (#7064)
Browse files Browse the repository at this point in the history
* Add dashboard for sponsors

* Add dashboard for sponsors

* Restrict one prize

* fix overflow text

* Toggle description

* Update styles

* Add pay button for sponsor dashboard

* Update title to being a link

Co-authored-by: Dan Lipert <danlipert@gmail.com>
  • Loading branch information
zoek1 and danlipert authored Jul 28, 2020
1 parent c435440 commit 58d6daa
Show file tree
Hide file tree
Showing 8 changed files with 600 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
path('hackathon/<str:hackathon>/new/', dashboard.views.new_hackathon_bounty, name='new_hackathon_bounty'),
path('hackathon/<str:hackathon>/new', dashboard.views.new_hackathon_bounty, name='new_hackathon_bounty2'),
path('hackathon/<str:hackathon>/', dashboard.views.hackathon, name='hackathon'),
path('hackathon/dashboard/<str:hackathon>', dashboard.views.dashboard_sponsors, name='sponsors-dashboard'),
path('hackathon/<str:hackathon>', dashboard.views.hackathon, name='hackathon2'),
path('hackathon/<str:hackathon>/onboard/', dashboard.views.hackathon_onboard, name='hackathon_onboard2'),
path('hackathon/<str:hackathon>/<str:panel>/', dashboard.views.hackathon, name='hackathon'),
Expand Down Expand Up @@ -251,6 +252,7 @@
re_path(r'^hackathons/?$', dashboard.views.get_hackathons, name='get_hackathons4'),
url(r'^register_hackathon/', dashboard.views.hackathon_registration, name='hackathon_registration'),
path('api/v0.1/hackathon/<str:hackathon>/save/', dashboard.views.save_hackathon, name='save_hackathon'),
path('api/v1/hackathon/<str:hackathon>/prizes', dashboard.views.hackathon_prizes, name='hackathon_prizes'),
path('api/v0.1/hackathon/<str:hackathon>/showcase/', dashboard.views.showcase, name='hackathon_showcase'),

# action URLs
Expand Down Expand Up @@ -688,7 +690,7 @@
url(settings.GITHUB_EVENT_HOOK_URL, gitcoinbot.views.payload, name='payload'),
url(r'^impersonate/', include('impersonate.urls')),
url(r'^api/v0.1/hackathon_project/set_winner/', dashboard.views.set_project_winner, name='project_winner'),
url(r'^api/v0.1/hackathon_project/set_winner/', dashboard.views.set_project_winner, name='project_winner'),
url(r'^api/v0.1/hackathon_project/set_notes/', dashboard.views.set_project_notes, name='project_notes'),

# users
url(r'^api/v0.1/user_bounties/', dashboard.views.get_user_bounties, name='get_user_bounties'),
Expand Down
23 changes: 23 additions & 0 deletions app/assets/v2/js/pages/dashboard-hackathon.js
Original file line number Diff line number Diff line change
Expand Up @@ -928,11 +928,34 @@

}
},
computed: {
isSponsor: () => {
let vm = this;

if (document.contxt.is_staff) {
return true;
}

for (let i = 0; i < vm.hackathonSponsors.length; i++) {
if (vm.hackathonSponsors[i].org_name === document.contxt.github_handle) {
return true;
}
}

for (let i = 0; i < vm.prizeFounders.length; i++) {
if (vm.prizeFounders[i] === document.contxt.github_handle) {
return true;
}
}
return false;
}
},
data: () => ({
is_registered: document.is_registered,
activePanel: document.activePanel,
hackathonObj: document.hackathonObj,
hackathonSponsors: document.hackathonSponsors,
prizeFounders: document.prizeFounders,
hackathonProjects: [],
chatURL: document.chatURL,
hackHasEnded: document.displayShowcase
Expand Down
136 changes: 136 additions & 0 deletions app/assets/v2/js/pages/dashboard-sponsors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
(function($) {
$(function() {
window.hackathonApp = new Vue({
delimiters: [ '[[', ']]' ],
el: '#sponsors-app',
mounted() {
this.retrieveSponsorPrizes();
},
methods: {
markWinner: function($event, project, prizeIndex) {
let vm = this;
const url = '/api/v0.1/hackathon_project/set_winner/';
const markWinner = fetchData(url, 'POST', {
project_id: project.pk,
winner: $event ? 1 : 0
}, {'X-CSRFToken': vm.csrf});

vm.prizes[prizeIndex].submissions.forEach((submission, submissionIndex) => {
if (submission.pk !== project.pk && submission.winner) {
console.log(submission.pk);
console.log(project.pk);
const unmarkPreviousWinner = fetchData(url, 'POST', {
project_id: submission.pk,
winner: 0
}, {'X-CSRFToken': vm.csrf});

$.when(unmarkPreviousWinner).then(() => {
vm.$set(vm.prizes[prizeIndex].submissions[submissionIndex], 'winner', false);
});
}
});

$.when(markWinner).then(response => {
if (response.message) {
alert(response.message);
}
}).catch(err => {
console.log(err);
});
},
setNote: function($event, project) {
let vm = this;

const url = '/api/v0.1/hackathon_project/set_notes/';
const setNotes = fetchData(url, 'POST', {
project_id: project.pk,
notes: vm.comments[project.pk]
}, {'X-CSRFToken': vm.csrf});

$.when(setNotes).then(response => {
if (response.message) {
alert(response.message);
}
}).catch(err => {
console.log(err);
});
},
addNote: function(project) {
let vm = this;

vm.$set(vm.comments, project.pk, '');
},
getComment: function(project) {
let vm = this;

return vm.comments[project];
},
retrieveSponsorPrizes: function() {
const vm = this;
const hackathon = fetchData(`/api/v1/hackathon/${vm.hackathonObj['slug']}/prizes`);

$.when(hackathon).then((response) => {
for (let i = 0; i < response.prizes.length; i++) {
if (response.prizes[i].submissions.length) {
response.prizes[i].submissions.forEach((submission) => {
vm.$set(vm.comments, submission.pk, submission.extra.notes);
});
}
}
vm.prizes = response.prizes;
});
},
tabChange: function(input) {
let vm = this;

switch (input) {
default:
case 0:
newPathName = 'prizes';
break;
case 1:
newPathName = 'submissions';
break;
}
let newUrl = `/hackathon/dashboard/${vm.hackathonObj['slug']}/${newPathName}`;

history.pushState({}, `${vm.hackathonObj['slug']} - ${newPathName}`, newUrl);

},
start_and_end: function(str) {
if (str.length > 25) {
return str.substr(0, 8) + '...' + str.substr(str.length - 5, str.length);
}
return str;
},
getSummary: function(project) {
if (project.showDescription || project.summary.length < 177) {
return project.summary;
}
return `${project.summary.slice(0, 177)}...`;
},
toggleSummary: function(prizeIndex, submissionIndex) {
let vm = this;
const showDescription = !vm.prizes[prizeIndex].submissions[submissionIndex].showDescription;

vm.$set(vm.prizes[prizeIndex].submissions[submissionIndex], 'showDescription', showDescription);
}
},
computed: {
isMobileDevice() {
return this.windowWidth < 576;
}
},
data: () => ({
activePanel: document.activePanel,
hackathonObj: document.hackathonObj,
hackathonSponsors: document.hackathonSponsors,
hackathonProjects: [],
chatURL: document.chatURL,
prizes: [],
comments: [],
csrf: $("input[name='csrfmiddlewaretoken']").val() || ''
})
});
});
})(jQuery);
4 changes: 3 additions & 1 deletion app/assets/v2/js/vue-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ Vue.mixin({
},
methods: {
chatWindow: function(channel, dm) {
let vm = this;

dm = dm || channel ? channel.indexOf('@') >= 0 : false;
channel = channel || 'town-square';
let vm = this;

const hackathonTeamSlug = 'hackathons';
const gitcoinTeamSlug = 'gitcoin';
const isHackathon = (document.hackathon_id !== null);
Expand Down
27 changes: 27 additions & 0 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4893,6 +4893,33 @@ def url(self):
def get_absolute_url(self):
return self.url()

def to_json(self):
profiles = [
{
'handle': profile.handle,
'name': profile.name,
'email': profile.email,
'payout_address': profile.preferred_payout_address,
'url': profile.url,
'avatar': profile.active_avatar.avatar_url if profile.active_avatar else ''
} for profile in self.profiles.all()
]

return {
'pk': self.pk,
'name': self.name,
'logo': self.logo.url,
'badge': self.badge,
'profiles': profiles,
'work_url': self.work_url,
'summary': self.summary,
'status': self.status,
'message': self.message,
'chat_channel_id': self.chat_channel_id,
'winner': self.winner,
'extra': self.extra
}


class FeedbackEntry(SuperModel):
bounty = models.ForeignKey(
Expand Down
3 changes: 3 additions & 0 deletions app/dashboard/templates/dashboard/index-vue.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
<small class="hackathon-countdown text-uppercase">Hackathon Over</small>
{% endif %}
</p>
<a href="{% url "sponsors-dashboard" hackathon.slug %}" v-if="isSponsor" class="btn btn-gc-blue float-right mr-5">Sponsor dashboard</a>
</div>
</div>
<div class="col-12 col-xl-10 body hackathon-explorer">
Expand Down Expand Up @@ -817,6 +818,7 @@ <h4 class="font-bigger-1 font-weight-bold mb-3">[[hackathon.name]] Wall of Fame<
<script src='{% static "v2/js/vue-components.js" %}'></script>
{{orgs|json_script:"sponsor-list"}}
{{hackathon_obj|json_script:"hackathon-object"}}
{{prize_founders|json_script:"prize-founders"}}
<script>
$('body').bootstrapTooltip({
selector: '[data-toggle="tooltip"]'
Expand All @@ -829,6 +831,7 @@ <h4 class="font-bigger-1 font-weight-bold mb-3">[[hackathon.name]] Wall of Fame<
document.hackathon_id = "{{ hackathon.id | safe }}";
document.hackathonSponsors = JSON.parse(document.getElementById('sponsor-list').textContent);
document.hackathonObj = JSON.parse(document.getElementById('hackathon-object').textContent);
document.prizeFounders = JSON.parse(document.getElementById('prize-founders').textContent);
document.activePanel = parseInt({{panel | safe}});
document.chatURL = "{{ chat_url | safe}}";
document.displayShowcase = {{hackathon.display_showcase|yesno:"true,false" }}
Expand Down
Loading

0 comments on commit 58d6daa

Please sign in to comment.