diff --git a/js/script.js b/js/script.js index 2b1f9ed..8bd6cb6 100644 --- a/js/script.js +++ b/js/script.js @@ -204,14 +204,14 @@ View.prototype = { this._editableId(note.id); this._editableTitle(note.title); this._editableContent(note.content); - this._editablePinned(note.ispinned); + this._editablePinned(note.isPinned); this._editableColor(note.color); - this._editableShares(note.shared_with); + this._editableShares(note.sharedWith); this._editableTags(note.tags); - this._editableAttachts(note.attachts, !note.is_shared); + this._editableAttachts(note.attachments, !note.sharedBy.length); // Create medium div editor. - this._isEditable(!note.is_shared); + this._isEditable(!note.sharedBy.length); // Show modal editor this._showEditor(id); @@ -222,11 +222,11 @@ View.prototype = { id: this._editableId(), title: this._editableTitle(), content: this._editableContent(), - attachts: this._editableAttachts(), + attachments: this._editableAttachts(), color: this._editableColor(), - pinned: this._editablePinned(), + isPinned: this._editablePinned(), tags: this._editableTags(), - shared_with: this._editableShares() + sharedWith: this._editableShares() }; var self = this; this._notes.update(fakeNote).done(function (note) { @@ -390,7 +390,7 @@ View.prototype = { var id = parseInt(gridNote.data('id'), 10); var note = self._notes.read(id); - note.pinned = true; + note.isPinned = true; self._notes.update(note).done(function () { icon.removeClass("hide-header-icon"); @@ -413,7 +413,7 @@ View.prototype = { var id = parseInt(gridNote.data('id'), 10); var note = self._notes.read(id); - note.pinned = false; + note.isPinned = false; self._notes.update(note).done(function () { icon.removeClass("fixed-header-icon"); @@ -851,7 +851,7 @@ View.prototype = { }; }); } else { - var html = Handlebars.templates['shares']({shared_with: shared_with}); + var html = Handlebars.templates['shares']({sharedWith: shared_with}); $("#modal-note-div .note-shares").replaceWith(html); } }, @@ -878,7 +878,7 @@ View.prototype = { }; }); } else { - var html = Handlebars.templates['attachts']({ attachts: attachts, can_delete: can_delete}); + var html = Handlebars.templates['attachts']({ attachments: attachts, can_delete: can_delete}); $("#modal-note-div .note-attachts").replaceWith(html); lozad('.attach-preview').observe(); diff --git a/js/templates/attachts.handlebars b/js/templates/attachts.handlebars index 63d04d3..9763cde 100644 --- a/js/templates/attachts.handlebars +++ b/js/templates/attachts.handlebars @@ -1,5 +1,5 @@
- {{#each attachts}} + {{#each attachments}}
diff --git a/js/templates/note-item.handlebars b/js/templates/note-item.handlebars index 5c36109..3773662 100644 --- a/js/templates/note-item.handlebars +++ b/js/templates/note-item.handlebars @@ -1,8 +1,8 @@
-
+
- {{#each attachts}} + {{#each attachments}}
@@ -11,7 +11,7 @@
- {{#if ispinned}} + {{#if isPinned}}
{{else}}
@@ -25,7 +25,7 @@ {{{ content }}}
- {{#each shared_with}} + {{#each sharedWith}} {{/each}}
diff --git a/js/templates/notes.handlebars b/js/templates/notes.handlebars index 683987b..db84aa2 100644 --- a/js/templates/notes.handlebars +++ b/js/templates/notes.handlebars @@ -2,10 +2,10 @@
{{#each notes}}
-
+
- {{#each attachts}} + {{#each attachments}}
@@ -14,11 +14,11 @@
- {{#if is_shared}} -
-
+ {{#if sharedBy}} +
+
{{else}} - {{#if ispinned}} + {{#if isPinned}}
{{else}}
@@ -33,7 +33,7 @@ {{{ content }}}
- {{#each shared_with}} + {{#each sharedWith}} {{/each}}
diff --git a/js/templates/shares.handlebars b/js/templates/shares.handlebars index 77c5a7d..542c009 100644 --- a/js/templates/shares.handlebars +++ b/js/templates/shares.handlebars @@ -1,5 +1,5 @@
- {{#each shared_with}} + {{#each sharedWith}} {{/each}}
\ No newline at end of file diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index f67f6d1..719d758 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -32,14 +32,18 @@ use OCP\IServerContainer; class Application extends App { /** @var string */ - public const APP_NAME = 'quicknotes'; + public const APP_ID = 'quicknotes'; + + /** @var string */ + public const API_VERSION = '1.0'; public function __construct(array $urlParams = []) { - parent::__construct(self::APP_NAME, $urlParams); + parent::__construct(self::APP_ID, $urlParams); } public function register(): void { $this->registerNavigationEntry(); + $this->registerCapabilities(); } private function registerNavigationEntry(): void { @@ -59,4 +63,9 @@ class Application extends App { }); } + private function registerCapabilities(): void { + $container = $this->getContainer(); + $container->registerCapability(Capabilities::class); + } + } \ No newline at end of file diff --git a/lib/AppInfo/Capabilities.php b/lib/AppInfo/Capabilities.php new file mode 100644 index 0000000..a24939a --- /dev/null +++ b/lib/AppInfo/Capabilities.php @@ -0,0 +1,47 @@ + + * + * @author 2016 Matias De lellis + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + + +namespace OCA\QuickNotes\AppInfo; + +use OCP\Capabilities\ICapability; +use OCP\App\IAppManager; + +class Capabilities implements ICapability { + + /** @var IAppManager */ + private $appManager; + + public function __construct(IAppManager $appManager) { + $this->appManager = $appManager; + } + + public function getCapabilities() { + return [ + Application::APP_ID => [ + 'version' => $this->appManager->getAppVersion(Application::APP_ID), + 'api_version' => Application::API_VERSION, + ], + ]; + } + +} \ No newline at end of file diff --git a/lib/Controller/NoteApiController.php b/lib/Controller/NoteApiController.php index c4bcd4f..dbc1bc2 100644 --- a/lib/Controller/NoteApiController.php +++ b/lib/Controller/NoteApiController.php @@ -37,7 +37,7 @@ class NoteApiController extends ApiController { private $userId; public function __construct($AppName, - IRequest $request, + IRequest $request, NoteService $noteService, $userId) { @@ -74,7 +74,7 @@ class NoteApiController extends ApiController { * * @param int $id */ - public function show($id): JSONResponse { + public function show(int $id): JSONResponse { $note = $this->noteService->get($this->userId, $id); if (is_null($note)) { return new JSONResponse([], Http::STATUS_NOT_FOUND); @@ -96,9 +96,27 @@ class NoteApiController extends ApiController { * @param string $title * @param string $content * @param string $color + * @param bool $isPinned + * @param array $sharedWith + * @param array $tags + * @param array $attachments */ - public function create($title, $content, $color = "#F7EB96") { - $note = $this->noteService->create($this->userId, $title, $content, $color); + public function create(string $title, + string $content, + string $color = null, + bool $isPinned = false, + array $sharedWith = [], + array $tags = [], + array $attachments = []) + { + $note = $this->noteService->create($this->userId, + $title, + $content, + $color, + $isPinned, + $sharedWith, + $tags, + $attachments); $etag = md5(json_encode($note)); @@ -116,13 +134,31 @@ class NoteApiController extends ApiController { * @param int $id * @param string $title * @param string $content - * @param array $attachts - * @param bool $pinned - * @param array $tags * @param string $color + * @param bool $isPinned + * @param array $tags + * @param array $attachments + * @param array $sharedWith */ - public function update(int $id, string $title, string $content, array $attachts, bool $pinned, array $tags, string $color = "#F7EB96"): JSONResponse { - $note = $this->noteService->update($this->userId, $id, $title, $content, $attachts, $pinned, $tags, $color); + public function update(int $id, + string $title, + string $content, + string $color, + bool $isPinned, + array $tags, + array $attachments, + array $sharedWith): JSONResponse + { + $note = $this->noteService->update($this->userId, + $id, + $title, + $content, + $color, + $isPinned, + $tags, + $attachments, + $sharedWith); + if (is_null($note)) { return new JSONResponse([], Http::STATUS_NOT_FOUND); } diff --git a/lib/Controller/NoteController.php b/lib/Controller/NoteController.php index 3581ecf..476ab97 100644 --- a/lib/Controller/NoteController.php +++ b/lib/Controller/NoteController.php @@ -37,7 +37,7 @@ class NoteController extends Controller { private $userId; public function __construct($AppName, - IRequest $request, + IRequest $request, NoteService $noteService, $userId) { @@ -70,7 +70,7 @@ class NoteController extends Controller { * * @param int $id */ - public function show($id): JSONResponse { + public function show(int $id): JSONResponse { $note = $this->noteService->get($this->userId, $id); if (is_null($note)) { return new JSONResponse([], Http::STATUS_NOT_FOUND); @@ -90,9 +90,27 @@ class NoteController extends Controller { * @param string $title * @param string $content * @param string $color + * @param bool $isPinned + * @param array $sharedWith + * @param array $tags + * @param array $attachments */ - public function create($title, $content, $color = NULL) { - $note = $this->noteService->create($this->userId, $title, $content, $color); + public function create(string $title, + string $content, + string $color = null, + bool $isPinned = false, + array $sharedWith = [], + array $tags = [], + array $attachments = []) + { + $note = $this->noteService->create($this->userId, + $title, + $content, + $color, + $isPinned, + $sharedWith, + $tags, + $attachments); $etag = md5(json_encode($note)); @@ -108,14 +126,31 @@ class NoteController extends Controller { * @param int $id * @param string $title * @param string $content - * @param array $attachts - * @param bool $pinned - * @param array $tags - * @param array $shared_with * @param string $color + * @param bool $isPinned + * @param array $tags + * @param array $attachments + * @param array $sharedWith */ - public function update(int $id, string $title, string $content, array $attachts, bool $pinned, array $tags, array $shared_with, string $color = "#F7EB96"): JSONResponse { - $note = $this->noteService->update($this->userId, $id, $title, $content, $attachts, $pinned, $tags, $shared_with, $color); + public function update(int $id, + string $title, + string $content, + string $color, + bool $isPinned, + array $tags, + array $attachments, + array $sharedWith): JSONResponse + { + $note = $this->noteService->update($this->userId, + $id, + $title, + $content, + $color, + $isPinned, + $tags, + $attachments, + $sharedWith); + if (is_null($note)) { return new JSONResponse([], Http::STATUS_NOT_FOUND); } @@ -137,4 +172,5 @@ class NoteController extends Controller { $this->noteService->destroy($this->userId, $id); return new JSONResponse([]); } + } diff --git a/lib/Db/Note.php b/lib/Db/Note.php index 15007da..7bd54d4 100644 --- a/lib/Db/Note.php +++ b/lib/Db/Note.php @@ -15,7 +15,6 @@ class Note extends Entity implements JsonSerializable { protected $userId; protected $sharedWith = []; protected $sharedBy = []; - protected $isShared; protected $tags; protected $attachts; @@ -32,20 +31,16 @@ class Note extends Entity implements JsonSerializable { public function jsonSerialize() { return [ - 'id' => $this->id, - 'title' => $this->title, - 'content' => $this->content, - 'pinned' => $this->pinned, - 'ispinned' => $this->isPinned, - 'timestamp' => $this->timestamp, - 'colorid' => $this->colorId, - 'color' => $this->color, - 'userid' => $this->userId, - 'shared_with' => $this->sharedWith, - 'shared_by' => $this->sharedBy, - 'is_shared' => $this->isShared, - 'tags' => $this->tags, - 'attachts' => $this->attachts + 'id' => $this->id, + 'title' => $this->title, + 'content' => $this->content, + 'isPinned' => $this->isPinned, + 'timestamp' => $this->timestamp, + 'color' => $this->color, + 'sharedWith' => $this->sharedWith, + 'sharedBy' => $this->sharedBy, + 'tags' => $this->tags, + 'attachments' => $this->attachts ]; } } diff --git a/lib/Service/NoteService.php b/lib/Service/NoteService.php index bd8c08c..9e0a96c 100644 --- a/lib/Service/NoteService.php +++ b/lib/Service/NoteService.php @@ -81,7 +81,6 @@ class NoteService { // Set shares with others. foreach($notes as $note) { - $note->setIsShared(false); $note->setSharedWith($this->noteShareMapper->getSharesForNote($note->getId())); } @@ -90,8 +89,6 @@ class NoteService { $sharedEntries = $this->noteShareMapper->findForUser($userId); foreach($sharedEntries as $sharedEntry) { $sharedNote = $this->notemapper->findShared($sharedEntry->getNoteId()); - $sharedNote->setIsShared(true); - $sharedEntry->setUserId($sharedNote->getUserId()); $sharedNote->setSharedBy([$sharedEntry]); $shares[] = $sharedNote; @@ -155,9 +152,21 @@ class NoteService { * @param string $userId * @param string $title * @param string $content - * @param string $color + * @param string $color optional color. + * @param bool $isPinned optional if note must be pinned + * @param array $sharedWith optional list of shares + * @param array $tags optional list of tags + * @param array $attachments optional list of attachments */ - public function create(string $userId, string $title, string $content, string $color = NULL): Note { + public function create(string $userId, + string $title, + string $content, + string $color = null, + bool $isPinned = false, + array $sharedWith = [], + array $tags = [], + array $attachments = []): ?Note + { if (is_null($color)) { $color = $this->settingsService->getColorForNewNotes(); } @@ -171,20 +180,24 @@ class NoteService { $hcolor = $this->colormapper->insert($hcolor); } + // Create note and insert it $note = new Note(); $note->setTitle($title); $note->setContent($content); + $note->setPinned($isPinned ? 1 : 0); $note->setTimestamp(time()); $note->setColorId($hcolor->id); $note->setUserId($userId); $newNote = $this->notemapper->insert($note); + // TODO: Insert optional shares, tags and attachments. + // Insert true color pin and tags to response $newNote->setColor($hcolor->getColor()); - $newNote->setIsPinned(false); + $newNote->setIsPinned($isPinned); $newNote->setTags([]); $newNote->setAttachts([]); @@ -193,24 +206,24 @@ class NoteService { /** * @param string userId - * @param int $id + * @param int $id * @param string $title * @param string $content - * @param array $attachts - * @param bool $pinned - * @param array $tags - * @param array $shares * @param string $color + * @param bool $isPinned + * @param array $tags + * @param array $attachments + * @param array $sharedWith */ public function update(string $userId, int $id, string $title, string $content, - array $attachts, - bool $pinned, + string $color, + bool $isPinned, array $tags, - array $shares, - string $color): ?Note + array $attachments, + array $sharedWith): ?Note { // Get current Note and Color. $note = $this->get($userId, $id); @@ -244,7 +257,7 @@ class NoteService { } // Add new attachts - foreach ($attachts as $attach) { + foreach ($attachments as $attach) { if (!$this->attachMapper->fileAttachExists($userId, $id, $attach['file_id'])) { $hAttach = new Attach(); $hAttach->setUserId($userId); @@ -259,7 +272,7 @@ class NoteService { $dbShares = $this->noteShareMapper->getSharesForNote($id); foreach ($dbShares as $dbShare) { $delete = true; - foreach ($shares as $share) { + foreach ($sharedWith as $share) { if ($dbShare->getSharedUser() === $share['shared_user']) { $delete = false; break; @@ -271,7 +284,7 @@ class NoteService { } // Add new shares - foreach ($shares as $share) { + foreach ($sharedWith as $share) { if (!$this->noteShareMapper->existsByNoteAndUser($id, $share['shared_user'])) { $hShare = new NoteShare(); $hShare->setNoteId($id); @@ -320,7 +333,7 @@ class NoteService { // Set new info on Note $note->setTitle($title); $note->setContent($content); - $note->setPinned($pinned ? 1 : 0); + $note->setPinned($isPinned ? 1 : 0); $note->setTimestamp(time()); $note->setColorId($hcolor->id); @@ -329,7 +342,7 @@ class NoteService { // Insert true color and pin to response $newnote->setColor($hcolor->getColor()); - $newnote->setIsPinned($note->getPinned() ? true : false); + $newnote->setIsPinned($isPinned); // Fill new tags $newnote->setTags($this->tagmapper->getTagsForNote($userId, $newnote->getId())); @@ -343,7 +356,6 @@ class NoteService { $newnote->setAttachts($attachts); // Fill shared with with others - $newnote->setIsShared(false); $newnote->setSharedWith($this->noteShareMapper->getSharesForNote($newnote->getId())); // Remove old color if necessary @@ -363,7 +375,7 @@ class NoteService { * @param string $userId * @param int $id */ - public function destroy($userId, $id) { + public function destroy (string $userId, int $id) { // Get Note and Color try { $note = $this->notemapper->find($id, $userId); diff --git a/lib/Service/SettingsService.php b/lib/Service/SettingsService.php index 97ff5bc..0df0daf 100644 --- a/lib/Service/SettingsService.php +++ b/lib/Service/SettingsService.php @@ -55,11 +55,11 @@ class SettingsService { public function getColorForNewNotes(): string { - return $this->config->getUserValue($this->userId, Application::APP_NAME, self::COLOR_FOR_NEW_NOTES_KEY, self::DEFAULT_COLOR_FOR_NEW_NOTES); + return $this->config->getUserValue($this->userId, Application::APP_ID, self::COLOR_FOR_NEW_NOTES_KEY, self::DEFAULT_COLOR_FOR_NEW_NOTES); } public function setColorForNewNotes(string $color) { - $this->config->setUserValue($this->userId, Application::APP_NAME, self::COLOR_FOR_NEW_NOTES_KEY, $color); + $this->config->setUserValue($this->userId, Application::APP_ID, self::COLOR_FOR_NEW_NOTES_KEY, $color); } }