mirror of
https://github.com/JanGross/quicknotes.git
synced 2025-11-30 23:37:16 +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\Note;
|
||||||
use OCA\QuickNotes\Db\Color;
|
use OCA\QuickNotes\Db\Color;
|
||||||
|
use OCA\QuickNotes\Db\NoteShare;
|
||||||
use OCA\QuickNotes\Db\NoteMapper;
|
use OCA\QuickNotes\Db\NoteMapper;
|
||||||
use OCA\QuickNotes\Db\ColorMapper;
|
use OCA\QuickNotes\Db\ColorMapper;
|
||||||
|
use OCA\QuickNotes\Db\NoteShareMapper;
|
||||||
|
|
||||||
class NoteController extends Controller {
|
class NoteController extends Controller {
|
||||||
|
|
||||||
private $notemapper;
|
private $notemapper;
|
||||||
private $colormapper;
|
private $colormapper;
|
||||||
|
private $notesharemapper;
|
||||||
private $userId;
|
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);
|
parent::__construct($AppName, $request);
|
||||||
$this->notemapper = $notemapper;
|
$this->notemapper = $notemapper;
|
||||||
$this->colormapper = $colormapper;
|
$this->colormapper = $colormapper;
|
||||||
|
$this->notesharemapper = $notesharemapper;
|
||||||
$this->userId = $UserId;
|
$this->userId = $UserId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,6 +43,18 @@ class NoteController extends Controller {
|
|||||||
*/
|
*/
|
||||||
public function index() {
|
public function index() {
|
||||||
$notes = $this->notemapper->findAll($this->userId);
|
$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
|
// Insert true color to response
|
||||||
foreach ($notes as $note) {
|
foreach ($notes as $note) {
|
||||||
$note->setColor($this->colormapper->find($note->getColorId())->getColor());
|
$note->setColor($this->colormapper->find($note->getColorId())->getColor());
|
||||||
|
|||||||
@@ -47,8 +47,6 @@
|
|||||||
/* Grid Note */
|
/* Grid Note */
|
||||||
|
|
||||||
#div-content .note-title {
|
#div-content .note-title {
|
||||||
height: 28px;
|
|
||||||
width: calc(100% - 20px);
|
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
@@ -56,6 +54,12 @@
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#div-content .shared-title {
|
||||||
|
float: right;
|
||||||
|
margin: 2px;
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
.noselect {
|
.noselect {
|
||||||
-webkit-touch-callout: none; /* iOS Safari */
|
-webkit-touch-callout: none; /* iOS Safari */
|
||||||
-webkit-user-select: none; /* Chrome/Safari/Opera */
|
-webkit-user-select: none; /* Chrome/Safari/Opera */
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ class Note extends Entity implements JsonSerializable {
|
|||||||
protected $timestamp;
|
protected $timestamp;
|
||||||
protected $colorId;
|
protected $colorId;
|
||||||
protected $userId;
|
protected $userId;
|
||||||
|
protected $isShared;
|
||||||
|
|
||||||
protected $color;
|
protected $color;
|
||||||
|
|
||||||
@@ -26,7 +27,9 @@ class Note extends Entity implements JsonSerializable {
|
|||||||
'content' => $this->content,
|
'content' => $this->content,
|
||||||
'timestamp' => $this->timestamp,
|
'timestamp' => $this->timestamp,
|
||||||
'colorid' => $this->colorId,
|
'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]);
|
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) {
|
public function findAll($userId) {
|
||||||
$sql = 'SELECT * FROM *PREFIX*quicknotes_notes WHERE user_id = ?';
|
$sql = 'SELECT * FROM *PREFIX*quicknotes_notes WHERE user_id = ?';
|
||||||
return $this->findEntities($sql, [$userId]);
|
return $this->findEntities($sql, [$userId]);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use JsonSerializable;
|
|||||||
|
|
||||||
use OCP\AppFramework\Db\Entity;
|
use OCP\AppFramework\Db\Entity;
|
||||||
|
|
||||||
class Share extends Entity implements JsonSerializable {
|
class NoteShare extends Entity implements JsonSerializable {
|
||||||
|
|
||||||
protected $noteId;
|
protected $noteId;
|
||||||
protected $sharedUser;
|
protected $sharedUser;
|
||||||
@@ -14,9 +14,9 @@ class Share extends Entity implements JsonSerializable {
|
|||||||
public function jsonSerialize() {
|
public function jsonSerialize() {
|
||||||
return [
|
return [
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'note' => $this->noteId,
|
'noteid' => $this->noteId,
|
||||||
'user' => $this->sharedUser,
|
'shareduser' => $this->sharedUser,
|
||||||
'group' => $this->sharedGroup
|
'sharedgroup' => $this->sharedGroup
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,10 +5,10 @@ use OCP\IDb;
|
|||||||
use OCP\AppFramework\Db\Mapper;
|
use OCP\AppFramework\Db\Mapper;
|
||||||
use OCP\AppFramework\Db\DoesNotExistException;
|
use OCP\AppFramework\Db\DoesNotExistException;
|
||||||
|
|
||||||
class ShareMapper extends Mapper {
|
class NoteShareMapper extends Mapper {
|
||||||
|
|
||||||
public function __construct(IDb $db) {
|
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) {
|
/*public function find($id, $userId) {
|
||||||
@@ -269,6 +269,7 @@ View.prototype = {
|
|||||||
$("#app-content").on("click", ".quicknote", function (event) {
|
$("#app-content").on("click", ".quicknote", function (event) {
|
||||||
event.stopPropagation(); // Not work so need fix on next binding..
|
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 modalnote = $("#modal-note-editable .quicknote");
|
||||||
var modalid = modalnote.data('id');
|
var modalid = modalnote.data('id');
|
||||||
if (modalid > 0) return;
|
if (modalid > 0) return;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<div contenteditable="true" id='content-editable' class='note-content' data-placeholder="No content"></div>
|
<div contenteditable="true" id='content-editable' class='note-content' data-placeholder="No content"></div>
|
||||||
<div class="note-options">
|
<div class="note-options">
|
||||||
<div class="save-button">
|
<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='cancel-button'><?php p($l->t('Cancel')); ?></button>
|
||||||
<button id='save-button'><?php p($l->t('Save')); ?></button>
|
<button id='save-button'><?php p($l->t('Save')); ?></button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
<div class="note-grid-item">
|
<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>
|
<div id='title-editable' class='note-title'>{{{ title }}}</div>
|
||||||
<button class="icon-delete hide-delete-icon icon-delete-note" title="Delete"></button>
|
<button class="icon-delete hide-delete-icon icon-delete-note" title="Delete"></button>
|
||||||
<div id='content-editable' class='note-content'>{{{ content }}}</div>
|
<div id='content-editable' class='note-content'>{{{ content }}}</div>
|
||||||
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
Reference in New Issue
Block a user