Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0 Upgrade #35

Draft
wants to merge 18 commits into
base: flarum-2.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ on: [workflow_dispatch, push, pull_request]

jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@1.x
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@2.x
with:
enable_backend_testing: false
enable_phpstan: true
php_versions: '["7.4", "8.0", "8.1", "8.2"]'
php_versions: '["8.2", "8.3", "8.4"]'

backend_directory: .
2 changes: 1 addition & 1 deletion .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [workflow_dispatch, push, pull_request]

jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_frontend.yml@1.x
uses: flarum/framework/.github/workflows/REUSABLE_frontend.yml@2.x
with:
enable_bundlewatch: false
enable_prettier: true
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"flarum/core": "^1.7.0"
"php": "^8.2",
"flarum/core": "^2.0.0-beta"
},
"minimum-stability": "dev",
"authors": [
{
"name": "Christian Lopez",
Expand Down Expand Up @@ -56,7 +57,7 @@
}
},
"require-dev": {
"flarum/phpstan": "*"
"flarum/phpstan": "^2.0.0-beta"
},
"scripts": {
"analyse:phpstan": "phpstan analyse",
Expand Down
30 changes: 13 additions & 17 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

namespace FoF\FrontPage;

use Flarum\Api\Controller\ListDiscussionsController;
use Flarum\Api\Serializer\DiscussionSerializer;
use Flarum\Api\Resource;
use Flarum\Api\Sort\SortColumn;
use Flarum\Discussion\Discussion;
use Flarum\Discussion\Event\Saving;
use Flarum\Discussion\Filter\DiscussionFilterer;
use Flarum\Discussion\Search\DiscussionSearcher;
use Flarum\Extend;
use Flarum\Search\Database\DatabaseSearchDriver;
use FoF\FrontPage\Api\DiscussionResourceFields;

return [
(new Extend\Frontend('forum'))
Expand All @@ -28,28 +28,24 @@
->js(__DIR__.'/js/dist/admin.js'),
new Extend\Locales(__DIR__.'/resources/locale'),

(new Extend\Event())
->listen(Saving::class, Listeners\SaveFrontToDatabase::class),

(new Extend\SimpleFlarumSearch(DiscussionSearcher::class))
->addGambit(Query\FrontFilterGambit::class),

(new Extend\Filter(DiscussionFilterer::class))
->addFilter(Query\FrontFilterGambit::class),

(new Extend\Model(Discussion::class))
->cast('frontdate', 'datetime')
->cast('frontpage', 'bool'),

(new Extend\ApiSerializer(DiscussionSerializer::class))
->attributes(Listeners\AddApiAttributes::class),
(new Extend\ApiResource(Resource\DiscussionResource::class))
->fields(DiscussionResourceFields::class),

(new Extend\ApiController(ListDiscussionsController::class))
->addSortField('frontdate'),
(new Extend\ApiResource(Resource\DiscussionResource::class))
->sorts(fn () => [
SortColumn::make('frontdate'),
]),

(new Extend\ServiceProvider())
->register(Provider\FrontpageSortmapProvider::class),

(new Extend\Middleware('forum'))
->add(Middleware\AddFrontpageFilter::class),

(new Extend\SearchDriver(DatabaseSearchDriver::class))
->addFilter(DiscussionSearcher::class, Query\FrontFilter::class),
];
10 changes: 5 additions & 5 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"private": true,
"prettier": "@flarum/prettier-config",
"devDependencies": {
"prettier": "^3.0.3",
"@flarum/prettier-config": "^1.0.0",
"flarum-tsconfig": "^1.0.3",
"flarum-webpack-config": "^2.0.0",
"flarum-tsconfig": "^2.0.0",
"flarum-webpack-config": "^3.0.0",
"prettier": "^3.0.3",
"typescript-coverage-report": "^0.6.1",
"webpack": "^5.94.0",
"webpack-cli": "^5.1.4",
"typescript-coverage-report": "^0.6.1"
"webpack-cli": "^5.1.4"
},
"scripts": {
"dev": "webpack --mode development --watch",
Expand Down
16 changes: 16 additions & 0 deletions js/src/admin/extend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import app from 'flarum/admin/app';
import Extend from 'flarum/common/extenders';
import { default as commonExtend } from '../common/extend';

export default [
...commonExtend,

new Extend.Admin().permission(
() => ({
icon: 'fas fa-home',
label: app.translator.trans('fof-frontpage.admin.permissions.can_push_to_frontpage_label'),
permission: 'discussion.front',
}),
'moderate'
),
];
13 changes: 1 addition & 12 deletions js/src/admin/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1 @@
import app from 'flarum/admin/app';

app.initializers.add('fof/frontpage', () => {
app.extensionData.for('fof-frontpage').registerPermission(
{
icon: 'fas fa-home',
label: app.translator.trans('core.admin.permissions.can_push_to_frontpage_label'),
permission: 'discussion.front',
},
'moderate'
);
});
export { default as extend } from './extend';
4 changes: 4 additions & 0 deletions js/src/common/extend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Extend from 'flarum/common/extenders';
import FrontGambit from './gambits/FrontGambit';

export default [new Extend.Search().gambit('discussions', FrontGambit)];
12 changes: 12 additions & 0 deletions js/src/common/gambits/FrontGambit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import app from 'flarum/common/app';
import { BooleanGambit } from 'flarum/common/query/IGambit';

export default class FrontGambit extends BooleanGambit {
key() {
return app.translator.trans('fof-frontpage.lib.gambits.frontpage.key', {}, true);
}

filterKey() {
return 'frontpage';
}
}
3 changes: 3 additions & 0 deletions js/src/forum/extend.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { default as commonExtend } from '../common/extend';
import Extend from 'flarum/common/extenders';
import Discussion from 'flarum/common/models/Discussion';
import Model from 'flarum/common/Model';

export default [
...commonExtend,

new Extend.Model(Discussion) //
.attribute<boolean>('frontpage')
.attribute('frontdate', Model.transformDate)
Expand Down
3 changes: 2 additions & 1 deletion js/src/forum/extenders/addFrontSort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { extend } from 'flarum/common/extend';
import DiscussionListState from 'flarum/forum/states/DiscussionListState';

import type { PaginatedListParams } from 'flarum/common/states/PaginatedListState';
import type { SortMap } from 'flarum/common/states/PaginatedListState';

export default function () {
extend(DiscussionListState.prototype, 'requestParams', function (this: DiscussionListState, params: PaginatedListParams) {
Expand All @@ -14,7 +15,7 @@ export default function () {
}
});

extend(DiscussionListState.prototype, 'sortMap', function (map: Record<string, string>) {
extend(DiscussionListState.prototype, 'sortMap', function (map: SortMap) {
map.front = '-frontdate';
});
}
2 changes: 1 addition & 1 deletion js/src/forum/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import addStickyBadge from './extenders/addStickyBadge';

export { default as extend } from './extend';

app.initializers.add('fof/frontpage', () => {
app.initializers.add('fof-frontpage', () => {
addFrontSort();
addFrontPage();
addStickyBadge();
Expand Down
Loading
Loading