diff --git a/assets/src/bundles/add_forge/index.js b/assets/src/bundles/add_forge/index.js new file mode 100644 --- /dev/null +++ b/assets/src/bundles/add_forge/index.js @@ -0,0 +1,29 @@ +/** + * Copyright (C) 2022 The Software Heritage developers + * See the AUTHORS file at the top-level directory of this distribution + * License: GNU Affero General Public License version 3, or any later version + * See top-level LICENSE file for more information + */ + +export function initAddForge() { + $(document).ready(() => { + // populateRequests + $('#requestForm').submit(function(event) { + event.preventDefault(); + + $.ajax({ + data: $(this).serialize(), + type: $(this).attr('method'), + url: $(this).attr('action'), + success: function(response) { + $('#userMessage').text('Your request has been submitted'); + $('#userMessage').addClass('badge-success'); + }, + error: function(request, status, error) { + $('#userMessage').text('Sorry following error happened, ' + error); + $('#userMessage').addClass('badge-danger'); + } + }); + }); + }); +} diff --git a/swh/web/add_forge_now/urls.py b/swh/web/add_forge_now/urls.py new file mode 100644 --- /dev/null +++ b/swh/web/add_forge_now/urls.py @@ -0,0 +1,7 @@ +from django.conf.urls import url + +from swh.web.add_forge_now import views + +urlpatterns = [ + url(r"^add/$", views.create_request, name="forge-add"), +] diff --git a/swh/web/add_forge_now/views.py b/swh/web/add_forge_now/views.py new file mode 100644 --- /dev/null +++ b/swh/web/add_forge_now/views.py @@ -0,0 +1,39 @@ +# Copyright (C) 2022 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU Affero General Public License version 3, or any later version +# See top-level LICENSE file for more information + +from django import forms +from django.shortcuts import render + +from swh.web.add_forge_now.models import Request as AddForgeRequest + +FORGE_TYPES = [ + ("cgit", "cgit"), + ("gitlab", "gitlab"), + ("heptapod", "heptapod"), + ("gitea", "gitea"), +] + + +class RequestForm(forms.Form): + forge_type = forms.ChoiceField(choices=FORGE_TYPES) + forge_type.widget.attrs.update({"class": "form-control"}) + forge_url = forms.CharField(label="Forge contact name", max_length=200) + forge_url.widget.attrs.update({"class": "form-control"}) + forge_contact_email = forms.EmailField(label="Forge contact email", max_length=100) + forge_contact_email.widget.attrs.update({"class": "form-control"}) + forge_contact_name = forms.CharField(label="Forge contact name", max_length=100) + forge_contact_name.widget.attrs.update({"class": "form-control"}) + forge_contact_comment = forms.CharField(label="Comment", widget=forms.Textarea) + forge_contact_comment.widget.attrs.update({"class": "form-control", "rows": "3"}) + + +def create_request(request): + request_form = RequestForm() + existing = AddForgeRequest.objects.all() + return render( + request, + "add_forge_now/create-request.html", + {"request_form": request_form, "existing": existing}, + ) diff --git a/swh/web/templates/add_forge_now/create-request.html b/swh/web/templates/add_forge_now/create-request.html new file mode 100644 --- /dev/null +++ b/swh/web/templates/add_forge_now/create-request.html @@ -0,0 +1,123 @@ +{% extends "../layout.html" %} + +{% comment %} +Copyright (C) 2022 The Software Heritage developers +See the AUTHORS file at the top-level directory of this distribution +License: GNU Affero General Public License version 3, or any later version +See top-level LICENSE file for more information +{% endcomment %} + +{% load render_bundle from webpack_loader %} +{% load static %} + +{% block header %} +{% render_bundle 'add_forge' %} +{% endblock %} + +{% block title %}{{ heading }} – Software Heritage archive{% endblock %} + +{% block navbar-content %} +
Date | +Type | +URL | +Status | +
---|---|---|---|
{{ each.submission_date }} | +{{ each.forge_type }} | +{{ each.forge_url }} | +{{ each.status }} | +
Save code now
+Add forge now
+ +