From 8aaf921a5c5057661734003410179d4b8046bdd2 Mon Sep 17 00:00:00 2001 From: Sami Mazouz Date: Sat, 23 Nov 2024 14:36:16 +0100 Subject: [PATCH] fix: admin UI --- extend.php | 1 - js/src/admin/components/SettingsPage.js | 272 +++++++++++++++--------- resources/less/admin/extension.less | 64 ++---- src/Api/ForumResourceFields.php | 2 +- src/Api/Resource/RankResource.php | 9 +- 5 files changed, 196 insertions(+), 152 deletions(-) diff --git a/extend.php b/extend.php index 47c6a6e..95b22f4 100644 --- a/extend.php +++ b/extend.php @@ -29,7 +29,6 @@ use FoF\Extend\Extend\ExtensionSettings; use FoF\Gamification\Api\Controllers; use FoF\Gamification\Notification\VoteBlueprint; -use FoF\Gamification\Provider\GamificationSortOptionsProvider; return [ (new Extend\Frontend('admin')) diff --git a/js/src/admin/components/SettingsPage.js b/js/src/admin/components/SettingsPage.js index 574715b..b9e8ec9 100755 --- a/js/src/admin/components/SettingsPage.js +++ b/js/src/admin/components/SettingsPage.js @@ -6,6 +6,9 @@ import Switch from 'flarum/common/components/Switch'; import withAttr from 'flarum/common/utils/withAttr'; import Stream from 'flarum/common/utils/Stream'; import ItemList from 'flarum/common/utils/ItemList'; +import Form from 'flarum/common/components/Form'; +import FormSection from 'flarum/admin/components/FormSection'; +import FormSectionGroup from 'flarum/admin/components/FormSectionGroup'; import UploadImageButton from './UploadImageButton'; import GroupSettings from './GroupSettings'; @@ -99,11 +102,13 @@ export default class SettingsPage extends ExtensionPage { name: this.newRank.name(), color: this.newRank.color(), }) - .then(() => { + .then((rank) => { this.newRank.color(''); this.newRank.name(''); this.newRank.points(''); + this.ranks.push(rank); + m.redraw(); }); } @@ -160,7 +165,7 @@ export default class SettingsPage extends ExtensionPage { items.add( 'convertLikesToUpvotes', -
+
{app.translator.trans('fof-gamification.admin.page.convert.help')}
{this.values.convertedLikes() === undefined ? ( , + 0 + ); + + return items; + } + + firstSectionGroupItems() { + const items = new ItemList(); + items.add( 'ranks', -
- {app.translator.trans('fof-gamification.admin.page.ranks.title')} + +
{this.rankItems().toArray()}
+
, + 90 + ); + + items.add( + 'voteSettings', + +
{this.voteItems().toArray()}
+
, + 80 + ); + + return items; + } + + secondSectionGroupItems() { + const items = new ItemList(); + + items.add( + 'rankingsPage', + {this.rankingsItems().toArray()}, + 70 + ); + + items.add( + 'groups', + +
{app.translator.trans('fof-gamification.admin.page.groups.help')}
+ +
, + 60 + ); + + return items; + } + + rankItems() { + const items = new ItemList(); + + items.add( + 'ranks', +
{app.translator.trans('fof-gamification.admin.page.ranks.help.help')}
-
- {this.ranks.map((rank) => ( -
- - - -
- ))} -
-
+ {this.ranks.length > 0 ? ( +
+ {this.ranks.map((rank) => ( +
+ + + +
+ ))} +
+ ) : null} +
+
, + 100 + ); + + items.add( + 'rankNumbers', +
-
, - 90 - ); - - items.add( - 'voteSettings', - <> - {app.translator.trans('fof-gamification.admin.page.votes.title')} - {this.voteItems().toArray()} - , +
, 80 ); - items.add( - 'rankingsPage', - <> - {app.translator.trans('fof-gamification.admin.page.rankings.title')} - {this.rankingsItems().toArray()} - , - 70 - ); - - items.add( - 'groups', -
- {app.translator.trans('fof-gamification.admin.page.groups.title')} -
{app.translator.trans('fof-gamification.admin.page.groups.help')}
- -
, - 60 - ); - - items.add( - 'submit', - , - 0 - ); - return items; } @@ -304,7 +347,7 @@ export default class SettingsPage extends ExtensionPage { items.add( 'icon', - <> +
{app.translator.trans('fof-gamification.admin.page.votes.icon_help')}
- , +
, 100 ); items.add( 'altIcon', - <> +
{app.translator.trans('fof-gamification.admin.page.votes.icon_help')}
- , +
, 90 ); items.add( 'autoUpvote', - - {app.translator.trans('fof-gamification.admin.page.votes.auto_upvote')} - , +
+ + {app.translator.trans('fof-gamification.admin.page.votes.auto_upvote')} + +
, 80 ); items.add( 'rateLimit', - - {app.translator.trans('fof-gamification.admin.page.votes.rate_limit')} - , +
+ + {app.translator.trans('fof-gamification.admin.page.votes.rate_limit')} + +
, 70 ); items.add( 'opVotesOnDiscussionList', - - {app.translator.trans('fof-gamification.admin.page.votes.discussion_page')} - , +
+ + {app.translator.trans('fof-gamification.admin.page.votes.discussion_page')} + +
, 60 ); items.add( 'altDiscussionListLayout', - - {app.translator.trans('fof-gamification.admin.page.votes.alternate_layout')} - , +
+ + {app.translator.trans('fof-gamification.admin.page.votes.alternate_layout')} + +
, 50 ); items.add( 'altPostLayout', - - {app.translator.trans('fof-gamification.admin.page.votes.alternate_post_layout')} - , +
+ + {app.translator.trans('fof-gamification.admin.page.votes.alternate_post_layout')} + +
, 40 ); items.add( 'upvotesOnly', - - {app.translator.trans('fof-gamification.admin.page.votes.upvotes_only')} - , +
+ + {app.translator.trans('fof-gamification.admin.page.votes.upvotes_only')} + +
, 30 ); items.add( 'firstPostOnly', - - {app.translator.trans('fof-gamification.admin.page.votes.first_post_only')} - , +
+ + {app.translator.trans('fof-gamification.admin.page.votes.first_post_only')} + +
, 20 ); items.add( 'allowSelfVotes', - - {app.translator.trans('fof-gamification.admin.page.votes.allow_self_votes')} - , +
+ + {app.translator.trans('fof-gamification.admin.page.votes.allow_self_votes')} + +
, 10 ); @@ -404,32 +463,34 @@ export default class SettingsPage extends ExtensionPage { items.add( 'customImages', - - {app.translator.trans('fof-gamification.admin.page.rankings.enable')} - , +
+ + {app.translator.trans('fof-gamification.admin.page.rankings.enable')} + +
, 100 ); items.add( 'ignoredUsers', - <> +
+
{app.translator.trans('fof-gamification.admin.page.rankings.blocked.help')}
- , +
, 90 ); items.add( 'customImages', <> -
{app.translator.trans('fof-gamification.admin.page.rankings.blocked.help')}
{[1, 2, 3].map((num) => ( - <> +
-
- +
))} , 80 diff --git a/resources/less/admin/extension.less b/resources/less/admin/extension.less index cb55190..acb0d41 100755 --- a/resources/less/admin/extension.less +++ b/resources/less/admin/extension.less @@ -3,17 +3,7 @@ .SettingsPage { padding: 20px 0; - - legend { - margin-top: 25px; - } - @media @desktop-up { - .container { - max-width: 600px; - margin: 0; - } - fieldset { margin-bottom: 30px; @@ -30,42 +20,16 @@ margin-top: 5px; margin-bottom: 5px } - + .Upload-label { margin-right: 15px; } - + .Upload-button { margin-top: 7.5px; margin-bottom: 7.5px; } - .helpText { - margin-bottom: 20px; - } - - .SettingsPage-ranks { - margin-top: 20px; - } - - .Ranks-number { - width: 15%; - float: left; - margin: 5px 5px 5px; - } - .Ranks-name { - width: 30%; - float: left; - margin: 5px 5px 5px; - } - .Ranks-color { - width: 18%; - float: left; - margin: 5px 5px 5px; - } - .Ranks-button { - margin: 5px 0 5px; - } .Ranks-default { width: 30%; margin-top: 5px; @@ -74,8 +38,26 @@ .Ranks-save { margin-top: 15px; } - .votes-switch { - margin-top: 20px; - margin-bottom: 20px; + + .Ranks--Container-row { + display: flex; + gap: 4px; + width: auto; + } + + .Ranks--Container-row > * { + flex-shrink: 1; + flex-grow: 0; + } + + .Ranks--Container-row > button { + flex-grow: 1; + flex-shrink: 0; + } + + .Ranks--Container { + display: flex; + flex-direction: column; + gap: 6px; } } diff --git a/src/Api/ForumResourceFields.php b/src/Api/ForumResourceFields.php index 1179721..aec2bba 100644 --- a/src/Api/ForumResourceFields.php +++ b/src/Api/ForumResourceFields.php @@ -48,7 +48,7 @@ public function __invoke(): array Schema\Relationship\ToMany::make('ranks') ->type('ranks') ->includable() - ->get(fn () => Rank::all()), + ->get(fn () => Rank::query()->get()->all()), ]; } diff --git a/src/Api/Resource/RankResource.php b/src/Api/Resource/RankResource.php index 3a7c8fe..c478a94 100644 --- a/src/Api/Resource/RankResource.php +++ b/src/Api/Resource/RankResource.php @@ -49,11 +49,14 @@ public function fields(): array return [ Schema\Number::make('points') - ->requiredOnCreate(), + ->requiredOnCreate() + ->writable(), Schema\Str::make('name') - ->requiredOnCreate(), + ->requiredOnCreate() + ->writable(), Schema\Str::make('color') - ->requiredOnCreate(), + ->requiredOnCreate() + ->writable(), ]; }