Skip to content

Commit 9d34110

Browse files
authored
Merge pull request #158 from SPARSH1608/mysql
Added MySQL 10 support to Frontend Code
2 parents bd19df5 + 933dd09 commit 9d34110

File tree

14 files changed

+138
-54
lines changed

14 files changed

+138
-54
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'; // Ensure correct path
3+
4+
export default helper(function jsonToTable([data]) {
5+
return convertToTable(data);
6+
});

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

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
</div>
1919
{{/if}}
2020
<SubmissionResult
21+
@allowedLanguages={{contest.allowedLanguages}}
2122
@fullScreen={{fullScreen}}
2223
@judgeResult={{if (not submission.codeTaskGroup.isRunning) lastResult}} />
2324
</div>

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

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import Component from '@ember/component';
22
import { action, computed } from '@ember/object';
3+
import { inject as service } from '@ember/service';
34

45
export default class CodeWindowComponent extends Component {
6+
@service('language-selection') languageSelection;
7+
58
isLanguageSelectOpen = false
69
customInputOpen = true
710
customInput = ''
@@ -48,9 +51,15 @@ export default class CodeWindowComponent extends Component {
4851
code: "csharp",
4952
mode: "csharp",
5053
source: ""
54+
},
55+
{
56+
name: "MySQL 10",
57+
code: "mysql",
58+
mode: "mysql",
59+
source: ""
5160
}
5261
]
53-
62+
5463
setSubmission = () => {
5564
this.set('selectedLanguage', this.languageSpecs.find(spec => spec.code === this.submission.language))
5665
this.set('selectedLanguage.source', window.atob(this.submission.solution.source))
@@ -80,11 +89,10 @@ export default class CodeWindowComponent extends Component {
8089

8190
@action
8291
selectLanguage(languageCode) {
83-
// console.log(languageCode)
84-
this.set('selectedLanguage', this.get('languageSpecs').find((spec) => {
85-
return spec.code === languageCode
86-
}))
87-
this.trigger("restoreCodeFromStorage")
92+
let selectedLanguage = this.languageSpecs.find((spec) => spec.code === languageCode);
93+
this.set('selectedLanguage', selectedLanguage);
94+
this.languageSelection.set('selectedLanguage', selectedLanguage);
95+
this.trigger("restoreCodeFromStorage");
8896
}
8997

9098
@action
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
import Component from '@ember/component';
2+
import { inject as service } from '@ember/service';
3+
import {jsonToTable} from '../../../util/json-to-table'
24

35
export default Component.extend({
6+
languageSelection: service('language-selection'),
7+
8+
init() {
9+
this._super(...arguments);
10+
let contest = this.get('contest');
11+
},
12+
jsonToTable(data) {
13+
const table = jsonToTable(data);
14+
return table;
15+
}
416
});
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
1+
2+
13
<div class="py-4">
2-
<p>
3-
{{markdown-to-html problem.details.description}}
4-
</p>
4+
<p>{{markdown-to-html problem.details.description}}</p>
5+
56
<div class="extra-bold">Input Format</div>
6-
<p>
7-
{{markdown-to-html problem.details.input_format}}
8-
</p>
7+
8+
<pre>{{problem.details.input_format}}</pre>
9+
10+
911
<div class="extra-bold">Constraints</div>
1012
<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>
13+
<p>{{markdown-to-html problem.details.constraints}}</p>
1414
</div>
15+
1516
<div class="extra-bold">Output Format</div>
16-
<p>
17-
{{markdown-to-html problem.details.output_format}}
18-
</p>
17+
<pre>{{problem.details.output_format}}</pre>
1918
<div class="extra-bold">Sample Input</div>
2019
<div class="bg-grey br-5 w-60 px-4 py-2 my-2">
21-
<pre>{{problem.details.sample_input}}</pre>
20+
<pre>{{ problem.details.sample_input}}</pre>
2221
</div>
22+
2323
<div class="extra-bold">Sample Output</div>
2424
<div class="bg-grey br-5 w-60 px-4 py-2 my-2">
25+
{{#if (includes contest.allowedLanguages "mysql")}}
26+
<pre>{{json-to-table problem.details.sample_output}}</pre>
27+
{{else}}
2528
<pre>{{problem.details.sample_output}}</pre>
29+
{{/if}}
30+
2631
</div>
32+
2733
{{#if problem.details.explanation}}
2834
<div class="extra-bold">Explanation</div>
2935
<div class="bg-grey br-5 w-60 px-4 py-2 my-2">
3036
{{markdown-to-html problem.details.explanation}}
3137
</div>
3238
{{/if}}
33-
</div>
39+
</div>

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

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

3434
{{#liquid-if (eq selectedTab "problem")}}
3535
<ProblemExplanation
36-
@problem={{problem}} />
36+
@problem={{problem}} @contest={{contest}} />
3737
{{else if (eq selectedTab "submissions")}}
3838
<SubmissionsList
3939
@contest={{contest}}

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

+2
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@
5757
{{/if}}
5858
</div>
5959
</div>
60+
6061
{{#if (or submitProjectTask.isRunning lastResult)}}
6162
<div class="mt-4">
6263
<SubmissionResult
64+
@allowedLanguages={{contest.allowedLanguages}}
6365
@contentType={{content.type}}
6466
@judgeResult={{if (not submitProjectTask.isRunning) lastResult}}
6567
/>

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

+2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import { computed } from '@ember/object';
44
export default class RunResultComponent extends Component {
55
didRender() {
66
this.element.scrollIntoView({behavior: "smooth", block: "end" })
7+
78
}
89

910
@computed('judgeResult')
1011
get output() {
12+
1113
if (this.judgeResult.data){
1214
return window.atob(this.judgeResult.data.output)
1315
} else if (this.judgeResult.error) {
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,48 @@
11
import Component from '@ember/component';
22
import { computed } from '@ember/object';
3+
import { jsonToTable } from '../../../util/json-to-table';
4+
5+
export default Component.extend({
36

4-
export default class SubmissionResult extends Component {
57
didRender() {
6-
this.element.scrollIntoView({ behavior: "smooth", block: "end" })
7-
}
8+
this._super(...arguments);
9+
this.element.scrollIntoView({ behavior: "smooth", block: "end" });
10+
},
811

9-
@computed('judgeResult')
10-
get isRunning() {
11-
return !this.judgeResult
12-
}
12+
isRunning: computed('judgeResult', function() {
13+
return !this.get('judgeResult');
14+
}),
1315

14-
@computed('judgeResult')
15-
get isErrored() {
16-
return !!this.judgeResult.stderr
17-
}
16+
isErrored: computed('judgeResult', function() {
17+
return !!this.get('judgeResult')?.stderr;
18+
}),
1819

19-
@computed('judgeResult')
20-
get isSubmission() {
21-
return !!(this.judgeResult.testcases)
22-
}
20+
isSubmission: computed('judgeResult', function() {
21+
return !!this.get('judgeResult')?.testcases;
22+
}),
2323

24-
@computed('isErrored')
25-
get errorPayload() {
26-
if (this.isErrored) {
27-
return window.atob(this.judgeResult.stderr || this.judgeResult.stdout)
24+
errorPayload: computed('isErrored', function() {
25+
if (this.get('isErrored')) {
26+
return window.atob(this.get('judgeResult')?.stderr || this.get('judgeResult')?.stdout);
2827
}
29-
}
28+
}),
29+
30+
output: computed('isSubmission', function() {
31+
if (!this.get('isSubmission')) {
32+
const output = window.atob(this.get('judgeResult')?.stdout);
3033

31-
@computed('isSubmission')
32-
get output() {
33-
if (!this.isSubmission) {
34-
return window.atob(this.judgeResult.stdout)
34+
return output;
3535
}
36-
}
36+
}),
3737

38-
@computed('isSubmission')
39-
get testcasesPayload() {
40-
if (this.isSubmission) {
41-
return this.judgeResult.testcases
38+
testcasesPayload: computed('isSubmission', function() {
39+
if (this.get('isSubmission')) {
40+
return this.get('judgeResult')?.testcases;
4241
}
42+
}),
43+
44+
jsonToTable(data) {
45+
const table = jsonToTable(data);
46+
return table;
4347
}
44-
}
48+
});

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

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

app/util/json-to-table.js

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

config/environment.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,4 @@ module.exports = function (environment) {
101101
ENV.apiHost + "/api/v2/jwt/refresh/";
102102

103103
return ENV;
104-
};
104+
};

0 commit comments

Comments
 (0)