Skip to content

Commit 6627ebe

Browse files
Merge pull request #533 from coding-blocks/polymorphic_problem
Polymorphic problem
2 parents c4d384f + 63ef3ec commit 6627ebe

File tree

23 files changed

+90
-390
lines changed

23 files changed

+90
-390
lines changed

app/models/code-challenge.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import env from 'codingblocks-online/config/environment'
44

55
export default DS.Model.extend({
66
name: DS.attr(),
7-
hbProblemId: DS.attr(),
7+
hbContentId: DS.attr(),
88
content: DS.belongsTo('content'),
99
testcases: DS.hasMany('testcase')
1010
})

app/models/problem-leaderboard.js renamed to app/models/content-leaderboard.js

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import DS from "ember-data";
2-
import { computed } from '@ember/object'
3-
import { isValidResult, isPassedTestcase } from "codingblocks-online/utils/testcases";
4-
import { pipe, not } from "codingblocks-online/utils/functional";
52

63
export default DS.Model.extend({
74
language: DS.attr(),

app/models/problem.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { computed } from '@ember/object';
33

44
export default DS.Model.extend({
55
name: DS.attr(),
6-
content: DS.attr(),
6+
details: DS.attr(),
77
submissions: DS.hasMany('submission'),
88
solutionStubs: DS.hasMany('solution-stub'),
99
mostSuccessfullSubmission: computed('submissions', function(){

app/models/submission.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import { pipe, not } from "codingblocks-online/utils/functional";
66
export default DS.Model.extend({
77
language: DS.attr(),
88
score: DS.attr(),
9-
source: DS.attr(),
9+
solution: DS.attr(),
10+
source: computed('solution', function () {
11+
return this.solution.source
12+
}),
1013
explanation: DS.attr(),
1114
'submit-at': DS.attr(),
1215
'judge-result': DS.attr(),

app/pods/attempt/content/code-challenge/route.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@ export default class CodeChallengeRoute extends Route {
1212
const runAttempt = this.modelFor('attempt')
1313
this.set("api.headers.hackJwt", this.get("currentUser.user.hackJwt"));
1414

15-
const problem = this.api.request('code_challenges/problems', {
15+
const problem = this.api.request(`code_challenges/${content.payload.get('id')}/problem`, {
1616
data: {
17-
contest_id: runAttempt.get("run.contestId"),
18-
problem_id: content.payload.get("hbProblemId")
17+
contest_id: runAttempt.get("run.contestId")
1918
}
2019
}).then(payload => {
2120
if (!payload) return {}
2221

2322
this.store.unloadAll('problem')
2423
this.store.pushPayload(payload)
25-
return this.store.peekRecord('problem', content.payload.get('hbProblemId'))
24+
return this.store.peekRecord('problem', payload.data.id)
2625
}).catch(err => {
2726
console.log(err)
2827
return {}

app/pods/attempt/content/code-challenge/template.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
</div>
3232

3333
Contest ID: {{runAttempt.run.contestId}} <br>
34-
Problem ID: {{codeChallenge.hbProblemId}} <br>
34+
Problem ID: {{codeChallenge.hbContentId}} <br>
3535
Run ID: {{runAttempt.run.id}} <br>
3636
Run Attempt ID: {{runAttempt.id}}
3737
</div>

app/pods/components/code-challenge/code-challenge-code-editor/component.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export default class CodeEditor extends Component {
129129
const payload = yield this.api.request("code_challenges/submit", {
130130
method: "POST",
131131
data: {
132-
problemId: this.codeChallenge.get("hbProblemId"),
132+
contentId: this.codeChallenge.get("hbContentId"),
133133
custom_input: Base64.encode(this.customInputText),
134134
source: Base64.encode(this.selectedLanguage.source),
135135
language: this.selectedLanguage.code,
@@ -151,7 +151,7 @@ export default class CodeEditor extends Component {
151151
method: "POST",
152152
data: {
153153
contestId: runAttempt.get("run.contestId"),
154-
problemId: this.codeChallenge.get("hbProblemId"),
154+
contentId: this.codeChallenge.get("hbContentId"),
155155
language: this.selectedLanguage.code,
156156
source: Base64.encode(this.selectedLanguage.source)
157157
}
@@ -162,21 +162,19 @@ export default class CodeEditor extends Component {
162162
"method": "GET"
163163
}), submissionStatus => submissionStatus && submissionStatus['judge-result'] !== null);
164164

165-
this.get('api').request('code_challenges/problems',{
165+
this.get('api').request(`code_challenges/${this.codeChallenge.get('id')}/problems`,{
166166
data: {
167-
contest_id: runAttempt.get("run.contestId"),
168-
problem_id: this.codeChallenge.get("hbProblemId")
167+
contest_id: runAttempt.get("run.contestId")
169168
},
170169
}).then(async result=>{
171170
this.set("problemJsonApiPayload", result);
172171
const payload = JSON.parse(JSON.stringify(result))
173172
this.get('store').unloadAll('problem')
174173
later(async() => {
175174
this.get('store').pushPayload(payload)
176-
const problem = await this.get('store').peekRecord('problem', this.codeChallenge.get('hbProblemId'))
175+
const problem = await this.get('store').peekRecord('problem', result.data.id)
177176
if (await problem.get('hasLatestSubmissionPassed') && await problem.get('mostSuccessfullSubmission.score') == 100) {
178177
const progress = await this.get('content.progress')
179-
debugger
180178
progress.set("status", 'DONE')
181179
return progress.save();
182180
}
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
<p>
2-
{{markdown-to-html problem.content.description}}
2+
{{markdown-to-html problem.details.description}}
33
</p>
44
<div class="extra-bold">Input Format</div>
55
<p>
6-
{{markdown-to-html problem.content.input-format}}
6+
{{markdown-to-html problem.details.input-format}}
77
</p>
88
<div class="extra-bold">Constraints</div>
99
<div class="bg-dark-grey br-5 w-60 px-4 py-2 my-2">
1010
<p>
11-
{{markdown-to-html problem.content.constraints}}
11+
{{markdown-to-html problem.details.constraints}}
1212
</p>
1313
</div>
1414
<div class="extra-bold">Output Format</div>
1515
<p>
16-
{{markdown-to-html problem.content.output-format}}
16+
{{markdown-to-html problem.details.output-format}}
1717
</p>
1818
<div class="extra-bold">Sample Input</div>
1919
<div class="bg-dark-grey br-5 w-60 px-4 py-2 my-2">
20-
<pre>{{problem.content.sample-input}}</pre>
20+
<pre>{{problem.details.sample-input}}</pre>
2121
</div>
2222
<div class="extra-bold">Sample Output</div>
2323
<div class="bg-dark-grey br-5 w-60 px-4 py-2 my-2">
24-
<pre>{{problem.content.sample-output}}</pre>
24+
<pre>{{problem.details.sample-output}}</pre>
2525
</div>
26-
{{#if problem.content.explanation}}
26+
{{#if problem.details.explanation}}
2727
<div class="extra-bold">Explanation</div>
2828
<div class="bg-dark-grey br-5 w-60 px-4 py-2 my-2">
29-
{{markdown-to-html problem.content.explanation}}
29+
{{markdown-to-html problem.details.explanation}}
3030
</div>
3131
{{/if}}

app/pods/components/code-challenge/code-challenge-leaderboard/component.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@ export default class LeaderboardComponent extends Component {
1010

1111
@restartableTask fetchLeaderboardTask = function *() {
1212
const runAttempt = this.store.peekRecord('run-attempt', this.player.runAttemptId)
13-
yield this.hbApi.request('submissions/leaderboard', {
13+
yield this.hbApi.request('content-leaderboards', {
1414
data: {
15-
contest_id: runAttempt.get("run.contestId"),
16-
problem_id: this.codeChallenge.get("hbProblemId")
15+
filter: {
16+
contestId: runAttempt.get("run.contestId"),
17+
contentId: this.codeChallenge.get("hbContentId")
18+
},
19+
include: 'user,college'
1720
}
1821
}).then(result => {
19-
this.store.unloadAll('problem-leaderboard')
22+
this.store.unloadAll('content-leaderboard')
2023
later(() => {
2124
this.store.pushPayload(result)
22-
this.set('leaderboard', this.get('store').peekAll('problem-leaderboard'))
25+
this.set('leaderboard', this.get('store').peekAll('content-leaderboard'))
2326
})
2427
})
2528
}

app/pods/components/code-challenge/code-challenge-solution/component.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default class CodeChallengeSolution extends Component {
2323
type: "GET",
2424
data: {
2525
contest_id: runAttempt.run.get("contestId"),
26-
p_id: this.codeChallenge.get('hbProblemId')
26+
p_id: this.problem.get('id')
2727
}
2828
}
2929
);
@@ -38,7 +38,7 @@ export default class CodeChallengeSolution extends Component {
3838
type: "GET",
3939
data: {
4040
contest_id: runAttempt.run.get("contestId"),
41-
p_id: this.codeChallenge.get('hbProblemId')
41+
p_id: this.problem.get('id')
4242
}
4343
})
4444
return testcasesPayload.data.map(t => ({
@@ -52,7 +52,7 @@ export default class CodeChallengeSolution extends Component {
5252
this.set('api.headers.hackJwt', this.get('currentUser.user.hackJwt'))
5353
yield this
5454
.get("api")
55-
.request(`code_challenges/`+ which +`?contest_id=${runAttempt.run.get("contestId")}&p_id=${this.codeChallenge.get("hbProblemId")}&force=true`)
55+
.request(`code_challenges/`+ which +`?contest_id=${runAttempt.run.get("contestId")}&p_id=${this.problem.get("id")}&force=true`)
5656

5757
return (which === 'editorials' ? this.fetchEditorialTask : this.fetchTestcaseTask).perform()
5858
}

app/pods/components/code-challenge/code-challenge-submission/component.js

+23
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,33 @@
11
import Component from '@ember/component';
22
import { action } from '@ember/object';
3+
import { restartableTask } from 'ember-concurrency-decorators';
4+
import { inject as service } from '@ember/service';
35

46
export default class SubmissionComponent extends Component {
7+
@service hbApi
8+
@service player
9+
@service store
10+
511
submissionToView = null
612
viewSubmissionCode = false
713

14+
@restartableTask fetchSubmissionsTask = function *() {
15+
const runAttempt = this.store.peekRecord('run-attempt', this.player.runAttemptId)
16+
return this.hbApi.request('submissions', {
17+
data: {
18+
filter: {
19+
contest_id: runAttempt.get("run.contestId"),
20+
content_id: this.codeChallenge.get("hbContentId")
21+
},
22+
sort: '-createdAt'
23+
}
24+
}).then(submissions => {
25+
this.store.unloadAll('submission')
26+
this.store.pushPayload(submissions)
27+
return this.store.peekAll('submission')
28+
})
29+
}
30+
831
@action
932
viewSubmission(submission) {
1033
this.set('submissionToView', submission)

app/pods/components/code-challenge/code-challenge-submission/template.hbs

+30-26
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
1-
<table class="w-100">
2-
<thead class="bold">
3-
<tr>
4-
<td class="pb-2">Result</td>
5-
<td class="pb-2">Score</td>
6-
<td class="pb-2">Time</td>
7-
<td class="pb-2">Language</td>
8-
<td class="pb-2">Test Cases</td>
9-
</tr>
10-
</thead>
11-
<tbody>
12-
{{#each problem.submissions as |submission|}}
1+
<WAsync
2+
@task={{fetchSubmissionsTask}}
3+
@autoFire="true" as |submissions|>
4+
<table class="w-100">
5+
<thead class="bold">
136
<tr>
14-
<td class="pb-4 pt-4 {{submission.resultParams.color}} font-sm">
15-
<FaIcon @icon={{submission.resultParams.icon}} class="pr-3" />
16-
<span>{{submission.resultParams.message}}</span>
17-
<a href="#" class="orange font-xs bold ml-3" {{action "viewSubmission" submission}}>View</a>
18-
</td>
19-
<td class="pb-4 pt-4">{{submission.score}}/100</td>
20-
<td class="pb-4 pt-4">{{submission.executionTime}}</td>
21-
<td class="pb-4 pt-4">{{submission.language}}</td>
22-
<td class="pb-4 pt-4">
23-
Passed: {{submission.passedTestCasesArray.length}} | Failed: {{submission.failedTestCasesArray.length}}
24-
</td>
7+
<td class="pb-2">Result</td>
8+
<td class="pb-2">Score</td>
9+
<td class="pb-2">Time</td>
10+
<td class="pb-2">Language</td>
11+
<td class="pb-2">Test Cases</td>
2512
</tr>
26-
{{/each}}
27-
</tbody>
28-
</table>
13+
</thead>
14+
<tbody>
15+
{{#each submissions as |submission|}}
16+
<tr>
17+
<td class="pb-4 pt-4 {{submission.resultParams.color}} font-sm">
18+
<FaIcon @icon={{submission.resultParams.icon}} class="pr-3" />
19+
<span>{{submission.resultParams.message}}</span>
20+
<a href="#" class="orange font-xs bold ml-3" {{action "viewSubmission" submission}}>View</a>
21+
</td>
22+
<td class="pb-4 pt-4">{{submission.score}}/100</td>
23+
<td class="pb-4 pt-4">{{submission.executionTime}}</td>
24+
<td class="pb-4 pt-4">{{submission.language}}</td>
25+
<td class="pb-4 pt-4">
26+
Passed: {{submission.passedTestCasesArray.length}} | Failed: {{submission.failedTestCasesArray.length}}
27+
</td>
28+
</tr>
29+
{{/each}}
30+
</tbody>
31+
</table>
32+
</WAsync>
2933

3034
{{#if (and submissionToView viewSubmissionCode)}}
3135
{{#modal-dialog

app/pods/components/leaderboard-component/component.js

-25
This file was deleted.

app/pods/components/leaderboard-component/template.hbs

-30
This file was deleted.

app/pods/components/problem-statement-component/component.js

-12
This file was deleted.

0 commit comments

Comments
 (0)