diff --git a/js/forum/dist/extension.js b/js/forum/dist/extension.js index 103f9b5..694543e 100644 --- a/js/forum/dist/extension.js +++ b/js/forum/dist/extension.js @@ -1,9 +1,9 @@ 'use strict'; -System.register('reflar/koseki/components/ChildTagView', ['flarum/Component', 'flarum/helpers/avatar', 'flarum/helpers/username', 'flarum/helpers/humanTime'], function (_export, _context) { +System.register('reflar/koseki/components/ChildTagView', ['flarum/Component', 'flarum/helpers/avatar', 'flarum/helpers/username', 'flarum/helpers/humanTime', 'reflar/koseki/components/LastDiscussionView'], function (_export, _context) { "use strict"; - var Component, avatar, username, humanTime, ChildTagView; + var Component, avatar, username, humanTime, LastDiscussionView, ChildTagView; return { setters: [function (_flarumComponent) { Component = _flarumComponent.default; @@ -13,6 +13,8 @@ System.register('reflar/koseki/components/ChildTagView', ['flarum/Component', 'f username = _flarumHelpersUsername.default; }, function (_flarumHelpersHumanTime) { humanTime = _flarumHelpersHumanTime.default; + }, function (_reflarKosekiComponentsLastDiscussionView) { + LastDiscussionView = _reflarKosekiComponentsLastDiscussionView.default; }], execute: function () { ChildTagView = function (_Component) { @@ -24,11 +26,14 @@ System.register('reflar/koseki/components/ChildTagView', ['flarum/Component', 'f } babelHelpers.createClass(ChildTagView, [{ + key: 'init', + value: function init() { + babelHelpers.get(ChildTagView.prototype.__proto__ || Object.getPrototypeOf(ChildTagView.prototype), 'init', this).call(this); + } + }, { key: 'view', value: function view() { var tag = this.props.tag; - var discussion = tag.lastDiscussion(); - var user = app.store.getById('users', tag.lastUserId()); return m( 'div', @@ -66,7 +71,74 @@ System.register('reflar/koseki/components/ChildTagView', ['flarum/Component', 'f tag.commentsCount() + ' ' + app.translator.transChoice('reflar-koseki.forum.posts', tag.commentsCount() == 0 ? 0 : tag.commentsCount(), { count: tag.commentsCount() == 0 ? 0 : tag.commentsCount() }) ) ), - discussion ? m( + LastDiscussionView.component({ tag: tag }) + ); + } + }]); + return ChildTagView; + }(Component); + + _export('default', ChildTagView); + } + }; +});; +'use strict'; + +System.register('reflar/koseki/components/LastDiscussionView', ['flarum/Component', 'flarum/helpers/avatar', 'flarum/helpers/username', 'flarum/helpers/humanTime', 'flarum/utils/stringToColor', 'flarum/utils/computed'], function (_export, _context) { + "use strict"; + + var Component, avatar, username, humanTime, stringToColor, computed, LastDiscussionView; + return { + setters: [function (_flarumComponent) { + Component = _flarumComponent.default; + }, function (_flarumHelpersAvatar) { + avatar = _flarumHelpersAvatar.default; + }, function (_flarumHelpersUsername) { + username = _flarumHelpersUsername.default; + }, function (_flarumHelpersHumanTime) { + humanTime = _flarumHelpersHumanTime.default; + }, function (_flarumUtilsStringToColor) { + stringToColor = _flarumUtilsStringToColor.default; + }, function (_flarumUtilsComputed) { + computed = _flarumUtilsComputed.default; + }], + execute: function () { + LastDiscussionView = function (_Component) { + babelHelpers.inherits(LastDiscussionView, _Component); + + function LastDiscussionView() { + babelHelpers.classCallCheck(this, LastDiscussionView); + return babelHelpers.possibleConstructorReturn(this, (LastDiscussionView.__proto__ || Object.getPrototypeOf(LastDiscussionView)).apply(this, arguments)); + } + + babelHelpers.createClass(LastDiscussionView, [{ + key: 'init', + value: function init() { + babelHelpers.get(LastDiscussionView.prototype.__proto__ || Object.getPrototypeOf(LastDiscussionView.prototype), 'init', this).call(this); + } + }, { + key: 'view', + value: function view() { + var tag = this.props.tag; + var discussion = tag.lastDiscussion(); + + if (tag.lastUser() != null) { + var user = { + username: m.prop(tag.lastUser().username), + avatarUrl: tag.lastUser().avatar_path != null ? m.prop('assets/avatars/' + tag.lastUser().avatar_path) : m.prop(), + color: computed('username', 'avatarUrl', 'avatarColor', function (username, avatarUrl, avatarColor) { + if (avatarColor) { + return 'rgb(' + avatarColor.join(', ') + ')'; + } else if (avatarUrl) { + this.calculateAvatarColor(); + return ''; + } + + return '#' + stringToColor(username); + }) + }; + + return m( 'div', { className: 'TagChild-last' }, m( @@ -100,14 +172,16 @@ System.register('reflar/koseki/components/ChildTagView', ['flarum/Component', 'f humanTime(discussion.lastTime()) ) ) - ) : '' - ); + ); + } else { + return m('div', null); + } } }]); - return ChildTagView; + return LastDiscussionView; }(Component); - _export('default', ChildTagView); + _export('default', LastDiscussionView); } }; });; @@ -217,7 +291,7 @@ System.register('reflar/koseki/main', ['flarum/extend', 'reflar/koseki/pages/Cat }; Tag.prototype.commentsCount = Model.attribute('commentsCount'); - Tag.prototype.lastUserId = Model.attribute('lastUserId'); + Tag.prototype.lastUser = Model.attribute('lastUser'); }); } }; diff --git a/js/forum/src/components/ChildTagView.js b/js/forum/src/components/ChildTagView.js index bf254fa..19c128a 100644 --- a/js/forum/src/components/ChildTagView.js +++ b/js/forum/src/components/ChildTagView.js @@ -2,12 +2,15 @@ import Component from 'flarum/Component'; import avatar from 'flarum/helpers/avatar'; import username from 'flarum/helpers/username'; import humanTime from 'flarum/helpers/humanTime'; +import LastDiscussionView from 'reflar/koseki/components/LastDiscussionView'; export default class ChildTagView extends Component { + init() { + super.init(); + } + view() { const tag = this.props.tag; - const discussion = tag.lastDiscussion(); - const user = app.store.getById('users', tag.lastUserId()) return (
@@ -25,19 +28,9 @@ export default class ChildTagView extends Component { { tag.commentsCount() + ' ' + app.translator.transChoice('reflar-koseki.forum.posts', tag.commentsCount() == 0 ? 0 : tag.commentsCount(), {count: tag.commentsCount() == 0 ? 0 : tag.commentsCount()})}
- { discussion ? - (
-
{ avatar(user) } {' '}
-
- { discussion.title() } - { app.translator.trans('reflar-koseki.forum.by') }  - - { username(user) } -
- { humanTime(discussion.lastTime()) } -
-
) : '' } + {LastDiscussionView.component({tag})} ); + } } diff --git a/js/forum/src/components/LastDiscussionView.js b/js/forum/src/components/LastDiscussionView.js new file mode 100644 index 0000000..5d0631a --- /dev/null +++ b/js/forum/src/components/LastDiscussionView.js @@ -0,0 +1,51 @@ +import Component from 'flarum/Component'; +import avatar from 'flarum/helpers/avatar'; +import username from 'flarum/helpers/username'; +import humanTime from 'flarum/helpers/humanTime'; +import stringToColor from 'flarum/utils/stringToColor'; +import computed from 'flarum/utils/computed'; +export default class LastDiscussionView extends Component { + + init() { + super.init(); + } + + view() { + let tag = this.props.tag; + let discussion = tag.lastDiscussion(); + + if (tag.lastUser() != null) { + let user = { + username: m.prop(tag.lastUser().username), + avatarUrl: tag.lastUser().avatar_path != null ? m.prop('assets/avatars/' + tag.lastUser().avatar_path) : m.prop(), + color: computed('username', 'avatarUrl', 'avatarColor', function(username, avatarUrl, avatarColor) { + if (avatarColor) { + return 'rgb(' + avatarColor.join(', ') + ')'; + } else if (avatarUrl) { + this.calculateAvatarColor(); + return ''; + } + + return '#' + stringToColor(username); + }), + }; + + return ( +
+
{ avatar(user) } {' '}
+
+ { discussion.title() } + + { app.translator.trans('reflar-koseki.forum.by') }  + + { username(user) } +
+ { humanTime(discussion.lastTime()) } +
+
+ ); + } else { + return (
); + } + } +} diff --git a/js/forum/src/components/PrimaryTagView.js b/js/forum/src/components/PrimaryTagView.js index 77850c5..07818d9 100644 --- a/js/forum/src/components/PrimaryTagView.js +++ b/js/forum/src/components/PrimaryTagView.js @@ -7,6 +7,7 @@ export default class PrimaryTagView extends Component { super.init(); this.tags = sortTags(app.store.all('tags').filter(tag => tag.parent() == this.props.tag)); + } view() { diff --git a/js/forum/src/main.js b/js/forum/src/main.js index 80e1c0d..4eaf5e1 100644 --- a/js/forum/src/main.js +++ b/js/forum/src/main.js @@ -10,5 +10,5 @@ app.initializers.add('reflar-koseki', app => { }; Tag.prototype.commentsCount = Model.attribute('commentsCount'); - Tag.prototype.lastUserId = Model.attribute('lastUserId'); + Tag.prototype.lastUser = Model.attribute('lastUser'); }); diff --git a/resources/less/categories.less b/resources/less/categories.less index 51d2adf..3adcb56 100755 --- a/resources/less/categories.less +++ b/resources/less/categories.less @@ -158,3 +158,17 @@ clear: both; } } + +/* Mobile / Tablet */ +@media only screen and (max-width: 769px) { + .KosekiPage .TagTile-title { + width: 300px; + } + } + +@media only screen and (max-width: 500px) { + .PollOption { + width: 100%; + margin-right: 0; + } + } diff --git a/src/Listeners/AddRelationships.php b/src/Listeners/AddRelationships.php index 023a80e..f2effee 100644 --- a/src/Listeners/AddRelationships.php +++ b/src/Listeners/AddRelationships.php @@ -64,7 +64,16 @@ public function prepareApiAttributes(PrepareApiAttributes $event) $user = User::find($event->model->lastDiscussion->last_user_id); $event->attributes['commentsCount'] = max($event->model->discussions->max('comments_count') - 1, 0); - $event->attributes['lastUserId'] = $event->model->lastDiscussion->last_user_id; + + if ($user) { + $groups = $user->groups()->get()->all(); + + $event->attributes['lastUser'] = array( + 'username' => $user->username, + 'avatar_path' => $user->avatar_path, + 'color' => isset($groups[0]) ? $groups[0]['color'] : '' + ); + } } }