From 8b0c163527d1500f3dc219f021d07e5a604b4d16 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 19 Feb 2015 18:06:09 +0100 Subject: MiniLinux download with version selection --- inc/property.inc.php | 2 +- lang/de/templates/minilinux/filelist.json | 2 ++ lang/en/templates/minilinux/filelist.json | 2 ++ modules/minilinux.inc.php | 48 ++++++++++++++++++++++++------- templates/minilinux/filelist.html | 17 ++++++++++- templates/page-minilinux.html | 23 +++++++-------- 6 files changed, 70 insertions(+), 24 deletions(-) diff --git a/inc/property.inc.php b/inc/property.inc.php index 7c3b7d37..d5a91872 100644 --- a/inc/property.inc.php +++ b/inc/property.inc.php @@ -99,7 +99,7 @@ class Property if (!isset($task['id'])) return 'Could not start list download (' . Message::asString() . ')'; if ($task['statusCode'] !== TASK_FINISHED) { - $task = Taskmanager::waitComplete($task['id']); + $task = Taskmanager::waitComplete($task['id'], 4000); } if ($task['statusCode'] !== TASK_FINISHED || !isset($task['data']['content'])) { return $task['data']['error']; diff --git a/lang/de/templates/minilinux/filelist.json b/lang/de/templates/minilinux/filelist.json index fa00b2ca..214d758a 100644 --- a/lang/de/templates/minilinux/filelist.json +++ b/lang/de/templates/minilinux/filelist.json @@ -3,6 +3,8 @@ "lang_canUpdate1": "Mindestens eine Komponente von", "lang_canUpdate2": "kann aktualisiert werden. F\u00fcr einen reibungslosen Betrieb wird empfohlen, alle Komponenten auf dem aktuellen Stand zu halten.", "lang_configurationPackageNotFound": "Keine Konfigurationspakete gefunden!", + "lang_desiredVersion": "Gew\u00fcnschte Version", + "lang_filesInVersion": "Dateien zu Version", "lang_outdated": "Veraltet", "lang_redownload": "Erneut herunterladen", "lang_systemUpdated": "Das System ist auf dem aktuellen Stand.", diff --git a/lang/en/templates/minilinux/filelist.json b/lang/en/templates/minilinux/filelist.json index 33b6686d..89fed42b 100644 --- a/lang/en/templates/minilinux/filelist.json +++ b/lang/en/templates/minilinux/filelist.json @@ -3,6 +3,8 @@ "lang_canUpdate1": "At least one component of", "lang_canUpdate2": "can be updated. For a smooth operation, it is recommended to keep all components up to date.", "lang_configurationPackageNotFound": "Configuration package not found!", + "lang_desiredVersion": "Desired version", + "lang_filesInVersion": "Files for version", "lang_outdated": "Outdated", "lang_redownload": "Download again", "lang_systemUpdated": "The system is up to date.", diff --git a/modules/minilinux.inc.php b/modules/minilinux.inc.php index c9d73b61..0853c0db 100644 --- a/modules/minilinux.inc.php +++ b/modules/minilinux.inc.php @@ -18,6 +18,9 @@ class Page_MiniLinux extends Page Render::addTemplate('page-minilinux', array( 'listurl' => '?do=MiniLinux&async=true&action=list' )); + Render::addFooter(''); } protected function doAjax() @@ -30,11 +33,31 @@ class Page_MiniLinux extends Page return; } $action = Request::any('action'); + $selectedVersion = (int)Request::any('version', 0); switch ($action) { case 'list': $count = 0; foreach ($data['systems'] as &$system) { - foreach ($system['files'] as &$file) { + // Get latest version, build simple array of all version numbers + $versionNumbers = array(); + $selected = false; + foreach ($system['versions'] as $version) { + if (!is_numeric($version['version']) || $version['version'] < 1) + continue; + if ($selectedVersion === 0 && ($selected === false || $selected['version'] < $version['version'])) + $selected = $version; + elseif ($version['version'] == $selectedVersion) + $selected = $version; + $versionNumbers[(int)$version['version']] = array( + 'version' => $version['version'] + ); + } + if ($selected === false) continue; // No versions for this system!? + ksort($versionNumbers); + // Mark latest version as selected + $versionNumbers[(int)$selected['version']]['selected'] = true; + // Add status information to system and its files + foreach ($selected['files'] as &$file) { $file['uid'] = 'dlid' . $count++; $local = CONFIG_HTTP_DIR . '/' . $system['id'] . '/' . $file['name']; if (!file_exists($local) || filesize($local) !== $file['size'] || filemtime($local) < $file['mtime']) { @@ -52,10 +75,12 @@ class Page_MiniLinux extends Page } } } + unset($system['versions']); + $system['files'] = $selected['files']; + $system['version'] = $selected['version']; } - echo Render::parse('minilinux/filelist', array( - 'systems' => $data['systems'] - )); + $data['versions'] = array_values($versionNumbers); + echo Render::parse('minilinux/filelist', $data); return; case 'download': $id = Request::post('id'); @@ -68,11 +93,14 @@ class Page_MiniLinux extends Page $gpg = 'missing'; foreach ($data['systems'] as &$system) { if ($system['id'] !== $id) continue; - foreach ($system['files'] as &$f) { - if ($f['name'] !== $name) continue; - $file = $f; - if (!empty($f['gpg'])) $gpg = $f['gpg']; - break; + foreach ($system['versions'] as &$version) { + if ($version['version'] != $selectedVersion) continue; + foreach ($version['files'] as &$f) { + if ($f['name'] !== $name) continue; + $file = $f; + if (!empty($f['gpg'])) $gpg = $f['gpg']; + break; + } } } if ($file === false) { @@ -80,7 +108,7 @@ class Page_MiniLinux extends Page return; } $task = Taskmanager::submit('DownloadFile', array( - 'url' => CONFIG_REMOTE_ML . '/' . $id . '/' . $name, + 'url' => CONFIG_REMOTE_ML . '/' . $id . '/' . $selectedVersion . '/' . $name, 'destination' => CONFIG_HTTP_DIR . '/' . $id . '/' . $name, 'gpg' => $gpg )); diff --git a/templates/minilinux/filelist.html b/templates/minilinux/filelist.html index 39ed0b43..ca94f4d0 100644 --- a/templates/minilinux/filelist.html +++ b/templates/minilinux/filelist.html @@ -4,6 +4,19 @@

{{title}}

+
+ {{lang_desiredVersion}} + +
{{#systemChanged}}

{{lang_canUpdate1}} {{title}} {{lang_canUpdate2}} @@ -13,6 +26,8 @@ {{^systemChanged}}

{{lang_systemUpdated}}

{{/systemChanged}} +
+

{{lang_filesInVersion}} {{version}}