\ No newline at end of file
diff --git a/lib/Controller/NoteController.php b/lib/Controller/NoteController.php
index ee18753..623e96a 100644
--- a/lib/Controller/NoteController.php
+++ b/lib/Controller/NoteController.php
@@ -91,7 +91,7 @@ class NoteController extends Controller {
* @param string $content
* @param string $color
*/
- public function create($title, $content, $color = "#F7EB96") {
+ public function create($title, $content, $color = NULL) {
$note = $this->noteService->create($this->userId, $title, $content, $color);
$etag = md5(json_encode($note));
diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php
new file mode 100644
index 0000000..6cff97a
--- /dev/null
+++ b/lib/Controller/SettingsController.php
@@ -0,0 +1,112 @@
+
+ *
+ * @author Matias De lellis
+ *
+ * @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\AppFramework\Controller;
+use OCP\AppFramework\Http\JSONResponse;
+use OCP\IRequest;
+
+use OCA\QuickNotes\Service\SettingsService;
+
+
+class SettingsController extends Controller {
+
+ /** @var SettingsService */
+ private $settingsService;
+
+ /** @var string */
+ private $userId;
+
+ const STATE_OK = 0;
+ const STATE_FALSE = 1;
+ const STATE_SUCCESS = 2;
+ const STATE_ERROR = 3;
+
+ public function __construct ($appName,
+ IRequest $request,
+ SettingsService $settingsService,
+ $userId)
+ {
+ parent::__construct($appName, $request);
+
+ $this->appName = $appName;
+ $this->settingsService = $settingsService;
+ $this->userId = $userId;
+ }
+
+ /**
+ * @NoAdminRequired
+ * @param $type
+ * @param $value
+ * @return JSONResponse
+ */
+ public function setUserValue($type, $value) {
+ $status = self::STATE_SUCCESS;
+
+ switch ($type) {
+ case SettingsService::COLOR_FOR_NEW_NOTES_KEY:
+ $this->settingsService->setColorForNewNotes($value);
+ break;
+ default:
+ $status = self::STATE_ERROR;
+ break;
+ }
+
+ // Response
+ $result = [
+ 'status' => $status,
+ 'value' => $value
+ ];
+
+ return new JSONResponse($result);
+ }
+
+ /**
+ * @NoAdminRequired
+ * @param $type
+ * @return JSONResponse
+ */
+ public function getUserValue($type) {
+ $status = self::STATE_OK;
+ $value ='nodata';
+
+ switch ($type) {
+ case SettingsService::COLOR_FOR_NEW_NOTES_KEY:
+ $value = $this->settingsService->getColorForNewNotes($this->userId);
+ break;
+ default:
+ $status = self::STATE_FALSE;
+ break;
+ }
+
+ $result = [
+ 'status' => $status,
+ 'value' => $value
+ ];
+
+ return new JSONResponse($result);
+ }
+
+}
diff --git a/lib/Service/NoteService.php b/lib/Service/NoteService.php
index 14c4b5f..99c7b9b 100644
--- a/lib/Service/NoteService.php
+++ b/lib/Service/NoteService.php
@@ -52,6 +52,7 @@ class NoteService {
private $attachMapper;
private $tagmapper;
private $fileService;
+ private $settingsService;
public function __construct(NoteMapper $notemapper,
NoteTagMapper $notetagmapper,
@@ -59,7 +60,8 @@ class NoteService {
ColorMapper $colormapper,
AttachMapper $attachMapper,
TagMapper $tagmapper,
- FileService $fileService)
+ FileService $fileService,
+ SettingsService $settingsService)
{
$this->notemapper = $notemapper;
$this->notetagmapper = $notetagmapper;
@@ -68,6 +70,7 @@ class NoteService {
$this->attachMapper = $attachMapper;
$this->tagmapper = $tagmapper;
$this->fileService = $fileService;
+ $this->settingsService = $settingsService;
}
/**
@@ -154,7 +157,11 @@ class NoteService {
* @param string $content
* @param string $color
*/
- public function create(string $userId, string $title, string $content, string $color = "#F7EB96"): Note {
+ public function create(string $userId, string $title, string $content, string $color = NULL): Note {
+ if (is_null($color)) {
+ $color = $this->settingsService->getColorForNewNotes();
+ }
+
// Get color or append it
if ($this->colormapper->colorExists($color)) {
$hcolor = $this->colormapper->findByColor($color);
diff --git a/lib/Service/SettingsService.php b/lib/Service/SettingsService.php
new file mode 100644
index 0000000..97ff5bc
--- /dev/null
+++ b/lib/Service/SettingsService.php
@@ -0,0 +1,65 @@
+
+ *
+ * @author Matias De lellis
+ *
+ * @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\Service;
+
+use OCA\QuickNotes\AppInfo\Application;
+
+use OCP\IConfig;
+
+class SettingsService {
+
+ /**
+ * Settings keys and default values.
+ */
+ const COLOR_FOR_NEW_NOTES_KEY = 'default_color';
+ const DEFAULT_COLOR_FOR_NEW_NOTES = '#F7EB96';
+
+ /** @var IConfig Config */
+ private $config;
+
+ /** @var string|null */
+ private $userId;
+
+ /**
+ * @param IConfig $config
+ * @param string $userId
+ */
+ public function __construct(IConfig $config,
+ $userId)
+ {
+ $this->config = $config;
+ $this->userId = $userId;
+ }
+
+
+ public function getColorForNewNotes(): string {
+ return $this->config->getUserValue($this->userId, Application::APP_NAME, self::COLOR_FOR_NEW_NOTES_KEY, self::DEFAULT_COLOR_FOR_NEW_NOTES);
+ }
+
+ public function setColorForNewNotes(string $color) {
+ $this->config->setUserValue($this->userId, Application::APP_NAME, self::COLOR_FOR_NEW_NOTES_KEY, $color);
+ }
+
+}
diff --git a/templates/fake.php b/templates/fake.php
index 8a20d5c..73b15c4 100644
--- a/templates/fake.php
+++ b/templates/fake.php
@@ -8,4 +8,5 @@ p($l->t('Shared'));
p($l->t('Shared with others'));
p($l->t('Shared with you'));
p($l->t('Share note'));
-p($l->t('Close'));
\ No newline at end of file
+p($l->t('Close'));
+p($l->t('Default color for new notes'));
\ No newline at end of file
diff --git a/templates/part.settings.php b/templates/part.settings.php
index 7eebe65..594ef30 100644
--- a/templates/part.settings.php
+++ b/templates/part.settings.php
@@ -1,8 +1,8 @@