From 4031d439708b38d4e431242f3fbf5d18bbcbfa16 Mon Sep 17 00:00:00 2001 From: emkael Date: Mon, 29 Jan 2018 23:23:32 +0100 Subject: Anchors and anchored links to specified tables --- tdd-bootstrap.php | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'tdd-bootstrap.php') diff --git a/tdd-bootstrap.php b/tdd-bootstrap.php index f85a786..2af5ac1 100644 --- a/tdd-bootstrap.php +++ b/tdd-bootstrap.php @@ -13,11 +13,11 @@ class Protocol { throw new Exception('file not found: ' . $this->get_filename()); } } - + function get_filename() { return $this->prefix . $this->round . 'b-' . $this->board . '.html'; } - + function set_deal($table, $deal) { $this->deals_by_tables[$table] = $deal; } @@ -43,10 +43,10 @@ class Protocol { // if is played on both tables of a match // note that the contract field for arbitral scores starts with 'A' (e.g. 'ARB' or 'AAA') - if(($score1 !== '' || strpos($contract1, 'A') === 0) + if(($score1 !== '' || strpos($contract1, 'A') === 0) && ($score2 !== '' || strpos($contract2, 'A') === 0)) { $deal = $this->deals_by_tables[$table]; - $insert = "

Stół $table – Rozdanie {$deal->deal_num}

" . $deal->html(); + $insert = "

Stół $table – Rozdanie {$deal->deal_num}

" . $deal->html(); $modified = 1; } else { $insert = '

...

'; @@ -56,17 +56,17 @@ class Protocol { } $tr = @$tr->next_sibling(); } - + if($modified) { $header_tr2 = $header_tr->next_sibling(); $header_tr->outertext = ''; $header_tr2->outertext = ''; $dom->find('/html/body/table/tr', 0)->outertext = ''; } - + print $dom->outertext; } - + } class NoSuchDealNumber extends Exception { @@ -78,23 +78,23 @@ class Deal { $this->deal_num = $num_in_pbn; $this->_parse($filename, $num_in_pbn); } - + function _parse($filename, $num_in_pbn) { $pbn = file_get_contents($filename); $start = strpos($pbn, '[Board "' . $num_in_pbn . '"]'); if($start === false) { throw new NoSuchDealNumber($num_in_pbn); } - + $pbn = substr($pbn, $start + 5); $stop = strpos($pbn,'[Board "'); if($stop != false) { $pbn = substr($pbn, 0, $stop); } - + preg_match('|Dealer "([NESW])"|', $pbn, $m); $this->dealer = $m[1]; - + preg_match('|Vulnerable "([^"]+)"|', $pbn, $m); $this->vuln = $m[1]; if($this->vuln == 'None') { @@ -102,25 +102,25 @@ class Deal { } else if($this->vuln == 'All') { $this->vuln = 'Obie'; } - + preg_match('|Ability "([^"]+)"|', $pbn, $m); if($m[1]) { $this->ability = explode(' ',$m[1]); } - + preg_match('|Minimax "([^"]+)"|', $pbn, $m); $this->minimax = $m[1]; - + preg_match('|Deal "(N:)?([^"]+)"|', $pbn, $m); $this->hands = explode(' ',$m[2]); } - + function html() { ob_start(); include('tdd-handrecord-tpl.php'); return ob_get_clean(); } - + function format_hand($hand_num) { $hand = $this->hands[$hand_num]; $hand = str_replace('T','10',$hand); @@ -150,7 +150,7 @@ class Deal { {$ab[4]} {$ab[5]}"; } - + function format_minimax() { $minimax = $this->minimax; $minimax = preg_replace('|^(..)D(.+)|','$1x$2', $minimax); @@ -164,17 +164,17 @@ class Deal { function load_deals_for_tables($prefix, $round, $board_in_teamy) { $deals_by_tables = array(); - + $prefix = preg_quote($prefix); $filename_regex = "/$prefix-r$round-t(\d+)-b(\d+).pbn/"; foreach(scandir('.') as $filename) { if(preg_match($filename_regex, $filename, $match)) { $file_table = $match[1]; $file_start_board = $match[2]; - + // 1 in teamy -> 1 in pbn; 24 in teamy -> 1 in pbn; 25 in teamy -> 1 in pbn $num_in_pbn = $board_in_teamy - $file_start_board + 1; - + try { $deal = new Deal($filename, $num_in_pbn); $deals_by_tables[$file_table] = $deal; -- cgit v1.2.3 From b063e5df09c75d32f88d9c61590f0060037ff43b Mon Sep 17 00:00:00 2001 From: emkael Date: Mon, 29 Jan 2018 23:45:36 +0100 Subject: Adding some structure to the protocol table rows, prepending table header even if the layout is hidden --- tdd-bootstrap.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'tdd-bootstrap.php') diff --git a/tdd-bootstrap.php b/tdd-bootstrap.php index 2af5ac1..9d7998d 100644 --- a/tdd-bootstrap.php +++ b/tdd-bootstrap.php @@ -41,18 +41,19 @@ class Protocol { $contract2 = trim(str_replace(' ', '', $tr->next_sibling()->find('td[class="bdc"]', 0)->innertext)); $score2 = trim(str_replace(' ', '', end($tr->next_sibling()->find('td'))->innertext)); + $deal = $this->deals_by_tables[$table]; + $insert = "

Stół $table – Rozdanie {$deal->deal_num}

"; // if is played on both tables of a match // note that the contract field for arbitral scores starts with 'A' (e.g. 'ARB' or 'AAA') if(($score1 !== '' || strpos($contract1, 'A') === 0) && ($score2 !== '' || strpos($contract2, 'A') === 0)) { - $deal = $this->deals_by_tables[$table]; - $insert = "

Stół $table – Rozdanie {$deal->deal_num}

" . $deal->html(); + $insert .= $deal->html(); $modified = 1; } else { - $insert = '

...

'; + $insert .= '

...

'; } - $tr->outertext = '' . $insert . '' . $tr->outertext; + $tr->outertext = '' . $insert . '' . $tr->outertext; } $tr = @$tr->next_sibling(); } -- cgit v1.2.3 From 98f99725d698fe72090087442a72a5bd17c29fa8 Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 30 Jan 2018 02:32:14 +0100 Subject: Replacing refresh with JS refresh to preserve state (e.g. hash) of the refreshed frame --- tdd-bootstrap.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tdd-bootstrap.php') diff --git a/tdd-bootstrap.php b/tdd-bootstrap.php index 9d7998d..2ed216b 100644 --- a/tdd-bootstrap.php +++ b/tdd-bootstrap.php @@ -65,6 +65,15 @@ class Protocol { $dom->find('/html/body/table/tr', 0)->outertext = ''; } + // replacing meta http-equiv refresh with a javascript refresh to preserve hash in the result page + $meta = $head->find('meta'); + foreach ($meta as $metaTag) { + if ($metaTag->hasAttribute('http-equiv') && strtolower($metaTag->getAttribute('http-equiv')) == 'refresh') { + $head->innertext = str_replace($metaTag->outertext, '', $head->innertext) . ''; + break; + } + } + print $dom->outertext; } -- cgit v1.2.3 From 55ab3dc2fb6b59d9d07c5166f58b313321741490 Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 30 Jan 2018 02:35:34 +0100 Subject: Adding CSS that decreases tables opacity by default --- css/tdd.css | 7 +++++++ tdd-bootstrap.php | 3 +++ 2 files changed, 10 insertions(+) create mode 100644 css/tdd.css (limited to 'tdd-bootstrap.php') diff --git a/css/tdd.css b/css/tdd.css new file mode 100644 index 0000000..94ee73b --- /dev/null +++ b/css/tdd.css @@ -0,0 +1,7 @@ +body > table > tbody > tr { + opacity: 0.2 +} +body > table > tbody > tr.hovered, +body > table > tbody > tr.specified { + opacity: 1.0; +} diff --git a/tdd-bootstrap.php b/tdd-bootstrap.php index 2ed216b..342ecd0 100644 --- a/tdd-bootstrap.php +++ b/tdd-bootstrap.php @@ -65,6 +65,9 @@ class Protocol { $dom->find('/html/body/table/tr', 0)->outertext = ''; } + $head = $dom->find('/html/head', 0); + $head->innertext .= ''; + // replacing meta http-equiv refresh with a javascript refresh to preserve hash in the result page $meta = $head->find('meta'); foreach ($meta as $metaTag) { -- cgit v1.2.3 From 794a1fd682fa39d21a4fcc12c7065ca751acd576 Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 30 Jan 2018 02:37:09 +0100 Subject: Adding JavaScript to handle highlighting single table --- sklady/tdd.js | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ tdd-bootstrap.php | 4 ++- 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 sklady/tdd.js (limited to 'tdd-bootstrap.php') diff --git a/sklady/tdd.js b/sklady/tdd.js new file mode 100644 index 0000000..bc75356 --- /dev/null +++ b/sklady/tdd.js @@ -0,0 +1,74 @@ +var TDD = { + + rowSelector: 'body > table > tbody > tr', + rowHeaderClass: 'tdd-header', + + findTable: function(element) { + var row = element.closest(TDD.rowSelector); + var headerRow = row; + while (headerRow.length && !headerRow.hasClass(TDD.rowHeaderClass)) { + headerRow = headerRow.prev(TDD.rowSelector); + } + var rows = []; + if (headerRow) { + rows.push(headerRow[0]); + headerRow = headerRow.next(TDD.rowSelector); + while (headerRow.length && !headerRow.hasClass(TDD.rowHeaderClass)) { + rows.push(headerRow[0]); + headerRow = headerRow.next(TDD.rowSelector); + } + } + return $(rows); + }, + + highlightTable: function(elem) { + TDD.findTable(elem).addClass('specified'); + }, + + hoverTable: function(ev) { + TDD.findTable($(ev.currentTarget)).addClass('hovered'); + }, + + unhoverTable: function(ev) { + TDD.findTable($(ev.currentTarget)).removeClass('hovered'); + }, + + switchTable: function(ev) { + var header = TDD.findTable($(ev.currentTarget)).find('h4[id]'); + location.hash = header.attr('id'); + ev.stopPropagation(); + }, + + detectReferer: function() { + var regex = document.referrer.match(/\d+t(\d+)-\d+\.htm/); + if (regex) { + return regex[1]; + } + return undefined; + }, + + bindEvents: function() { + $('tr').hover(TDD.hoverTable, TDD.unhoverTable); + $('tr').click(TDD.switchTable); + $(window).on('hashchange', function() { + var table = $(location.hash); + if (table.length) { + $('.specified').removeClass('specified'); + TDD.highlightTable(table); + } else { + var tableNo = TDD.detectReferer(); + if (tableNo) { + location.hash = '#table-' + tableNo; + } else { + $('h4[id]').each(function() { TDD.highlightTable($(this)); }); + } + } + }); + } + +}; + +$(document).ready(function() { + TDD.bindEvents(); + $(window).trigger('hashchange'); +}); diff --git a/tdd-bootstrap.php b/tdd-bootstrap.php index 342ecd0..79320b6 100644 --- a/tdd-bootstrap.php +++ b/tdd-bootstrap.php @@ -66,7 +66,9 @@ class Protocol { } $head = $dom->find('/html/head', 0); - $head->innertext .= ''; + $head->innertext .= '' + . '' + . ''; // replacing meta http-equiv refresh with a javascript refresh to preserve hash in the result page $meta = $head->find('meta'); -- cgit v1.2.3 From 8f49020717fb7f33d3fd5d4264c1c419c1e65a5c Mon Sep 17 00:00:00 2001 From: Michal Zimniewicz Date: Sat, 3 Feb 2018 22:22:58 +0100 Subject: refactor deletion of http-equiv=refresh --- tdd-bootstrap.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tdd-bootstrap.php') diff --git a/tdd-bootstrap.php b/tdd-bootstrap.php index 79320b6..255e535 100644 --- a/tdd-bootstrap.php +++ b/tdd-bootstrap.php @@ -74,7 +74,8 @@ class Protocol { $meta = $head->find('meta'); foreach ($meta as $metaTag) { if ($metaTag->hasAttribute('http-equiv') && strtolower($metaTag->getAttribute('http-equiv')) == 'refresh') { - $head->innertext = str_replace($metaTag->outertext, '', $head->innertext) . ''; + $head->innertext .= ''; + $metaTag->outertext = ''; // delete $metaTag break; } } -- cgit v1.2.3 From 84dca9772cdefaf08bf46704bce3c1cc7768ebb0 Mon Sep 17 00:00:00 2001 From: Michal Zimniewicz Date: Sat, 3 Feb 2018 22:49:24 +0100 Subject: Revert "refactor deletion of http-equiv=refresh" This reverts commit 8f49020717fb7f33d3fd5d4264c1c419c1e65a5c. --- tdd-bootstrap.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tdd-bootstrap.php') diff --git a/tdd-bootstrap.php b/tdd-bootstrap.php index 255e535..79320b6 100644 --- a/tdd-bootstrap.php +++ b/tdd-bootstrap.php @@ -74,8 +74,7 @@ class Protocol { $meta = $head->find('meta'); foreach ($meta as $metaTag) { if ($metaTag->hasAttribute('http-equiv') && strtolower($metaTag->getAttribute('http-equiv')) == 'refresh') { - $head->innertext .= ''; - $metaTag->outertext = ''; // delete $metaTag + $head->innertext = str_replace($metaTag->outertext, '', $head->innertext) . ''; break; } } -- cgit v1.2.3 From 179574d7d2ee03d9d7cfa9f37ad62e96fcbd4656 Mon Sep 17 00:00:00 2001 From: Michal Zimniewicz Date: Sat, 3 Feb 2018 23:18:48 +0100 Subject: move inline style to .css --- css/tdd.css | 4 ++++ tdd-bootstrap.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'tdd-bootstrap.php') diff --git a/css/tdd.css b/css/tdd.css index 94ee73b..3ebce4f 100644 --- a/css/tdd.css +++ b/css/tdd.css @@ -1,3 +1,7 @@ +body > table > tbody > tr.tdd-header > td { + border-bottom: 1px solid #006; + padding-top: 30px; +} body > table > tbody > tr { opacity: 0.2 } diff --git a/tdd-bootstrap.php b/tdd-bootstrap.php index 79320b6..9f874a3 100644 --- a/tdd-bootstrap.php +++ b/tdd-bootstrap.php @@ -53,7 +53,7 @@ class Protocol { $insert .= '

...

'; } - $tr->outertext = '' . $insert . '' . $tr->outertext; + $tr->outertext = '' . $insert . '' . $tr->outertext; } $tr = @$tr->next_sibling(); } -- cgit v1.2.3 From 4e91dd3b096afbd8e05fa052001589308e29405b Mon Sep 17 00:00:00 2001 From: emkael Date: Sun, 4 Feb 2018 13:05:14 +0100 Subject: Passing through unchanged original HTML file if no deal files are found --- tdd-bootstrap.php | 12 ++++-------- tdd-protocol.php | 11 ++++++++--- 2 files changed, 12 insertions(+), 11 deletions(-) (limited to 'tdd-bootstrap.php') diff --git a/tdd-bootstrap.php b/tdd-bootstrap.php index 9f874a3..48b088f 100644 --- a/tdd-bootstrap.php +++ b/tdd-bootstrap.php @@ -24,7 +24,6 @@ class Protocol { function output() { $content = file_get_contents($this->get_filename()); - $modified = 0; $dom = str_get_html($content); $header_td1 = $dom->find("/html/body/table/tr/td[class=\"bdcc12\"]", 0); @@ -48,7 +47,6 @@ class Protocol { if(($score1 !== '' || strpos($contract1, 'A') === 0) && ($score2 !== '' || strpos($contract2, 'A') === 0)) { $insert .= $deal->html(); - $modified = 1; } else { $insert .= '

...

'; } @@ -58,12 +56,10 @@ class Protocol { $tr = @$tr->next_sibling(); } - if($modified) { - $header_tr2 = $header_tr->next_sibling(); - $header_tr->outertext = ''; - $header_tr2->outertext = ''; - $dom->find('/html/body/table/tr', 0)->outertext = ''; - } + $header_tr2 = $header_tr->next_sibling(); + $header_tr->outertext = ''; + $header_tr2->outertext = ''; + $dom->find('/html/body/table/tr', 0)->outertext = ''; $head = $dom->find('/html/head', 0); $head->innertext .= '' diff --git a/tdd-protocol.php b/tdd-protocol.php index 7f6eb7b..3dcc0d8 100644 --- a/tdd-protocol.php +++ b/tdd-protocol.php @@ -18,7 +18,12 @@ if($request_uri_ending != '/' . $html_filename) { // $deals_by_tables = load_deals_for_tables($prefix, $round, $board); -foreach($deals_by_tables as $table => $deal) { - $protocol->set_deal($table, $deal); +if (count($deals_by_tables) > 0) { + foreach($deals_by_tables as $table => $deal) { + $protocol->set_deal($table, $deal); + } + echo $protocol->output(); +} +else { + readfile($html_filename); } -echo $protocol->output(); -- cgit v1.2.3