yxc
This commit is contained in:
@@ -66,6 +66,7 @@
|
|||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
placeholderSchemaStore.tables = [];
|
placeholderSchemaStore.tables = [];
|
||||||
|
placeholderSchemaStore.promise = null;
|
||||||
log('PLACEHOLDER ERROR', `Schema konnte nicht geladen werden: ${err.message || err}`, 'red', 'error');
|
log('PLACEHOLDER ERROR', `Schema konnte nicht geladen werden: ${err.message || err}`, 'red', 'error');
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
@@ -90,18 +91,12 @@
|
|||||||
const domc = editor.DomComponents;
|
const domc = editor.DomComponents;
|
||||||
if (domc.getType(PLACEHOLDER_COMPONENT)) return;
|
if (domc.getType(PLACEHOLDER_COMPONENT)) return;
|
||||||
|
|
||||||
const defaultType = domc.getType('default');
|
|
||||||
const defaultModel = defaultType ? defaultType.model : null;
|
|
||||||
const defaultView = defaultType ? defaultType.view : null;
|
|
||||||
|
|
||||||
domc.addType(PLACEHOLDER_COMPONENT, {
|
domc.addType(PLACEHOLDER_COMPONENT, {
|
||||||
model: (defaultModel || editor.DomComponents.Component).extend({
|
extend: 'text',
|
||||||
|
model: {
|
||||||
defaults: {
|
defaults: {
|
||||||
...(defaultModel && defaultModel.prototype?.defaults ? defaultModel.prototype.defaults : {}),
|
|
||||||
name: 'Placeholder',
|
name: 'Placeholder',
|
||||||
tagName: 'span',
|
tagName: 'span',
|
||||||
selectable: true,
|
|
||||||
hoverable: true,
|
|
||||||
droppable: false,
|
droppable: false,
|
||||||
attributes: {
|
attributes: {
|
||||||
'data-placeholder-type': 'custom',
|
'data-placeholder-type': 'custom',
|
||||||
@@ -145,14 +140,17 @@
|
|||||||
init() {
|
init() {
|
||||||
this.listenTo(this, 'change:attributes', this.updatePlaceholderState);
|
this.listenTo(this, 'change:attributes', this.updatePlaceholderState);
|
||||||
this.updatePlaceholderState();
|
this.updatePlaceholderState();
|
||||||
fetchPlaceholderSchema().then(() => {
|
fetchPlaceholderSchema()
|
||||||
this.updateSchemaTraits();
|
.then(() => this.updateSchemaTraits())
|
||||||
}).catch(() => {
|
.catch(() => this.updateSchemaTraits([]));
|
||||||
this.updateSchemaTraits([]);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
updatePlaceholderState() {
|
updatePlaceholderState() {
|
||||||
|
const attrs = this.getAttributes();
|
||||||
|
const type = attrs['data-placeholder-type'] || 'custom';
|
||||||
|
if (type === 'database' && placeholderSchemaStore.tables.length === 0) {
|
||||||
|
this.addAttributes({ 'data-placeholder-type': 'custom' });
|
||||||
|
}
|
||||||
this.updateTraitVisibility();
|
this.updateTraitVisibility();
|
||||||
this.updateSchemaTraits();
|
this.updateSchemaTraits();
|
||||||
this.updateLabel();
|
this.updateLabel();
|
||||||
@@ -181,11 +179,18 @@
|
|||||||
const tables = Array.isArray(tablesOverride) ? tablesOverride : placeholderSchemaStore.tables;
|
const tables = Array.isArray(tablesOverride) ? tablesOverride : placeholderSchemaStore.tables;
|
||||||
const tableTrait = getTraitByName(this, 'data-placeholder-table');
|
const tableTrait = getTraitByName(this, 'data-placeholder-table');
|
||||||
const columnTrait = getTraitByName(this, 'data-placeholder-column');
|
const columnTrait = getTraitByName(this, 'data-placeholder-column');
|
||||||
|
const loading = !tablesOverride && placeholderSchemaStore.promise && !tables.length;
|
||||||
|
|
||||||
if (tableTrait) {
|
if (tableTrait) {
|
||||||
const opts = tables.map(tbl => ({ id: tbl.name, label: tbl.name }));
|
let opts;
|
||||||
tableTrait.set('options', opts);
|
if (tables.length) {
|
||||||
if (tableTrait.view && tableTrait.view.render) tableTrait.view.render();
|
opts = tables.map(tbl => ({ id: tbl.name, label: tbl.name }));
|
||||||
|
} else if (loading) {
|
||||||
|
opts = [{ id: '', label: 'Tabellen werden geladen…', disabled: true }];
|
||||||
|
} else {
|
||||||
|
opts = [{ id: '', label: 'Keine Tabellen verfügbar', disabled: true }];
|
||||||
|
}
|
||||||
|
setTraitOptions(tableTrait, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (columnTrait) {
|
if (columnTrait) {
|
||||||
@@ -193,13 +198,9 @@
|
|||||||
const tableName = (attrs['data-placeholder-table'] || '').toLowerCase();
|
const tableName = (attrs['data-placeholder-table'] || '').toLowerCase();
|
||||||
const table = tables.find(tbl => tbl.name.toLowerCase() === tableName);
|
const table = tables.find(tbl => tbl.name.toLowerCase() === tableName);
|
||||||
const colOpts = table
|
const colOpts = table
|
||||||
? table.columns.map(col => ({
|
? table.columns.map(col => ({ id: col.name, label: `${col.name} (${col.type})` }))
|
||||||
id: col.name,
|
: [{ id: '', label: table ? 'Keine Felder' : 'Feld wählen', disabled: !table }];
|
||||||
label: `${col.name} (${col.type})`,
|
setTraitOptions(columnTrait, colOpts);
|
||||||
}))
|
|
||||||
: [];
|
|
||||||
columnTrait.set('options', colOpts);
|
|
||||||
if (columnTrait.view && columnTrait.view.render) columnTrait.view.render();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -230,11 +231,9 @@
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
view: (defaultView || editor.DomComponents.View).extend({
|
view: editor.DomComponents.View.extend({
|
||||||
render() {
|
render() {
|
||||||
defaultView && defaultView.prototype.render
|
editor.DomComponents.View.prototype.render.apply(this, arguments);
|
||||||
? defaultView.prototype.render.apply(this, arguments)
|
|
||||||
: editor.DomComponents.View.prototype.render.apply(this, arguments);
|
|
||||||
this.el.classList.add('placeholder-block');
|
this.el.classList.add('placeholder-block');
|
||||||
this.el.style.display = 'inline-block';
|
this.el.style.display = 'inline-block';
|
||||||
this.el.style.padding = '2px 8px';
|
this.el.style.padding = '2px 8px';
|
||||||
@@ -249,6 +248,14 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function setTraitOptions(trait, options) {
|
||||||
|
if (!trait) return;
|
||||||
|
trait.set('options', options);
|
||||||
|
if (trait.view && typeof trait.view.render === 'function') {
|
||||||
|
trait.view.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function register(editor) {
|
function register(editor) {
|
||||||
log('EXECUTION', `Starte Block-Registrierung für ${TARGET_CAT_ID}.`, '#DAA520');
|
log('EXECUTION', `Starte Block-Registrierung für ${TARGET_CAT_ID}.`, '#DAA520');
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ let debugStylesInjected = false;
|
|||||||
let consolePatched = false;
|
let consolePatched = false;
|
||||||
const consoleBuffer = [];
|
const consoleBuffer = [];
|
||||||
|
|
||||||
|
ensureConsoleCapture();
|
||||||
|
|
||||||
export function initUserPanel() {
|
export function initUserPanel() {
|
||||||
avatarBtn = document.getElementById('btn-user');
|
avatarBtn = document.getElementById('btn-user');
|
||||||
userMenuPanel = document.getElementById('userMenuPanel');
|
userMenuPanel = document.getElementById('userMenuPanel');
|
||||||
|
|||||||
Reference in New Issue
Block a user