Skip to content
Open

Admin #185

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions admin/.clasp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"scriptId":"1ayOszkKcVSChNjDGnC2V2gx5zOqe7LrC6MdQC6WsR30Vhtv1phLkWpeM","rootDir":"/Users/eren.yener/Desktop/repo/erenyener/codex/admin"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you keep scriptId and rootDir intentionally?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

script id can be public, because it is restricted by default via google auth

5 changes: 5 additions & 0 deletions admin/.claspignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/**
.git
.doc
!src/**
!appsscript.json
27 changes: 27 additions & 0 deletions admin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Codex Admin Appscripts


## Quick Links
[Panel Link](https://docs.google.com/spreadsheets/d/1TSYzDuSMnv_3uVRcM7o0tNyUdRlKy3C6gFHKMVh5fjc/edit#gid=0)


## 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)

```
7 changes: 7 additions & 0 deletions admin/appsscript.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"timeZone": "Europe/Istanbul",
"dependencies": {
},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8"
}
32 changes: 32 additions & 0 deletions admin/src/controllers/challange.controller.js
Original file line number Diff line number Diff line change
@@ -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 = "<script>window.stringifiedData = " + JSON.stringify(data) + "</script>";
const template = HtmlService.createTemplate(dataScript + addProblemModalHtml)
.evaluate()
.setWidth(800)
.setHeight(350);

SpreadsheetApp.getUi().showModalDialog(template, 'Add New Challange');
}

ChallangeController.prototype.addChallange = function () {
return true;
}
32 changes: 32 additions & 0 deletions admin/src/controllers/problem.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function ProblemController() { }

function processAddProblem(problem) {
const problemController = new ProblemController();
problemController.addProblem();
return true;
}

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 dataScript = "<script>window.stringifiedData = " + JSON.stringify(data) + "</script>";
const template = HtmlService.createTemplate(dataScript + addProblemModalHtml)
.evaluate()
.setWidth(1000)
.setHeight(600);

SpreadsheetApp.getUi().showModalDialog(template, 'Add New Problem');
}

ProblemController.prototype.addProblem = function () {
return true;
}
57 changes: 57 additions & 0 deletions admin/src/controllers/test.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
function TestController() { }

function processAddTest() {
const testController = new TestController();
testController.addTest();
}

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({
input: row[0],
output: row[1],
isPublic: row[2],
})
}

return tests;
}

TestController.prototype.renderAddTestsModal = function() {

const addNewTestsHtml = HtmlService
.createTemplateFromFile('src/views/add-new-tests-modal/add-new-tests-modal')
.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 = "<script>window.stringifiedData = " + JSON.stringify(data) + "</script>";

const template = HtmlService.createTemplate(dataScript + addNewTestsHtml)
.evaluate()
.setWidth(600)
.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()
}
30 changes: 30 additions & 0 deletions admin/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function onOpen() {
renderMenu();
}

function renderMenu() {

const ui = SpreadsheetApp.getUi();

ui.createMenu('Codex Admin')
.addItem('Add Problem', 'addProblem')
.addItem('Add Challenge', 'addChallange')
.addItem('Add Tests', 'addTests')
.addToUi();
}


function addProblem() {
const problemController = new ProblemController();
problemController.renderAddProblemModal();
}

function addChallange() {
const challangeController = new ChallangeController();
challangeController.renderAddChallangeModal();
}

function addTests() {
const testController = new TestController();
testController.renderAddTestsModal();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html>

<head>
<base target="_top">
<?!= HtmlService.createHtmlOutputFromFile("src/views/add-new-challange-modal/styles-add-new-challange-modal").getContent(); ?>
</head>

<body>
<div class="container">
<div id="loader" class="lds-facebook hide"><div></div><div></div><div></div></div>
<div id="formContainer" class="form-container">
<div class="row">
<div class="col-6">
<div class="form-group">
<label for="name">Name</label>
<input type="text" placeholder="Trendyol Champs" class="text-field" id="name" name="name" />
</div>
<div class="form-group">
<label for="description">Description</label>
<textarea type="text" class="text-area-field description-editor" id="description" name="description" placeholder="### markdown"></textarea>
</div>

<div class="form-group">
<button id="submitButton" onclick="submit"> Submit </button>
</div>
</div>
<div class="col-6">

<div class="form-group">
<label for="problem-choice">Select Problem</label>
<input list="problems" data-selected="" class="text-field" name="problem-choice" id="problemChoice">
<datalist id="problems"></datalist>
</div>

<div class="form-group">
<label for="duration">Duration</label>
<input type="text" placeholder="10" class="text-field" id="duration" name="duration" />
</div>
<div class="form-group">
<label for="teamSize">Team Size</label>
<input type="text" placeholder="2" class="text-field" id="teamSize" name="teamSize" />
</div>
<div class="form-group">
<label for="date">Date</label>
<input type="text" placeholder="2023-04-07T11:50:06.963Z" class="text-field" id="date" name="date" />
</div>
</div>
</div>
</div>
</div>
</body>
<?!= HtmlService.createHtmlOutputFromFile("src/views/add-new-challange-modal/scripts-add-new-challange-modal").getContent(); ?>

</html>
Loading