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

Commit

Permalink
Hide or show statistics widget
Browse files Browse the repository at this point in the history
  • Loading branch information
ShahiemS committed Sep 5, 2018
1 parent 6bedea6 commit f552681
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 15 deletions.
24 changes: 21 additions & 3 deletions js/admin/dist/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,17 @@ System.register('reflar/koseki/addNavItem', ['flarum/extend', 'flarum/components
});;
'use strict';

System.register('reflar/koseki/components/KosekiPage', ['flarum/components/Page', 'flarum/components/Button', 'flarum/utils/saveSettings'], function (_export, _context) {
System.register('reflar/koseki/components/KosekiPage', ['flarum/components/Page', 'flarum/components/Button', 'flarum/components/Switch', 'flarum/utils/saveSettings'], function (_export, _context) {
"use strict";

var Page, Button, saveSettings, KosekiPage;
var Page, Button, Switch, saveSettings, KosekiPage;
return {
setters: [function (_flarumComponentsPage) {
Page = _flarumComponentsPage.default;
}, function (_flarumComponentsButton) {
Button = _flarumComponentsButton.default;
}, function (_flarumComponentsSwitch) {
Switch = _flarumComponentsSwitch.default;
}, function (_flarumUtilsSaveSettings) {
saveSettings = _flarumUtilsSaveSettings.default;
}],
Expand All @@ -90,6 +92,7 @@ System.register('reflar/koseki/components/KosekiPage', ['flarum/components/Page'
this.loading = false;

this.tagsView = m.prop(app.data.settings['koseki.tags_view']);
this.statisticsWidget = m.prop(app.data.settings['koseki.statistics_widget']);
}
}, {
key: 'view',
Expand Down Expand Up @@ -169,6 +172,20 @@ System.register('reflar/koseki/components/KosekiPage', ['flarum/components/Page'
'Last post'
)
),
m(
'h3',
null,
'Settings'
),
m(
'div',
{ 'class': 'Form-group' },
Switch.component({
state: this.statisticsWidget(),
children: 'Hide forum statistics',
onchange: this.statisticsWidget
})
),
Button.component({
type: 'submit',
className: 'Button Button--primary',
Expand All @@ -191,7 +208,8 @@ System.register('reflar/koseki/components/KosekiPage', ['flarum/components/Page'
this.loading = true;

var settings = {
'koseki.tags_view': this.tagsView()
'koseki.tags_view': this.tagsView(),
'koseki.statistics_widget': this.statisticsWidget()
};

saveSettings(settings).then(function () {
Expand Down
14 changes: 13 additions & 1 deletion js/admin/src/components/KosekiPage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Page from 'flarum/components/Page';
import Button from 'flarum/components/Button';
import Switch from 'flarum/components/Switch';
import saveSettings from 'flarum/utils/saveSettings';

export default class KosekiPage extends Page {
Expand All @@ -8,6 +9,7 @@ export default class KosekiPage extends Page {
this.loading = false;

this.tagsView = m.prop(app.data.settings['koseki.tags_view']);
this.statisticsWidget = m.prop(app.data.settings['koseki.statistics_widget']);
}
view() {
return (
Expand Down Expand Up @@ -38,6 +40,15 @@ export default class KosekiPage extends Page {
<div className="KosekiPage-viewBar">Last post</div>
</div>

<h3>Settings</h3>
<div class="Form-group">
{Switch.component({
state: this.statisticsWidget(),
children: 'Hide forum statistics',
onchange: this.statisticsWidget
})}
</div>

{Button.component({
type: 'submit',
className: 'Button Button--primary',
Expand All @@ -58,7 +69,8 @@ export default class KosekiPage extends Page {
this.loading = true;

const settings = {
'koseki.tags_view': this.tagsView()
'koseki.tags_view': this.tagsView(),
'koseki.statistics_widget': this.statisticsWidget(),
};

saveSettings(settings)
Expand Down
15 changes: 7 additions & 8 deletions js/forum/dist/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,17 +489,13 @@ System.register('reflar/koseki/components/StatisticsWidget', ['flarum/Component'
});;
'use strict';

System.register('reflar/koseki/main', ['flarum/extend', 'reflar/koseki/pages/CategoryPage', 'flarum/components/IndexPage', 'flarum/Model', 'flarum/tags/models/Tag'], function (_export, _context) {
System.register('reflar/koseki/main', ['reflar/koseki/pages/CategoryPage', 'flarum/Model', 'flarum/tags/models/Tag'], function (_export, _context) {
"use strict";

var extend, CategoryPage, IndexPage, Model, Tag;
var CategoryPage, Model, Tag;
return {
setters: [function (_flarumExtend) {
extend = _flarumExtend.extend;
}, function (_reflarKosekiPagesCategoryPage) {
setters: [function (_reflarKosekiPagesCategoryPage) {
CategoryPage = _reflarKosekiPagesCategoryPage.default;
}, function (_flarumComponentsIndexPage) {
IndexPage = _flarumComponentsIndexPage.default;
}, function (_flarumModel) {
Model = _flarumModel.default;
}, function (_flarumTagsModelsTag) {
Expand Down Expand Up @@ -586,6 +582,9 @@ System.register('reflar/koseki/pages/CategoryPage', ['flarum/components/Page', '
key: 'view',
value: function view() {
var tagView = app.forum.attribute('kosekiTagsView');
var statisticsWidget = app.forum.attribute('kosekiStatistics');

console.log(statisticsWidget);

return m(
'div',
Expand Down Expand Up @@ -685,7 +684,7 @@ System.register('reflar/koseki/pages/CategoryPage', ['flarum/components/Page', '
)
) : ''
),
StatisticsWidget.component()
statisticsWidget == null || statisticsWidget == 0 ? StatisticsWidget.component() : ''
)
)
);
Expand Down
2 changes: 0 additions & 2 deletions js/forum/src/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { extend } from 'flarum/extend';
import CategoryPage from 'reflar/koseki/pages/CategoryPage';
import IndexPage from 'flarum/components/IndexPage';
import Model from 'flarum/Model';
import Tag from 'flarum/tags/models/Tag';

Expand Down
6 changes: 5 additions & 1 deletion js/forum/src/pages/CategoryPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export default class CategoryPage extends Page {

view() {
const tagView = app.forum.attribute('kosekiTagsView');
const statisticsWidget = app.forum.attribute('kosekiStatistics');

console.log(statisticsWidget)

return (
<div className="KosekiPage">
Expand Down Expand Up @@ -84,10 +87,11 @@ export default class CategoryPage extends Page {
) : ''}
</div>

{StatisticsWidget.component()}
{ statisticsWidget == null || statisticsWidget == 0 ? StatisticsWidget.component() : '' }
</div>
</div>
</div>
);

}
}
1 change: 1 addition & 0 deletions src/Listeners/AddRelationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function prepareApiAttributes(PrepareApiAttributes $event)
$event->attributes['usersCount'] = User::all()->count();
$event->attributes['lastUser'] = $lastUser->username;
$event->attributes['kosekiTagsView'] = $this->settings->get('koseki.tags_view');
$event->attributes['kosekiStatistics'] = $this->settings->get('koseki.statistics_widget');
}
}
}

0 comments on commit f552681

Please sign in to comment.