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.

70 lines
1.5 KiB

3 years ago
3 years ago
3 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(
  14. private schema: Schema,
  15. public template: string
  16. ) {}
  17. static valueOf(
  18. { schema, template }:
  19. { schema: Schema, template: string }
  20. ): ConfigTemplateItem {
  21. return new ConfigTemplateItem(schema, template)
  22. }
  23. get modelName(): string {
  24. return this.schema.title
  25. }
  26. get fields(): ParametersForUI[] {
  27. const response: ParametersForUI[] = []
  28. for (const [key, value] of Object.entries(this.schema.properties)) {
  29. if ('type' in value && value.type === 'string') {
  30. response.push({name: key, type: 'textField', value: ''})
  31. } else if ('anyOf' in value) {
  32. response.push(
  33. {
  34. name: key,
  35. type: 'selectField',
  36. value: '',
  37. items: value.anyOf.map(
  38. (item: {'const': string, 'type': string}) => item.const
  39. )
  40. }
  41. )
  42. } else if ('type' in value && value.type === 'object') {
  43. response.push(
  44. {
  45. name: key,
  46. type: 'objectField',
  47. value: []
  48. }
  49. )
  50. }
  51. }
  52. return response
  53. }
  54. toObject(): Fields {
  55. return {
  56. modelName: this.modelName,
  57. template: this.template,
  58. modelAttrs: this.fields,
  59. labelMapping: [],
  60. taskType: ''
  61. }
  62. }
  63. }