FIX: Custom flags didn't work when flagging a topic

This commit is contained in:
Robin Ward 2017-10-19 14:27:38 -04:00
parent 7cfb8ed5c1
commit a9f718fe57
3 changed files with 11 additions and 13 deletions

View File

@ -53,19 +53,17 @@ export default Ember.Controller.extend(ModalFunctionality, {
return flagsAvailable;
} else {
// flagging topic
const self = this,
lookup = Em.Object.create();
_.each(this.get("model.actions_summary"),function(a) {
a.flagTopic = self.get('model');
a.actionType = self.site.topicFlagTypeById(a.id);
const actionSummary = ActionSummary.create(a);
lookup.set(a.actionType.get('name_key'), actionSummary);
let lookup = Em.Object.create();
let model = this.get('model');
model.get('actions_summary').forEach(a => {
a.flagTopic = model;
a.actionType = this.site.topicFlagTypeById(a.id);
lookup.set(a.actionType.get('name_key'), ActionSummary.create(a));
});
this.set('topicActionByName', lookup);
return this.site.get('topic_flag_types').filter(function(item) {
return _.any(self.get("model.actions_summary"), function(a) {
return this.site.get('topic_flag_types').filter(item => {
return _.any(this.get("model.actions_summary"), a => {
return (a.id === item.get('id') && a.can_act);
});
});

View File

@ -59,8 +59,8 @@ class SiteSerializer < ApplicationSerializer
def topic_flag_types
cache_fragment("post_action_flag_types_#{I18n.locale}") do
flags = PostActionType.ordered.where(id: PostActionType.topic_flag_types.values)
ActiveModel::ArraySerializer.new(flags, each_serializer: TopicFlagTypeSerializer).as_json
types = PostActionType.topic_flag_types.values.map { |id| PostActionType.new(id: id) }
ActiveModel::ArraySerializer.new(types, each_serializer: TopicFlagTypeSerializer).as_json
end
end

View File

@ -3,7 +3,7 @@ class TopicFlagTypeSerializer < PostActionTypeSerializer
protected
def i18n(field, vars = nil)
key = "topic_flag_types.#{object.name_key}.#{field}"
key = "topic_flag_types.#{name_key}.#{field}"
vars ? I18n.t(key, vars) : I18n.t(key)
end