App management: add update section
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
parent
968d4f6396
commit
8d1b32e597
|
@ -493,16 +493,23 @@ img, object, video, button, textarea, input, select {
|
||||||
.icon-category-installed {
|
.icon-category-installed {
|
||||||
background-image: url('../img/actions/user.svg?v=1');
|
background-image: url('../img/actions/user.svg?v=1');
|
||||||
}
|
}
|
||||||
|
|
||||||
.icon-category-enabled {
|
.icon-category-enabled {
|
||||||
background-image: url('../img/actions/checkmark.svg?v=1');
|
background-image: url('../img/actions/checkmark.svg?v=1');
|
||||||
}
|
}
|
||||||
|
|
||||||
.icon-category-disabled {
|
.icon-category-disabled {
|
||||||
background-image: url('../img/actions/close.svg?v=1');
|
background-image: url('../img/actions/close.svg?v=1');
|
||||||
}
|
}
|
||||||
|
|
||||||
.icon-category-app-bundles {
|
.icon-category-app-bundles {
|
||||||
background-image: url('../img/categories/bundles.svg?v=1');
|
background-image: url('../img/categories/bundles.svg?v=1');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.icon-category-updates {
|
||||||
|
background-image: url('../img/actions/download.svg?v=1');
|
||||||
|
}
|
||||||
|
|
||||||
.icon-category-files {
|
.icon-category-files {
|
||||||
background-image: url('../img/categories/files.svg?v=1');
|
background-image: url('../img/categories/files.svg?v=1');
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ class AppSettingsController extends Controller {
|
||||||
const CAT_DISABLED = 1;
|
const CAT_DISABLED = 1;
|
||||||
const CAT_ALL_INSTALLED = 2;
|
const CAT_ALL_INSTALLED = 2;
|
||||||
const CAT_APP_BUNDLES = 3;
|
const CAT_APP_BUNDLES = 3;
|
||||||
|
const CAT_UPDATES = 4;
|
||||||
|
|
||||||
/** @var \OCP\IL10N */
|
/** @var \OCP\IL10N */
|
||||||
private $l10n;
|
private $l10n;
|
||||||
|
@ -130,8 +131,10 @@ class AppSettingsController extends Controller {
|
||||||
private function getAllCategories() {
|
private function getAllCategories() {
|
||||||
$currentLanguage = substr($this->l10nFactory->findLanguage(), 0, 2);
|
$currentLanguage = substr($this->l10nFactory->findLanguage(), 0, 2);
|
||||||
|
|
||||||
|
$updateCount = count($this->getAppsWithUpdates());
|
||||||
$formattedCategories = [
|
$formattedCategories = [
|
||||||
['id' => self::CAT_ALL_INSTALLED, 'ident' => 'installed', 'displayName' => (string)$this->l10n->t('Your apps')],
|
['id' => self::CAT_ALL_INSTALLED, 'ident' => 'installed', 'displayName' => (string)$this->l10n->t('Your apps')],
|
||||||
|
['id' => self::CAT_UPDATES, 'ident' => 'updates', 'displayName' => (string)$this->l10n->t('Updates'), 'counter' => $updateCount],
|
||||||
['id' => self::CAT_ENABLED, 'ident' => 'enabled', 'displayName' => (string)$this->l10n->t('Enabled apps')],
|
['id' => self::CAT_ENABLED, 'ident' => 'enabled', 'displayName' => (string)$this->l10n->t('Enabled apps')],
|
||||||
['id' => self::CAT_DISABLED, 'ident' => 'disabled', 'displayName' => (string)$this->l10n->t('Disabled apps')],
|
['id' => self::CAT_DISABLED, 'ident' => 'disabled', 'displayName' => (string)$this->l10n->t('Disabled apps')],
|
||||||
['id' => self::CAT_APP_BUNDLES, 'ident' => 'app-bundles', 'displayName' => (string)$this->l10n->t('App bundles')],
|
['id' => self::CAT_APP_BUNDLES, 'ident' => 'app-bundles', 'displayName' => (string)$this->l10n->t('App bundles')],
|
||||||
|
@ -273,6 +276,28 @@ class AppSettingsController extends Controller {
|
||||||
return $formattedApps;
|
return $formattedApps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getAppsWithUpdates() {
|
||||||
|
$appClass = new \OC_App();
|
||||||
|
$apps = $appClass->listAllApps();
|
||||||
|
foreach($apps as $key => $app) {
|
||||||
|
$newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher);
|
||||||
|
if($newVersion !== false) {
|
||||||
|
$apps[$key]['update'] = $newVersion;
|
||||||
|
} else {
|
||||||
|
unset($apps[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
usort($apps, function ($a, $b) {
|
||||||
|
$a = (string)$a['name'];
|
||||||
|
$b = (string)$b['name'];
|
||||||
|
if ($a === $b) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return ($a < $b) ? -1 : 1;
|
||||||
|
});
|
||||||
|
return $apps;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all available apps in a category
|
* Get all available apps in a category
|
||||||
*
|
*
|
||||||
|
@ -301,6 +326,10 @@ class AppSettingsController extends Controller {
|
||||||
return ($a < $b) ? -1 : 1;
|
return ($a < $b) ? -1 : 1;
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
// updates
|
||||||
|
case 'updates':
|
||||||
|
$apps = $this->getAppsWithUpdates();
|
||||||
|
break;
|
||||||
// enabled apps
|
// enabled apps
|
||||||
case 'enabled':
|
case 'enabled':
|
||||||
$apps = $appClass->listAllApps();
|
$apps = $appClass->listAllApps();
|
||||||
|
|
|
@ -42,6 +42,7 @@ OC.Settings.Apps = OC.Settings.Apps || {
|
||||||
|
|
||||||
var categories = [
|
var categories = [
|
||||||
{displayName: t('settings', 'Your apps'), ident: 'installed', id: '0'},
|
{displayName: t('settings', 'Your apps'), ident: 'installed', id: '0'},
|
||||||
|
{displayName: t('settings', 'Updates'), ident: 'updates', id: '3'},
|
||||||
{displayName: t('settings', 'Enabled apps'), ident: 'enabled', id: '1'},
|
{displayName: t('settings', 'Enabled apps'), ident: 'enabled', id: '1'},
|
||||||
{displayName: t('settings', 'Disabled apps'), ident: 'disabled', id: '2'}
|
{displayName: t('settings', 'Disabled apps'), ident: 'disabled', id: '2'}
|
||||||
];
|
];
|
||||||
|
@ -58,6 +59,12 @@ OC.Settings.Apps = OC.Settings.Apps || {
|
||||||
type:'GET',
|
type:'GET',
|
||||||
success:function (jsondata) {
|
success:function (jsondata) {
|
||||||
var html = template(jsondata);
|
var html = template(jsondata);
|
||||||
|
var updateCategory = $.grep(jsondata, function(element, index) {
|
||||||
|
return element.ident === 'updates'
|
||||||
|
});
|
||||||
|
if (updateCategory.length === 1) {
|
||||||
|
OC.Settings.Apps.State.availableUpdates = updateCategory[0].counter;
|
||||||
|
}
|
||||||
$('#apps-categories').html(html);
|
$('#apps-categories').html(html);
|
||||||
$('#app-category-' + OC.Settings.Apps.State.currentCategory).addClass('active');
|
$('#app-category-' + OC.Settings.Apps.State.currentCategory).addClass('active');
|
||||||
},
|
},
|
||||||
|
@ -99,7 +106,7 @@ OC.Settings.Apps = OC.Settings.Apps || {
|
||||||
return _.extend({level: 0}, app);
|
return _.extend({level: 0}, app);
|
||||||
});
|
});
|
||||||
var source;
|
var source;
|
||||||
if (categoryId === 'enabled' || categoryId === 'disabled' || categoryId === 'installed' || categoryId === 'app-bundles') {
|
if (categoryId === 'enabled' || categoryId === 'updates' || categoryId === 'disabled' || categoryId === 'installed' || categoryId === 'app-bundles') {
|
||||||
source = $("#app-template-installed").html();
|
source = $("#app-template-installed").html();
|
||||||
$('#apps-list').addClass('installed');
|
$('#apps-list').addClass('installed');
|
||||||
} else {
|
} else {
|
||||||
|
@ -134,13 +141,8 @@ OC.Settings.Apps = OC.Settings.Apps || {
|
||||||
var $update = $('#app-' + app.id + ' .update');
|
var $update = $('#app-' + app.id + ' .update');
|
||||||
$update.removeClass('hidden');
|
$update.removeClass('hidden');
|
||||||
$update.val(t('settings', 'Update to %s').replace(/%s/g, app.update));
|
$update.val(t('settings', 'Update to %s').replace(/%s/g, app.update));
|
||||||
OC.Settings.Apps.State.availableUpdates++;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (OC.Settings.Apps.State.availableUpdates > 0) {
|
|
||||||
OC.Settings.Apps.State.$updateNotification = OC.Notification.show(n('settings', 'You have %n app update pending', 'You have %n app updates pending', OC.Settings.Apps.State.availableUpdates));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$('#apps-list').addClass('hidden');
|
$('#apps-list').addClass('hidden');
|
||||||
$('#apps-list-empty').removeClass('hidden').find('h2').text(t('settings', 'No apps found for your version'));
|
$('#apps-list-empty').removeClass('hidden').find('h2').text(t('settings', 'No apps found for your version'));
|
||||||
|
@ -539,14 +541,8 @@ OC.Settings.Apps = OC.Settings.Apps || {
|
||||||
var $version = $('#app-' + appId + ' .app-version');
|
var $version = $('#app-' + appId + ' .app-version');
|
||||||
$version.text(OC.Settings.Apps.State.apps[appId]['update']);
|
$version.text(OC.Settings.Apps.State.apps[appId]['update']);
|
||||||
|
|
||||||
if (OC.Settings.Apps.State.$updateNotification) {
|
|
||||||
OC.Notification.hide(OC.Settings.Apps.State.$updateNotification);
|
|
||||||
}
|
|
||||||
|
|
||||||
OC.Settings.Apps.State.availableUpdates--;
|
OC.Settings.Apps.State.availableUpdates--;
|
||||||
if (OC.Settings.Apps.State.availableUpdates > 0) {
|
OC.Settings.Apps.refreshUpdateCounter();
|
||||||
OC.Settings.Apps.State.$updateNotification = OC.Notification.show(n('settings', 'You have %n app update pending', 'You have %n app updates pending', OC.Settings.Apps.State.availableUpdates));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},'json');
|
},'json');
|
||||||
},
|
},
|
||||||
|
@ -656,6 +652,10 @@ OC.Settings.Apps = OC.Settings.Apps || {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
refreshUpdateCounter: function() {
|
||||||
|
$('#app-category-updates').find('.app-navigation-entry-utils-counter').html(OC.Settings.Apps.State.availableUpdates);
|
||||||
|
},
|
||||||
|
|
||||||
showErrorMessage: function(appId, message) {
|
showErrorMessage: function(appId, message) {
|
||||||
$('div#app-'+appId+' .warning')
|
$('div#app-'+appId+' .warning')
|
||||||
.show()
|
.show()
|
||||||
|
|
|
@ -19,6 +19,11 @@ script(
|
||||||
{{#each this}}
|
{{#each this}}
|
||||||
<li id="app-category-{{ident}}" data-category-id="{{ident}}" tabindex="0">
|
<li id="app-category-{{ident}}" data-category-id="{{ident}}" tabindex="0">
|
||||||
<a href="#" class="icon-category-{{ident}}">{{displayName}}</a>
|
<a href="#" class="icon-category-{{ident}}">{{displayName}}</a>
|
||||||
|
<div class="app-navigation-entry-utils">
|
||||||
|
<ul>
|
||||||
|
<li class="app-navigation-entry-utils-counter">{{ counter }}</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
</li>
|
</li>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
||||||
|
@ -65,9 +70,6 @@ script(
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<div class="app-dependencies update hidden">
|
|
||||||
<p><?php p($l->t('This app has an update available.')); ?></p>
|
|
||||||
</div>
|
|
||||||
<div class="warning hidden"></div>
|
<div class="warning hidden"></div>
|
||||||
<input class="update hidden" type="submit" value="<?php p($l->t('Update to %s', array('{{update}}'))); ?>" data-appid="{{id}}" />
|
<input class="update hidden" type="submit" value="<?php p($l->t('Update to %s', array('{{update}}'))); ?>" data-appid="{{id}}" />
|
||||||
{{#if canUnInstall}}
|
{{#if canUnInstall}}
|
||||||
|
|
|
@ -101,6 +101,12 @@ class AppSettingsControllerTest extends TestCase {
|
||||||
'ident' => 'installed',
|
'ident' => 'installed',
|
||||||
'displayName' => 'Your apps',
|
'displayName' => 'Your apps',
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'id' => 4,
|
||||||
|
'ident' => 'updates',
|
||||||
|
'displayName' => 'Updates',
|
||||||
|
'counter' => 0,
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'id' => 0,
|
'id' => 0,
|
||||||
'ident' => 'enabled',
|
'ident' => 'enabled',
|
||||||
|
|
Loading…
Reference in New Issue