add basich sharing functionality logic

This commit is contained in:
Vinzenz
2016-05-31 14:16:43 +02:00
parent 9eede1756d
commit df3db489f4
9 changed files with 49 additions and 15 deletions

View File

@@ -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());

View File

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

View File

@@ -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
];
}
}

View File

@@ -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]);

View File

@@ -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
];
}
}

View File

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

View File

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

View File

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

View File

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