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 @@