summaryrefslogtreecommitdiff
path: root/src/scripts/main.entry.ts
blob: 48ab7f372fadac7240844d57420d0b4f8dba9dc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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() {
        const canvas = $("#main-canvas");
        const 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);
                    });
                });
        });

    }
}