You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.4 KiB

3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
  1. import { Fields, ParametersForUI } from '~/domain/models/autoLabeling/config'
  2. export interface Schema {
  3. title: string
  4. type: string
  5. properties: object
  6. }
  7. export interface ConfigResponse {
  8. name: string
  9. schema: Schema
  10. template: string
  11. }
  12. export class ConfigTemplateItem {
  13. constructor(private schema: Schema, public template: string) {}
  14. static valueOf({ schema, template }: { schema: Schema; template: string }): ConfigTemplateItem {
  15. return new ConfigTemplateItem(schema, template)
  16. }
  17. get modelName(): string {
  18. return this.schema.title
  19. }
  20. get fields(): ParametersForUI[] {
  21. const response: ParametersForUI[] = []
  22. for (const [key, value] of Object.entries(this.schema.properties)) {
  23. if ('type' in value && value.type === 'string') {
  24. response.push({ name: key, type: 'textField', value: '' })
  25. } else if ('anyOf' in value) {
  26. response.push({
  27. name: key,
  28. type: 'selectField',
  29. value: '',
  30. items: value.anyOf.map((item: { const: string; type: string }) => item.const)
  31. })
  32. } else if ('type' in value && value.type === 'object') {
  33. response.push({
  34. name: key,
  35. type: 'objectField',
  36. value: []
  37. })
  38. }
  39. }
  40. return response
  41. }
  42. toObject(): Fields {
  43. return {
  44. modelName: this.modelName,
  45. template: this.template,
  46. modelAttrs: this.fields,
  47. labelMapping: [],
  48. taskType: ''
  49. }
  50. }
  51. }