From d4ebd680522362250dc0503bfc3ffccd79648d21 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Tue, 26 May 2015 13:53:22 +0000 Subject: [PATCH] Show list of available updates at "About" page --- src/mibew/js/source/about.js | 40 ----------------- .../Mibew/Controller/AboutController.php | 44 ++++++++++++++++--- .../server_side/about.handlebars | 22 +++++++--- 3 files changed, 54 insertions(+), 52 deletions(-) delete mode 100644 src/mibew/js/source/about.js diff --git a/src/mibew/js/source/about.js b/src/mibew/js/source/about.js deleted file mode 100644 index 7636e2e8..00000000 --- a/src/mibew/js/source/about.js +++ /dev/null @@ -1,40 +0,0 @@ -/*! - * This file is a part of Mibew Messenger. - * - * Copyright 2005-2015 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -(function (Mibew, $) { - Mibew.updateVersion = function(data) { - if (!data.core || !data.core.stable) { - return; - } - - $(document).ready(function() { - var currentVersion = $("#current-version").html(), - core = data.core.stable; - - if (currentVersion != core.version) { - if (currentVersion < core.version) { - $("#current-version").css("color", "red"); - } - $("#latest-version").html(core.version + ", Download " + core.title + ""); - } else { - $("#current-version").css("color", "green"); - $("#latest-version").html(core.version); - } - }); - } -})(Mibew, jQuery); diff --git a/src/mibew/libs/classes/Mibew/Controller/AboutController.php b/src/mibew/libs/classes/Mibew/Controller/AboutController.php index b9ac3c12..49a1be2c 100644 --- a/src/mibew/libs/classes/Mibew/Controller/AboutController.php +++ b/src/mibew/libs/classes/Mibew/Controller/AboutController.php @@ -19,7 +19,7 @@ namespace Mibew\Controller; -use Mibew\Asset\AssetManagerInterface; +use Mibew\Maintenance\AvailableUpdate; use Symfony\Component\HttpFoundation\Request; /** @@ -43,16 +43,11 @@ class AboutController extends AbstractController 'version' => MIBEW_VERSION, 'title' => getlocal('About'), 'menuid' => 'about', + 'availableUpdates' => $this->getAvailableUpdates(), ), prepare_menu($this->getOperator()) ); - $this->getAssetManager()->attachJs('js/compiled/about.js'); - $this->getAssetManager()->attachJs( - 'https://mibew.org/api/updates', - AssetManagerInterface::ABSOLUTE_URL - ); - return $this->render('about', $page); } @@ -86,4 +81,39 @@ class AboutController extends AbstractController return $info; } + + /** + * Builds list of available updates to display in the template. + * + * @return array List of updates data. Each item of the list is associative + * array with the following keys: + * - "title": string, title of the update. + * - "version": string, the latest available version. + * - "url": string, URL of the page the updated version can be downloaded + * from. + * - "description": string, description of the update. + */ + protected function getAvailableUpdates() + { + $updates = AvailableUpdate::all(); + if (!$updates) { + return array(); + } + + $data = array(); + foreach ($updates as $update) { + $title = ($update->target == 'core') + ? 'Mibew' + : getlocal('{0} plugin', array($update->target)); + + $data[] = array( + 'title' => $title, + 'version' => $update->version, + 'url' => $update->url, + 'description' => $update->description, + ); + } + + return $data; + } } diff --git a/src/mibew/styles/pages/default/templates_src/server_side/about.handlebars b/src/mibew/styles/pages/default/templates_src/server_side/about.handlebars index 6396699a..52f02513 100644 --- a/src/mibew/styles/pages/default/templates_src/server_side/about.handlebars +++ b/src/mibew/styles/pages/default/templates_src/server_side/about.handlebars @@ -22,11 +22,6 @@
-

{{l10n "Latest version:"}}

-
- -
-

{{l10n "Installed localizations:"}}

{{#each localizations}} {{this}} @@ -36,6 +31,23 @@

{{l10n "Environment:"}}

PHP {{phpVersion}} {{#each extensions}}{{@key}}{{#if loaded}}{{#if version}}/{{version}}{{/if}}{{else}}/absent{{/if}} {{/each}} + +

+ + {{#if availableUpdates}} +

{{l10n "Available updates"}}

+ {{#each availableUpdates}} +

{{title}} ({{version}})

+ {{#if description}} +
{{description}}
+ {{/if}} +
+ Download +
+ +
+ {{/each}} + {{/if}}