diff --git a/css/style.scss b/css/style.scss
index 079c112..60abd62 100644
--- a/css/style.scss
+++ b/css/style.scss
@@ -226,7 +226,8 @@ div[contenteditable="true"] {
border: none;
}
-.note-options {
+.note-options,
+.note-disable-options {
padding: 8px;
padding-top: 0px;
}
@@ -249,6 +250,7 @@ div[contenteditable="true"] {
opacity: 0.5;
}
+.slim-share,
.slim-tag {
display: inline-block;
cursor: pointer;
@@ -260,6 +262,7 @@ div[contenteditable="true"] {
font-size: 90%;
}
+.slim-share:hover,
.slim-tag:hover {
background-color: rgba(0,0,0,0.12);
}
diff --git a/js/script.js b/js/script.js
index b54033e..e07930e 100644
--- a/js/script.js
+++ b/js/script.js
@@ -164,11 +164,12 @@ View.prototype = {
this._editableContent(note.content);
this._editablePinned(note.ispinned);
this._editableColor(note.color);
+ this._editableShares(note.shared_by, note.shared_with);
this._editableTags(note.tags);
this._editableAttachts(note.attachts);
// Create medium div editor.
- this._initEditor();
+ this._isEditable(!note.is_shared);
// Show modal editor
this._showEditor(id);
@@ -490,6 +491,12 @@ View.prototype = {
);
});
+ // handle cancel editing notes.
+ $('#modal-note-div #close-button').click(function (event) {
+ event.stopPropagation();
+ self.cancelEdit();
+ });
+
// handle cancel editing notes.
$('#modal-note-div #cancel-button').click(function (event) {
event.stopPropagation();
@@ -655,6 +662,24 @@ View.prototype = {
return digits[1] + '#' + rgb.toString(16).toUpperCase();
},
+ _isEditable: function(editable) {
+ if (editable === undefined)
+ return $('#title-editable').prop('contenteditable');
+ else {
+ if (editable) {
+ $('#title-editable').prop('contenteditable', true);
+ $('#modal-note-div .icon-header-note').show();
+ $('#modal-note-div .note-options').show();
+ $('#modal-note-div .note-disable-options').hide();
+ this._initEditor();
+ } else {
+ $('#modal-note-div .note-options').hide();
+ $('#modal-note-div .icon-header-note').hide();
+ $('#title-editable').removeAttr("contentEditable");
+ $('#modal-note-div .note-disable-options').show();
+ }
+ }
+ },
_editableId: function(id) {
if (id === undefined)
return $("#modal-note-div .quicknote").data('id');
@@ -706,6 +731,19 @@ View.prototype = {
$("#modal-note-div .quicknote").css("background-color", color);
}
},
+ _editableShares: function(shared_by, shared_with) {
+ if (shared_with === undefined) {
+ return $("#modal-note-div .slim-share").toArray().map(function (value) {
+ return {
+ id: value.getAttribute('tag-id'),
+ name: value.textContent.trim()
+ };
+ });
+ } else {
+ var html = Handlebars.templates['shares']({ shared_by: shared_by, shared_with: shared_with});
+ $("#modal-note-div .note-shares").replaceWith(html);
+ }
+ },
_editableTags: function(tags) {
if (tags === undefined) {
return $("#modal-note-div .slim-tag").toArray().map(function (value) {
@@ -797,8 +835,10 @@ View.prototype = {
this._editor = editor;
},
_destroyEditor: function() {
- this._editor.destroy();
- this._editor = undefined;
+ if (this._editor != undefined) {
+ this._editor.destroy();
+ this._editor = undefined;
+ }
this._changed = false;
this._editableId(-1);
@@ -821,7 +861,6 @@ View.prototype = {
"left" : note.offset().left,
"top" : note.offset().top,
"width" : note.width(),
- "min-height": note.height(),
"height:" : "auto"
});
diff --git a/js/templates/notes.handlebars b/js/templates/notes.handlebars
index a05d93e..9b63dd5 100644
--- a/js/templates/notes.handlebars
+++ b/js/templates/notes.handlebars
@@ -2,18 +2,7 @@
{{#each notes}}
-
- {{#if isshared}}
-
-
- {{{ content }}}
-
- {{else}}
+
-
-
+
+
+
+
+
+
+
diff --git a/js/templates/shares.handlebars b/js/templates/shares.handlebars
new file mode 100644
index 0000000..3efea72
--- /dev/null
+++ b/js/templates/shares.handlebars
@@ -0,0 +1,8 @@
+
+ {{#each shared_with}}
+
{{{ shared_user }}}
+ {{/each}}
+ {{#each shared_by}}
+
{{{ user_id }}}
+ {{/each}}
+
\ No newline at end of file
diff --git a/lib/Db/Note.php b/lib/Db/Note.php
index c941ee8..15007da 100644
--- a/lib/Db/Note.php
+++ b/lib/Db/Note.php
@@ -13,7 +13,8 @@ class Note extends Entity implements JsonSerializable {
protected $timestamp;
protected $colorId;
protected $userId;
- protected $sharedWith;
+ protected $sharedWith = [];
+ protected $sharedBy = [];
protected $isShared;
protected $tags;
protected $attachts;
@@ -40,8 +41,9 @@ class Note extends Entity implements JsonSerializable {
'colorid' => $this->colorId,
'color' => $this->color,
'userid' => $this->userId,
- 'sharedwith' => $this->sharedWith,
- 'isshared' => $this->isShared,
+ 'shared_with' => $this->sharedWith,
+ 'shared_by' => $this->sharedBy,
+ 'is_shared' => $this->isShared,
'tags' => $this->tags,
'attachts' => $this->attachts
];
diff --git a/lib/Db/NoteMapper.php b/lib/Db/NoteMapper.php
index 5b7e287..c8ca2a0 100644
--- a/lib/Db/NoteMapper.php
+++ b/lib/Db/NoteMapper.php
@@ -31,6 +31,22 @@ class NoteMapper extends QBMapper {
return $this->findEntity($qb);
}
+ /**
+ * @param int $id
+ * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
+ * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
+ * @return Note
+ */
+ public function findShared($id) {
+ $qb = $this->db->getQueryBuilder();
+ $qb->select('*')
+ ->from($this->tableName)
+ ->where(
+ $qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))
+ );
+ return $this->findEntity($qb);
+ }
+
public function findAll($userId) {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
diff --git a/lib/Db/NoteShare.php b/lib/Db/NoteShare.php
index bf32689..f522a1c 100644
--- a/lib/Db/NoteShare.php
+++ b/lib/Db/NoteShare.php
@@ -8,15 +8,18 @@ use OCP\AppFramework\Db\Entity;
class NoteShare extends Entity implements JsonSerializable {
protected $noteId;
+ protected $userId;
protected $sharedUser;
protected $sharedGroup;
public function jsonSerialize() {
return [
'id' => $this->id,
- 'noteid' => $this->noteId,
- 'shareduser' => $this->sharedUser,
- 'sharedgroup' => $this->sharedGroup
+ 'user_id' => $this->userId,
+ 'note_id' => $this->noteId,
+ 'shared_user' => $this->sharedUser,
+ 'shared_group' => $this->sharedGroup
];
}
+
}
diff --git a/lib/Service/NoteService.php b/lib/Service/NoteService.php
index 9110d85..265b73a 100644
--- a/lib/Service/NoteService.php
+++ b/lib/Service/NoteService.php
@@ -75,50 +75,44 @@ class NoteService {
*/
public function getAll(string $userId): array {
$notes = $this->notemapper->findAll($userId);
+
+ // Set shares with others.
foreach($notes as $note) {
$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);
- }
- $note->setTags($this->tagmapper->getTagsForNote($userId, $note->getId()));
+ $note->setSharedWith($this->notesharemapper->getSharesForNote($note->getId()));
}
- $shareEntries = $this->notesharemapper->findForUser($userId);
- $shares = array();
- foreach($shareEntries as $entry) {
- try {
- //find is only to check if current user is owner
- $this->notemapper->find($entry->getNoteId(), $userId);
- //user is owner, nothing to do
- } catch(\OCP\AppFramework\Db\DoesNotExistException $e) {
- $share = $this->notemapper->findById($entry->getNoteId());
- $share->setIsShared(true);
- $shares[] = $share;
- }
+
+ // Get shares from others.
+ $shares = [];
+ $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;
}
+
+ // Attahch shared notes from others to same response
$notes = array_merge($notes, $shares);
- foreach ($notes as $note) {
- $note->setTitle(strip_tags($note->getTitle()));
+ // Set tags to response.
+ foreach($notes as $note) {
+ $note->setTags($this->tagmapper->getTagsForNote($userId, $note->getId()));
}
- // Insert true color to response
+ // Insert color to response
foreach ($notes as $note) {
$note->setColor($this->colormapper->find($note->getColorId())->getColor());
}
- // Insert true color to response
+ // Insert pin to response
foreach ($notes as $note) {
$note->setIsPinned($note->getPinned() ? true : false);
}
- // Insert true attachts to response
+ // Insert attachts to response.
foreach ($notes as $note) {
$attachts = $this->attachMapper->findFromNote($userId, $note->getId());
foreach ($attachts as $attach) {