mirror of
https://github.com/JanGross/quicknotes.git
synced 2025-12-01 07:37:18 +01:00
Use display name of users to share dialog and notes. See issue #49
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* @copyright 2019-2020 Matias De lellis <mati86dl@gmail.com>
|
* @copyright 2019-2022 Matias De lellis <mati86dl@gmail.com>
|
||||||
*
|
*
|
||||||
* @author 2019 Matias De lellis <mati86dl@gmail.com>
|
* @author 2019 Matias De lellis <mati86dl@gmail.com>
|
||||||
*
|
*
|
||||||
@@ -159,7 +159,7 @@ const QnDialogs = {
|
|||||||
var data = [];
|
var data = [];
|
||||||
availableUsers.forEach(function (item, index) {
|
availableUsers.forEach(function (item, index) {
|
||||||
// Select2 expect id, text.
|
// Select2 expect id, text.
|
||||||
data.push({id: item, text: item});
|
data.push({id: item[0], text: item[1]});
|
||||||
});
|
});
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
@@ -168,7 +168,7 @@ const QnDialogs = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
input.val(selectedUsers.map(function (value) { return value.shared_user }));
|
input.val(selectedUsers.map(function (value) { return value.id }));
|
||||||
input.trigger("change");
|
input.trigger("change");
|
||||||
|
|
||||||
$('.select2-input').on("keyup", function (event) {
|
$('.select2-input').on("keyup", function (event) {
|
||||||
@@ -208,7 +208,9 @@ const QnDialogs = {
|
|||||||
// Quicknotes shares expect id, shared_user
|
// Quicknotes shares expect id, shared_user
|
||||||
newUsers = input.select2("data");
|
newUsers = input.select2("data");
|
||||||
newUsers.forEach(function (item) {
|
newUsers.forEach(function (item) {
|
||||||
item['shared_user'] = item.text;
|
item['shared_user'] = item.id;
|
||||||
|
item['display_name'] = item.text;
|
||||||
|
|
||||||
users.push(item);
|
users.push(item);
|
||||||
});
|
});
|
||||||
callback(true, users);
|
callback(true, users);
|
||||||
|
|||||||
14
js/script.js
14
js/script.js
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* @copyright 2016-2020 Matias De lellis <mati86dl@gmail.com>
|
* @copyright 2016-2022 Matias De lellis <mati86dl@gmail.com>
|
||||||
*
|
*
|
||||||
* @author 2016 Matias De lellis <mati86dl@gmail.com>
|
* @author 2016 Matias De lellis <mati86dl@gmail.com>
|
||||||
*
|
*
|
||||||
@@ -169,10 +169,10 @@ Notes.prototype = {
|
|||||||
}).done(function (shares) {
|
}).done(function (shares) {
|
||||||
var users = [];
|
var users = [];
|
||||||
$.each(shares.ocs.data.exact.users, function(index, user) {
|
$.each(shares.ocs.data.exact.users, function(index, user) {
|
||||||
users.push(user.value.shareWith);
|
users.push([user.value.shareWith, user.label]);
|
||||||
});
|
});
|
||||||
$.each(shares.ocs.data.users, function(index, user) {
|
$.each(shares.ocs.data.users, function(index, user) {
|
||||||
users.push(user.value.shareWith);
|
users.push([user.value.shareWith, user.label]);
|
||||||
});
|
});
|
||||||
self._usersSharing = users;
|
self._usersSharing = users;
|
||||||
}).fail(function () {
|
}).fail(function () {
|
||||||
@@ -233,6 +233,7 @@ View.prototype = {
|
|||||||
tags: this._editableTags(),
|
tags: this._editableTags(),
|
||||||
sharedWith: this._editableShares()
|
sharedWith: this._editableShares()
|
||||||
};
|
};
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
this._notes.update(fakeNote).done(function (note) {
|
this._notes.update(fakeNote).done(function (note) {
|
||||||
// Create an new note and replace in grid.
|
// Create an new note and replace in grid.
|
||||||
@@ -530,6 +531,12 @@ View.prototype = {
|
|||||||
$('#modal-note-div #tag-button').trigger( "click");
|
$('#modal-note-div #tag-button').trigger( "click");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Handle shares on modal
|
||||||
|
$('#modal-note-div').on("click", ".slim-share", function (event) {
|
||||||
|
event.stopPropagation();
|
||||||
|
$('#modal-note-div #share-button').trigger( "click");
|
||||||
|
});
|
||||||
|
|
||||||
// handle tags button.
|
// handle tags button.
|
||||||
$('#modal-note-div').on("click", "#share-button", function (event) {
|
$('#modal-note-div').on("click", "#share-button", function (event) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
@@ -545,6 +552,7 @@ View.prototype = {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// handle color button.
|
||||||
$('#modal-note-div').on("click", "#color-button", function (event) {
|
$('#modal-note-div').on("click", "#color-button", function (event) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
self._colorPick.toggle();
|
self._colorPick.toggle();
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class='note-shares'>
|
<div class='note-shares'>
|
||||||
{{#each sharedWith}}
|
{{#each sharedWith}}
|
||||||
<div class="icon-user slim-share" share-id="{{ shared_user }}" title="Shared with {{ shared_user }}">{{{ shared_user }}}</div>
|
<div class="icon-user slim-share" share-id="{{ shared_user }}" title="Shared with {{ display_name }}">{{{ display_name }}}</div>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</div>
|
</div>
|
||||||
<div class='note-tags'>
|
<div class='note-tags'>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<div class='note-body'>
|
<div class='note-body'>
|
||||||
<div>
|
<div>
|
||||||
{{#if sharedBy}}
|
{{#if sharedBy}}
|
||||||
<div class="icon-header-note icon-share" title="{{tSB sharedBy.0.user_id}}"></div>
|
<div class="icon-header-note icon-share" title="{{tSB sharedBy.0.display_name}}"></div>
|
||||||
<div class="icon-header-note icon-delete hide-header-icon icon-delete-note" title="{{t "quicknotes" "Leave this shared note"}}"></div>
|
<div class="icon-header-note icon-delete hide-header-icon icon-delete-note" title="{{t "quicknotes" "Leave this shared note"}}"></div>
|
||||||
{{else}}
|
{{else}}
|
||||||
{{#if isPinned}}
|
{{#if isPinned}}
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class='note-shares'>
|
<div class='note-shares'>
|
||||||
{{#each sharedWith}}
|
{{#each sharedWith}}
|
||||||
<div class="icon-user slim-share" share-id="{{ shared_user }}" title="{{tSW shared_user}}">{{{ shared_user }}}</div>
|
<div class="icon-user slim-share" share-id="{{ shared_user }}" title="{{tSW display_name}}">{{{ display_name }}}</div>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</div>
|
</div>
|
||||||
<div class='note-tags'>
|
<div class='note-tags'>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<div class='note-shares'>
|
<div class='note-shares'>
|
||||||
{{#each sharedWith}}
|
{{#each sharedWith}}
|
||||||
<div class="icon-user slim-share" share-id="{{ shared_user }}" title="{{tSW shared_user}}">{{{ shared_user }}}</div>
|
<div class="icon-user slim-share" share-id="{{ shared_user }}" title="{{tSW display_name}}">{{{ display_name }}}</div>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</div>
|
</div>
|
||||||
@@ -20,18 +20,24 @@ class NoteShare extends Entity implements JsonSerializable {
|
|||||||
protected $sharedGroup;
|
protected $sharedGroup;
|
||||||
|
|
||||||
protected $userId;
|
protected $userId;
|
||||||
|
protected $displayname;
|
||||||
|
|
||||||
public function setUserId (string $userId): void {
|
public function setUserId (string $userId): void {
|
||||||
$this->userId = $userId;
|
$this->userId = $userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setDisplayName (string $displayName): void {
|
||||||
|
$this->displayName = $displayName;
|
||||||
|
}
|
||||||
|
|
||||||
public function jsonSerialize() {
|
public function jsonSerialize() {
|
||||||
return [
|
return [
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'note_id' => $this->noteId,
|
'note_id' => $this->noteId,
|
||||||
'shared_user' => $this->sharedUser,
|
'shared_user' => $this->sharedUser,
|
||||||
'shared_group' => $this->sharedGroup,
|
'shared_group' => $this->sharedGroup,
|
||||||
'user_id' => $this->userId
|
'user_id' => $this->userId,
|
||||||
|
'display_name' => $this->displayName
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
* @copyright 2016-2020 Matias De lellis <mati86dl@gmail.com>
|
* @copyright 2016-2022 Matias De lellis <mati86dl@gmail.com>
|
||||||
*
|
*
|
||||||
* @author 2016 Matias De lellis <mati86dl@gmail.com>
|
* @author 2016 Matias De lellis <mati86dl@gmail.com>
|
||||||
*
|
*
|
||||||
@@ -45,6 +45,8 @@ use OCA\QuickNotes\Service\SettingsService;
|
|||||||
|
|
||||||
use OCP\AppFramework\Db\DoesNotExistException;
|
use OCP\AppFramework\Db\DoesNotExistException;
|
||||||
|
|
||||||
|
use OCP\IUserManager;
|
||||||
|
|
||||||
class NoteService {
|
class NoteService {
|
||||||
|
|
||||||
private $notemapper;
|
private $notemapper;
|
||||||
@@ -56,6 +58,9 @@ class NoteService {
|
|||||||
private $fileService;
|
private $fileService;
|
||||||
private $settingsService;
|
private $settingsService;
|
||||||
|
|
||||||
|
/** @var IUserManager */
|
||||||
|
private $userManager;
|
||||||
|
|
||||||
public function __construct(NoteMapper $notemapper,
|
public function __construct(NoteMapper $notemapper,
|
||||||
NoteTagMapper $notetagmapper,
|
NoteTagMapper $notetagmapper,
|
||||||
NoteShareMapper $noteShareMapper,
|
NoteShareMapper $noteShareMapper,
|
||||||
@@ -63,7 +68,8 @@ class NoteService {
|
|||||||
AttachMapper $attachMapper,
|
AttachMapper $attachMapper,
|
||||||
TagMapper $tagmapper,
|
TagMapper $tagmapper,
|
||||||
FileService $fileService,
|
FileService $fileService,
|
||||||
SettingsService $settingsService)
|
SettingsService $settingsService,
|
||||||
|
IUserManager $userManager)
|
||||||
{
|
{
|
||||||
$this->notemapper = $notemapper;
|
$this->notemapper = $notemapper;
|
||||||
$this->notetagmapper = $notetagmapper;
|
$this->notetagmapper = $notetagmapper;
|
||||||
@@ -73,6 +79,7 @@ class NoteService {
|
|||||||
$this->tagmapper = $tagmapper;
|
$this->tagmapper = $tagmapper;
|
||||||
$this->fileService = $fileService;
|
$this->fileService = $fileService;
|
||||||
$this->settingsService = $settingsService;
|
$this->settingsService = $settingsService;
|
||||||
|
$this->userManager = $userManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,7 +90,19 @@ class NoteService {
|
|||||||
|
|
||||||
// Set shares with others.
|
// Set shares with others.
|
||||||
foreach($notes as $note) {
|
foreach($notes as $note) {
|
||||||
$note->setSharedWith($this->noteShareMapper->getSharesForNote($note->getId()));
|
$sharedWith = [];
|
||||||
|
$sharedEntries = $this->noteShareMapper->getSharesForNote($note->getId());
|
||||||
|
foreach ($sharedEntries as $sharedEntry) {
|
||||||
|
$sharedUid = $sharedEntry->getSharedUser();
|
||||||
|
$user = $this->userManager->get($sharedUid);
|
||||||
|
if (!$user) {
|
||||||
|
// TODO: Debug that...
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$sharedEntry->setDisplayName($user->getDisplayName());
|
||||||
|
$sharedWith[] = $sharedEntry;
|
||||||
|
}
|
||||||
|
$note->setSharedWith($sharedWith);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get shares from others.
|
// Get shares from others.
|
||||||
@@ -91,7 +110,15 @@ class NoteService {
|
|||||||
$sharedEntries = $this->noteShareMapper->findForUser($userId);
|
$sharedEntries = $this->noteShareMapper->findForUser($userId);
|
||||||
foreach($sharedEntries as $sharedEntry) {
|
foreach($sharedEntries as $sharedEntry) {
|
||||||
$sharedNote = $this->notemapper->findShared($sharedEntry->getNoteId());
|
$sharedNote = $this->notemapper->findShared($sharedEntry->getNoteId());
|
||||||
$sharedEntry->setUserId($sharedNote->getUserId());
|
|
||||||
|
$uid = $sharedNote->getUserId();
|
||||||
|
$sharedEntry->setUserId($uid);
|
||||||
|
$user = $this->userManager->get($uid);
|
||||||
|
if (!$user) {
|
||||||
|
// TODO: Debug that...
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$sharedEntry->setDisplayName($user->getDisplayName());
|
||||||
$sharedNote->setSharedBy([$sharedEntry]);
|
$sharedNote->setSharedBy([$sharedEntry]);
|
||||||
$shares[] = $sharedNote;
|
$shares[] = $sharedNote;
|
||||||
}
|
}
|
||||||
@@ -300,7 +327,7 @@ class NoteService {
|
|||||||
foreach ($dbShares as $dbShare) {
|
foreach ($dbShares as $dbShare) {
|
||||||
$delete = true;
|
$delete = true;
|
||||||
foreach ($sharedWith as $share) {
|
foreach ($sharedWith as $share) {
|
||||||
if ($dbShare->getSharedUser() === $share['shared_user']) {
|
if ($dbShare->getSharedUser() === $share['id']) {
|
||||||
$delete = false;
|
$delete = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -312,10 +339,10 @@ class NoteService {
|
|||||||
|
|
||||||
// Add new shares
|
// Add new shares
|
||||||
foreach ($sharedWith as $share) {
|
foreach ($sharedWith as $share) {
|
||||||
if (!$this->noteShareMapper->existsByNoteAndUser($id, $share['shared_user'])) {
|
if (!$this->noteShareMapper->existsByNoteAndUser($id, $share['id'])) {
|
||||||
$hShare = new NoteShare();
|
$hShare = new NoteShare();
|
||||||
$hShare->setNoteId($id);
|
$hShare->setNoteId($id);
|
||||||
$hShare->setSharedUser($share['shared_user']);
|
$hShare->setSharedUser($share['id']);
|
||||||
$this->noteShareMapper->insert($hShare);
|
$this->noteShareMapper->insert($hShare);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -384,7 +411,20 @@ class NoteService {
|
|||||||
$newnote->setAttachts($attachts);
|
$newnote->setAttachts($attachts);
|
||||||
|
|
||||||
// Fill shared with with others
|
// Fill shared with with others
|
||||||
$newnote->setSharedWith($this->noteShareMapper->getSharesForNote($newnote->getId()));
|
$sharedWith = [];
|
||||||
|
$sharedEntries = $this->noteShareMapper->getSharesForNote($note->getId());
|
||||||
|
foreach ($sharedEntries as $sharedEntry) {
|
||||||
|
$sharedUid = $sharedEntry->getSharedUser();
|
||||||
|
$user = $this->userManager->get($sharedUid);
|
||||||
|
if (!$user) {
|
||||||
|
// TODO: Debug that...
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$sharedEntry->setDisplayName($user->getDisplayName());
|
||||||
|
|
||||||
|
$sharedWith[] = $sharedEntry;
|
||||||
|
}
|
||||||
|
$note->setSharedWith($sharedWith);
|
||||||
|
|
||||||
// Remove old color if necessary
|
// Remove old color if necessary
|
||||||
if (($oldcolorid !== $hcolor->getId()) &&
|
if (($oldcolorid !== $hcolor->getId()) &&
|
||||||
|
|||||||
Reference in New Issue
Block a user