Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permalinks #24434

Merged
merged 5 commits into from
May 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions apps/files/appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use OCP\AppFramework\App;
use \OCA\Files\Service\TagService;
use \OCP\IContainer;
use OCA\Files\Controller\ViewController;

class Application extends App {
public function __construct(array $urlParams=array()) {
Expand All @@ -48,6 +49,20 @@ public function __construct(array $urlParams=array()) {
);
});

$container->registerService('ViewController', function (IContainer $c) use ($server) {
return new ViewController(
$c->query('AppName'),
$c->query('Request'),
$server->getURLGenerator(),
$server->getNavigationManager(),
$c->query('L10N'),
$server->getConfig(),
$server->getEventDispatcher(),
$server->getUserSession(),
$server->getUserFolder()
);
});

/**
* Core
*/
Expand Down
48 changes: 46 additions & 2 deletions apps/files/controller/viewcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* @author Christoph Wurst <[email protected]>
* @author Lukas Reschke <[email protected]>
* @author Thomas Müller <[email protected]>
* @author Vincent Petry <[email protected]>
*
* @copyright Copyright (c) 2016, ownCloud, Inc.
* @license AGPL-3.0
Expand All @@ -26,6 +27,7 @@
use OC\AppFramework\Http\Request;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
Expand All @@ -35,6 +37,8 @@
use OCP\IURLGenerator;
use OCP\IUserSession;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use OCP\AppFramework\Http\NotFoundResponse;
use OCP\Files\Folder;

/**
* Class ViewController
Expand All @@ -58,6 +62,8 @@ class ViewController extends Controller {
protected $eventDispatcher;
/** @var IUserSession */
protected $userSession;
/** @var \OCP\Files\Folder */
protected $userFolder;

/**
* @param string $appName
Expand All @@ -68,6 +74,7 @@ class ViewController extends Controller {
* @param IConfig $config
* @param EventDispatcherInterface $eventDispatcherInterface
* @param IUserSession $userSession
* @param Folder $userFolder
*/
public function __construct($appName,
IRequest $request,
Expand All @@ -76,7 +83,9 @@ public function __construct($appName,
IL10N $l10n,
IConfig $config,
EventDispatcherInterface $eventDispatcherInterface,
IUserSession $userSession) {
IUserSession $userSession,
Folder $userFolder
) {
parent::__construct($appName, $request);
$this->appName = $appName;
$this->request = $request;
Expand All @@ -86,6 +95,7 @@ public function __construct($appName,
$this->config = $config;
$this->eventDispatcher = $eventDispatcherInterface;
$this->userSession = $userSession;
$this->userFolder = $userFolder;
}

/**
Expand Down Expand Up @@ -124,10 +134,15 @@ protected function getStorageInfo() {
*
* @param string $dir
* @param string $view
* @param string $fileid
* @return TemplateResponse
* @throws \OCP\Files\NotFoundException
*/
public function index($dir = '', $view = '') {
public function index($dir = '', $view = '', $fileid = null) {
if ($fileid !== null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So fileid always has preference if it is there. Sounds good

return $this->showFile($fileid);
}

$nav = new \OCP\Template('files', 'appnavigation', '');

// Load the files we need
Expand Down Expand Up @@ -239,4 +254,33 @@ public function index($dir = '', $view = '') {

return $response;
}

/**
* Redirects to the file list and highlight the given file id
*
* @param string $fileId file id to show
* @return Response redirect response or not found response
*
* @NoCSRFRequired
* @NoAdminRequired
*/
public function showFile($fileId) {
$files = $this->userFolder->getById($fileId);
$params = [];

if (!empty($files)) {
$file = current($files);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking... maybe it is good to loop over all files (if a file is shared via multiple ways)... and pick the one with the highest permission?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course harder then it sounds because which do you pick if 1 has edit and 1 has share permissions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also not that common scenario...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rullzer yeah good point, possibly something for later.

Also I thought about adding a "trashbin" route in case the file is detected in trash instead, but something for later also.

if ($file instanceof Folder) {
// set the full path to enter the folder
$params['dir'] = $this->userFolder->getRelativePath($file->getPath());
} else {
// set parent path as dir
$params['dir'] = $this->userFolder->getRelativePath($file->getParent()->getPath());
// and scroll to the entry
$params['scrollto'] = $file->getName();
}
return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params));
}
return new NotFoundResponse();
}
}
13 changes: 13 additions & 0 deletions apps/files/css/detailsView.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@
width: 100%;
}

#app-sidebar .mainFileInfoView .icon {
display: inline-block;
}

#app-sidebar .mainFileInfoView .permalink {
margin-left: 10px;
opacity: .5;
}
#app-sidebar .mainFileInfoView .permalink-field>input {
clear: both;
width: 90%;
}

#app-sidebar .file-details-container {
display: inline-block;
float: left;
Expand Down
37 changes: 34 additions & 3 deletions apps/files/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@

// detect when app changed their current directory
$('#app-content').delegate('>div', 'changeDirectory', _.bind(this._onDirectoryChanged, this));
$('#app-content').delegate('>div', 'afterChangeDirectory', _.bind(this._onAfterDirectoryChanged, this));
$('#app-content').delegate('>div', 'changeViewerMode', _.bind(this._onChangeViewerMode, this));

$('#app-navigation').on('itemChanged', _.bind(this._onNavigationChanged, this));
Expand Down Expand Up @@ -224,7 +225,16 @@
*/
_onDirectoryChanged: function(e) {
if (e.dir) {
this._changeUrl(this.navigation.getActiveItem(), e.dir);
this._changeUrl(this.navigation.getActiveItem(), e.dir, e.fileId);
}
},

/**
* Event handler for when an app notified that its directory changed
*/
_onAfterDirectoryChanged: function(e) {
if (e.dir && e.fileId) {
this._changeUrl(this.navigation.getActiveItem(), e.dir, e.fileId);
}
},

Expand Down Expand Up @@ -260,15 +270,36 @@
this.navigation.getActiveContainer().trigger(new $.Event('urlChanged', params));
},

/**
* Encode URL params into a string, except for the "dir" attribute
* that gets encoded as path where "/" is not encoded
*
* @param {Object.<string>} params
* @return {string} encoded params
*/
_makeUrlParams: function(params) {
var dir = params.dir;
delete params.dir;
return 'dir=' + OC.encodePath(dir) + '&' + OC.buildQueryString(params);
},

/**
* Change the URL to point to the given dir and view
*/
_changeUrl: function(view, dir) {
_changeUrl: function(view, dir, fileId) {
var params = {dir: dir};
if (view !== 'files') {
params.view = view;
} else if (fileId) {
params.fileid = fileId;
}
var currentParams = OC.Util.History.parseUrlQuery();
if (currentParams.dir === params.dir && currentParams.view === params.view && currentParams.fileid !== params.fileid) {
// if only fileid changed or was added, replace instead of push
OC.Util.History.replaceState(this._makeUrlParams(params));
} else {
OC.Util.History.pushState(this._makeUrlParams(params));
}
OC.Util.History.pushState(params);
}
};
})();
Expand Down
2 changes: 1 addition & 1 deletion apps/files/js/fileactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@

this.register('dir', 'Open', OC.PERMISSION_READ, '', function (filename, context) {
var dir = context.$file.attr('data-path') || context.fileList.getCurrentDirectory();
context.fileList.changeDirectory(OC.joinPaths(dir, filename));
context.fileList.changeDirectory(OC.joinPaths(dir, filename), true, false, parseInt(context.$file.attr('data-id'), 10));
});

this.registerAction({
Expand Down
36 changes: 27 additions & 9 deletions apps/files/js/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -1362,19 +1362,20 @@
return parseInt(this.$el.find('#permissions').val(), 10);
},
/**
* @brief Changes the current directory and reload the file list.
* @param targetDir target directory (non URL encoded)
* @param changeUrl false if the URL must not be changed (defaults to true)
* @param {boolean} force set to true to force changing directory
* Changes the current directory and reload the file list.
* @param {string} targetDir target directory (non URL encoded)
* @param {boolean} [changeUrl=true] if the URL must not be changed (defaults to true)
* @param {boolean} [force=false] set to true to force changing directory
* @param {string} [fileId] optional file id, if known, to be appended in the URL
*/
changeDirectory: function(targetDir, changeUrl, force) {
changeDirectory: function(targetDir, changeUrl, force, fileId) {
var self = this;
var currentDir = this.getCurrentDirectory();
targetDir = targetDir || '/';
if (!force && currentDir === targetDir) {
return;
}
this._setCurrentDir(targetDir, changeUrl);
this._setCurrentDir(targetDir, changeUrl, fileId);
this.reload().then(function(success){
if (!success) {
self.changeDirectory(currentDir, true);
Expand All @@ -1389,8 +1390,9 @@
* Sets the current directory name and updates the breadcrumb.
* @param targetDir directory to display
* @param changeUrl true to also update the URL, false otherwise (default)
* @param {string} [fileId] file id
*/
_setCurrentDir: function(targetDir, changeUrl) {
_setCurrentDir: function(targetDir, changeUrl, fileId) {
targetDir = targetDir.replace(/\\/g, '/');
var previousDir = this.getCurrentDirectory(),
baseDir = OC.basename(targetDir);
Expand All @@ -1408,10 +1410,14 @@
this.$el.find('#dir').val(targetDir);

if (changeUrl !== false) {
this.$el.trigger(jQuery.Event('changeDirectory', {
var params = {
dir: targetDir,
previousDir: previousDir
}));
};
if (fileId) {
params.fileId = fileId;
}
this.$el.trigger(jQuery.Event('changeDirectory', params));
}
this.breadcrumb.setDirectory(this.getCurrentDirectory());
},
Expand Down Expand Up @@ -1557,6 +1563,18 @@

result.sort(this._sortComparator);
this.setFiles(result);

if (this.dirInfo) {
var newFileId = this.dirInfo.id;
// update fileid in URL
var params = {
dir: this.getCurrentDirectory()
};
if (newFileId) {
params.fileId = newFileId;
}
this.$el.trigger(jQuery.Event('afterChangeDirectory', params));
}
return true;
},

Expand Down
38 changes: 35 additions & 3 deletions apps/files/js/mainfileinfodetailview.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,23 @@
var TEMPLATE =
'<div class="thumbnailContainer"><a href="#" class="thumbnail action-default"><div class="stretcher"/></a></div>' +
'<div class="file-details-container">' +
'<div class="fileName"><h3 title="{{name}}" class="ellipsis">{{name}}</h3></div>' +
'<div class="fileName">' +
'<h3 title="{{name}}" class="ellipsis">{{name}}</h3>' +
'<a class="permalink" href="{{permalink}}" title="{{permalinkTitle}}">' +
'<span class="icon icon-public"></span>' +
'<span class="hidden-visually">{{permalinkTitle}}</span>' +
'</a>' +
'</div>' +
' <div class="file-details ellipsis">' +
' <a href="#" ' +
' class="action action-favorite favorite">' +
' <img class="svg" alt="{{starAltText}}" src="{{starIcon}}" />' +
' </a>' +
' {{#if hasSize}}<span class="size" title="{{altSize}}">{{size}}</span>, {{/if}}<span class="date" title="{{altDate}}">{{date}}</span>' +
' </div>' +
'</div>' +
'<div class="hidden permalink-field">' +
'<input type="text" value="{{permalink}}" placeholder="{{permalinkTitle}}" readonly="readonly"/>' +
'</div>';

/**
Expand Down Expand Up @@ -50,7 +59,9 @@

events: {
'click a.action-favorite': '_onClickFavorite',
'click a.action-default': '_onClickDefaultAction'
'click a.action-default': '_onClickDefaultAction',
'click a.permalink': '_onClickPermalink',
'focus .permalink-field>input': '_onFocusPermalink'
},

template: function(data) {
Expand All @@ -72,6 +83,20 @@
}
},

_onClickPermalink: function() {
var $row = this.$('.permalink-field');
$row.toggleClass('hidden');
if (!$row.hasClass('hidden')) {
$row.find('>input').focus();
}
// cancel click, user must right-click + copy or middle click
return false;
},

_onFocusPermalink: function() {
this.$('.permalink-field>input').select();
},

_onClickFavorite: function(event) {
event.preventDefault();
this._fileActions.triggerAction('Favorite', this.model, this._fileList);
Expand All @@ -87,6 +112,11 @@
this.render();
},

_makePermalink: function(fileId) {
var baseUrl = OC.getProtocol() + '://' + OC.getHost();
return baseUrl + OC.generateUrl('/f/{fileId}', {fileId: fileId});
},

setFileInfo: function(fileInfo) {
if (this.model) {
this.model.off('change', this._onModelChanged, this);
Expand Down Expand Up @@ -118,7 +148,9 @@
altDate: OC.Util.formatDate(this.model.get('mtime')),
date: OC.Util.relativeModifiedDate(this.model.get('mtime')),
starAltText: isFavorite ? t('files', 'Favorited') : t('files', 'Favorite'),
starIcon: OC.imagePath('core', isFavorite ? 'actions/starred' : 'actions/star')
starIcon: OC.imagePath('core', isFavorite ? 'actions/starred' : 'actions/star'),
permalink: this._makePermalink(this.model.get('id')),
permalinkTitle: t('files', 'Local link')
}));

// TODO: we really need OC.Previews
Expand Down
Loading