Skip to content

Commit

Permalink
Merge pull request #12360 from owncloud/files-tags
Browse files Browse the repository at this point in the history
Add favorites to files app
  • Loading branch information
LukasReschke committed Dec 15, 2014
2 parents 76357af + 207d77e commit be3d4fd
Show file tree
Hide file tree
Showing 20 changed files with 1,209 additions and 10 deletions.
40 changes: 38 additions & 2 deletions apps/files/appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use OC\AppFramework\Utility\SimpleContainer;
use OCA\Files\Controller\ApiController;
use OCP\AppFramework\App;
use \OCA\Files\Service\TagService;
use \OCP\IContainer;

class Application extends App {
public function __construct(array $urlParams=array()) {
Expand All @@ -21,10 +23,44 @@ public function __construct(array $urlParams=array()) {
/**
* Controllers
*/
$container->registerService('APIController', function (SimpleContainer $c) {
$container->registerService('APIController', function (IContainer $c) {
return new ApiController(
$c->query('AppName'),
$c->query('Request')
$c->query('Request'),
$c->query('TagService')
);
});

/**
* Core
*/
$container->registerService('L10N', function(IContainer $c) {
return $c->query('ServerContainer')->getL10N($c->query('AppName'));
});

/**
* Services
*/
$container->registerService('Tagger', function(IContainer $c) {
return $c->query('ServerContainer')->getTagManager()->load('files');
});
$container->registerService('TagService', function(IContainer $c) {
$homeFolder = $c->query('ServerContainer')->getUserFolder();
return new TagService(
$c->query('ServerContainer')->getUserSession(),
$c->query('Tagger'),
$homeFolder
);
});

/**
* Controllers
*/
$container->registerService('APIController', function (IContainer $c) {
return new ApiController(
$c->query('AppName'),
$c->query('Request'),
$c->query('TagService')
);
});
}
Expand Down
29 changes: 25 additions & 4 deletions apps/files/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,31 @@
namespace OCA\Files\Appinfo;

$application = new Application();
$application->registerRoutes($this, array('routes' => array(
array('name' => 'API#getThumbnail', 'url' => '/api/v1/thumbnail/{x}/{y}/{file}', 'verb' => 'GET', 'requirements' => array('file' => '.+')),
)));

$application->registerRoutes(
$this,
array(
'routes' => array(
array(
'name' => 'API#getThumbnail',
'url' => '/api/v1/thumbnail/{x}/{y}/{file}',
'verb' => 'GET',
'requirements' => array('file' => '.+')
),
array(
'name' => 'API#updateFileTags',
'url' => '/api/v1/files/{path}',
'verb' => 'POST',
'requirements' => array('path' => '.+'),
),
array(
'name' => 'API#getFilesByTag',
'url' => '/api/v1/tags/{tagName}/files',
'verb' => 'GET',
'requirements' => array('tagName' => '.+'),
),
)
)
);

/** @var $this \OC\Route\Router */

Expand Down
56 changes: 55 additions & 1 deletion apps/files/controller/apicontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@
use OCP\AppFramework\Controller;
use OCP\IRequest;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\DownloadResponse;
use OC\Preview;
use OCA\Files\Service\TagService;

class ApiController extends Controller {

public function __construct($appName, IRequest $request){
/**
* @var TagService $tagService
*/
private $tagService;

public function __construct($appName, IRequest $request, TagService $tagService){
parent::__construct($appName, $request);
$this->tagService = $tagService;
}


Expand Down Expand Up @@ -49,4 +57,50 @@ public function getThumbnail($x, $y, $file) {
}
}

/**
* Updates the info of the specified file path
* The passed tags are absolute, which means they will
* replace the actual tag selection.
*
* @NoAdminRequired
* @CORS
*
* @param string $path path
* @param array $tags array of tags
*/
public function updateFileTags($path, $tags = null) {
$result = array();
// if tags specified or empty array, update tags
if (!is_null($tags)) {
try {
$this->tagService->updateFileTags($path, $tags);
} catch (\OCP\Files\NotFoundException $e) {
return new DataResponse($e->getMessage(), Http::STATUS_NOT_FOUND);
}
$result['tags'] = $tags;
}
return new DataResponse($result, Http::STATUS_OK);
}

/**
* Returns a list of all files tagged with the given tag.
*
* @NoAdminRequired
* @CORS
*
* @param array $tagName tag name to filter by
*/
public function getFilesByTag($tagName) {
$files = array();
$fileInfos = $this->tagService->getFilesByTag($tagName);
foreach ($fileInfos as &$fileInfo) {
$file = \OCA\Files\Helper::formatFileInfo($fileInfo);
$parts = explode('/', dirname($fileInfo->getPath()), 4);
$file['path'] = '/' . $parts[3];
$file['tags'] = array($tagName);
$files[] = $file;
}
return new DataResponse(array('files' => $files), Http::STATUS_OK);
}

}
26 changes: 25 additions & 1 deletion apps/files/css/files.css
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,15 @@ table th#headerName {
width: 9999px; /* not really sure why this works better than 100% … table styling */
padding: 0;
}

#headerName-container {
position: relative;
height: 50px;
}
.has-favorites #headerName-container {
padding-left: 50px;
}

table th#headerSize, table td.filesize {
text-align: right;
}
Expand Down Expand Up @@ -286,6 +291,10 @@ table td.filename .nametext {
max-width: 800px;
height: 100%;
}
.has-favorites #fileList td.filename a.name {
left: 50px;
margin-right: 50px;
}

table td.filename .nametext .innernametext {
text-overflow: ellipsis;
Expand Down Expand Up @@ -403,6 +412,9 @@ table td.filename .uploadtext {
left: 18px;
z-index: 10;
}
.has-favorites .select-all {
left: 68px;
}

#fileList tr td.filename {
position: relative;
Expand All @@ -417,6 +429,18 @@ table td.filename .uploadtext {
height: 50px;
}

#fileList tr td.filename .favorite {
display: inline-block;
float: left;
}
#fileList tr td.filename .action-favorite {
display: block;
float: left;
width: 30px;
line-height: 100%;
text-align: center;
}

#uploadsize-message,#delete-confirm { display:none; }

/* File actions */
Expand All @@ -442,7 +466,7 @@ table td.filename .uploadtext {
padding: 17px 14px;
}

#fileList .action.action-share-notification span, #fileList a {
#fileList .action.action-share-notification span, #fileList a.name {
cursor: default !important;
}

Expand Down
19 changes: 19 additions & 0 deletions apps/files/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
use OCA\Files\Appinfo\Application;

// Check if we are a user
OCP\User::checkLoggedIn();
Expand All @@ -38,8 +39,16 @@
OCP\Util::addscript('files', 'breadcrumb');
OCP\Util::addscript('files', 'filelist');

\OCP\Util::addScript('files', 'favoritesfilelist');
\OCP\Util::addScript('files', 'tagsplugin');
\OCP\Util::addScript('files', 'favoritesplugin');

\OC_Util::addVendorScript('core', 'handlebars/handlebars');

OCP\App::setActiveNavigationEntry('files_index');

$l = \OC::$server->getL10N('files');

$isIE8 = false;
preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches);
if (count($matches) > 0 && $matches[1] <= 9) {
Expand Down Expand Up @@ -79,6 +88,16 @@ function sortNavigationItems($item1, $item2) {
return $item1['order'] - $item2['order'];
}

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

$navItems = \OCA\Files\App::getNavigationManager()->getAll();
usort($navItems, 'sortNavigationItems');
$nav->assign('navigationItems', $navItems);
Expand Down
2 changes: 2 additions & 0 deletions apps/files/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
// refer to the one of the "files" view
window.FileList = this.fileList;

OC.Plugins.attach('OCA.Files.App', this);

this._setupEvents();
// trigger URL change event handlers
this._onPopState(urlParams);
Expand Down
99 changes: 99 additions & 0 deletions apps/files/js/favoritesfilelist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com>
*
* This file is licensed under the Affero General Public License version 3
* or later.
*
* See the COPYING-README file.
*
*/

// HACK: this piece needs to be loaded AFTER the files app (for unit tests)
$(document).ready(function() {
(function(OCA) {
/**
* @class OCA.Files.FavoritesFileList
* @augments OCA.Files.FavoritesFileList
*
* @classdesc Favorites file list.
* Displays the list of files marked as favorites
*
* @param $el container element with existing markup for the #controls
* and a table
* @param [options] map of options, see other parameters
*/
var FavoritesFileList = function($el, options) {
this.initialize($el, options);
};
FavoritesFileList.prototype = _.extend({}, OCA.Files.FileList.prototype,
/** @lends OCA.Files.FavoritesFileList.prototype */ {
id: 'favorites',
appName: 'Favorites',

_clientSideSort: true,
_allowSelection: false,

/**
* @private
*/
initialize: function($el, options) {
OCA.Files.FileList.prototype.initialize.apply(this, arguments);
if (this.initialized) {
return;
}
OC.Plugins.attach('OCA.Files.FavoritesFileList', this);
},

updateEmptyContent: function() {
var dir = this.getCurrentDirectory();
if (dir === '/') {
// root has special permissions
this.$el.find('#emptycontent').toggleClass('hidden', !this.isEmpty);
this.$el.find('#filestable thead th').toggleClass('hidden', this.isEmpty);
}
else {
OCA.Files.FileList.prototype.updateEmptyContent.apply(this, arguments);
}
},

getDirectoryPermissions: function() {
return OC.PERMISSION_READ | OC.PERMISSION_DELETE;
},

updateStorageStatistics: function() {
// no op because it doesn't have
// storage info like free space / used space
},

reload: function() {
var tagName = OC.TAG_FAVORITE;
this.showMask();
if (this._reloadCall) {
this._reloadCall.abort();
}
this._reloadCall = $.ajax({
url: OC.generateUrl('/apps/files/api/v1/tags/{tagName}/files', {tagName: tagName}),
type: 'GET',
dataType: 'json'
});
var callBack = this.reloadCallback.bind(this);
return this._reloadCall.then(callBack, callBack);
},

reloadCallback: function(result) {
delete this._reloadCall;
this.hideMask();

if (result.files) {
this.setFiles(result.files.sort(this._sortComparator));
}
else {
// TODO: error handling
}
}
});

OCA.Files.FavoritesFileList = FavoritesFileList;
})(OCA);
});

Loading

0 comments on commit be3d4fd

Please sign in to comment.