mirror of
https://github.com/JanGross/quicknotes.git
synced 2025-11-30 23:37:16 +01:00
Open attachment when click thumbnail on modal
This commit is contained in:
15
js/script.js
15
js/script.js
@@ -459,14 +459,12 @@ View.prototype = {
|
||||
event.stopPropagation();
|
||||
OC.dialogs.filepicker(t('quicknotes', 'Select file to attach'), function(datapath, returntype) {
|
||||
OC.Files.getClient().getFileInfo(datapath).then((status, fileInfo) => {
|
||||
var attach = {
|
||||
file_id: fileInfo.id,
|
||||
preview_url: OC.generateUrl('core') + '/preview.png?file=' + encodeURI(datapath) + '&x=512&y=512'
|
||||
};
|
||||
|
||||
var attachts = self._editableAttachts();
|
||||
attachts.push(attach);
|
||||
|
||||
attachts.push({
|
||||
file_id: fileInfo.id,
|
||||
preview_url: OC.generateUrl('core') + '/preview.png?file=' + encodeURI(datapath) + '&x=512&y=512',
|
||||
redirect_url: OC.generateUrl('/apps/files/?dir={dir}&scrollto={scrollto}', {dir: fileInfo.path, scrollto: fileInfo.name})
|
||||
});
|
||||
self._editableAttachts(attachts);
|
||||
}).fail(() => {
|
||||
console.log("ERRORRR");
|
||||
@@ -722,7 +720,8 @@ View.prototype = {
|
||||
return $("#modal-note-div .note-attach").toArray().map(function (value) {
|
||||
return {
|
||||
file_id: value.getAttribute('attach-file-id'),
|
||||
preview_url: value.getAttribute('data-background-image')
|
||||
preview_url: value.getAttribute('data-background-image'),
|
||||
redirect_url: value.parentElement.getAttribute('href')
|
||||
};
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
<div class='note-attachts'>
|
||||
{{#each attachts}}
|
||||
<div class='note-attach-grid'>
|
||||
<div class="attach-preview note-attach" attach-file-id="{{file_id}}" data-background-image="{{preview_url}}"/>
|
||||
<a target="_blank" href="{{redirect_url}}">
|
||||
<div class="attach-preview note-attach" attach-file-id="{{file_id}}" data-background-image="{{preview_url}}"/>
|
||||
</a>
|
||||
<div class="attach-remove icon-delete" title="{{t "quicknotes" "Delete attachment"}}"/>
|
||||
</div>
|
||||
{{/each}}
|
||||
|
||||
@@ -128,6 +128,7 @@ class NoteController extends Controller {
|
||||
$attachts = $this->attachMapper->findFromNote($this->userId, $note->getId());
|
||||
foreach ($attachts as $attach) {
|
||||
$attach->setPreviewUrl($this->fileService->getPreviewUrl($attach->getFileId(), 512));
|
||||
$attach->setRedirectUrl($this->fileService->getRedirectToFileUrl($attach->getFileId()));
|
||||
}
|
||||
$note->setAttachts($attachts);
|
||||
}
|
||||
@@ -299,6 +300,7 @@ class NoteController extends Controller {
|
||||
$attachts = $this->attachMapper->findFromNote($this->userId, $newnote->getId());
|
||||
foreach ($attachts as $attach) {
|
||||
$attach->setPreviewUrl($this->fileService->getPreviewUrl($attach->getFileId(), 512));
|
||||
$attach->setRedirectUrl($this->fileService->getRedirectToFileUrl($attach->getFileId()));
|
||||
}
|
||||
$newnote->setAttachts($attachts);
|
||||
|
||||
|
||||
@@ -1,29 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* ownCloud - quicknotes
|
||||
/*
|
||||
* @copyright 2016-2020 Matias De lellis <mati86dl@gmail.com>
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
* @author 2016 Matias De lellis <mati86dl@gmail.com>
|
||||
*
|
||||
* @author Matias De lellis <mati86dl@gmail.com>
|
||||
* @copyright Matias De lellis 2016
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace OCA\QuickNotes\Controller;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\Controller;
|
||||
|
||||
use OCP\IRequest;
|
||||
|
||||
class PageController extends Controller {
|
||||
protected $appName;
|
||||
|
||||
public function __construct($appName,
|
||||
IRequest $request) {
|
||||
parent::__construct($appName, $request);
|
||||
|
||||
private $userId;
|
||||
|
||||
public function __construct($AppName, IRequest $request, $UserId){
|
||||
parent::__construct($AppName, $request);
|
||||
$this->userId = $UserId;
|
||||
$this->appName = $appName;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,9 +48,7 @@ class PageController extends Controller {
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function index() {
|
||||
$params = ['user' => $this->userId];
|
||||
return new TemplateResponse('quicknotes', 'main', $params); // templates/main.php
|
||||
return new TemplateResponse($this->appName, 'main');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -11,11 +11,16 @@ class Attach extends Entity implements JsonSerializable {
|
||||
protected $fileId;
|
||||
protected $createdAt;
|
||||
protected $previewUrl;
|
||||
protected $redirectUrl;
|
||||
|
||||
public function setPreviewUrl($previewUrl) {
|
||||
$this->previewUrl = $previewUrl;
|
||||
}
|
||||
|
||||
public function setRedirectUrl($redirectUrl) {
|
||||
$this->redirectUrl = $redirectUrl;
|
||||
}
|
||||
|
||||
public function jsonSerialize() {
|
||||
return [
|
||||
'id' => $this->id,
|
||||
@@ -23,6 +28,7 @@ class Attach extends Entity implements JsonSerializable {
|
||||
'file_id' => $this->fileId,
|
||||
'created_at' => $this->createdAt,
|
||||
'preview_url' => $this->previewUrl,
|
||||
'redirect_url' => $this->redirectUrl
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,11 +25,10 @@ namespace OCA\QuickNotes\Service;
|
||||
|
||||
use OCP\IURLGenerator;
|
||||
|
||||
use OCP\Files\IRootFolder;
|
||||
use OCP\Files\File;
|
||||
use OCP\Files\Folder;
|
||||
use OCP\Files\Node;
|
||||
|
||||
use OCP\Files\IRootFolder;
|
||||
use OCP\Files\NotFoundException;
|
||||
|
||||
class FileService {
|
||||
@@ -52,7 +51,13 @@ class FileService {
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
}
|
||||
|
||||
public function getPreviewUrl($fileId, $sideSize): string {
|
||||
/**
|
||||
* Get thumbnail of the give file id
|
||||
*
|
||||
* @param int $fileId file id to show
|
||||
* @param int $sideSize side lenght to show
|
||||
*/
|
||||
public function getPreviewUrl(int $fileId, int $sideSize): string {
|
||||
$userFolder = $this->rootFolder->getUserFolder($this->userId);
|
||||
$node = current($userFolder->getById($fileId));
|
||||
$path = $userFolder->getRelativePath($node->getPath());
|
||||
@@ -64,4 +69,24 @@ class FileService {
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirects to the file list and highlight the given file id
|
||||
*
|
||||
* @param int $fileId file id to show
|
||||
*/
|
||||
public function getRedirectToFileUrl(int $fileId): ?string {
|
||||
$userFolder = $this->rootFolder->getUserFolder($this->userId);
|
||||
$file = current($userFolder->getById($fileId));
|
||||
|
||||
if(!($file instanceof File)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$params = [];
|
||||
$params['dir'] = $userFolder->getRelativePath($file->getParent()->getPath());
|
||||
$params['scrollto'] = $file->getName();
|
||||
|
||||
return $this->urlGenerator->linkToRoute('files.view.index', $params);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user