From c9eaadf688e53edad40da568b74854b82b75b4a7 Mon Sep 17 00:00:00 2001 From: Anthony Correa Date: Thu, 17 Aug 2023 08:25:51 -0500 Subject: [PATCH] add opponents --- routes/index.js | 49 +++++++++++++++++++++++++++++++++++++++++++++ views/opponent.pug | 35 ++++++++++++++++++++++++++++++++ views/opponents.pug | 18 +++++++++++++++++ views/team.pug | 17 ++++++++++------ 4 files changed, 113 insertions(+), 6 deletions(-) create mode 100644 views/opponent.pug create mode 100644 views/opponents.pug diff --git a/routes/index.js b/routes/index.js index 0bb96e9..652e723 100644 --- a/routes/index.js +++ b/routes/index.js @@ -387,4 +387,53 @@ router.get("/:team_id/events", ensureLoggedIn, function (req, res, next) { }); }); +router.get("/:team_id/opponents", ensureLoggedIn, function (req, res, next) { + authTeamsnap(req.user); + team_id = req.params.team_id; + teamsnap.loadCollections(function (err) { + teamsnap.bulkLoad(team_id, ["team", "opponent"]).then((items) => { + res.set("Content-Type", "text/html"); + res.render("opponents", { + team: items.find((i) => i.type == "team" && i.id == team_id), + opponents: items.filter((i) => i.type == "opponent"), + team_id: team_id, + }); + }); + }); +}); + +router.get( + "/:team_id/opponent/:opponent_id", + ensureLoggedIn, + function (req, res, next) { + authTeamsnap(req.user); + team_id = req.params.team_id; + opponent_id = req.params.opponent_id; + teamsnap.loadCollections(function (err) { + teamsnap.enablePersistence(); + teamsnap + .bulkLoad(team_id, ["team", "opponent"]) + .then(() => { + teamsnap.loadTeamMedia(team_id); + }) + .then(() => { + items = teamsnap.getAllItems(); + res.set("Content-Type", "text/html"); + res.render("opponent", { + team: items.find((i) => i.type == "team" && i.id == team_id), + opponent: items.find( + (i) => i.type == "opponent" && i.id == opponent_id + ), + opponent_logo: items.find( + (i) => + i.type == "teamMedium" && + i.description == `team-logo-${opponent_id}.png` + ), + team_id: team_id, + }); + }); + }); + } +); + module.exports = router; diff --git a/views/opponent.pug b/views/opponent.pug new file mode 100644 index 0000000..a7b56b4 --- /dev/null +++ b/views/opponent.pug @@ -0,0 +1,35 @@ +html +head + meta(charset='utf-8') + meta(name='viewport' content='width=device-width, initial-scale=1') + title BenchCoach - Teams + link(rel='stylesheet' href='/css/bootstrap.min.css') + link(rel='stylesheet' href='/font/bootstrap-icons.min.css') + link(rel='stylesheet' href='/css/teamsnap-ui.css') + +body + .container + .Panel + .Panel-header + .Panel-title #{opponent.name} + .Panel-body + .Panel-row.Panel-row--withCells + .Panel-cell.Panel-cell--header Contact Name + .panel-cell #{opponent.contactsName} + .Panel-row.Panel-row--withCells + .Panel-cell.Panel-cell--header Contact Phone + .panel-cell #{opponent.contactsPhone} + .Panel-row.Panel-row--withCells + .Panel-cell.Panel-cell--header Contact Email + .panel-cell #{opponent.contactsEmail} + .Panel-row.Panel-row--withCells + .Panel-cell.Panel-cell--header Logo + .panel-cell + if opponent_logo + img(src=`${opponent_logo.mediumUrl}` width="64" height="64") + else + button.Button Upload + .Panel-row.Panel-row--withCells + .Panel-cell.Panel-cell--header Notes + .panel-cell #{opponent.Notes} + diff --git a/views/opponents.pug b/views/opponents.pug new file mode 100644 index 0000000..1a43136 --- /dev/null +++ b/views/opponents.pug @@ -0,0 +1,18 @@ +html +head + meta(charset='utf-8') + meta(name='viewport' content='width=device-width, initial-scale=1') + title BenchCoach - Teams + link(rel='stylesheet' href='/css/bootstrap.min.css') + link(rel='stylesheet' href='/font/bootstrap-icons.min.css') + link(rel='stylesheet' href='/css/teamsnap-ui.css') + +body + .container + .Panel + .Panel-header + .Panel-title Opponents + .Panel-body + each opponent in opponents + .Panel-row + a(class='opponent' href=`/${team.id}/opponent/${opponent.id}`) #{opponent.name} diff --git a/views/team.pug b/views/team.pug index d8ed89c..7d4d4a3 100644 --- a/views/team.pug +++ b/views/team.pug @@ -9,9 +9,14 @@ html body .container - h2 #{team.name} - p #{team.seasonName} - hr - ul.list-group - a(class="list-group-item" href=`${team.id}/events`) Events - a(class="list-group-item" href=`${team.id}/roster`) Roster \ No newline at end of file + .Panel + .Panel-header + h2.Panel-title #{team.name} + p #{team.seasonName} + .Panel-body + .Panel-row + a(class="list-group-item" href=`${team.id}/events`) Events + .Panel-row + a(class="list-group-item" href=`${team.id}/roster`) Roster + .Panel-row + a(class="list-group-item" href=`${team.id}/opponents`) Opponents \ No newline at end of file