brantje / nextnote

A full Evernote / OneNote style WYSIWYG note editor for Nextcloud / ownCloud. Join our telegram at: https://t.me/NextNote
GNU Affero General Public License v3.0
163 stars 19 forks source link

Can not find how to save note as a html file to a folder. #60

Closed lwinch2006 closed 6 years ago

lwinch2006 commented 6 years ago

Like header says I have a small trouble with finding how to save note as html file to a folder. At least description in Readme.md says it is possible. (maybe it is enabled in separate branch folder only? I have installed master branch at the moment)

Features:
...
Ability to save files to a folder as HTML files (untested)
...

Another small thing is copy-paste from clipboard not working. Only works when open source code and copy-paste there directly.

ThomasDaheim commented 6 years ago

I have worked on that some time ago. Would need to re-add to the current version. But I would rather wait til v1.0 is out and add to this. Just be patient for a while longer ;-)

brantje commented 6 years ago

Hi there, Saving to file was removed during the rewrite. It will be added soon by @ThomasDaheim and me. I've updated the readme accordingly. Sorry for any inconvenience

lwinch2006 commented 6 years ago

Hello. This is great. Just take your time devs ;-). Meanwhile since saving to files is crucial for me since I need html notes synced to my mobile device. So I created a little hack that maybe would help to somebody else like me or maybe gave you an idea to implement some simple solution before a serious one.

Generally it does:

Sorry for poor PHP language syntax.

Code examples:


...

use OCP\Files\IRootFolder;
use OCP\Files\Folder;

...

class NextNoteService {

...

private $rootFolder;

...

public function __construct(NextNoteMapper $noteMapper, Utils $utils, NextNoteShareBackend $shareBackend, IRootFolder $rootFolder) {
...
$this->rootFolder = $rootFolder;
...
}

...

public function create($note, $userId) {
...
$folder = $this->rootFolder->get('/[user name]/files/HtmlNotes');
$newNoteName = $note->getName();

$fileName = $newNoteName . '.html';

if ($folder->nodeExists($fileName)) {
    $file = $folder->get($fileName);
} else {
    $file = $folder->newFile($fileName);
}

$file->putContent($note->getNote());
...
}

...

public function update($note) {
...
$oldNoteName = $entity->getName();
...
$folder = $this->rootFolder->get('/[user name]/files/HtmlNotes');
$newNoteName = $note->getName();

if (strtolower($oldNoteName) <> strtolower($newNoteName)) {
    $fileName = $oldNoteName . '.html';

    if ($folder->nodeExists($fileName)) {
        $file = $folder->get($fileName);
        $file->delete();
    }
}

$fileName = $newNoteName . '.html';

if ($folder->nodeExists($fileName)) {
    $file = $folder->get($fileName);
} else {
    $file = $folder->newFile($fileName);
}

if ($note->getDeleted() == 0) {
    $file->putContent($note->getNote());
} else {
    $file->delete();
}

...
}

...

}