From 726b9a460d60872f317eaa310cc3cc4fe24ab1ef Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 27 Feb 2017 15:00:04 +0000 Subject: [PATCH 1/5] Added empty box icon to unsolved topics --- .../initializers/extend-for-solved-button.js.es6 | 7 +++++++ config/locales/server.en.yml | 1 + config/settings.yml | 3 +++ plugin.rb | 8 +++++++- 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/initializers/extend-for-solved-button.js.es6 b/assets/javascripts/discourse/initializers/extend-for-solved-button.js.es6 index 375471b..0f3fcc8 100644 --- a/assets/javascripts/discourse/initializers/extend-for-solved-button.js.es6 +++ b/assets/javascripts/discourse/initializers/extend-for-solved-button.js.es6 @@ -223,6 +223,13 @@ export default { title: I18n.t('solved.has_accepted_answer'), icon: 'check-square-o' }); + }else if(this.topic.can_have_answer && this.siteSettings.solved_enabled && this.siteSettings.empty_box_on_unsolved){ + results.push({ + openTag: 'span', + closeTag: 'span', + title: I18n.t('solved.no_accepted_answer'), + icon: 'square-o' + }); } return results; }.property() diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 2ac8d35..3ea8b27 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -3,6 +3,7 @@ en: solved_enabled: "Enable solved plugin, allow users to select solutions for topics" allow_solved_on_all_topics: "Allow users to select solutions on all topics (by default you control this by editing categories)" accept_all_solutions_trust_level: "Minimum trust level required to accept solutions on any topic (even when not OP)" + empty_box_on_unsolved: "Display an empty box next to unsolved topics" reports: accepted_solutions: title: "Accepted solutions" diff --git a/config/settings.yml b/config/settings.yml index 20e2d68..fb42003 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -8,3 +8,6 @@ plugins: accept_all_solutions_trust_level: default: 4 client: true + empty_box_on_unsolved: + default: false + client: true diff --git a/plugin.rb b/plugin.rb index 65dd583..5c1bcda 100644 --- a/plugin.rb +++ b/plugin.rb @@ -340,11 +340,17 @@ SQL require_dependency 'topic_list_item_serializer' class ::TopicListItemSerializer - attributes :has_accepted_answer + attributes :has_accepted_answer, :can_have_answer def has_accepted_answer object.custom_fields["accepted_answer_post_id"] ? true : false end + + def can_have_answer + return true if SiteSetting.allow_solved_on_all_topics + + return scope.allow_accepted_answers_on_category?(object.category_id) + end end TopicList.preloaded_custom_fields << "accepted_answer_post_id" if TopicList.respond_to? :preloaded_custom_fields From ea8c94681bc1d9b596cc143956fea7d85d778f0d Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 27 Feb 2017 17:40:51 +0000 Subject: [PATCH 2/5] Only send can_have_answer attribute if empty_box_on_unsolved is true --- plugin.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugin.rb b/plugin.rb index 5c1bcda..f992a30 100644 --- a/plugin.rb +++ b/plugin.rb @@ -340,16 +340,20 @@ SQL require_dependency 'topic_list_item_serializer' class ::TopicListItemSerializer - attributes :has_accepted_answer, :can_have_answer + attributes :has_accepted_answer def has_accepted_answer object.custom_fields["accepted_answer_post_id"] ? true : false end - def can_have_answer - return true if SiteSetting.allow_solved_on_all_topics + if SiteSetting.empty_box_on_unsolved + attributes :can_have_answer - return scope.allow_accepted_answers_on_category?(object.category_id) + def can_have_answer + return true if SiteSetting.allow_solved_on_all_topics + + return scope.allow_accepted_answers_on_category?(object.category_id) + end end end From f17d8ca52e690030986aeca9d7785217025bb0e1 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 27 Feb 2017 17:42:58 +0000 Subject: [PATCH 3/5] Add missing translation string --- .../discourse/initializers/extend-for-solved-button.js.es6 | 2 +- config/locales/client.en.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/initializers/extend-for-solved-button.js.es6 b/assets/javascripts/discourse/initializers/extend-for-solved-button.js.es6 index 0f3fcc8..83a7733 100644 --- a/assets/javascripts/discourse/initializers/extend-for-solved-button.js.es6 +++ b/assets/javascripts/discourse/initializers/extend-for-solved-button.js.es6 @@ -227,7 +227,7 @@ export default { results.push({ openTag: 'span', closeTag: 'span', - title: I18n.t('solved.no_accepted_answer'), + title: I18n.t('solved.has_no_accepted_answer'), icon: 'square-o' }); } diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 652b645..668a516 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -5,6 +5,7 @@ en: allow_accepted_answers: "Allow topic owner and staff to mark a reply as the solution" accept_answer: "This reply solves the problem" has_accepted_answer: "This topic has a solution" + has_no_accepted_answer: "This topic has no solution" unaccept_answer: "This reply no longer solves the problem" accepted_answer: "Solution" solution: "Solution" From d8f0b310f76a56211602ad252d4d9b7828953fe5 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 27 Feb 2017 21:19:58 +0000 Subject: [PATCH 4/5] Revert "Only send can_have_answer attribute if empty_box_on_unsolved is true" This reverts commit ea8c94681bc1d9b596cc143956fea7d85d778f0d. --- plugin.rb | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/plugin.rb b/plugin.rb index f992a30..5c1bcda 100644 --- a/plugin.rb +++ b/plugin.rb @@ -340,20 +340,16 @@ SQL require_dependency 'topic_list_item_serializer' class ::TopicListItemSerializer - attributes :has_accepted_answer + attributes :has_accepted_answer, :can_have_answer def has_accepted_answer object.custom_fields["accepted_answer_post_id"] ? true : false end - if SiteSetting.empty_box_on_unsolved - attributes :can_have_answer + def can_have_answer + return true if SiteSetting.allow_solved_on_all_topics - def can_have_answer - return true if SiteSetting.allow_solved_on_all_topics - - return scope.allow_accepted_answers_on_category?(object.category_id) - end + return scope.allow_accepted_answers_on_category?(object.category_id) end end From dd37edf49d67b41e3eb24d8b91a6820635b41d84 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 27 Feb 2017 21:26:09 +0000 Subject: [PATCH 5/5] Only include can_have_answer if empty_box_on_unsolved is true. Thanks @SamSaffron --- plugin.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugin.rb b/plugin.rb index 5c1bcda..3f47cda 100644 --- a/plugin.rb +++ b/plugin.rb @@ -351,6 +351,10 @@ SQL return scope.allow_accepted_answers_on_category?(object.category_id) end + + def include_can_have_answer? + SiteSetting.empty_box_on_unsolved + end end TopicList.preloaded_custom_fields << "accepted_answer_post_id" if TopicList.respond_to? :preloaded_custom_fields