frontend/src/app/structures/HostRecord.ts

73 lines
1.8 KiB
TypeScript
Raw Normal View History

2020-02-08 09:36:14 +00:00
export default class HostRecord {
public value = '';
2020-11-17 04:48:59 +00:00
// tslint:disable-next-line:max-line-length
public type: 'paragraph'|'database_ref'|'code_ref'|'file_ref'|'markdown'|'form_input_text'|'form_input_number'|'form_input_password'|'form_input_email'|'form_input_select'|'form_input_multiselect'|'form_input_textarea'|'file_box' = 'paragraph';
2020-02-08 09:36:14 +00:00
public CreatedAt: string;
public PageId: string;
private privUUID: string;
public UpdatedAt: string;
public Value: any;
2020-11-17 04:48:59 +00:00
public AdditionalData: any;
2020-02-08 09:36:14 +00:00
public get UUID(): string {
return this.privUUID;
}
public set UUID(val: string) {}
2020-02-08 09:36:14 +00:00
constructor(value = '') {
this.value = value;
}
2020-02-09 05:09:46 +00:00
public isNorm() {
return ['paragraph', 'header1', 'header2', 'header3', 'header4', 'block_code', 'click_link', 'page_sep'].includes(this.type);
2020-02-09 05:09:46 +00:00
}
2020-11-17 04:48:59 +00:00
public isForm() {
return !!this.type?.toLowerCase()?.startsWith('form_input_');
}
load(data: any) {
this.type = data.Type;
this.privUUID = data.UUID;
[
'CreatedAt',
'PageId',
'UpdatedAt',
'Value',
2020-11-17 04:48:59 +00:00
'AdditionalData',
].forEach(field => {
if ( field in data ) {
this[field] = data[field];
}
});
}
toSave() {
const data: any = {
Type: this.type
};
[
'CreatedAt',
'PageId',
'UUID',
'UpdatedAt',
'Value',
2020-11-17 04:48:59 +00:00
'AdditionalData',
].forEach(field => {
if ( field in this ) {
data[field] = this[field];
}
});
if ( !data.Value ) {
data.Value = {};
}
data.Value.Value = this.value;
return data;
}
2020-02-08 09:36:14 +00:00
}