diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2017-04-23 22:10:17 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2017-04-26 20:07:49 +0200 |
commit | 47cd9760350baaf24bdf92c7a77129e59ec2f8f3 (patch) | |
tree | c7e81c5440588267a6a275dbd661b07b3363dea8 /settings | |
parent | 646db7f88d911459bdfa038d8a66ded27ae888a4 (diff) | |
download | nextcloud-server-47cd9760350baaf24bdf92c7a77129e59ec2f8f3.tar.gz nextcloud-server-47cd9760350baaf24bdf92c7a77129e59ec2f8f3.zip |
Add app bundles
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'settings')
-rw-r--r-- | settings/Controller/AppSettingsController.php | 27 | ||||
-rw-r--r-- | settings/ajax/enableapp.php | 17 | ||||
-rw-r--r-- | settings/ajax/updateapp.php | 3 | ||||
-rw-r--r-- | settings/js/apps.js | 36 |
4 files changed, 72 insertions, 11 deletions
diff --git a/settings/Controller/AppSettingsController.php b/settings/Controller/AppSettingsController.php index 7be6c2bf562..0d204bd47ab 100644 --- a/settings/Controller/AppSettingsController.php +++ b/settings/Controller/AppSettingsController.php @@ -27,6 +27,7 @@ namespace OC\Settings\Controller; +use OC\App\AppStore\Bundles\BundleFetcher; use OC\App\AppStore\Fetcher\AppFetcher; use OC\App\AppStore\Fetcher\CategoryFetcher; use OC\App\AppStore\Version\VersionParser; @@ -50,6 +51,7 @@ class AppSettingsController extends Controller { const CAT_ENABLED = 0; const CAT_DISABLED = 1; const CAT_ALL_INSTALLED = 2; + const CAT_APP_BUNDLES = 3; /** @var \OCP\IL10N */ private $l10n; @@ -65,6 +67,8 @@ class AppSettingsController extends Controller { private $appFetcher; /** @var IFactory */ private $l10nFactory; + /** @var BundleFetcher */ + private $bundleFetcher; /** * @param string $appName @@ -76,6 +80,7 @@ class AppSettingsController extends Controller { * @param CategoryFetcher $categoryFetcher * @param AppFetcher $appFetcher * @param IFactory $l10nFactory + * @param BundleFetcher $bundleFetcher */ public function __construct($appName, IRequest $request, @@ -85,7 +90,8 @@ class AppSettingsController extends Controller { IAppManager $appManager, CategoryFetcher $categoryFetcher, AppFetcher $appFetcher, - IFactory $l10nFactory) { + IFactory $l10nFactory, + BundleFetcher $bundleFetcher) { parent::__construct($appName, $request); $this->l10n = $l10n; $this->config = $config; @@ -94,6 +100,7 @@ class AppSettingsController extends Controller { $this->categoryFetcher = $categoryFetcher; $this->appFetcher = $appFetcher; $this->l10nFactory = $l10nFactory; + $this->bundleFetcher = $bundleFetcher; } /** @@ -131,6 +138,7 @@ class AppSettingsController extends Controller { $formattedCategories = [ ['id' => self::CAT_ALL_INSTALLED, 'ident' => 'installed', 'displayName' => (string)$this->l10n->t('Your apps')], ['id' => self::CAT_ENABLED, 'ident' => 'enabled', 'displayName' => (string)$this->l10n->t('Enabled apps')], + ['id' => self::CAT_APP_BUNDLES, 'ident' => 'app-bundles', 'displayName' => (string)$this->l10n->t('App bundles')], ['id' => self::CAT_DISABLED, 'ident' => 'disabled', 'displayName' => (string)$this->l10n->t('Disabled apps')], ]; $categories = $this->categoryFetcher->get(); @@ -334,6 +342,23 @@ class AppSettingsController extends Controller { return ($a < $b) ? -1 : 1; }); break; + case 'app-bundles': + $bundles = $this->bundleFetcher->getBundles(); + $apps = []; + foreach($bundles as $bundle) { + $apps[] = [ + 'id' => $bundle->getIdentifier(), + 'author' => 'Nextcloud', + 'name' => $bundle->getName() . ' (' . $bundle->getDescription() .')', + 'description' => '', + 'internal' => true, + 'active' => false, + 'removable' => false, + 'groups' => [], + 'apps' => $bundle->getAppIdentifiers(), + ]; + } + break; default: $apps = $this->getAppsForCategory($category); diff --git a/settings/ajax/enableapp.php b/settings/ajax/enableapp.php index b6d62671a63..4c4fa0be666 100644 --- a/settings/ajax/enableapp.php +++ b/settings/ajax/enableapp.php @@ -36,13 +36,20 @@ if ($lastConfirm < (time() - 30 * 60 + 15)) { // allow 15 seconds delay } $groups = isset($_POST['groups']) ? (array)$_POST['groups'] : null; +$appIds = isset($_POST['appIds']) ? (array)$_POST['appIds'] : []; try { - $app = new OC_App(); - $appId = (string)$_POST['appid']; - $appId = OC_App::cleanAppId($appId); - $app->enable($appId, $groups); - OC_JSON::success(['data' => ['update_required' => \OC_App::shouldUpgrade($appId)]]); + $updateRequired = false; + foreach($appIds as $appId) { + $app = new OC_App(); + $appId = OC_App::cleanAppId($appId); + $app->enable($appId, $groups); + if(\OC_App::shouldUpgrade($appId)) { + $updateRequired = true; + } + } + + OC_JSON::success(['data' => ['update_required' => $updateRequired]]); } catch (Exception $e) { \OCP\Util::writeLog('core', $e->getMessage(), \OCP\Util::ERROR); OC_JSON::error(array("data" => array("message" => $e->getMessage()) )); diff --git a/settings/ajax/updateapp.php b/settings/ajax/updateapp.php index 3020f828577..bcf8e149140 100644 --- a/settings/ajax/updateapp.php +++ b/settings/ajax/updateapp.php @@ -44,7 +44,8 @@ try { \OC::$server->getAppFetcher(), \OC::$server->getHTTPClientService(), \OC::$server->getTempManager(), - \OC::$server->getLogger() + \OC::$server->getLogger(), + \OC::$server->getConfig() ); $result = $installer->updateAppstoreApp($appId); $config->setSystemValue('maintenance', false); diff --git a/settings/js/apps.js b/settings/js/apps.js index 3326886951f..cda0b5112ea 100644 --- a/settings/js/apps.js +++ b/settings/js/apps.js @@ -29,6 +29,7 @@ OC.Settings.Apps = OC.Settings.Apps || { State: { currentCategory: null, + currentCategoryElements: null, apps: null, $updateNotification: null, availableUpdates: 0 @@ -90,14 +91,15 @@ OC.Settings.Apps = OC.Settings.Apps || { }), { type:'GET', success: function (apps) { + OC.Settings.Apps.State.currentCategoryElements = apps.apps; var appListWithIndex = _.indexBy(apps.apps, 'id'); OC.Settings.Apps.State.apps = appListWithIndex; var appList = _.map(appListWithIndex, function(app) { // default values for missing fields return _.extend({level: 0}, app); }); - var source - if (categoryId === 'enabled' || categoryId === 'disabled' || categoryId === 'installed') { + var source; + if (categoryId === 'enabled' || categoryId === 'disabled' || categoryId === 'installed' || categoryId === 'app-bundles') { source = $("#app-template-installed").html(); $('#apps-list').addClass('installed'); } else { @@ -303,6 +305,20 @@ OC.Settings.Apps = OC.Settings.Apps || { return $.get(OC.generateUrl('apps/files')); }, + enableAppBundle:function(bundleId, active, element, groups) { + if (OC.PasswordConfirmation.requiresPasswordConfirmation()) { + OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.enableAppBundle, this, bundleId, active, element, groups)); + return; + } + + var bundles = OC.Settings.Apps.State.currentCategoryElements; + bundles.forEach(function(bundle) { + if(bundle['id'] === bundleId) { + OC.Settings.Apps.enableApp(bundle['apps'], active, element, groups); + } + }); + }, + enableApp:function(appId, active, element, groups) { if (OC.PasswordConfirmation.requiresPasswordConfirmation()) { OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.enableApp, this, appId, active, element, groups)); @@ -342,7 +358,14 @@ OC.Settings.Apps = OC.Settings.Apps || { // TODO: display message to admin to not refresh the page! // TODO: lock UI to prevent further operations element.val(t('settings','Enabling app …')); - $.post(OC.filePath('settings','ajax','enableapp.php'),{appid: appId, groups: groups},function(result) { + + var appIdArray = []; + if( typeof appId === 'string' ) { + appIdArray = [appId]; + } else { + appIdArray = appId; + } + $.post(OC.filePath('settings','ajax','enableapp.php'),{appIds: appIdArray, groups: groups},function(result) { if(!result || result.status !== 'success') { if (result.data && result.data.message) { OC.Settings.Apps.showErrorMessage(appId, result.data.message); @@ -777,7 +800,12 @@ OC.Settings.Apps = OC.Settings.Apps || { var element = $(this); var active = $(this).data('active'); - OC.Settings.Apps.enableApp(appId, active, element); + var category = $('#app-navigation').attr('data-category'); + if(category === 'app-bundles') { + OC.Settings.Apps.enableAppBundle(appId, active, element); + } else { + OC.Settings.Apps.enableApp(appId, active, element); + } }); $(document).on('click', '#apps-list input.uninstall', function () { |