mirror of
https://github.com/JanGross/quicknotes.git
synced 2025-12-01 07:37:18 +01:00
Missiong update on note in grid, but now you can create tags in the modal.. =)
This commit is contained in:
@@ -72,7 +72,7 @@ class NoteController extends Controller {
|
|||||||
} else {
|
} else {
|
||||||
$note->setSharedWith(null);
|
$note->setSharedWith(null);
|
||||||
}
|
}
|
||||||
$note->setTags($this->tagmapper->getTagsForNote($note->getId()));
|
$note->setTags($this->tagmapper->getTagsForNote($this->userId, $note->getId()));
|
||||||
}
|
}
|
||||||
$shareEntries = $this->notesharemapper->findForUser($this->userId);
|
$shareEntries = $this->notesharemapper->findForUser($this->userId);
|
||||||
$shares = array();
|
$shares = array();
|
||||||
@@ -147,7 +147,7 @@ class NoteController extends Controller {
|
|||||||
* @param string $content
|
* @param string $content
|
||||||
* @param string $color
|
* @param string $color
|
||||||
*/
|
*/
|
||||||
public function update($id, $title, $content, $color = "#F7EB96") {
|
public function update($id, $title, $content, $tags, $color = "#F7EB96") {
|
||||||
// Get current Note and Color.
|
// Get current Note and Color.
|
||||||
try {
|
try {
|
||||||
$note = $this->notemapper->find($id, $this->userId);
|
$note = $this->notemapper->find($id, $this->userId);
|
||||||
@@ -165,6 +165,36 @@ class NoteController extends Controller {
|
|||||||
$hcolor = $this->colormapper->insert($hcolor);
|
$hcolor = $this->colormapper->insert($hcolor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete old tag relations
|
||||||
|
$noteTags = $this->tagmapper->getTagsForNote($this->userId, $id);
|
||||||
|
foreach ($noteTags as $tag) {
|
||||||
|
if (!in_array($tag->getName(), $tags)) {
|
||||||
|
$hnotetag = $this->notetagmapper->findNoteTag($this->userId, $id, $tag->getId());
|
||||||
|
$this->notetagmapper->delete($hnotetag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add new tags and update relations.
|
||||||
|
foreach ($tags as $name) {
|
||||||
|
if (!$this->tagmapper->tagExists($this->userId, $name)) {
|
||||||
|
$htag = new Tag();
|
||||||
|
$htag->setName($name);
|
||||||
|
$htag->setUserId($this->userId);
|
||||||
|
$htag = $this->tagmapper->insert($htag);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$htag = $this->tagmapper->getTag($this->userId, $name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->notetagmapper->noteTagExists($this->userId, $id, $htag->getId())) {
|
||||||
|
$noteTag = new NoteTag();
|
||||||
|
$noteTag->setNoteId($id);
|
||||||
|
$noteTag->setTagId($htag->getId());
|
||||||
|
$noteTag->setUserId($this->userId);
|
||||||
|
$this->notetagmapper->insert($noteTag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Set new info on Note
|
// Set new info on Note
|
||||||
$note->setTitle($title);
|
$note->setTitle($title);
|
||||||
$note->setContent($content);
|
$note->setContent($content);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use OCP\AppFramework\Db\Entity;
|
|||||||
class NoteTag extends Entity implements JsonSerializable {
|
class NoteTag extends Entity implements JsonSerializable {
|
||||||
|
|
||||||
protected $noteId;
|
protected $noteId;
|
||||||
protected $tagId
|
protected $tagId;
|
||||||
protected $userId;
|
protected $userId;
|
||||||
|
|
||||||
public function jsonSerialize() {
|
public function jsonSerialize() {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use OCP\AppFramework\Db\Mapper;
|
|||||||
class NoteTagMapper extends Mapper {
|
class NoteTagMapper extends Mapper {
|
||||||
|
|
||||||
public function __construct(IDBConnection $db) {
|
public function __construct(IDBConnection $db) {
|
||||||
parent::__construct($db, 'quicknotes_note_tags', '\OCA\QuickNotes\Db\Tag');
|
parent::__construct($db, 'quicknotes_note_tags', '\OCA\QuickNotes\Db\NoteTag');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function find($id, $userId) {
|
public function find($id, $userId) {
|
||||||
@@ -20,4 +20,19 @@ class NoteTagMapper extends Mapper {
|
|||||||
return $this->findEntities($sql, [$userId]);
|
return $this->findEntities($sql, [$userId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function findNoteTag($userId, $noteId, $tagId) {
|
||||||
|
$sql = 'SELECT * FROM *PREFIX*quicknotes_note_tags WHERE user_id = ? AND note_id = ? AND tag_id = ?';
|
||||||
|
return $this->findEntity($sql, [$userId, $noteId, $tagId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function noteTagExists($userId, $noteId, $tagId) {
|
||||||
|
$sql = 'SELECT * FROM *PREFIX*quicknotes_note_tags WHERE user_id = ? AND note_id = ? AND tag_id = ?';
|
||||||
|
try {
|
||||||
|
return $this->findEntities($sql, [$userId, $noteId, $tagId]);
|
||||||
|
} catch (DoesNotExistException $e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -20,12 +20,27 @@ class TagMapper extends Mapper {
|
|||||||
return $this->findEntities($sql, [$userId]);
|
return $this->findEntities($sql, [$userId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTagsForNote ($noteId) {
|
public function getTagsForNote($userId, $noteId) {
|
||||||
$sql = 'SELECT T.id, T.name FROM *PREFIX*quicknotes_tags T ';
|
$sql = 'SELECT T.id, T.name FROM *PREFIX*quicknotes_tags T ';
|
||||||
$sql.= 'INNER JOIN *PREFIX*quicknotes_note_tags NT ';
|
$sql.= 'INNER JOIN *PREFIX*quicknotes_note_tags NT ';
|
||||||
$sql.= 'ON T.id = NT.tag_id ';
|
$sql.= 'ON T.id = NT.tag_id ';
|
||||||
$sql.= 'WHERE NT.note_id = ?';
|
$sql.= 'WHERE NT.user_id = ? AND NT.note_id = ?';
|
||||||
return $this->findEntities($sql, [$noteId]);
|
return $this->findEntities($sql, [$userId, $noteId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTag($userId, $name) {
|
||||||
|
$sql = 'SELECT * FROM *PREFIX*quicknotes_tags WHERE user_id = ? AND name = ?';
|
||||||
|
return $this->findEntity($sql, [$userId, $name]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tagExists($userId, $name) {
|
||||||
|
$sql = 'SELECT * FROM *PREFIX*quicknotes_tags WHERE user_id = ? AND name = ?';
|
||||||
|
try {
|
||||||
|
return $this->findEntities($sql, [$userId, $name]);
|
||||||
|
} catch (DoesNotExistException $e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
12
js/script.js
12
js/script.js
@@ -126,10 +126,11 @@ Notes.prototype = {
|
|||||||
isLoaded: function () {
|
isLoaded: function () {
|
||||||
return this._loaded;
|
return this._loaded;
|
||||||
},
|
},
|
||||||
updateActive: function (title, content, color) {
|
updateActive: function (title, content, tags, color) {
|
||||||
var note = this.getActive();
|
var note = this.getActive();
|
||||||
note.title = title;
|
note.title = title;
|
||||||
note.content = content;
|
note.content = content;
|
||||||
|
note.tags = tags;
|
||||||
note.color = color;
|
note.color = color;
|
||||||
|
|
||||||
return $.ajax({
|
return $.ajax({
|
||||||
@@ -139,9 +140,9 @@ Notes.prototype = {
|
|||||||
data: JSON.stringify(note)
|
data: JSON.stringify(note)
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
updateId: function (id, title, content, color) {
|
updateId: function (id, title, content, tags, color) {
|
||||||
this.load(id);
|
this.load(id);
|
||||||
return this.updateActive(title, content, color);
|
return this.updateActive(title, content, tags, color);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -328,6 +329,9 @@ View.prototype = {
|
|||||||
var title = $('#modal-note-div #title-editable').html().trim();
|
var title = $('#modal-note-div #title-editable').html().trim();
|
||||||
var content = $('#modal-note-div #content-editable').html().trim();
|
var content = $('#modal-note-div #content-editable').html().trim();
|
||||||
var color = this.colorToHex($("#modal-note-div .quicknote").css("background-color"));
|
var color = this.colorToHex($("#modal-note-div .quicknote").css("background-color"));
|
||||||
|
var tags = $("#modal-note-div .slim-tag").toArray().map(function (value) {
|
||||||
|
return value.textContent.trim();
|
||||||
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
var shareSelect = $('.note-share-select');
|
var shareSelect = $('.note-share-select');
|
||||||
@@ -343,7 +347,7 @@ View.prototype = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
this._notes.updateId(id, title, content, color).done(function () {
|
this._notes.updateId(id, title, content, tags, color).done(function () {
|
||||||
var modal = $('#modal-note-div');
|
var modal = $('#modal-note-div');
|
||||||
var modalnote = $("#modal-note-div .quicknote");
|
var modalnote = $("#modal-note-div .quicknote");
|
||||||
var modaltitle = $('#modal-note-div #title-editable');
|
var modaltitle = $('#modal-note-div #title-editable');
|
||||||
|
|||||||
Reference in New Issue
Block a user