diff --git a/.nextcloudignore b/.nextcloudignore new file mode 100644 index 000000000..90b486c88 --- /dev/null +++ b/.nextcloudignore @@ -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/ diff --git a/appinfo/info.xml b/appinfo/info.xml index 4014d76a3..bf162a42a 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -7,7 +7,7 @@ - 4.6.0 + 4.7.0-beta.0 agpl Kristof Hamann Bernhard Posselt @@ -22,12 +22,13 @@ The Notes app is a distraction free notes taking app for [Nextcloud](https://www https://github.com/nextcloud/notes.git https://raw.githubusercontent.com/nextcloud/screenshots/master/apps/Notes/notes.png - + OCA\Notes\Migration\Cleanup + OCA\Notes\Migration\EditorHint diff --git a/appinfo/routes.php b/appinfo/routes.php index bc16fec3d..b1a7cd8b6 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -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 ////////// diff --git a/krankerl.toml b/krankerl.toml new file mode 100644 index 000000000..2c98a14f4 --- /dev/null +++ b/krankerl.toml @@ -0,0 +1,5 @@ +[package] +before_cmds = [ + 'npm ci', + 'npm run build' +] diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index b9baf3e0c..d61803461 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -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'); @@ -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); diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 1d6efb340..9d7a6fbd9 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -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(); + } } diff --git a/lib/Migration/EditorHint.php b/lib/Migration/EditorHint.php new file mode 100644 index 000000000..1a1f922ea --- /dev/null +++ b/lib/Migration/EditorHint.php @@ -0,0 +1,63 @@ + + * + * @author Julius Härtl + * + * @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\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'); + }); + } +} diff --git a/lib/Service/SettingsService.php b/lib/Service/SettingsService.php index 5fb97bcba..5f9a8d571 100644 --- a/lib/Service/SettingsService.php +++ b/lib/Service/SettingsService.php @@ -18,7 +18,7 @@ class SettingsService { /* Allowed attributes */ private array $attrs; - private $defaultSuffixes = [ '.txt', '.md' ]; + private $defaultSuffixes = [ '.md', '.txt' ]; public function __construct( IConfig $config, @@ -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) { @@ -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); diff --git a/package-lock.json b/package-lock.json index 39e20d53e..b61f1e226 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,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", diff --git a/package.json b/package.json index 66b28972c..f0b766197 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/App.vue b/src/App.vue index d36b2616d..f9f0bff7d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,5 +1,6 @@