Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cat-voices): proposal template models #1363

Merged
merged 22 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
093487c
draft for setup segment
LynxLynxx Dec 9, 2024
508cb91
fix: delete unused files
LynxLynxx Dec 9, 2024
3757c4a
feat: dtos for properties
LynxLynxx Dec 10, 2024
93f2329
feat:creating dtos for proposal schema
LynxLynxx Dec 16, 2024
5e0c5c7
feat: merge mve3
LynxLynxx Dec 16, 2024
8eb4a81
feat: creating toModels
LynxLynxx Dec 17, 2024
9d91618
feat: sort section/elements by xorder
LynxLynxx Dec 18, 2024
4b5487a
feat: adding missing toModels for definitions
LynxLynxx Dec 18, 2024
e5f765c
fix: delete unused property from element class
LynxLynxx Dec 18, 2024
f696fb4
feat: creating generic_proposal.json
LynxLynxx Dec 19, 2024
2ad36ca
test: adding unit tests
LynxLynxx Dec 19, 2024
15fd551
feat: range class for easier representation for max min values
LynxLynxx Dec 20, 2024
5ed4e8c
feat: adding proper from/to Json for proposal_builder class
LynxLynxx Dec 20, 2024
41f56b3
feat: change name of the files to make it more generic -document-
LynxLynxx Dec 20, 2024
b326558
feat: change name of the document property widget
LynxLynxx Dec 20, 2024
e5e89d2
feat: adding equatable for classes
LynxLynxx Dec 20, 2024
9968cf8
Merge branch 'mve3' into feat/proposal-template-models
dtscalac Dec 23, 2024
0106505
chore: update chain follower
dtscalac Dec 23, 2024
4d70b4a
feat: sortingBy order
LynxLynxx Dec 23, 2024
cfdd91d
Merge branch 'feat/proposal-template-models' of github.com:input-outp…
LynxLynxx Dec 23, 2024
5141c75
Merge branch 'mve3' into feat/proposal-template-models
dtscalac Dec 23, 2024
b0783c5
chore: revert merge conflicts
dtscalac Dec 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
abstract class Definition {
LynxLynxx marked this conversation as resolved.
Show resolved Hide resolved
final String type;
LynxLynxx marked this conversation as resolved.
Show resolved Hide resolved
final String? format;
final String? contentMediaType;
final String? pattern;

const Definition({
required this.type,
this.format,
this.contentMediaType,
this.pattern,
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import 'package:catalyst_voices_models/src/proposal_template/definitions/definition.dart';

sealed class ListEntryDefinition extends Definition {
final bool uniqueItems;
final List<dynamic> defaultValue;

ListEntryDefinition({
this.uniqueItems = true,
required this.defaultValue,
super.type = 'array',
super.format,
});
}

final class SingleLineTextEntryListDefinition extends ListEntryDefinition {
SingleLineTextEntryListDefinition({
super.uniqueItems,
required super.defaultValue,
required super.type,
super.format = 'singleLineTextEntryList',
});
}

final class MultiLineTextEntryListMarkdownDefinition
extends ListEntryDefinition {
MultiLineTextEntryListMarkdownDefinition({
super.uniqueItems,
required super.defaultValue,
super.format = 'multiLineTextEntryListMarkdown',
});
}

final class SingleLineHttpsURLEntryListDefinition extends ListEntryDefinition {
SingleLineHttpsURLEntryListDefinition({
super.uniqueItems,
required super.defaultValue,
super.format = 'singleLineHttpsURLEntryList',
LynxLynxx marked this conversation as resolved.
Show resolved Hide resolved
});
}

final class NestedQuestionsListDefinition extends ListEntryDefinition {
NestedQuestionsListDefinition({
super.uniqueItems,
required super.defaultValue,
super.format = 'nestedQuestionsList',
});
}

final class NestedQuestionsDefinition extends Definition {
final bool additionalProperties;

NestedQuestionsDefinition({
this.additionalProperties = false,
super.type = 'object',
super.format = 'nestedQuestions',
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:catalyst_voices_models/src/proposal_template/definitions/definition.dart';

sealed class LogicalSectionDefinition extends Definition {
final bool additionalProperties;

const LogicalSectionDefinition({
required this.additionalProperties,
}) : super(type: 'object');
}

final class SegmentDefinition extends LogicalSectionDefinition {
const SegmentDefinition() : super(additionalProperties: false);
}

final class SectionDefinition extends LogicalSectionDefinition {
const SectionDefinition() : super(additionalProperties: false);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import 'package:catalyst_voices_models/src/proposal_template/definitions/definition.dart';

final class SchemaReferenceDefinition extends Definition {
final bool readOnly;

const SchemaReferenceDefinition({
required this.readOnly,
required String format,
}) : super(
type: 'string',
format: format,
);
}

final class DropDownSingleSelectDefinition extends Definition {
const DropDownSingleSelectDefinition()
: super(
type: 'string',
contentMediaType: 'text/plain',
pattern: r'^.*$',
format: 'dropDownSingleSelect',
);
}

final class MultiSelectDefinition extends Definition {
final bool uniqueItems;

const MultiSelectDefinition({
this.uniqueItems = true,
}) : super(
type: 'array',
format: 'multiSelect',
);
}

final class TokenValueCardanoADADefinition extends Definition {
const TokenValueCardanoADADefinition()
: super(
type: 'integer',
format: 'token:cardano:ada',
);
}

final class DurationInMonthsDefinition extends Definition {
const DurationInMonthsDefinition()
: super(
type: 'integer',
format: 'datetime:duration:months',
);
}

final class YesNoChoiceDefinition extends Definition {
final bool defaultValue;

const YesNoChoiceDefinition({
this.defaultValue = false,
}) : super(
type: 'boolean',
format: 'yesNoChoice',
);
}

final class AgreementConfirmationDefinition extends Definition {
final bool defaultValue;
final bool constValue;

const AgreementConfirmationDefinition({
this.defaultValue = false,
this.constValue = true,
}) : super(
type: 'boolean',
format: 'agreementConfirmation',
);
}

final class SPDXLicenseOrURLDefinition extends Definition {
const SPDXLicenseOrURLDefinition()
: super(
type: 'string',
contentMediaType: 'text/plain',
pattern: r'^.*$',
format: 'spdxLicenseOrURL',
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'package:catalyst_voices_models/src/proposal_template/definitions/definition.dart';

sealed class TagDefinition extends Definition {
const TagDefinition({
required super.type,
required super.format,
super.pattern,
});
}

final class SingleGroupedTagSelectorDefinition extends TagDefinition {
final bool additionalProperties;

const SingleGroupedTagSelectorDefinition({
this.additionalProperties = false,
}) : super(
type: 'object',
format: 'singleGroupedTagSelector',
);
}

final class TagGroupDefinition extends TagDefinition {
const TagGroupDefinition()
: super(
type: 'string',
format: 'tagGroup',
pattern: r'^.*$',
);
}

final class TagSelectionDefinition extends TagDefinition {
const TagSelectionDefinition()
: super(
type: 'string',
format: 'tagSelection',
pattern: r'^.*$',
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import 'package:catalyst_voices_models/src/proposal_template/definitions/definition.dart';

sealed class TextEntryDefinition extends Definition {
const TextEntryDefinition({
required String super.contentMediaType,
required String super.pattern,
required super.type,
});
}

final class SingleLineTextEntryDefinition extends TextEntryDefinition {
const SingleLineTextEntryDefinition()
: super(
contentMediaType: 'text/plain',
pattern: r'^.*$',
type: 'string',
);
}

final class SingleLineHttpsURLEntryDefinition extends TextEntryDefinition {
const SingleLineHttpsURLEntryDefinition()
: super(
contentMediaType: 'text/plain',
pattern: '^https:.*',
type: 'string',
);
}

final class MultiLineTextEntryDefinition extends TextEntryDefinition {
const MultiLineTextEntryDefinition()
: super(
contentMediaType: 'text/plain',
pattern: r'^[\S\s]*$',
type: 'string',
);
}

final class MultiLineTextEntryMarkdownDefinition extends TextEntryDefinition {
const MultiLineTextEntryMarkdownDefinition()
: super(
contentMediaType: 'text/markdown',
pattern: r'^[\S\s]*$',
type: 'string',
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import 'package:catalyst_voices_models/src/proposal_template/dtos/proposal_template_segment_dto.dart';
import 'package:equatable/equatable.dart';
import 'package:json_annotation/json_annotation.dart';

part 'proposal_template_dto.g.dart';

@JsonSerializable()
class ProposalTemplateDTO extends Equatable {
@JsonKey(name: r'$schema')
final String schema;
final String title;
final String description;
final Map<String, dynamic> definitions;
final String type;
final bool additionalProperties;
final List<ProposalTemplateSegmentDTO> properties;
@JsonKey(name: 'x-order')
final List<String> order;

const ProposalTemplateDTO({
required this.schema,
required this.title,
required this.description,
required this.definitions,
this.type = 'object',
this.additionalProperties = false,
required this.properties,
required this.order,
});

factory ProposalTemplateDTO.fromJson(Map<String, dynamic> json) {
final segmentsMap = json['properties'] as Map<String, dynamic>;
json['properties'] = MapUtils.convertMapToListWithIds(segmentsMap);

return _$ProposalTemplateDTOFromJson(json);
}

Map<String, dynamic> toJson() => _$ProposalTemplateDTOToJson(this);
LynxLynxx marked this conversation as resolved.
Show resolved Hide resolved

@override
List<Object?> get props => [
schema,
title,
description,
definitions,
type,
additionalProperties,
properties,
order,
];
}

class MapUtils {
static List<Map<String, dynamic>> convertMapToListWithIds(
Map<String, dynamic> map,
) {
final list = <Map<String, dynamic>>[];

for (final entry in map.entries) {
if (entry.key == r'$schema') continue;
final value = entry.value as Map<String, dynamic>;
value['id'] = entry.key;
list.add(value);
}

return list;
}
}
LynxLynxx marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import 'package:catalyst_voices_models/src/proposal_template/dtos/proposal_template_dto.dart';
import 'package:equatable/equatable.dart';
import 'package:json_annotation/json_annotation.dart';

part 'proposal_template_element_dto.g.dart';

@JsonSerializable()
class ProposalTemplateElementDto extends Equatable {
@JsonKey(name: r'$ref', includeToJson: false)
final String ref;
final String id;
final String title;
final String description;
final String? minLength;
final String? maxLength;
@JsonKey(name: 'default')
final String defaultValue;
@JsonKey(name: 'x-guidance')
final String guidance;
@JsonKey(name: 'enum')
final List<String> enumValues;
final int? maxItems;
final int? minItems;
final int? minimum;
final int? maximum;
final List<String> examples;
final Map<String, dynamic> items; // TODO(ryszard-shossler): return to this

const ProposalTemplateElementDto({
required this.ref,
required this.id,
required this.title,
required this.description,
required this.minLength,
required this.maxLength,
this.defaultValue = '',
required this.guidance,
this.enumValues = const <String>[],
required this.maxItems,
required this.minItems,
required this.minimum,
required this.maximum,
this.examples = const <String>[],
this.items = const <String, dynamic>{},
});

factory ProposalTemplateElementDto.fromJson(Map<String, dynamic> json) {
final segmentsMap = json['properties'] as Map<String, dynamic>;
json['properties'] = MapUtils.convertMapToListWithIds(segmentsMap);

return _$ProposalTemplateElementDtoFromJson(json);
}

Map<String, dynamic> toJson() => _$ProposalTemplateElementDtoToJson(this);

@override
List<Object?> get props => [];
}
Loading
Loading