Skip to content

Commit

Permalink
Default templates: Cleaned up ux, added case for added endpoint
Browse files Browse the repository at this point in the history
Cleaned up and updated page picker a bit, allowing longer names to show,
clicking through to item without triggering popup, and updated to use
hidden attributes instead of styles.

Added phpunit tests to cover supporting entity-selector-templates
endpoint.
  • Loading branch information
ssddanbrown committed Dec 12, 2023
1 parent d75eb06 commit 2081a78
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 16 deletions.
3 changes: 2 additions & 1 deletion resources/js/components/page-picker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Component} from './component';

function toggleElem(elem, show) {
elem.style.display = show ? null : 'none';
elem.toggleAttribute('hidden', !show);
}

export class PagePicker extends Component {
Expand All @@ -21,6 +21,7 @@ export class PagePicker extends Component {
setupListeners() {
this.selectButton.addEventListener('click', this.showPopup.bind(this));
this.display.parentElement.addEventListener('click', this.showPopup.bind(this));
this.display.addEventListener('click', e => e.stopPropagation());

this.resetButton.addEventListener('click', () => {
this.setValue('', '');
Expand Down
6 changes: 5 additions & 1 deletion resources/sass/_layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,14 @@ body.flexbox {
overflow: hidden;
}

.fill-height {
.height-fill {
height: 100%;
}

.height-auto {
height: auto !important;
}

.float {
float: left;
&.right {
Expand Down
17 changes: 9 additions & 8 deletions resources/views/books/parts/form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,18 @@
<label for="template-manager">{{ trans('entities.books_default_template') }}</label>
</button>
<div refs="collapsible@content" class="collapse-content">
<div class="flex-container-row items-center gap-m justify-space-between pt-s pb-xs">
<p class="text-muted small my-none">
<div class="flex-container-row gap-l justify-space-between pb-xs wrap">
<p class="text-muted small my-none min-width-xs flex">
{{ trans('entities.books_default_template_explain') }}
</p>


@include('form.page-picker', [
'name' => 'default_template_id',
'placeholder' => trans('entities.books_default_template_select'),
'value' => $book?->default_template_id ?? null,
])
<div class="min-width-m">
@include('form.page-picker', [
'name' => 'default_template_id',
'placeholder' => trans('entities.books_default_template_select'),
'value' => $book?->default_template_id ?? null,
])
</div>
</div>

</div>
Expand Down
10 changes: 5 additions & 5 deletions resources/views/form/page-picker.blade.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

{{--Depends on entity selector popup--}}
<div component="page-picker">
<div class="input-base overflow-hidden">
<span @if($value) style="display: none" @endif refs="page-picker@default-display" class="text-muted italic">{{ $placeholder }}</span>
<a @if(!$value) style="display: none" @endif href="{{ url('/link/' . $value) }}" target="_blank" rel="noopener" class="text-page" refs="page-picker@display">#{{$value}}, {{$value ? \BookStack\Entities\Models\Page::query()->visible()->find($value)->name ?? '' : '' }}</a>
<div class="input-base overflow-hidden height-auto">
<span @if($value) hidden @endif refs="page-picker@default-display" class="text-muted italic">{{ $placeholder }}</span>
<a @if(!$value) hidden @endif href="{{ url('/link/' . $value) }}" target="_blank" rel="noopener" class="text-page" refs="page-picker@display">#{{$value}}, {{$value ? \BookStack\Entities\Models\Page::query()->visible()->find($value)->name ?? '' : '' }}</a>
</div>
<br>
<input refs="page-picker@input" type="hidden" value="{{$value}}" name="{{$name}}" id="{{$name}}">
<button @if(!$value) style="display: none" @endif type="button" refs="page-picker@reset-button" class="text-button">{{ trans('common.reset') }}</button>
<span refs="page-picker@button-seperator" @if(!$value) style="display: none" @endif class="sep">|</span>
<button @if(!$value) hidden @endif type="button" refs="page-picker@reset-button" class="text-button">{{ trans('common.reset') }}</button>
<span refs="page-picker@button-seperator" @if(!$value) hidden @endif class="sep">|</span>
<button type="button" refs="page-picker@select-button" class="text-button">{{ trans('common.select') }}</button>
</div>
2 changes: 1 addition & 1 deletion resources/views/pages/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@section('content')

<div id="main-content" class="flex-fill flex fill-height">
<div id="main-content" class="flex-fill flex height-fill">
<form action="{{ $page->getUrl() }}" autocomplete="off" data-page-id="{{ $page->id }}" method="POST" class="flex flex-fill">
{{ csrf_field() }}

Expand Down
25 changes: 25 additions & 0 deletions tests/Entity/EntitySearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,31 @@ public function test_entity_selector_search_reflects_items_without_permission()
$this->withHtml($resp)->assertElementContains($baseSelector, "You don't have the required permissions to select this item");
}

public function test_entity_template_selector_search()
{
$templatePage = $this->entities->newPage(['name' => 'Template search test', 'html' => 'template test']);
$templatePage->template = true;
$templatePage->save();

$nonTemplatePage = $this->entities->newPage(['name' => 'Nontemplate page', 'html' => 'nontemplate', 'template' => false]);

// Visit both to make popular
$this->asEditor()->get($templatePage->getUrl());
$this->asEditor()->get($nonTemplatePage->getUrl());

$normalSearch = $this->get('/search/entity-selector-templates?term=test');
$normalSearch->assertSee($templatePage->name);
$normalSearch->assertDontSee($nonTemplatePage->name);

$normalSearch = $this->get('/search/entity-selector-templates?term=beans');
$normalSearch->assertDontSee($templatePage->name);
$normalSearch->assertDontSee($nonTemplatePage->name);

$defaultListTest = $this->get('/search/entity-selector-templates');
$defaultListTest->assertSee($templatePage->name);
$defaultListTest->assertDontSee($nonTemplatePage->name);
}

public function test_sibling_search_for_pages()
{
$chapter = $this->entities->chapterHasPages();
Expand Down

0 comments on commit 2081a78

Please sign in to comment.