diff --git a/app/app/urls.py b/app/app/urls.py index 917231c7d40..9c34733d88c 100644 --- a/app/app/urls.py +++ b/app/app/urls.py @@ -247,6 +247,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//save/', dashboard.views.save_hackathon, name='save_hackathon'), + path('api/v0.1/hackathon//resource/', dashboard.views.hackathon_resource, name='hackathon_resource'), # action URLs url(r'^funder', retail.views.funder_bounties_redirect, name='funder_bounties_redirect'), diff --git a/app/assets/v2/js/pages/dashboard-hackathon.js b/app/assets/v2/js/pages/dashboard-hackathon.js index dace643354b..5cbd2ffe21e 100644 --- a/app/assets/v2/js/pages/dashboard-hackathon.js +++ b/app/assets/v2/js/pages/dashboard-hackathon.js @@ -915,6 +915,9 @@ case 4: newPathName = 'participants'; break; + case 5: + newPathName = 'about'; + break; } let newUrl = `/hackathon/${vm.hackathonObj['slug']}/${newPathName}/${window.location.search}`; diff --git a/app/assets/v2/js/vue-components.js b/app/assets/v2/js/vue-components.js index 7a1c8a25d93..d5270d50200 100644 --- a/app/assets/v2/js/vue-components.js +++ b/app/assets/v2/js/vue-components.js @@ -185,6 +185,106 @@ Vue.component('tribes-settings', { methods: {} }); +Vue.component('about-hackathon', { + delimiters: [ '[[', ']]' ], + props: [], + data: () => ({ + is_registered: document.is_registered, + activePanel: document.activePanel, + hackathonObj: document.hackathonObj, + documentation: document.documentation || [], + quests: document.quests || [], + workshops: document.workshops || [], + new_quest_text: '', + new_quest_url: '', + new_work_url: '', + new_work_text: '', + new_doc_url: '', + new_doc_text: '' + }), + mounted() { + this.fetchResources(); + }, + methods: { + goTo: function(section, event) { + event.preventDefault(); + document.getElementById(section).scrollIntoView(); + }, + fetchResources: function() { + let vm = this; + const resource_url = `/api/v0.1/hackathon/${document.hackathonObj.id}/resource/`; + const retrieveResources = fetchData(resource_url, 'GET', {}, {'X-CSRFToken': vm.csrf}); + + $.when(retrieveResources).then((response) => { + vm.documentation = response.resources.filter(resource => resource.type === 'documentation'); + vm.quests = response.resources.filter(resource => resource.type === 'quest'); + vm.workshops = response.resources.filter(resource => resource.type === 'workshop'); + }).fail((error) => { + console.log(error); + }); + }, + remove_resource: function(resource, name, event) { + event.preventDefault(); + let vm = this; + + const resource_url = `/api/v0.1/hackathon/${document.hackathonObj.id}/resource/`; + const sendJoin = fetchData(resource_url, 'POST', { + resource: resource, + name: name, + action: 'delete' + }, {'X-CSRFToken': vm.csrf}); + + $.when(sendJoin).then((response) => { + console.log(vm); + vm.fetchResources(); + }).fail((error) => { + _alert(`Failed to update ${resource}`); + console.log(error); + }); + }, + add_resource: function(resource, name, url, event) { + event.preventDefault(); + let vm = this; + + if (name.length === 0) { + _alert(`The ${resource} name is missing`, 'warning'); + return; + } + + if (url.length === 0) { + _alert(`The ${resource} url is missing`, 'warning'); + return; + } + + + const resource_url = `/api/v0.1/hackathon/${document.hackathonObj.id}/resource/`; + const sendJoin = fetchData(resource_url, 'POST', { + resource: resource, + name: name, + url: url + }, {'X-CSRFToken': vm.csrf}); + + $.when(sendJoin).then((response) => { + vm.documentation = response.resources.filter(resource => resource.type === 'documentation'); + vm.quests = response.resources.filter(resource => resource.type === 'quest'); + vm.workshops = response.resources.filter(resource => resource.type === 'workshop'); + if (resource === 'quest') { + vm.new_quest_text = ''; + vm.new_quest_url = ''; + } else if (resource === 'documentation') { + vm.new_doc_url = ''; + vm.new_doc_text = ''; + } else if (resource === 'workshop') { + vm.new_work_url = ''; + vm.new_work_text = ''; + } + }).fail((error) => { + _alert(`Failed to update ${resource}`); + console.log(error); + }); + } + } +}); Vue.component('project-directory', { delimiters: [ '[[', ']]' ], diff --git a/app/dashboard/migrations/0116_hackathonevent_resources.py b/app/dashboard/migrations/0116_hackathonevent_resources.py new file mode 100644 index 00000000000..71f6e59a9ef --- /dev/null +++ b/app/dashboard/migrations/0116_hackathonevent_resources.py @@ -0,0 +1,20 @@ +# Generated by Django 2.2.4 on 2020-05-27 13:17 + +import django.contrib.postgres.fields +import django.contrib.postgres.fields.jsonb +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('dashboard', '0115_merge_20200527_0856'), + ] + + operations = [ + migrations.AddField( + model_name='hackathonevent', + name='resources', + field=django.contrib.postgres.fields.ArrayField(base_field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, default=dict, null=True), blank=True, default=list, size=None), + ), + ] diff --git a/app/dashboard/models.py b/app/dashboard/models.py index fcab638b03b..b1b66c04cdb 100644 --- a/app/dashboard/models.py +++ b/app/dashboard/models.py @@ -3127,7 +3127,7 @@ def get_desc(self, funded_bounties, fulfilled_bounties): return f"@{self.handle} is a {role} who has participated in {total_funded_participated} " \ f"transaction{plural} on Gitcoin" - + @property def desc(self): @@ -4560,6 +4560,7 @@ class HackathonEvent(SuperModel): chat_channel_id = models.CharField(max_length=255, blank=True, null=True) visible = models.BooleanField(help_text=_('Can this HackathonEvent be seeing on /hackathons ?'), default=True) default_channels = ArrayField(models.CharField(max_length=255), blank=True, default=list) + resources = ArrayField(JSONField(default=dict, blank=True, null=True), blank=True, default=list) objects = HackathonEventQuerySet.as_manager() def __str__(self): diff --git a/app/dashboard/templates/dashboard/index-vue.html b/app/dashboard/templates/dashboard/index-vue.html index f406bb4669f..13732c7062f 100644 --- a/app/dashboard/templates/dashboard/index-vue.html +++ b/app/dashboard/templates/dashboard/index-vue.html @@ -385,7 +385,7 @@

Hackathon Coming Soon!

- +