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

Commit

Permalink
Guests can now see the koseki page too
Browse files Browse the repository at this point in the history
  • Loading branch information
ShahiemS committed May 11, 2018
1 parent d219171 commit 876fa75
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 26 deletions.
94 changes: 84 additions & 10 deletions js/forum/dist/extension.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) {
Expand All @@ -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',
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}
};
});;
Expand Down Expand Up @@ -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');
});
}
};
Expand Down
21 changes: 7 additions & 14 deletions js/forum/src/components/ChildTagView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="TagChild">
Expand All @@ -25,19 +28,9 @@ export default class ChildTagView extends Component {
<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>

{ discussion ?
(<div className="TagChild-last">
<div className="TagChild-avatar">{ avatar(user) } {' '}</div>
<div className="TagChild-post">
<a href={ app.route.discussion(discussion, discussion.lastPostNumber()) } className="TagChild-discussion">{ discussion.title() }</a>
{ app.translator.trans('reflar-koseki.forum.by') }&nbsp;
<a href={ app.route.user(user) } config={ m.route }>
{ username(user) } <i class="fa fa-icon fa-arrow-circle-right"></i>
</a><br/>
<small>{ humanTime(discussion.lastTime()) }</small>
</div>
</div>) : '' }
{LastDiscussionView.component({tag})}
</div>
);

}
}
51 changes: 51 additions & 0 deletions js/forum/src/components/LastDiscussionView.js
Original file line number Diff line number Diff line change
@@ -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 (
<div className="TagChild-last">
<div className="TagChild-avatar">{ avatar(user) } {' '}</div>
<div className="TagChild-post">
<a href={ app.route.discussion(discussion, discussion.lastPostNumber()) } className="TagChild-discussion">{ discussion.title() }</a>

{ app.translator.trans('reflar-koseki.forum.by') }&nbsp;
<a href={ app.route.user(user) } config={ m.route }>
{ username(user) } <i class="fa fa-icon fa-arrow-circle-right"></i>
</a><br/>
<small>{ humanTime(discussion.lastTime()) }</small>
</div>
</div>
);
} else {
return (<div></div>);
}
}
}
1 change: 1 addition & 0 deletions js/forum/src/components/PrimaryTagView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion js/forum/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
14 changes: 14 additions & 0 deletions resources/less/categories.less
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
11 changes: 10 additions & 1 deletion src/Listeners/AddRelationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] : ''
);
}
}
}

Expand Down

0 comments on commit 876fa75

Please sign in to comment.