diff --git a/assets/main.coffee b/assets/main.coffee index d2b9a5a..bf08c87 100644 --- a/assets/main.coffee +++ b/assets/main.coffee @@ -34,8 +34,39 @@ document.addEventListener 'DOMContentLoaded', (event) -> ref = event.target.parentNode.dataset.ref ver = event.target.innerText + meta = window.metadata[ref] + #console.log("Meta: %o", meta) + vermeta = meta['versions'][ver] + + if vermeta['FULL'].length > 0 + fullmeta = vermeta['FULL'][0] + fullInfo = "✔️ (first released: #{fullmeta['published_first']})" + else + fullInfo = "❌" + + if vermeta['OTA'].length > 0 + fromList = (v['fv'] for v in vermeta['OTA']) + fromList = fromList.join ', ' + otaInfo = "✔️ (from #{fromList})" + else + otaInfo = "❌" + + if vermeta['OTA_FROM'].length > 0 + toList = (v['tv'] for v in vermeta['OTA_FROM']) + toList = toList.join ', ' + updateInfo = "OTA possible to #{toList}" + else + updateInfo = "No further OTA update." + tt_title.innerHTML = ver - tt_text.innerHTML = "for #{ref}" + tt_text.innerHTML = """ + for #{ref} - #{meta['variant']}
+
+ FULL: #{fullInfo}
+ OTA: #{otaInfo}
+
+ #{updateInfo} + """ # Show tooltip @@ -71,11 +102,27 @@ document.addEventListener 'DOMContentLoaded', (event) -> # show tooltip right of cursor tooltip.style.left = (mouseX + cursorOffset) + 'px' - versionitems = document.querySelectorAll '.version' - for vi in versionitems - vi.addEventListener 'mousemove', (event) -> - positionTooltip event.clientX + window.scrollX, event.clientY + window.scrollY - vi.addEventListener 'mouseover', (event) -> - showTooltip event - vi.addEventListener 'mouseout', (event) -> - document.querySelector('#tooltip').style.display = 'none' + # Load metadata + metadata = {} + xhr = new XMLHttpRequest() + xhr.open('GET', 'json_updatedetails.php', true); + xhr.onreadystatechange = -> + if xhr.readyState is 4 and xhr.status is 200 + window.metadata = JSON.parse xhr.responseText + + # Add event listeners to all versions so tooltips start to work AFTER data was loaded + versionitems = document.querySelectorAll '.version' + for vi in versionitems + vi.addEventListener 'mousemove', (event) -> + positionTooltip event.clientX + window.scrollX, event.clientY + window.scrollY + vi.addEventListener 'mouseover', (event) -> + showTooltip event + vi.addEventListener 'mouseout', (event) -> + document.querySelector('#tooltip').style.display = 'none' + + snackbar = new mdc.snackbar.MDCSnackbar document.querySelector '.mdc-snackbar' + snackbar.show + message: 'Update details loaded. Hover a version number to see details.' + timeout: 5000 + + xhr.send() diff --git a/index_main.php b/index_main.php index f6718eb..c9dabe2 100644 --- a/index_main.php +++ b/index_main.php @@ -99,6 +99,14 @@ foreach ($allVars as $family => $models) { Contents here. + + + diff --git a/json_updatedetails.php b/json_updatedetails.php new file mode 100644 index 0000000..cf6470d --- /dev/null +++ b/json_updatedetails.php @@ -0,0 +1,53 @@ +getAllRefs(); +$vars = $db->getAllVariantsFlat(); + +$output = array(); +foreach ($refs as $ref) { + $updates = $db->getAllUpdates($ref); + + $versions = array(); + foreach ($updates as $update) { + $fv = $update['fv']; + $tv = $update['tv']; + $update['note'] = json_decode($update['note'], true); + $similar_refs = $db->getAllRefsForFile($update['file_sha1']); + $update['applies_to'] = $similar_refs; + if ($fv && !isset($versions[$fv])) { + $versions[$fv] = array('OTA_FROM' => array(), 'OTA' => array(), 'FULL' => array()); + } + if (!isset($versions[$tv])) { + $versions[$tv] = array('OTA_FROM' => array(), 'OTA' => array(), 'FULL' => array()); + } + if (!$update['fv']) { + $versions[$tv]['FULL'][] = $update; + } else { + $versions[$fv]['OTA_FROM'][] = $update; + $versions[$tv]['OTA'][] = $update; + } + } + + $output[$ref] = array( + 'curef' => $ref, + 'variant' => $vars[$ref], + 'versions' => $versions, + ); +} + +header('Content-Type: text/json'); + +$output = json_encode($output, JSON_PRETTY_PRINT); +if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false) { + ini_set('zlib.output_compression', 'Off'); + header('Content-Encoding: gzip'); + $output = gzencode($output); +} + +echo $output; diff --git a/lib/TclUpdates/SQLiteReader.php b/lib/TclUpdates/SQLiteReader.php index 92dfd42..abfa3ba 100644 --- a/lib/TclUpdates/SQLiteReader.php +++ b/lib/TclUpdates/SQLiteReader.php @@ -168,4 +168,17 @@ class SQLiteReader sort($version); return $version; } + + public function getAllRefsForFile($sha1) + { + $sql = 'SELECT curef FROM updates u WHERE u.file_sha1=?'; + $stmt = $this->pdo->prepare($sql); + $ok = $stmt->execute(array($sha1)); + $result = $stmt->fetchAll(\PDO::FETCH_ASSOC); + $refs = array(); + foreach ($result as $row) { + $refs[] = $row['curef']; + } + return $refs; + } }