From e1994ef2cf6552516888422063cf859586f0de14 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Tue, 29 Mar 2016 19:26:13 +0100 Subject: [PATCH] Added editor control in admin settings & Fixed some markdown editor bugs Also updated the setting system with a more sane approach to handling default values. (Now done via the setting-defaults config file) --- app/Repos/PageRepo.php | 4 +++ app/Services/SettingService.php | 13 ++++++++- config/setting-defaults.php | 10 +++++++ ...2016_03_25_123157_add_markdown_support.php | 4 +-- resources/assets/js/controllers.js | 6 ++-- resources/views/pages/form.blade.php | 6 ++-- resources/views/settings/index.blade.php | 28 ++++++++++++------- 7 files changed, 53 insertions(+), 18 deletions(-) create mode 100644 config/setting-defaults.php diff --git a/app/Repos/PageRepo.php b/app/Repos/PageRepo.php index 4c3512fa7..9a7502754 100644 --- a/app/Repos/PageRepo.php +++ b/app/Repos/PageRepo.php @@ -312,6 +312,7 @@ class PageRepo extends EntityRepo $page->fill($input); $page->html = $this->formatHtml($input['html']); $page->text = strip_tags($page->html); + if (setting('app-editor') !== 'markdown') $page->markdown = ''; $page->updated_by = $userId; $page->save(); @@ -348,6 +349,7 @@ class PageRepo extends EntityRepo public function saveRevision(Page $page) { $revision = $this->pageRevision->fill($page->toArray()); + if (setting('app-editor') !== 'markdown') $revision->markdown = ''; $revision->page_id = $page->id; $revision->slug = $page->slug; $revision->book_slug = $page->book->slug; @@ -386,6 +388,8 @@ class PageRepo extends EntityRepo } $draft->fill($data); + if (setting('app-editor') !== 'markdown') $draft->markdown = ''; + $draft->save(); return $draft; } diff --git a/app/Services/SettingService.php b/app/Services/SettingService.php index bcc7eae31..bf5fa918e 100644 --- a/app/Services/SettingService.php +++ b/app/Services/SettingService.php @@ -44,28 +44,39 @@ class SettingService /** * Gets a setting value from the cache or database. + * Looks at the system defaults if not cached or in database. * @param $key * @param $default * @return mixed */ protected function getValueFromStore($key, $default) { + // Check for an overriding value $overrideValue = $this->getOverrideValue($key); if ($overrideValue !== null) return $overrideValue; + // Check the cache $cacheKey = $this->cachePrefix . $key; if ($this->cache->has($cacheKey)) { return $this->cache->get($cacheKey); } + // Check the database $settingObject = $this->getSettingObjectByKey($key); - if ($settingObject !== null) { $value = $settingObject->value; $this->cache->forever($cacheKey, $value); return $value; } + // Check the defaults set in the app config. + $configPrefix = 'setting-defaults.' . $key; + if (config()->has($configPrefix)) { + $value = config($configPrefix); + $this->cache->forever($cacheKey, $value); + return $value; + } + return $default; } diff --git a/config/setting-defaults.php b/config/setting-defaults.php new file mode 100644 index 000000000..17bae1848 --- /dev/null +++ b/config/setting-defaults.php @@ -0,0 +1,10 @@ + 'wysiwyg' + +]; \ No newline at end of file diff --git a/database/migrations/2016_03_25_123157_add_markdown_support.php b/database/migrations/2016_03_25_123157_add_markdown_support.php index 45efe5a09..2daa32cfb 100644 --- a/database/migrations/2016_03_25_123157_add_markdown_support.php +++ b/database/migrations/2016_03_25_123157_add_markdown_support.php @@ -13,11 +13,11 @@ class AddMarkdownSupport extends Migration public function up() { Schema::table('pages', function (Blueprint $table) { - $table->longText('markdown'); + $table->longText('markdown')->default(''); }); Schema::table('page_revisions', function (Blueprint $table) { - $table->longText('markdown'); + $table->longText('markdown')->default(''); }); } diff --git a/resources/assets/js/controllers.js b/resources/assets/js/controllers.js index 09187c0c2..dbd2e1ae6 100644 --- a/resources/assets/js/controllers.js +++ b/resources/assets/js/controllers.js @@ -258,6 +258,10 @@ module.exports = function (ngApp, events) { } } + if (!isMarkdown) { + $scope.editorChange = function() {}; + } + /** * Start the AutoSave loop, Checks for content change * before performing the costly AJAX request. @@ -292,8 +296,6 @@ module.exports = function (ngApp, events) { if (isMarkdown) data.markdown = $scope.editContent; - console.log(data.markdown); - $http.put('/ajax/page/' + pageId + '/save-draft', data).then((responseData) => { $scope.draftText = responseData.data.message; if (!$scope.isNewPageDraft) $scope.isUpdateDraft = true; diff --git a/resources/views/pages/form.blade.php b/resources/views/pages/form.blade.php index 6b16cb870..fe3d28cbc 100644 --- a/resources/views/pages/form.blade.php +++ b/resources/views/pages/form.blade.php @@ -1,5 +1,5 @@ -
+
{{ csrf_field() }}
@@ -42,7 +42,7 @@
- @if(config('app.editor') === 'html') + @if(setting('app-editor') === 'wysiwyg') @if($errors->has('html')) @@ -50,7 +50,7 @@ @endif @endif - @if(config('app.editor') === 'markdown') + @if(setting('app-editor') === 'markdown')
diff --git a/resources/views/settings/index.blade.php b/resources/views/settings/index.blade.php index f94623256..eb580bb8b 100644 --- a/resources/views/settings/index.blade.php +++ b/resources/views/settings/index.blade.php @@ -17,29 +17,37 @@
- +
- +

For performance reasons, all images are public by default, This option adds a random, hard-to-guess characters in front of image names. Ensure directory indexes are not enabled to prevent easy access.

- + +
+
+ +

Select which editor will be used by all users to edit pages.

+

This image should be 43px in height.
Large images will be scaled down.

- +

This should be a hex value.
Leave empty to reset to the default color.

- - + +
@@ -53,14 +61,14 @@
- +
+