use BookStack\Entities\Repos\BookRepo;
use BookStack\Entities\Repos\BookshelfRepo;
use BookStack\Entities\Tools\PageContent;
+use BookStack\Util\SimpleListOptions;
+use Illuminate\Http\Request;
class HomeController extends Controller
{
/**
* Display the homepage.
*/
- public function index(ActivityQueries $activities)
+ public function index(Request $request, ActivityQueries $activities)
{
$activity = $activities->latest(10);
$draftPages = [];
if ($homepageOption === 'bookshelves' || $homepageOption === 'books') {
$key = $homepageOption;
$view = setting()->getForCurrentUser($key . '_view_type');
- $sort = setting()->getForCurrentUser($key . '_sort', 'name');
- $order = setting()->getForCurrentUser($key . '_sort_order', 'asc');
-
- $sortOptions = [
- 'name' => trans('common.sort_name'),
+ $listOptions = SimpleListOptions::fromRequest($request, $key)->withSortOptions([
+ 'name' => trans('common.sort_name'),
'created_at' => trans('common.sort_created_at'),
'updated_at' => trans('common.sort_updated_at'),
- ];
+ ]);
$commonData = array_merge($commonData, [
'view' => $view,
- 'sort' => $sort,
- 'order' => $order,
- 'sortOptions' => $sortOptions,
+ 'listOptions' => $listOptions,
]);
}
if ($homepageOption === 'bookshelves') {
- $shelves = app(BookshelfRepo::class)->getAllPaginated(18, $commonData['sort'], $commonData['order']);
+ $shelves = app(BookshelfRepo::class)->getAllPaginated(18, $commonData['listOptions']->getSort(), $commonData['listOptions']->getOrder());
$data = array_merge($commonData, ['shelves' => $shelves]);
return view('home.shelves', $data);
}
if ($homepageOption === 'books') {
- $bookRepo = app(BookRepo::class);
- $books = $bookRepo->getAllPaginated(18, $commonData['sort'], $commonData['order']);
+ $books = app(BookRepo::class)->getAllPaginated(18, $commonData['listOptions']->getSort(), $commonData['listOptions']->getOrder());
$data = array_merge($commonData, ['books' => $books]);
return view('home.books', $data);
$resp->assertSeeText($page->name);
$resp->assertSeeText('page_create');
$resp->assertSeeText($activity->created_at->toDateTimeString());
- $this->withHtml($resp)->assertElementContains('.table-user-item', $admin->name);
+ $this->withHtml($resp)->assertElementContains('a[href*="users/' . $admin->id . '"]', $admin->name);
}
public function test_shows_name_for_deleted_items()
$this->createRevisions($page, 1, ['html' => 'new page html']);
$resp = $this->asAdmin()->get($page->refresh()->getUrl('/revisions'));
- $this->withHtml($resp)->assertElementContains('td', '(WYSIWYG)');
- $this->withHtml($resp)->assertElementNotContains('td', '(Markdown)');
+ $this->withHtml($resp)->assertElementContains('.item-list-row > div:nth-child(2)', 'WYSIWYG)');
+ $this->withHtml($resp)->assertElementNotContains('.item-list-row > div:nth-child(2)', 'Markdown)');
$this->createRevisions($page, 1, ['markdown' => '# Some markdown content']);
$resp = $this->get($page->refresh()->getUrl('/revisions'));
- $this->withHtml($resp)->assertElementContains('td', '(Markdown)');
+ $this->withHtml($resp)->assertElementContains('.item-list-row > div:nth-child(2)', 'Markdown)');
}
public function test_revision_restore_action_only_visible_with_permission()
$resp->assertSee('OtherTestContent');
$resp->assertDontSee('OtherTagName');
$resp->assertSee('Active Filter:');
- $this->withHtml($resp)->assertElementCount('table .tag-item', 2);
+ $this->withHtml($resp)->assertElementCount('.item-list .tag-item', 2);
$this->withHtml($resp)->assertElementContains('form[action$="/tags"]', 'Clear Filter');
}
$viewReq = $this->asAdmin()->get('/settings/recycle-bin');
$html = $this->withHtml($viewReq);
- $html->assertElementContains('table.table', $page->name);
- $html->assertElementContains('table.table', $editor->name);
- $html->assertElementContains('table.table', $book->name);
- $html->assertElementContains('table.table', $book->pages_count . ' Pages');
- $html->assertElementContains('table.table', $book->chapters_count . ' Chapters');
+ $html->assertElementContains('.item-list-row', $page->name);
+ $html->assertElementContains('.item-list-row', $editor->name);
+ $html->assertElementContains('.item-list-row', $book->name);
+ $html->assertElementContains('.item-list-row', $book->pages_count . ' Pages');
+ $html->assertElementContains('.item-list-row', $book->chapters_count . ' Chapters');
}
public function test_recycle_bin_empty()
$this->assertEquals('desc', setting()->getForCurrentUser('books_sort_order'));
}
- public function test_update_sort_preference_defaults()
- {
- $editor = $this->getEditor();
- $this->actingAs($editor);
-
- $updateRequest = $this->patch('/settings/users/' . $editor->id . '/change-sort/bookshelves', [
- 'sort' => 'cat',
- 'order' => 'dog',
- ]);
- $updateRequest->assertStatus(302);
-
- $this->assertEquals('name', setting()->getForCurrentUser('bookshelves_sort'));
- $this->assertEquals('asc', setting()->getForCurrentUser('bookshelves_sort_order'));
- }
-
public function test_update_sort_bad_entity_type_handled()
{
$editor = $this->getEditor();