Rebuild app navigation in JS
Retrieve all app navigations to prevent reloading appinfo/app.php and causing an error when the app isn't fully loaded. The addition/deletion logic has been moved to JS, simplifying a lot of code.
This commit is contained in:
parent
7f8bca64cb
commit
b06bc409e0
3 changed files with 16 additions and 50 deletions
|
@ -384,29 +384,6 @@ class OC_App {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the navigation entries for the $app
|
||||
*
|
||||
* @param string $app app
|
||||
* @return array an array of the $data added with addNavigationEntry
|
||||
*
|
||||
* Warning: destroys the existing entries
|
||||
*/
|
||||
public static function getAppNavigationEntries($app) {
|
||||
if (is_file(self::getAppPath($app) . '/appinfo/app.php')) {
|
||||
OC::$server->getNavigationManager()->clear();
|
||||
try {
|
||||
require $app . '/appinfo/app.php';
|
||||
} catch (\OC\Encryption\Exceptions\ModuleAlreadyExistsException $e) {
|
||||
// FIXME we should avoid getting this exception in first place,
|
||||
// For now we just catch it, since we don't care about encryption modules
|
||||
// when trying to find out, whether the app has a navigation entry.
|
||||
}
|
||||
return OC::$server->getNavigationManager()->getAll();
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the active Menu entry
|
||||
*
|
||||
|
|
|
@ -23,14 +23,6 @@
|
|||
OC_Util::checkAdminUser();
|
||||
OCP\JSON::callCheck();
|
||||
|
||||
$app = (string)$_GET['app'];
|
||||
$app = OC_App::cleanAppId($app);
|
||||
$navigation = \OC::$server->getNavigationManager()->getAll();
|
||||
|
||||
$navigation = OC_App::getAppNavigationEntries($app);
|
||||
|
||||
$navIds = array();
|
||||
foreach ($navigation as $nav) {
|
||||
$navIds[] = $nav['id'];
|
||||
}
|
||||
|
||||
OCP\JSON::success(array('nav_ids' => array_values($navIds), 'nav_entries' => $navigation));
|
||||
OCP\JSON::success(['nav_entries' => $navigation]);
|
||||
|
|
|
@ -219,10 +219,10 @@ OC.Settings.Apps = OC.Settings.Apps || {
|
|||
element.val(t('settings','Disable'));
|
||||
appItem.addClass('appwarning');
|
||||
} else {
|
||||
OC.Settings.Apps.rebuildNavigation();
|
||||
appItem.data('active',false);
|
||||
appItem.data('groups', '');
|
||||
element.data('active',false);
|
||||
OC.Settings.Apps.removeNavigation(appId);
|
||||
appItem.removeClass('active');
|
||||
element.val(t('settings','Enable'));
|
||||
element.parent().find(".groups-enable").hide();
|
||||
|
@ -245,7 +245,7 @@ OC.Settings.Apps = OC.Settings.Apps || {
|
|||
element.val(t('settings','Enable'));
|
||||
appItem.addClass('appwarning');
|
||||
} else {
|
||||
OC.Settings.Apps.addNavigation(appId);
|
||||
OC.Settings.Apps.rebuildNavigation();
|
||||
appItem.data('active',true);
|
||||
element.data('active',true);
|
||||
appItem.addClass('active');
|
||||
|
@ -278,7 +278,6 @@ OC.Settings.Apps = OC.Settings.Apps || {
|
|||
appItem.data('errormsg', t('settings', 'Error while enabling app'));
|
||||
appItem.data('active',false);
|
||||
appItem.addClass('appwarning');
|
||||
OC.Settings.Apps.removeNavigation(appId);
|
||||
element.val(t('settings','Enable'));
|
||||
});
|
||||
}
|
||||
|
@ -312,7 +311,7 @@ OC.Settings.Apps = OC.Settings.Apps || {
|
|||
OC.Settings.Apps.showErrorMessage(appId, t('settings','Error while uninstalling app'));
|
||||
element.val(t('settings','Uninstall'));
|
||||
} else {
|
||||
OC.Settings.Apps.removeNavigation(appId);
|
||||
OC.Settings.Apps.rebuildNavigation();
|
||||
element.parent().fadeOut(function() {
|
||||
element.remove();
|
||||
});
|
||||
|
@ -320,23 +319,15 @@ OC.Settings.Apps = OC.Settings.Apps || {
|
|||
},'json');
|
||||
},
|
||||
|
||||
removeNavigation: function(appId){
|
||||
$.getJSON(OC.filePath('settings', 'ajax', 'navigationdetect.php'), {app: appId}).done(function(response){
|
||||
if(response.status === 'success'){
|
||||
var navIds=response.nav_ids;
|
||||
for(var i=0; i< navIds.length; i++){
|
||||
$('#apps ul').children('li[data-id="'+navIds[i]+'"]').remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
addNavigation: function(appid){
|
||||
$.getJSON(OC.filePath('settings', 'ajax', 'navigationdetect.php'), {app: appid}).done(function(response){
|
||||
rebuildNavigation: function() {
|
||||
$.getJSON(OC.filePath('settings', 'ajax', 'navigationdetect.php')).done(function(response){
|
||||
if(response.status === 'success'){
|
||||
var idsToKeep = {};
|
||||
var navEntries=response.nav_entries;
|
||||
var container = $('#apps ul');
|
||||
for(var i=0; i< navEntries.length; i++){
|
||||
var entry = navEntries[i];
|
||||
var container = $('#apps ul');
|
||||
idsToKeep[entry.id] = true;
|
||||
|
||||
if(container.children('li[data-id="'+entry.id+'"]').length === 0){
|
||||
var li=$('<li></li>');
|
||||
|
@ -377,6 +368,12 @@ OC.Settings.Apps = OC.Settings.Apps || {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
container.children('li[data-id]').each(function(index, el) {
|
||||
if (!idsToKeep[$(el).data('id')]) {
|
||||
$(el).remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue