mirror of
https://github.com/JanGross/quicknotes.git
synced 2025-12-01 07:37:18 +01:00
add basic sharing dialog and enable group sharing
This commit is contained in:
@@ -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']
|
||||
]
|
||||
];
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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]);
|
||||
|
||||
104
js/script.js
104
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('<span>(group)</span>');
|
||||
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('<span>(group)</span>');
|
||||
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<groups.length; i++) {
|
||||
var li = document.createElement('li');
|
||||
li.appendChild(document.createTextNode(groups[i]));
|
||||
var sp = document.createElement('span');
|
||||
sp.appendChild(document.createTextNode('(group)'));
|
||||
li.className = "unselected-share";
|
||||
li.appendChild(sp);
|
||||
$(li).hide();
|
||||
neg[0].appendChild(li);
|
||||
}
|
||||
for(var i=0; i<users.length; i++) {
|
||||
var li = document.createElement('li');
|
||||
li.appendChild(document.createTextNode(users[i]));
|
||||
li.className = "unselected-share";
|
||||
$(li).hide();
|
||||
neg[0].appendChild(li);
|
||||
}
|
||||
|
||||
$('.unselected-share').click(moveToSelectedShare);
|
||||
$('.selected-share').click(moveToUnselectedShare);
|
||||
|
||||
shareOptions.show();
|
||||
var modalNote = $('.note-active');
|
||||
modalNote.outerHeight(modalNote.outerHeight(true) + shareOptions.outerHeight(true));
|
||||
sear.on('input', function() {
|
||||
var val = $(this).val().toLowerCase().trim();
|
||||
var lis = neg.children();
|
||||
if(val.length == 0) {
|
||||
lis.hide();
|
||||
} else {
|
||||
for(var i=0; i<lis.length; i++) {
|
||||
if(lis[i].innerHTML.toLowerCase().indexOf(val) >= 0) {
|
||||
$(lis[i]).show();
|
||||
} else {
|
||||
$(lis[i]).hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -10,6 +10,13 @@
|
||||
<button id='cancel-button'><?php p($l->t('Cancel')); ?></button>
|
||||
<button id='save-button'><?php p($l->t('Save')); ?></button>
|
||||
</div>
|
||||
<div id="note-share-options">
|
||||
<ul id="share-pos">
|
||||
</ul>
|
||||
<input type="text" id="share-search" />
|
||||
<ul id="share-neg">
|
||||
</ul>
|
||||
</div>
|
||||
<div class="note-toolbar">
|
||||
<a href="#" class="circle-toolbar" style="background-color: #F7EB96"></a>
|
||||
<a href="#" class="circle-toolbar" style="background-color: #88B7E3"></a>
|
||||
@@ -22,9 +29,6 @@
|
||||
<a href="#" class="circle-toolbar" style="background-color: #C1D756"></a>
|
||||
<a href="#" class="circle-toolbar" style="background-color: #CECECE"></a>
|
||||
</div>
|
||||
<div id="note-share-options">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user