summaryrefslogtreecommitdiff
path: root/src/scripts/main.entry.ts
diff options
context:
space:
mode:
authorGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-01-24 12:06:09 +0100
committerGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-01-24 12:06:09 +0100
commitc96e6ffafb62bde1e08987b1fdf3c0786487f6ec (patch)
tree37eaf4cf199ca77dc131b4212c526b707adf2e30 /src/scripts/main.entry.ts
Initial commit
Diffstat (limited to 'src/scripts/main.entry.ts')
-rw-r--r--src/scripts/main.entry.ts69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/scripts/main.entry.ts b/src/scripts/main.entry.ts
new file mode 100644
index 00000000..c7d6ef90
--- /dev/null
+++ b/src/scripts/main.entry.ts
@@ -0,0 +1,69 @@
+///<reference path="../../typings/index.d.ts" />
+///<reference path="./views/mapview.ts" />
+import * as $ from "jquery";
+import {MapView} from "./views/mapview";
+import {APIController} from "./controllers/connection/api";
+window["$"] = $;
+require("jquery-mousewheel");
+window["jQuery"] = $;
+
+require("./user");
+
+
+$(document).ready(function () {
+ new Display(); //tslint:disable-line:no-unused-expression
+});
+
+
+/**
+ * Class responsible for launching the main view.
+ */
+class Display {
+ private stage: createjs.Stage;
+ private view: MapView;
+
+
+ /**
+ * Adjusts the canvas size to fit the window's initial dimensions (full expansion).
+ */
+ private static fitCanvasSize() {
+ let canvas = $("#main-canvas");
+ let parent = canvas.parent();
+ parent.height($(window).height() - 50);
+ canvas.attr("width", parent.width());
+ canvas.attr("height", parent.height());
+ }
+
+ constructor() {
+ // Check whether project has been selected before going to the app page
+ if (localStorage.getItem("simulationId") === null) {
+ window.location.replace("projects");
+ return;
+ }
+
+ Display.fitCanvasSize();
+ this.stage = new createjs.Stage("main-canvas");
+
+ new APIController((api: APIController) => {
+ api.getSimulation(parseInt(localStorage.getItem("simulationId")))
+ .then((simulationData: ISimulation) => {
+ if (simulationData.name !== "") {
+ document.title = simulationData.name + " | OpenDC";
+ }
+
+ api.getPathsBySimulation(simulationData.id)
+ .then((pathData: IPath[]) => {
+ simulationData.paths = pathData;
+ }).then(() => {
+ return api.getExperimentsBySimulation(simulationData.id);
+ }).then((experimentData: IExperiment[]) => {
+ $(".loading-overlay").hide();
+
+ simulationData.experiments = experimentData;
+ this.view = new MapView(simulationData, this.stage);
+ });
+ });
+ });
+
+ }
+}