aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2016-04-06 21:09:01 +0900
committerKazuki Yamaguchi <k@rhe.jp>2016-04-06 21:09:01 +0900
commitb42d3e56e62572cb7fbf8b060648a81ed0c79be5 (patch)
tree51af0dd9093802a30f73df4c580afc82ea26ff05
parent8c13d60fb068bf00ffd1336abf4f4207bbf2a513 (diff)
downloadpoe-b42d3e56e62572cb7fbf8b060648a81ed0c79be5.tar.gz
frontend: prototype をむりやり取り替えることで型キャストする
-rw-r--r--frontend/app/app.component.ts2
-rw-r--r--frontend/app/snippet-detail.component.ts31
-rw-r--r--frontend/app/snippet.service.ts61
3 files changed, 65 insertions, 29 deletions
diff --git a/frontend/app/app.component.ts b/frontend/app/app.component.ts
index 57e0039..67b3f17 100644
--- a/frontend/app/app.component.ts
+++ b/frontend/app/app.component.ts
@@ -48,7 +48,7 @@ import {EditorComponent} from "./editor.component";
])
export class AppComponent {
private editing: EditingData;
- private poe_description = "run code in 15+ Ruby interpreters";
+ private poe_description = "eval code in 15+ Ruby interpreters";
constructor(
private _service: SnippetService,
diff --git a/frontend/app/snippet-detail.component.ts b/frontend/app/snippet-detail.component.ts
index 72640f2..cdacb64 100644
--- a/frontend/app/snippet-detail.component.ts
+++ b/frontend/app/snippet-detail.component.ts
@@ -8,10 +8,10 @@ import {EditingData, EditingDataService} from "./editing-data.service";
<div class="result-items-container" *ngIf="snippet">
<div class="result-item panel"
*ngFor="#group of result_classes; #i = index"
- [ngClass]="{'panel-success': isSuccess(group.results[0]), 'panel-failure': isFailure(group.results[0]), 'panel-running': isRunning(group.results[0])}">
+ [ngClass]="group.status_class_table">
<div class="panel-heading" [id]="'result-type-'+i">
<div *ngFor="#r of group.results" class="result-compiler-tab-item" (click)="group.current = r" [ngClass]="{'active': group.current === r}">
- {{r.compiler.id}} ({{r.elapsed_ms}}ms)
+ {{r.compiler.abbrev()}} ({{r.elapsed_ms}}ms)
</div>
</div>
<div class="panel-body" *ngIf="group.current">
@@ -46,7 +46,7 @@ export class SnippetDetailComponent implements OnInit {
// Result に移動したいんだけどどうすればいいんだろ
formatted_output(r: Result): string {
- if (this.isRunning(r)) return "Running...";
+ if (r.isRunning()) return "Running...";
if (r._) return r._; // うーーーーーーーーーーん💩
let str = "";
@@ -85,26 +85,21 @@ export class SnippetDetailComponent implements OnInit {
return str;
}
- isSuccess(r: Result) {
- return r.result === 0 && r.exit === 0;
- }
-
- isFailure(r: Result) {
- return !this.isRunning(r) && !this.isSuccess(r);
- }
-
- isRunning(r: Result) {
- return r.result === null;
- }
-
classifyResults() {
var classes = [];
this.snippet.results.slice().reverse().forEach(curr => {
const found = classes.some(group =>
- Result.compareOutput(curr, group.results[0]) &&
- group.results.push(curr));
+ curr.isSameResult(group.results[0]) && group.results.push(curr));
if (!found)
- classes.push({ current: curr, results: [curr] });
+ classes.push({
+ current: curr,
+ results: [curr],
+ status_class_table: {
+ "panel-success": curr.isSuccess(),
+ "panel-failure": curr.isFailure(),
+ "panel-running": curr.isRunning()
+ },
+ });
});
this.result_classes = classes;
}
diff --git a/frontend/app/snippet.service.ts b/frontend/app/snippet.service.ts
index 92e62c5..dbf3332 100644
--- a/frontend/app/snippet.service.ts
+++ b/frontend/app/snippet.service.ts
@@ -4,13 +4,29 @@ import {Observable} from "rxjs/Observable";
import {EditingData} from "./editing-data.service";
export class Compiler {
+ private static _pt = (<any>new Compiler()).__proto__;
public id: string;
+ public lang: string;
public version: string;
public version_command: string;
public commandline: string[];
+
+ // これどうしたらいいんだろ
+ public static fromJSON(obj: any): Compiler {
+ obj.__proto__ = Compiler._pt;
+ return obj;
+ }
+
+ public abbrev() {
+ if (this.id.startsWith(this.lang + "-"))
+ return this.id.substr(this.lang.length + 1);
+ else
+ return this.id;
+ }
}
export class Result {
+ private static _pt = (<any>new Result()).__proto__;
public compiler: Compiler;
public result: number;
public exit: number;
@@ -20,22 +36,47 @@ export class Result {
public _: string;
public truncated: boolean;
- public static compareOutput(a: Result, b: Result) {
- return a.result === b.result &&
- a.exit === b.exit &&
- a.message === b.message &&
- a.output && b.output &&
- a.output.every((c, i) => b.output[i] && c[0] === b.output[i][0] && c[1] === b.output[i][1]) &&
- a.truncated === b.truncated;
+ public static fromJSON(obj: any): Result {
+ obj.__proto__ = Result._pt;
+ Compiler.fromJSON(obj.compiler);
+ return obj;
+ }
+
+ public isSameResult(b: Result) {
+ return this.result === b.result &&
+ this.exit === b.exit &&
+ this.message === b.message &&
+ this.output && b.output &&
+ this.output.every((c, i) => b.output[i] && c[0] === b.output[i][0] && c[1] === b.output[i][1]) &&
+ this.truncated === b.truncated;
+ }
+
+ public isRunning() {
+ return this.result === null;
+ }
+
+ public isSuccess() {
+ return this.result === 0 && this.exit === 0;
+ }
+
+ public isFailure() {
+ return !this.isSuccess() && !this.isRunning();
}
}
export class Snippet {
+ private static _pt = (<any>new Snippet()).__proto__;
public id: string;
public lang: string;
public code: string;
public created: number;
public results: Result[];
+
+ public static fromJSON(obj: any): Snippet {
+ obj.__proto__ = Snippet._pt;
+ obj.results.forEach(Result.fromJSON);
+ return obj;
+ }
}
@Injectable()
@@ -44,7 +85,7 @@ export class SnippetService {
getSnippet(id: string) {
return this.http.get("/api/snippet/" + id)
- .map(res => <Snippet>res.json())
+ .map(res => Snippet.fromJSON(res.json()))
.catch(this.handleError);
}
@@ -54,7 +95,7 @@ export class SnippetService {
code: edit.code
};
return this.http.post("/api/snippet/new", this.urlEncode(data))
- .map(res => <Snippet>res.json())
+ .map(res => Snippet.fromJSON(res.json()))
.catch(this.handleError);
}
@@ -64,7 +105,7 @@ export class SnippetService {
cid: comp.id
};
return this.http.post("/api/snippet/run", this.urlEncode(data))
- .map(res => <Result>res.json())
+ .map(res => Result.fromJSON(res.json()))
.catch(this.handleError);
}