Browse Source

Improve schema export.

pull/303/head
Sebastian 8 years ago
parent
commit
69b7d804a7
  1. 56
      src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts

56
src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts

@ -108,46 +108,48 @@ export class SchemaPageComponent implements OnDestroy, OnInit {
} }
private export() { private export() {
const cleanup = (source: any, ...exclude: string[]): any => {
const clone = {};
for (const key in source) {
if (source.hasOwnProperty(key) && exclude.indexOf(key) < 0) {
const value = source[key];
if (value) {
clone[key] = value;
}
}
}
return clone;
};
const result: any = { const result: any = {
fields: this.schema.fields.map(field => { fields: this.schema.fields.map(field => {
const { fieldId, ...copy } = field; const copy = cleanup(field, 'fieldId');
if (Types.isArray(copy.nested)) { if (Types.isArray(copy.nested)) {
for (let i = 0; i < copy.nested.length; i++) { if (copy.nested.length === 0) {
const nestedField = copy.nested[i]; delete copy['nested'];
const { fieldId, parentId, ...nestedCopy } = nestedField; } else {
for (let i = 0; i < copy.nested.length; i++) {
for (const key in nestedCopy.properties) { const nestedField = copy.nested[i];
if (nestedCopy.properties.hasOwnProperty(key) && const nestedCopy = cleanup(nestedField, 'fieldId', 'parentId');
!nestedCopy.properties[key]) {
delete copy.properties[key];
}
}
copy.nested[i] = <any>nestedCopy; nestedCopy.properties = cleanup(nestedField.properties);
}
}
for (const key in copy.properties) { copy.nested[i] = nestedCopy;
if (copy.properties.hasOwnProperty(key) && }
!copy.properties[key]) {
delete copy.properties[key];
} }
} }
copy.properties = cleanup(field.properties);
return copy; return copy;
}), }),
properties: {} properties: cleanup(this.schema.properties)
}; };
if (this.schema.properties.label) {
result.properties.label = this.schema.properties.label;
}
if (this.schema.properties.hints) {
result.properties.hints = this.schema.properties.hints;
}
this.schemaExport = result; this.schemaExport = result;
} }

Loading…
Cancel
Save