-
Notifications
You must be signed in to change notification settings - Fork 1
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
[WIP] Added tags/favorites support #2
Closed
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
3a448c5
Added tags/favorites support (WIP)
PVince81 e2e6b4d
A few tweaks which didn't fix the issue
PVince81 f872896
Fixed app
PVince81 c1a1ca1
Now using getUserFolder() to access files
PVince81 f413561
Fix errors on apps page
PVince81 3b864a1
Populate favorites list (WIP)
PVince81 0e4cc34
Use nodes API to resolve FileInfo from fileIds
PVince81 1f38133
Now using searchByTag function to find by tag
PVince81 b4a6a4e
Fix tags code to use new return format
PVince81 2ac6b8d
Use JS plugin system to register favorites app
PVince81 b9d8d36
Use DataReponse instead of JsonResponse
PVince81 1c6a7d1
Small fixes
PVince81 40fb9fd
Inject path and tags in favorites list
PVince81 8297fff
Added WIP JS unit tests
PVince81 025b2a0
Updated travis config
PVince81 07723e1
Added JS unit tests, now for real!
PVince81 48f23f4
Fix app name in travis config
PVince81 2f41aa4
fix travis-ci
DeepDiver1975 b2bc898
Add .scrutinizer.yml
DeepDiver1975 b44fa5d
Update build.xml
DeepDiver1975 49b13db
Merge pull request #5 from owncloud/fix-travis-2
DeepDiver1975 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
filter: | ||
excluded_paths: | ||
- 'l10n/*' | ||
- 'tests/*' | ||
|
||
imports: | ||
- javascript | ||
- php | ||
|
||
tools: | ||
external_code_coverage: true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
language: php | ||
php: | ||
- 5.4 | ||
- 5.5 | ||
- 5.6 | ||
|
||
env: | ||
global: | ||
- CORE_BRANCH=master | ||
- APP_NAME=metadata | ||
matrix: | ||
- DB=sqlite | ||
|
||
branches: | ||
only: | ||
- master | ||
|
||
before_install: | ||
- wget https://raw.githubusercontent.com/owncloud/administration/master/travis-ci/before_install.sh | ||
- bash ./before_install.sh $APP_NAME $CORE_BRANCH $DB | ||
- cd ../core | ||
- php occ app:enable $APP_NAME | ||
|
||
script: | ||
# Test lint | ||
- cd ../core/apps/$APP_NAME | ||
- sh -c "if [ '$DB' = 'sqlite' ]; then ant test; fi" | ||
|
||
# Run phpunit tests | ||
- cd tests/unit | ||
- phpunit --configuration phpunit.xml | ||
|
||
# Create coverage report | ||
- wget https://scrutinizer-ci.com/ocular.phar | ||
- php ocular.phar code-coverage:upload --format=php-clover clover.xml | ||
|
||
matrix: | ||
include: | ||
- php: 5.4 | ||
env: DB=mysql | ||
- php: 5.4 | ||
env: DB=pgsql | ||
- php: 5.4 | ||
env: DB=oracle | ||
allow_failures: | ||
- php: hhvm | ||
fast_finish: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Authors | ||
|
||
* Vincent Petry: <pvince81@owncloud.com> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
owncloud-metadata (0.0.1) | ||
* First release |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
metadata | ||
======== | ||
# Metadata | ||
Place this app in **owncloud/apps/** | ||
|
||
|
||
## Running tests | ||
After [Installing PHPUnit](http://phpunit.de/getting-started.html) run: | ||
|
||
phpunit tests/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
/** | ||
* ownCloud - metadata | ||
* | ||
* This file is licensed under the Affero General Public License version 3 or | ||
* later. See the COPYING file. | ||
* | ||
* @author Vincent Petry <pvince81@owncloud.com> | ||
* @copyright 2014 Vincent Petry | ||
*/ | ||
|
||
namespace OCA\Metadata\AppInfo; | ||
|
||
$app = new Application(); | ||
$c = $app->getContainer(); | ||
$l = $c->query('L10N'); | ||
|
||
\OC_FileProxy::register(new \OCA\Metadata\TagsProxy($c->query('Tagger'))); | ||
|
||
// FIXME: I wish there was a way to load scripts only | ||
// on a specific route of the files app (index) | ||
\OCP\Util::addScript('metadata', 'app'); | ||
\OCP\Util::addScript('metadata', 'favoritesplugin'); | ||
\OCP\Util::addScript('metadata', 'favoritesfilelist'); | ||
|
||
\OCA\Files\App::getNavigationManager()->add( | ||
array( | ||
"id" => 'favorites', | ||
"appname" => 'files', | ||
"script" => 'list.php', | ||
"order" => 10, | ||
"name" => $l->t('Favorites') | ||
) | ||
); | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* ownCloud - metadata | ||
* | ||
* This file is licensed under the Affero General Public License version 3 or | ||
* later. See the COPYING file. | ||
* | ||
* @author Vincent Petry <pvince81@owncloud.com> | ||
* @copyright 2014 Vincent Petry | ||
*/ | ||
|
||
namespace OCA\Metadata\AppInfo; | ||
|
||
|
||
use \OCP\AppFramework\App; | ||
use \OCP\IContainer; | ||
|
||
use \OCA\Metadata\Controller\ApiController; | ||
use \OCA\Metadata\Service\TagService; | ||
|
||
|
||
class Application extends App { | ||
|
||
|
||
public function __construct (array $urlParams=array()) { | ||
parent::__construct('metadata', $urlParams); | ||
|
||
$container = $this->getContainer(); | ||
|
||
/** | ||
* 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('Tagger'), | ||
$homeFolder | ||
); | ||
}); | ||
|
||
/** | ||
* Controllers | ||
*/ | ||
$container->registerService('APIController', function (IContainer $c) { | ||
return new ApiController( | ||
$c->query('AppName'), | ||
$c->query('Request'), | ||
$c->query('TagService') | ||
); | ||
}); | ||
|
||
/** | ||
* Core | ||
*/ | ||
$container->registerService('UserId', function(IContainer $c) { | ||
return \OCP\User::getUser(); | ||
}); | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0"?> | ||
<info> | ||
<id>metadata</id> | ||
<name>Files Metadata</name> | ||
<description></description> | ||
<licence>AGPL</licence> | ||
<author>Vincent Petry</author> | ||
<version>0.0.1</version> | ||
<requiremin>7.0.0</requiremin> | ||
</info> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/** | ||
* ownCloud - metadata | ||
* | ||
* This file is licensed under the Affero General Public License version 3 or | ||
* later. See the COPYING file. | ||
* | ||
* @author Vincent Petry <pvince81@owncloud.com> | ||
* @copyright 2014 Vincent Petry | ||
*/ | ||
|
||
namespace OCA\Metadata\AppInfo; | ||
|
||
/** | ||
* Create your routes in here. The name is the lowercase name of the controller | ||
* without the controller part, the stuff after the hash is the method. | ||
* e.g. page#index -> PageController->index() | ||
* | ||
* The controller class has to be registered in the application.php file since | ||
* it's instantiated in there | ||
*/ | ||
$application = new Application(); | ||
|
||
$application->registerRoutes( | ||
$this, | ||
array( | ||
'routes' => array( | ||
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' => '.+'), | ||
), | ||
), | ||
) | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<project name="owncloud-metadata" basedir="." default="test"> | ||
|
||
<!-- test - Tests if the code syntax is correct and executes phpunit tests --> | ||
<target name="test"> | ||
<apply executable="php" failonerror="true"> | ||
<arg value="-l" /> | ||
<fileset dir="."> | ||
<include name="**/*.php" /> | ||
<exclude name="**/l10n/**" /> | ||
</fileset> | ||
</apply> | ||
|
||
</target> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
/** | ||
* Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com> | ||
* This file is licensed under the Affero General Public License version 3 or | ||
* later. | ||
* See the COPYING-README file. | ||
*/ | ||
|
||
namespace OCA\Metadata\Controller; | ||
|
||
use OCP\AppFramework\Http; | ||
use OCP\AppFramework\Controller; | ||
use OCP\IRequest; | ||
use OCP\AppFramework\Http\DataResponse; | ||
use OCP\AppFramework\Http\DownloadResponse; | ||
use OC\Preview; | ||
use OCA\Metadata\Service\TagService; | ||
|
||
class ApiController extends Controller { | ||
|
||
private $tagService; | ||
|
||
public function __construct($appName, IRequest $request, TagService $tagService){ | ||
parent::__construct($appName, $request); | ||
$this->tagService = $tagService; | ||
} | ||
|
||
/** | ||
* Updates the info of the specified file path | ||
* The passed tags are absolute, which means they will | ||
* replace the actual tag selection. | ||
* | ||
* @NoAdminRequired | ||
* @CORS | ||
* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about enabling CORS on that endpoint? ( |
||
* @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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#hello { | ||
color: red; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* 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. | ||
* | ||
*/ | ||
(function(OCA) { | ||
|
||
OCA.Metadata = OCA.Metadata || {}; | ||
|
||
/** | ||
* @class OCA.Metadata.FavoritesPlugin | ||
* @augments OCA.Metadata.FavoritesPlugin | ||
* | ||
* @classdesc Favorites plugin | ||
* Registers the favorites file list and file actions. | ||
*/ | ||
OCA.Metadata.App = { | ||
name: 'Favorites', | ||
|
||
initialize: function($container) { | ||
// register favorite list for sidebar section | ||
this.favoritesFileList = new OCA.Metadata.FavoritesFileList( | ||
$container, { | ||
scrollContainer: $('#app-content'), | ||
fileActions: OCA.Files.fileActions | ||
} | ||
); | ||
} | ||
}; | ||
})(OCA); | ||
|
||
$(document).ready(function() { | ||
$('#app-content-favorites').one('show', function(e) { | ||
OCA.Metadata.App.initialize($(e.target)); | ||
}); | ||
}); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mhm. Why not inject IUser/IUserSession instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied this from another app, so you might want to ask that person the same question 😉