0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 17:30:29 +01:00

Handle corrupted wizard data

Dieser Commit ist enthalten in:
Angus McLeod 2020-04-15 15:22:21 +10:00
Ursprung 03ae1dc7c9
Commit e285674c8f
7 geänderte Dateien mit 57 neuen und 23 gelöschten Zeilen

Datei anzeigen

@ -1,6 +1,8 @@
import Component from "@ember/component"; import Component from "@ember/component";
import { gt } from '@ember/object/computed'; import { gt } from '@ember/object/computed';
import { computed } from "@ember/object"; import { computed } from "@ember/object";
import { defaultConnector } from '../lib/wizard-mapper';
import { later } from "@ember/runloop";
export default Component.extend({ export default Component.extend({
classNameBindings: [':mapper-connector', ':mapper-block', 'hasMultiple::single'], classNameBindings: [':mapper-connector', ':mapper-block', 'hasMultiple::single'],
@ -9,5 +11,16 @@ export default Component.extend({
let key = this.connector; let key = this.connector;
let path = this.inputTypes ? `input.${key}.name` : `connector.${key}`; let path = this.inputTypes ? `input.${key}.name` : `connector.${key}`;
return I18n.t(`admin.wizard.${path}`); return I18n.t(`admin.wizard.${path}`);
}) }),
didReceiveAttrs() {
if (!this.connector) {
later(() => {
this.set(
'connector',
defaultConnector(this.connectorType, this.inputType, this.options)
);
});
}
}
}); });

Datei anzeigen

@ -5,7 +5,7 @@ import { getOwner } from 'discourse-common/lib/get-owner';
import { defaultSelectionType, selectionTypes } from '../lib/wizard-mapper'; import { defaultSelectionType, selectionTypes } from '../lib/wizard-mapper';
import { snakeCase } from '../lib/wizard'; import { snakeCase } from '../lib/wizard';
import Component from "@ember/component"; import Component from "@ember/component";
import { bind } from "@ember/runloop"; import { bind, later } from "@ember/runloop";
export default Component.extend({ export default Component.extend({
classNameBindings: [':mapper-selector', 'activeType'], classNameBindings: [':mapper-selector', 'activeType'],
@ -33,6 +33,10 @@ export default Component.extend({
showTypes: false, showTypes: false,
didInsertElement() { didInsertElement() {
if (this.activeType && !this[`${this.activeType}Enabled`]) {
later(() => this.resetActiveType());
}
$(document).on("click", bind(this, this.documentClick)); $(document).on("click", bind(this, this.documentClick));
}, },

Datei anzeigen

@ -22,13 +22,9 @@ function inputTypesContent(options = {}) {
mapInputTypes(selectableInputTypes); mapInputTypes(selectableInputTypes);
} }
// Connectors // connectorTypes
const connectors = { const connectors = {
output: [
'then',
'set',
],
pair: [ pair: [
'equal', 'equal',
'greater', 'greater',
@ -36,16 +32,26 @@ const connectors = {
'greater_or_equal', 'greater_or_equal',
'less_or_equal', 'less_or_equal',
'regex' 'regex'
] ],
output: [
'then',
'set',
],
} }
function defaultConnector(connectorType, inputType, opts = {}) { function defaultConnector(connectorType, inputType, options={}) {
if (opts[`${connectorType}Connector`]) return opts[`${connectorType}Connector`]; if (connectorType === 'input') {
if (inputType === 'conditional' && connectorType === 'output') return 'then'; return defaultInputType(options);
if (inputType === 'conditional' && connectorType === 'pair') return 'equal'; }
if (inputType === 'assignment' && connectorType === 'output') return 'set'; if (connectorType === 'pair') {
if (inputType === 'association' && connectorType === 'pair') return 'association'; if (inputType === 'conditional') return 'equal';
if (inputType === 'validation' && connectorType === 'pair') return 'equal'; if (inputType === 'association') return 'association';
if (inputType === 'validation') return 'equal';
}
if (connectorType === 'output') {
if (inputType === 'conditional') return 'then';
if (inputType === 'assignment') return 'set';
}
return 'equal'; return 'equal';
} }
@ -53,7 +59,7 @@ function connectorContent(connectorType, inputType, opts) {
let connector = opts[`${connectorType}Connector`]; let connector = opts[`${connectorType}Connector`];
if ((!connector && connectorType === 'output') || inputType === 'association') { if ((!connector && connectorType === 'output') || inputType === 'association') {
connector = defaultConnector(connectorType, inputType, opts); connector = defaultConnector(connectorType, inputType);
} }
let content = connector ? [connector] : connectors[connectorType]; let content = connector ? [connector] : connectors[connectorType];

Datei anzeigen

@ -4,7 +4,9 @@
content=connectors content=connectors
onChange=(action (mut connector))}} onChange=(action (mut connector))}}
{{else}} {{else}}
<span class="connector-single"> {{#if connector}}
{{connectorLabel}} <span class="connector-single">
</span> {{connectorLabel}}
</span>
{{/if}}
{{/if}} {{/if}}

Datei anzeigen

@ -1,7 +1,10 @@
{{wizard-mapper-connector {{wizard-mapper-connector
connector=input.type connector=input.type
connectors=inputTypes connectors=inputTypes
inputTypes=true}} inputTypes=true
inputType=inputType
connectorType="type"
options=options}}
{{#if hasPairs}} {{#if hasPairs}}
<div class="mapper-pairs mapper-block"> <div class="mapper-pairs mapper-block">
@ -26,7 +29,10 @@
{{#if hasPairs}} {{#if hasPairs}}
{{wizard-mapper-connector {{wizard-mapper-connector
connector=input.output_connector connector=input.output_connector
connectors=connectors}} connectors=connectors
connectorType="output"
inputType=inputType
options=options}}
{{/if}} {{/if}}
<div class="output mapper-block"> <div class="output mapper-block">

Datei anzeigen

@ -9,7 +9,10 @@
{{wizard-mapper-connector {{wizard-mapper-connector
connector=pair.connector connector=pair.connector
connectors=connectors}} connectors=connectors
connectorType="pair"
inputType=inputType
options=options}}
<div class="value mapper-block"> <div class="value mapper-block">
{{wizard-mapper-selector {{wizard-mapper-selector

Datei anzeigen

@ -1,6 +1,6 @@
{{#each inputs as |input|}} {{#each inputs as |input|}}
{{#if input.connector}} {{#if input.connector}}
{{wizard-mapper-connector connector=input.connector}} {{wizard-mapper-connector connector=input.connector connectorType="input"}}
{{/if}} {{/if}}
{{wizard-mapper-input {{wizard-mapper-input