Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a3374e8
chore(2.0): update dependencies
DavideIadeluca Dec 18, 2024
4cb67c2
chore(2.0): update infrastructure
DavideIadeluca Dec 18, 2024
b60c6e8
chore(2.0): misc frontend changes
DavideIadeluca Dec 18, 2024
e44f72f
chore(2.0): JSON:API changes
DavideIadeluca Dec 18, 2024
ad12e3e
chore(2.0): Search & Filter API changes
DavideIadeluca Dec 18, 2024
0960d1f
chore(2.0): `LESS` code changes
DavideIadeluca Dec 18, 2024
df7ac97
chore: update lockfile
DavideIadeluca Dec 18, 2024
3db4956
chore(2.0): minor frontend cleanup
DavideIadeluca Dec 18, 2024
8440e59
chore(2.0): minor translation changes
DavideIadeluca Dec 18, 2024
18f1d53
chore(2.0): cleanup
DavideIadeluca Dec 18, 2024
b72a314
chore(2.0): try to refactor the remainder of the backend
DavideIadeluca Dec 18, 2024
050b054
Apply fixes from StyleCI
StyleCIBot Dec 18, 2024
e0ff4a3
chore: empty line eof
DavideIadeluca Dec 18, 2024
ef92c0d
fix(2.0): adjust frontend typings
DavideIadeluca Dec 18, 2024
2740499
chore: cleanup
DavideIadeluca Dec 18, 2024
ccb59ea
chore
DavideIadeluca Jan 24, 2025
24bc462
chore: output of `yarn upgrade`
DavideIadeluca Jan 24, 2025
18f75cd
Apply fixes from StyleCI
StyleCIBot Jan 24, 2025
e5f8bc3
chore: change main git brach
DavideIadeluca Nov 8, 2025
856000a
chore: bump phpstan level
DavideIadeluca Nov 8, 2025
d5d1925
test: implement basic backend testing
DavideIadeluca Nov 8, 2025
ea4947c
Apply fixes from StyleCI
StyleCIBot Nov 8, 2025
38740da
test: add test for searching
DavideIadeluca Nov 8, 2025
0e49afc
Apply fixes from StyleCI
StyleCIBot Nov 8, 2025
d8a178d
chore: enable backend testing in CI
DavideIadeluca Nov 8, 2025
1ac270b
chore: remove php_versions definition
DavideIadeluca Nov 8, 2025
dfc90fc
chore: add empty admin frontend initializer
DavideIadeluca Nov 8, 2025
c68202b
chore
DavideIadeluca Nov 8, 2025
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
5 changes: 2 additions & 3 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ 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_backend_testing: true
enable_phpstan: true
php_versions: '["7.4", "8.0", "8.1", "8.2"]'

backend_directory: .
4 changes: 2 additions & 2 deletions .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 All @@ -13,7 +13,7 @@ jobs:
frontend_directory: ./js
backend_directory: .
js_package_manager: yarn
main_git_branch: flarum-2.x
main_git_branch: 2.x

secrets:
bundlewatch_github_token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ js/dist
js/node_modules
vendor
composer.lock
tests/.phpunit.result.cache
31 changes: 25 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"flarum/core": "^1.7.0"
"flarum/core": "^2.0.0-beta"
},
"minimum-stability": "dev",
"authors": [
{
"name": "Christian Lopez",
Expand Down Expand Up @@ -51,18 +51,37 @@
},
"flarum-cli": {
"modules": {
"githubActions": true
"githubActions": true,
"backendTesting": true
}
}
},
"require-dev": {
"flarum/phpstan": "*"
"flarum/phpstan": "^2.0.0-beta",
"flarum/testing": "^2.0.0-beta",
"flarum/tags": "^2.0.0-beta"
},
"scripts": {
"analyse:phpstan": "phpstan analyse",
"clear-cache:phpstan": "phpstan clear-result-cache"
"clear-cache:phpstan": "phpstan clear-result-cache",
"test": [
"@test:unit",
"@test:integration"
],
"test:unit": "phpunit -c tests/phpunit.unit.xml",
"test:integration": "phpunit -c tests/phpunit.integration.xml",
"test:setup": "@php tests/integration/setup.php"
},
"scripts-descriptions": {
"analyse:phpstan": "Run static analysis"
"analyse:phpstan": "Run static analysis",
"test": "Runs all tests.",
"test:unit": "Runs all unit tests.",
"test:integration": "Runs all integration tests.",
"test:setup": "Sets up a database for use with integration tests. Execute this only once."
},
"autoload-dev": {
"psr-4": {
"FoF\\FrontPage\\Tests\\": "tests/"
}
}
}
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'
),
];
12 changes: 3 additions & 9 deletions js/src/admin/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import app from 'flarum/admin/app';
export { default as extend } from './extend';

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'
);
app.initializers.add('fof-frontpage', () => {
// Nothing here yet
});
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