Fix fav quickaccess ressource addition
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
parent
6f45607f57
commit
e1a2bb9d69
|
@ -40,27 +40,27 @@ $templateManager->registerTemplate('application/vnd.oasis.opendocument.text', 'c
|
||||||
$templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadsheet', 'core/templates/filetemplates/template.ods');
|
$templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadsheet', 'core/templates/filetemplates/template.ods');
|
||||||
|
|
||||||
\OCA\Files\App::getNavigationManager()->add([
|
\OCA\Files\App::getNavigationManager()->add([
|
||||||
'id' => 'files',
|
'id' => 'files',
|
||||||
'appname' => 'files',
|
'appname' => 'files',
|
||||||
'script' => 'list.php',
|
'script' => 'list.php',
|
||||||
'order' => 0,
|
'order' => 0,
|
||||||
'name' => $l->t('All files'),
|
'name' => $l->t('All files')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
\OCA\Files\App::getNavigationManager()->add([
|
\OCA\Files\App::getNavigationManager()->add([
|
||||||
'id' => 'recent',
|
'id' => 'recent',
|
||||||
'appname' => 'files',
|
'appname' => 'files',
|
||||||
'script' => 'recentlist.php',
|
'script' => 'recentlist.php',
|
||||||
'order' => 2,
|
'order' => 2,
|
||||||
'name' => $l->t('Recent'),
|
'name' => $l->t('Recent')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
\OCA\Files\App::getNavigationManager()->add([
|
\OCA\Files\App::getNavigationManager()->add([
|
||||||
'id' => 'favorites',
|
'id' => 'favorites',
|
||||||
'appname' => 'files',
|
'appname' => 'files',
|
||||||
'script' => 'simplelist.php',
|
'script' => 'simplelist.php',
|
||||||
'order' => 5,
|
'order' => 5,
|
||||||
'name' => $l->t('Favorites'),
|
'name' => $l->t('Favorites'),
|
||||||
'expandedState' => 'show_Quick_Access'
|
'expandedState' => 'show_Quick_Access'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
@ -68,29 +68,22 @@
|
||||||
* @param {String} appfolder folder to be removed
|
* @param {String} appfolder folder to be removed
|
||||||
*/
|
*/
|
||||||
function removeFavoriteFromList (appfolder) {
|
function removeFavoriteFromList (appfolder) {
|
||||||
|
|
||||||
var quickAccessList = 'sublist-favorites';
|
var quickAccessList = 'sublist-favorites';
|
||||||
var collapsibleButtonId = 'button-collapse-favorites';
|
|
||||||
var listULElements = document.getElementById(quickAccessList);
|
var listULElements = document.getElementById(quickAccessList);
|
||||||
if (!listULElements) {
|
if (!listULElements) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var listLIElements = listULElements.getElementsByTagName('li');
|
|
||||||
|
|
||||||
var apppath=appfolder;
|
var apppath=appfolder;
|
||||||
if(appfolder.startsWith("//")){
|
if(appfolder.startsWith("//")){
|
||||||
apppath=appfolder.substring(1, appfolder.length);
|
apppath=appfolder.substring(1, appfolder.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i <= listLIElements.length - 1; i++) {
|
$(listULElements).find('[data-dir="' + apppath + '"]').remove();
|
||||||
if (listLIElements[i].getElementsByTagName('a')[0].href.endsWith("dir=" + apppath)) {
|
|
||||||
listLIElements[i].remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (listULElements.childElementCount === 0) {
|
if (listULElements.childElementCount === 0) {
|
||||||
var collapsibleButton = document.getElementById("button-collapse-favorites");
|
var collapsibleButton = $(listULElements).parent().find('button.collapse');
|
||||||
collapsibleButton.style.display = 'none';
|
collapsibleButton.hide();
|
||||||
$("#button-collapse-parent-favorites").removeClass('collapsible');
|
$("#button-collapse-parent-favorites").removeClass('collapsible');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,7 +95,6 @@
|
||||||
*/
|
*/
|
||||||
function addFavoriteToList (appfolder) {
|
function addFavoriteToList (appfolder) {
|
||||||
var quickAccessList = 'sublist-favorites';
|
var quickAccessList = 'sublist-favorites';
|
||||||
var collapsibleButtonId = 'button-collapse-favorites';
|
|
||||||
var listULElements = document.getElementById(quickAccessList);
|
var listULElements = document.getElementById(quickAccessList);
|
||||||
if (!listULElements) {
|
if (!listULElements) {
|
||||||
return;
|
return;
|
||||||
|
@ -110,13 +102,13 @@
|
||||||
var listLIElements = listULElements.getElementsByTagName('li');
|
var listLIElements = listULElements.getElementsByTagName('li');
|
||||||
|
|
||||||
var appName = appfolder.substring(appfolder.lastIndexOf("/") + 1, appfolder.length);
|
var appName = appfolder.substring(appfolder.lastIndexOf("/") + 1, appfolder.length);
|
||||||
var apppath=appfolder;
|
var apppath = appfolder;
|
||||||
|
|
||||||
if(appfolder.startsWith("//")){
|
if(appfolder.startsWith("//")){
|
||||||
apppath=appfolder.substring(1, appfolder.length);
|
apppath = appfolder.substring(1, appfolder.length);
|
||||||
}
|
}
|
||||||
var url=OC.generateUrl('/apps/files/?dir=')+apppath;
|
var url = OC.generateUrl('/apps/files/?dir=' + apppath + '&view=files');
|
||||||
|
|
||||||
|
|
||||||
var innerTagA = document.createElement('A');
|
var innerTagA = document.createElement('A');
|
||||||
innerTagA.setAttribute("href", url);
|
innerTagA.setAttribute("href", url);
|
||||||
|
@ -125,7 +117,9 @@
|
||||||
|
|
||||||
var length = listLIElements.length + 1;
|
var length = listLIElements.length + 1;
|
||||||
var innerTagLI = document.createElement('li');
|
var innerTagLI = document.createElement('li');
|
||||||
innerTagLI.setAttribute("data-id", url);
|
innerTagLI.setAttribute("data-id", apppath.replace('/', '-'));
|
||||||
|
innerTagLI.setAttribute("data-dir", apppath);
|
||||||
|
innerTagLI.setAttribute("data-view", 'files');
|
||||||
innerTagLI.setAttribute("class", "nav-" + appName);
|
innerTagLI.setAttribute("class", "nav-" + appName);
|
||||||
innerTagLI.setAttribute("folderpos", length.toString());
|
innerTagLI.setAttribute("folderpos", length.toString());
|
||||||
innerTagLI.appendChild(innerTagA);
|
innerTagLI.appendChild(innerTagA);
|
||||||
|
@ -134,10 +128,9 @@
|
||||||
if (data === "dir") {
|
if (data === "dir") {
|
||||||
if (listULElements.childElementCount <= 0) {
|
if (listULElements.childElementCount <= 0) {
|
||||||
listULElements.appendChild(innerTagLI);
|
listULElements.appendChild(innerTagLI);
|
||||||
var collapsibleButton = document.getElementById(collapsibleButtonId);
|
var collapsibleButton = $(listULElements).parent().find('button.collapse');
|
||||||
collapsibleButton.style.display = '';
|
collapsibleButton.show();
|
||||||
|
$(listULElements).parent().addClass('collapsible');
|
||||||
$("#button-collapse-parent-favorites").addClass('collapsible');
|
|
||||||
} else {
|
} else {
|
||||||
listLIElements[listLIElements.length - 1].after(innerTagLI);
|
listLIElements[listLIElements.length - 1].after(innerTagLI);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,8 @@ use OCP\AppFramework\Controller;
|
||||||
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
||||||
use OCP\AppFramework\Http\RedirectResponse;
|
use OCP\AppFramework\Http\RedirectResponse;
|
||||||
use OCP\AppFramework\Http\TemplateResponse;
|
use OCP\AppFramework\Http\TemplateResponse;
|
||||||
|
use OCP\App\IAppManager;
|
||||||
|
use OCP\Files\Folder;
|
||||||
use OCP\Files\IRootFolder;
|
use OCP\Files\IRootFolder;
|
||||||
use OCP\Files\NotFoundException;
|
use OCP\Files\NotFoundException;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
|
@ -41,8 +43,6 @@ use OCP\IRequest;
|
||||||
use OCP\IURLGenerator;
|
use OCP\IURLGenerator;
|
||||||
use OCP\IUserSession;
|
use OCP\IUserSession;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use OCP\Files\Folder;
|
|
||||||
use OCP\App\IAppManager;
|
|
||||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,27 +73,27 @@ class ViewController extends Controller {
|
||||||
protected $activityHelper;
|
protected $activityHelper;
|
||||||
|
|
||||||
public function __construct(string $appName,
|
public function __construct(string $appName,
|
||||||
IRequest $request,
|
IRequest $request,
|
||||||
IURLGenerator $urlGenerator,
|
IURLGenerator $urlGenerator,
|
||||||
IL10N $l10n,
|
IL10N $l10n,
|
||||||
IConfig $config,
|
IConfig $config,
|
||||||
EventDispatcherInterface $eventDispatcherInterface,
|
EventDispatcherInterface $eventDispatcherInterface,
|
||||||
IUserSession $userSession,
|
IUserSession $userSession,
|
||||||
IAppManager $appManager,
|
IAppManager $appManager,
|
||||||
IRootFolder $rootFolder,
|
IRootFolder $rootFolder,
|
||||||
Helper $activityHelper
|
Helper $activityHelper
|
||||||
) {
|
) {
|
||||||
parent::__construct($appName, $request);
|
parent::__construct($appName, $request);
|
||||||
$this->appName = $appName;
|
$this->appName = $appName;
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
$this->urlGenerator = $urlGenerator;
|
$this->urlGenerator = $urlGenerator;
|
||||||
$this->l10n = $l10n;
|
$this->l10n = $l10n;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->eventDispatcher = $eventDispatcherInterface;
|
$this->eventDispatcher = $eventDispatcherInterface;
|
||||||
$this->userSession = $userSession;
|
$this->userSession = $userSession;
|
||||||
$this->appManager = $appManager;
|
$this->appManager = $appManager;
|
||||||
$this->rootFolder = $rootFolder;
|
$this->rootFolder = $rootFolder;
|
||||||
$this->activityHelper = $activityHelper;
|
$this->activityHelper = $activityHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,8 +102,8 @@ class ViewController extends Controller {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function renderScript($appName, $scriptName) {
|
protected function renderScript($appName, $scriptName) {
|
||||||
$content = '';
|
$content = '';
|
||||||
$appPath = \OC_App::getAppPath($appName);
|
$appPath = \OC_App::getAppPath($appName);
|
||||||
$scriptPath = $appPath . '/' . $scriptName;
|
$scriptPath = $appPath . '/' . $scriptName;
|
||||||
if (file_exists($scriptPath)) {
|
if (file_exists($scriptPath)) {
|
||||||
// TODO: sanitize path / script name ?
|
// TODO: sanitize path / script name ?
|
||||||
|
@ -112,6 +112,7 @@ class ViewController extends Controller {
|
||||||
$content = ob_get_contents();
|
$content = ob_get_contents();
|
||||||
@ob_end_clean();
|
@ob_end_clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,6 +124,7 @@ class ViewController extends Controller {
|
||||||
*/
|
*/
|
||||||
protected function getStorageInfo() {
|
protected function getStorageInfo() {
|
||||||
$dirInfo = \OC\Files\Filesystem::getFileInfo('/', false);
|
$dirInfo = \OC\Files\Filesystem::getFileInfo('/', false);
|
||||||
|
|
||||||
return \OC_Helper::getStorageInfo('/', $dirInfo);
|
return \OC_Helper::getStorageInfo('/', $dirInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,21 +173,21 @@ class ViewController extends Controller {
|
||||||
$favoritesSublistArray = Array();
|
$favoritesSublistArray = Array();
|
||||||
|
|
||||||
$navBarPositionPosition = 6;
|
$navBarPositionPosition = 6;
|
||||||
$currentCount = 0;
|
$currentCount = 0;
|
||||||
foreach ($favElements['folders'] as $dir) {
|
foreach ($favElements['folders'] as $dir) {
|
||||||
|
|
||||||
$id = substr($dir, strrpos($dir, '/') + 1, strlen($dir));
|
$id = substr($dir, strrpos($dir, '/') + 1, strlen($dir));
|
||||||
$link = $this->urlGenerator->linkToRoute('files.view.index', ['dir' => $dir, 'view' => 'files']);
|
$link = $this->urlGenerator->linkToRoute('files.view.index', ['dir' => $dir, 'view' => 'files']);
|
||||||
$sortingValue = ++$currentCount;
|
$sortingValue = ++$currentCount;
|
||||||
$element = [
|
$element = [
|
||||||
'id' => str_replace('/', '-', $dir),
|
'id' => str_replace('/', '-', $dir),
|
||||||
'view' => 'files',
|
'view' => 'files',
|
||||||
'href' => $link,
|
'href' => $link,
|
||||||
'dir' => $dir,
|
'dir' => $dir,
|
||||||
'order' => $navBarPositionPosition,
|
'order' => $navBarPositionPosition,
|
||||||
'folderPosition' => $sortingValue,
|
'folderPosition' => $sortingValue,
|
||||||
'name' => $id,
|
'name' => $id,
|
||||||
'icon' => 'files',
|
'icon' => 'files',
|
||||||
'quickaccesselement' => 'true'
|
'quickaccesselement' => 'true'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -193,19 +195,16 @@ class ViewController extends Controller {
|
||||||
$navBarPositionPosition++;
|
$navBarPositionPosition++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$navItems = \OCA\Files\App::getNavigationManager()->getAll();
|
$navItems = \OCA\Files\App::getNavigationManager()->getAll();
|
||||||
|
|
||||||
// transform the favorites entry in menu
|
// add the favorites entry in menu
|
||||||
$navItems['favorites']['sublist'] = $favoritesSublistArray;
|
$navItems['favorites']['sublist'] = $favoritesSublistArray;
|
||||||
$navItems['favorites']['classes'] = $collapseClasses;
|
$navItems['favorites']['classes'] = $collapseClasses;
|
||||||
|
|
||||||
|
|
||||||
// parse every menu and add the expandedState user value
|
// parse every menu and add the expandedState user value
|
||||||
foreach ($navItems as $key => $item) {
|
foreach ($navItems as $key => $item) {
|
||||||
if (isset($item['expandedState'])) {
|
if (isset($item['expandedState'])) {
|
||||||
$defaultValue = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1';
|
$navItems[$key]['defaultExpandedState'] = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1';
|
||||||
$navItems[$key]['defaultExpandedState'] = $defaultValue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,34 +236,34 @@ class ViewController extends Controller {
|
||||||
$subcontent = $this->renderScript($subitem['appname'], $subitem['script']);
|
$subcontent = $this->renderScript($subitem['appname'], $subitem['script']);
|
||||||
}
|
}
|
||||||
$contentItems[$subitem['id']] = [
|
$contentItems[$subitem['id']] = [
|
||||||
'id' => $subitem['id'],
|
'id' => $subitem['id'],
|
||||||
'content' =>$subcontent
|
'content' => $subcontent
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$contentItems[$item['id']] = [
|
$contentItems[$item['id']] = [
|
||||||
'id' => $item['id'],
|
'id' => $item['id'],
|
||||||
'content' =>$content
|
'content' => $content
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$event = new GenericEvent(null, ['hiddenFields' => []]);
|
$event = new GenericEvent(null, ['hiddenFields' => []]);
|
||||||
$this->eventDispatcher->dispatch('OCA\Files::loadAdditionalScripts', $event);
|
$this->eventDispatcher->dispatch('OCA\Files::loadAdditionalScripts', $event);
|
||||||
|
|
||||||
$params = [];
|
$params = [];
|
||||||
$params['usedSpacePercent'] = (int)$storageInfo['relative'];
|
$params['usedSpacePercent'] = (int) $storageInfo['relative'];
|
||||||
$params['owner'] = $storageInfo['owner'];
|
$params['owner'] = $storageInfo['owner'];
|
||||||
$params['ownerDisplayName'] = $storageInfo['ownerDisplayName'];
|
$params['ownerDisplayName'] = $storageInfo['ownerDisplayName'];
|
||||||
$params['isPublic'] = false;
|
$params['isPublic'] = false;
|
||||||
$params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes');
|
$params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes');
|
||||||
$params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name');
|
$params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name');
|
||||||
$params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc');
|
$params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc');
|
||||||
$showHidden = (bool)$this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false);
|
$showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false);
|
||||||
$params['showHiddenFiles'] = $showHidden ? 1 : 0;
|
$params['showHiddenFiles'] = $showHidden ? 1 : 0;
|
||||||
$params['fileNotFound'] = $fileNotFound ? 1 : 0;
|
$params['fileNotFound'] = $fileNotFound ? 1 : 0;
|
||||||
$params['appNavigation'] = $nav;
|
$params['appNavigation'] = $nav;
|
||||||
$params['appContents'] = $contentItems;
|
$params['appContents'] = $contentItems;
|
||||||
$params['hiddenFields'] = $event->getArgument('hiddenFields');
|
$params['hiddenFields'] = $event->getArgument('hiddenFields');
|
||||||
|
|
||||||
$response = new TemplateResponse(
|
$response = new TemplateResponse(
|
||||||
$this->appName,
|
$this->appName,
|
||||||
|
@ -275,7 +274,6 @@ class ViewController extends Controller {
|
||||||
$policy->addAllowedFrameDomain('\'self\'');
|
$policy->addAllowedFrameDomain('\'self\'');
|
||||||
$response->setContentSecurityPolicy($policy);
|
$response->setContentSecurityPolicy($policy);
|
||||||
|
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,14 +285,14 @@ class ViewController extends Controller {
|
||||||
* @throws \OCP\Files\NotFoundException
|
* @throws \OCP\Files\NotFoundException
|
||||||
*/
|
*/
|
||||||
private function showFile($fileId) {
|
private function showFile($fileId) {
|
||||||
$uid = $this->userSession->getUser()->getUID();
|
$uid = $this->userSession->getUser()->getUID();
|
||||||
$baseFolder = $this->rootFolder->getUserFolder($uid);
|
$baseFolder = $this->rootFolder->getUserFolder($uid);
|
||||||
$files = $baseFolder->getById($fileId);
|
$files = $baseFolder->getById($fileId);
|
||||||
$params = [];
|
$params = [];
|
||||||
|
|
||||||
if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) {
|
if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) {
|
||||||
$baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/');
|
$baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/');
|
||||||
$files = $baseFolder->getById($fileId);
|
$files = $baseFolder->getById($fileId);
|
||||||
$params['view'] = 'trashbin';
|
$params['view'] = 'trashbin';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,6 +307,7 @@ class ViewController extends Controller {
|
||||||
// and scroll to the entry
|
// and scroll to the entry
|
||||||
$params['scrollto'] = $file->getName();
|
$params['scrollto'] = $file->getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params));
|
return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params));
|
||||||
}
|
}
|
||||||
throw new \OCP\Files\NotFoundException();
|
throw new \OCP\Files\NotFoundException();
|
||||||
|
|
Loading…
Reference in New Issue