From d9eca98d6d77a25fb22ac461e42fa557a5a0d709 Mon Sep 17 00:00:00 2001 From: Adam Jones Date: Mon, 10 Jun 2019 11:15:14 +0100 Subject: [PATCH 01/12] Create initial campaign editor --- campaigns.html | 118 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 campaigns.html diff --git a/campaigns.html b/campaigns.html new file mode 100644 index 0000000..235e276 --- /dev/null +++ b/campaigns.html @@ -0,0 +1,118 @@ + + + + + + + Commons Mobile App Campaign Editor + + + + + +
+

Campaign editor

+ +
+

Config

+
+
+ + +
+
+ + +
+
+
+ +
+

Campaigns

+
+
+ +
+
+ +
+

Result

+

+			
+ +
+
+
+ + + + + + + + + \ No newline at end of file From b7a9f0cb7aba308d5a9bf256cf29aeeb9f4e89b1 Mon Sep 17 00:00:00 2001 From: Adam Jones Date: Sat, 15 Jun 2019 18:33:35 +0100 Subject: [PATCH 02/12] Add JSON validation to campaign editor --- campaigns.html | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/campaigns.html b/campaigns.html index 235e276..35e8825 100644 --- a/campaigns.html +++ b/campaigns.html @@ -38,6 +38,7 @@

Campaigns

Result


+			

@@ -48,10 +49,17 @@

Result

- + + \ No newline at end of file From 0c1cc85577adbdee08560349b8b72c004a8e5580 Mon Sep 17 00:00:00 2001 From: Adam Jones Date: Sat, 15 Jun 2019 19:40:16 +0100 Subject: [PATCH 07/12] Add link to edit on Github --- campaigns.html | 1 + 1 file changed, 1 insertion(+) diff --git a/campaigns.html b/campaigns.html index 0723ad5..c642442 100644 --- a/campaigns.html +++ b/campaigns.html @@ -52,6 +52,7 @@

Result


 			
+ Edit on GitHub
From 0756361c400c1bac5571ffd8ce1b58d58ed3412d Mon Sep 17 00:00:00 2001 From: Adam Jones Date: Mon, 17 Jun 2019 22:54:32 +0100 Subject: [PATCH 08/12] Improve buttons --- campaigns.html | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/campaigns.html b/campaigns.html index c642442..2ec5ce4 100644 --- a/campaigns.html +++ b/campaigns.html @@ -24,11 +24,16 @@

Campaign editor

Campaigns

-
- - - - +
+ + +
+ + +
From a5b9c8a0fd7b22b0d8c1be0842560fb6f0c7fb6a Mon Sep 17 00:00:00 2001 From: Adam Jones Date: Mon, 17 Jun 2019 23:45:50 +0100 Subject: [PATCH 09/12] Add import warning --- campaigns.html | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/campaigns.html b/campaigns.html index 2ec5ce4..b3d071a 100644 --- a/campaigns.html +++ b/campaigns.html @@ -30,8 +30,8 @@

Campaigns

@@ -161,6 +161,10 @@

Result

document.body.removeChild(textarea); } + function overwriteConfirm(f) { + if(confirm("Warning: importing will overwrite the current data. Do you want to proceed?")) f(); + } + function importFromPaste() { const result = prompt("Paste in campaigns.json"); if (result != null && result.trim() != "") importFromText(result); From 27ad367a29d8111909cb2dd1ef361e420926a257 Mon Sep 17 00:00:00 2001 From: Adam Jones Date: Mon, 17 Jun 2019 23:53:25 +0100 Subject: [PATCH 10/12] Add copy title button --- campaigns.html | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/campaigns.html b/campaigns.html index b3d071a..4f3bd9f 100644 --- a/campaigns.html +++ b/campaigns.html @@ -89,7 +89,12 @@

Result

- +
+ +
+ +
+
From 7009cf4b3082a857bc57faa5e8d97ae8d5a3351a Mon Sep 17 00:00:00 2001 From: Adam Jones Date: Tue, 18 Jun 2019 00:22:26 +0100 Subject: [PATCH 11/12] Improve responsive layouts --- campaigns.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/campaigns.html b/campaigns.html index 4f3bd9f..41b35dd 100644 --- a/campaigns.html +++ b/campaigns.html @@ -83,11 +83,11 @@

Result

const section = document.createElement("div"); const n = form.childElementCount; section.innerHTML = - `
+ `
-
+
@@ -96,17 +96,17 @@

Result

-
+
-
+
-
+
- +
`; section.classList.add("mt-3", "pt-3", "pb-2", "row", "campaign"); form.appendChild(section); From 1503bf0dff8a4f2e60af5d73e154c724776c3010 Mon Sep 17 00:00:00 2001 From: Adam Jones Date: Tue, 18 Jun 2019 00:22:36 +0100 Subject: [PATCH 12/12] Add arbitrary campaign removal ability --- campaigns.html | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/campaigns.html b/campaigns.html index 41b35dd..1e8c2b9 100644 --- a/campaigns.html +++ b/campaigns.html @@ -72,6 +72,7 @@

Result

const form = document.getElementById('form'); const result = document.getElementById('result'); const resultValidity = document.getElementById('resultValidity'); + let campaignCounter = 0; let validate = null; fetch('https://raw.githubusercontent.com/commons-app/campaigns/master/schema.json') .then(res => res.json()) @@ -81,7 +82,7 @@

Result

function addSection() { const section = document.createElement("div"); - const n = form.childElementCount; + const n = campaignCounter++; section.innerHTML = `
@@ -107,23 +108,32 @@

Result

+
+
+
`; section.classList.add("mt-3", "pt-3", "pb-2", "row", "campaign"); + section.id = `campaign${n}`; form.appendChild(section); document.getElementById('removeSectionButton').disabled = false; } - function removeSection() { - if (form.childElementCount == 0) return; + function removeSection(n) { + if (n == undefined) { + if (form.childElementCount == 0) throw new Error("No sections to remove"); + form.removeChild(form.children[form.childElementCount - 1]); + } else { + form.removeChild(document.getElementById(`campaign${n}`)); + } - form.removeChild(form.children[form.childElementCount - 1]); generateJSON(); - if (form.childElementCount == 0) document.getElementById('removeSectionButton').disabled = true; } function generateJSON() { - const campaigns = [...form.children].map((e, n) => ({ + const campaigns = [...form.children] + .map(e => e.id.slice(-1)) + .map(n => ({ "title": document.getElementById(`title${n}`).value, "description": document.getElementById(`description${n}`).value, "startDate": document.getElementById(`startDate${n}`).value, @@ -206,7 +216,8 @@

Result

document.getElementById('sortBy').value = parsed.config.sortBy; form.innerHTML = ""; - parsed.campaigns.forEach((campaign, n) => { + parsed.campaigns.forEach(campaign => { + const n = campaignCounter; addSection(); document.getElementById(`title${n}`).value = campaign.title; document.getElementById(`description${n}`).value = campaign.description;