diff --git a/js/script.js b/js/script.js index 0db671f..b1e1762 100644 --- a/js/script.js +++ b/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 { diff --git a/js/templates/attachts.handlebars b/js/templates/attachts.handlebars index eaed505..d1f1b90 100644 --- a/js/templates/attachts.handlebars +++ b/js/templates/attachts.handlebars @@ -1,7 +1,9 @@
{{#each attachts}}
-
+ +
+
{{/each}} diff --git a/lib/Controller/NoteController.php b/lib/Controller/NoteController.php index b0549c7..8544d73 100644 --- a/lib/Controller/NoteController.php +++ b/lib/Controller/NoteController.php @@ -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); diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 654fa60..2c3c2d8 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -1,29 +1,40 @@ * - * This file is licensed under the Affero General Public License version 3 or - * later. See the COPYING file. + * @author 2016 Matias De lellis * - * @author Matias De lellis - * @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 . */ 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'); } - } \ No newline at end of file diff --git a/lib/Db/Attach.php b/lib/Db/Attach.php index ba14054..76a5588 100644 --- a/lib/Db/Attach.php +++ b/lib/Db/Attach.php @@ -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 ]; } } diff --git a/lib/Service/FileService.php b/lib/Service/FileService.php index 563077d..c2dbc06 100644 --- a/lib/Service/FileService.php +++ b/lib/Service/FileService.php @@ -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); + } + }