Skip to content

Commit 17d6948

Browse files
committed
Add getGridCellsContent method and the cells do get populated, but there are too many values being passed and the content is not formatted properly
1 parent 8400a05 commit 17d6948

File tree

2 files changed

+114
-12
lines changed

2 files changed

+114
-12
lines changed

src/components/Login.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<!-- Server status -->
55
<h4>Server Status</h4>
66
<div class="server-status">
7-
<ServerStatusGrid></ServerStatusGrid>
7+
<ServerStatusGrid :serverOptions="serverOptions"></ServerStatusGrid>
88
<!-- <table>
99
<tr>
1010
<th>Server</th>
@@ -30,7 +30,7 @@
3030
</td>
3131
<td>{{!server.gamesRunning ? '-' : `${server.gamesRunning} ${server.gamesRunning === 1 ? 'game' : 'games'}`}}</td>
3232
<td>{{!server.ais ? '-' : `${server.ais} ${server.ais === 1 ? 'AI' : 'AIs'}`}}</td>
33-
<td>{{! server.latency ? '-' : `${server.latency} ms`}}</td>
33+
<td>{{!server.latency ? '-' : `${server.latency} ms`}}</td>
3434
</tr>
3535
</table> -->
3636
<input @click="refreshServers()" :disabled="refreshing" type="button" value="Refresh" class="btn btn-navbar" style="margin-top: 10px;"/>

src/components/css_grid/ServerStatusGrid.vue

Lines changed: 112 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,128 @@
88
class="server-status-header"
99
v-for="(headerName, index) in headerNames"
1010
:key="index">
11-
<div>{{headerName}}</div>
11+
{{headerName}}
12+
</css-grid-item>
13+
14+
<css-grid-item
15+
class="server-status-cell"
16+
v-for="(content, index) in getGridCellsContent(serverOptions)"
17+
:key="index">
18+
{{content}}
1219
</css-grid-item>
1320

1421
</css-grid>
1522
</template>
23+
1624
<script>
25+
const headerNames = [
26+
"Server",
27+
"Online",
28+
"Users",
29+
"Mods",
30+
"Games",
31+
"AIs",
32+
"Latency"
33+
];
34+
1735
export default {
1836
name: "ServerStatusGrid",
37+
props: ["serverOptions"],
1938
data() {
2039
return {
21-
headerNames: [
22-
"Server",
23-
"Online",
24-
"Users",
25-
"Mods",
26-
"Games",
27-
"AIs",
28-
"Latency"
29-
]
40+
headerNames: headerNames
3041
}
3142
},
43+
methods: {
44+
getGridCellsContent: function(serverOptions) {
45+
console.log(serverOptions);
46+
const allServerValues = [];
47+
const serverValueIndexes = {
48+
name: 0,
49+
isOnline: 1,
50+
userCount: 2,
51+
availableMods: 3,
52+
gamesRunning: 4,
53+
ais: 5,
54+
latency: 6
55+
};
56+
for (let server in serverOptions) {
57+
const thisServerValues = [
58+
server.name,
59+
server.isOnline,
60+
server.userCount,
61+
server.availableMods,
62+
server.gamesRunning,
63+
server.ais,
64+
server.latency
65+
];
66+
for (let index = 0; index < thisServerValues.length; index++) {
67+
switch(index) {
68+
case serverValueIndexes.name:
69+
allServerValues.push(server[index]);
70+
break;
71+
case serverValueIndexes.isOnline:
72+
allServerValues.push(server[index] ? "true" : "false");
73+
case serverValueIndexes.userCount:
74+
let realUserCount = parseInt(server.userCount);
75+
realUserCount--;
76+
allServerValues.push(server[index]
77+
? '-'
78+
: `${realUserCount} ${realUserCount === 1 ? 'user' : 'users'}`
79+
);
80+
break;
81+
case serverValueIndexes.availableMods:
82+
allServerValues.push(
83+
`<ul class="server-mod-list">` +
84+
`<li>` +
85+
`<router-link :to="/cards?server=${server.address}&mod=${serverValueIndexes.availableMods}">` +
86+
`{{ key }}` +
87+
`</router-link>` +
88+
`</li>` +
89+
`</ul>`
90+
);
91+
break;
92+
case serverValueIndexes.gamesRunning:
93+
const gamesRunning = server.gamesRunning;
94+
allServerValues.push(!gamesRunning
95+
? '-'
96+
: `${gamesRunning} ${gamesRunning === 1 ? 'game' : 'games'}`
97+
);
98+
break;
99+
case serverValueIndexes.ais:
100+
const serverAis = server.ais;
101+
allServerValues.push(
102+
!serverAis
103+
? '-'
104+
: `${serverAis} ${serverAis === 1 ? 'AI' : 'AIs'}`
105+
);
106+
break;
107+
case serverValueIndexes.latency:
108+
allServerValues.push(
109+
!server.latency ? '-' : `${server.latency} ms`
110+
);
111+
break;
112+
default:
113+
allServerValues.push(null);
114+
break;
115+
}
116+
}
117+
}
118+
console.log(allServerValues);
119+
return allServerValues;
120+
}
121+
}
32122
}
33123
</script>
124+
125+
<style>
126+
.server-status-header {
127+
background-color: #eee;
128+
color: #000;
129+
padding: 5px;
130+
border: 1px solid #000;
131+
border-collapse: collapse;
132+
font-weight: bold;
133+
font-size: 1.2em;
134+
}
135+
</style>

0 commit comments

Comments
 (0)