Skip to content

feat(editor): Use text editor #958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .nextcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/build/
/.git
/.github
/docs/
/tests
/babel.config.js
/.editorconfig
/.eslintrc.js
/.nextcloudignore
/webpack.*.js
/.codecov.yml
/composer.json
/composer.lock
/_config.yml
/.drone.yml
/.travis.yml
/.eslintignore
/.eslintrc.yml
/.gitignore
/issue_template.md
/krankerl.toml
/Makefile
/mkdocs.yml
/run-eslint.sh
/package.json
/package-lock.json
/node_modules/
/src/
5 changes: 3 additions & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<description><![CDATA[
The Notes app is a distraction free notes taking app for [Nextcloud](https://www.nextcloud.com/). It provides categories for better organization and supports formatting using [Markdown](https://en.wikipedia.org/wiki/Markdown) syntax. Notes are saved as files in your Nextcloud, so you can view and edit them with every Nextcloud client. Furthermore, a separate [REST API](https://github.com/nextcloud/notes/blob/master/docs/api/README.md) allows for an easy integration into third-party apps (currently, there are notes apps for [Android](https://github.com/nextcloud/notes-android), [iOS](https://github.com/nextcloud/notes-ios) and the [console](https://git.danielmoch.com/nncli/about) which allow convenient access to your Nextcloud notes). Further features include marking notes as favorites.
]]></description>
<version>4.6.0</version>
<version>4.7.0-beta.0</version>
<licence>agpl</licence>
<author>Kristof Hamann</author>
<author>Bernhard Posselt</author>
Expand All @@ -22,12 +22,13 @@ The Notes app is a distraction free notes taking app for [Nextcloud](https://www
<repository type="git">https://github.com/nextcloud/notes.git</repository>
<screenshot small-thumbnail="https://github.com/raw/nextcloud/screenshots/master/apps/Notes/notes-thumbnail.jpg">https://github.com/raw/nextcloud/screenshots/master/apps/Notes/notes.png</screenshot>
<dependencies>
<php min-version="7.4" max-version="8.1" />
<php min-version="7.4" max-version="8.2" />
<nextcloud min-version="25" max-version="27" />
</dependencies>
<repair-steps>
<post-migration>
<step>OCA\Notes\Migration\Cleanup</step>
<step>OCA\Notes\Migration\EditorHint</step>
</post-migration>
</repair-steps>

Expand Down
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
////////// S E T T I N G S //////////
['name' => 'settings#set', 'url' => '/settings', 'verb' => 'PUT'],
['name' => 'settings#get', 'url' => '/settings', 'verb' => 'GET'],
['name' => 'settings#migrate', 'url' => '/settings/migrate', 'verb' => 'POST'],


////////// A P I //////////
Expand Down
5 changes: 5 additions & 0 deletions krankerl.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
before_cmds = [
'npm ci',
'npm run build'
]
33 changes: 32 additions & 1 deletion lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,55 @@

namespace OCA\Notes\Controller;

use OCA\Notes\AppInfo\Application;
use OCA\Notes\Service\NotesService;

use OCA\Notes\Service\SettingsService;
use OCA\Text\Event\LoadEditor;
use OCP\App\IAppManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserSession;

class PageController extends Controller {
private NotesService $notesService;
private IConfig $config;
private IUserSession $userSession;
private IURLGenerator $urlGenerator;
private IEventDispatcher $eventDispatcher;
private IInitialState $initialState;

public function __construct(
string $AppName,
IRequest $request,
NotesService $notesService,
IConfig $config,
IUserSession $userSession,
IURLGenerator $urlGenerator
IURLGenerator $urlGenerator,
IEventDispatcher $eventDispatcher,
IInitialState $initialState
) {
parent::__construct($AppName, $request);
$this->notesService = $notesService;
$this->config = $config;
$this->userSession = $userSession;
$this->urlGenerator = $urlGenerator;
$this->eventDispatcher = $eventDispatcher;
$this->initialState = $initialState;
}


/**
* @NoAdminRequired
* @NoCSRFRequired
* @suppress PhanUndeclaredClassReference, PhanTypeMismatchArgument, PhanUndeclaredClassMethod
*/
public function index() : TemplateResponse {
$devMode = !is_file(dirname(__FILE__).'/../../js/notes-main.js');
Expand All @@ -45,6 +62,20 @@ public function index() : TemplateResponse {
[ ]
);

if (\OCP\Server::get(IAppManager::class)->isEnabledForUser('text') && class_exists(LoadEditor::class)) {
$this->eventDispatcher->dispatchTyped(new LoadEditor());
}

$this->initialState->provideInitialState(
'config',
\OCP\Server::get(SettingsService::class)->getPublic($this->userSession->getUser()->getUID())
);

$this->initialState->provideInitialState(
'editorHint',
$this->config->getUserValue($this->userSession->getUser()->getUID(), Application::APP_ID, 'editorHint', '')
);

$csp = new ContentSecurityPolicy();
$csp->addAllowedImageDomain('*');
$response->setContentSecurityPolicy($csp);
Expand Down
5 changes: 5 additions & 0 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@ public function set(): JSONResponse {
public function get(): JSONResponse {
return new JSONResponse($this->service->getAll($this->getUID()));
}

public function migrate(): JSONResponse {
$this->service->delete($this->getUID(), 'editorHint');
return new JSONResponse();
}
}
63 changes: 63 additions & 0 deletions lib/Migration/EditorHint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2023 Julius Härtl <[email protected]>
*
* @author Julius Härtl <[email protected]>
*
* @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\Notes\Migration;

use OCA\Notes\AppInfo\Application;
use OCP\IConfig;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;

class EditorHint implements IRepairStep {
private IConfig $config;
private IUserManager $userManager;
public function __construct(IConfig $config, IUserManager $userManager) {
$this->config = $config;
$this->userManager = $userManager;
}

public function getName() {
return 'Show a hint about the new editor to existing users';
}

public function run(IOutput $output) {
$appVersion = $this->config->getAppValue('text', 'installed_version');

if (!$appVersion || version_compare($appVersion, '4.7.0') !== -1) {
return;
}

$this->userManager->callForSeenUsers(function (IUser $user) {
if ($this->config->getUserValue($user->getUID(), Application::APP_ID, 'notesLastViewedNote', '') === '') {
return;
}

$this->config->setUserValue($user->getUID(), Application::APP_ID, 'editorHint', 'yes');
});
}
}
8 changes: 6 additions & 2 deletions lib/Service/SettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SettingsService {
/* Allowed attributes */
private array $attrs;

private $defaultSuffixes = [ '.txt', '.md' ];
private $defaultSuffixes = [ '.md', '.txt' ];

public function __construct(
IConfig $config,
Expand Down Expand Up @@ -48,7 +48,7 @@ public function __construct(
return implode(DIRECTORY_SEPARATOR, $path);
},
],
'noteMode' => $this->getListAttrs('noteMode', ['edit', 'preview']),
'noteMode' => $this->getListAttrs('noteMode', ['rich', 'edit', 'preview']),
'customSuffix' => [
'default' => $this->defaultSuffixes[0],
'validate' => function ($value) {
Expand Down Expand Up @@ -168,6 +168,10 @@ public function get(string $uid, string $name) : string {
}
}

public function delete(string $uid, string $name): void {
$this->config->deleteUserValue($uid, Application::APP_ID, $name);
}

public function getPublic(string $uid) : \stdClass {
// initialize and load settings
$settings = $this->getAll($uid, true);
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@nextcloud/axios": "^2.2.0",
"@nextcloud/dialogs": "^3.2.0",
"@nextcloud/event-bus": "^3.0.2",
"@nextcloud/initial-state": "^2.0.0",
"@nextcloud/moment": "^1.2.1",
"@nextcloud/router": "^2.0.1",
"@nextcloud/vue": "^7.3.0",
Expand Down
7 changes: 6 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<template>
<NcContent app-name="notes" :content-class="{loading: loading.notes}">
<EditorHint v-if="editorHint" @close="editorHint=false" />
<NcContent v-else app-name="notes" :content-class="{loading: loading.notes}">
<NcAppNavigation :class="{loading: loading.notes, 'icon-error': error}">
<NcAppNavigationNew
v-show="!loading.notes && !error"
Expand Down Expand Up @@ -52,6 +53,7 @@ import {
NcAppNavigationItem,
NcContent,
} from '@nextcloud/vue'
import { loadState } from '@nextcloud/initial-state'
import { showSuccess, TOAST_UNDO_TIMEOUT, TOAST_PERMANENT_TIMEOUT } from '@nextcloud/dialogs'
import '@nextcloud/dialogs/styles/toast.scss'

Expand All @@ -61,6 +63,7 @@ import PlusIcon from 'vue-material-design-icons/Plus.vue'
import AppSettings from './components/AppSettings.vue'
import NavigationList from './components/NavigationList.vue'
import AppHelp from './components/AppHelp.vue'
import EditorHint from './components/Modal/EditorHint.vue'

import { config } from './config.js'
import { fetchNotes, noteExists, createNote, undoDeleteNote } from './NotesService.js'
Expand All @@ -72,6 +75,7 @@ export default {
components: {
AppHelp,
AppSettings,
EditorHint,
InfoIcon,
NavigationList,
NcAppContent,
Expand All @@ -97,6 +101,7 @@ export default {
deletedNotes: [],
refreshTimer: null,
helpVisible: false,
editorHint: loadState('notes', 'editorHint', '') === 'yes' && window.oc_appswebroots.text,
}
},

Expand Down
9 changes: 9 additions & 0 deletions src/NotesService.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ export const setSettings = settings => {
})
}

export const deleteEditorMode = () => {
return axios
.post(url('/settings/migrate'))
.catch(err => {
console.error(err)
throw err
})
}

export const getDashboardData = () => {
return axios
.get(url('/notes/dashboard'))
Expand Down
3 changes: 2 additions & 1 deletion src/components/AppSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ export default {
data() {
return {
extensions: [
{ value: '.txt', label: '.txt' },
{ value: '.md', label: '.md' },
{ value: '.txt', label: '.txt' },
{ value: 'custom', label: t('notes', 'User defined') },
],
noteModes: [
{ value: 'rich', label: t('notes', 'Open in rich text mode') },
{ value: 'edit', label: t('notes', 'Open in edit mode') },
{ value: 'preview', label: t('notes', 'Open in preview mode') },
],
Expand Down
Loading