Skip to content
Prev Previous commit
Next Next commit
Fix fav quickaccess ressource addition
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
  • Loading branch information
skjnldsv committed Jul 13, 2018
commit e1a2bb9d69bf1aeba6362672c6b161bb96ad8a48
26 changes: 13 additions & 13 deletions apps/files/appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,27 @@
$templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadsheet', 'core/templates/filetemplates/template.ods');

\OCA\Files\App::getNavigationManager()->add([
'id' => 'files',
'id' => 'files',
'appname' => 'files',
'script' => 'list.php',
'order' => 0,
'name' => $l->t('All files'),
'script' => 'list.php',
'order' => 0,
'name' => $l->t('All files')
]);

\OCA\Files\App::getNavigationManager()->add([
'id' => 'recent',
'id' => 'recent',
'appname' => 'files',
'script' => 'recentlist.php',
'order' => 2,
'name' => $l->t('Recent'),
'script' => 'recentlist.php',
'order' => 2,
'name' => $l->t('Recent')
]);

\OCA\Files\App::getNavigationManager()->add([
'id' => 'favorites',
'appname' => 'files',
'script' => 'simplelist.php',
'order' => 5,
'name' => $l->t('Favorites'),
'id' => 'favorites',
'appname' => 'files',
'script' => 'simplelist.php',
'order' => 5,
'name' => $l->t('Favorites'),
'expandedState' => 'show_Quick_Access'
]);

Expand Down
33 changes: 13 additions & 20 deletions apps/files/js/tagsplugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,22 @@
* @param {String} appfolder folder to be removed
*/
function removeFavoriteFromList (appfolder) {

var quickAccessList = 'sublist-favorites';
var collapsibleButtonId = 'button-collapse-favorites';
var listULElements = document.getElementById(quickAccessList);
if (!listULElements) {
return;
}
var listLIElements = listULElements.getElementsByTagName('li');

var apppath=appfolder;
if(appfolder.startsWith("//")){
apppath=appfolder.substring(1, appfolder.length);
}

for (var i = 0; i <= listLIElements.length - 1; i++) {
if (listLIElements[i].getElementsByTagName('a')[0].href.endsWith("dir=" + apppath)) {
listLIElements[i].remove();
}
}
$(listULElements).find('[data-dir="' + apppath + '"]').remove();

if (listULElements.childElementCount === 0) {
var collapsibleButton = document.getElementById("button-collapse-favorites");
collapsibleButton.style.display = 'none';
var collapsibleButton = $(listULElements).parent().find('button.collapse');
collapsibleButton.hide();
$("#button-collapse-parent-favorites").removeClass('collapsible');
}
}
Expand All @@ -102,21 +95,20 @@
*/
function addFavoriteToList (appfolder) {
var quickAccessList = 'sublist-favorites';
var collapsibleButtonId = 'button-collapse-favorites';
var listULElements = document.getElementById(quickAccessList);
if (!listULElements) {
return;
}
var listLIElements = listULElements.getElementsByTagName('li');

var appName = appfolder.substring(appfolder.lastIndexOf("/") + 1, appfolder.length);
var apppath=appfolder;
var apppath = appfolder;

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');
innerTagA.setAttribute("href", url);
Expand All @@ -125,7 +117,9 @@

var length = listLIElements.length + 1;
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("folderpos", length.toString());
innerTagLI.appendChild(innerTagA);
Expand All @@ -134,10 +128,9 @@
if (data === "dir") {
if (listULElements.childElementCount <= 0) {
listULElements.appendChild(innerTagLI);
var collapsibleButton = document.getElementById(collapsibleButtonId);
collapsibleButton.style.display = '';

$("#button-collapse-parent-favorites").addClass('collapsible');
var collapsibleButton = $(listULElements).parent().find('button.collapse');
collapsibleButton.show();
$(listULElements).parent().addClass('collapsible');
} else {
listLIElements[listLIElements.length - 1].after(innerTagLI);
}
Expand Down
123 changes: 61 additions & 62 deletions apps/files/lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\App\IAppManager;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\IConfig;
Expand All @@ -41,8 +43,6 @@
use OCP\IURLGenerator;
use OCP\IUserSession;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use OCP\Files\Folder;
use OCP\App\IAppManager;
use Symfony\Component\EventDispatcher\GenericEvent;

/**
Expand Down Expand Up @@ -73,27 +73,27 @@ class ViewController extends Controller {
protected $activityHelper;

public function __construct(string $appName,
IRequest $request,
IURLGenerator $urlGenerator,
IL10N $l10n,
IConfig $config,
EventDispatcherInterface $eventDispatcherInterface,
IUserSession $userSession,
IAppManager $appManager,
IRootFolder $rootFolder,
Helper $activityHelper
IRequest $request,
IURLGenerator $urlGenerator,
IL10N $l10n,
IConfig $config,
EventDispatcherInterface $eventDispatcherInterface,
IUserSession $userSession,
IAppManager $appManager,
IRootFolder $rootFolder,
Helper $activityHelper
) {
parent::__construct($appName, $request);
$this->appName = $appName;
$this->request = $request;
$this->urlGenerator = $urlGenerator;
$this->l10n = $l10n;
$this->config = $config;
$this->appName = $appName;
$this->request = $request;
$this->urlGenerator = $urlGenerator;
$this->l10n = $l10n;
$this->config = $config;
$this->eventDispatcher = $eventDispatcherInterface;
$this->userSession = $userSession;
$this->appManager = $appManager;
$this->rootFolder = $rootFolder;
$this->activityHelper = $activityHelper;
$this->userSession = $userSession;
$this->appManager = $appManager;
$this->rootFolder = $rootFolder;
$this->activityHelper = $activityHelper;
}

/**
Expand All @@ -102,8 +102,8 @@ public function __construct(string $appName,
* @return string
*/
protected function renderScript($appName, $scriptName) {
$content = '';
$appPath = \OC_App::getAppPath($appName);
$content = '';
$appPath = \OC_App::getAppPath($appName);
$scriptPath = $appPath . '/' . $scriptName;
if (file_exists($scriptPath)) {
// TODO: sanitize path / script name ?
Expand All @@ -112,6 +112,7 @@ protected function renderScript($appName, $scriptName) {
$content = ob_get_contents();
@ob_end_clean();
}

return $content;
}

Expand All @@ -123,6 +124,7 @@ protected function renderScript($appName, $scriptName) {
*/
protected function getStorageInfo() {
$dirInfo = \OC\Files\Filesystem::getFileInfo('/', false);

return \OC_Helper::getStorageInfo('/', $dirInfo);
}

Expand Down Expand Up @@ -171,41 +173,38 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
$favoritesSublistArray = Array();

$navBarPositionPosition = 6;
$currentCount = 0;
$currentCount = 0;
foreach ($favElements['folders'] as $dir) {

$id = substr($dir, strrpos($dir, '/') + 1, strlen($dir));
$link = $this->urlGenerator->linkToRoute('files.view.index', ['dir' => $dir, 'view' => 'files']);
$id = substr($dir, strrpos($dir, '/') + 1, strlen($dir));
$link = $this->urlGenerator->linkToRoute('files.view.index', ['dir' => $dir, 'view' => 'files']);
$sortingValue = ++$currentCount;
$element = [
'id' => str_replace('/', '-', $dir),
'view' => 'files',
'href' => $link,
'dir' => $dir,
'order' => $navBarPositionPosition,
'folderPosition' => $sortingValue,
'name' => $id,
'icon' => 'files',
$element = [
'id' => str_replace('/', '-', $dir),
'view' => 'files',
'href' => $link,
'dir' => $dir,
'order' => $navBarPositionPosition,
'folderPosition' => $sortingValue,
'name' => $id,
'icon' => 'files',
'quickaccesselement' => 'true'
];

array_push($favoritesSublistArray, $element);
$navBarPositionPosition++;
}


$navItems = \OCA\Files\App::getNavigationManager()->getAll();

// transform the favorites entry in menu
// add the favorites entry in menu
$navItems['favorites']['sublist'] = $favoritesSublistArray;
$navItems['favorites']['classes'] = $collapseClasses;


// parse every menu and add the expandedState user value
foreach ($navItems as $key => $item) {
if (isset($item['expandedState'])) {
$defaultValue = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1';
$navItems[$key]['defaultExpandedState'] = $defaultValue;
$navItems[$key]['defaultExpandedState'] = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1';
}
}

Expand Down Expand Up @@ -237,34 +236,34 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
$subcontent = $this->renderScript($subitem['appname'], $subitem['script']);
}
$contentItems[$subitem['id']] = [
'id' => $subitem['id'],
'content' =>$subcontent
'id' => $subitem['id'],
'content' => $subcontent
];
}
}
$contentItems[$item['id']] = [
'id' => $item['id'],
'content' =>$content
'id' => $item['id'],
'content' => $content
];
}

$event = new GenericEvent(null, ['hiddenFields' => []]);
$this->eventDispatcher->dispatch('OCA\Files::loadAdditionalScripts', $event);

$params = [];
$params['usedSpacePercent'] = (int)$storageInfo['relative'];
$params['owner'] = $storageInfo['owner'];
$params['ownerDisplayName'] = $storageInfo['ownerDisplayName'];
$params['isPublic'] = false;
$params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes');
$params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name');
$params = [];
$params['usedSpacePercent'] = (int) $storageInfo['relative'];
$params['owner'] = $storageInfo['owner'];
$params['ownerDisplayName'] = $storageInfo['ownerDisplayName'];
$params['isPublic'] = false;
$params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes');
$params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name');
$params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc');
$showHidden = (bool)$this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false);
$params['showHiddenFiles'] = $showHidden ? 1 : 0;
$params['fileNotFound'] = $fileNotFound ? 1 : 0;
$params['appNavigation'] = $nav;
$params['appContents'] = $contentItems;
$params['hiddenFields'] = $event->getArgument('hiddenFields');
$showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false);
$params['showHiddenFiles'] = $showHidden ? 1 : 0;
$params['fileNotFound'] = $fileNotFound ? 1 : 0;
$params['appNavigation'] = $nav;
$params['appContents'] = $contentItems;
$params['hiddenFields'] = $event->getArgument('hiddenFields');

$response = new TemplateResponse(
$this->appName,
Expand All @@ -275,7 +274,6 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
$policy->addAllowedFrameDomain('\'self\'');
$response->setContentSecurityPolicy($policy);


return $response;
}

Expand All @@ -287,14 +285,14 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
* @throws \OCP\Files\NotFoundException
*/
private function showFile($fileId) {
$uid = $this->userSession->getUser()->getUID();
$uid = $this->userSession->getUser()->getUID();
$baseFolder = $this->rootFolder->getUserFolder($uid);
$files = $baseFolder->getById($fileId);
$params = [];
$files = $baseFolder->getById($fileId);
$params = [];

if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) {
$baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/');
$files = $baseFolder->getById($fileId);
$baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/');
$files = $baseFolder->getById($fileId);
$params['view'] = 'trashbin';
}

Expand All @@ -309,6 +307,7 @@ private function showFile($fileId) {
// and scroll to the entry
$params['scrollto'] = $file->getName();
}

return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params));
}
throw new \OCP\Files\NotFoundException();
Expand Down