Merge pull request #10230 from nextcloud/feature/shareoverview

Feature/shares overview
This commit is contained in:
Morris Jobke 2018-07-17 12:53:45 +02:00 committed by GitHub
commit a155f80485
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 521 additions and 471 deletions

View File

@ -39,24 +39,29 @@ $templateManager->registerTemplate('application/vnd.oasis.opendocument.presentat
$templateManager->registerTemplate('application/vnd.oasis.opendocument.text', 'core/templates/filetemplates/template.odt');
$templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadsheet', 'core/templates/filetemplates/template.ods');
\OCA\Files\App::getNavigationManager()->add(function () use ($l) {
return [
'id' => 'files',
'appname' => 'files',
'script' => 'list.php',
'order' => 0,
'name' => $l->t('All files'),
];
});
\OCA\Files\App::getNavigationManager()->add([
'id' => 'files',
'appname' => 'files',
'script' => 'list.php',
'order' => 0,
'name' => $l->t('All files')
]);
\OCA\Files\App::getNavigationManager()->add(function () use ($l) {
return [
'id' => 'recent',
'appname' => 'files',
'script' => 'recentlist.php',
'order' => 2,
'name' => $l->t('Recent'),
];
});
\OCA\Files\App::getNavigationManager()->add([
'id' => 'recent',
'appname' => 'files',
'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'),
'expandedState' => 'show_Quick_Access'
]);
\OCP\Util::connectHook('\OCP\Config', 'js', '\OCA\Files\App', 'extendJsConfig');

View File

@ -77,14 +77,9 @@ $application->registerRoutes(
'verb' => 'GET',
],
[
'name' => 'API#showQuickAccess',
'url' => '/api/v1/quickaccess/set/showList',
'verb' => 'GET',
],
[
'name' => 'API#getShowQuickAccess',
'url' => '/api/v1/quickaccess/get/showList',
'verb' => 'GET',
'name' => 'API#toggleShowFolder',
'url' => '/api/v1/toggleShowFolder/{key}',
'verb' => 'POST'
],
[
'name' => 'API#getShowQuickaccessSettings',

View File

@ -93,7 +93,8 @@
background-image: url('../img/star.svg?v=1');
}
.nav-icon-sharingin,
.nav-icon-sharingout {
.nav-icon-sharingout,
.nav-icon-shareoverview {
background-image: url('../img/share.svg?v=1');
}
.nav-icon-sharinglinks {

View File

@ -172,30 +172,18 @@
*/
_onClickMenuButton: function (ev) {
var $target = $(ev.target);
var $menu = $target.parent('li');
var itemId = $target.closest('button').attr('id');
var collapsibleToggles = [];
var dotmenuToggles = [];
// The collapsibleToggles-Array consists of a list of Arrays. Every subarray must contain the Button to listen to at the 0th index,
// and the parent, which should be toggled at the first arrayindex.
collapsibleToggles.push(["#button-collapse-favorites", "#button-collapse-parent-favorites"]);
// The dotmenuToggles-Array consists of a list of Arrays. Every subarray must contain the Button to listen to at the 0th index,
// and the parent, which should be toggled at the first arrayindex.
dotmenuToggles.push(["#dotmenu-button-favorites", "dotmenu-content-favorites"]);
collapsibleToggles.forEach(function foundToggle (item) {
if (item[0] === ("#" + itemId)) {
$(item[1]).toggleClass('open');
var show = 1;
if (!$(item[1]).hasClass('open')) {
show = 0;
}
$.get(OC.generateUrl("/apps/files/api/v1/quickaccess/set/showList"), {show: show}, function (data, status) {
});
}
});
if ($menu.hasClass('collapsible') && $menu.data('expandedstate')) {
$menu.toggleClass('open');
var show = $menu.hasClass('open') ? 1 : 0;
var key = $menu.data('expandedstate');
$.post(OC.generateUrl("/apps/files/api/v1/toggleShowFolder/" + key), {show: show});
}
dotmenuToggles.forEach(function foundToggle (item) {
if (item[0] === ("#" + itemId)) {

View File

@ -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');
}
}
@ -102,7 +95,6 @@
*/
function addFavoriteToList (appfolder) {
var quickAccessList = 'sublist-favorites';
var collapsibleButtonId = 'button-collapse-favorites';
var listULElements = document.getElementById(quickAccessList);
if (!listULElements) {
return;
@ -110,13 +102,13 @@
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);
@ -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);
@ -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);
}

View File

@ -291,29 +291,28 @@ class ApiController extends Controller {
}
/**
* Toggle default for showing/hiding QuickAccess folder
* Toggle default for showing/hiding xxx folder
*
* @NoAdminRequired
*
* @param bool $show
* @param bool $show
* @param bool $key the key of the folder
*
* @return Response
*/
public function showQuickAccess($show) {
$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_Quick_Access', (int)$show);
return new Response();
}
/**
* Toggle default for showing/hiding QuickAccess folder
*
* @NoAdminRequired
*
* @return String
*/
public function getShowQuickAccess() {
return $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_Quick_Access', 0);
public function toggleShowFolder(int $show, string $key) {
// ensure the edited key exists
$navItems = \OCA\Files\App::getNavigationManager()->getAll();
foreach ($navItems as $item) {
// check if data is valid
if (($show === 0 || $show === 1) && isset($item['expandedState']) && $key === $item['expandedState']) {
$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', $key, (int)$show);
return new Response();
}
}
$response = new Response();
$response->setStatus(Http::STATUS_FORBIDDEN);
return $response;
}
/**

View File

@ -33,6 +33,8 @@ use OCP\AppFramework\Controller;
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;
@ -41,8 +43,6 @@ use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserSession;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use OCP\Files\Folder;
use OCP\App\IAppManager;
use Symfony\Component\EventDispatcher\GenericEvent;
/**
@ -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;
}
/**
@ -102,8 +102,8 @@ class ViewController extends Controller {
* @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 ?
@ -112,6 +112,7 @@ class ViewController extends Controller {
$content = ob_get_contents();
@ob_end_clean();
}
return $content;
}
@ -123,6 +124,7 @@ class ViewController extends Controller {
*/
protected function getStorageInfo() {
$dirInfo = \OC\Files\Filesystem::getFileInfo('/', false);
return \OC_Helper::getStorageInfo('/', $dirInfo);
}
@ -156,6 +158,7 @@ class ViewController extends Controller {
$user = $this->userSession->getUser()->getUID();
// Get all the user favorites to create a submenu
try {
$favElements = $this->activityHelper->getFavoriteFilePaths($this->userSession->getUser()->getUID());
} catch (\RuntimeException $e) {
@ -170,21 +173,21 @@ class ViewController extends Controller {
$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'
];
@ -192,28 +195,18 @@ class ViewController extends Controller {
$navBarPositionPosition++;
}
// show_Quick_Access stored as string
$defaultExpandedState = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_Quick_Access', '0') === '1';
\OCA\Files\App::getNavigationManager()->add(
[
'id' => 'favorites',
'appname' => 'files',
'script' => 'simplelist.php',
'classes' => $collapseClasses,
'order' => 5,
'name' => $this->l10n->t('Favorites'),
'sublist' => $favoritesSublistArray,
'defaultExpandedState' => $defaultExpandedState,
'enableMenuButton' => 0,
]
);
$navItems = \OCA\Files\App::getNavigationManager()->getAll();
usort($navItems, function ($item1, $item2) {
return $item1['order'] - $item2['order'];
});
// 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'])) {
$navItems[$key]['defaultExpandedState'] = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1';
}
}
$nav->assign('navigationItems', $navItems);
@ -235,29 +228,42 @@ class ViewController extends Controller {
if (isset($item['script'])) {
$content = $this->renderScript($item['appname'], $item['script']);
}
$contentItem = [];
$contentItem['id'] = $item['id'];
$contentItem['content'] = $content;
$contentItems[] = $contentItem;
// parse submenus
if (isset($item['sublist'])) {
foreach ($item['sublist'] as $subitem) {
$subcontent = '';
if (isset($subitem['script'])) {
$subcontent = $this->renderScript($subitem['appname'], $subitem['script']);
}
$contentItems[$subitem['id']] = [
'id' => $subitem['id'],
'content' => $subcontent
];
}
}
$contentItems[$item['id']] = [
'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,
@ -268,7 +274,6 @@ class ViewController extends Controller {
$policy->addAllowedFrameDomain('\'self\'');
$response->setContentSecurityPolicy($policy);
return $response;
}
@ -280,14 +285,14 @@ class ViewController extends Controller {
* @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';
}
@ -302,6 +307,7 @@ class ViewController extends Controller {
// and scroll to the entry
$params['scrollto'] = $file->getName();
}
return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params));
}
throw new \OCP\Files\NotFoundException();

View File

@ -66,21 +66,26 @@
function NavigationListElements($item, $l, $pinned) {
strpos($item['classes'], 'pinned') !== false ? $pinned++ : '';
?>
<li <?php if (isset($item['sublist'])){ ?>id="button-collapse-parent-<?php p($item['id']); ?>"<?php } ?>
data-id="<?php p($item['id']) ?>" data-dir="<?php p($item['dir']) ?>" data-view="<?php p($item['view']) ?>"
class="nav-<?php p($item['id']) ?> <?php p($item['classes']) ?> <?php p($pinned === 1 ? 'first-pinned' : '') ?> <?php if ($item['defaultExpandedState']) { ?> open<?php } ?>"
<li
data-id="<?php p($item['id']) ?>"
<?php if (isset($item['dir'])) { ?> data-dir="<?php p($item['dir']); ?>" <?php } ?>
<?php if (isset($item['view'])) { ?> data-view="<?php p($item['view']); ?>" <?php } ?>
<?php if (isset($item['expandedState'])) { ?> data-expandedstate="<?php p($item['expandedState']); ?>" <?php } ?>
class="nav-<?php p($item['id']) ?>
<?php if (isset($item['classes'])) { p($item['classes']); } ?>
<?php p($pinned === 1 ? 'first-pinned' : '') ?>
<?php if (isset($item['defaultExpandedState']) && $item['defaultExpandedState']) { ?> open<?php } ?>"
<?php if (isset($item['folderPosition'])) { ?> folderposition="<?php p($item['folderPosition']); ?>" <?php } ?>>
<a href="<?php p(isset($item['href']) ? $item['href'] : '#') ?>"
class="nav-icon-<?php p($item['icon'] !== '' ? $item['icon'] : $item['id']) ?> svg"><?php p($item['name']); ?></a>
class="nav-icon-<?php p(isset($item['icon']) && $item['icon'] !== '' ? $item['icon'] : $item['id']) ?> svg"><?php p($item['name']); ?></a>
<?php
NavigationElementMenu($item);
if (isset($item['sublist'])) {
?>
<button id="button-collapse-<?php p($item['id']); ?>"
class="collapse app-navigation-noclose" <?php if (sizeof($item['sublist']) == 0) { ?> style="display: none" <?php } ?>></button>
<button class="collapse app-navigation-noclose" <?php if (sizeof($item['sublist']) == 0) { ?> style="display: none" <?php } ?>></button>
<ul id="sublist-<?php p($item['id']); ?>">
<?php
foreach ($item['sublist'] as $item) {
@ -104,10 +109,10 @@ function NavigationListElements($item, $l, $pinned) {
* @return void
*/
function NavigationElementMenu($item) {
if ($item['menubuttons'] === 'true') {
if (isset($item['menubuttons']) && $item['menubuttons'] === 'true') {
?>
<div id="dotmenu-<?php p($item['id']); ?>"
class="app-navigation-entry-utils" <?php if ($item['enableMenuButton'] === 0) { ?> style="display: none"<?php } ?>>
class="app-navigation-entry-utils" <?php if (isset($item['enableMenuButton']) && $item['enableMenuButton'] === 0) { ?> style="display: none"<?php } ?>>
<ul>
<li class="app-navigation-entry-utils-menu-button svg">
<button id="dotmenu-button-<?php p($item['id']) ?>"></button>

View File

@ -145,7 +145,7 @@ class ViewControllerTest extends TestCase {
$nav->assign('total_space', '100 B');
//$nav->assign('webdavurl', '');
$nav->assign('navigationItems', [
[
'files' => [
'id' => 'files',
'appname' => 'files',
'script' => 'list.php',
@ -156,7 +156,7 @@ class ViewControllerTest extends TestCase {
'type' => 'link',
'classes' => '',
],
[
'recent' => [
'id' => 'recent',
'appname' => 'files',
'script' => 'recentlist.php',
@ -167,65 +167,21 @@ class ViewControllerTest extends TestCase {
'type' => 'link',
'classes' => '',
],
[
'favorites' => [
'id' => 'favorites',
'appname' => 'files',
'script' => 'simplelist.php',
'order' => 5,
'name' => null,
'name' => \OC::$server->getL10N('files')->t('Favorites'),
'active' => false,
'icon' => '',
'type' => 'link',
'classes' => '',
'sublist' => [],
'defaultExpandedState' => false,
'enableMenuButton' => 0,
'expandedState' => 'show_Quick_Access'
],
[
'id' => 'sharingin',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 15,
'name' => \OC::$server->getL10N('files_sharing')->t('Shared with you'),
'active' => false,
'icon' => '',
'type' => 'link',
'classes' => '',
],
[
'id' => 'sharingout',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 16,
'name' => \OC::$server->getL10N('files_sharing')->t('Shared with others'),
'active' => false,
'icon' => '',
'type' => 'link',
'classes' => '',
],
[
'id' => 'sharinglinks',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 17,
'name' => \OC::$server->getL10N('files_sharing')->t('Shared by link', []),
'active' => false,
'icon' => '',
'type' => 'link',
'classes' => '',
],
[
'id' => 'deletedshares',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 18,
'name' => \OC::$server->getL10N('files_sharing')->t('Deleted shares'),
'active' => false,
'icon' => '',
'type' => 'link',
'classes' => '',
],
[
'systemtagsfilter' => [
'id' => 'systemtagsfilter',
'appname' => 'systemtags',
'script' => 'list.php',
@ -236,7 +192,7 @@ class ViewControllerTest extends TestCase {
'type' => 'link',
'classes' => '',
],
[
'trashbin' => [
'id' => 'trashbin',
'appname' => 'files_trashbin',
'script' => 'list.php',
@ -264,39 +220,23 @@ class ViewControllerTest extends TestCase {
'allowShareWithLink' => 'yes',
'appNavigation' => $nav,
'appContents' => [
[
'files' => [
'id' => 'files',
'content' => null,
],
[
'recent' => [
'id' => 'recent',
'content' => null,
],
[
'favorites' => [
'id' => 'favorites',
'content' => null,
],
[
'id' => 'sharingin',
'content' => null,
],
[
'id' => 'sharingout',
'content' => null,
],
[
'id' => 'sharinglinks',
'content' => null,
],
[
'id' => 'deletedshares',
'content' => null,
],
[
'systemtagsfilter' => [
'id' => 'systemtagsfilter',
'content' => null,
],
[
'trashbin' => [
'id' => 'trashbin',
'content' => null,
],

View File

@ -50,54 +50,62 @@ $eventDispatcher->addListener(
$config = \OC::$server->getConfig();
$shareManager = \OC::$server->getShareManager();
$userSession = \OC::$server->getUserSession();
$l = \OC::$server->getL10N('files_sharing');
if ($config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes') {
\OCA\Files\App::getNavigationManager()->add(function () {
$l = \OC::$server->getL10N('files_sharing');
return [
'id' => 'sharingin',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 15,
'name' => $l->t('Shared with you'),
];
});
\OCA\Files\App::getNavigationManager()->add(function () {
$l = \OC::$server->getL10N('files_sharing');
return [
'id' => 'deletedshares',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 18,
'name' => $l->t('Deleted shares'),
];
});
$sharingSublistArray = [];
if (\OCP\Util::isSharingDisabledForUser() === false) {
\OCA\Files\App::getNavigationManager()->add(function () {
$l = \OC::$server->getL10N('files_sharing');
return [
'id' => 'sharingout',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 16,
'name' => $l->t('Shared with others'),
];
});
array_push($sharingSublistArray, [
'id' => 'sharingout',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 16,
'name' => $l->t('Shared with others'),
]);
}
array_push($sharingSublistArray, [
'id' => 'sharingin',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 15,
'name' => $l->t('Shared with you'),
]);
if (\OCP\Util::isSharingDisabledForUser() === false) {
// Check if sharing by link is enabled
if ($config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') {
\OCA\Files\App::getNavigationManager()->add(function () {
$l = \OC::$server->getL10N('files_sharing');
return [
'id' => 'sharinglinks',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 17,
'name' => $l->t('Shared by link'),
];
});
array_push($sharingSublistArray, [
'id' => 'sharinglinks',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 17,
'name' => $l->t('Shared by link'),
]);
}
}
array_push($sharingSublistArray, [
'id' => 'deletedshares',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 19,
'name' => $l->t('Deleted shares'),
]);
// show_Quick_Access stored as string
$defaultExpandedState = $config->getUserValue($userSession->getUser()->getUID(), 'files', 'show_sharing_menu', '0') === '1';
\OCA\Files\App::getNavigationManager()->add([
'id' => 'shareoverview',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 18,
'name' => $l->t('Shares'),
'classes' => 'collapsible',
'sublist' => $sharingSublistArray,
'expandedState' => 'show_sharing_menu'
]);
}

View File

@ -21,6 +21,7 @@ OCA.Sharing.App = {
_inFileList: null,
_outFileList: null,
_overviewFileList: null,
initSharingIn: function($el) {
if (this._inFileList) {
@ -116,6 +117,28 @@ OCA.Sharing.App = {
return this._deletedFileList;
},
initShareingOverview: function($el) {
if (this._overviewFileList) {
return this._overviewFileList;
}
this._overviewFileList = new OCA.Sharing.FileList(
$el,
{
id: 'shares.overview',
scrollContainer: $('#app-content'),
config: OCA.Files.App.getFilesConfig(),
isOverview: true
}
);
this._extendFileList(this._overviewFileList);
this._overviewFileList.appName = t('files_sharing', 'Shares');
this._overviewFileList.$el.find('#emptycontent').html('<div class="icon-share"></div>' +
'<h2>' + t('files_sharing', 'No shares') + '</h2>' +
'<p>' + t('files_sharing', 'Shares will show up here') + '</p>');
return this._overviewFileList;
},
removeSharingIn: function() {
if (this._inFileList) {
this._inFileList.$fileList.empty();
@ -140,6 +163,12 @@ OCA.Sharing.App = {
}
},
removeSharingOverview: function() {
if (this._overviewFileList) {
this._overviewFileList.$fileList.empty();
}
},
/**
* Destroy the app
*/
@ -152,6 +181,7 @@ OCA.Sharing.App = {
this._inFileList = null;
this._outFileList = null;
this._linkFileList = null;
this._overviewFileList = null;
delete this._globalActionsInitialized;
},
@ -252,4 +282,10 @@ $(document).ready(function() {
$('#app-content-deletedshares').on('hide', function() {
OCA.Sharing.App.removeSharingDeleted();
});
$('#app-content-shareoverview').on('show', function(e) {
OCA.Sharing.App.initShareingOverview($(e.target));
});
$('#app-content-shareoverview').on('hide', function() {
OCA.Sharing.App.removeSharingOverview();
});
});

View File

@ -40,6 +40,7 @@
_showDeleted: false,
_clientSideSort: true,
_allowSelection: false,
_isOverview: false,
/**
* @private
@ -60,6 +61,9 @@
if (options && options.showDeleted) {
this._showDeleted = true;
}
if (options && options.isOverview) {
this._isOverview = true;
}
},
_renderRow: function() {
@ -191,55 +195,62 @@
// there is only root
this._setCurrentDir('/', false);
if (this._showDeleted) {
var shares = $.ajax({
url: OC.linkToOCS('apps/files_sharing/api/v1', 2) + 'deletedshares',
/* jshint camelcase: false */
data: {
format: 'json',
include_tags: true
},
type: 'GET',
beforeSend: function(xhr) {
xhr.setRequestHeader('OCS-APIREQUEST', 'true');
},
});
} else {
var shares = $.ajax({
url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares',
/* jshint camelcase: false */
data: {
format: 'json',
shared_with_me: !!this._sharedWithUser,
include_tags: true
},
type: 'GET',
beforeSend: function(xhr) {
xhr.setRequestHeader('OCS-APIREQUEST', 'true');
},
});
}
var promises = [];
promises.push(shares);
if (!!this._sharedWithUser) {
var remoteShares = $.ajax({
url: OC.linkToOCS('apps/files_sharing/api/v1') + 'remote_shares',
/* jshint camelcase: false */
data: {
format: 'json',
include_tags: true
},
type: 'GET',
beforeSend: function(xhr) {
xhr.setRequestHeader('OCS-APIREQUEST', 'true');
},
});
promises.push(remoteShares);
var deletedShares = {
url: OC.linkToOCS('apps/files_sharing/api/v1', 2) + 'deletedshares',
/* jshint camelcase: false */
data: {
format: 'json',
include_tags: true
},
type: 'GET',
beforeSend: function (xhr) {
xhr.setRequestHeader('OCS-APIREQUEST', 'true');
},
};
var shares = {
url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares',
/* jshint camelcase: false */
data: {
format: 'json',
shared_with_me: this._sharedWithUser !== false,
include_tags: true
},
type: 'GET',
beforeSend: function (xhr) {
xhr.setRequestHeader('OCS-APIREQUEST', 'true');
},
};
var remoteShares = {
url: OC.linkToOCS('apps/files_sharing/api/v1') + 'remote_shares',
/* jshint camelcase: false */
data: {
format: 'json',
include_tags: true
},
type: 'GET',
beforeSend: function (xhr) {
xhr.setRequestHeader('OCS-APIREQUEST', 'true');
},
};
// Add the proper ajax requests to the list and run them
// and make sure we have 2 promises
if (this._showDeleted) {
promises.push($.ajax(deletedShares));
} else {
//Push empty promise so callback gets called the same way
promises.push($.Deferred().resolve());
promises.push($.ajax(shares));
if (this._sharedWithUser !== false || this._isOverview) {
promises.push($.ajax(remoteShares));
}
if (this._isOverview) {
shares.data.shared_with_me = !shares.data.shared_with_me
promises.push($.ajax(shares));
}
}
this._reloadCall = $.when.apply($, promises);
@ -247,7 +258,7 @@
return this._reloadCall.then(callBack, callBack);
},
reloadCallback: function(shares, remoteShares) {
reloadCallback: function(shares, remoteShares, additionnalShares) {
delete this._reloadCall;
this.hideMask();
@ -257,14 +268,30 @@
var files = [];
if (shares[0].ocs && shares[0].ocs.data) {
files = files.concat(this._makeFilesFromShares(shares[0].ocs.data));
// make sure to use the same format
if (shares[0] && shares[0].ocs) {
shares = shares[0];
}
if (remoteShares && remoteShares[0] && remoteShares[0].ocs) {
remoteShares = remoteShares[0];
}
if (additionnalShares && additionnalShares[0] && additionnalShares[0].ocs) {
additionnalShares = additionnalShares[0];
}
if (remoteShares && remoteShares[0].ocs && remoteShares[0].ocs.data) {
files = files.concat(this._makeFilesFromRemoteShares(remoteShares[0].ocs.data));
if (shares.ocs && shares.ocs.data) {
files = files.concat(this._makeFilesFromShares(shares.ocs.data, this._sharedWithUser));
}
if (remoteShares && remoteShares.ocs && remoteShares.ocs.data) {
files = files.concat(this._makeFilesFromRemoteShares(remoteShares.ocs.data));
}
if (additionnalShares && additionnalShares && additionnalShares.ocs && additionnalShares.ocs.data) {
files = files.concat(this._makeFilesFromShares(additionnalShares.ocs.data, !this._sharedWithUser));
}
this.setFiles(files);
return true;
},
@ -303,7 +330,7 @@
* @param {Array} data OCS API share array
* @return {Array.<OCA.Sharing.SharedFileInfo>} array of shared file info
*/
_makeFilesFromShares: function(data) {
_makeFilesFromShares: function(data, sharedWithUser) {
/* jshint camelcase: false */
var self = this;
var files = data;
@ -339,7 +366,7 @@
stime: share.stime * 1000,
expiration: share.expiration,
};
if (self._sharedWithUser) {
if (sharedWithUser) {
file.shareOwner = share.displayname_owner;
file.shareOwnerId = share.uid_owner;
file.name = OC.basename(share.file_target);

View File

@ -100,7 +100,7 @@ class NavigationManager implements INavigationManager {
if(!isset($entry['type'])) {
$entry['type'] = 'link';
}
$this->entries[] = $entry;
$this->entries[$entry['id']] = $entry;
}
/**
@ -133,7 +133,7 @@ class NavigationManager implements INavigationManager {
* @return array
*/
private function proceedNavigation(array $list): array {
usort($list, function($a, $b) {
uasort($list, function($a, $b) {
if (isset($a['order']) && isset($b['order'])) {
return ($a['order'] < $b['order']) ? -1 : 1;
} else if (isset($a['order']) || isset($b['order'])) {

View File

@ -12,10 +12,6 @@
namespace Test;
use OC\App\AppManager;
use OC\Group\Manager;
use OC\NavigationManager;
use OC\SubAdmin;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
@ -23,6 +19,10 @@ use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OC\App\AppManager;
use OC\Group\Manager;
use OC\NavigationManager;
use OC\SubAdmin;
class NavigationManagerTest extends TestCase {
/** @var AppManager|\PHPUnit_Framework_MockObject_MockObject */
@ -44,12 +44,12 @@ class NavigationManagerTest extends TestCase {
protected function setUp() {
parent::setUp();
$this->appManager = $this->createMock(AppManager::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->l10nFac = $this->createMock(IFactory::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->groupManager = $this->createMock(Manager::class);
$this->config = $this->createMock(IConfig::class);
$this->appManager = $this->createMock(AppManager::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->l10nFac = $this->createMock(IFactory::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->groupManager = $this->createMock(Manager::class);
$this->config = $this->createMock(IConfig::class);
$this->navigationManager = new NavigationManager(
$this->appManager,
$this->urlGenerator,
@ -65,46 +65,46 @@ class NavigationManagerTest extends TestCase {
public function addArrayData() {
return [
[
[
'id' => 'entry id',
'name' => 'link text',
'order' => 1,
'icon' => 'optional',
'href' => 'url',
'type' => 'settings',
'classes' => '',
],
[
'id' => 'entry id',
'name' => 'link text',
'order' => 1,
'icon' => 'optional',
'href' => 'url',
'active' => false,
'type' => 'settings',
'classes' => '',
'entry id' => [
'id' => 'entry id',
'name' => 'link text',
'order' => 1,
'icon' => 'optional',
'href' => 'url',
'type' => 'settings',
'classes' => ''
],
'entry id2' => [
'id' => 'entry id',
'name' => 'link text',
'order' => 1,
'icon' => 'optional',
'href' => 'url',
'active' => false,
'type' => 'settings',
'classes' => ''
]
],
[
[
'id' => 'entry id',
'name' => 'link text',
'order' => 1,
'entry id' => [
'id' => 'entry id',
'name' => 'link text',
'order' => 1,
//'icon' => 'optional',
'href' => 'url',
'active' => true,
'href' => 'url',
'active' => true
],
[
'id' => 'entry id',
'name' => 'link text',
'order' => 1,
'icon' => '',
'href' => 'url',
'active' => false,
'type' => 'link',
'classes' => '',
],
],
'entry id2' => [
'id' => 'entry id',
'name' => 'link text',
'order' => 1,
'icon' => '',
'href' => 'url',
'active' => false,
'type' => 'link',
'classes' => ''
]
]
];
}
@ -120,7 +120,7 @@ class NavigationManagerTest extends TestCase {
$navigationEntries = $this->navigationManager->getAll('all');
$this->assertCount(1, $navigationEntries, 'Expected that 1 navigation entry exists');
$this->assertEquals($expectedEntry, $navigationEntries[0]);
$this->assertEquals($expectedEntry, $navigationEntries['entry id']);
$this->navigationManager->clear(false);
$this->assertEmpty($this->navigationManager->getAll('all'), 'Expected no navigation entry exists after clear()');
@ -148,12 +148,12 @@ class NavigationManagerTest extends TestCase {
$navigationEntries = $this->navigationManager->getAll('all');
$this->assertEquals(1, $testAddClosureNumberOfCalls, 'Expected that the closure is called by getAll()');
$this->assertCount(1, $navigationEntries, 'Expected that 1 navigation entry exists');
$this->assertEquals($expectedEntry, $navigationEntries[0]);
$this->assertEquals($expectedEntry, $navigationEntries['entry id']);
$navigationEntries = $this->navigationManager->getAll('all');
$this->assertEquals(1, $testAddClosureNumberOfCalls, 'Expected that the closure is only called once for getAll()');
$this->assertCount(1, $navigationEntries, 'Expected that 1 navigation entry exists');
$this->assertEquals($expectedEntry, $navigationEntries[0]);
$this->assertEquals($expectedEntry, $navigationEntries['entry id']);
$this->navigationManager->clear(false);
$this->assertEmpty($this->navigationManager->getAll('all'), 'Expected no navigation entry exists after clear()');
@ -161,11 +161,11 @@ class NavigationManagerTest extends TestCase {
public function testAddArrayClearGetAll() {
$entry = [
'id' => 'entry id',
'name' => 'link text',
'order' => 1,
'icon' => 'optional',
'href' => 'url',
'id' => 'entry id',
'name' => 'link text',
'order' => 1,
'icon' => 'optional',
'href' => 'url'
];
$this->assertEmpty($this->navigationManager->getAll(), 'Expected no navigation entry exists');
@ -178,11 +178,11 @@ class NavigationManagerTest extends TestCase {
$this->assertEmpty($this->navigationManager->getAll(), 'Expected no navigation entry exists');
$entry = [
'id' => 'entry id',
'name' => 'link text',
'order' => 1,
'icon' => 'optional',
'href' => 'url',
'id' => 'entry id',
'name' => 'link text',
'order' => 1,
'icon' => 'optional',
'href' => 'url'
];
global $testAddClosureNumberOfCalls;
@ -208,36 +208,36 @@ class NavigationManagerTest extends TestCase {
public function testWithAppManager($expected, $navigation, $isAdmin = false) {
$l = $this->createMock(IL10N::class);
$l->expects($this->any())->method('t')->willReturnCallback(function($text, $parameters = []) {
$l->expects($this->any())->method('t')->willReturnCallback(function ($text, $parameters = []) {
return vsprintf($text, $parameters);
});
$this->appManager->expects($this->once())->method('getAppInfo')->with('test')->willReturn($navigation);
$this->l10nFac->expects($this->any())->method('get')->willReturn($l);
$this->urlGenerator->expects($this->any())->method('imagePath')->willReturnCallback(function($appName, $file) {
$this->urlGenerator->expects($this->any())->method('imagePath')->willReturnCallback(function ($appName, $file) {
return "/apps/$appName/img/$file";
});
$this->urlGenerator->expects($this->any())->method('linkToRoute')->willReturnCallback(function() {
return "/apps/test/";
$this->urlGenerator->expects($this->any())->method('linkToRoute')->willReturnCallback(function () {
return '/apps/test/';
});
$this->urlGenerator
->expects($this->once())
->method('linkToRouteAbsolute')
->with(
'core.login.logout',
[
'requesttoken' => \OCP\Util::callRegister(),
]
)
->willReturn('https://example.com/logout');
->expects($this->once())
->method('linkToRouteAbsolute')
->with(
'core.login.logout',
[
'requesttoken' => \OCP\Util::callRegister()
]
)
->willReturn('https://example.com/logout');
$user = $this->createMock(IUser::class);
$user->expects($this->any())->method('getUID')->willReturn('user001');
$this->userSession->expects($this->any())->method('getUser')->willReturn($user);
$this->userSession->expects($this->any())->method('isLoggedIn')->willReturn(true);
$this->appManager->expects($this->once())
->method('getEnabledAppsForUser')
->with($user)
->willReturn(['test']);
->method('getEnabledAppsForUser')
->with($user)
->willReturn(['test']);
$this->groupManager->expects($this->any())->method('isAdmin')->willReturn($isAdmin);
$subadmin = $this->createMock(SubAdmin::class);
$subadmin->expects($this->any())->method('isSubAdmin')->with($user)->willReturn(false);
@ -250,72 +250,119 @@ class NavigationManagerTest extends TestCase {
public function providesNavigationConfig() {
$apps = [
[
'id' => 'core_apps',
'order' => 3,
'href' => '/apps/test/',
'icon' => '/apps/settings/img/apps.svg',
'name' => 'Apps',
'active' => false,
'type' => 'settings',
'classes' => '',
'core_apps' => [
'id' => 'core_apps',
'order' => 3,
'href' => '/apps/test/',
'icon' => '/apps/settings/img/apps.svg',
'name' => 'Apps',
'active' => false,
'type' => 'settings',
'classes' => ''
]
];
$defaults = [
[
'id' => 'settings',
'order' => 1,
'href' => '/apps/test/',
'icon' => '/apps/settings/img/admin.svg',
'name' => 'Settings',
'active' => false,
'type' => 'settings',
'classes' => '',
],
[
'id' => 'logout',
'order' => 99999,
'href' => 'https://example.com/logout',
'icon' => '/apps/core/img/actions/logout.svg',
'name' => 'Log out',
'active' => false,
'type' => 'settings',
'classes' => '',
'settings' => [
'id' => 'settings',
'order' => 1,
'href' => '/apps/test/',
'icon' => '/apps/settings/img/admin.svg',
'name' => 'Settings',
'active' => false,
'type' => 'settings',
'classes' => ''
],
'logout' => [
'id' => 'logout',
'order' => 99999,
'href' => 'https://example.com/logout',
'icon' => '/apps/core/img/actions/logout.svg',
'name' => 'Log out',
'active' => false,
'type' => 'settings',
'classes' => ''
]
];
return [
'minimalistic' => [array_merge([$defaults[0]], [[
'id' => 'test',
'order' => 100,
'href' => '/apps/test/',
'icon' => '/apps/test/img/app.svg',
'name' => 'Test',
'active' => false,
'type' => 'link',
'classes' => '',
]], [$defaults[1]]), ['navigations' => [['route' => 'test.page.index', 'name' => 'Test']]]],
'minimalistic-settings' => [array_merge([$defaults[0]], [[
'id' => 'test',
'order' => 100,
'href' => '/apps/test/',
'icon' => '/apps/test/img/app.svg',
'name' => 'Test',
'active' => false,
'type' => 'settings',
'classes' => '',
]], [$defaults[1]]), ['navigations' => [['route' => 'test.page.index', 'name' => 'Test', 'type' => 'settings']]]],
'admin' => [array_merge([$defaults[0]], $apps, [[
'id' => 'test',
'order' => 100,
'href' => '/apps/test/',
'icon' => '/apps/test/img/app.svg',
'name' => 'Test',
'active' => false,
'type' => 'link',
'classes' => '',
]], [$defaults[1]]), ['navigations' => [['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index', 'name' => 'Test']]], true],
'no name' => [array_merge([$defaults[0]], $apps, [$defaults[1]]), ['navigations' => [['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index']]], true],
'no admin' => [$defaults, ['navigations' => [['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index', 'name' => 'Test']]]]
'minimalistic' => [
array_merge(
['settings' => $defaults['settings']],
['test' => [
'id' => 'test',
'order' => 100,
'href' => '/apps/test/',
'icon' => '/apps/test/img/app.svg',
'name' => 'Test',
'active' => false,
'type' => 'link',
'classes' => ''
]],
['logout' => $defaults['logout']]
),
['navigations' => [
['route' => 'test.page.index', 'name' => 'Test']
]]
],
'minimalistic-settings' => [
array_merge(
['settings' => $defaults['settings']],
['test' => [
'id' => 'test',
'order' => 100,
'href' => '/apps/test/',
'icon' => '/apps/test/img/app.svg',
'name' => 'Test',
'active' => false,
'type' => 'settings',
'classes' => ''
]],
['logout' => $defaults['logout']]
),
['navigations' => [
['route' => 'test.page.index', 'name' => 'Test', 'type' => 'settings']
]
]],
'admin' => [
array_merge(
['settings' => $defaults['settings']],
$apps,
['test' => [
'id' => 'test',
'order' => 100,
'href' => '/apps/test/',
'icon' => '/apps/test/img/app.svg',
'name' => 'Test',
'active' => false,
'type' => 'link',
'classes' => ''
]],
['logout' => $defaults['logout']]
),
['navigations' => [
['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index', 'name' => 'Test']
]],
true
],
'no name' => [
array_merge(
['settings' => $defaults['settings']],
$apps,
['logout' => $defaults['logout']]
),
['navigations' => [
['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index']
]],
true
],
'no admin' => [
$defaults,
['navigations' => [[
'@attributes' => ['role' => 'admin'],
'route' => 'test.page.index',
'name' => 'Test'
]]]
]
];
}
}