mirror of
https://github.com/JanGross/quicknotes.git
synced 2025-11-30 23:37:16 +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>
|
||||
*
|
||||
@@ -159,7 +159,7 @@ const QnDialogs = {
|
||||
var data = [];
|
||||
availableUsers.forEach(function (item, index) {
|
||||
// Select2 expect id, text.
|
||||
data.push({id: item, text: item});
|
||||
data.push({id: item[0], text: item[1]});
|
||||
});
|
||||
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");
|
||||
|
||||
$('.select2-input').on("keyup", function (event) {
|
||||
@@ -208,7 +208,9 @@ const QnDialogs = {
|
||||
// Quicknotes shares expect id, shared_user
|
||||
newUsers = input.select2("data");
|
||||
newUsers.forEach(function (item) {
|
||||
item['shared_user'] = item.text;
|
||||
item['shared_user'] = item.id;
|
||||
item['display_name'] = item.text;
|
||||
|
||||
users.push(item);
|
||||
});
|
||||
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>
|
||||
*
|
||||
@@ -169,10 +169,10 @@ Notes.prototype = {
|
||||
}).done(function (shares) {
|
||||
var users = [];
|
||||
$.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) {
|
||||
users.push(user.value.shareWith);
|
||||
users.push([user.value.shareWith, user.label]);
|
||||
});
|
||||
self._usersSharing = users;
|
||||
}).fail(function () {
|
||||
@@ -233,6 +233,7 @@ View.prototype = {
|
||||
tags: this._editableTags(),
|
||||
sharedWith: this._editableShares()
|
||||
};
|
||||
|
||||
var self = this;
|
||||
this._notes.update(fakeNote).done(function (note) {
|
||||
// Create an new note and replace in grid.
|
||||
@@ -530,6 +531,12 @@ View.prototype = {
|
||||
$('#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.
|
||||
$('#modal-note-div').on("click", "#share-button", function (event) {
|
||||
event.stopPropagation();
|
||||
@@ -545,6 +552,7 @@ View.prototype = {
|
||||
);
|
||||
});
|
||||
|
||||
// handle color button.
|
||||
$('#modal-note-div').on("click", "#color-button", function (event) {
|
||||
event.stopPropagation();
|
||||
self._colorPick.toggle();
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
</div>
|
||||
<div class='note-shares'>
|
||||
{{#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}}
|
||||
</div>
|
||||
<div class='note-tags'>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<div class='note-body'>
|
||||
<div>
|
||||
{{#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>
|
||||
{{else}}
|
||||
{{#if isPinned}}
|
||||
@@ -34,7 +34,7 @@
|
||||
</div>
|
||||
<div class='note-shares'>
|
||||
{{#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}}
|
||||
</div>
|
||||
<div class='note-tags'>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<div class='note-shares'>
|
||||
{{#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}}
|
||||
</div>
|
||||
@@ -20,18 +20,24 @@ class NoteShare extends Entity implements JsonSerializable {
|
||||
protected $sharedGroup;
|
||||
|
||||
protected $userId;
|
||||
protected $displayname;
|
||||
|
||||
public function setUserId (string $userId): void {
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
public function setDisplayName (string $displayName): void {
|
||||
$this->displayName = $displayName;
|
||||
}
|
||||
|
||||
public function jsonSerialize() {
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'note_id' => $this->noteId,
|
||||
'shared_user' => $this->sharedUser,
|
||||
'shared_group' => $this->sharedGroup,
|
||||
'user_id' => $this->userId
|
||||
'user_id' => $this->userId,
|
||||
'display_name' => $this->displayName
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?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>
|
||||
*
|
||||
@@ -45,6 +45,8 @@ use OCA\QuickNotes\Service\SettingsService;
|
||||
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
|
||||
use OCP\IUserManager;
|
||||
|
||||
class NoteService {
|
||||
|
||||
private $notemapper;
|
||||
@@ -56,6 +58,9 @@ class NoteService {
|
||||
private $fileService;
|
||||
private $settingsService;
|
||||
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
|
||||
public function __construct(NoteMapper $notemapper,
|
||||
NoteTagMapper $notetagmapper,
|
||||
NoteShareMapper $noteShareMapper,
|
||||
@@ -63,7 +68,8 @@ class NoteService {
|
||||
AttachMapper $attachMapper,
|
||||
TagMapper $tagmapper,
|
||||
FileService $fileService,
|
||||
SettingsService $settingsService)
|
||||
SettingsService $settingsService,
|
||||
IUserManager $userManager)
|
||||
{
|
||||
$this->notemapper = $notemapper;
|
||||
$this->notetagmapper = $notetagmapper;
|
||||
@@ -73,6 +79,7 @@ class NoteService {
|
||||
$this->tagmapper = $tagmapper;
|
||||
$this->fileService = $fileService;
|
||||
$this->settingsService = $settingsService;
|
||||
$this->userManager = $userManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,7 +90,19 @@ class NoteService {
|
||||
|
||||
// Set shares with others.
|
||||
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.
|
||||
@@ -91,7 +110,15 @@ class NoteService {
|
||||
$sharedEntries = $this->noteShareMapper->findForUser($userId);
|
||||
foreach($sharedEntries as $sharedEntry) {
|
||||
$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]);
|
||||
$shares[] = $sharedNote;
|
||||
}
|
||||
@@ -300,7 +327,7 @@ class NoteService {
|
||||
foreach ($dbShares as $dbShare) {
|
||||
$delete = true;
|
||||
foreach ($sharedWith as $share) {
|
||||
if ($dbShare->getSharedUser() === $share['shared_user']) {
|
||||
if ($dbShare->getSharedUser() === $share['id']) {
|
||||
$delete = false;
|
||||
break;
|
||||
}
|
||||
@@ -312,10 +339,10 @@ class NoteService {
|
||||
|
||||
// Add new shares
|
||||
foreach ($sharedWith as $share) {
|
||||
if (!$this->noteShareMapper->existsByNoteAndUser($id, $share['shared_user'])) {
|
||||
if (!$this->noteShareMapper->existsByNoteAndUser($id, $share['id'])) {
|
||||
$hShare = new NoteShare();
|
||||
$hShare->setNoteId($id);
|
||||
$hShare->setSharedUser($share['shared_user']);
|
||||
$hShare->setSharedUser($share['id']);
|
||||
$this->noteShareMapper->insert($hShare);
|
||||
}
|
||||
}
|
||||
@@ -384,7 +411,20 @@ class NoteService {
|
||||
$newnote->setAttachts($attachts);
|
||||
|
||||
// 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
|
||||
if (($oldcolorid !== $hcolor->getId()) &&
|
||||
|
||||
Reference in New Issue
Block a user