Skip to content

Commit

Permalink
Update for beta 16
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Mar 18, 2021
1 parent c7d4a94 commit 8a31796
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 65 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"forum": "https://discuss.flarum.org/d/25907"
},
"require": {
"flarum/core": "^0.1.0-beta.15"
"flarum/core": "^0.1.0-beta.16"
},
"authors": [
{
Expand All @@ -28,7 +28,7 @@
"extra": {
"flarum-extension": {
"title": "HTML Head Items",
"category": "other",
"category": "feature",
"icon": {
"name": "fas fa-heading",
"backgroundColor": "#0072e3",
Expand Down
30 changes: 18 additions & 12 deletions js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"lint": "prettier --single-quote --trailing-comma es5 --print-width 150 --tab-width 4 --write src"
},
"devDependencies": {
"flarum": "0.1.0-beta.16",
"prettier": "^2.2.1"
}
}
10 changes: 6 additions & 4 deletions js/src/admin/components/CreateHeadItemModal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Modal from 'flarum/components/Modal';
import Button from 'flarum/components/Button';
import Stream from 'flarum/utils/Stream';
import Modal from 'flarum/common/components/Modal';
import Button from 'flarum/common/components/Button';
import Stream from 'flarum/common/utils/Stream';

export default class CreateHeadItemModal extends Modal {
oninit(vnode) {
Expand All @@ -19,7 +19,9 @@ export default class CreateHeadItemModal extends Modal {
}

title() {
return this.item.exists ? app.translator.trans('ianm-html-head.admin.modal.edit_title') : app.translator.trans('ianm-html-head.admin.modal.create_title');
return this.item.exists
? app.translator.trans('ianm-html-head.admin.modal.edit_title')
: app.translator.trans('ianm-html-head.admin.modal.create_title');
}

content() {
Expand Down
8 changes: 4 additions & 4 deletions js/src/admin/components/HeadItemList.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Component from 'flarum/Component';
import LoadingIndicator from 'flarum/components/LoadingIndicator';
import Placeholder from 'flarum/components/Placeholder';
import Button from 'flarum/components/Button';
import Component from 'flarum/common/Component';
import LoadingIndicator from 'flarum/common/components/LoadingIndicator';
import Placeholder from 'flarum/common/components/Placeholder';
import Button from 'flarum/common/components/Button';
import HeadItemListItem from './HeadItemListItem';
import CreateHeadItemModal from './CreateHeadItemModal';

Expand Down
8 changes: 4 additions & 4 deletions js/src/admin/components/HeadItemListItem.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Component from 'flarum/Component';
import Button from 'flarum/components/Button';
import Switch from 'flarum/components/Switch';
import Component from 'flarum/common/Component';
import Button from 'flarum/common/components/Button';
import Switch from 'flarum/common/components/Switch';
import CreateHeadItemModal from './CreateHeadItemModal';

export default class HeadItemListItem extends Component {
Expand Down Expand Up @@ -44,7 +44,7 @@ export default class HeadItemListItem extends Component {
{Button.component(
{
className: 'Button Button--secondary',
onclick: () => app.modal.show(CreateHeadItemModal, {item: this.item}),
onclick: () => app.modal.show(CreateHeadItemModal, { item: this.item }),
},
app.translator.trans('ianm-html-head.admin.table.edit_button')
)}
Expand Down
2 changes: 1 addition & 1 deletion js/src/admin/htmlHeadSettingsPage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ExtensionPage from 'flarum/components/ExtensionPage';
import ExtensionPage from 'flarum/common/components/ExtensionPage';
import HeadItem from './components/HeadItemList';

export default class HtmlHeadSettingsPage extends ExtensionPage {
Expand Down
2 changes: 1 addition & 1 deletion js/src/admin/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import app from 'flarum/app';
import app from 'flarum/common/app';
import HtmlHeadSettingsPage from './htmlHeadSettingsPage';
import HeadItem from './model/HeadItem';

Expand Down
2 changes: 1 addition & 1 deletion js/src/admin/model/HeadItem.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Model from 'flarum/Model';
import Model from 'flarum/common/Model';

export default class HeadItem extends Model {
id = Model.attribute('id');
Expand Down
8 changes: 4 additions & 4 deletions src/Api/Controllers/ListHeadersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@

use Flarum\Api\Controller\AbstractListController;
use Flarum\Http\UrlGenerator;
use Flarum\Search\SearchCriteria;
use Flarum\Query\QueryCriteria;
use IanM\HtmlHead\Api\Serializers\HeaderSerializer;
use IanM\HtmlHead\Header;
use IanM\HtmlHead\Search\HeadItemSearcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -29,7 +28,7 @@ class ListHeadersController extends AbstractListController
public $serializer = HeaderSerializer::class;

/**
* @var PageSearcher
* @var HeadItemSearcher
*/
protected $searcher;

Expand All @@ -53,14 +52,15 @@ public function __construct(HeadItemSearcher $searcher, UrlGenerator $url)
*/
protected function data(ServerRequestInterface $request, Document $document)
{
/** @var \Flarum\User\User */
$actor = $request->getAttribute('actor');

$actor->assertAdmin();

$query = Arr::get($this->extractFilter($request), 'q');
$sort = $this->extractSort($request);

$criteria = new SearchCriteria($actor, $query, $sort);
$criteria = new QueryCriteria($actor, $query, $sort);
$limit = $this->extractLimit($request);
$offset = $this->extractOffset($request);
$results = $this->searcher->search($criteria, $limit, $offset);
Expand Down
2 changes: 0 additions & 2 deletions src/Repositories/HtmlHeadRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
use IanM\HtmlHead\Header;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;

class HtmlHeadRepository
{
Expand Down
22 changes: 0 additions & 22 deletions src/Search/HeadItemSearch.php

This file was deleted.

19 changes: 11 additions & 8 deletions src/Search/HeadItemSearcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@

namespace IanM\HtmlHead\Search;

use Flarum\Search\ApplySearchParametersTrait;
use Flarum\Query\ApplyQueryParametersTrait;
use Flarum\Query\QueryCriteria;
use Flarum\Query\QueryResults;
use Flarum\Search\GambitManager;
use Flarum\Search\SearchCriteria;
use Flarum\Search\SearchResults;
use Flarum\Search\SearchState;
use IanM\HtmlHead\Repositories\HtmlHeadRepository;

class HeadItemSearcher
{
use ApplySearchParametersTrait;
use ApplyQueryParametersTrait;

/**
* @var GambitManager
Expand Down Expand Up @@ -48,7 +51,7 @@ public function __construct(GambitManager $gambits, HtmlHeadRepository $bannedIP
*
* @return SearchResults
*/
public function search(SearchCriteria $criteria, $limit = null, $offset = 0)
public function search(QueryCriteria $criteria, $limit = null, $offset = 0): QueryResults
{
$actor = $criteria->actor;

Expand All @@ -58,20 +61,20 @@ public function search(SearchCriteria $criteria, $limit = null, $offset = 0)
$query->whereIsHidden(0);
}

$search = new HeadItemSearch($query->getQuery(), $actor);
$search = new SearchState($query->getQuery(), $actor);

$this->gambits->apply($search, $criteria->query);

$this->applySort($search, $criteria->sort);
$this->applyOffset($search, $offset);
$this->applyLimit($search, $limit + 1);

$bannedIPs = $query->get();
$headItems = $query->get();

if ($areMoreResults = ($limit > 0 && $bannedIPs->count() > $limit)) {
$bannedIPs->pop();
if ($areMoreResults = ($limit > 0 && $headItems->count() > $limit)) {
$headItems->pop();
}

return new SearchResults($bannedIPs, $areMoreResults);
return new QueryResults($headItems, $areMoreResults);
}
}

0 comments on commit 8a31796

Please sign in to comment.