From 45fa10394f396ff70d0cd4749500b9b0ea6493a8 Mon Sep 17 00:00:00 2001 From: Vinzenz Rosenkranz Date: Tue, 31 May 2016 00:38:56 +0200 Subject: [PATCH 01/12] set sharing layout --- appinfo/database.xml | 36 +++++++++++++++++++++++++- appinfo/info.xml | 4 +-- db/share.php | 22 ++++++++++++++++ db/sharemapper.php | 28 ++++++++++++++++++++ templates/part.note-modal-editable.php | 1 + 5 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 db/share.php create mode 100644 db/sharemapper.php diff --git a/appinfo/database.xml b/appinfo/database.xml index 5389d05..61e0441 100644 --- a/appinfo/database.xml +++ b/appinfo/database.xml @@ -108,4 +108,38 @@ - \ No newline at end of file + + *dbprefix*quicknotes_shares + + + id + integer + true + true + true + true + 8 + + + note_id + integer + true + true + true + 8 + + + shared_user + text + 200 + + + + shared_group + text + 200 + + + +
+ diff --git a/appinfo/info.xml b/appinfo/info.xml index 4fe1fab..f0b9b76 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -5,7 +5,7 @@ Quick notes with text, check lists and pictures AGPL Matias De lellis - 0.1.0 + 0.1.1 QuickNotes tool https://github.com/matiasdelellis @@ -15,4 +15,4 @@ - \ No newline at end of file + diff --git a/db/share.php b/db/share.php new file mode 100644 index 0000000..c571140 --- /dev/null +++ b/db/share.php @@ -0,0 +1,22 @@ + $this->id, + 'note' => $this->noteId, + 'user' => $this->sharedUser, + 'group' => $this->sharedGroup + ]; + } +} diff --git a/db/sharemapper.php b/db/sharemapper.php new file mode 100644 index 0000000..bd295d5 --- /dev/null +++ b/db/sharemapper.php @@ -0,0 +1,28 @@ +findEntity($sql, [$id, $userId]); + }*/ + + public function findForUser($userId) { + $sql = 'SELECT * FROM *PREFIX*quicknotes_shares WHERE shared_user = ?'; + return $this->findEntities($sql, [$userId]); + } + + public function findForGroup($groupId) { + $sql = 'SELECT * FROM *PREFIX*quicknotes_shares WHERE shared_group = ?'; + return $this->findEntities($sql, [$groupId]); + } +} diff --git a/templates/part.note-modal-editable.php b/templates/part.note-modal-editable.php index 6c53453..0b7216a 100644 --- a/templates/part.note-modal-editable.php +++ b/templates/part.note-modal-editable.php @@ -5,6 +5,7 @@
+
From 9eede1756d7a9abf8ed96c0e38c804ea6d11087a Mon Sep 17 00:00:00 2001 From: Vinzenz Date: Tue, 31 May 2016 01:10:36 +0200 Subject: [PATCH 02/12] remove auto inc --- appinfo/database.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/appinfo/database.xml b/appinfo/database.xml index 61e0441..99b4165 100644 --- a/appinfo/database.xml +++ b/appinfo/database.xml @@ -124,7 +124,6 @@ note_id integer true - true true 8 From df3db489f43b41bd36149cb255e6434cfe93705d Mon Sep 17 00:00:00 2001 From: Vinzenz Date: Tue, 31 May 2016 14:16:43 +0200 Subject: [PATCH 03/12] add basich sharing functionality logic --- controller/notecontroller.php | 18 +++++++++++++++++- css/style.css | 8 ++++++-- db/note.php | 7 +++++-- db/notemapper.php | 7 ++++++- db/{share.php => noteshare.php} | 8 ++++---- db/{sharemapper.php => notesharemapper.php} | 4 ++-- js/script.js | 1 + templates/part.note-modal-editable.php | 2 +- templates/part.note.php | 9 +++++++-- 9 files changed, 49 insertions(+), 15 deletions(-) rename db/{share.php => noteshare.php} (58%) rename db/{sharemapper.php => notesharemapper.php} (93%) diff --git a/controller/notecontroller.php b/controller/notecontroller.php index 5c5b847..e203012 100644 --- a/controller/notecontroller.php +++ b/controller/notecontroller.php @@ -18,19 +18,23 @@ use OCP\AppFramework\Controller; use OCA\QuickNotes\Db\Note; use OCA\QuickNotes\Db\Color; +use OCA\QuickNotes\Db\NoteShare; use OCA\QuickNotes\Db\NoteMapper; use OCA\QuickNotes\Db\ColorMapper; +use OCA\QuickNotes\Db\NoteShareMapper; class NoteController extends Controller { private $notemapper; private $colormapper; + private $notesharemapper; private $userId; - public function __construct($AppName, IRequest $request, NoteMapper $notemapper, ColorMapper $colormapper, $UserId) { + public function __construct($AppName, IRequest $request, NoteMapper $notemapper, NoteShareMapper $notesharemapper, ColorMapper $colormapper, $UserId) { parent::__construct($AppName, $request); $this->notemapper = $notemapper; $this->colormapper = $colormapper; + $this->notesharemapper = $notesharemapper; $this->userId = $UserId; } @@ -39,6 +43,18 @@ class NoteController extends Controller { */ public function index() { $notes = $this->notemapper->findAll($this->userId); + foreach($notes as $note) { + $note->setIsShared(false); + } + $shareEntries = $this->notesharemapper->findForUser($this->userId); + $shares = array(); + foreach($shareEntries as $entry) { + $share = $this->notemapper->findById($entry->getNoteId()); + $share->setIsShared(true); + $shares[] = $share; + + } + $notes = array_merge($notes, $shares); // Insert true color to response foreach ($notes as $note) { $note->setColor($this->colormapper->find($note->getColorId())->getColor()); diff --git a/css/style.css b/css/style.css index 75e7523..d32cf1a 100644 --- a/css/style.css +++ b/css/style.css @@ -47,8 +47,6 @@ /* Grid Note */ #div-content .note-title { - height: 28px; - width: calc(100% - 20px); font-size: 18px; font-weight: bold; text-overflow: ellipsis; @@ -56,6 +54,12 @@ overflow: hidden; } +#div-content .shared-title { + float: right; + margin: 2px; + opacity: 0.5; +} + .noselect { -webkit-touch-callout: none; /* iOS Safari */ -webkit-user-select: none; /* Chrome/Safari/Opera */ diff --git a/db/note.php b/db/note.php index 301e229..1021775 100644 --- a/db/note.php +++ b/db/note.php @@ -12,6 +12,7 @@ class Note extends Entity implements JsonSerializable { protected $timestamp; protected $colorId; protected $userId; + protected $isShared; protected $color; @@ -26,7 +27,9 @@ class Note extends Entity implements JsonSerializable { 'content' => $this->content, 'timestamp' => $this->timestamp, 'colorid' => $this->colorId, - 'color' => $this->color + 'color' => $this->color, + 'userid' => $this->userId, + 'isshared' => $this->isShared ]; } -} \ No newline at end of file +} diff --git a/db/notemapper.php b/db/notemapper.php index 1cb3261..b5eb702 100644 --- a/db/notemapper.php +++ b/db/notemapper.php @@ -16,6 +16,11 @@ class NoteMapper extends Mapper { return $this->findEntity($sql, [$id, $userId]); } + public function findById($id) { + $sql = 'SELECT * FROM *PREFIX*quicknotes_notes WHERE id = ?'; + return $this->findEntity($sql, [$id]); + } + public function findAll($userId) { $sql = 'SELECT * FROM *PREFIX*quicknotes_notes WHERE user_id = ?'; return $this->findEntities($sql, [$userId]); @@ -29,4 +34,4 @@ class NoteMapper extends Mapper { return $row['count']; } -} \ No newline at end of file +} diff --git a/db/share.php b/db/noteshare.php similarity index 58% rename from db/share.php rename to db/noteshare.php index c571140..bf32689 100644 --- a/db/share.php +++ b/db/noteshare.php @@ -5,7 +5,7 @@ use JsonSerializable; use OCP\AppFramework\Db\Entity; -class Share extends Entity implements JsonSerializable { +class NoteShare extends Entity implements JsonSerializable { protected $noteId; protected $sharedUser; @@ -14,9 +14,9 @@ class Share extends Entity implements JsonSerializable { public function jsonSerialize() { return [ 'id' => $this->id, - 'note' => $this->noteId, - 'user' => $this->sharedUser, - 'group' => $this->sharedGroup + 'noteid' => $this->noteId, + 'shareduser' => $this->sharedUser, + 'sharedgroup' => $this->sharedGroup ]; } } diff --git a/db/sharemapper.php b/db/notesharemapper.php similarity index 93% rename from db/sharemapper.php rename to db/notesharemapper.php index bd295d5..108db20 100644 --- a/db/sharemapper.php +++ b/db/notesharemapper.php @@ -5,10 +5,10 @@ use OCP\IDb; use OCP\AppFramework\Db\Mapper; use OCP\AppFramework\Db\DoesNotExistException; -class ShareMapper extends Mapper { +class NoteShareMapper extends Mapper { public function __construct(IDb $db) { - parent::__construct($db, 'quicknotes_notes', '\OCA\QuickNotes\Db\Share'); + parent::__construct($db, 'quicknotes_notes', '\OCA\QuickNotes\Db\NoteShare'); } /*public function find($id, $userId) { diff --git a/js/script.js b/js/script.js index c23f6ed..84fc763 100644 --- a/js/script.js +++ b/js/script.js @@ -269,6 +269,7 @@ View.prototype = { $("#app-content").on("click", ".quicknote", function (event) { event.stopPropagation(); // Not work so need fix on next binding.. + if($(this).hasClass('shared')) return; //shares don't allow editing var modalnote = $("#modal-note-editable .quicknote"); var modalid = modalnote.data('id'); if (modalid > 0) return; diff --git a/templates/part.note-modal-editable.php b/templates/part.note-modal-editable.php index 0b7216a..634c377 100644 --- a/templates/part.note-modal-editable.php +++ b/templates/part.note-modal-editable.php @@ -5,7 +5,7 @@
- +
diff --git a/templates/part.note.php b/templates/part.note.php index 8cc1875..98b7cd2 100644 --- a/templates/part.note.php +++ b/templates/part.note.php @@ -1,7 +1,12 @@
-
+
+ {{#if isshared}} +
{{{ title }}}
+
{{{ content }}}
+ {{else}}
{{{ title }}}
{{{ content }}}
+ {{/if}}
-
\ No newline at end of file +
From a19bc47bd3173760b88f1cc19bbd2ba7b152aff0 Mon Sep 17 00:00:00 2001 From: Vinzenz Date: Tue, 31 May 2016 17:01:12 +0200 Subject: [PATCH 04/12] delete share if note is deleted --- controller/notecontroller.php | 4 +++- db/notesharemapper.php | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/controller/notecontroller.php b/controller/notecontroller.php index e203012..0b9534f 100644 --- a/controller/notecontroller.php +++ b/controller/notecontroller.php @@ -167,6 +167,8 @@ class NoteController extends Controller { } $oldcolorid = $note->getColorId(); + $this->notesharemapper->deleteByNoteId($note->getId()); + // Delete note. $this->notemapper->delete($note); @@ -178,4 +180,4 @@ class NoteController extends Controller { return new DataResponse($note); } -} \ No newline at end of file +} diff --git a/db/notesharemapper.php b/db/notesharemapper.php index 108db20..3b98571 100644 --- a/db/notesharemapper.php +++ b/db/notesharemapper.php @@ -25,4 +25,9 @@ class NoteShareMapper extends Mapper { $sql = 'SELECT * FROM *PREFIX*quicknotes_shares WHERE shared_group = ?'; return $this->findEntities($sql, [$groupId]); } + + public function deleteByNoteId($noteId) { + $sql = 'DELETE FROM *PREFIX*quicknotes_shares WHERE note_id = ?'; + $this->execute($sql, [$noteId]); + } } From c84dbf4d97a07236dde529faa9d4c1c3d8b574e5 Mon Sep 17 00:00:00 2001 From: Vinzenz Date: Tue, 31 May 2016 17:23:15 +0200 Subject: [PATCH 05/12] add share icon to owner's note as well --- controller/notecontroller.php | 12 +++++++++++- css/style.css | 6 +++++- db/note.php | 2 ++ db/notesharemapper.php | 5 +++++ templates/part.note.php | 3 +++ 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/controller/notecontroller.php b/controller/notecontroller.php index 0b9534f..d142e74 100644 --- a/controller/notecontroller.php +++ b/controller/notecontroller.php @@ -44,7 +44,17 @@ class NoteController extends Controller { public function index() { $notes = $this->notemapper->findAll($this->userId); foreach($notes as $note) { - $note->setIsShared(false); + $note->setIsShared(false); + $sharedWith = $this->notesharemapper->getSharesForNote($note->getId()); + if(count($sharedWith) > 0) { + $shareList = array(); + foreach($sharedWith as $share) { + $shareList[] = $share->getSharedUser(); + } + $note->setSharedWith(implode(", ", $shareList)); + } else { + $note->setSharedWith(null); + } } $shareEntries = $this->notesharemapper->findForUser($this->userId); $shares = array(); diff --git a/css/style.css b/css/style.css index d32cf1a..a55ba50 100644 --- a/css/style.css +++ b/css/style.css @@ -54,12 +54,16 @@ overflow: hidden; } -#div-content .shared-title { +#div-content .shared-title, #div-content .shared-title-owner { float: right; margin: 2px; opacity: 0.5; } +#div-content .shared-title-owner { + margin-right: 25px; +} + .noselect { -webkit-touch-callout: none; /* iOS Safari */ -webkit-user-select: none; /* Chrome/Safari/Opera */ diff --git a/db/note.php b/db/note.php index 1021775..a96095a 100644 --- a/db/note.php +++ b/db/note.php @@ -12,6 +12,7 @@ class Note extends Entity implements JsonSerializable { protected $timestamp; protected $colorId; protected $userId; + protected $sharedWith; protected $isShared; protected $color; @@ -29,6 +30,7 @@ class Note extends Entity implements JsonSerializable { 'colorid' => $this->colorId, 'color' => $this->color, 'userid' => $this->userId, + 'sharedwith' => $this->sharedWith, 'isshared' => $this->isShared ]; } diff --git a/db/notesharemapper.php b/db/notesharemapper.php index 3b98571..0796420 100644 --- a/db/notesharemapper.php +++ b/db/notesharemapper.php @@ -26,6 +26,11 @@ class NoteShareMapper extends Mapper { return $this->findEntities($sql, [$groupId]); } + public function getSharesForNote($noteId) { + $sql = 'SELECT * FROM *PREFIX*quicknotes_shares WHERE note_id = ?'; + return $this->findEntities($sql, [$noteId]); + } + public function deleteByNoteId($noteId) { $sql = 'DELETE FROM *PREFIX*quicknotes_shares WHERE note_id = ?'; $this->execute($sql, [$noteId]); diff --git a/templates/part.note.php b/templates/part.note.php index 98b7cd2..a1d10d9 100644 --- a/templates/part.note.php +++ b/templates/part.note.php @@ -4,6 +4,9 @@
{{{ title }}}
{{{ content }}}
{{else}} + {{#if sharedwith}} +
+ {{/if}}
{{{ title }}}
{{{ content }}}
From 65f56144c08a6ec72ddc90ab6e971feebefd4b22 Mon Sep 17 00:00:00 2001 From: Vinzenz Date: Tue, 31 May 2016 17:46:40 +0200 Subject: [PATCH 06/12] add share filter --- js/script.js | 12 ++++++++++++ templates/part.navigation.php | 2 ++ templates/part.note.php | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/js/script.js b/js/script.js index 84fc763..5b193af 100644 --- a/js/script.js +++ b/js/script.js @@ -385,6 +385,18 @@ View.prototype = { $('#app-navigation .any-color').addClass('icon-checkmark'); }); + $('#shared-with-you').click(function () { + $('.notes-grid').isotope({ filter: function() { + return $(this).children().hasClass('shared'); + } }); + }); + + $('#shared-by-you').click(function () { + $('.notes-grid').isotope({ filter: function() { + return $(this).children().hasClass('shareowner'); + } }); + }); + // create a new note var self = this; $('#new-note').click(function () { diff --git a/templates/part.navigation.php b/templates/part.navigation.php index 247255a..34e5a3c 100644 --- a/templates/part.navigation.php +++ b/templates/part.navigation.php @@ -4,6 +4,8 @@