Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions assets/javascripts/discourse/components/rating-object.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@
action=this.updateObject
actionParam=this.object
label="admin.ratings.type.update"
icon="save"
icon="check"
disabled=this.saveDisabled
}}
{{/if}}

{{d-button action=this.destroyObject actionParam=this.object icon="times"}}
{{d-button action=this.destroyObject actionParam=this.object icon="xmark"}}
</td>

{{#if this.error}}
Expand Down
4 changes: 2 additions & 2 deletions assets/javascripts/discourse/components/rating-type.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
action=this.updateType
actionParam=this.type
label="admin.ratings.type.update"
icon="save"
icon="check"
disabled=this.updateDisabled
}}
{{/if}}

{{d-button action=this.destroyType actionParam=this.type icon="times"}}
{{d-button action=this.destroyType actionParam=this.type icon="xmark"}}
{{/if}}
</td>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Component from "@glimmer/component";
import { htmlSafe } from "@ember/template";
import { ratingListHtml } from "../../lib/rating-utilities";

export default class PostRatings extends Component {
get showRatings() {
return this.args.post.ratings && this.args.post.ratings.length > 0;
}

get ratingList() {
return htmlSafe(ratingListHtml(this.args.post.ratings));
}

<template>
{{yield}}
{{#if this.showRatings}}
<span class="post-ratings">{{this.ratingList}}</span>
{{/if}}
</template>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { action } from "@ember/object";
import { notEmpty } from "@ember/object/computed";
import { service } from "@ember/service";
import { i18n } from "discourse-i18n";
import RatingType from "../models/rating-type";
import RatingType from "../../models/rating-type";

export default class AdminPluginsRatingsController extends Controller {
@service dialog;
Expand Down
22 changes: 1 addition & 21 deletions assets/javascripts/discourse/initializers/initialize-ratings.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { withPluginApi } from "discourse/lib/plugin-api";
import Category from "discourse/models/category";
import Composer from "discourse/models/composer";
import { i18n } from "discourse-i18n";
import { ratingListHtml } from "../lib/rating-utilities";

const PLUGIN_ID = "discourse-ratings";

Expand All @@ -33,26 +32,7 @@ export default {
withPluginApi("0.10.0", (api) => {
const currentUser = api.getCurrentUser();

api.includePostAttributes("ratings");

api.decorateWidget("poster-name:after", function (helper) {
const post = helper.getModel();

if (post && post.topic && post.topic.show_ratings && post.ratings) {
return helper.rawHtml(ratingListHtml(post.ratings));
}
});

api.reopenWidget("poster-name", {
buildClasses() {
const post = this.findAncestorModel();
let classes = [];
if (post && post.topic && post.topic.show_ratings && post.ratings) {
classes.push("has-ratings");
}
return classes;
},
});
api.addTrackedPostProperties("ratings");

api.modifyClass("model:composer", {
pluginId: PLUGIN_ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { service } from "@ember/service";
import { all } from "rsvp";
import DiscourseRoute from "discourse/routes/discourse";
import { i18n } from "discourse-i18n";
import RatingObject from "../models/rating-object";
import RatingType from "../models/rating-type";
import RatingObject from "../../models/rating-object";
import RatingType from "../../models/rating-type";

const noneType = "none";

Expand Down
8 changes: 6 additions & 2 deletions assets/stylesheets/common/ratings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@
}
}

.topic-meta-data .names.has-ratings {
align-items: flex-start;
.topic-meta-data .names .rating-list {
margin-left: 1em;
.rating-type {
// there is a .names span.first { font-weight: bold; } in core... :sobs:
font-weight: normal;
}

.rating {
margin: 0 5px 0 0;
Expand Down
19 changes: 8 additions & 11 deletions plugin.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true
# name: discourse-ratings
# about: A Discourse plugin that lets you use topics to rate things
# version: 0.2.3
# authors: Angus McLeod, Faizaan Gagan
# version: 1.0
# authors: Pavilion
# url: https://github.com/paviliondev/discourse-ratings
# contact_emails: development@pavilion.tech

Expand Down Expand Up @@ -182,12 +182,7 @@
)
end

add_to_serializer(:post, :ratings, respect_plugin_enabled: false) do
DiscourseRatings::Rating.serialize(object.ratings)
end

add_to_serializer(:post, :include_ratings?) do
# we need to explictly check for plugin enabled when defining custom include method
add_to_serializer(:post, :ratings, respect_plugin_enabled: false, include_condition: -> {
SiteSetting.rating_enabled &&
(
!SiteSetting.rating_hide_except_own_entry ||
Expand All @@ -196,6 +191,8 @@
(scope.current_user.staff? || scope.current_user.id === object.user.id)
)
)
}) do
DiscourseRatings::Rating.serialize(object.ratings)
end

###### Topic ######
Expand Down Expand Up @@ -230,10 +227,10 @@
object.topic.ratings.present?
end

add_to_serializer(:topic_view, :user_can_rate) { object.topic.user_can_rate(scope.current_user) }

add_to_serializer(:topic_view, :include_user_can_rate?) do
add_to_serializer(:topic_view, :user_can_rate, include_condition: -> {
scope.current_user && object.topic.rating_enabled?
}) do
object.topic.user_can_rate(scope.current_user)
end

::Topic.singleton_class.prepend TopicRatingsExtension
Expand Down
Loading