summaryrefslogtreecommitdiff
path: root/src/scripts
diff options
context:
space:
mode:
authorGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-01-26 23:26:20 +0100
committerGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-01-26 23:26:20 +0100
commitb0b5253f66f5ba6e031f5a88dc1bef613517b3b6 (patch)
treef764e84ad48de6cb514cbc97e366c21d734e247c /src/scripts
parent027b379cf9d53a12782781e586f79051461ab661 (diff)
Refactor remaining codebase to use 'const'
Diffstat (limited to 'src/scripts')
-rw-r--r--src/scripts/error404.entry.ts12
-rw-r--r--src/scripts/main.entry.ts4
-rw-r--r--src/scripts/profile.entry.ts8
-rw-r--r--src/scripts/projects.entry.ts40
-rw-r--r--src/scripts/serverconnection.ts6
-rw-r--r--src/scripts/splash.entry.ts27
-rw-r--r--src/scripts/user.ts8
-rw-r--r--src/scripts/util.ts59
-rw-r--r--src/scripts/views/layers/dcobject.ts18
-rw-r--r--src/scripts/views/layers/dcprogressbar.ts6
-rw-r--r--src/scripts/views/layers/gray.ts6
-rw-r--r--src/scripts/views/layers/room.ts6
-rw-r--r--src/scripts/views/layers/roomtext.ts6
-rw-r--r--src/scripts/views/mapview.ts48
14 files changed, 123 insertions, 131 deletions
diff --git a/src/scripts/error404.entry.ts b/src/scripts/error404.entry.ts
index 07dc9ca0..477a46c0 100644
--- a/src/scripts/error404.entry.ts
+++ b/src/scripts/error404.entry.ts
@@ -3,24 +3,24 @@ import * as $ from "jquery";
$(document).ready(() => {
- let text =
+ const text =
" oo oooo oo <br>" +
" oo oo oo oo <br>" +
" oo oo oo oo <br>" +
" oooooo oo oo oooooo <br>" +
" oo oo oo oo <br>" +
" oo oooo oo <br>";
- let charList = text.split('');
+ const charList = text.split('');
- let binary = "01001111011100000110010101101110010001000100001100100001";
- let binaryIndex = 0;
+ const binaryString = "01001111011100000110010101101110010001000100001100100001";
+ let binaryIndex = 0;
for (let i = 0; i < charList.length; i++) {
if (charList[i] === "o") {
- charList[i] = binary[binaryIndex];
+ charList[i] = binaryString[binaryIndex];
binaryIndex++;
}
}
$(".code-block").html(charList.join(""));
-}); \ No newline at end of file
+});
diff --git a/src/scripts/main.entry.ts b/src/scripts/main.entry.ts
index c7d6ef90..48ab7f37 100644
--- a/src/scripts/main.entry.ts
+++ b/src/scripts/main.entry.ts
@@ -27,8 +27,8 @@ class Display {
* Adjusts the canvas size to fit the window's initial dimensions (full expansion).
*/
private static fitCanvasSize() {
- let canvas = $("#main-canvas");
- let parent = canvas.parent();
+ const canvas = $("#main-canvas");
+ const parent = canvas.parent();
parent.height($(window).height() - 50);
canvas.attr("width", parent.width());
canvas.attr("height", parent.height());
diff --git a/src/scripts/profile.entry.ts b/src/scripts/profile.entry.ts
index 57c6b56c..b194e3a9 100644
--- a/src/scripts/profile.entry.ts
+++ b/src/scripts/profile.entry.ts
@@ -6,14 +6,14 @@ window["jQuery"] = $;
$(document).ready(() => {
- let api = new APIController(() => {
+ const api = new APIController(() => {
});
$("#delete-account").on("click", () => {
- let modalDialog = <any>$("#confirm-delete-account");
+ const modalDialog = <any>$("#confirm-delete-account");
// Function called on delete confirmation
- let callback = () => {
+ const callback = () => {
api.deleteUser(parseInt(localStorage.getItem("userId"))).then(() => {
removeUserInfo();
gapi.auth2.getAuthInstance().signOut().then(() => {
@@ -23,7 +23,7 @@ $(document).ready(() => {
modalDialog.find("button.confirm").off();
modalDialog.modal("hide");
- let alert = $(".account-delete-alert");
+ const alert = $(".account-delete-alert");
alert.find("code").text(reason.code + ": " + reason.description);
alert.slideDown(200);
diff --git a/src/scripts/projects.entry.ts b/src/scripts/projects.entry.ts
index 1ceb308b..9ae78586 100644
--- a/src/scripts/projects.entry.ts
+++ b/src/scripts/projects.entry.ts
@@ -12,7 +12,7 @@ $(document).ready(() => {
new APIController((apiInstance: APIController) => {
api = apiInstance;
api.getAuthorizationsByUser(parseInt(localStorage.getItem("userId"))).then((data: any) => {
- let projectsController = new ProjectsController(data, api);
+ const projectsController = new ProjectsController(data, api);
new WindowController(projectsController, api);
});
});
@@ -54,7 +54,7 @@ class ProjectsController {
* @param list The list of authorizations to be displayed
*/
public static populateList(list: IAuthorization[]): void {
- let body = $(".project-list .list-body");
+ const body = $(".project-list .list-body");
body.empty();
list.forEach((element: IAuthorization) => {
@@ -82,7 +82,7 @@ class ProjectsController {
* @returns {IAuthorization[]} A filtered list of authorizations
*/
public static filterList(list: IAuthorization[], ownedByUser: boolean): IAuthorization[] {
- let resultList: IAuthorization[] = [];
+ const resultList: IAuthorization[] = [];
list.forEach((element: IAuthorization) => {
if (element.authorizationLevel === "OWN") {
@@ -160,12 +160,12 @@ class ProjectsController {
* @param target The element that was clicked on to launch this view
*/
private displayProjectView(target: JQuery): void {
- let closestRow = target.closest(".project-row");
- let activeElement = $(".project-row.active");
+ const closestRow = target.closest(".project-row");
+ const activeElement = $(".project-row.active");
// Disable previously selected row elements and remove any project-views, to have only one view open at a time
if (activeElement.length > 0) {
- let view = $(".project-view").first();
+ const view = $(".project-view").first();
view.slideUp(200, () => {
activeElement.removeClass("active");
@@ -177,19 +177,19 @@ class ProjectsController {
}
}
- let simulationId = parseInt(closestRow.attr("data-id"), 10);
+ const simulationId = parseInt(closestRow.attr("data-id"), 10);
// Generate a list of participants of this project
this.api.getAuthorizationsBySimulation(simulationId).then((data: any) => {
- let simAuthorizations = data;
- let participants = [];
+ const simAuthorizations = data;
+ const participants = [];
Util.sortAuthorizations(simAuthorizations);
// For each participant of this simulation, include his/her name along with an icon of their authorization
// level in the list
simAuthorizations.forEach((authorization: IAuthorization) => {
- let authorizationString = ' (<span class="glyphicon ' +
+ const authorizationString = ' (<span class="glyphicon ' +
ProjectsController.authIconMap[authorization.authorizationLevel] + '"></span>)';
if (authorization.userId === this.currentUserId) {
participants.push(
@@ -203,7 +203,7 @@ class ProjectsController {
});
// Generate a project view component with participants and relevant actions
- let object = $('<div class="project-view">').append(
+ const object = $('<div class="project-view">').append(
$('<div class="participants">').append(
$('<strong>').text("Participants"),
$('<div>').html(participants.join(", "))
@@ -217,7 +217,7 @@ class ProjectsController {
closestRow.after(object);
// Hide the 'edit' button for non-owners and -editors
- let currentAuth = this.authorizationsFiltered[closestRow.index(".project-row")];
+ const currentAuth = this.authorizationsFiltered[closestRow.index(".project-row")];
if (currentAuth.authorizationLevel !== "OWN") {
$(".project-view .inline-btn.edit").hide();
}
@@ -380,7 +380,7 @@ class WindowController {
$(".project-name-form input").val(authorizations[0].simulation.name);
$(".project-name-form .btn").css("display", "inline-block").click(() => {
- let nameInput = $(".project-name-form input").val();
+ const nameInput = $(".project-name-form input").val();
if (nameInput !== "") {
authorizations[0].simulation.name = nameInput;
this.api.updateSimulation(authorizations[0].simulation);
@@ -528,7 +528,7 @@ class WindowController {
* @param name A selector that uniquely identifies the alert body to be shown.
*/
private showAlert(name): void {
- let alert = $(name);
+ const alert = $(name);
alert.slideDown(200);
setTimeout(() => {
@@ -556,7 +556,7 @@ class WindowController {
$(event.target).closest(".participant-level").find("div").removeClass("active");
$(event.target).addClass("active");
- let affectedRow = $(event.target).closest(".participant-row");
+ const affectedRow = $(event.target).closest(".participant-row");
for (let level in ProjectsController.authIconMap) {
if (!ProjectsController.authIconMap.hasOwnProperty(level)) {
@@ -576,7 +576,7 @@ class WindowController {
* @param callback The function to be called if the participant could be found and can be added.
*/
private handleParticipantAdd(callback: (userId: number) => any): void {
- let inputForm = $(".participant-add-form input");
+ const inputForm = $(".participant-add-form input");
this.api.getUserByEmail(inputForm.val()).then((data: any) => {
let insert = true;
for (let i = 0; i < this.simAuthorizations.length; i++) {
@@ -585,7 +585,7 @@ class WindowController {
}
}
- let simulationId = this.editMode ? this.simulationId : -1;
+ const simulationId = this.editMode ? this.simulationId : -1;
if (data.id !== this.projectsController.currentUserId && insert) {
this.simAuthorizations.push({
userId: data.id,
@@ -614,9 +614,9 @@ class WindowController {
* @param callback The function to be executed on removal of the participant from the internal list
*/
private handleParticipantDelete(event: JQueryEventObject, callback: (authorization: IAuthorization) => any): void {
- let affectedRow = $(event.target).closest(".participant-row");
- let index = affectedRow.index();
- let authorization = this.simAuthorizations[index];
+ const affectedRow = $(event.target).closest(".participant-row");
+ const index = affectedRow.index();
+ const authorization = this.simAuthorizations[index];
this.simAuthorizations.splice(index, 1);
this.populateParticipantList();
callback(authorization);
diff --git a/src/scripts/serverconnection.ts b/src/scripts/serverconnection.ts
index c7f6e598..e5cbf48a 100644
--- a/src/scripts/serverconnection.ts
+++ b/src/scripts/serverconnection.ts
@@ -11,7 +11,7 @@ export class ServerConnection {
public static send(request: IRequest): Promise<any> {
return new Promise((resolve, reject) => {
- let checkUnimplemented = ServerConnection.interceptUnimplementedEndpoint(request);
+ const checkUnimplemented = ServerConnection.interceptUnimplementedEndpoint(request);
if (checkUnimplemented) {
resolve(checkUnimplemented.content);
return;
@@ -28,7 +28,7 @@ export class ServerConnection {
}
public static convertFlatToNestedPositionData(responseContent, resolve): void {
- let nestPositionCoords = (content: any) => {
+ const nestPositionCoords = (content: any) => {
if (content["positionX"] !== undefined) {
content["position"] = {
x: content["positionX"],
@@ -56,4 +56,4 @@ export class ServerConnection {
// Endpoints that are unimplemented can be intercepted here
return null;
}
-} \ No newline at end of file
+}
diff --git a/src/scripts/splash.entry.ts b/src/scripts/splash.entry.ts
index c1be1c28..700f52bb 100644
--- a/src/scripts/splash.entry.ts
+++ b/src/scripts/splash.entry.ts
@@ -15,7 +15,7 @@ $(document).ready(() => {
* jQuery for page scrolling feature
*/
$('a.page-scroll').bind('click', function (event) {
- let $anchor = $(this);
+ const $anchor = $(this);
$('html, body').stop().animate({
scrollTop: $($anchor.attr('href')).offset().top
}, 1000, 'easeInOutExpo', () => {
@@ -28,7 +28,7 @@ $(document).ready(() => {
event.preventDefault();
});
- let checkScrollState = () => {
+ const checkScrollState = () => {
const startY = 100;
if ($(window).scrollTop() > startY || window.innerWidth < 768) {
@@ -44,7 +44,7 @@ $(document).ready(() => {
checkScrollState();
- let googleSigninBtn = $("#google-signin");
+ const googleSigninBtn = $("#google-signin");
googleSigninBtn.click(() => {
hasClickedLogin = true;
});
@@ -56,7 +56,7 @@ $(document).ready(() => {
googleSigninBtn.hide();
$(".navbar .logged-in").css("display", "inline-block");
$(".logged-in .sign-out").click(() => {
- let auth2 = gapi.auth2.getAuthInstance();
+ const auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(() => {
// Remove session storage items
@@ -72,12 +72,12 @@ $(document).ready(() => {
});
// Check whether Google auth. token has expired and signin again if necessary
- let currentTime = (new Date()).getTime();
+ const currentTime = (new Date()).getTime();
if (parseInt(localStorage.getItem("googleTokenExpiration")) - currentTime <= 0) {
gapi.auth2.getAuthInstance().signIn().then(() => {
- let authResponse = gapi.auth2.getAuthInstance().currentUser.get().getAuthResponse();
+ const authResponse = gapi.auth2.getAuthInstance().currentUser.get().getAuthResponse();
localStorage.setItem("googleToken", authResponse.id_token);
- let expirationTime = (new Date()).getTime() / 1000 + parseInt(authResponse.expires_in) - 5;
+ const expirationTime = (new Date()).getTime() / 1000 + parseInt(authResponse.expires_in) - 5;
localStorage.setItem("googleTokenExpiration", expirationTime.toString());
});
}
@@ -98,13 +98,10 @@ window["renderButton"] = () => {
let api;
new APIController((apiInstance: APIController) => {
api = apiInstance;
- let email = googleUser.getBasicProfile().getEmail();
+ const email = googleUser.getBasicProfile().getEmail();
- let getUser = (userId: number) => {
- let reload = true;
- if (localStorage.getItem("userId") !== null) {
- reload = false;
- }
+ const getUser = (userId: number) => {
+ const reload = localStorage.getItem("userId") === null;
localStorage.setItem("userId", userId.toString());
@@ -118,9 +115,9 @@ window["renderButton"] = () => {
};
// Send the token to the server
- let id_token = googleUser.getAuthResponse().id_token;
+ const id_token = googleUser.getAuthResponse().id_token;
// Calculate token expiration time (in seconds since epoch)
- let expirationTime = (new Date()).getTime() / 1000 + googleUser.getAuthResponse().expires_in - 5;
+ const expirationTime = (new Date()).getTime() / 1000 + googleUser.getAuthResponse().expires_in - 5;
$.post('https://opendc.ewi.tudelft.nl/tokensignin', {
idtoken: id_token
diff --git a/src/scripts/user.ts b/src/scripts/user.ts
index dda2dcab..7b157603 100644
--- a/src/scripts/user.ts
+++ b/src/scripts/user.ts
@@ -36,7 +36,7 @@ window["gapiSigninButton"] = () => {
gapi.signin2.render('google-signin', {
'scope': 'profile email',
'onsuccess': (googleUser) => {
- let auth2 = gapi.auth2.getAuthInstance();
+ const auth2 = gapi.auth2.getAuthInstance();
// Handle signout click
$("nav .user .sign-out").click(() => {
@@ -47,12 +47,12 @@ window["gapiSigninButton"] = () => {
});
// Check if the token has expired
- let currentTime = (new Date()).getTime() / 1000;
+ const currentTime = (new Date()).getTime() / 1000;
if (parseInt(localStorage.getItem("googleTokenExpiration")) - currentTime <= 0) {
auth2.signIn().then(() => {
localStorage.setItem("googleToken", googleUser.getAuthResponse().id_token);
- let expirationTime = (new Date()).getTime() / 1000 + parseInt(googleUser.getAuthResponse().expires_in) - 5;
+ const expirationTime = (new Date()).getTime() / 1000 + parseInt(googleUser.getAuthResponse().expires_in) - 5;
localStorage.setItem("googleTokenExpiration", expirationTime.toString());
});
}
@@ -73,4 +73,4 @@ export function removeUserInfo() {
localStorage.removeItem("googleEmail");
localStorage.removeItem("userId");
localStorage.removeItem("simulationId");
-} \ No newline at end of file
+}
diff --git a/src/scripts/util.ts b/src/scripts/util.ts
index d0c6dd38..7aa615ec 100644
--- a/src/scripts/util.ts
+++ b/src/scripts/util.ts
@@ -22,12 +22,12 @@ export class Util {
* Does so by computing an outline around all tiles in the rooms.
*/
public static deriveWallLocations(rooms: IRoom[]): IRoomWall[] {
- let verticalWalls = {};
- let horizontalWalls = {};
+ const verticalWalls = {};
+ const horizontalWalls = {};
let doInsert;
rooms.forEach((room: IRoom) => {
room.tiles.forEach((tile: ITile) => {
- let x = tile.position.x, y = tile.position.y;
+ const x = tile.position.x, y = tile.position.y;
for (let dX = -1; dX <= 1; dX++) {
for (let dY = -1; dY <= 1; dY++) {
if (Math.abs(dX) === Math.abs(dY)) {
@@ -77,10 +77,10 @@ export class Util {
});
});
- let result: IRoomWall[] = [];
- let walls = [verticalWalls, horizontalWalls];
+ const result: IRoomWall[] = [];
+ const walls = [verticalWalls, horizontalWalls];
for (let i = 0; i < 2; i++) {
- let wallList = walls[i];
+ const wallList = walls[i];
for (let a in wallList) {
if (!wallList.hasOwnProperty(a)) {
return;
@@ -91,7 +91,7 @@ export class Util {
});
let startPos = wallList[a][0];
- let positionArray = (i === 1 ? <number[]>[startPos, parseInt(a)] : <number[]>[parseInt(a), startPos]);
+ const positionArray = (i === 1 ? <number[]>[startPos, parseInt(a)] : <number[]>[parseInt(a), startPos]);
if (wallList[a].length === 1) {
result.push({
@@ -144,11 +144,11 @@ export class Util {
* @returns {Array} A 2D list of tile positions that are valid next tile choices.
*/
public static deriveValidNextTilePositions(rooms: IRoom[], selectedTiles: ITile[]): IGridPosition[] {
- let result = [], newPosition = {x: 0, y: 0};
+ const result = [], newPosition = {x: 0, y: 0};
let isSurroundingTile;
selectedTiles.forEach((tile: ITile) => {
- let x = tile.position.x, y = tile.position.y;
+ const x = tile.position.x, y = tile.position.y;
for (let dX = -1; dX <= 1; dX++) {
for (let dY = -1; dY <= 1; dY++) {
if (Math.abs(dX) === Math.abs(dY)) {
@@ -195,10 +195,9 @@ export class Util {
*/
public static tileListPositionIndexOf(list: ITile[], position: IGridPosition): number {
let index = -1;
- let element;
for (let i = 0; i < list.length; i++) {
- element = list[i];
+ const element = list[i];
if (position.x === element.position.x && position.y === element.position.y) {
index = i;
break;
@@ -228,10 +227,9 @@ export class Util {
*/
public static positionListPositionIndexOf(list: IGridPosition[], position: IGridPosition): number {
let index = -1;
- let element;
for (let i = 0; i < list.length; i++) {
- element = list[i];
+ const element = list[i];
if (position.x === element.x && position.y === element.y) {
index = i;
break;
@@ -252,10 +250,9 @@ export class Util {
*/
public static roomCollisionIndexOf(rooms: IRoom[], position: IGridPosition): number {
let index = -1;
- let room;
for (let i = 0; i < rooms.length; i++) {
- room = rooms[i];
+ const room = rooms[i];
if (Util.tileListContainsPosition(room.tiles, position)) {
index = i;
break;
@@ -285,8 +282,8 @@ export class Util {
* @returns {IBounds} The coordinates of the minimum, center, and maximum
*/
public static calculateRoomListBounds(rooms: IRoom[]): IBounds {
- let min = [Number.MAX_VALUE, Number.MAX_VALUE];
- let max = [-1, -1];
+ const min = [Number.MAX_VALUE, Number.MAX_VALUE];
+ const max = [-1, -1];
rooms.forEach((room: IRoom) => {
room.tiles.forEach((tile: ITile) => {
@@ -309,7 +306,7 @@ export class Util {
max[0]++;
max[1]++;
- let gridCenter = [min[0] + (max[0] - min[0]) / 2.0, min[1] + (max[1] - min[1]) / 2.0];
+ const gridCenter = [min[0] + (max[0] - min[0]) / 2.0, min[1] + (max[1] - min[1]) / 2.0];
return {
min: min,
@@ -329,7 +326,7 @@ export class Util {
}
public static calculateRoomNamePosition(room: IRoom): IRoomNamePos {
- let result: IRoomNamePos = {
+ const result: IRoomNamePos = {
topLeft: {x: 0, y: 0},
length: 0
};
@@ -348,14 +345,14 @@ export class Util {
}
// Find the left-most tile at the top and the length of its adjacent tiles to the right
- let topTilePositions: number[] = [];
+ const topTilePositions: number[] = [];
room.tiles.forEach((tile: ITile) => {
if (tile.position.y === topMin) {
topTilePositions.push(tile.position.x);
}
});
topTilePositions.sort();
- let leftMin = topTilePositions[0];
+ const leftMin = topTilePositions[0];
let length = 0;
while (length < topTilePositions.length && topTilePositions[length] - leftMin === length) {
@@ -428,7 +425,7 @@ export class Util {
* @returns {IDateTime} A DateTime object with the parsed date and time information as content
*/
public static parseDateTime(input: string): IDateTime {
- let output: IDateTime = {
+ const output: IDateTime = {
year: 0,
month: 0,
day: 0,
@@ -437,13 +434,13 @@ export class Util {
second: 0
};
- let dateAndTime = input.split("T");
- let dateComponents = dateAndTime[0].split("-");
+ const dateAndTime = input.split("T");
+ const dateComponents = dateAndTime[0].split("-");
output.year = parseInt(dateComponents[0], 10);
output.month = parseInt(dateComponents[1], 10);
output.day = parseInt(dateComponents[2], 10);
- let timeComponents = dateAndTime[1].split(":");
+ const timeComponents = dateAndTime[1].split(":");
output.hour = parseInt(timeComponents[0], 10);
output.minute = parseInt(timeComponents[1], 10);
output.second = parseInt(timeComponents[2], 10);
@@ -453,7 +450,7 @@ export class Util {
public static formatDateTime(input: IDateTime) {
let date;
- let currentDate = new Date();
+ const currentDate = new Date();
date = Util.addPaddingToTwo(input.day) + "/" +
Util.addPaddingToTwo(input.month) + "/" +
@@ -474,10 +471,10 @@ export class Util {
}
public static getCurrentDateTime(): string {
- let date = new Date();
- return date.getFullYear() + "-" + Util.addPaddingToTwo(date.getMonth() + 1) + "-" +
- Util.addPaddingToTwo(date.getDate()) + "T" + Util.addPaddingToTwo(date.getHours()) + ":" +
- Util.addPaddingToTwo(date.getMinutes()) + ":" + Util.addPaddingToTwo(date.getSeconds());
+ const currentDate = new Date();
+ return currentDate.getFullYear() + "-" + Util.addPaddingToTwo(currentDate.getMonth() + 1) + "-" +
+ Util.addPaddingToTwo(currentDate.getDate()) + "T" + Util.addPaddingToTwo(currentDate.getHours()) + ":" +
+ Util.addPaddingToTwo(currentDate.getMinutes()) + ":" + Util.addPaddingToTwo(currentDate.getSeconds());
}
/**
@@ -493,7 +490,7 @@ export class Util {
* @returns {any} A copy of the object without any populated properties (of type object).
*/
public static packageForSending(object: any) {
- let result: any = {};
+ const result: any = {};
for (let prop in object) {
if (object.hasOwnProperty(prop)) {
if (typeof object[prop] !== "object") {
diff --git a/src/scripts/views/layers/dcobject.ts b/src/scripts/views/layers/dcobject.ts
index 6cec1f7e..f883a218 100644
--- a/src/scripts/views/layers/dcobject.ts
+++ b/src/scripts/views/layers/dcobject.ts
@@ -31,7 +31,7 @@ export class DCObjectLayer implements Layer {
public static drawHoverRack(position: IGridPosition): createjs.Container {
- let result = new createjs.Container();
+ const result = new createjs.Container();
DCObjectLayer.drawItemRectangle(
position, Colors.RACK_BACKGROUND, Colors.RACK_BORDER, result
@@ -47,7 +47,7 @@ export class DCObjectLayer implements Layer {
}
public static drawHoverPSU(position: IGridPosition): createjs.Container {
- let result = new createjs.Container();
+ const result = new createjs.Container();
DCObjectLayer.drawItemRectangle(
position, Colors.PSU_BACKGROUND, Colors.PSU_BORDER, result
@@ -57,7 +57,7 @@ export class DCObjectLayer implements Layer {
}
public static drawHoverCoolingItem(position: IGridPosition): createjs.Container {
- let result = new createjs.Container();
+ const result = new createjs.Container();
DCObjectLayer.drawItemRectangle(
position, Colors.COOLING_ITEM_BACKGROUND, Colors.COOLING_ITEM_BORDER, result
@@ -77,7 +77,7 @@ export class DCObjectLayer implements Layer {
*/
private static drawItemRectangle(position: IGridPosition, color: string, borderColor: string,
container: createjs.Container): createjs.Shape {
- let shape = new createjs.Shape();
+ const shape = new createjs.Shape();
shape.graphics.beginStroke(borderColor);
shape.graphics.setStrokeStyle(DCObjectLayer.STROKE_WIDTH);
shape.graphics.beginFill(color);
@@ -101,7 +101,7 @@ export class DCObjectLayer implements Layer {
*/
private static drawItemIcon(position: IGridPosition, container: createjs.Container,
originBitmap: createjs.Bitmap): createjs.Bitmap {
- let bitmap = originBitmap.clone();
+ const bitmap = originBitmap.clone();
container.addChild(bitmap);
bitmap.x = position.x * CELL_SIZE + DCObjectLayer.ITEM_MARGIN + DCObjectLayer.ITEM_PADDING * 1.5;
bitmap.y = position.y * CELL_SIZE + DCObjectLayer.ITEM_MARGIN + DCObjectLayer.ITEM_PADDING * 1.5;
@@ -157,7 +157,7 @@ export class DCObjectLayer implements Layer {
this.mapView.currentDatacenter.rooms.forEach((room: IRoom) => {
room.tiles.forEach((tile: ITile) => {
if (tile.object !== undefined) {
- let index = tile.position.y * MapView.MAP_SIZE + tile.position.x;
+ const index = tile.position.y * MapView.MAP_SIZE + tile.position.x;
switch (tile.objectType) {
case "RACK":
@@ -194,15 +194,13 @@ export class DCObjectLayer implements Layer {
}
public draw(): void {
- let currentObject;
-
this.container.removeAllChildren();
this.container.cursor = "pointer";
for (let property in this.dcObjectMap) {
if (this.dcObjectMap.hasOwnProperty(property)) {
- currentObject = this.dcObjectMap[property];
+ const currentObject = this.dcObjectMap[property];
switch (currentObject.type) {
case "RACK":
@@ -249,4 +247,4 @@ export class DCObjectLayer implements Layer {
this.mapView.updateScene = true;
}
-} \ No newline at end of file
+}
diff --git a/src/scripts/views/layers/dcprogressbar.ts b/src/scripts/views/layers/dcprogressbar.ts
index d0ec4397..e518ead4 100644
--- a/src/scripts/views/layers/dcprogressbar.ts
+++ b/src/scripts/views/layers/dcprogressbar.ts
@@ -30,7 +30,7 @@ export class DCProgressBar {
public static drawItemProgressRectangle(position: IGridPosition, color: string,
container: createjs.Container, distanceFromBottom: number,
fractionFilled: number): createjs.Shape {
- let shape = new createjs.Shape();
+ const shape = new createjs.Shape();
shape.graphics.beginFill(color);
let x = position.x * CELL_SIZE + DCObjectLayer.ITEM_MARGIN + DCObjectLayer.ITEM_PADDING;
let y = (position.y + 1) * CELL_SIZE - DCObjectLayer.ITEM_MARGIN - DCObjectLayer.ITEM_PADDING -
@@ -67,7 +67,7 @@ export class DCProgressBar {
*/
public static drawProgressbarIcon(position: IGridPosition, container: createjs.Container, originBitmap: createjs.Bitmap,
distanceFromBottom: number): createjs.Bitmap {
- let bitmap = originBitmap.clone();
+ const bitmap = originBitmap.clone();
container.addChild(bitmap);
bitmap.x = (position.x + 0.5) * CELL_SIZE - DCProgressBar.PROGRESS_BAR_WIDTH * 0.5;
bitmap.y = (position.y + 1) * CELL_SIZE - DCObjectLayer.ITEM_MARGIN - DCObjectLayer.ITEM_PADDING -
@@ -96,4 +96,4 @@ export class DCProgressBar {
DCProgressBar.drawProgressbarIcon(this.position, this.container, this.bitmap, this.distanceFromBottom);
}
-} \ No newline at end of file
+}
diff --git a/src/scripts/views/layers/gray.ts b/src/scripts/views/layers/gray.ts
index ed3c9429..63911d19 100644
--- a/src/scripts/views/layers/gray.ts
+++ b/src/scripts/views/layers/gray.ts
@@ -33,9 +33,9 @@ export class GrayLayer implements Layer {
this.container.removeAllChildren();
- let roomBounds = Util.calculateRoomBounds(this.currentRoom);
+ const roomBounds = Util.calculateRoomBounds(this.currentRoom);
- let shape = new createjs.Shape();
+ const shape = new createjs.Shape();
shape.graphics.beginFill(Colors.GRAYED_OUT_AREA);
shape.cursor = "pointer";
@@ -142,4 +142,4 @@ export class GrayLayer implements Layer {
public isGrayedOut(): boolean {
return this.currentRoom !== undefined;
}
-} \ No newline at end of file
+}
diff --git a/src/scripts/views/layers/room.ts b/src/scripts/views/layers/room.ts
index 0e31fee0..c1989206 100644
--- a/src/scripts/views/layers/room.ts
+++ b/src/scripts/views/layers/room.ts
@@ -65,7 +65,7 @@ export class RoomLayer implements Layer {
public addSelectedTile(tile: ITile): void {
this.selectedTiles.push(tile);
- let tileObject = MapView.drawRectangle(tile.position, Colors.ROOM_SELECTED, this.container);
+ const tileObject = MapView.drawRectangle(tile.position, Colors.ROOM_SELECTED, this.container);
this.selectedTileObjects.push({
position: {x: tile.position.x, y: tile.position.y},
tileObject: tileObject
@@ -84,7 +84,7 @@ export class RoomLayer implements Layer {
* @param objectIndex The index of the tile in the selectedTileObjects array
*/
public removeSelectedTile(position: IGridPosition, objectIndex: number): void {
- let index = Util.tileListPositionIndexOf(this.selectedTiles, position);
+ const index = Util.tileListPositionIndexOf(this.selectedTiles, position);
// Check whether the given position doesn't belong to an already removed tile
if (index === -1) {
@@ -174,4 +174,4 @@ export class RoomLayer implements Layer {
tileObj.tileObject.cursor = value ? "pointer" : "default";
});
}
-} \ No newline at end of file
+}
diff --git a/src/scripts/views/layers/roomtext.ts b/src/scripts/views/layers/roomtext.ts
index 65ea0735..63fab0ed 100644
--- a/src/scripts/views/layers/roomtext.ts
+++ b/src/scripts/views/layers/roomtext.ts
@@ -42,15 +42,15 @@ export class RoomTextLayer implements Layer {
return;
}
- let textPos = Util.calculateRoomNamePosition(room);
+ const textPos = Util.calculateRoomNamePosition(room);
- let bottomY = this.renderText(room.name, "12px Arial", textPos,
+ const bottomY = this.renderText(room.name, "12px Arial", textPos,
textPos.topLeft.y * CELL_SIZE + RoomTextLayer.TEXT_PADDING);
this.renderText("Type: " + Util.toSentenceCase(room.roomType), "10px Arial", textPos, bottomY + 5);
}
private renderText(text: string, font: string, textPos: IRoomNamePos, startY: number): number {
- let name = new createjs.Text(text, font, Colors.ROOM_NAME_COLOR);
+ const name = new createjs.Text(text, font, Colors.ROOM_NAME_COLOR);
if (name.getMeasuredWidth() > textPos.length * CELL_SIZE - RoomTextLayer.TEXT_PADDING * 2) {
name.scaleX = name.scaleY = (textPos.length * CELL_SIZE - RoomTextLayer.TEXT_PADDING * 2) /
diff --git a/src/scripts/views/mapview.ts b/src/scripts/views/mapview.ts
index ae7fd5cb..50fc2e45 100644
--- a/src/scripts/views/mapview.ts
+++ b/src/scripts/views/mapview.ts
@@ -70,7 +70,7 @@ export class MapView {
*/
public static drawLine(x1: number, y1: number, x2: number, y2: number,
lineWidth: number, color: string, container: createjs.Container): createjs.Shape {
- let line = new createjs.Shape();
+ const line = new createjs.Shape();
line.graphics.setStrokeStyle(lineWidth).beginStroke(color);
line.graphics.moveTo(x1, y1);
line.graphics.lineTo(x2, y2);
@@ -89,7 +89,7 @@ export class MapView {
*/
public static drawRectangle(position: IGridPosition, color: string, container: createjs.Container,
sizeX?: number, sizeY?: number): createjs.Shape {
- let tile = new createjs.Shape();
+ const tile = new createjs.Shape();
tile.graphics.setStrokeStyle(0);
tile.graphics.beginFill(color);
tile.graphics.drawRect(
@@ -125,14 +125,14 @@ export class MapView {
constructor(simulation: ISimulation, stage: createjs.Stage) {
this.simulation = simulation;
- let path = this.simulation.paths[this.simulation.paths.length - 1];
+ const path = this.simulation.paths[this.simulation.paths.length - 1];
this.currentDatacenter = path.sections[path.sections.length - 1].datacenter;
this.stage = stage;
console.log("THE DATA", simulation);
- let canvas = $("#main-canvas");
+ const canvas = $("#main-canvas");
this.canvasWidth = canvas.width();
this.canvasHeight = canvas.height();
@@ -207,22 +207,22 @@ export class MapView {
// Calculate position difference if zoomed, in order to later compensate for this
// unwanted movement
- let oldPosition = [
+ const oldPosition = [
position[0] - this.mapContainer.x, position[1] - this.mapContainer.y
];
- let newPosition = [
+ const newPosition = [
(oldPosition[0] / this.mapContainer.scaleX) * newZoom,
(oldPosition[1] / this.mapContainer.scaleX) * newZoom
];
- let positionDelta = [
+ const positionDelta = [
newPosition[0] - oldPosition[0], newPosition[1] - oldPosition[1]
];
// Apply the transformation operation to keep the selected position static
- let newX = this.mapContainer.x - positionDelta[0];
- let newY = this.mapContainer.y - positionDelta[1];
+ const newX = this.mapContainer.x - positionDelta[0];
+ const newY = this.mapContainer.y - positionDelta[1];
- let finalPos = this.mapController.checkCanvasMovement(newX, newY, newZoom);
+ const finalPos = this.mapController.checkCanvasMovement(newX, newY, newZoom);
if (!this.animating) {
this.animate(this.mapContainer, {
@@ -270,24 +270,24 @@ export class MapView {
* @param rooms The array of rooms to be viewed
*/
private zoomInOnRooms(rooms: IRoom[]): void {
- let bounds = Util.calculateRoomListBounds(rooms);
- let newScale = this.calculateNewScale(bounds);
+ const bounds = Util.calculateRoomListBounds(rooms);
+ const newScale = this.calculateNewScale(bounds);
// Coordinates of the center of the room, relative to the global origin of the map
- let roomCenterCoords = [
+ const roomCenterCoords = [
bounds.center[0] * CELL_SIZE * newScale,
bounds.center[1] * CELL_SIZE * newScale
];
// Coordinates of the center of the stage (the visible part of the canvas), relative to the global map origin
- let stageCenterCoords = [
+ const stageCenterCoords = [
-this.mapContainer.x + this.canvasWidth / 2,
-this.mapContainer.y + this.canvasHeight / 2
];
- let newX = this.mapContainer.x - roomCenterCoords[0] + stageCenterCoords[0];
- let newY = this.mapContainer.y - roomCenterCoords[1] + stageCenterCoords[1];
+ const newX = this.mapContainer.x - roomCenterCoords[0] + stageCenterCoords[0];
+ const newY = this.mapContainer.y - roomCenterCoords[1] + stageCenterCoords[1];
- let newPosition = this.mapController.checkCanvasMovement(newX, newY, newScale);
+ const newPosition = this.mapController.checkCanvasMovement(newX, newY, newScale);
this.animate(this.mapContainer, {
scaleX: newScale, scaleY: newScale,
@@ -299,11 +299,11 @@ export class MapView {
const viewPadding = 30;
const sideMenuWidth = 350;
- let width = bounds.max[0] - bounds.min[0];
- let height = bounds.max[1] - bounds.min[1];
+ const width = bounds.max[0] - bounds.min[0];
+ const height = bounds.max[1] - bounds.min[1];
- let scaleX = (this.canvasWidth - 2 * sideMenuWidth) / (width * CELL_SIZE + 2 * viewPadding);
- let scaleY = this.canvasHeight / (height * CELL_SIZE + 2 * viewPadding);
+ const scaleX = (this.canvasWidth - 2 * sideMenuWidth) / (width * CELL_SIZE + 2 * viewPadding);
+ const scaleY = this.canvasHeight / (height * CELL_SIZE + 2 * viewPadding);
let newScale = Math.min(scaleX, scaleY);
@@ -321,10 +321,10 @@ export class MapView {
*/
private drawMap(): void {
// Create and draw the container for the entire map
- let gridPixelSize = CELL_SIZE * MapView.MAP_SIZE;
+ const gridPixelSize = CELL_SIZE * MapView.MAP_SIZE;
// Add a white background to the entire container
- let background = new createjs.Shape();
+ const background = new createjs.Shape();
background.graphics.beginFill("#fff");
background.graphics.drawRect(0, 0,
gridPixelSize, gridPixelSize);
@@ -370,4 +370,4 @@ export class MapView {
}
});
}
-} \ No newline at end of file
+}