diff --git a/app/Http/Controllers/ChapterController.php b/app/Http/Controllers/ChapterController.php index a4e0b6409..b737afc6d 100644 --- a/app/Http/Controllers/ChapterController.php +++ b/app/Http/Controllers/ChapterController.php @@ -107,17 +107,14 @@ class ChapterController extends Controller * @param $bookSlug * @param $chapterSlug * @return Response + * @throws \BookStack\Exceptions\NotFoundException */ public function update(Request $request, $bookSlug, $chapterSlug) { $chapter = $this->entityRepo->getBySlug('chapter', $chapterSlug, $bookSlug); $this->checkOwnablePermission('chapter-update', $chapter); - if ($chapter->name !== $request->get('name')) { - $chapter->slug = $this->entityRepo->findSuitableSlug('chapter', $request->get('name'), $chapter->id, $chapter->book->id); - } - $chapter->fill($request->all()); - $chapter->updated_by = user()->id; - $chapter->save(); + + $this->entityRepo->updateFromInput('chapter', $chapter, $request->all()); Activity::add($chapter, 'chapter_update', $chapter->book->id); return redirect($chapter->getUrl()); } diff --git a/app/Repos/EntityRepo.php b/app/Repos/EntityRepo.php index ece9aa305..e94d34369 100644 --- a/app/Repos/EntityRepo.php +++ b/app/Repos/EntityRepo.php @@ -492,14 +492,19 @@ class EntityRepo public function createFromInput($type, $input = [], $book = false) { $isChapter = strtolower($type) === 'chapter'; - $entity = $this->getEntity($type)->newInstance($input); - $entity->slug = $this->findSuitableSlug($type, $entity->name, false, $isChapter ? $book->id : false); - $entity->created_by = user()->id; - $entity->updated_by = user()->id; - $isChapter ? $book->chapters()->save($entity) : $entity->save(); - $this->permissionService->buildJointPermissionsForEntity($entity); - $this->searchService->indexEntity($entity); - return $entity; + $entityModel = $this->getEntity($type)->newInstance($input); + $entityModel->slug = $this->findSuitableSlug($type, $entityModel->name, false, $isChapter ? $book->id : false); + $entityModel->created_by = user()->id; + $entityModel->updated_by = user()->id; + $isChapter ? $book->chapters()->save($entityModel) : $entityModel->save(); + + if (isset($input['tags'])) { + $this->tagRepo->saveTagsToEntity($entityModel, $input['tags']); + } + + $this->permissionService->buildJointPermissionsForEntity($entityModel); + $this->searchService->indexEntity($entityModel); + return $entityModel; } /** @@ -518,6 +523,11 @@ class EntityRepo $entityModel->fill($input); $entityModel->updated_by = user()->id; $entityModel->save(); + + if (isset($input['tags'])) { + $this->tagRepo->saveTagsToEntity($entityModel, $input['tags']); + } + $this->permissionService->buildJointPermissionsForEntity($entityModel); $this->searchService->indexEntity($entityModel); return $entityModel; diff --git a/resources/assets/js/vues/tag-manager.js b/resources/assets/js/vues/tag-manager.js index 97c00487e..177af681f 100644 --- a/resources/assets/js/vues/tag-manager.js +++ b/resources/assets/js/vues/tag-manager.js @@ -2,7 +2,8 @@ const draggable = require('vuedraggable'); const autosuggest = require('./components/autosuggest'); let data = { - pageId: false, + entityId: false, + entityType: null, tags: [], }; @@ -48,9 +49,10 @@ let methods = { }; function mounted() { - this.pageId = Number(this.$el.getAttribute('page-id')); + this.entityId = Number(this.$el.getAttribute('entity-id')); + this.entityType = this.$el.getAttribute('entity-type'); - let url = window.baseUrl(`/ajax/tags/get/page/${this.pageId}`); + let url = window.baseUrl(`/ajax/tags/get/${this.entityType}/${this.entityId}`); this.$http.get(url).then(response => { let tags = response.data; for (let i = 0, len = tags.length; i < len; i++) { diff --git a/resources/assets/sass/_blocks.scss b/resources/assets/sass/_blocks.scss index 4cf2397bc..f876ff281 100644 --- a/resources/assets/sass/_blocks.scss +++ b/resources/assets/sass/_blocks.scss @@ -226,6 +226,7 @@ text-align: center; justify-content: center; width: 28px; + flex-grow: 0; padding-left: $-xs; padding-right: $-xs; &:hover { @@ -237,6 +238,7 @@ } > div .outline input { margin: $-s 0; + width: 100%; } > div.padded { padding: $-s 0 !important; @@ -251,6 +253,7 @@ > div { padding: 0 $-s; max-width: 80%; + flex: 1; } } diff --git a/resources/assets/sass/_components.scss b/resources/assets/sass/_components.scss index 84eebc89b..31e006e27 100644 --- a/resources/assets/sass/_components.scss +++ b/resources/assets/sass/_components.scss @@ -604,3 +604,7 @@ body.flexbox-support #entity-selector-wrap .popup-body .form-group { color: #999; } } + +#tag-manager .drag-card { + max-width: 500px; +} \ No newline at end of file diff --git a/resources/assets/sass/_forms.scss b/resources/assets/sass/_forms.scss index 11adc7951..3ab2de522 100644 --- a/resources/assets/sass/_forms.scss +++ b/resources/assets/sass/_forms.scss @@ -237,6 +237,9 @@ input:checked + .toggle-switch { &.open .collapse-title label:before { transform: rotate(90deg); } + &+.form-group[collapsible] { + margin-top: -($-s + 1); + } } .inline-input-style { diff --git a/resources/lang/en/entities.php b/resources/lang/en/entities.php index 8a47ae011..c25dbb623 100644 --- a/resources/lang/en/entities.php +++ b/resources/lang/en/entities.php @@ -200,8 +200,10 @@ return [ * Editor sidebar */ 'page_tags' => 'Page Tags', + 'chapter_tags' => 'Chapter Tags', + 'book_tags' => 'Book Tags', 'tag' => 'Tag', - 'tags' => '', + 'tags' => 'Tags', 'tag_value' => 'Tag Value (Optional)', 'tags_explain' => "Add some tags to better categorise your content. \n You can assign a value to a tag for more in-depth organisation.", 'tags_add' => 'Add another tag', diff --git a/resources/views/books/form.blade.php b/resources/views/books/form.blade.php index 0620ae976..880149777 100644 --- a/resources/views/books/form.blade.php +++ b/resources/views/books/form.blade.php @@ -11,23 +11,32 @@
{{ trans('common.cover_image_description') }}
+{{ trans('common.cover_image_description') }}
- @include('components.image-picker', [ - 'resizeHeight' => '512', - 'resizeWidth' => '512', - 'showRemove' => false, - 'defaultImage' => baseUrl('/book_default_cover.png'), - 'currentImage' => @isset($model) ? $model->getBookCover() : baseUrl('/book_default_cover.png') , - 'currentId' => @isset($model) ? $model->image_id : 0, - 'name' => 'image_id', - 'imageClass' => 'cover' - ]) -value) colspan="2" @endif>{{ $tag->name }} | + @if($tag->value){{$tag->value}} | @endif +
value) colspan="2" @endif>{{ $tag->name }} | - @if($tag->value){{$tag->value}} | @endif -