|
|
@ -13,12 +13,12 @@ import { |
|
|
AddFieldDto, |
|
|
AddFieldDto, |
|
|
AppComponentBase, |
|
|
AppComponentBase, |
|
|
AppsStoreService, |
|
|
AppsStoreService, |
|
|
|
|
|
AuthService, |
|
|
createProperties, |
|
|
createProperties, |
|
|
fadeAnimation, |
|
|
fadeAnimation, |
|
|
FieldDto, |
|
|
FieldDto, |
|
|
fieldTypes, |
|
|
fieldTypes, |
|
|
HistoryChannelUpdated, |
|
|
HistoryChannelUpdated, |
|
|
ImmutableArray, |
|
|
|
|
|
MessageBus, |
|
|
MessageBus, |
|
|
ModalView, |
|
|
ModalView, |
|
|
NotificationService, |
|
|
NotificationService, |
|
|
@ -27,8 +27,7 @@ import { |
|
|
SchemaPropertiesDto, |
|
|
SchemaPropertiesDto, |
|
|
SchemasService, |
|
|
SchemasService, |
|
|
UpdateFieldDto, |
|
|
UpdateFieldDto, |
|
|
ValidatorsEx, |
|
|
ValidatorsEx |
|
|
Version |
|
|
|
|
|
} from 'shared'; |
|
|
} from 'shared'; |
|
|
|
|
|
|
|
|
import { SchemaDeleted, SchemaUpdated } from './../messages'; |
|
|
import { SchemaDeleted, SchemaUpdated } from './../messages'; |
|
|
@ -45,11 +44,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { |
|
|
public fieldTypes = fieldTypes; |
|
|
public fieldTypes = fieldTypes; |
|
|
|
|
|
|
|
|
public schemaExport: any; |
|
|
public schemaExport: any; |
|
|
public schemaName: string; |
|
|
public schema: SchemaDetailsDto; |
|
|
public schemaFields = ImmutableArray.empty<FieldDto>(); |
|
|
|
|
|
public schemaVersion = new Version(''); |
|
|
|
|
|
public schemaProperties: SchemaPropertiesDto; |
|
|
|
|
|
public schemaInformation: any; |
|
|
|
|
|
public schemas: SchemaDto[]; |
|
|
public schemas: SchemaDto[]; |
|
|
|
|
|
|
|
|
public confirmDeleteDialog = new ModalView(); |
|
|
public confirmDeleteDialog = new ModalView(); |
|
|
@ -59,8 +54,6 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { |
|
|
public editOptionsDropdown = new ModalView(); |
|
|
public editOptionsDropdown = new ModalView(); |
|
|
public editSchemaDialog = new ModalView(); |
|
|
public editSchemaDialog = new ModalView(); |
|
|
|
|
|
|
|
|
public isPublished: boolean; |
|
|
|
|
|
|
|
|
|
|
|
public addFieldFormSubmitted = false; |
|
|
public addFieldFormSubmitted = false; |
|
|
public addFieldForm: FormGroup = |
|
|
public addFieldForm: FormGroup = |
|
|
this.formBuilder.group({ |
|
|
this.formBuilder.group({ |
|
|
@ -81,11 +74,12 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
constructor(apps: AppsStoreService, notifications: NotificationService, |
|
|
constructor(apps: AppsStoreService, notifications: NotificationService, |
|
|
private readonly schemasService: SchemasService, |
|
|
private readonly authService: AuthService, |
|
|
private readonly messageBus: MessageBus, |
|
|
|
|
|
private readonly formBuilder: FormBuilder, |
|
|
private readonly formBuilder: FormBuilder, |
|
|
|
|
|
private readonly messageBus: MessageBus, |
|
|
private readonly route: ActivatedRoute, |
|
|
private readonly route: ActivatedRoute, |
|
|
private readonly router: Router |
|
|
private readonly router: Router, |
|
|
|
|
|
private readonly schemasService: SchemasService |
|
|
) { |
|
|
) { |
|
|
super(notifications, apps); |
|
|
super(notifications, apps); |
|
|
} |
|
|
} |
|
|
@ -93,13 +87,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { |
|
|
public ngOnInit() { |
|
|
public ngOnInit() { |
|
|
this.route.data.map(p => p['schema']) |
|
|
this.route.data.map(p => p['schema']) |
|
|
.subscribe((schema: SchemaDetailsDto) => { |
|
|
.subscribe((schema: SchemaDetailsDto) => { |
|
|
this.schemaName = schema.name; |
|
|
this.schema = schema; |
|
|
this.schemaFields = ImmutableArray.of(schema.fields); |
|
|
|
|
|
this.schemaVersion = schema.version; |
|
|
|
|
|
this.schemaProperties = schema.properties; |
|
|
|
|
|
this.schemaInformation = { properties: schema.properties, name: schema.name }; |
|
|
|
|
|
|
|
|
|
|
|
this.isPublished = schema.isPublished; |
|
|
|
|
|
|
|
|
|
|
|
this.export(); |
|
|
this.export(); |
|
|
}); |
|
|
}); |
|
|
@ -119,10 +107,9 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { |
|
|
|
|
|
|
|
|
public publish() { |
|
|
public publish() { |
|
|
this.appNameOnce() |
|
|
this.appNameOnce() |
|
|
.switchMap(app => this.schemasService.publishSchema(app, this.schemaName, this.schemaVersion)).retry(2) |
|
|
.switchMap(app => this.schemasService.publishSchema(app, this.schema.name, this.schema.version)).retry(2) |
|
|
.subscribe(() => { |
|
|
.subscribe(() => { |
|
|
this.isPublished = true; |
|
|
this.updateSchema(this.schema.publish(this.authService.user.token)); |
|
|
this.notify(); |
|
|
|
|
|
}, error => { |
|
|
}, error => { |
|
|
this.notifyError(error); |
|
|
this.notifyError(error); |
|
|
}); |
|
|
}); |
|
|
@ -130,10 +117,9 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { |
|
|
|
|
|
|
|
|
public unpublish() { |
|
|
public unpublish() { |
|
|
this.appNameOnce() |
|
|
this.appNameOnce() |
|
|
.switchMap(app => this.schemasService.unpublishSchema(app, this.schemaName, this.schemaVersion)).retry(2) |
|
|
.switchMap(app => this.schemasService.unpublishSchema(app, this.schema.name, this.schema.version)).retry(2) |
|
|
.subscribe(() => { |
|
|
.subscribe(() => { |
|
|
this.isPublished = false; |
|
|
this.updateSchema(this.schema.unpublish(this.authService.user.token)); |
|
|
this.notify(); |
|
|
|
|
|
}, error => { |
|
|
}, error => { |
|
|
this.notifyError(error); |
|
|
this.notifyError(error); |
|
|
}); |
|
|
}); |
|
|
@ -141,9 +127,9 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { |
|
|
|
|
|
|
|
|
public enableField(field: FieldDto) { |
|
|
public enableField(field: FieldDto) { |
|
|
this.appNameOnce() |
|
|
this.appNameOnce() |
|
|
.switchMap(app => this.schemasService.enableField(app, this.schemaName, field.fieldId, this.schemaVersion)).retry(2) |
|
|
.switchMap(app => this.schemasService.enableField(app, this.schema.name, field.fieldId, this.schema.version)).retry(2) |
|
|
.subscribe(() => { |
|
|
.subscribe(() => { |
|
|
this.updateField(field, new FieldDto(field.fieldId, field.name, field.isHidden, false, field.partitioning, field.properties)); |
|
|
this.updateSchema(this.schema.updateField(this.authService.user.token, field.enable())); |
|
|
}, error => { |
|
|
}, error => { |
|
|
this.notifyError(error); |
|
|
this.notifyError(error); |
|
|
}); |
|
|
}); |
|
|
@ -151,9 +137,9 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { |
|
|
|
|
|
|
|
|
public disableField(field: FieldDto) { |
|
|
public disableField(field: FieldDto) { |
|
|
this.appNameOnce() |
|
|
this.appNameOnce() |
|
|
.switchMap(app => this.schemasService.disableField(app, this.schemaName, field.fieldId, this.schemaVersion)).retry(2) |
|
|
.switchMap(app => this.schemasService.disableField(app, this.schema.name, field.fieldId, this.schema.version)).retry(2) |
|
|
.subscribe(() => { |
|
|
.subscribe(() => { |
|
|
this.updateField(field, new FieldDto(field.fieldId, field.name, field.isHidden, true, field.partitioning, field.properties)); |
|
|
this.updateSchema(this.schema.updateField(this.authService.user.token, field.disable())); |
|
|
}, error => { |
|
|
}, error => { |
|
|
this.notifyError(error); |
|
|
this.notifyError(error); |
|
|
}); |
|
|
}); |
|
|
@ -161,9 +147,9 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { |
|
|
|
|
|
|
|
|
public showField(field: FieldDto) { |
|
|
public showField(field: FieldDto) { |
|
|
this.appNameOnce() |
|
|
this.appNameOnce() |
|
|
.switchMap(app => this.schemasService.showField(app, this.schemaName, field.fieldId, this.schemaVersion)).retry(2) |
|
|
.switchMap(app => this.schemasService.showField(app, this.schema.name, field.fieldId, this.schema.version)).retry(2) |
|
|
.subscribe(() => { |
|
|
.subscribe(() => { |
|
|
this.updateField(field, new FieldDto(field.fieldId, field.name, false, field.isDisabled, field.partitioning, field.properties)); |
|
|
this.updateSchema(this.schema.updateField(this.authService.user.token, field.show())); |
|
|
}, error => { |
|
|
}, error => { |
|
|
this.notifyError(error); |
|
|
this.notifyError(error); |
|
|
}); |
|
|
}); |
|
|
@ -171,9 +157,9 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { |
|
|
|
|
|
|
|
|
public hideField(field: FieldDto) { |
|
|
public hideField(field: FieldDto) { |
|
|
this.appNameOnce() |
|
|
this.appNameOnce() |
|
|
.switchMap(app => this.schemasService.hideField(app, this.schemaName, field.fieldId, this.schemaVersion)).retry(2) |
|
|
.switchMap(app => this.schemasService.hideField(app, this.schema.name, field.fieldId, this.schema.version)).retry(2) |
|
|
.subscribe(() => { |
|
|
.subscribe(() => { |
|
|
this.updateField(field, new FieldDto(field.fieldId, field.name, true, field.isDisabled, field.partitioning, field.properties)); |
|
|
this.updateSchema(this.schema.updateField(this.authService.user.token, field.hide())); |
|
|
}, error => { |
|
|
}, error => { |
|
|
this.notifyError(error); |
|
|
this.notifyError(error); |
|
|
}); |
|
|
}); |
|
|
@ -181,33 +167,31 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { |
|
|
|
|
|
|
|
|
public deleteField(field: FieldDto) { |
|
|
public deleteField(field: FieldDto) { |
|
|
this.appNameOnce() |
|
|
this.appNameOnce() |
|
|
.switchMap(app => this.schemasService.deleteField(app, this.schemaName, field.fieldId, this.schemaVersion)).retry(2) |
|
|
.switchMap(app => this.schemasService.deleteField(app, this.schema.name, field.fieldId, this.schema.version)).retry(2) |
|
|
.subscribe(() => { |
|
|
.subscribe(() => { |
|
|
this.updateFields(this.schemaFields.remove(field)); |
|
|
this.updateSchema(this.schema.removeField(this.authService.user.token, field)); |
|
|
}, error => { |
|
|
}, error => { |
|
|
this.notifyError(error); |
|
|
this.notifyError(error); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public sortFields(fields: FieldDto[]) { |
|
|
public sortFields(fields: FieldDto[]) { |
|
|
this.updateFields(ImmutableArray.of(fields)); |
|
|
|
|
|
|
|
|
|
|
|
this.appNameOnce() |
|
|
this.appNameOnce() |
|
|
.switchMap(app => this.schemasService.putFieldOrdering(app, this.schemaName, fields.map(t => t.fieldId), this.schemaVersion)).retry(2) |
|
|
.switchMap(app => this.schemasService.putFieldOrdering(app, this.schema.name, fields.map(t => t.fieldId), this.schema.version)).retry(2) |
|
|
.subscribe(() => { |
|
|
.subscribe(() => { |
|
|
this.updateFields(ImmutableArray.of(fields)); |
|
|
this.updateSchema(this.schema.replaceFields(this.authService.user.token, fields)); |
|
|
}, error => { |
|
|
}, error => { |
|
|
this.notifyError(error); |
|
|
this.notifyError(error); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public saveField(field: FieldDto, newField: FieldDto) { |
|
|
public saveField(field: FieldDto) { |
|
|
const requestDto = new UpdateFieldDto(newField.properties); |
|
|
const requestDto = new UpdateFieldDto(field.properties); |
|
|
|
|
|
|
|
|
this.appNameOnce() |
|
|
this.appNameOnce() |
|
|
.switchMap(app => this.schemasService.putField(app, this.schemaName, field.fieldId, requestDto, this.schemaVersion)).retry(2) |
|
|
.switchMap(app => this.schemasService.putField(app, this.schema.name, field.fieldId, requestDto, this.schema.version)).retry(2) |
|
|
.subscribe(() => { |
|
|
.subscribe(() => { |
|
|
this.updateField(field, new FieldDto(field.fieldId, field.name, newField.isHidden, field.isDisabled, field.partitioning, newField.properties)); |
|
|
this.updateSchema(this.schema.updateField(this.authService.user.token, field)); |
|
|
}, error => { |
|
|
}, error => { |
|
|
this.notifyError(error); |
|
|
this.notifyError(error); |
|
|
}); |
|
|
}); |
|
|
@ -215,16 +199,15 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { |
|
|
|
|
|
|
|
|
public deleteSchema() { |
|
|
public deleteSchema() { |
|
|
this.appNameOnce() |
|
|
this.appNameOnce() |
|
|
.switchMap(app => this.schemasService.deleteSchema(app, this.schemaName, this.schemaVersion)).retry(2) |
|
|
.switchMap(app => this.schemasService.deleteSchema(app, this.schema.name, this.schema.version)).retry(2) |
|
|
.finally(() => { |
|
|
|
|
|
this.confirmDeleteDialog.hide(); |
|
|
|
|
|
}) |
|
|
|
|
|
.subscribe(() => { |
|
|
.subscribe(() => { |
|
|
this.messageBus.publish(new SchemaDeleted(this.schemaName)); |
|
|
this.messageBus.publish(new SchemaDeleted(this.schema.id)); |
|
|
|
|
|
|
|
|
this.router.navigate(['../'], { relativeTo: this.route }); |
|
|
this.router.navigate(['../'], { relativeTo: this.route }); |
|
|
}, error => { |
|
|
}, error => { |
|
|
this.notifyError(error); |
|
|
this.notifyError(error); |
|
|
|
|
|
}, () => { |
|
|
|
|
|
this.confirmDeleteDialog.hide(); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -246,17 +229,9 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
this.appNameOnce() |
|
|
this.appNameOnce() |
|
|
.switchMap(app => this.schemasService.postField(app, this.schemaName, requestDto, this.schemaVersion)) |
|
|
.switchMap(app => this.schemasService.postField(app, this.schema.name, requestDto, this.schema.version)) |
|
|
.subscribe(dto => { |
|
|
.subscribe(dto => { |
|
|
const newField = |
|
|
this.updateSchema(this.schema.addField(this.authService.user.token, dto)); |
|
|
new FieldDto(parseInt(dto.id, 10), |
|
|
|
|
|
requestDto.name, |
|
|
|
|
|
false, |
|
|
|
|
|
false, |
|
|
|
|
|
requestDto.partitioning, |
|
|
|
|
|
requestDto.properties); |
|
|
|
|
|
|
|
|
|
|
|
this.updateFields(this.schemaFields.push(newField)); |
|
|
|
|
|
reset(); |
|
|
reset(); |
|
|
}, error => { |
|
|
}, error => { |
|
|
this.notifyError(error); |
|
|
this.notifyError(error); |
|
|
@ -271,28 +246,13 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public onSchemaSaved(properties: SchemaPropertiesDto) { |
|
|
public onSchemaSaved(properties: SchemaPropertiesDto) { |
|
|
this.updateProperties(properties); |
|
|
this.updateSchema(this.schema.update(this.authService.user.token, properties)); |
|
|
|
|
|
|
|
|
this.editSchemaDialog.hide(); |
|
|
this.editSchemaDialog.hide(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private updateProperties(properties: SchemaPropertiesDto) { |
|
|
private updateSchema(schema: SchemaDetailsDto) { |
|
|
this.schemaProperties = properties; |
|
|
this.schema = schema; |
|
|
this.schemaInformation = { properties: properties, name: this.schemaName }; |
|
|
|
|
|
|
|
|
|
|
|
this.notify(); |
|
|
|
|
|
this.export(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private updateField(field: FieldDto, newField: FieldDto) { |
|
|
|
|
|
this.schemaFields = this.schemaFields.replace(field, newField); |
|
|
|
|
|
|
|
|
|
|
|
this.notify(); |
|
|
|
|
|
this.export(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private updateFields(fields: ImmutableArray<FieldDto>) { |
|
|
|
|
|
this.schemaFields = fields; |
|
|
|
|
|
|
|
|
|
|
|
this.notify(); |
|
|
this.notify(); |
|
|
this.export(); |
|
|
this.export(); |
|
|
@ -300,7 +260,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { |
|
|
|
|
|
|
|
|
private export() { |
|
|
private export() { |
|
|
const result: any = { |
|
|
const result: any = { |
|
|
fields: this.schemaFields.values.map(field => { |
|
|
fields: this.schema.fields.map(field => { |
|
|
const copy: any = Object.assign({}, field); |
|
|
const copy: any = Object.assign({}, field); |
|
|
|
|
|
|
|
|
delete copy.fieldId; |
|
|
delete copy.fieldId; |
|
|
@ -318,12 +278,12 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { |
|
|
properties: {} |
|
|
properties: {} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
if (this.schemaProperties.label) { |
|
|
if (this.schema.properties.label) { |
|
|
result.properties.label = this.schemaProperties.label; |
|
|
result.properties.label = this.schema.properties.label; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (this.schemaProperties.hints) { |
|
|
if (this.schema.properties.hints) { |
|
|
result.properties.hints = this.schemaProperties.hints; |
|
|
result.properties.hints = this.schema.properties.hints; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this.schemaExport = result; |
|
|
this.schemaExport = result; |
|
|
@ -331,7 +291,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { |
|
|
|
|
|
|
|
|
private notify() { |
|
|
private notify() { |
|
|
this.messageBus.publish(new HistoryChannelUpdated()); |
|
|
this.messageBus.publish(new HistoryChannelUpdated()); |
|
|
this.messageBus.publish(new SchemaUpdated(this.schemaName, this.schemaProperties, this.isPublished, this.schemaVersion.value)); |
|
|
this.messageBus.publish(new SchemaUpdated(this.schema)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|