Initial settings that allow to choose the default color of the notes.

This commit is contained in:
Matias De lellis
2020-06-16 22:56:34 -03:00
parent 8c6b0a2392
commit dd534e1f1b
10 changed files with 279 additions and 19 deletions

View File

@@ -5,6 +5,22 @@ return ['resources' =>
'noteApi' => ['url' => '/api/v1/notes'] 'noteApi' => ['url' => '/api/v1/notes']
], ],
'routes' => [ 'routes' => [
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'] // Main page
[
'name' => 'page#index',
'url' => '/',
'verb' => 'GET'
],
// User Settings
[
'name' => 'settings#setUserValue',
'url' => '/setuservalue',
'verb' => 'POST'
],
[
'name' => 'settings#getUserValue',
'url' => '/getuservalue',
'verb' => 'GET'
]
] ]
]; ];

View File

@@ -267,12 +267,13 @@ div[contenteditable="true"] {
background-color: rgba(0,0,0,0.12); background-color: rgba(0,0,0,0.12);
} }
.note-tags { .note-shares > .slim-share,
margin-top: 8px; .note-tags > .slim-tag {
margin-top: 5px;
} }
/* Restore defaults select2 rules */
/* Restore defaults select2 rules */
.select2-container-multi .select2-container-multi
.select2-choices .select2-choices

View File

@@ -563,8 +563,7 @@ View.prototype = {
$('#new-note').click(function () { $('#new-note').click(function () {
var fakenote = { var fakenote = {
title: t('quicknotes', 'New note'), title: t('quicknotes', 'New note'),
content: '', content: ''
color: '#F7EB96'
}; };
self._notes.create(fakenote).done(function(note) { self._notes.create(fakenote).done(function(note) {
if (self._notes.length() > 1) { if (self._notes.length() > 1) {
@@ -588,7 +587,7 @@ View.prototype = {
$('#all-notes').click(function () { $('#all-notes').click(function () {
$('.notes-grid').isotope({ filter: '*'}); $('.notes-grid').isotope({ filter: '*'});
var oldColorTool = $('#app-navigation .circle-toolbar.icon-checkmark'); var oldColorTool = $('#colors-folder .circle-toolbar.icon-checkmark');
$.each(oldColorTool, function(i, oct) { $.each(oldColorTool, function(i, oct) {
$(oct).removeClass('icon-checkmark'); $(oct).removeClass('icon-checkmark');
}); });
@@ -625,9 +624,9 @@ View.prototype = {
event.stopPropagation(); event.stopPropagation();
}); });
$('#app-navigation .circle-toolbar').click(function (event) { $('#colors-folder .circle-toolbar').click(function (event) {
event.stopPropagation(); event.stopPropagation();
var oldColorTool = $('#app-navigation .circle-toolbar.icon-checkmark'); var oldColorTool = $('#colors-folder .circle-toolbar.icon-checkmark');
$.each(oldColorTool, function(i, oct) { $.each(oldColorTool, function(i, oct) {
$(oct).removeClass('icon-checkmark'); $(oct).removeClass('icon-checkmark');
}); });
@@ -687,8 +686,48 @@ View.prototype = {
$(oct).removeClass('icon-checkmark'); $(oct).removeClass('icon-checkmark');
}); });
}); });
},
},
renderSettings: function () {
/* Render view */
var html = Handlebars.templates['settings']({});
$('#app-settings-content').html(html);
var self = this;
$.get(OC.generateUrl('apps/quicknotes/getuservalue'), {'type': 'default_color'})
.done(function (response) {
var color = response.value;;
var colors = $("#setting-defaul-color")[0].getElementsByClassName("circle-toolbar");
$.each(colors, function(i, c) {
if (color === self._colorToHex(c.style.backgroundColor)) {
c.className += " icon-checkmark";
}
});
});
/* Settings */
$("#app-settings-content").off();
$('#app-settings-content').on('click', '.circle-toolbar', function (event) {
event.stopPropagation();
var currentColor = $(this);
var color = self._colorToHex(currentColor.css("background-color"));
$.ajax({
url: OC.generateUrl('apps/quicknotes/setuservalue'),
type: 'POST',
data: {
'type': 'default_color',
'value': color
},
success: function (response) {
$('#setting-defaul-color .circle-toolbar').removeClass('icon-checkmark');
currentColor.addClass('icon-checkmark');
}
});
});
},
/** /**
* Some 'private' functions as helpers. * Some 'private' functions as helpers.
*/ */
@@ -977,6 +1016,7 @@ View.prototype = {
render: function () { render: function () {
this.renderNavigation(); this.renderNavigation();
this.renderContent(); this.renderContent();
this.renderSettings();
} }
}; };
@@ -1038,8 +1078,7 @@ view.renderContent();
* Loading notes and render final view. * Loading notes and render final view.
*/ */
notes.load().done(function () { notes.load().done(function () {
view.renderNavigation(); view.render();
view.renderContent();
}).fail(function () { }).fail(function () {
alert('Could not load notes'); alert('Could not load notes');
}); });

View File

@@ -0,0 +1,19 @@
<div>
<label>{{t "quicknotes" "Default color for new notes"}}</label>
</div>
<div id="setting-defaul-color">
<div id="defaultColor" style="display: flex; justify-content: center;">
<div class="colors-toolbar">
<a href="#" class="circle-toolbar" style="background-color: #F7EB96"></a>
<a href="#" class="circle-toolbar" style="background-color: #88B7E3"></a>
<a href="#" class="circle-toolbar" style="background-color: #C1ECB0"></a>
<a href="#" class="circle-toolbar" style="background-color: #BFA6E9"></a>
<a href="#" class="circle-toolbar" style="background-color: #DAF188"></a>
<a href="#" class="circle-toolbar" style="background-color: #FF96AC"></a>
<a href="#" class="circle-toolbar" style="background-color: #FCF66F"></a>
<a href="#" class="circle-toolbar" style="background-color: #F2F1EF"></a>
<a href="#" class="circle-toolbar" style="background-color: #C1D756"></a>
<a href="#" class="circle-toolbar" style="background-color: #CECECE"></a>
</div>
</div>
</div>

View File

@@ -91,7 +91,7 @@ class NoteController extends Controller {
* @param string $content * @param string $content
* @param string $color * @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); $note = $this->noteService->create($this->userId, $title, $content, $color);
$etag = md5(json_encode($note)); $etag = md5(json_encode($note));

View File

@@ -0,0 +1,112 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Matias De lellis <mati86dl@gmail.com>
*
* @author Matias De lellis <mati86dl@gmail.com>
*
* @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\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);
}
}

View File

@@ -52,6 +52,7 @@ class NoteService {
private $attachMapper; private $attachMapper;
private $tagmapper; private $tagmapper;
private $fileService; private $fileService;
private $settingsService;
public function __construct(NoteMapper $notemapper, public function __construct(NoteMapper $notemapper,
NoteTagMapper $notetagmapper, NoteTagMapper $notetagmapper,
@@ -59,7 +60,8 @@ class NoteService {
ColorMapper $colormapper, ColorMapper $colormapper,
AttachMapper $attachMapper, AttachMapper $attachMapper,
TagMapper $tagmapper, TagMapper $tagmapper,
FileService $fileService) FileService $fileService,
SettingsService $settingsService)
{ {
$this->notemapper = $notemapper; $this->notemapper = $notemapper;
$this->notetagmapper = $notetagmapper; $this->notetagmapper = $notetagmapper;
@@ -68,6 +70,7 @@ class NoteService {
$this->attachMapper = $attachMapper; $this->attachMapper = $attachMapper;
$this->tagmapper = $tagmapper; $this->tagmapper = $tagmapper;
$this->fileService = $fileService; $this->fileService = $fileService;
$this->settingsService = $settingsService;
} }
/** /**
@@ -154,7 +157,11 @@ class NoteService {
* @param string $content * @param string $content
* @param string $color * @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 // Get color or append it
if ($this->colormapper->colorExists($color)) { if ($this->colormapper->colorExists($color)) {
$hcolor = $this->colormapper->findByColor($color); $hcolor = $this->colormapper->findByColor($color);

View File

@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Matias De lellis <mati86dl@gmail.com>
*
* @author Matias De lellis <mati86dl@gmail.com>
*
* @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\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);
}
}

View File

@@ -8,4 +8,5 @@ p($l->t('Shared'));
p($l->t('Shared with others')); p($l->t('Shared with others'));
p($l->t('Shared with you')); p($l->t('Shared with you'));
p($l->t('Share note')); p($l->t('Share note'));
p($l->t('Close')); p($l->t('Close'));
p($l->t('Default color for new notes'));

View File

@@ -1,8 +1,8 @@
<div id="app-settings"> <div id="app-settings">
<div id="app-settings-header"> <div id="app-settings-header">
<button class="settings-button" <button class="settings-button" data-apps-slide-toggle="#app-settings-content">
data-apps-slide-toggle="#app-settings-content" <?php p($l->t('Settings'));?>
></button> </button>
</div> </div>
<div id="app-settings-content"> <div id="app-settings-content">
</div> </div>