|
1 | 1 | import Component from '@ember/component'; |
2 | 2 | import { computed } from '@ember/object'; |
| 3 | +import { jsonToTable } from '../../../util/json-to-table'; |
| 4 | +// const data = { |
| 5 | +// "meta": {}, |
| 6 | +// "data": { |
| 7 | +// "type": "submissions", |
| 8 | +// "id": "7298192", |
| 9 | +// "attributes": { |
| 10 | +// "id": 7298192, |
| 11 | +// "solution": { |
| 12 | +// "source": "U0VMRUNUIGUubmFtZSBBUyAiRW1wbG95ZWUiIEZST00gRW1wbG95ZWUgYXMgZQpJTk5FUiBKT0lOIEVtcGxveWVlIGFzIG0KT04gZS5tYW5hZ2VySWQgPSBtLmlkCldIRVJFIGUuc2FsYXJ5ID4gbS5zYWxhcnk7" |
| 13 | +// }, |
| 14 | +// "submit-at": "2025-02-19T09:00:58.477Z", |
| 15 | +// "language": "mysql", |
| 16 | +// "score": 0, |
| 17 | +// "result": -1, |
| 18 | +// "judge-result": { |
| 19 | +// "id": 116, |
| 20 | +// "code": 0, |
| 21 | +// "time": 1.22, |
| 22 | +// "stderr": "", |
| 23 | +// "stdout": "W3siRW1wbG95ZWUiOiJKb2UifV0K", |
| 24 | +// "scenario": "run" |
| 25 | +// }, |
| 26 | +// "explanation": null, |
| 27 | +// "is-top-submission": false, |
| 28 | +// "plagiarism-detected": false, |
| 29 | +// "created-at": "2025-02-19T09:00:58.478Z" |
| 30 | +// }, |
| 31 | +// "relationships": { |
| 32 | +// "user": { "data": { "type": "users", "id": "241321" } }, |
| 33 | +// "content": { "data": { "type": "contents", "id": "1747" } }, |
| 34 | +// "contest": { "data": null }, |
| 35 | +// "badge": { "data": null } |
| 36 | +// } |
| 37 | +// } |
| 38 | +// }; |
| 39 | +export default Component.extend({ |
| 40 | + // judgeResult: null, |
| 41 | + // allowedLanguages: null, |
3 | 42 |
|
4 | | -export default class SubmissionResult extends Component { |
5 | 43 | didRender() { |
6 | | - this.element.scrollIntoView({ behavior: "smooth", block: "end" }) |
7 | | - } |
| 44 | + this._super(...arguments); |
| 45 | + this.element.scrollIntoView({ behavior: "smooth", block: "end" }); |
8 | 46 |
|
9 | | - @computed('judgeResult') |
10 | | - get isRunning() { |
11 | | - return !this.judgeResult |
12 | | - } |
| 47 | + // this.set('judgeResult', data.data.attributes['judge-result']); |
| 48 | + // this.set('allowedLanguages', this.get('allowedLanguages')); |
| 49 | + // console.log('judgeResult:', this.get('judgeResult')); |
| 50 | + // console.log('Allowed Languages:', this.allowedLanguages); |
| 51 | + }, |
13 | 52 |
|
14 | | - @computed('judgeResult') |
15 | | - get isErrored() { |
16 | | - return !!this.judgeResult.stderr |
17 | | - } |
| 53 | + isRunning: computed('judgeResult', function() { |
| 54 | + return !this.get('judgeResult'); |
| 55 | + }), |
18 | 56 |
|
19 | | - @computed('judgeResult') |
20 | | - get isSubmission() { |
21 | | - return !!(this.judgeResult.testcases) |
22 | | - } |
| 57 | + isErrored: computed('judgeResult', function() { |
| 58 | + return !!this.get('judgeResult')?.stderr; |
| 59 | + }), |
| 60 | + |
| 61 | + isSubmission: computed('judgeResult', function() { |
| 62 | + return !!this.get('judgeResult')?.testcases; |
| 63 | + }), |
23 | 64 |
|
24 | | - @computed('isErrored') |
25 | | - get errorPayload() { |
26 | | - if (this.isErrored) { |
27 | | - return window.atob(this.judgeResult.stderr || this.judgeResult.stdout) |
| 65 | + errorPayload: computed('isErrored', function() { |
| 66 | + if (this.get('isErrored')) { |
| 67 | + return window.atob(this.get('judgeResult')?.stderr || this.get('judgeResult')?.stdout); |
28 | 68 | } |
29 | | - } |
| 69 | + }), |
| 70 | + |
| 71 | + output: computed('isSubmission', function() { |
| 72 | + if (!this.get('isSubmission')) { |
| 73 | + const output = window.atob(this.get('judgeResult')?.stdout); |
30 | 74 |
|
31 | | - @computed('isSubmission') |
32 | | - get output() { |
33 | | - if (!this.isSubmission) { |
34 | | - return window.atob(this.judgeResult.stdout) |
| 75 | + return output; |
35 | 76 | } |
36 | | - } |
| 77 | + }), |
37 | 78 |
|
38 | | - @computed('isSubmission') |
39 | | - get testcasesPayload() { |
40 | | - if (this.isSubmission) { |
41 | | - return this.judgeResult.testcases |
| 79 | + testcasesPayload: computed('isSubmission', function() { |
| 80 | + if (this.get('isSubmission')) { |
| 81 | + return this.get('judgeResult')?.testcases; |
42 | 82 | } |
| 83 | + }), |
| 84 | + |
| 85 | + jsonToTable(data) { |
| 86 | + const table = jsonToTable(data); |
| 87 | + // console.log('jsonToTable output:', table); |
| 88 | + return table; |
43 | 89 | } |
44 | | -} |
| 90 | +}); |
0 commit comments