Skip to content

Commit

Permalink
Various bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
roncli committed Jun 18, 2019
1 parent 9ac097c commit 9531c2c
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 18 deletions.
12 changes: 8 additions & 4 deletions public/css/match.css
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@

#stats {
display: grid;
grid-template-columns: auto auto auto auto auto auto auto;
grid-template-columns: auto 18px auto auto auto auto auto;
color: white;
font-size: 14px;
margin-top: 5px;
Expand All @@ -181,6 +181,10 @@
font-size: 14px;
}

#stats .header.name {
grid-column-end: span 2;
}

#stats .diamond, #details .diamond {
display: inline-block;
width: 8px;
Expand Down Expand Up @@ -222,7 +226,7 @@
white-space: nowrap;
}

.twitch-image {
#stats .twitch-image {
display: inline-block;
background-image: url(/images/twitch.png);
background-size: 14px 14px;
Expand All @@ -236,16 +240,16 @@
color: white;
font-size: 14px;
margin-top: 5px;
max-width: 500px;
width: 100%;
}

#details > div:nth-child(odd) {
text-align: right;
padding-left: 5px;
padding-right: 3px;
}

#details > div:nth-child(even) {
text-align: left;
padding-left: 3px;
padding-right: 5px;
}
1 change: 1 addition & 0 deletions public/css/matches.css
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@

#matches #completed .paginator {
display: flex;
flex-wrap: wrap;
border-collapse: collapse;
color: white;
padding: 0 10px;
Expand Down
23 changes: 22 additions & 1 deletion public/js/matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@
* A class that handles the matches page.
*/
class Matches {
// ### #
// #
// ### ### ### ### ## # ## # # ##
// # # # # # # ## # ## # # #### # ##
// # # # ## # ## ## # # # # ##
// ### # # # ### ## # ### # # ##
// #
/**
* Parses time elements to display the local time.
* @returns {void}
*/
static parseTime() {
for (const time of document.getElementsByClassName("local")) {
time.innerText = MatchView.Common.formatDate(new Date(time.dateTime));
}
}

// ### ## # # ## # # # # #
// # # # # #### # # # # # # #
// # # # # #### # ## ### ### ## ### ### # ## ### ### ## ###
Expand Down Expand Up @@ -38,7 +55,9 @@ class Matches {

Matches.page = +paginator.innerText;

Common.loadDataIntoTemplate(`/api/match?season=${document.getElementById("season").innerText}&page=${Matches.page}`, "#completed-matches", MatchView.get);
Common.loadDataIntoTemplate(`/api/match?season=${document.getElementById("season").innerText}&page=${Matches.page}`, "#completed-matches", MatchView.get).then(() => {
Matches.parseTime();
});
});

paginator.addEventListener("selectstart", (ev) => {
Expand Down Expand Up @@ -69,6 +88,8 @@ class Matches {
document.getElementById("select-next").addEventListener("selectstart", (ev) => {
ev.preventDefault();
});

Matches.parseTime();
}
}

Expand Down
38 changes: 38 additions & 0 deletions public/views/405.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// # # # # # # # # # ## ## # # # #
// # # # # # # # # # # # # # # #
// ## ## ### #### # ## ### ## # ## # ### #### # # # # ### # # ### ## # # # ## ### # #
// # # # # # # ## # # # # ## # # # # # # # # # # # # # # # # # ## # # # # # # #
// # # ##### # # # # # # # # ## # # # ##### # # # # # # # ##### # # # # # ##### # # #
// # # # # # # # # # # ## # # # # # # # # # # # # # # # # # ## # # # # # # #
// # # ### ## # # ### ## # # # ### ## # # ### ### ### # # ### ## # # ### ### # #
/**
* A class that represents the 404 view.
*/
class MethodNotAllowedView {
// #
// #
// ### ## ###
// # # # ## #
// ## ## #
// # ## ##
// ###
/**
* Gets the rendered not found template.
* @param {{message: string}} data The data for the not found view.
* @returns {string} An HTML string of the not found view.
*/
static get(data) {
const {message} = data;

return /* html */`
<div id="error">
<div class="section">405 - Cloaking device activated.</div>
<div class="text">${message}</div>
</div>
`;
}
}

if (typeof module !== "undefined") {
module.exports = MethodNotAllowedView; // eslint-disable-line no-undef
}
4 changes: 2 additions & 2 deletions public/views/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class MatchView {
${details.stats && details.stats.length > 0 ? /* html */`
<div id="stats">
<div class="header">Team</div>
<div class="header">Name</div>
<div class="header name">Name</div>
<div class="header">KDA</div>
<div class="header">Kills</div>
<div class="header">Assists</div>
Expand All @@ -92,10 +92,10 @@ class MatchView {
<div class="tag">${(team = challenge.challengingTeam.id === s.teamId ? challenge.challengingTeam : challenge.challengedTeam) === null ? "" : /* html */`
<div class="diamond${team.role && team.role.hexColor ? "" : "-empty"}" ${team.role && team.role.hexColor ? `style="background-color: ${team.role.hexColor};"` : ""}></div> <a href="/team/${team.tag}">${team.tag}</a>
`}</div>
<div class="name"><a href="/player/${s.playerId}/${encodeURIComponent(s.name)}">${MatchView.Common.htmlEncode(s.name)}</a></div>
<div class="twitch">${s.twitchName ? /* html */`
<a href="https://twitch.tv/${encodeURIComponent(s.twitchName)}"><div class="twitch-image"></div></a>
` : ""}</div>
<div class="name"><a href="/player/${s.playerId}/${encodeURIComponent(s.name)}">${MatchView.Common.htmlEncode(s.name)}</a></div>
<div class="numeric kda">${((s.kills + s.assists) / Math.max(s.deaths, 1)).toFixed(3)}</div>
<div class="numeric kills">${s.kills}</div>
<div class="numeric assists">${s.assists}</div>
Expand Down
2 changes: 1 addition & 1 deletion public/views/matches/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class MatchView {
${match.map}${match.overtimePeriods > 0 ? `, ${match.overtimePeriods > 1 ? match.overtimePeriods : ""}OT` : ""}
</div>
<div class="date">
<a href="/match/${match.challengeId}/${match.challengingTeam.tag}/${match.challengedTeam.tag}"><script>document.write(MatchView.Common.formatDate(new Date("${match.matchTime}")));</script></a>
<a href="/match/${match.challengeId}/${match.challengingTeam.tag}/${match.challengedTeam.tag}"><time class="local" datetime="${match.matchTime}"></time></a>
</div>
${match.vod ? /* html */`
<div class="vod">
Expand Down
12 changes: 10 additions & 2 deletions src/cache.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const Redis = require("./redis");
const Redis = require("./redis"),

dateMatch = /^(?:\d{4})-(?:\d{2})-(?:\d{2})T(?:\d{2}):(?:\d{2}):(?:\d{2}(?:\.\d*))(?:Z|(?:\+|-)(?:[\d|:]*))?$/;

// ### #
// # # #
Expand Down Expand Up @@ -63,7 +65,13 @@ class Cache {
return void 0;
}

return JSON.parse(value);
return JSON.parse(value, (k, v) => {
if (typeof v === "string" && dateMatch.test(v)) {
return new Date(v);
}

return v;
});
}

// # ## # # #
Expand Down
2 changes: 1 addition & 1 deletion src/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -3644,7 +3644,7 @@ class Commands {
throw new Warning("Caster is not set.");
}

if (challenge.details.caster.id === member.id) {
if (challenge.details.caster.id !== member.id) {
await Discord.queue(`Sorry, ${member}, but ${challenge.details.caster} cast this match already.`, channel);
throw new Warning("Caster is already set.");
}
Expand Down
9 changes: 6 additions & 3 deletions src/database/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -826,19 +826,22 @@ class ChallengeDb {
const data = await db.query(/* sql */`
SELECT ChallengeId, DateClockDeadline
FROM tblChallenge
WHERE DateClockDeadlineNotified IS NULL
WHERE DateClockDeadline IS NOT NULL
AND DateClockDeadlineNotified IS NULL
AND DateClosed IS NULL
SELECT ChallengeId, MatchTime
FROM tblChallenge
WHERE DateMatchTimeNotified IS NULL
WHERE MatchTime IS NOT NULL
AND DateMatchTimeNotified IS NULL
AND DateConfirmed IS NULL
AND DateVoided IS NULL
AND DateClosed IS NULL
SELECT ChallengeId, MatchTime
FROM tblChallenge
WHERE DateMatchTimePassedNotified IS NULL
WHERE MatchTime IS NOT NULL
AND DateMatchTimePassedNotified IS NULL
AND DateConfirmed IS NULL
AND DateVoided IS NULL
AND DateClosed IS NULL
Expand Down
2 changes: 1 addition & 1 deletion src/discord.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const DiscordJs = require("discord.js"),

commands = new Commands(),
discord = new DiscordJs.Client(/** @type {DiscordJs.ClientOptions} */ (settings.discord.options)), // eslint-disable-line no-extra-parens
messageParse = /^!(?<command>[^ ]+)(?: +(?<args>.*[^ ]))? *$/;
messageParse = /^!(?<cmd>[^ ]+)(?: +(?<args>.*[^ ]))? *$/;

let readied = false;

Expand Down
2 changes: 1 addition & 1 deletion src/models/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class Match {
matchTime: match.matchTime,
map: match.map,
twitchName: match.twitchName,
timeRemaining: match.matchTime.getTime() - new Date().getTime()
timeRemaining: match.matchTime ? match.matchTime.getTime() - new Date().getTime() : void 0
};
}),
completed
Expand Down
4 changes: 2 additions & 2 deletions web/controllers/405.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Common = require("../includes/common"),
NotFoundView = require("../../public/views/404");
MethodNotAllowedView = require("../../public/views/405");

/**
* @typedef {import("express").Request} Express.Request
Expand Down Expand Up @@ -35,7 +35,7 @@ class MethodNotAllowed {
/* html */`
<link rel="stylesheet" href="/css/error.css" />
`,
NotFoundView.get({message: "This method not allowed."}),
MethodNotAllowedView.get({message: "This method not allowed."}),
req
));
}
Expand Down

0 comments on commit 9531c2c

Please sign in to comment.