mirror of
https://github.com/JanGross/quicknotes.git
synced 2025-12-01 15:47:17 +01:00
add basich sharing functionality logic
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
@@ -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;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<div contenteditable="true" id='content-editable' class='note-content' data-placeholder="No content"></div>
|
||||
<div class="note-options">
|
||||
<div class="save-button">
|
||||
<button id='share-button' class='icon-share'><?php p($l->t('Share'));?></button>
|
||||
<button id='share-button'><?php p($l->t('Share'));?></button>
|
||||
<button id='cancel-button'><?php p($l->t('Cancel')); ?></button>
|
||||
<button id='save-button'><?php p($l->t('Save')); ?></button>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
<div class="note-grid-item">
|
||||
<div class="quicknote noselect {{#if active}}note-active{{/if}}" style="background-color: {{color}}" data-id="{{ id }}" data-timestamp="{{ timestamp }}" >
|
||||
<div class="quicknote noselect {{#if active}}note-active{{/if}} {{#if isshared}}shared{{/if}}" style="background-color: {{color}}" data-id="{{ id }}" data-timestamp="{{ timestamp }}" >
|
||||
{{#if isshared}}
|
||||
<div class='icon-share shared-title' title="shared with you by {{ userid }}"></div><div id='title' class='note-title'>{{{ title }}}</div>
|
||||
<div id='content' class='note-content'>{{{ content }}}</div>
|
||||
{{else}}
|
||||
<div id='title-editable' class='note-title'>{{{ title }}}</div>
|
||||
<button class="icon-delete hide-delete-icon icon-delete-note" title="Delete"></button>
|
||||
<div id='content-editable' class='note-content'>{{{ content }}}</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user