From 3326e4adcafebe37c611131a1b70837e497fd89d Mon Sep 17 00:00:00 2001
From: "Steinar H. Gunderson"
Date: Mon, 30 Oct 2017 00:09:50 +0100
Subject: [PATCH] Add some code to display rosters.
---
client/mainwindow.cpp | 22 +++++++++
client/mainwindow.h | 2 +
client/mainwindow.ui | 33 ++++++++++---
roster.js | 106 ++++++++++++++++++++++++++++++++++++++++++
score.css | 19 ++++++++
score.html | 4 ++
6 files changed, 180 insertions(+), 6 deletions(-)
create mode 100644 roster.js
diff --git a/client/mainwindow.cpp b/client/mainwindow.cpp
index 9787ecb..baf103d 100644
--- a/client/mainwindow.cpp
+++ b/client/mainwindow.cpp
@@ -129,6 +129,9 @@ MainWindow::MainWindow(QWidget *parent) :
connect(ui->show_schedule_btn, &QPushButton::clicked, this, &MainWindow::show_schedule_clicked);
connect(ui->show_carousel_btn, &QPushButton::clicked, this, &MainWindow::show_carousel_clicked);
connect(ui->show_nothing_btn, &QPushButton::clicked, this, &MainWindow::show_nothing_clicked);
+ connect(ui->show_roster_1_btn, &QPushButton::clicked, this, [this]() { show_roster_clicked(ui->initials_1_edit->text().toStdString()); });
+ connect(ui->show_roster_2_btn, &QPushButton::clicked, this, [this]() { show_roster_clicked(ui->initials_2_edit->text().toStdString()); });
+ connect(ui->show_roster_carousel_btn, &QPushButton::clicked, this, &MainWindow::show_roster_carousel_clicked);
autocomment_update();
@@ -309,6 +312,15 @@ void MainWindow::show_group_clicked(const std::string &group_name)
acmp->send_command("cg 1 invoke 1 showgroup_from_state");
}
+void MainWindow::show_roster_clicked(const std::string &team_code)
+{
+ map param;
+ param["team_code"] = team_code;
+ acmp->send_command("cg 1 invoke 1 stopcarousel");
+ acmp->send_command("cg 1 update 1 \"" + escape_quotes(serialize_as_json(param)) + "\"");
+ acmp->send_command("cg 1 invoke 1 showroster_from_state");
+}
+
void MainWindow::show_schedule_clicked()
{
acmp->send_command("cg 1 invoke 1 stopcarousel");
@@ -321,6 +333,16 @@ void MainWindow::show_carousel_clicked()
acmp->send_command("cg 1 invoke 1 showcarousel");
}
+void MainWindow::show_roster_carousel_clicked()
+{
+ map param;
+ param["team1"] = escape_html(ui->initials_1_edit->text().toStdString());
+ param["team2"] = escape_html(ui->initials_2_edit->text().toStdString());
+ acmp->send_command("cg 1 invoke 1 stopcarousel");
+ acmp->send_command("cg 1 update 1 \"" + escape_quotes(serialize_as_json(param)) + "\"");
+ acmp->send_command("cg 1 invoke 1 showrostercarousel_from_state");
+}
+
void MainWindow::show_nothing_clicked()
{
acmp->send_command("cg 1 invoke 1 hidescorebug");
diff --git a/client/mainwindow.h b/client/mainwindow.h
index b9e9021..99b8a34 100644
--- a/client/mainwindow.h
+++ b/client/mainwindow.h
@@ -42,8 +42,10 @@ private:
void autocomment_update();
void show_scorebug_clicked();
void show_group_clicked(const std::string &group_name);
+ void show_roster_clicked(const std::string &team_code);
void show_schedule_clicked();
void show_carousel_clicked();
+ void show_roster_carousel_clicked();
void show_nothing_clicked();
Ui::MainWindow *ui;
diff --git a/client/mainwindow.ui b/client/mainwindow.ui
index 37d38bf..fe5886d 100644
--- a/client/mainwindow.ui
+++ b/client/mainwindow.ui
@@ -6,8 +6,8 @@
0
0
- 720
- 552
+ 803
+ 597
@@ -88,28 +88,49 @@
-
- Show scorebug
+ Show score
+
+
+
+ -
+
+
+ Roster 1
+
+
+
+ -
+
+
+ Roster 2
+
+
+
+ -
+
+
+ Roster 1+2
-
- Show group A
+ Group A
-
- Show group B
+ Group B
-
- Show schedule
+ Schedule
diff --git a/roster.js b/roster.js
new file mode 100644
index 0000000..b9230fd
--- /dev/null
+++ b/roster.js
@@ -0,0 +1,106 @@
+function load_roster(sheet, cb)
+{
+ var req = new XMLHttpRequest();
+ req.onload = function(e) {
+ var response = JSON.parse(req.responseText);
+
+ var team_name = '';
+ if (response.values[0].length >= 1 &&
+ response.values[0][0] !== undefined &&
+ response.values[0][0] !== null) {
+ team_name = response.values[0][0];
+ }
+
+ var roster = [];
+ var i;
+ for (i = 0; i < response.values.length; ++i) {
+ if (response.values[i][0] === 'Number') {
+ ++i;
+ break;
+ }
+ }
+
+ for ( ; response.values[i] !== undefined && response.values[i].length >= 3; ++i) {
+ var display_number = response.values[i][1];
+ var name = response.values[i][2];
+ roster.push({
+ "number": display_number,
+ "name": name
+ });
+ }
+ cb(team_name, roster);
+ };
+ req.open('GET', 'https://sheets.googleapis.com/v4/spreadsheets/1RciMlauWxqM9LYKdsY6lPjJbIAcHJpCXTqyZSEHxH3U/values/\'' + sheet + '\'!A1:J50?key=AIzaSyAuP9yQn8g0bSay6r_RpGtpFeIbwprH1TU');
+ req.send();
+};
+
+function display_roster(team_name, roster)
+{
+ document.getElementById('entire-bug').style.display = 'none';
+
+ var carousel = document.getElementById('carousel');
+ clear_carousel(carousel);
+
+ if (team_name === '') {
+ addheading(carousel, 4, 'Team lineup');
+ } else {
+ addheading(carousel, 4, 'Team lineup
' + team_name);
+ }
+
+ for (var i = 0; i < roster.length; i += 2) {
+ var tr = document.createElement("tr");
+
+ addth(tr, "playernum", roster[i].number);
+ addtd(tr, "playername", roster[i].name);
+
+ if (i + 1 < roster.length) {
+ addth(tr, "playernum", roster[i + 1].number);
+ addtd(tr, "playername", roster[i + 1].name);
+ } else {
+ addth(tr, "playernum", "");
+ addtd(tr, "playername", "");
+ }
+ carousel.appendChild(tr);
+ }
+ fade_in_rows(carousel);
+
+ carousel.style.display = 'table';
+}
+
+function showroster(sheet)
+{
+ load_roster(sheet, display_roster);
+}
+
+function showroster_from_state()
+{
+ showroster(state['team_code']);
+}
+
+function showrostercarousel(sheet1, sheet2)
+{
+ var team_names = [null, null];
+ var rosters = [null, null];
+ var num_left = 2;
+
+ var cb = function(id, team_name, roster) {
+ team_names[id] = team_name;
+ rosters[id] = roster;
+ if (--num_left == 0) {
+ do_series([
+ [ 13000, function() { display_roster(team_names[0], rosters[0]); } ],
+ [ 2000, function() { hidetable(); } ],
+ [ 13000, function() { display_roster(team_names[1], rosters[1]); } ],
+ [ 2000, function() { hidetable(); } ]
+ ]);
+ }
+ };
+
+ load_roster(sheet1, function(team_name, roster) { cb(0, team_name, roster); });
+ load_roster(sheet2, function(team_name, roster) { cb(1, team_name, roster); });
+}
+
+function showrostercarousel_from_state()
+{
+ showrostercarousel(state['team1'], state['team2']);
+}
diff --git a/score.css b/score.css
index 01dcbd1..e2d5edc 100644
--- a/score.css
+++ b/score.css
@@ -323,6 +323,25 @@ body {
text-transform: none;
}
+/* roster */
+#carousel .playerpadding {
+ font-size: 25px;
+ background: rgba(0,0,0,0);
+}
+#carousel th.playernum, #carousel .playername {
+ font-size: 35px;
+}
+#carousel th.playernum {
+ text-align: center;
+ padding-right: 8px;
+ padding-left: 0px; margin-left: 0px;
+ width: 80px;
+}
+#carousel .playername {
+ text-transform: none;
+ width: auto;
+}
+
.nplayed, .gd, .pts {
text-align: center;
}
diff --git a/score.html b/score.html
index c6f385b..4d7921d 100644
--- a/score.html
+++ b/score.html
@@ -66,6 +66,9 @@
show scorebug
+ show roster 1
+ show roster 2
+ show roster 1+2
show group A
show group B
show schedule
@@ -77,5 +80,6 @@
+