From bb79efcb4a10d341024951ae8cecb273229fd6f2 Mon Sep 17 00:00:00 2001 From: Eren Yener Date: Thu, 11 May 2023 09:56:31 +0300 Subject: [PATCH 01/13] init admin --- admin/.clasp.json | 1 + admin/Code.js | 3 +++ admin/README.md | 3 +++ admin/appsscript.json | 7 +++++++ 4 files changed, 14 insertions(+) create mode 100644 admin/.clasp.json create mode 100644 admin/Code.js create mode 100644 admin/README.md create mode 100644 admin/appsscript.json diff --git a/admin/.clasp.json b/admin/.clasp.json new file mode 100644 index 0000000..e1e41e5 --- /dev/null +++ b/admin/.clasp.json @@ -0,0 +1 @@ +{"scriptId":"1ayOszkKcVSChNjDGnC2V2gx5zOqe7LrC6MdQC6WsR30Vhtv1phLkWpeM","rootDir":"/Users/eren.yener/Desktop/repo/erenyener/codex/admin"} diff --git a/admin/Code.js b/admin/Code.js new file mode 100644 index 0000000..f8f2594 --- /dev/null +++ b/admin/Code.js @@ -0,0 +1,3 @@ +function myFunction() { + +} diff --git a/admin/README.md b/admin/README.md new file mode 100644 index 0000000..8a3a3d0 --- /dev/null +++ b/admin/README.md @@ -0,0 +1,3 @@ +# Codex Admin Appscripts + +[Panel Link](https://docs.google.com/spreadsheets/d/1TSYzDuSMnv_3uVRcM7o0tNyUdRlKy3C6gFHKMVh5fjc/edit#gid=0) \ No newline at end of file diff --git a/admin/appsscript.json b/admin/appsscript.json new file mode 100644 index 0000000..c088c19 --- /dev/null +++ b/admin/appsscript.json @@ -0,0 +1,7 @@ +{ + "timeZone": "Europe/Istanbul", + "dependencies": { + }, + "exceptionLogging": "STACKDRIVER", + "runtimeVersion": "V8" +} \ No newline at end of file From c0d6b04c174c8168ba7b90bcf53cc6d2c1cdd510 Mon Sep 17 00:00:00 2001 From: erenyener Date: Thu, 11 May 2023 10:09:31 +0300 Subject: [PATCH 02/13] update readme --- admin/README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/admin/README.md b/admin/README.md index 8a3a3d0..5e78397 100644 --- a/admin/README.md +++ b/admin/README.md @@ -1,3 +1,8 @@ # Codex Admin Appscripts -[Panel Link](https://docs.google.com/spreadsheets/d/1TSYzDuSMnv_3uVRcM7o0tNyUdRlKy3C6gFHKMVh5fjc/edit#gid=0) \ No newline at end of file +[Panel Link](https://docs.google.com/spreadsheets/d/1TSYzDuSMnv_3uVRcM7o0tNyUdRlKy3C6gFHKMVh5fjc/edit#gid=0) + +#### Development + + +#### How to \ No newline at end of file From 13ae2a1293cfcdcd539fe202a1a138abf5306ea0 Mon Sep 17 00:00:00 2001 From: erenyener Date: Thu, 11 May 2023 10:54:57 +0300 Subject: [PATCH 03/13] claspignore added --- admin/.claspignore | 5 +++++ admin/src/main.js | 3 +++ 2 files changed, 8 insertions(+) create mode 100644 admin/.claspignore create mode 100644 admin/src/main.js diff --git a/admin/.claspignore b/admin/.claspignore new file mode 100644 index 0000000..de04126 --- /dev/null +++ b/admin/.claspignore @@ -0,0 +1,5 @@ +**/** +.git +.doc +!src/** +!appsscript.json \ No newline at end of file diff --git a/admin/src/main.js b/admin/src/main.js new file mode 100644 index 0000000..5711e5d --- /dev/null +++ b/admin/src/main.js @@ -0,0 +1,3 @@ +function myFunction1() { + Logger.log("my function") +} From da8aa201dd31553ef069b90d43719c38b1c322eb Mon Sep 17 00:00:00 2001 From: erenyener Date: Fri, 12 May 2023 11:12:18 +0300 Subject: [PATCH 04/13] Controllers Added --- admin/Code.js | 3 --- admin/README.md | 23 +++++++++++++++++-- admin/src/controllers/problem.controller.js | 6 +++++ admin/src/controllers/test.controller.js | 6 +++++ admin/src/main.js | 25 +++++++++++++++++++-- 5 files changed, 56 insertions(+), 7 deletions(-) delete mode 100644 admin/Code.js create mode 100644 admin/src/controllers/problem.controller.js create mode 100644 admin/src/controllers/test.controller.js diff --git a/admin/Code.js b/admin/Code.js deleted file mode 100644 index f8f2594..0000000 --- a/admin/Code.js +++ /dev/null @@ -1,3 +0,0 @@ -function myFunction() { - -} diff --git a/admin/README.md b/admin/README.md index 5e78397..59bda9f 100644 --- a/admin/README.md +++ b/admin/README.md @@ -1,8 +1,27 @@ # Codex Admin Appscripts + +## Quick Links [Panel Link](https://docs.google.com/spreadsheets/d/1TSYzDuSMnv_3uVRcM7o0tNyUdRlKy3C6gFHKMVh5fjc/edit#gid=0) -#### Development +## Install + +First download `clasp`: + +```sh +npm install -g @google/clasp +``` + +Then enable the Google Apps Script API: https://script.google.com/home/usersettings + +![Enable Apps Script API](https://user-images.githubusercontent.com/744973/54870967-a9135780-4d6a-11e9-991c-9f57a508bdf0.gif) + + +## Commands + +```sh +clasp login (Login with your LDAP) +clasp pull (Get Latest Code From Google Cloud Scripts) -#### How to \ No newline at end of file +``` \ No newline at end of file diff --git a/admin/src/controllers/problem.controller.js b/admin/src/controllers/problem.controller.js new file mode 100644 index 0000000..01b3d98 --- /dev/null +++ b/admin/src/controllers/problem.controller.js @@ -0,0 +1,6 @@ +function ProblemController() { } + + +ProblemController.prototype.renderAddProblemModal = function(personName) { + Logger.log("renderAddProblemModal") +} diff --git a/admin/src/controllers/test.controller.js b/admin/src/controllers/test.controller.js new file mode 100644 index 0000000..ac53560 --- /dev/null +++ b/admin/src/controllers/test.controller.js @@ -0,0 +1,6 @@ +function TestController() { } + + +TestController.prototype.renderAddTestsModal = function(personName) { + Logger.log("renderAddTestsModal") +} diff --git a/admin/src/main.js b/admin/src/main.js index 5711e5d..c33a242 100644 --- a/admin/src/main.js +++ b/admin/src/main.js @@ -1,3 +1,24 @@ -function myFunction1() { - Logger.log("my function") +function onOpen() { + renderMenu(); } + +function renderMenu() { + + const ui = SpreadsheetApp.getUi(); + + ui.createMenu('Codex Addon') + .addItem('Add Problem', 'addProblem') + .addItem('Add Tests', 'addTests') + .addToUi(); +} + + +function addProblem() { + const problemController = new ProblemController(); + problemController.renderAddProblemModal(); +} + +function addTests() { + const testController = new TestController(); + testController.renderAddTestsModal(); +} \ No newline at end of file From 736e138c095ff7aec7b1cf95f1a3a12303a25aa0 Mon Sep 17 00:00:00 2001 From: erenyener Date: Fri, 12 May 2023 11:17:51 +0300 Subject: [PATCH 05/13] empty modals added --- admin/src/controllers/problem.controller.js | 16 ++++++++++++++-- admin/src/controllers/test.controller.js | 14 +++++++++++++- admin/src/views/add-new-problem.html | 1 + admin/src/views/add-new-tests.html | 0 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 admin/src/views/add-new-problem.html create mode 100644 admin/src/views/add-new-tests.html diff --git a/admin/src/controllers/problem.controller.js b/admin/src/controllers/problem.controller.js index 01b3d98..54acf13 100644 --- a/admin/src/controllers/problem.controller.js +++ b/admin/src/controllers/problem.controller.js @@ -1,6 +1,18 @@ function ProblemController() { } -ProblemController.prototype.renderAddProblemModal = function(personName) { - Logger.log("renderAddProblemModal") +ProblemController.prototype.renderAddProblemModal = function() { + + const addProblemModalHtml = HtmlService + .createTemplateFromFile('src/views/add-new-problem') + .evaluate() + .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL) + .getContent(); + + const template = HtmlService.createTemplate(addProblemModalHtml) + .evaluate() + .setWidth(600) + .setHeight(550); + + SpreadsheetApp.getUi().showModalDialog(template, 'Add New Problem'); } diff --git a/admin/src/controllers/test.controller.js b/admin/src/controllers/test.controller.js index ac53560..c14f571 100644 --- a/admin/src/controllers/test.controller.js +++ b/admin/src/controllers/test.controller.js @@ -1,6 +1,18 @@ function TestController() { } -TestController.prototype.renderAddTestsModal = function(personName) { +TestController.prototype.renderAddTestsModal = function() { Logger.log("renderAddTestsModal") + const addNewTestsHtml = HtmlService + .createTemplateFromFile('src/views/add-new-tests') + .evaluate() + .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL) + .getContent(); + + const template = HtmlService.createTemplate(addNewTestsHtml) + .evaluate() + .setWidth(600) + .setHeight(550); + + SpreadsheetApp.getUi().showModalDialog(template, 'Add New Tests'); } diff --git a/admin/src/views/add-new-problem.html b/admin/src/views/add-new-problem.html new file mode 100644 index 0000000..b4345f3 --- /dev/null +++ b/admin/src/views/add-new-problem.html @@ -0,0 +1 @@ +HELLO FROM ADD NEW PROBLEM \ No newline at end of file diff --git a/admin/src/views/add-new-tests.html b/admin/src/views/add-new-tests.html new file mode 100644 index 0000000..e69de29 From ddff0c3544bb9d28c4dd8363255df07d7bcbd0a3 Mon Sep 17 00:00:00 2001 From: erenyener Date: Fri, 12 May 2023 11:18:19 +0300 Subject: [PATCH 06/13] typo fix --- admin/src/controllers/test.controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/src/controllers/test.controller.js b/admin/src/controllers/test.controller.js index c14f571..edf2d22 100644 --- a/admin/src/controllers/test.controller.js +++ b/admin/src/controllers/test.controller.js @@ -2,7 +2,7 @@ function TestController() { } TestController.prototype.renderAddTestsModal = function() { - Logger.log("renderAddTestsModal") + const addNewTestsHtml = HtmlService .createTemplateFromFile('src/views/add-new-tests') .evaluate() From 0b168fce3aa9d7e7877e36e402afe480cd9a1726 Mon Sep 17 00:00:00 2001 From: erenyener Date: Fri, 12 May 2023 14:08:50 +0300 Subject: [PATCH 07/13] refactor views --- admin/src/controllers/problem.controller.js | 3 +-- admin/src/controllers/test.controller.js | 3 +-- admin/src/main.js | 2 +- .../add-new-problem-modal.html | 13 +++++++++++++ .../styles-add-new-problem-modal.html | 7 +++++++ admin/src/views/add-new-problem.html | 1 - .../add-new-tests-modal/add-new-tests-modal.html | 13 +++++++++++++ .../styles-add-new-tests-modal.html | 7 +++++++ admin/src/views/add-new-tests.html | 0 9 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 admin/src/views/add-new-problem-modal/add-new-problem-modal.html create mode 100644 admin/src/views/add-new-problem-modal/styles-add-new-problem-modal.html delete mode 100644 admin/src/views/add-new-problem.html create mode 100644 admin/src/views/add-new-tests-modal/add-new-tests-modal.html create mode 100644 admin/src/views/add-new-tests-modal/styles-add-new-tests-modal.html delete mode 100644 admin/src/views/add-new-tests.html diff --git a/admin/src/controllers/problem.controller.js b/admin/src/controllers/problem.controller.js index 54acf13..b0fb48a 100644 --- a/admin/src/controllers/problem.controller.js +++ b/admin/src/controllers/problem.controller.js @@ -1,10 +1,9 @@ function ProblemController() { } - ProblemController.prototype.renderAddProblemModal = function() { const addProblemModalHtml = HtmlService - .createTemplateFromFile('src/views/add-new-problem') + .createTemplateFromFile('src/views/add-new-problem-modal/add-new-problem-modal') .evaluate() .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL) .getContent(); diff --git a/admin/src/controllers/test.controller.js b/admin/src/controllers/test.controller.js index edf2d22..dc85471 100644 --- a/admin/src/controllers/test.controller.js +++ b/admin/src/controllers/test.controller.js @@ -1,10 +1,9 @@ function TestController() { } - TestController.prototype.renderAddTestsModal = function() { const addNewTestsHtml = HtmlService - .createTemplateFromFile('src/views/add-new-tests') + .createTemplateFromFile('src/views/add-new-tests-modal/add-new-tests-modal') .evaluate() .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL) .getContent(); diff --git a/admin/src/main.js b/admin/src/main.js index c33a242..0ab7783 100644 --- a/admin/src/main.js +++ b/admin/src/main.js @@ -6,7 +6,7 @@ function renderMenu() { const ui = SpreadsheetApp.getUi(); - ui.createMenu('Codex Addon') + ui.createMenu('Codex Admin') .addItem('Add Problem', 'addProblem') .addItem('Add Tests', 'addTests') .addToUi(); diff --git a/admin/src/views/add-new-problem-modal/add-new-problem-modal.html b/admin/src/views/add-new-problem-modal/add-new-problem-modal.html new file mode 100644 index 0000000..6219d87 --- /dev/null +++ b/admin/src/views/add-new-problem-modal/add-new-problem-modal.html @@ -0,0 +1,13 @@ + + + + + + + + + +
Hello World
+ + + \ No newline at end of file diff --git a/admin/src/views/add-new-problem-modal/styles-add-new-problem-modal.html b/admin/src/views/add-new-problem-modal/styles-add-new-problem-modal.html new file mode 100644 index 0000000..df99c5f --- /dev/null +++ b/admin/src/views/add-new-problem-modal/styles-add-new-problem-modal.html @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/admin/src/views/add-new-problem.html b/admin/src/views/add-new-problem.html deleted file mode 100644 index b4345f3..0000000 --- a/admin/src/views/add-new-problem.html +++ /dev/null @@ -1 +0,0 @@ -HELLO FROM ADD NEW PROBLEM \ No newline at end of file diff --git a/admin/src/views/add-new-tests-modal/add-new-tests-modal.html b/admin/src/views/add-new-tests-modal/add-new-tests-modal.html new file mode 100644 index 0000000..d1460fe --- /dev/null +++ b/admin/src/views/add-new-tests-modal/add-new-tests-modal.html @@ -0,0 +1,13 @@ + + + + + + + + + +
Hello World
+ + + \ No newline at end of file diff --git a/admin/src/views/add-new-tests-modal/styles-add-new-tests-modal.html b/admin/src/views/add-new-tests-modal/styles-add-new-tests-modal.html new file mode 100644 index 0000000..00335a8 --- /dev/null +++ b/admin/src/views/add-new-tests-modal/styles-add-new-tests-modal.html @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/admin/src/views/add-new-tests.html b/admin/src/views/add-new-tests.html deleted file mode 100644 index e69de29..0000000 From 4ff38fcbdefcbe4fdc078b87c92bb190b1ae836f Mon Sep 17 00:00:00 2001 From: erenyener Date: Fri, 12 May 2023 14:29:49 +0300 Subject: [PATCH 08/13] add problem view implemented without styles --- .../add-new-problem-modal.html | 25 ++++++++++++++++++- .../scripts-add-new-problem-modal.html | 5 ++++ .../styles-add-new-problem-modal.html | 8 +++--- 3 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 admin/src/views/add-new-problem-modal/scripts-add-new-problem-modal.html diff --git a/admin/src/views/add-new-problem-modal/add-new-problem-modal.html b/admin/src/views/add-new-problem-modal/add-new-problem-modal.html index 6219d87..abd28db 100644 --- a/admin/src/views/add-new-problem-modal/add-new-problem-modal.html +++ b/admin/src/views/add-new-problem-modal/add-new-problem-modal.html @@ -4,10 +4,33 @@ + -
Hello World
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
\ No newline at end of file diff --git a/admin/src/views/add-new-problem-modal/scripts-add-new-problem-modal.html b/admin/src/views/add-new-problem-modal/scripts-add-new-problem-modal.html new file mode 100644 index 0000000..3feb461 --- /dev/null +++ b/admin/src/views/add-new-problem-modal/scripts-add-new-problem-modal.html @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/admin/src/views/add-new-problem-modal/styles-add-new-problem-modal.html b/admin/src/views/add-new-problem-modal/styles-add-new-problem-modal.html index df99c5f..c5c3c67 100644 --- a/admin/src/views/add-new-problem-modal/styles-add-new-problem-modal.html +++ b/admin/src/views/add-new-problem-modal/styles-add-new-problem-modal.html @@ -1,7 +1,5 @@ \ No newline at end of file + \ No newline at end of file From 950d6873b1cb4886ed053b628c092ede5d677104 Mon Sep 17 00:00:00 2001 From: erenyener Date: Tue, 16 May 2023 17:30:08 +0300 Subject: [PATCH 09/13] add new problem --- admin/src/controllers/problem.controller.js | 7 +- .../add-new-problem-modal.html | 8 +- .../scripts-add-new-problem-modal.html | 94 ++++++++++++++++++- 3 files changed, 104 insertions(+), 5 deletions(-) diff --git a/admin/src/controllers/problem.controller.js b/admin/src/controllers/problem.controller.js index b0fb48a..b2d878e 100644 --- a/admin/src/controllers/problem.controller.js +++ b/admin/src/controllers/problem.controller.js @@ -2,13 +2,18 @@ function ProblemController() { } ProblemController.prototype.renderAddProblemModal = function() { + const scriptProperties = PropertiesService.getScriptProperties(); + const token = scriptProperties.getProperty("token") + const data = { token: token }; + const addProblemModalHtml = HtmlService .createTemplateFromFile('src/views/add-new-problem-modal/add-new-problem-modal') .evaluate() .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL) .getContent(); - const template = HtmlService.createTemplate(addProblemModalHtml) + const dataScript = ""; + const template = HtmlService.createTemplate(dataScript + addProblemModalHtml) .evaluate() .setWidth(600) .setHeight(550); diff --git a/admin/src/views/add-new-problem-modal/add-new-problem-modal.html b/admin/src/views/add-new-problem-modal/add-new-problem-modal.html index abd28db..331756b 100644 --- a/admin/src/views/add-new-problem-modal/add-new-problem-modal.html +++ b/admin/src/views/add-new-problem-modal/add-new-problem-modal.html @@ -4,7 +4,6 @@ - @@ -18,6 +17,10 @@ +
+ + +
- +
+ \ No newline at end of file diff --git a/admin/src/views/add-new-problem-modal/scripts-add-new-problem-modal.html b/admin/src/views/add-new-problem-modal/scripts-add-new-problem-modal.html index 3feb461..6327bcb 100644 --- a/admin/src/views/add-new-problem-modal/scripts-add-new-problem-modal.html +++ b/admin/src/views/add-new-problem-modal/scripts-add-new-problem-modal.html @@ -1,5 +1,95 @@ \ No newline at end of file From b16f1d1a490d67f50110fcb3e09d62bdfc3994e3 Mon Sep 17 00:00:00 2001 From: erenyener Date: Wed, 17 May 2023 09:47:03 +0300 Subject: [PATCH 10/13] format script --- .../scripts-add-new-problem-modal.html | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/admin/src/views/add-new-problem-modal/scripts-add-new-problem-modal.html b/admin/src/views/add-new-problem-modal/scripts-add-new-problem-modal.html index 6327bcb..b41daa9 100644 --- a/admin/src/views/add-new-problem-modal/scripts-add-new-problem-modal.html +++ b/admin/src/views/add-new-problem-modal/scripts-add-new-problem-modal.html @@ -1,14 +1,14 @@ "; const template = HtmlService.createTemplate(dataScript + addProblemModalHtml) .evaluate() - .setWidth(600) - .setHeight(550); + .setWidth(1000) + .setHeight(600); SpreadsheetApp.getUi().showModalDialog(template, 'Add New Problem'); } + +ProblemController.prototype.addProblem = function (problem) { + const problemsSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Problems'); + const row = [problem.id, problem.title, problem.content, problem.defaultCodes[0].defaultCode, problem.difficulty]; + problemsSheet.appendRow(row); +} diff --git a/admin/src/controllers/test.controller.js b/admin/src/controllers/test.controller.js index dc85471..9f4580d 100644 --- a/admin/src/controllers/test.controller.js +++ b/admin/src/controllers/test.controller.js @@ -1,5 +1,23 @@ function TestController() { } +TestController.prototype.getTestsSelection = function () { + const testsSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Tests'); + const activeRange = testsSheet.getActiveRange(); + const activeValues = activeRange.getValues(); + + let tests = []; + for(let row of activeValues){ + tests.push({ + id: row[0], + input: row[1], + output: row[2], + isPublic: row[3], + }) + } + + return tests; +} + TestController.prototype.renderAddTestsModal = function() { const addNewTestsHtml = HtmlService @@ -7,11 +25,22 @@ TestController.prototype.renderAddTestsModal = function() { .evaluate() .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL) .getContent(); + + const tests = this.getTestsSelection(); + const scriptProperties = PropertiesService.getScriptProperties(); + const token = scriptProperties.getProperty("token") + const data = { + token: token, + tests:tests + }; + const dataScript = ""; - const template = HtmlService.createTemplate(addNewTestsHtml) + const template = HtmlService.createTemplate(dataScript + addNewTestsHtml) .evaluate() .setWidth(600) .setHeight(550); + + SpreadsheetApp.getUi().showModalDialog(template, 'Add New Tests'); } diff --git a/admin/src/views/add-new-problem-modal/add-new-problem-modal.html b/admin/src/views/add-new-problem-modal/add-new-problem-modal.html index 331756b..d8dfba1 100644 --- a/admin/src/views/add-new-problem-modal/add-new-problem-modal.html +++ b/admin/src/views/add-new-problem-modal/add-new-problem-modal.html @@ -4,37 +4,52 @@ + -
-
-
- - -
-
- - -
-
- - -
-
- - -
-
- +
+
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+ + +
+ function foo(items) { + var x = "All this is syntax highlighted"; + return x; + } +
+
+
+ \ No newline at end of file diff --git a/admin/src/views/add-new-problem-modal/scripts-add-new-problem-modal.html b/admin/src/views/add-new-problem-modal/scripts-add-new-problem-modal.html index b41daa9..a25e33f 100644 --- a/admin/src/views/add-new-problem-modal/scripts-add-new-problem-modal.html +++ b/admin/src/views/add-new-problem-modal/scripts-add-new-problem-modal.html @@ -10,20 +10,52 @@ document.cookie = name + "=" + (value || "") + expires + "; path=/"; } + function hasClass(ele, cls) { + return !!ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)')); + } + + function addClass(ele, cls) { + if (!hasClass(ele, cls)) ele.className += " " + cls; + } + + function removeClass(ele, cls) { + if (hasClass(ele, cls)) { + var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)'); + ele.className = ele.className.replace(reg, ' '); + } + } + function DomController() { this.problemService = new ProblemService(); + this.editor = {}; init = () => { setCookie("access_token", window.stringifiedData.token, 100); document.getElementById("submitButton").addEventListener("click", submit); initElements(); + initEditor(); } initElements = () => { + this.loader = document.getElementById("loader"); + this.formContainer = document.getElementById("formContainer"); this.$title = document.getElementById("title"); this.$content = document.getElementById("content"); this.$difficulty = document.getElementById("difficulty"); - this.$code = document.getElementById("code"); + } + + initEditor = () => { + this.editor = ace.edit("editor"); + this.editor.setTheme("ace/theme/textmate"); + this.editor.session.setTabSize(4); + this.editor.session.setMode("ace/mode/javascript"); + } + + toggleLoader = (isShow) => { + if (isShow) { + addClass(this.formContainer, "hide"); + removeClass(this.loader, "hide"); + } } submit = (e) => { @@ -32,10 +64,18 @@ title: this.$title.value, content: this.$content.value, difficulty: this.$difficulty.value, - code: this.$code.value, + code: this.editor.getValue(), + } + + const isValid = this.problemService.validate(problem); + if (isValid) { + toggleLoader(true); + this.problemService.add(problem) } - this.problemService.validate(problem); - this.problemService.add(problem) + else { + alert("Problem is not valid, Make sure all the fields are filled"); + } + } return { @@ -50,6 +90,21 @@ validate = (problem) => { + if (problem.title.length === 0) { + return false; + } + else if (problem.content.length === 0) { + return false; + } + else if (problem.content.code === 0) { + return false; + } + + return true; + } + + onSuccess = () => { + google.script.host.close(); } add = (problem) => { @@ -76,12 +131,14 @@ } } - console.log(requestOptions) - fetch(url, requestOptions).then(response => { - console.log(response) - }).catch(error => { - console.log("ERROR") - }) + fetch(url, requestOptions). + then(response => response.json()). + then(json => { + google.script.run.withSuccessHandler(onSuccess).processAddProblem(json); + }). + catch(error => { + alert("Error occured, you probably not connected VPN") + }) } return { diff --git a/admin/src/views/add-new-problem-modal/styles-add-new-problem-modal.html b/admin/src/views/add-new-problem-modal/styles-add-new-problem-modal.html index c5c3c67..12e78bb 100644 --- a/admin/src/views/add-new-problem-modal/styles-add-new-problem-modal.html +++ b/admin/src/views/add-new-problem-modal/styles-add-new-problem-modal.html @@ -1,5 +1,174 @@ \ No newline at end of file diff --git a/admin/src/views/add-new-tests-modal/add-new-tests-modal.html b/admin/src/views/add-new-tests-modal/add-new-tests-modal.html index d1460fe..1fd5c31 100644 --- a/admin/src/views/add-new-tests-modal/add-new-tests-modal.html +++ b/admin/src/views/add-new-tests-modal/add-new-tests-modal.html @@ -7,7 +7,28 @@ -
Hello World
- +
+
+ + + + + + + + + + + +
Problem IdInputOutputIs Public
+
+
+
+ +
+
+
+ + \ No newline at end of file diff --git a/admin/src/views/add-new-tests-modal/scripts-add-new-tests-modal.html b/admin/src/views/add-new-tests-modal/scripts-add-new-tests-modal.html new file mode 100644 index 0000000..a56f5d2 --- /dev/null +++ b/admin/src/views/add-new-tests-modal/scripts-add-new-tests-modal.html @@ -0,0 +1,102 @@ + \ No newline at end of file From 59e0f8bbb658ccfaf7754b1382f842cd76baff10 Mon Sep 17 00:00:00 2001 From: erenyener Date: Tue, 23 May 2023 12:17:06 +0300 Subject: [PATCH 12/13] create new challange --- admin/src/controllers/challange.controller.js | 32 +++ admin/src/controllers/problem.controller.js | 9 +- admin/src/controllers/test.controller.js | 21 +- admin/src/main.js | 6 + .../add-new-challange-modal.html | 55 +++++ .../scripts-add-new-challange-modal.html | 204 ++++++++++++++++++ .../styles-add-new-challange-modal.html | 174 +++++++++++++++ .../add-new-tests-modal.html | 13 +- .../scripts-add-new-tests-modal.html | 134 ++++++++++-- .../styles-add-new-tests-modal.html | 203 ++++++++++++++++- 10 files changed, 820 insertions(+), 31 deletions(-) create mode 100644 admin/src/controllers/challange.controller.js create mode 100644 admin/src/views/add-new-challange-modal/add-new-challange-modal.html create mode 100644 admin/src/views/add-new-challange-modal/scripts-add-new-challange-modal.html create mode 100644 admin/src/views/add-new-challange-modal/styles-add-new-challange-modal.html diff --git a/admin/src/controllers/challange.controller.js b/admin/src/controllers/challange.controller.js new file mode 100644 index 0000000..640eb35 --- /dev/null +++ b/admin/src/controllers/challange.controller.js @@ -0,0 +1,32 @@ +function ChallangeController() { } + +function processAddChallange() { + const challangeController = new ChallangeController(); + challangeController.addChallange(); + return true; +} + +ChallangeController.prototype.renderAddChallangeModal = function () { + + const scriptProperties = PropertiesService.getScriptProperties(); + const token = scriptProperties.getProperty("token") + const data = { token: token }; + + const addProblemModalHtml = HtmlService + .createTemplateFromFile('src/views/add-new-challange-modal/add-new-challange-modal') + .evaluate() + .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL) + .getContent(); + + const dataScript = ""; + const template = HtmlService.createTemplate(dataScript + addProblemModalHtml) + .evaluate() + .setWidth(800) + .setHeight(350); + + SpreadsheetApp.getUi().showModalDialog(template, 'Add New Challange'); +} + +ChallangeController.prototype.addChallange = function () { + return true; +} diff --git a/admin/src/controllers/problem.controller.js b/admin/src/controllers/problem.controller.js index 8c74b70..fccb66e 100644 --- a/admin/src/controllers/problem.controller.js +++ b/admin/src/controllers/problem.controller.js @@ -2,7 +2,8 @@ function ProblemController() { } function processAddProblem(problem) { const problemController = new ProblemController(); - problemController.addProblem(problem); + problemController.addProblem(); + return true; } ProblemController.prototype.renderAddProblemModal = function () { @@ -26,8 +27,6 @@ ProblemController.prototype.renderAddProblemModal = function () { SpreadsheetApp.getUi().showModalDialog(template, 'Add New Problem'); } -ProblemController.prototype.addProblem = function (problem) { - const problemsSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Problems'); - const row = [problem.id, problem.title, problem.content, problem.defaultCodes[0].defaultCode, problem.difficulty]; - problemsSheet.appendRow(row); +ProblemController.prototype.addProblem = function () { + return true; } diff --git a/admin/src/controllers/test.controller.js b/admin/src/controllers/test.controller.js index 9f4580d..312636d 100644 --- a/admin/src/controllers/test.controller.js +++ b/admin/src/controllers/test.controller.js @@ -1,5 +1,10 @@ function TestController() { } +function processAddTest() { + const testController = new TestController(); + testController.addTest(); +} + TestController.prototype.getTestsSelection = function () { const testsSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Tests'); const activeRange = testsSheet.getActiveRange(); @@ -8,10 +13,9 @@ TestController.prototype.getTestsSelection = function () { let tests = []; for(let row of activeValues){ tests.push({ - id: row[0], - input: row[1], - output: row[2], - isPublic: row[3], + input: row[0], + output: row[1], + isPublic: row[2], }) } @@ -38,9 +42,16 @@ TestController.prototype.renderAddTestsModal = function() { const template = HtmlService.createTemplate(dataScript + addNewTestsHtml) .evaluate() .setWidth(600) - .setHeight(550); + .setHeight(380); SpreadsheetApp.getUi().showModalDialog(template, 'Add New Tests'); } + + +TestController.prototype.addTest = function () { + const testsSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Tests'); + const activeRange = testsSheet.getActiveRange(); + activeRange.clearContent() +} \ No newline at end of file diff --git a/admin/src/main.js b/admin/src/main.js index 0ab7783..435e90e 100644 --- a/admin/src/main.js +++ b/admin/src/main.js @@ -8,6 +8,7 @@ function renderMenu() { ui.createMenu('Codex Admin') .addItem('Add Problem', 'addProblem') + .addItem('Add Challenge', 'addChallange') .addItem('Add Tests', 'addTests') .addToUi(); } @@ -18,6 +19,11 @@ function addProblem() { problemController.renderAddProblemModal(); } +function addChallange() { + const challangeController = new ChallangeController(); + challangeController.renderAddChallangeModal(); +} + function addTests() { const testController = new TestController(); testController.renderAddTestsModal(); diff --git a/admin/src/views/add-new-challange-modal/add-new-challange-modal.html b/admin/src/views/add-new-challange-modal/add-new-challange-modal.html new file mode 100644 index 0000000..b7ef735 --- /dev/null +++ b/admin/src/views/add-new-challange-modal/add-new-challange-modal.html @@ -0,0 +1,55 @@ + + + + + + + + + +
+
+
+
+
+
+ + +
+
+ + +
+ +
+ +
+
+
+ +
+ + + +
+ +
+ + +
+
+ + +
+
+ + +
+
+
+
+
+ + + + \ No newline at end of file diff --git a/admin/src/views/add-new-challange-modal/scripts-add-new-challange-modal.html b/admin/src/views/add-new-challange-modal/scripts-add-new-challange-modal.html new file mode 100644 index 0000000..df82d59 --- /dev/null +++ b/admin/src/views/add-new-challange-modal/scripts-add-new-challange-modal.html @@ -0,0 +1,204 @@ + \ No newline at end of file diff --git a/admin/src/views/add-new-challange-modal/styles-add-new-challange-modal.html b/admin/src/views/add-new-challange-modal/styles-add-new-challange-modal.html new file mode 100644 index 0000000..da847e2 --- /dev/null +++ b/admin/src/views/add-new-challange-modal/styles-add-new-challange-modal.html @@ -0,0 +1,174 @@ + \ No newline at end of file diff --git a/admin/src/views/add-new-tests-modal/add-new-tests-modal.html b/admin/src/views/add-new-tests-modal/add-new-tests-modal.html index 1fd5c31..5ca4a94 100644 --- a/admin/src/views/add-new-tests-modal/add-new-tests-modal.html +++ b/admin/src/views/add-new-tests-modal/add-new-tests-modal.html @@ -8,11 +8,11 @@
-
+
+
- @@ -23,7 +23,14 @@
Problem Id Input Output Is Public
-
+
+ +
+ + + +
+
diff --git a/admin/src/views/add-new-tests-modal/scripts-add-new-tests-modal.html b/admin/src/views/add-new-tests-modal/scripts-add-new-tests-modal.html index a56f5d2..ef7e18f 100644 --- a/admin/src/views/add-new-tests-modal/scripts-add-new-tests-modal.html +++ b/admin/src/views/add-new-tests-modal/scripts-add-new-tests-modal.html @@ -10,15 +10,48 @@ document.cookie = name + "=" + (value || "") + expires + "; path=/"; } + function hasClass(ele, cls) { + return !!ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)')); + } + + function addClass(ele, cls) { + if (!hasClass(ele, cls)) ele.className += " " + cls; + } + + function removeClass(ele, cls) { + if (hasClass(ele, cls)) { + var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)'); + ele.className = ele.className.replace(reg, ' '); + } + } + function DomController() { this.testService = new TestService(); - init = () => { + this.problemService = new ProblemService(); + this.selectedIndex = -1; + const self = this; + + init = async () => { const tests = window.stringifiedData.tests; setCookie("access_token", window.stringifiedData.token, 100); document.getElementById("submitButton").addEventListener("click", submit); initTestTable(tests); + const problems = await this.problemService.getProblems(); + initDataList(problems); + this.formContainer = document.getElementById("formContainer"); + this.tableContainer = document.getElementById("tableContainer"); + this.loader = document.getElementById("loader"); } + initDataList = (problems) => { + const datalist = document.getElementById('problems') + problems.forEach(function(problem){ + let option = document.createElement('option'); + option.value = problem.title + ' - ' + problem.id; + datalist.appendChild(option); + }); + } + initTestTable = (tests) => { tests.forEach(test => { insertNewRow(test); @@ -26,32 +59,63 @@ } insertNewRow = (test) => { - const table = document.getElementById('testsTable'); + + const table = document.getElementById('testsTable').getElementsByTagName('tbody')[0]; let newRow = table.insertRow(-1); let l = table.rows.length-1; - //Col1 + //Col2 table.rows[l].insertCell(0); - table.rows[l].cells[0].innerHTML = test.id; + table.rows[l].cells[0].innerHTML = test.input; - //Col2 + //Col3 table.rows[l].insertCell(1); - table.rows[l].cells[1].innerHTML = test.input; + table.rows[l].cells[1].innerHTML = test.output; - //Col3 + //Col4 table.rows[l].insertCell(2); - table.rows[l].cells[2].innerHTML = test.output; + table.rows[l].cells[2].innerHTML = test.isPublic; + } - //Col4 - table.rows[l].insertCell(3); - table.rows[l].cells[3].innerHTML = test.isPublic; + toggleLoader = (isShow) => { + if (isShow) { + addClass(this.formContainer, "hide"); + addClass(this.tableContainer, "hide"); + removeClass(this.loader, "hide"); + } + else { + removeClass(this.formContainer, "hide"); + removeClass(this.tableContainer, "hide"); + addClass(this.loader, "hide"); + } } submit = (e) => { + toggleLoader(true); const tests = window.stringifiedData.tests; - for(let test of tests) { - this.testService.add(test); + const $problemChoice = document.getElementById('problemChoice'); + const selectedValue = $problemChoice.value; + const titleIdPair = selectedValue.split(' - '); + const problemId = titleIdPair[1]; + + if(problemId) { + for(let test of tests) { + test.id = problemId; + if(test.input && test.output) { + this.testService.add(test); + } + else{ + alert("test is invalid"); + toggleLoader(false); + } + + } + }else { + alert("test id is req"); + toggleLoader(false); } + + } return { @@ -59,7 +123,48 @@ } } + function ProblemService() { + + const self = this; + getProblems = () => { + let promise = new Promise((resolve, reject) => { + const url = "https://discovery-sfx-codex-service.moon.trendyol.com/problem"; + const requestOptions = { + method: "GET", + credentials: 'include', + headers: { + "Content-Type": "application/json", + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Credentials": "true", + "Access-Control-Allow-Methods": "DELETE, POST, GET, OPTIONS", + "Access-Control-Allow-Headers": "Content-Type, Authorization, X-Requested-With, cookie, cache-control, accept, authority", + } + }; + + fetch(url, requestOptions). + then(response => response.json()). + then(json => { + resolve(json); + }). + catch(error => { + reject(false); + }) + + }) + return promise; + } + + return { + getProblems + } + } + function TestService() { + + onSuccess = () => { + google.script.host.close(); + } + add = (test) => { const url = "https://discovery-sfx-codex-service.moon.trendyol.com/testcase" @@ -84,8 +189,7 @@ fetch(url, requestOptions). then(response => response.json()). then(json => { - console.log(json) - // google.script.run.withSuccessHandler(onSuccess).processAddProblem(json); + google.script.run.withSuccessHandler(onSuccess).processAddTest(json); }). catch(error => { console.log(error) diff --git a/admin/src/views/add-new-tests-modal/styles-add-new-tests-modal.html b/admin/src/views/add-new-tests-modal/styles-add-new-tests-modal.html index 00335a8..24126d1 100644 --- a/admin/src/views/add-new-tests-modal/styles-add-new-tests-modal.html +++ b/admin/src/views/add-new-tests-modal/styles-add-new-tests-modal.html @@ -1,7 +1,204 @@ \ No newline at end of file From d6e8704c009776761244b53df08d14816e2487a1 Mon Sep 17 00:00:00 2001 From: erenyener Date: Fri, 26 May 2023 15:27:07 +0300 Subject: [PATCH 13/13] fix validation --- .../scripts-add-new-challange-modal.html | 13 +++-------- .../scripts-add-new-problem-modal.html | 12 +--------- .../scripts-add-new-tests-modal.html | 23 ++++--------------- 3 files changed, 8 insertions(+), 40 deletions(-) diff --git a/admin/src/views/add-new-challange-modal/scripts-add-new-challange-modal.html b/admin/src/views/add-new-challange-modal/scripts-add-new-challange-modal.html index df82d59..2a70782 100644 --- a/admin/src/views/add-new-challange-modal/scripts-add-new-challange-modal.html +++ b/admin/src/views/add-new-challange-modal/scripts-add-new-challange-modal.html @@ -1,14 +1,6 @@