diff --git a/appinfo/routes.php b/appinfo/routes.php
index b128998..f7f2340 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -8,6 +8,10 @@ return [
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'note_api#preflighted_cors', 'url' => '/api/0.1/{path}',
'verb' => 'OPTIONS', 'requirements' => ['path' => '.+']],
- ['name' => 'note#get_user_groups_and_users', 'url' => '/api/0.1/getusergroups', 'verb' => 'GET']
+ ['name' => 'note#get_user_groups_and_users', 'url' => '/api/0.1/getusergroups', 'verb' => 'GET'],
+ ['name' => 'note#add_group_share', 'url' => '/api/0.1/groups/addshare', 'verb' => 'POST'],
+ ['name' => 'note#remove_group_share', 'url' => '/api/0.1/groups/removeshare', 'verb' => 'POST'],
+ ['name' => 'note#add_user_share', 'url' => '/api/0.1/users/addshare', 'verb' => 'POST'],
+ ['name' => 'note#remove_user_share', 'url' => '/api/0.1/users/removeshare', 'verb' => 'POST']
]
];
diff --git a/controller/notecontroller.php b/controller/notecontroller.php
index d7699a8..9536de0 100644
--- a/controller/notecontroller.php
+++ b/controller/notecontroller.php
@@ -198,17 +198,64 @@ class NoteController extends Controller {
public function getUserGroupsAndUsers() {
$userMgr = \OC::$server->getUserManager();
$grpMgr = \OC::$server->getGroupManager();
- $igroups = $grpMgr->getUserGroups($userMgr->get($this->userId));
$users = array();
$groups = array();
- foreach($igroups as $g) {
- $iusers = $g->getUsers();
+ if($grpMgr->isAdmin($this->userId)) {
+ $igroups = $grpMgr->search("");
+ $iusers = $userMgr->search("");
+ foreach($igroups as $g) {
+ $groups[] = $g->getGID();
+ }
foreach($iusers as $u) {
$users[] = $u->getUID();
}
- $groups[] = $g->getGID();
+ } else {
+ $igroups = $grpMgr->getUserGroups($userMgr->get($this->userId));
+ foreach($igroups as $g) {
+ $iusers = $g->getUsers();
+ foreach($iusers as $u) {
+ $users[] = $u->getUID();
+ }
+ $groups[] = $g->getGID();
+ }
}
$params = array('groups' => $groups, 'users' => array_unique($users));
return new JSONResponse($params);
}
+
+ /**
+ * @NoAdminRequired
+ */
+ public function addGroupShare($groupId, $noteId) {
+ $share = new NoteShare();
+ $share->setSharedGroup($groupId);
+ $share->setNoteId($noteId);
+ $this->notesharemapper->insert($share);
+ }
+
+ /**
+ * @NoAdminRequired
+ */
+ public function removeGroupShare($groupId, $noteId) {
+ $share = $this->notesharemapper->findByNoteAndGroup($noteId, $groupId);
+ $this->notesharemapper->delete($share);
+ }
+
+ /**
+ * @NoAdminRequired
+ */
+ public function addUserShare($userId, $noteId) {
+ $share = new NoteShare();
+ $share->setSharedUser($userId);
+ $share->setNoteId($noteId);
+ $this->notesharemapper->insert($share);
+ }
+
+ /**
+ * @NoAdminRequired
+ */
+ public function removeUserShare($userId, $noteId) {
+ $share = $this->notesharemapper->findByNoteAndUser($noteId, $userId);
+ $this->notesharemapper->delete($share);
+ }
}
diff --git a/css/style.css b/css/style.css
index 59aa2bc..9ad5126 100644
--- a/css/style.css
+++ b/css/style.css
@@ -153,6 +153,14 @@ div[data-placeholder]:not([data-placeholder=""]):empty::before {
content: attr(data-placeholder);
}
+#note-share-options {
+ display: none;
+}
+
+.selected-share:hover, .unselected-share:hover {
+ cursor: pointer;
+}
+
/* Modal Content */
.modal-content {
diff --git a/db/notesharemapper.php b/db/notesharemapper.php
index 0796420..aefbd45 100644
--- a/db/notesharemapper.php
+++ b/db/notesharemapper.php
@@ -8,7 +8,7 @@ use OCP\AppFramework\Db\DoesNotExistException;
class NoteShareMapper extends Mapper {
public function __construct(IDb $db) {
- parent::__construct($db, 'quicknotes_notes', '\OCA\QuickNotes\Db\NoteShare');
+ parent::__construct($db, 'quicknotes_shares', '\OCA\QuickNotes\Db\NoteShare');
}
/*public function find($id, $userId) {
@@ -26,6 +26,16 @@ class NoteShareMapper extends Mapper {
return $this->findEntities($sql, [$groupId]);
}
+ public function findByNoteAndUser($noteId, $userId) {
+ $sql = 'SELECT * FROM *PREFIX*quicknotes_shares WHERE shared_user = ? AND note_id = ?';
+ return $this->findEntity($sql, [$userId, $noteId]);
+ }
+
+ public function findByNoteAndGroup($noteId, $groupId) {
+ $sql = 'SELECT * FROM *PREFIX*quicknotes_shares WHERE shared_group = ? AND note_id = ?';
+ return $this->findEntity($sql, [$groupId, $noteId]);
+ }
+
public function getSharesForNote($noteId) {
$sql = 'SELECT * FROM *PREFIX*quicknotes_shares WHERE note_id = ?';
return $this->findEntities($sql, [$noteId]);
diff --git a/js/script.js b/js/script.js
index 8feba8f..2096d10 100644
--- a/js/script.js
+++ b/js/script.js
@@ -24,6 +24,65 @@ var Notes = function (baseUrl) {
this._activeNote = undefined;
};
+var moveToUnselectedShare = function() {
+ var curr = $(this).clone();
+ var groupIndex = curr.html().indexOf('(group)');
+ var id = $('.note-active').data('id');
+ if(groupIndex >= 0) {
+ var groupId = curr.html().substring(0, groupIndex);
+ var formData = {
+ groupId : groupId,
+ noteId : id
+ };
+ $.post(OC.generateUrl('/apps/quicknotes/api/0.1/groups/removeshare'), formData, function(data){
+ });
+ } else {
+ var userId = curr.html();
+ var formData = {
+ userId : userId,
+ noteId : id
+ };
+ $.post(OC.generateUrl('/apps/quicknotes/api/0.1/users/removeshare'), formData, function(data){
+ });
+ }
+ curr.switchClass('selected-share', 'unselected-share', 0);
+ curr.hide();
+ curr.click(moveToSelectedShare);
+ $(curr).appendTo($('#share-neg'));
+ $(this).remove();
+ var pos = $('#share-pos');
+ if(pos.children().length == 0) pos.hide();
+}
+
+var moveToSelectedShare = function() {
+ var curr = $(this).clone();
+ var groupIndex = curr.html().indexOf('(group)');
+ var id = $('.note-active').data('id');
+ if(groupIndex >= 0) {
+ var groupId = curr.html().substring(0, groupIndex);
+ var formData = {
+ groupId : groupId,
+ noteId : id
+ };
+ $.post(OC.generateUrl('/apps/quicknotes/api/0.1/groups/addshare'), formData, function(data){
+ });
+ } else {
+ var userId = curr.html();
+ var formData = {
+ userId : userId,
+ noteId : id
+ };
+ $.post(OC.generateUrl('/apps/quicknotes/api/0.1/users/addshare'), formData, function(data){
+ });
+ }
+ curr.switchClass('unselected-share', 'selected-share', 0);
+ curr.click(moveToUnselectedShare);
+ $(curr).appendTo($('#share-pos'));
+ $(this).remove();
+ $('#share-pos').show();
+ $('#share-search').val('');
+}
+
Notes.prototype = {
load: function (id) {
var self = this;
@@ -346,10 +405,51 @@ View.prototype = {
// handle share editing notes.
$('#modal-note-div #share-button').click(function (event) {
$.get(OC.generateUrl('/apps/quicknotes/api/0.1/getusergroups'), function(data) {
+ var shareOptions = $('#note-share-options');
var groups = data.groups;
var users = data.users;
- alert('groups: ' + groups.toSource());
- alert('users: ' + users.toSource());
+ var neg = $('#share-neg');
+ var pos = $('#share-pos');
+ var sear = $('#share-search');
+ for(var i=0; i= 0) {
+ $(lis[i]).show();
+ } else {
+ $(lis[i]).hide();
+ }
+ }
+ }
+ });
});
});
diff --git a/templates/part.note-modal-editable.php b/templates/part.note-modal-editable.php
index de186c7..c486d51 100644
--- a/templates/part.note-modal-editable.php
+++ b/templates/part.note-modal-editable.php
@@ -10,6 +10,13 @@
+
-
-
-