mirror of
https://github.com/mbirth/tcl_update_db.git
synced 2024-12-26 04:24:07 +00:00
JSON provider for version details. Tooltips now show actual details.
This commit is contained in:
parent
29d65bed78
commit
4f648aa3e2
@ -34,8 +34,39 @@ document.addEventListener 'DOMContentLoaded', (event) ->
|
|||||||
ref = event.target.parentNode.dataset.ref
|
ref = event.target.parentNode.dataset.ref
|
||||||
ver = event.target.innerText
|
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 = "<strong>OTA possible to #{toList}</strong>"
|
||||||
|
else
|
||||||
|
updateInfo = "No further OTA update."
|
||||||
|
|
||||||
tt_title.innerHTML = ver
|
tt_title.innerHTML = ver
|
||||||
tt_text.innerHTML = "for #{ref}"
|
tt_text.innerHTML = """
|
||||||
|
for #{ref} - #{meta['variant']}<br/>
|
||||||
|
<br/>
|
||||||
|
FULL: #{fullInfo}<br/>
|
||||||
|
OTA: #{otaInfo}<br/>
|
||||||
|
<br/>
|
||||||
|
#{updateInfo}
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
# Show tooltip
|
# Show tooltip
|
||||||
@ -71,11 +102,27 @@ document.addEventListener 'DOMContentLoaded', (event) ->
|
|||||||
# show tooltip right of cursor
|
# show tooltip right of cursor
|
||||||
tooltip.style.left = (mouseX + cursorOffset) + 'px'
|
tooltip.style.left = (mouseX + cursorOffset) + 'px'
|
||||||
|
|
||||||
versionitems = document.querySelectorAll '.version'
|
# Load metadata
|
||||||
for vi in versionitems
|
metadata = {}
|
||||||
vi.addEventListener 'mousemove', (event) ->
|
xhr = new XMLHttpRequest()
|
||||||
positionTooltip event.clientX + window.scrollX, event.clientY + window.scrollY
|
xhr.open('GET', 'json_updatedetails.php', true);
|
||||||
vi.addEventListener 'mouseover', (event) ->
|
xhr.onreadystatechange = ->
|
||||||
showTooltip event
|
if xhr.readyState is 4 and xhr.status is 200
|
||||||
vi.addEventListener 'mouseout', (event) ->
|
window.metadata = JSON.parse xhr.responseText
|
||||||
document.querySelector('#tooltip').style.display = 'none'
|
|
||||||
|
# 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()
|
||||||
|
@ -99,6 +99,14 @@ foreach ($allVars as $family => $models) {
|
|||||||
Contents here.
|
Contents here.
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="mdc-snackbar" aria-live="assertive" aria-atomic="true" aria-hidden="true">
|
||||||
|
<div class="mdc-snackbar__text"></div>
|
||||||
|
<div class="mdc-snackbar__action-wrapper">
|
||||||
|
<button type="button" class="mdc-snackbar__action-button"></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
53
json_updatedetails.php
Normal file
53
json_updatedetails.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once __DIR__ . '/lib/autoloader.php';
|
||||||
|
|
||||||
|
use \TclUpdates\SQLiteReader;
|
||||||
|
|
||||||
|
$db = new SQLiteReader();
|
||||||
|
|
||||||
|
$refs = $db->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;
|
@ -168,4 +168,17 @@ class SQLiteReader
|
|||||||
sort($version);
|
sort($version);
|
||||||
return $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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user