Skip to content

Commit 34c1fd3

Browse files
authored
Merge pull request #162 from SPARSH1608/feature/sql-added
fixed locked contest issue
2 parents fa9177f + 7ae3a41 commit 34c1fd3

File tree

15 files changed

+125
-22
lines changed

15 files changed

+125
-22
lines changed

app/helpers/json-to-table.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { helper } from '@ember/component/helper';
2+
import convertToTable from '../util/json-to-table';
3+
4+
export default helper(function jsonToTable([data]) {
5+
return convertToTable(data);
6+
});

app/pods/components/code-editor-component/template.hbs

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
{{/if}}
2020
<SubmissionResult
2121
@fullScreen={{fullScreen}}
22+
@allowedLanguages={{contest.allowedLanguages}}
23+
2224
@judgeResult={{if (not submission.codeTaskGroup.isRunning) lastResult}} />
2325
</div>
2426
{{/if}}

app/pods/components/code-window/component.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ export default class CodeWindowComponent extends Component {
4848
code: "csharp",
4949
mode: "csharp",
5050
source: ""
51-
}
51+
}, {
52+
name: "MySQL 10",
53+
code: "mysql",
54+
mode: "mysql",
55+
source: ""
56+
}
5257
]
5358

5459
setSubmission = () => {

app/pods/components/full-screen-problem-view/template.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
</div>
4949
<div class="w-100">
5050
{{#liquid-if (eq currentTab 'problem')}}
51-
<ProblemExplanation @problem={{problem}} />
51+
<ProblemExplanation @problem={{problem}} @contest={{contest}}/>
5252
{{else if (eq currentTab 'submissions')}}
5353
<SubmissionsList
5454
@contest={{contest}}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,34 @@
11
import Component from '@ember/component';
2+
import { inject as service } from '@ember/service';
3+
import jsonToTable from '../../../helpers/json-to-table';
24

35
export default Component.extend({
4-
});
6+
7+
languageSelection: service('language-selection'),
8+
init(){
9+
this._super(...arguments);
10+
let contest = this.get('contest').data;
11+
12+
document.addEventListener('contextmenu', function (event) {
13+
event.preventDefault();
14+
});
15+
document.addEventListener('keydown', function (event) {
16+
if (
17+
event.key === 'F12' ||
18+
(event.ctrlKey && event.shiftKey && event.key === 'I') ||
19+
(event.ctrlKey && event.shiftKey && event.key === 'C') ||
20+
(event.ctrlKey && event.shiftKey && event.key === 'J') ||
21+
(event.ctrlKey && event.key === 'U')
22+
) {
23+
event.preventDefault();
24+
}
25+
});
26+
27+
},
28+
jsonToTable(data) {
29+
30+
const table = jsonToTable(data);
31+
return table;
32+
}
33+
34+
});

app/pods/components/problem-explanation/template.hbs

+17-13
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
<div class="py-4">
2-
<p>
3-
{{markdown-to-html problem.details.description}}
4-
</p>
2+
<p class="no-select">{{markdown-to-html problem.details.description}}</p>
3+
54
<div class="extra-bold">Input Format</div>
6-
<p>
7-
{{markdown-to-html problem.details.input_format}}
8-
</p>
5+
6+
<pre>{{problem.details.input_format}}</pre>
7+
8+
99
<div class="extra-bold">Constraints</div>
1010
<div class="bg-grey br-5 w-60 px-4 py-2 my-2">
11-
<p>
12-
{{markdown-to-html problem.details.constraints}}
13-
</p>
11+
<p>{{markdown-to-html problem.details.constraints}}</p>
1412
</div>
13+
1514
<div class="extra-bold">Output Format</div>
16-
<p>
17-
{{markdown-to-html problem.details.output_format}}
18-
</p>
15+
<pre>{{problem.details.output_format}}</pre>
1916
<div class="extra-bold">Sample Input</div>
2017
<div class="bg-grey br-5 w-60 px-4 py-2 my-2">
21-
<pre>{{problem.details.sample_input}}</pre>
18+
<pre>{{ problem.details.sample_input}}</pre>
2219
</div>
20+
2321
<div class="extra-bold">Sample Output</div>
2422
<div class="bg-grey br-5 w-60 px-4 py-2 my-2">
23+
{{#if (includes contest.allowedLanguages "mysql")}}
24+
<pre>{{json-to-table problem.details.sample_output}}</pre>
25+
{{else}}
2526
<pre>{{problem.details.sample_output}}</pre>
27+
{{/if}}
28+
2629
</div>
30+
2731
{{#if problem.details.explanation}}
2832
<div class="extra-bold">Explanation</div>
2933
<div class="bg-grey br-5 w-60 px-4 py-2 my-2">

app/pods/components/problem-view/template.hbs

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333

3434
{{#liquid-if (eq selectedTab "problem")}}
3535
<ProblemExplanation
36-
@problem={{problem}} />
36+
@problem={{problem}}
37+
@contest="{{this.contest}}"/>
3738
{{else if (eq selectedTab "submissions")}}
3839
<SubmissionsList
3940
@contest={{contest}}

app/pods/components/project-view/template.hbs

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
{{#if (or submitProjectTask.isRunning lastResult)}}
6161
<div class="mt-4">
6262
<SubmissionResult
63+
@allowedLanguages={{contest.allowedLanguages}}
64+
6365
@contentType={{content.type}}
6466
@judgeResult={{if (not submitProjectTask.isRunning) lastResult}}
6567
/>

app/pods/components/submission-result/component.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Component from '@ember/component';
22
import { computed } from '@ember/object';
3-
3+
import { jsonToTable } from '../../../util/json-to-table';
44
export default class SubmissionResult extends Component {
55
didRender() {
66
this.element.scrollIntoView({ behavior: "smooth", block: "end" })
@@ -41,4 +41,8 @@ export default class SubmissionResult extends Component {
4141
return this.judgeResult.testcases
4242
}
4343
}
44+
jsonToTable(data) {
45+
const table = jsonToTable(data);
46+
return table;
47+
}
4448
}

app/pods/components/submission-result/submission-success/template.hbs

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
<span class="font-sm bold">
33
Compilation Successful
44
</span>
5+
56
{{#if output}}
6-
<pre class="mt-3 bg-grey p-4">{{output}}</pre>
7+
{{#if (includes allowedLanguages "mysql")}}
8+
<pre class="mt-3 bg-grey p-4">{{json-to-table output}}</pre>
9+
{{else}}
10+
<pre class="mt-3 bg-grey p-4">{{output}}</pre>
11+
{{/if}}
712
{{/if}}
813
</div>
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
<div class="{{unless fullScreen "border-card mb-5"}} p-0">
2+
3+
24
{{#if isRunning}}
35
<SubmissionResult::SubmissionStatus />
46
{{else if isErrored}}
57
<SubmissionResult::SubmissionError @output={{errorPayload}} />
68
{{else if isSubmission}}
79
<SubmissionResult::SubmissionTestcases @testcases={{testcasesPayload}} />
810
{{else}}
9-
<SubmissionResult::SubmissionSuccess @message={{message}} @output={{output}} />
11+
<SubmissionResult::SubmissionSuccess
12+
@message={{message}}
13+
@output={{output}}
14+
@allowedLanguages={{allowedLanguages}}
15+
/>
16+
1017
{{/if}}
1118
</div>

app/services/language-selection.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
import Service from '@ember/service';
3+
4+
export default Service.extend({
5+
selectedLanguage: null
6+
});

app/styles/app.scss

+9-1
Original file line numberDiff line numberDiff line change
@@ -292,4 +292,12 @@ body{
292292
100% {
293293
box-shadow: 0 0 0 6px rgba(167, 89, 47, 0.032);
294294
}
295-
}
295+
}
296+
.no-select {
297+
user-select: none;
298+
-webkit-user-select: none;
299+
-moz-user-select: none;
300+
-ms-user-select: none;
301+
pointer-events: none;
302+
}
303+

app/util/json-to-table.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export default function convertToTable(data) {
2+
3+
data = JSON.parse(data);
4+
5+
6+
const headers = Array.from(new Set(data.flatMap(Object.keys)));
7+
const columnWidths = headers.map(header =>
8+
Math.max(header.length, ...data.map(row => String(row[header] ?? '').length))
9+
);
10+
11+
const createRow = (row) => '| ' + row.map((cell, i) => (cell ?? '').toString().padEnd(columnWidths[i])).join(' | ') + ' |';
12+
const separator = '+-' + columnWidths.map(width => '-'.repeat(width)).join('-+-') + '-+';
13+
14+
const table = [
15+
separator,
16+
createRow(headers),
17+
separator,
18+
...data.map(row => createRow(headers.map(header => row[header] ?? ''))),
19+
separator
20+
];
21+
22+
return table.join('\n');
23+
}

config/environment.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = function (environment) {
55
modulePrefix: "hackerblocks",
66
podModulePrefix: "hackerblocks/pods",
77
environment,
8-
rootURL: "/",
8+
rootURL: "/app",
99
locationType: "auto",
1010
"ember-simple-auth-token": {
1111
identificationField: "code",

0 commit comments

Comments
 (0)