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

manual edit of a note's title #474

Merged
merged 4 commits into from
Apr 13, 2020
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ appstore: clean lint build-js-production

### from vueexample

all: dev-setup lint build-js-production test
all: dev-setup build-js-production

# Dev env management
dev-setup: clean clean-dev init
Expand Down
29 changes: 2 additions & 27 deletions appinfo/app.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,4 @@
<?php
/**
* Nextcloud - Notes
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Bernhard Posselt <[email protected]>
* @copyright Bernhard Posselt 2012, 2014
*/

namespace OCA\Notes\AppInfo;

use OCP\AppFramework\App;

$app = new App('notes');
$container = $app->getContainer();

$container->query('OCP\INavigationManager')->add(function () use ($container) {
$urlGenerator = $container->query('OCP\IURLGenerator');
$l10n = $container->query('OCP\IL10N');
return [
'id' => 'notes',
'order' => 10,
'href' => $urlGenerator->linkToRoute('notes.page.index'),
'icon' => $urlGenerator->imagePath('notes', 'notes.svg'),
'name' => $l10n->t('Notes')
];
});
$app = new OCA\Notes\Application();
$app->register();
105 changes: 69 additions & 36 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
<?php
/**
* Nextcloud - Notes
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Bernhard Posselt <[email protected]>
* @copyright Bernhard Posselt 2012, 2014
*/

return ['routes' => [
// page
////////// P A G E //////////
[
'name' => 'page#index',
'url' => '/',
Expand All @@ -30,7 +20,8 @@
'requirements' => ['id' => '\d+'],
],

// notes

////////// N O T E S //////////
[
'name' => 'notes#index',
'url' => '/notes',
Expand Down Expand Up @@ -59,16 +50,13 @@
'requirements' => ['id' => '\d+'],
],
[
'name' => 'notes#category',
'url' => '/notes/{id}/category',
'name' => 'notes#updateProperty',
'url' => '/notes/{id}/{property}',
'verb' => 'PUT',
'requirements' => ['id' => '\d+'],
],
[
'name' => 'notes#favorite',
'url' => '/notes/{id}/favorite',
'verb' => 'PUT',
'requirements' => ['id' => '\d+'],
'requirements' => [
'id' => '\d+',
'property' => '(modified|title|category|favorite)',
],
],
[
'name' => 'notes#destroy',
Expand All @@ -77,43 +65,88 @@
'requirements' => ['id' => '\d+'],
],

// api

////////// S E T T I N G S //////////
['name' => 'settings#set', 'url' => '/settings', 'verb' => 'PUT'],
['name' => 'settings#get', 'url' => '/settings', 'verb' => 'GET'],


////////// A P I //////////
[
'name' => 'notes_api#index',
'url' => '/api/v0.2/notes',
'url' => '/api/{apiVersion}/notes',
'verb' => 'GET',
'requirements' => [
'apiVersion' => '(v0.2|v1)',
],
],
[
'name' => 'notes_api#get',
'url' => '/api/v0.2/notes/{id}',
'url' => '/api/{apiVersion}/notes/{id}',
'verb' => 'GET',
'requirements' => ['id' => '\d+'],
'requirements' => [
'apiVersion' => '(v0.2|v1)',
'id' => '\d+',
],
],
[
'name' => 'notes_api#createAutoTitle',
'url' => '/api/{apiVersion}/notes',
'verb' => 'POST',
'requirements' => [
'apiVersion' => '(v0.2)',
],
],
[
'name' => 'notes_api#create',
'url' => '/api/v0.2/notes',
'url' => '/api/{apiVersion}/notes',
'verb' => 'POST',
'requirements' => [
'apiVersion' => '(v1)',
],
],
[
'name' => 'notes_api#updateAutoTitle',
'url' => '/api/{apiVersion}/notes/{id}',
'verb' => 'PUT',
'requirements' => [
'apiVersion' => '(v0.2)',
'id' => '\d+',
],
],
[
'name' => 'notes_api#update',
'url' => '/api/v0.2/notes/{id}',
'url' => '/api/{apiVersion}/notes/{id}',
'verb' => 'PUT',
'requirements' => ['id' => '\d+'],
'requirements' => [
'apiVersion' => '(v1)',
'id' => '\d+',
],
],
[
'name' => 'notes_api#destroy',
'url' => '/api/v0.2/notes/{id}',
'url' => '/api/{apiVersion}/notes/{id}',
'verb' => 'DELETE',
'requirements' => ['id' => '\d+'],
'requirements' => [
'apiVersion' => '(v0.2|v1)',
'id' => '\d+',
],
],
[
'name' => 'notes_api#fail',
'url' => '/api/{catchAll}',
'verb' => 'GET',
'requirements' => [
'catchAll' => '.*',
],
],
[
'name' => 'notes_api#preflighted_cors',
'url' => '/api/v0.2/{path}',
'url' => '/api/{apiVersion}/{path}',
'verb' => 'OPTIONS',
'requirements' => ['path' => '.+'],
'requirements' => [
'apiVersion' => '(v0.2|v1)',
'path' => '.+',
],
],

// settings
['name' => 'settings#set', 'url' => '/settings', 'verb' => 'PUT'],
['name' => 'settings#get', 'url' => '/settings', 'verb' => 'GET'],
]];
31 changes: 31 additions & 0 deletions lib/Application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace OCA\Notes;

use OCP\AppFramework\App;

class Application extends App {

public static $API_VERSIONS = [ '0.2', '1.0' ];

public function __construct(array $urlParams = []) {
parent::__construct('notes', $urlParams);
}

public function register() : void {
$container = $this->getContainer();
$container->registerCapability(Capabilities::class);
$server = $container->getServer();
$server->getNavigationManager()->add(function () use ($server) {
$urlGenerator = $server->getURLGenerator();
$l10n = $server->getL10N('notes');
return [
'id' => 'notes',
'order' => 10,
'href' => $urlGenerator->linkToRoute('notes.page.index'),
'icon' => $urlGenerator->imagePath('notes', 'notes.svg'),
'name' => $l10n->t('Notes'),
];
});
}
}
16 changes: 16 additions & 0 deletions lib/Capabilities.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace OCA\Notes;

use OCP\Capabilities\ICapability;

class Capabilities implements ICapability {

public function getCapabilities() {
return [
'notes' => [
'api_version' => Application::$API_VERSIONS,
],
];
}
}
27 changes: 0 additions & 27 deletions lib/Controller/Errors.php

This file was deleted.

43 changes: 43 additions & 0 deletions lib/Controller/Helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php declare(strict_types=1);

namespace OCA\Notes\Controller;

use OCA\Notes\Application;
use OCA\Notes\Service\InsufficientStorageException;
use OCA\Notes\Service\NoteDoesNotExistException;

use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\ILogger;

class Helper {

private $logger;
private $appName;

public function __construct(
ILogger $logger,
string $appName
) {
$this->logger = $logger;
$this->appName = $appName;
}

public function handleErrorResponse(callable $respond) : DataResponse {
try {
$data = $respond();
$response = $data instanceof DataResponse ? $data : new DataResponse($data);
} catch (NoteDoesNotExistException $e) {
$this->logger->logException($e, [ 'app' => $this->appName ]);
$response = new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (InsufficientStorageException $e) {
$this->logger->logException($e, [ 'app' => $this->appName ]);
$response = new DataResponse([], Http::STATUS_INSUFFICIENT_STORAGE);
} catch (\Throwable $e) {
$this->logger->logException($e, [ 'app' => $this->appName ]);
$response = new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
}
$response->addHeader('X-Notes-API-Versions', implode(', ', Application::$API_VERSIONS));
return $response;
}
}
Loading