Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new option to hide voting when not allowed #113

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
'customRankingImages',
'useAlternateLayout',
'upVotesOnly',
'hideIfNoPermissions',
'iconNameAlt',
'altPostVotingUi',
]),
Expand Down
2 changes: 1 addition & 1 deletion js/dist/admin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dist/admin.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dist/forum.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dist/forum.js.map

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions js/src/admin/components/SettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default class SettingsPage extends ExtensionPage {
'useAlternateLayout',
'altPostVotingUi',
'upVotesOnly',
'hideIfNoPermissions',
'firstPostOnly',
'allowSelfVotes',
];
Expand Down Expand Up @@ -380,6 +381,14 @@ export default class SettingsPage extends ExtensionPage {
30
);

items.add(
'hideIfNoPermissions',
<Switch state={this.values.hideIfNoPermissions() || false} onchange={this.values.hideIfNoPermissions} className="votes-switch">
{app.translator.trans('fof-gamification.admin.page.votes.hide_if_no_permissions')}
</Switch>,
30
);

items.add(
'firstPostOnly',
<Switch state={this.values.firstPostOnly() || false} onchange={this.values.firstPostOnly} className="votes-switch">
Expand Down
4 changes: 4 additions & 0 deletions js/src/forum/addAlternateLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export default function addAlternateLayout() {
// We set canVote to true for guest users so that they can access the login by clicking the button
const canVote = !app.session.user || get(discussion, 'canVote');

if (setting('hideIfNoPermissions', true) && !post.canVote() && !post.canSeeVotes()) {
return;
}

const upvotesOnly = setting('upVotesOnly', true);
const altIcon = setting('iconNameAlt') || 'arrow';

Expand Down
4 changes: 4 additions & 0 deletions js/src/forum/addVoteButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export default function () {
// We set canVote to true for guest users so that they can access the login by clicking the button
const canVote = !app.session.user || post.canVote();

if (setting('hideIfNoPermissions', true) && !post.canVote() && !post.canSeeVotes()) {
return;
}

const onclick = (upvoted, downvoted) => saveVote(post, upvoted, downvoted, (val) => (this.voteLoading = val));

items.add(
Expand Down
1 change: 1 addition & 0 deletions resources/locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ fof-gamification:
icon_name: Upvote/downvote icon
icon_help: "Input any Font-Awesome icon that is suffixed with -up and -down. Examples: arrow, thumbs, chevron"
upvotes_only: Only allow upvoting
hide_if_no_permissions: Only show voting options when user has permission to vote on this post
first_post_only: Only allow up/down votes in the first post in a discussion
allow_self_votes: Users may vote on their own posts
save_settings: Save settings
Expand Down
Loading