From f539bb9e20aed81e3506fb3dc193ff17c166f6cf Mon Sep 17 00:00:00 2001 From: Shahiem Seymor Date: Sat, 18 Aug 2018 15:28:17 +0200 Subject: [PATCH] Add view switch --- js/admin/dist/extension.js | 4 +- js/admin/src/components/KosekiPage.js | 4 +- js/forum/dist/extension.js | 83 +++++++++++++++++------ js/forum/src/components/ChildTagView.js | 25 +++++-- js/forum/src/components/PrimaryTagView.js | 23 +++++-- resources/less/categories.less | 3 +- src/Listeners/AddRelationships.php | 14 ++++ 7 files changed, 116 insertions(+), 40 deletions(-) diff --git a/js/admin/dist/extension.js b/js/admin/dist/extension.js index 4000b97..bab6b47 100644 --- a/js/admin/dist/extension.js +++ b/js/admin/dist/extension.js @@ -89,7 +89,7 @@ System.register('reflar/koseki/components/KosekiPage', ['flarum/components/Page' babelHelpers.get(KosekiPage.prototype.__proto__ || Object.getPrototypeOf(KosekiPage.prototype), 'init', this).call(this); this.loading = false; - this.tagsView = m.prop(app.data.settings['kosekiTagsView']); + this.tagsView = m.prop(app.data.settings['koseki.tags_view']); } }, { key: 'view', @@ -191,7 +191,7 @@ System.register('reflar/koseki/components/KosekiPage', ['flarum/components/Page' this.loading = true; var settings = { - kosekiTagsView: this.tagsView() + 'koseki.tags_view': this.tagsView() }; saveSettings(settings).then(function () { diff --git a/js/admin/src/components/KosekiPage.js b/js/admin/src/components/KosekiPage.js index 6e7246a..cdac888 100644 --- a/js/admin/src/components/KosekiPage.js +++ b/js/admin/src/components/KosekiPage.js @@ -7,7 +7,7 @@ export default class KosekiPage extends Page { super.init(); this.loading = false; - this.tagsView = m.prop(app.data.settings['kosekiTagsView']); + this.tagsView = m.prop(app.data.settings['koseki.tags_view']); } view() { return ( @@ -57,7 +57,7 @@ export default class KosekiPage extends Page { this.loading = true; const settings = { - kosekiTagsView: this.tagsView() + 'koseki.tags_view': this.tagsView() }; saveSettings(settings) diff --git a/js/forum/dist/extension.js b/js/forum/dist/extension.js index eed3cdf..a866732 100644 --- a/js/forum/dist/extension.js +++ b/js/forum/dist/extension.js @@ -28,6 +28,7 @@ System.register('reflar/koseki/components/ChildTagView', ['flarum/Component', 'r key: 'view', value: function view() { var tag = this.props.tag; + var tagView = app.forum.attribute('kosekiTagsView'); return m( 'div', @@ -63,22 +64,43 @@ System.register('reflar/koseki/components/ChildTagView', ['flarum/Component', 'r ) ) ), - m( + tagView == 'compact' ? m( 'div', - { 'class': 'col-xs-2 col-lg-1' }, + null, m( - 'span', - { 'class': 'TagChild-topics' }, - tag.discussionsCount() + 'div', + { 'class': 'col-xs-2 col-lg-2' }, + m( + 'span', + { className: 'TagChild-topics' }, + tag.discussionsCount() + ' ' + app.translator.transChoice('reflar-koseki.forum.topics', tag.discussionsCount(), { count: tag.discussionsCount() }) + ), + m( + 'span', + { className: 'TagChild-posts' }, + tag.commentsCount() + ' ' + app.translator.transChoice('reflar-koseki.forum.posts', tag.commentsCount() == 0 ? 0 : tag.commentsCount(), { count: tag.commentsCount() == 0 ? 0 : tag.commentsCount() }) + ) ) - ), - m( + ) : m( 'div', - { 'class': 'col-xs-2 col-lg-1' }, + null, m( - 'span', - { 'class': 'TagChild-posts' }, - tag.commentsCount() + 'div', + { 'class': 'col-xs-2 col-lg-1' }, + m( + 'span', + { 'class': 'TagChild-topics' }, + tag.discussionsCount() + ) + ), + m( + 'div', + { 'class': 'col-xs-2 col-lg-1' }, + m( + 'span', + { 'class': 'TagChild-posts' }, + tag.commentsCount() + ) ) ), m( @@ -253,6 +275,7 @@ System.register('reflar/koseki/components/PrimaryTagView', ['flarum/Component', key: 'view', value: function view() { var tag = this.props.tag; + var tagView = app.forum.attribute('kosekiTagsView'); return m( 'div', @@ -275,22 +298,38 @@ System.register('reflar/koseki/components/PrimaryTagView', ['flarum/Component', tag.name() ) ), - m( + tagView == 'compact' ? m( 'div', - { 'class': 'col-xs-2 col-lg-1' }, + null, m( - 'span', - { 'class': 'TagTile-topics' }, - app.translator.trans('reflar-koseki.forum.topics_title') + 'div', + { 'class': 'col-xs-2 col-lg-2' }, + m( + 'span', + { 'class': 'TagTile-posts' }, + app.translator.trans('reflar-koseki.forum.statistics') + ) ) - ), - m( + ) : m( 'div', - { 'class': 'col-xs-2 col-lg-1' }, + null, m( - 'span', - { 'class': 'TagTile-posts' }, - app.translator.trans('reflar-koseki.forum.posts_title') + 'div', + { 'class': 'col-xs-2 col-lg-1' }, + m( + 'span', + { 'class': 'TagTile-topics' }, + app.translator.trans('reflar-koseki.forum.topics_title') + ) + ), + m( + 'div', + { 'class': 'col-xs-2 col-lg-1' }, + m( + 'span', + { 'class': 'TagTile-posts' }, + app.translator.trans('reflar-koseki.forum.posts_title') + ) ) ), m( diff --git a/js/forum/src/components/ChildTagView.js b/js/forum/src/components/ChildTagView.js index 8097559..1345af1 100644 --- a/js/forum/src/components/ChildTagView.js +++ b/js/forum/src/components/ChildTagView.js @@ -8,6 +8,7 @@ export default class ChildTagView extends Component { view() { const tag = this.props.tag; + const tagView = app.forum.attribute('kosekiTagsView'); return (
@@ -22,12 +23,24 @@ export default class ChildTagView extends Component {
-
- {tag.discussionsCount()} -
-
- {tag.commentsCount()} -
+ {tagView == 'compact' ? ( +
+
+ {tag.discussionsCount() + ' ' + app.translator.transChoice('reflar-koseki.forum.topics', tag.discussionsCount(), { count: tag.discussionsCount() })} + {tag.commentsCount() + ' ' + app.translator.transChoice('reflar-koseki.forum.posts', tag.commentsCount() == 0 ? 0 : tag.commentsCount(), { count: tag.commentsCount() == 0 ? 0 : tag.commentsCount() })} +
+
) : ( +
+
+ {tag.discussionsCount()} +
+
+ {tag.commentsCount()} +
+
+ ) + } +
{LastDiscussionView.component({ tag })}
diff --git a/js/forum/src/components/PrimaryTagView.js b/js/forum/src/components/PrimaryTagView.js index a16626f..b4ed00a 100644 --- a/js/forum/src/components/PrimaryTagView.js +++ b/js/forum/src/components/PrimaryTagView.js @@ -28,6 +28,7 @@ export default class PrimaryTagView extends Component { view() { const tag = this.props.tag; + const tagView = app.forum.attribute('kosekiTagsView'); return (
@@ -38,12 +39,22 @@ export default class PrimaryTagView extends Component { -
- {app.translator.trans('reflar-koseki.forum.topics_title')} -
-
- {app.translator.trans('reflar-koseki.forum.posts_title')} -
+ {tagView == 'compact' ? ( +
+
+ {app.translator.trans('reflar-koseki.forum.statistics')} +
+
) : ( +
+
+ {app.translator.trans('reflar-koseki.forum.topics_title')} +
+
+ {app.translator.trans('reflar-koseki.forum.posts_title')} +
+
+ ) + }
{app.translator.trans('reflar-koseki.forum.last_post')}
diff --git a/resources/less/categories.less b/resources/less/categories.less index ce22d28..87ef749 100755 --- a/resources/less/categories.less +++ b/resources/less/categories.less @@ -71,8 +71,7 @@ display: block; } .TagTile-description { - padding-top: 15px; - padding-bottom: 15px; + padding: 15px; } .TagChild { clear: both; diff --git a/src/Listeners/AddRelationships.php b/src/Listeners/AddRelationships.php index 1f1e437..8885462 100644 --- a/src/Listeners/AddRelationships.php +++ b/src/Listeners/AddRelationships.php @@ -18,10 +18,20 @@ use Flarum\Event\GetModelRelationship; use Flarum\Event\PrepareApiAttributes; use Flarum\Tags\Api\Serializer\TagSerializer; +use Flarum\Api\Serializer\ForumSerializer; +use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Contracts\Events\Dispatcher; class AddRelationships { + + protected $settings; + + public function __construct(SettingsRepositoryInterface $settings) + { + $this->settings = $settings; + } + public function subscribe(Dispatcher $events) { $events->listen(GetModelRelationship::class, [$this, 'getModelRelationship']); @@ -72,6 +82,10 @@ public function prepareApiAttributes(PrepareApiAttributes $event) ]; } } + + if ($event->isSerializer(ForumSerializer::class)) { + $event->attributes['kosekiTagsView'] = $this->settings->get('koseki.tags_view'); + } } /**