diff --git a/app/Entities/Repos/PageRepo.php b/app/Entities/Repos/PageRepo.php index 6b004984f..adaa7a8d3 100644 --- a/app/Entities/Repos/PageRepo.php +++ b/app/Entities/Repos/PageRepo.php @@ -69,6 +69,10 @@ class PageRepo extends EntityRepo $this->tagRepo->saveTagsToEntity($page, $input['tags']); } + if (isset($input['template']) && userCan('templates-manage')) { + $page->template = ($input['template'] === 'true'); + } + // Update with new details $userId = user()->id; $page->fill($input); @@ -85,8 +89,9 @@ class PageRepo extends EntityRepo $this->userUpdatePageDraftsQuery($page, $userId)->delete(); // Save a revision after updating - if ($oldHtml !== $input['html'] || $oldName !== $input['name'] || $input['summary'] !== null) { - $this->savePageRevision($page, $input['summary']); + $summary = $input['summary'] ?? null; + if ($oldHtml !== $input['html'] || $oldName !== $input['name'] || $summary !== null) { + $this->savePageRevision($page, $summary); } $this->searchService->indexEntity($page); @@ -300,6 +305,10 @@ class PageRepo extends EntityRepo $this->tagRepo->saveTagsToEntity($draftPage, $input['tags']); } + if (isset($input['template']) && userCan('templates-manage')) { + $draftPage->template = ($input['template'] === 'true'); + } + $draftPage->slug = $this->findSuitableSlug('page', $draftPage->name, false, $draftPage->book->id); $draftPage->html = $this->formatHtml($input['html']); $draftPage->text = $this->pageToPlainText($draftPage); diff --git a/database/migrations/2019_07_07_112515_add_template_support.php b/database/migrations/2019_07_07_112515_add_template_support.php new file mode 100644 index 000000000..a54508198 --- /dev/null +++ b/database/migrations/2019_07_07_112515_add_template_support.php @@ -0,0 +1,54 @@ +boolean('template')->default(false); + $table->index('template'); + }); + + // Create new templates-manage permission and assign to admin role + $adminRoleId = DB::table('roles')->where('system_name', '=', 'admin')->first()->id; + $permissionId = DB::table('role_permissions')->insertGetId([ + 'name' => 'templates-manage', + 'display_name' => 'Manage Page Templates', + 'created_at' => Carbon::now()->toDateTimeString(), + 'updated_at' => Carbon::now()->toDateTimeString() + ]); + DB::table('permission_role')->insert([ + 'role_id' => $adminRoleId, + 'permission_id' => $permissionId + ]); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('pages', function (Blueprint $table) { + $table->dropColumn('template'); + }); + + // Remove templates-manage permission + $templatesManagePermission = DB::table('role_permissions') + ->where('name', '=', 'templates_manage')->first(); + + DB::table('permission_role')->where('permission_id', '=', $templatesManagePermission->id)->delete(); + DB::table('role_permissions')->where('name', '=', 'templates_manage')->delete(); + } +} diff --git a/resources/assets/icons/template.svg b/resources/assets/icons/template.svg new file mode 100644 index 000000000..7c142124f --- /dev/null +++ b/resources/assets/icons/template.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/resources/assets/sass/_pages.scss b/resources/assets/sass/_pages.scss index 39e93f5b1..7f2dad147 100755 --- a/resources/assets/sass/_pages.scss +++ b/resources/assets/sass/_pages.scss @@ -258,7 +258,7 @@ display: block; cursor: pointer; padding: $-s $-m; - font-size: 13.5px; + font-size: 16px; line-height: 1.6; border-bottom: 1px solid rgba(255, 255, 255, 0.3); } diff --git a/resources/lang/en/entities.php b/resources/lang/en/entities.php index f6df7e71b..1a5eca207 100644 --- a/resources/lang/en/entities.php +++ b/resources/lang/en/entities.php @@ -233,6 +233,7 @@ return [ ], 'pages_draft_discarded' => 'Draft discarded, The editor has been updated with the current page content', 'pages_specific' => 'Specific Page', + 'pages_is_template' => 'Page Template', // Editor Sidebar 'page_tags' => 'Page Tags', @@ -269,6 +270,9 @@ return [ 'attachments_file_uploaded' => 'File successfully uploaded', 'attachments_file_updated' => 'File successfully updated', 'attachments_link_attached' => 'Link successfully attached to page', + 'templates' => 'Templates', + 'templates_set_as_template' => 'Page is a template', + 'templates_explain_set_as_template' => 'You can set this page as a template so its contents be utilized when creating other pages. Other users will be able to use this template if they have view permissions for this page.', // Profile View 'profile_user_for_x' => 'User for :time', diff --git a/resources/lang/en/settings.php b/resources/lang/en/settings.php index 43b4d4740..3ef53a247 100755 --- a/resources/lang/en/settings.php +++ b/resources/lang/en/settings.php @@ -85,6 +85,7 @@ return [ 'role_manage_roles' => 'Manage roles & role permissions', 'role_manage_entity_permissions' => 'Manage all book, chapter & page permissions', 'role_manage_own_entity_permissions' => 'Manage permissions on own book, chapter & pages', + 'role_manage_page_templates' => 'Manage page templates', 'role_manage_settings' => 'Manage app settings', 'role_asset' => 'Asset Permissions', 'role_asset_desc' => 'These permissions control default access to the assets within the system. Permissions on Books, Chapters and Pages will override these permissions.', diff --git a/resources/views/pages/attachment-manager.blade.php b/resources/views/pages/attachment-manager.blade.php new file mode 100644 index 000000000..7b16c6b7b --- /dev/null +++ b/resources/views/pages/attachment-manager.blade.php @@ -0,0 +1,99 @@ +
{{ trans('entities.attachments_explain') }} {{ trans('entities.attachments_explain_instant_save') }}
+ + + + +{{ trans('entities.attachments_explain') }} {{ trans('entities.attachments_explain_instant_save') }}
- - - - -+ {{ trans('entities.templates_explain_set_as_template') }} +
+ @include('components.toggle-switch', [ + 'name' => 'template', + 'value' => old('template', $page->template ? 'true' : 'false') === 'true', + 'label' => trans('entities.templates_set_as_template') + ]) +