0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-30 04:30:29 +01:00
discourse-custom-wizard/assets/javascripts/discourse/components/wizard-custom-action.js.es6

88 Zeilen
2,8 KiB
Text

2020-04-20 11:41:13 +02:00
import { default as discourseComputed } from 'discourse-common/utils/decorators';
2020-04-20 13:40:32 +02:00
import { equal, empty, or, and } from "@ember/object/computed";
import { generateName, selectKitContent } from '../lib/wizard';
2020-04-20 11:41:13 +02:00
import { computed } from "@ember/object";
import wizardSchema from '../lib/wizard-schema';
2020-04-20 11:41:13 +02:00
import UndoChanges from '../mixins/undo-changes';
2020-04-05 03:37:09 +02:00
import Component from "@ember/component";
import { notificationLevels } from '../lib/wizard';
2020-05-28 05:06:06 +02:00
import I18n from "I18n";
2017-10-13 15:02:34 +02:00
2020-04-20 11:41:13 +02:00
export default Component.extend(UndoChanges, {
componentType: 'action',
classNameBindings: [':wizard-custom-action', 'visible'],
visible: computed('currentActionId', function() { return this.action.id === this.currentActionId }),
2020-04-01 12:58:30 +02:00
createTopic: equal('action.type', 'create_topic'),
updateProfile: equal('action.type', 'update_profile'),
watchCategories: equal('action.type', 'watch_categories'),
2020-04-01 12:58:30 +02:00
sendMessage: equal('action.type', 'send_message'),
2020-04-08 04:52:07 +02:00
openComposer: equal('action.type', 'open_composer'),
2020-04-01 12:58:30 +02:00
sendToApi: equal('action.type', 'send_to_api'),
addToGroup: equal('action.type', 'add_to_group'),
routeTo: equal('action.type', 'route_to'),
2020-04-08 04:52:07 +02:00
apiEmpty: empty('action.api'),
2020-04-02 10:21:03 +02:00
groupPropertyTypes: selectKitContent(['id', 'name']),
2020-04-07 15:33:11 +02:00
hasAdvanced: or('hasCustomFields', 'routeTo'),
2020-04-20 13:40:32 +02:00
showAdvanced: and('hasAdvanced', 'action.type'),
2020-04-07 15:33:11 +02:00
hasCustomFields: or('basicTopicFields', 'updateProfile'),
2020-04-08 04:52:07 +02:00
basicTopicFields: or('createTopic', 'sendMessage', 'openComposer'),
publicTopicFields: or('createTopic', 'openComposer'),
showSkipRedirect: or('createTopic', 'sendMessage'),
2020-04-20 13:40:32 +02:00
actionTypes: Object.keys(wizardSchema.action.types).map(type => {
return {
id: type,
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}`)
};
}),
2020-04-20 13:40:32 +02:00
messageUrl: 'https://thepavilion.io/t/2810',
@discourseComputed('action.type')
messageKey(type) {
let key = 'type';
if (type) {
key = 'edit';
}
return key;
},
2020-04-02 07:21:57 +02:00
2020-04-08 04:52:07 +02:00
@discourseComputed('wizard.steps')
runAfterContent(steps) {
2020-04-08 09:59:54 +02:00
let content = steps.map(function(step) {
return {
id: step.id,
name: step.title || step.id
};
});
2020-04-08 04:52:07 +02:00
content.unshift({
id: 'wizard_completion',
name: I18n.t('admin.wizard.action.run_after.wizard_completion')
});
2020-04-08 09:59:54 +02:00
2020-04-08 04:52:07 +02:00
return content;
2019-06-03 09:09:24 +02:00
},
2020-04-22 15:03:18 +02:00
@discourseComputed('apis')
2019-06-03 09:09:24 +02:00
availableApis(apis) {
return apis.map(a => {
return {
id: a.name,
name: a.title
};
});
},
2020-04-22 15:03:18 +02:00
@discourseComputed('apis', 'action.api')
2019-06-03 09:09:24 +02:00
availableEndpoints(apis, api) {
if (!api) return [];
return apis.find(a => a.name === api).endpoints;
2017-10-13 15:02:34 +02:00
}
2017-09-23 04:34:07 +02:00
});