1
0
Fork 0

Merge pull request #40 from merefield/watch_action

FEATURE: added ability for user to select watched categories in wizard
Dieser Commit ist enthalten in:
Robert 2020-05-26 11:56:13 +01:00 committet von GitHub
Commit 050a0da61c
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
7 geänderte Dateien mit 127 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -5,6 +5,7 @@ import { computed } from "@ember/object";
import wizardSchema from '../lib/wizard-schema'; import wizardSchema from '../lib/wizard-schema';
import UndoChanges from '../mixins/undo-changes'; import UndoChanges from '../mixins/undo-changes';
import Component from "@ember/component"; import Component from "@ember/component";
import { notificationLevels } from '../lib/wizard';
export default Component.extend(UndoChanges, { export default Component.extend(UndoChanges, {
componentType: 'action', componentType: 'action',
@ -12,6 +13,7 @@ export default Component.extend(UndoChanges, {
visible: computed('currentActionId', function() { return this.action.id === this.currentActionId }), visible: computed('currentActionId', function() { return this.action.id === this.currentActionId }),
createTopic: equal('action.type', 'create_topic'), createTopic: equal('action.type', 'create_topic'),
updateProfile: equal('action.type', 'update_profile'), updateProfile: equal('action.type', 'update_profile'),
watchCategories: equal('action.type', 'watch_categories'),
sendMessage: equal('action.type', 'send_message'), sendMessage: equal('action.type', 'send_message'),
openComposer: equal('action.type', 'open_composer'), openComposer: equal('action.type', 'open_composer'),
sendToApi: equal('action.type', 'send_to_api'), sendToApi: equal('action.type', 'send_to_api'),
@ -31,6 +33,12 @@ export default Component.extend(UndoChanges, {
name: I18n.t(`admin.wizard.action.${type}.label`) name: I18n.t(`admin.wizard.action.${type}.label`)
}; };
}), }),
availableNotificationLevels: notificationLevels.map((type, index) => {
return {
id: type,
name: I18n.t(`admin.wizard.action.watch_categories.notification_level.${type}`)
};
}),
messageUrl: 'https://thepavilion.io/t/2810', messageUrl: 'https://thepavilion.io/t/2810',

Datei anzeigen

@ -141,6 +141,11 @@ const action = {
profile_updates: null, profile_updates: null,
custom_fields: null custom_fields: null
}, },
watch_categories: {
categories: null,
notification_level: null,
mute_remainder: null
},
add_to_group: { add_to_group: {
group: null group: null
}, },
@ -158,7 +163,9 @@ const action = {
'recipient', 'recipient',
'profile_updates', 'profile_updates',
'group', 'group',
'url' 'url',
'categories',
'mute_remainder'
], ],
advanced: [ advanced: [
'code', 'code',

Datei anzeigen

@ -49,6 +49,14 @@ const userProperties = [
'trust_level' 'trust_level'
]; ];
const notificationLevels = [
'regular',
'watching',
'tracking',
'watching_first_post',
'muted'
];
function listProperties(type, opts={}) { function listProperties(type, opts={}) {
let properties = Object.keys(wizardSchema[type].basic); let properties = Object.keys(wizardSchema[type].basic);
@ -106,5 +114,6 @@ export {
snakeCase, snakeCase,
userProperties, userProperties,
listProperties, listProperties,
notificationLevels,
wizardFieldList wizardFieldList
}; };

Datei anzeigen

@ -283,6 +283,63 @@
</div> </div>
{{/if}} {{/if}}
{{#if watchCategories}}
<div class="setting full field-mapper-setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.watch_categories.categories"}}</label>
</div>
<div class="setting-value">
{{wizard-mapper
inputs=action.categories
property='categories'
onUpdate=(action 'mappedFieldUpdated')
options=(hash
textSelection='key,value'
wizardFieldSelection=true
userFieldSelection='key,value'
categorySelection='output'
context='action'
)}}
</div>
</div>
<div class="setting full field-mapper-setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.watch_categories.mute_remainder"}}</label>
</div>
<div class="setting-value">
{{wizard-mapper
inputs=action.mute_remainder
property='mute_remainder'
onUpdate=(action 'mappedFieldUpdated')
options=(hash
context='action'
wizardFieldSelection=true
userFieldSelection='key,value'
)}}
</div>
</div>
<div class="setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.watch_categories.notification_level.label"}}</label>
</div>
<div class="setting-value">
{{combo-box
value=action.notification_level
content=availableNotificationLevels
onChange=(action (mut action.notification_level))
options=(hash
isDisabled=action.custom_title_enabled
none='admin.wizard.action.watch_categories.select_a_notification_level'
)}}
</div>
</div>
{{/if}}
{{#if showAdvanced}} {{#if showAdvanced}}
{{wizard-advanced-toggle showAdvanced=action.showAdvanced}} {{wizard-advanced-toggle showAdvanced=action.showAdvanced}}

Datei anzeigen

@ -208,6 +208,18 @@ en:
label: "Update Profile" label: "Update Profile"
setting: "Fields" setting: "Fields"
key: "field" key: "field"
watch_categories:
label: "Watch Categories"
categories: "Categories"
mute_remainder: "Mute Remainder"
notification_level:
label: "Notification Level"
regular: "Normal"
watching: "Watching"
tracking: "Tracking"
watching_first_post: "Watching First Post"
muted: "Muted"
select_a_notification_level: "Select level"
post_builder: post_builder:
checkbox: "Post Builder" checkbox: "Post Builder"
label: "Builder" label: "Builder"

Datei anzeigen

@ -116,12 +116,15 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController
:post, :post,
:post_builder, :post_builder,
:post_template, :post_template,
:notification_level,
title: mapped_params, title: mapped_params,
category: mapped_params, category: mapped_params,
tags: mapped_params, tags: mapped_params,
custom_fields: mapped_params, custom_fields: mapped_params,
required: mapped_params, required: mapped_params,
recipient: mapped_params, recipient: mapped_params,
categories: mapped_params,
mute_remainder: mapped_params,
profile_updates: mapped_params, profile_updates: mapped_params,
group: mapped_params, group: mapped_params,
url: mapped_params url: mapped_params

Datei anzeigen

@ -133,6 +133,36 @@ class CustomWizard::Action
end end
end end
def watch_categories
watched_categories = CustomWizard::Mapper.new(
inputs: action['categories'],
data: data,
user: user
).perform
notification_level = action['notification_level']
if notification_level.blank?
log_error("Notifcation Level was not set! Exiting wizard action")
return
end
mute_remainder = CustomWizard::Mapper.new(
inputs: action['mute_remainder'],
data: data,
user: user
).perform
Category.all.each do |category|
if watched_categories.present? && watched_categories.include?(category.id.to_s)
CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[notification_level.to_sym], category.id)
elsif mute_remainder
CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:muted], category.id)
end
end
end
def send_to_api def send_to_api
api_body = nil api_body = nil