Skip to content
This repository has been archived by the owner on Mar 25, 2019. It is now read-only.

Commit

Permalink
Add view switch
Browse files Browse the repository at this point in the history
  • Loading branch information
ShahiemS committed Aug 18, 2018
1 parent ef0c631 commit f539bb9
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 40 deletions.
4 changes: 2 additions & 2 deletions js/admin/dist/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 () {
Expand Down
4 changes: 2 additions & 2 deletions js/admin/src/components/KosekiPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
Expand Down
83 changes: 61 additions & 22 deletions js/forum/dist/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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',
Expand All @@ -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(
Expand Down
25 changes: 19 additions & 6 deletions js/forum/src/components/ChildTagView.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default class ChildTagView extends Component {

view() {
const tag = this.props.tag;
const tagView = app.forum.attribute('kosekiTagsView');

return (
<div class="row TagChild-row">
Expand All @@ -22,12 +23,24 @@ export default class ChildTagView extends Component {
</div>
</div>
</div>
<div class="col-xs-2 col-lg-1">
<span class="TagChild-topics">{tag.discussionsCount()}</span>
</div>
<div class="col-xs-2 col-lg-1">
<span class="TagChild-posts">{tag.commentsCount()}</span>
</div>
{tagView == 'compact' ? (
<div>
<div class="col-xs-2 col-lg-2">
<span className="TagChild-topics">{tag.discussionsCount() + ' ' + app.translator.transChoice('reflar-koseki.forum.topics', tag.discussionsCount(), { count: tag.discussionsCount() })}</span>
<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() })}</span>
</div>
</div>) : (
<div>
<div class="col-xs-2 col-lg-1">
<span class="TagChild-topics">{tag.discussionsCount()}</span>
</div>
<div class="col-xs-2 col-lg-1">
<span class="TagChild-posts">{tag.commentsCount()}</span>
</div>
</div>
)
}

<div class="visible-lg col-lg-2">
{LastDiscussionView.component({ tag })}
</div>
Expand Down
23 changes: 17 additions & 6 deletions js/forum/src/components/PrimaryTagView.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default class PrimaryTagView extends Component {

view() {
const tag = this.props.tag;
const tagView = app.forum.attribute('kosekiTagsView');

return (
<div class="container">
Expand All @@ -38,12 +39,22 @@ export default class PrimaryTagView extends Component {
<div class="col-xs-8 col-lg-7">
<a href={app.route('tag', { tags: tag.slug() })}>{tag.name()}</a>
</div>
<div class="col-xs-2 col-lg-1">
<span class="TagTile-topics">{app.translator.trans('reflar-koseki.forum.topics_title')}</span>
</div>
<div class="col-xs-2 col-lg-1">
<span class="TagTile-posts">{app.translator.trans('reflar-koseki.forum.posts_title')}</span>
</div>
{tagView == 'compact' ? (
<div>
<div class="col-xs-2 col-lg-2">
<span class="TagTile-posts">{app.translator.trans('reflar-koseki.forum.statistics')}</span>
</div>
</div>) : (
<div>
<div class="col-xs-2 col-lg-1">
<span class="TagTile-topics">{app.translator.trans('reflar-koseki.forum.topics_title')}</span>
</div>
<div class="col-xs-2 col-lg-1">
<span class="TagTile-posts">{app.translator.trans('reflar-koseki.forum.posts_title')}</span>
</div>
</div>
)
}
<div class="col-xs-2 col-lg-2 visible-lg">
<span class="TagTile-last">{app.translator.trans('reflar-koseki.forum.last_post')}</span>
</div>
Expand Down
3 changes: 1 addition & 2 deletions resources/less/categories.less
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@
display: block;
}
.TagTile-description {
padding-top: 15px;
padding-bottom: 15px;
padding: 15px;
}
.TagChild {
clear: both;
Expand Down
14 changes: 14 additions & 0 deletions src/Listeners/AddRelationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down Expand Up @@ -72,6 +82,10 @@ public function prepareApiAttributes(PrepareApiAttributes $event)
];
}
}

if ($event->isSerializer(ForumSerializer::class)) {
$event->attributes['kosekiTagsView'] = $this->settings->get('koseki.tags_view');
}
}

/**
Expand Down

0 comments on commit f539bb9

Please sign in to comment.