-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/system attrs in user dlg (#591)
* Started reendering custom attrs in UserDialog * Fixed q-select in schema item * Added integer schema field and corrected some warnings --------- Co-authored-by: Ramin Haeri Azad <[email protected]>
- Loading branch information
Showing
10 changed files
with
153 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import type { AttributeConfigurationDto, AttributeDto } from 'src/models/Agate'; | ||
import type { SchemaFormField, SchemaFormObject } from 'src/components/models'; | ||
|
||
export function attributesToSchema(attributes: AttributeConfigurationDto[], title: string, description: string) { | ||
const schema = { | ||
$schema: 'http://json-schema.org/schema#', | ||
title: title || '', | ||
description: description || '', | ||
type: 'array', | ||
items: [] as SchemaFormField[], | ||
required: [], | ||
} as SchemaFormObject; | ||
|
||
(attributes || []).forEach((attribute: AttributeConfigurationDto) => { | ||
const type = attribute.type.toLowerCase(); | ||
const field = { | ||
key: attribute.name, | ||
type: type, | ||
title: attribute.name, | ||
description: attribute.description, | ||
} as SchemaFormField; | ||
|
||
switch (attribute.type.toLowerCase()) { | ||
case 'number': | ||
case 'integer': | ||
case 'boolean': | ||
case 'string': | ||
if (type === 'string' && attribute.values) { | ||
field.enum = attribute.values.map((value: string) => ({ key: value, title: value })); | ||
} | ||
|
||
schema.items.push(field); | ||
if (attribute.required) { | ||
schema.required.push(attribute.name); | ||
} | ||
break; | ||
} | ||
}); | ||
|
||
return schema; | ||
} | ||
|
||
export function splitAttributes(attributes: AttributeDto[], systemAttributes: AttributeConfigurationDto[]) { | ||
const systemAttributesMap = new Map<string, AttributeConfigurationDto>(); | ||
systemAttributes.forEach((attribute: AttributeConfigurationDto) => { | ||
systemAttributesMap.set(attribute.name, attribute); | ||
}); | ||
|
||
const custom = [] as AttributeDto[]; | ||
const specific = [] as AttributeDto[]; | ||
|
||
(attributes || []).forEach((attribute: AttributeDto) => { | ||
if (systemAttributesMap.has(attribute.name)) { | ||
custom.push(attribute); | ||
} else { | ||
specific.push(attribute); | ||
} | ||
}); | ||
|
||
return { custom, specific }; | ||
} |