REFACTOR: Replace score bonuses with low/med/high priorities

REFACTOR: Replace score bonuses with low/med/high priorities

We removed score from the UX so it makes more sense to have sites set priorities instead of score bonuses.

diff --git a/app/assets/javascripts/discourse/controllers/review-settings.js.es6 b/app/assets/javascripts/discourse/controllers/review-settings.js.es6
index 339b005..f832f77 100644
--- a/app/assets/javascripts/discourse/controllers/review-settings.js.es6
+++ b/app/assets/javascripts/discourse/controllers/review-settings.js.es6
@@ -1,19 +1,32 @@
 import { ajax } from "discourse/lib/ajax";
 import { popupAjaxError } from "discourse/lib/ajax-error";
+import computed from "ember-addons/ember-computed-decorators";
 
 export default Ember.Controller.extend({
   saving: false,
   saved: false,
 
+  @computed
+  reviewablePriorities() {
+    return [
+      { id: 0, name: "low" },
+      { id: 5, name: "medium" },
+      { id: 10, name: "high" }
+    ];
+  },
+
   actions: {
     save() {
-      let bonuses = {};
+      let priorities = {};
       this.get("settings.reviewable_score_types").forEach(st => {
-        bonuses[st.id] = parseFloat(st.score_bonus);
+        priorities[st.id] = parseFloat(st.reviewable_priority);
       });
 
       this.set("saving", true);
-      ajax("/review/settings", { method: "PUT", data: { bonuses } })
+      ajax("/review/settings", {
+        method: "PUT",
+        data: { reviewable_priorities: priorities }
+      })
         .then(() => {
           this.set("saved", true);
         })
diff --git a/app/assets/javascripts/discourse/templates/review-settings.hbs b/app/assets/javascripts/discourse/templates/review-settings.hbs
index 142562c..2669a44 100644
--- a/app/assets/javascripts/discourse/templates/review-settings.hbs
+++ b/app/assets/javascripts/discourse/templates/review-settings.hbs
@@ -1,12 +1,11 @@
 <div class='reviewable-settings'>
-  <h4>{{i18n "review.settings.score_bonuses.title"}}</h4>
-  <p class='description'>{{i18n "review.settings.score_bonuses.description"}}</p>
+  <h4>{{i18n "review.settings.priorities.title"}}</h4>
 
   {{#each settings.reviewable_score_types as |rst|}}
     <div class='reviewable-score-type'>
       <div class='title'>{{rst.title}}</div>
       <div class='field'>
-        {{input value=rst.score_bonus}}
+        {{combo-box value=rst.reviewable_priority content=settings.reviewable_priorities}}
       </div>
     </div>
   {{/each}}
diff --git a/app/assets/stylesheets/common/base/reviewables.scss b/app/assets/stylesheets/common/base/reviewables.scss
index 8bdf2f3..8e78aed 100644
--- a/app/assets/stylesheets/common/base/reviewables.scss
+++ b/app/assets/stylesheets/common/base/reviewables.scss
@@ -51,8 +51,9 @@
 }
 
 .reviewable-settings {
-  p.description {
-    margin-bottom: 2em;
+  h4 {
+    margin-top: 1em;
+    margin-bottom: 1em;
   }
 
   .saved {
@@ -60,7 +61,11 @@
   }
   .reviewable-score-type {
     display: flex;
+    margin-bottom: 0.5em;
 
+    .select-kit {
+      min-width: 10em;
+    }
     .title {
       width: 30%;
     }
diff --git a/app/controllers/reviewables_controller.rb b/app/controllers/reviewables_controller.rb
index 63c4bb5..8d6818d 100644
--- a/app/controllers/reviewables_controller.rb
+++ b/app/controllers/reviewables_controller.rb
@@ -188,14 +188,21 @@ class ReviewablesController < ApplicationController
     raise Discourse::InvalidAccess.new unless current_user.admin?
 
     post_action_types = PostActionType.where(id: PostActionType.flag_types.values).order('id')
-    data = { reviewable_score_types: post_action_types }
 
     if request.put?
-      params[:bonuses].each do |id, bonus|
-        PostActionType.where(id: id).update_all(score_bonus: bonus.to_f)
+      params[:reviewable_priorities].each do |id, priority|
+        if !priority.nil? && Reviewable.priorities.has_value?(priority.to_i)
+          # For now, the score bonus is equal to the priority. In the future we might want
+          # to calculate it a different way.
+          PostActionType.where(id: id).update_all(
+            reviewable_priority: priority.to_i,
+            score_bonus: priority.to_f
+          )
+        end
       end
     end
 
+    data = { reviewable_score_types: post_action_types }
     render_serialized(data, ReviewableSettingsSerializer, rest_serializer: true)
   end
 
diff --git a/app/jobs/scheduled/reviewable_priorities.rb b/app/jobs/scheduled/reviewable_priorities.rb
index f67698a..49f4aa2 100644
--- a/app/jobs/scheduled/reviewable_priorities.rb
+++ b/app/jobs/scheduled/reviewable_priorities.rb
@@ -12,6 +12,8 @@ class Jobs::ReviewablePriorities < Jobs::Scheduled
         FROM reviewables
     SQL
 
-    Reviewable.set_priorities(medium: res[0], high: res[1])
+    medium, high = res
+
+    Reviewable.set_priorities(medium: medium, high: high)
   end
 end
diff --git a/app/models/post_action_type.rb b/app/models/post_action_type.rb
index 121db59..a1c8ea8 100644
--- a/app/models/post_action_type.rb
+++ b/app/models/post_action_type.rb
@@ -127,12 +127,12 @@ end
 #
 # Table name: post_action_types
 #
-#  name_key    :string(50)       not null
-#  is_flag     :boolean          default(FALSE), not null
-#  icon        :string(20)
-#  created_at  :datetime         not null
-#  updated_at  :datetime         not null
-#  id          :integer          not null, primary key
-#  position    :integer          default(0), not null
-#  score_bonus :float            default(0.0), not null
+#  name_key            :string(50)       not null
+#  is_flag             :boolean          default(FALSE), not null
+#  icon                :string(20)
+#  created_at          :datetime         not null
+#  updated_at          :datetime         not null
+#  id                  :integer          not null, primary key
+#  position            :integer          default(0), not null
+#  reviewable_priority :integer
 #
diff --git a/app/models/reviewable.rb b/app/models/reviewable.rb
index bbbd3a6..10cb024 100644
--- a/app/models/reviewable.rb
+++ b/app/models/reviewable.rb
@@ -41,6 +41,15 @@ class Reviewable < ActiveRecord::Base
     Jobs.enqueue(:notify_reviewable, reviewable_id: self.id) if pending?
   end
 
+  # The gaps are in case we want more accuracy in the future
+  def self.priorities
+    @priorities ||= Enum.new(
+      low: 0,
+      medium: 5,
+      high: 10
+    )
+  end
+
   def self.statuses
     @statuses ||= Enum.new(
       pending: 0,
@@ -157,15 +166,18 @@ class Reviewable < ActiveRecord::Base
     rs
   end
 
-  def self.set_priorities(medium: nil, high: nil)
-    PluginStore.set('reviewables', 'priority_medium', medium) if medium
-    PluginStore.set('reviewables', 'priority_high', high) if high
+  def self.set_priorities(values)
+    values.each do |k, v|
+      id = Reviewable.priorities[k]
+      PluginStore.set('reviewables', "priority_#{id}", v) unless id.nil?
+    end
   end
 
   def self.min_score_for_priority(priority = nil)
     priority ||= SiteSetting.reviewable_default_visibility
-    return 0.0 unless ['medium', 'high'].include?(priority)
-    return PluginStore.get('reviewables', "priority_#{priority}").to_f
+    id = Reviewable.priorities[priority.to_sym]
+    return 0.0 if id.nil?
+    return PluginStore.get('reviewables', "priority_#{id}").to_f
   end
 
   def history
@@ -502,6 +514,7 @@ end
 #  created_by_id           :integer          not null
 #  reviewable_by_moderator :boolean          default(FALSE), not null
 #  reviewable_by_group_id  :integer
+#  claimed_by_id           :integer
 #  category_id             :integer
 #  topic_id                :integer
 #  score                   :float            default(0.0), not null
diff --git a/app/models/reviewable_flagged_post.rb b/app/models/reviewable_flagged_post.rb
index 5c00228..75769ee 100644
--- a/app/models/reviewable_flagged_post.rb
+++ b/app/models/reviewable_flagged_post.rb
@@ -296,6 +296,7 @@ end
 #  created_by_id           :integer          not null
 #  reviewable_by_moderator :boolean          default(FALSE), not null
 #  reviewable_by_group_id  :integer
+#  claimed_by_id           :integer
 #  category_id             :integer
 #  topic_id                :integer
 #  score                   :float            default(0.0), not null

[... diff too long, it was truncated ...]

GitHub sha: e74cd54f

1 Like