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

[WIP] Added tags/favorites support #2

Closed
wants to merge 21 commits into from
Closed
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
12 changes: 12 additions & 0 deletions .scrutinizer.yml
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

47 changes: 47 additions & 0 deletions .travis.yml
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
4 changes: 4 additions & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Authors

* Vincent Petry: <pvince81@owncloud.com>

2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
owncloud-metadata (0.0.1)
* First release
661 changes: 661 additions & 0 deletions COPYING

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions README.md
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/
37 changes: 37 additions & 0 deletions appinfo/app.php
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')
)
);



72 changes: 72 additions & 0 deletions appinfo/application.php
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();

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?

Copy link
Author

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 😉

});

}


}
10 changes: 10 additions & 0 deletions appinfo/info.xml
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>
43 changes: 43 additions & 0 deletions appinfo/routes.php
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' => '.+'),
),
),
)
);

15 changes: 15 additions & 0 deletions build.xml
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>
73 changes: 73 additions & 0 deletions controller/apicontroller.php
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
*

Choose a reason for hiding this comment

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

What about enabling CORS on that endpoint? (@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);
}
}
3 changes: 3 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#hello {
color: red;
}
7 changes: 7 additions & 0 deletions img/app.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions js/app.js
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));
});
});

Loading