Skip to content
Permalink
Browse files

Dashboard functionality.

  • Loading branch information...
roncli committed Jul 13, 2015
1 parent 625c969 commit 5c66957c40b6e2f13e86a957a2cbfe2368b99bad
@@ -4,6 +4,7 @@
var app = angular.module("ddsn", []),
data = {
serverTab: "news",
dashboardMenuTab: "current",
serverMenuTab: "scoreboard",
addServerMenuTab: "saved",
settingsMenuTab: "descent3",
@@ -147,6 +148,20 @@ var app = angular.module("ddsn", []),
};
});

app.directive("dashboardCurrent", function() {
return {
restrict: "E",
templateUrl: "/templates/dashboard-current.htm"
};
});

app.directive("dashboardPast", function() {
return {
restrict: "E",
templateUrl: "/templates/dashboard-past.htm"
};
});

app.directive("server", function() {
return {
restrict: "E",
@@ -290,6 +305,22 @@ var app = angular.module("ddsn", []),
}
};

$scope.getTeamArray = function(teams) {
var ret = [],
key;

for (key in teams) {
if (teams.hasOwnProperty(key)) {
ret.push({
teamName: key,
points: teams[key]
});
}
}

return ret;
};

$scope.getTimestamp = function(time) {
var seconds = time / 1000,
minutes, hours;
@@ -368,6 +399,10 @@ var app = angular.module("ddsn", []),
}
};

$scope.openDashboard = function(screen) {
data.dashboardMenuTab = screen;
};

$scope.openAddServer = function(screen) {
data.addServerMenuTab = screen;
};
@@ -524,7 +559,7 @@ var app = angular.module("ddsn", []),
console: [],
events: [],
players: [],
teams: {},
teams: [],
playerNames: {},
loading: true,
logs: []
@@ -578,6 +613,10 @@ var app = angular.module("ddsn", []),

getPlayerNum = function(server, player) {
return server.playerNames[player];
},

getTeamNum = function(server, team) {
return server.settings.game.setTeamName.indexOf(team);
};

switch (message.message) {
@@ -600,7 +639,7 @@ var app = angular.module("ddsn", []),
return;
}

if (data.currentServer.settings.server.port === message.port) {
if (data.currentServer && data.currentServer.settings.server.port === message.port) {
data.currentServer = null;
if (data.serverTab === "server") {
data.serverTab = "dashboard";
@@ -789,7 +828,7 @@ var app = angular.module("ddsn", []),
server.console = [];
server.events = [];
server.players = [];
server.teams = {};
server.teams = [];
server.playerNames = {};
server.logs.push(message.event.log);
break;
@@ -945,11 +984,22 @@ var app = angular.module("ddsn", []),
break;
case "server.teamscore":
getServer(message.port, function(server) {
var teamNum;

if (!server) {
return;
}

server.teams[message.teamName] = message.score;
teamNum = getTeamNum(server, message.teamName);

if (teamNum || teamNum === 0) {
if (!server.teams[teamNum]) {
server.teams[teamNum] = {
teamName: message.teamName
};
}
server.teams[teamNum].points = message.score;
}

scope.$apply();
});
@@ -0,0 +1,86 @@
<div class="row">
<div class="col-xs-4" ng-repeat-start="server in data.servers">
<div class="text-center">
<div class="btn btn-default" ng-click="openServer(server.settings.server.port)">{{server.settings.game.gameName}} <span class="glyphicon glyphicon-arrow-right"></span> {{server.settings.server.port}}</div>
</div>
<div ng-if="server.startTime" class="h3 text-center" style="margin-top: 0; margin-bottom: 0;"><chrono ng-if="server.endTime" direction="down" time="{{server.endTime}}"></chrono><chrono ng-if="!server.endTime" direction="up" time="{{server.startTime}}"></chrono></div>
<div ng-if="['anarchy', 'co-op', 'hoard', 'hyper-anarchy', 'robo-anarchy'].indexOf(server.settings.game.scriptName.toLowerCase()) !== -1">
<table class="table table-condensed">
<tr ng-class="'player' + player.playerNum.toString()" ng-repeat="player in server.players | filter: {role: 'client', connected: true} | orderBy: '-points'">
<td style="vertical-align: middle;">
<div style="width: 32px; height: 32px; background-image: url('/images/{{player.ship}}.png'); background-size: 32px 32px;"></div>
</td>
<td class="h3" style="vertical-align: middle;">
<span ng-if="player.observing" class="glyphicon glyphicon-eye-open text-info"></span> {{player.name}}<img style="width: 32px; height: 32px;" ng-if="player.hyperorb" src="/images/hyperorb.png" />
</td>
<td class="h3 text-right" style="vertical-align: middle;">
{{player.points}}
</td>
<td class="text-center" style="vertical-align: middle;">
{{player.kills}} / {{player.deaths}} / {{player.suicides}}
</td>
<td class="text-right" style="vertical-align: middle;">
{{player.ping ? player.ping.toString() + " ms" : ""}}
</td>
</tr>
<tr ng-repeat="player in server.players | filter: {role: 'client', connected: false} | orderBy: '-points'">
<td></td>
<td>
{{player.name}}
</td>
<td CLASS="text-right">
{{player.points}}
</td>
<td class="text-center">
{{player.kills}} / {{player.deaths}} / {{player.suicides}}
</td>
<td></td>
</tr>
</table>
</div>
<div ng-if="['ctf', 'entropy', 'monsterball', 'team anarchy'].indexOf(server.settings.game.scriptName.toLowerCase()) !== -1">
<table ng-if="server.teams.length > 0" class="table table-condensed">
<tr ng-class="'h3 player' + server.settings.game.setTeamName.indexOf(team.teamName)" ng-repeat="team in server.teams | orderBy: '-points'">
<td style="width: 50%; text-align: right">{{team.teamName}}</td>
<td style="width: 50%;">{{team.points}}</td>
</tr>
</table>
<table class="table table-condensed">
<tr ng-class="'player' + server.settings.game.setTeamName.indexOf(player.teamName)" ng-repeat="player in server.players | filter: {role: 'client', connected: true} | orderBy: '-points'">
<td style="vertical-align: middle;">
<div style="width: 32px; height: 32px; background-image: url('/images/{{player.ship}}.png'); background-size: 32px 32px;"></div>
</td>
<td class="h3" style="vertical-align: middle;">
<span ng-if="player.observing" class="glyphicon glyphicon-eye-open text-info"></span> {{player.name}} <img ng-repeat="flag in player.flags" ng-src="/images/flag{{server.settings.game.setTeamName.indexOf(flag)}}.png" style="max-width: 32px; max-height: 32px;" />
</td>
<td class="h3 text-right" style="vertical-align: middle;">
{{player.points}}
</td>
<td ng-if="server.settings.game.scriptName.toLowerCase() === 'monsterball'" class="h3 text-right" style="vertical-align: middle;">
{{-player.blunders}}
</td>
<td class="text-center" style="vertical-align: middle;">
{{player.kills}} / {{player.deaths}} / {{player.suicides}}
</td>
<td class="text-right" style="vertical-align: middle;">
{{player.ping ? player.ping.toString() + " ms" : ""}}
</td>
</tr>
<tr ng-repeat="player in server.players | filter: {role: 'client', connected: false} | orderBy: '-points'">
<td></td>
<td>
{{player.name}}
</td>
<td CLASS="text-right">
{{player.points}}
</td>
<td class="text-center">
{{player.kills}} / {{player.deaths}} / {{player.suicides}}
</td>
<td></td>
</tr>
</table>
</div>
</div>
<div ng-repeat-end ng-if="$index < data.servers.length && $index % 3 === 2" class="clearfix"></div>
</div>
No changes.
@@ -1,8 +1,10 @@
<ul class="nav nav-pills">
<li role="presentation">
<button class="btn btn-success"><span class="glyphicon glyphicon-play"></span> Current Games</button>
<button ng-class="{true: 'btn btn-success', false: 'btn btn-primary'}[data.dashboardMenuTab === 'current']" ng-click="openDashboard('current')"><span class="glyphicon glyphicon-play"></span> Current Games</button>
</li>
<li role="presentation">
<button class="btn btn-primary"><span class="glyphicon glyphicon-list-alt"></span> Past Games</button>
<button ng-class="{true: 'btn btn-success', false: 'btn btn-primary'}[data.dashboardMenuTab === 'past']" ng-click="openDashboard('past')"><span class="glyphicon glyphicon-list-alt"></span> Past Games</button>
</li>
</ul>
</ul><br/>
<dashboard-current ng-if="data.dashboardMenuTab === 'current'"></dashboard-current>
<dashboard-past ng-if="data.dashboardMenuTab === 'past'"></dashboard-past>
@@ -40,10 +40,10 @@
</table>
</div>
<div ng-if="['ctf', 'entropy', 'monsterball', 'team anarchy'].indexOf(data.currentServer.settings.game.scriptName.toLowerCase()) !== -1">
<table class="table table-condensed">
<tr ng-class="'h3 player' + data.currentServer.settings.game.setTeamName.indexOf(teamName)" ng-repeat="(teamName, points) in data.currentServer.teams | orderBy: '-points'">
<td style="width: 50%; text-align: right">{{teamName}}</td>
<td style="width: 50%;">{{points}}</td>
<table ng-if="data.currentServer.teams.length > 0" class="table table-condensed">
<tr ng-class="'h3 player' + data.currentServer.settings.game.setTeamName.indexOf(team.teamName)" ng-repeat="team in data.currentServer.teams | orderBy: '-points'">
<td style="width: 50%; text-align: right">{{team.teamName}}</td>
<td style="width: 50%;">{{team.points}}</td>
</tr>
</table>
<table class="table table-condensed">
@@ -70,7 +70,7 @@
{{player.ping ? player.ping.toString() + " ms" : ""}}
</td>
</tr>
<tr ng-class="'player' + data.currentServer.settings.game.setTeamName.indexOf(player.teamName)" ng-repeat="player in data.currentServer.players | filter: {role: 'client', connected: false} | orderBy: '-points'">
<tr ng-repeat="player in data.currentServer.players | filter: {role: 'client', connected: false} | orderBy: '-points'">
<td></td>
<td>
{{player.name}}
@@ -51,6 +51,12 @@ Server.prototype.connect = function() {
reason: "failed",
port: server.settings.server.port
});
if (server.console) {
server.console.removeAllListeners();
server.console.close();
}
server.emit("close");

return;
}

@@ -277,7 +277,7 @@ module.exports = function() {
console: [],
events: [],
players: [],
teams: {},
teams: [],
playerNames: {},
loading: true,
logs: []
@@ -296,6 +296,10 @@ module.exports = function() {
return serverData.playerNames[player];
},

getTeamNum = function(team) {
return serverData.settings.game.setTeamName.indexOf(team);
},

addEvent = function(event) {
event.time = getElapsedTime();
serverData.events.push(event);
@@ -333,10 +337,10 @@ module.exports = function() {
});

server.on("close", function() {
servers.data.splice(servers.data.indexOf(data), 1);
servers.data.splice(servers.data.indexOf(serverData), 1);
servers.servers.splice(servers.servers.indexOf(server), 1);
server = null;
data = null;
serverData = null;
});

server.on("gameinfo", function(info) {
@@ -650,7 +654,16 @@ module.exports = function() {
});

server.on("teamscore", function(teamName, score) {
serverData.teams[teamName] = score;
var teamNum = getTeamNum(teamName);

if (teamNum || teamNum === 0) {
if (!serverData.teams[teamNum]) {
serverData.teams[teamNum] = {
teamName: teamName
};
}
serverData.teams[teamNum].points = score;
}
});

server.on("teamplayerscore", function(player, teamName, points, kills, deaths, suicides, ping) {
@@ -751,7 +764,7 @@ module.exports = function() {
serverData.console = [];
serverData.events = [];
serverData.players = [];
serverData.teams = {};
serverData.teams = [];
serverData.playerNames = {};
serverData.logs.push({
date: date,

0 comments on commit 5c66957

Please sign in to comment.
You can’t perform that action at this time.