Skip to content

Commit d1d3a22

Browse files
Andrea Barbassoatarix83
authored andcommitted
Merged in UXP-132 (pull request DSpace#1587)
[UXP-132] add markdown field parser Approved-by: Giuseppe Digilio
2 parents bbc336a + da98bc5 commit d1d3a22

4 files changed

Lines changed: 40 additions & 1 deletion

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { DynamicFormControlLayout, serializable } from '@ng-dynamic-forms/core';
2+
import { DsDynamicInputModel, DsDynamicInputModelConfig } from '../ds-dynamic-input.model';
3+
import { DYNAMIC_FORM_CONTROL_TYPE_MARKDOWN } from './dynamic-markdown.model';
4+
5+
6+
export class DsDynamicMarkdownModel extends DsDynamicInputModel {
7+
@serializable() type = DYNAMIC_FORM_CONTROL_TYPE_MARKDOWN;
8+
9+
constructor(config: DsDynamicInputModelConfig, layout?: DynamicFormControlLayout) {
10+
super(config, layout);
11+
12+
}
13+
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { FieldParser } from './field-parser';
2+
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
3+
import { environment } from '../../../../../environments/environment';
4+
import { DsDynamicMarkdownModel } from '../ds-dynamic-form-ui/models/markdown/ds-dynamic-markdown.model';
5+
import { DsDynamicInputModelConfig } from '../ds-dynamic-form-ui/models/ds-dynamic-input.model';
6+
7+
export class MarkdownFieldParser extends FieldParser {
8+
9+
public modelFactory(fieldValue?: FormFieldMetadataValueObject | any, label?: boolean): any {
10+
const markDownModelConfig: DsDynamicInputModelConfig = this.initModel(null, label);
11+
12+
markDownModelConfig.spellCheck = environment.form.spellCheck;
13+
this.setValues(markDownModelConfig, fieldValue);
14+
return new DsDynamicMarkdownModel(markDownModelConfig);
15+
}
16+
}

src/app/shared/form/builder/parsers/parser-factory.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { TextareaFieldParser } from './textarea-field-parser';
2222
import { NumberFieldParser } from './number-field-parser';
2323
import { CalendarFieldParser } from './calendar-field-parser';
2424
import { DisabledFieldParser } from './disabled-field-parser';
25+
import { MarkdownFieldParser } from './markdown-field-parser';
2526

2627
const fieldParserDeps = [
2728
SUBMISSION_ID,
@@ -143,6 +144,13 @@ export class ParserFactory {
143144
deps: [...fieldParserDeps]
144145
};
145146
}
147+
case ParserType.Markdown: {
148+
return {
149+
provide: FieldParser,
150+
useClass: MarkdownFieldParser,
151+
deps: [...fieldParserDeps]
152+
};
153+
}
146154
case undefined: {
147155
return {
148156
provide: FieldParser,

src/app/shared/form/builder/parsers/parser-type.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ export enum ParserType {
1515
Tag = 'tag',
1616
Textarea = 'textarea',
1717
Number = 'number',
18-
Calendar = 'calendar'
18+
Calendar = 'calendar',
19+
Markdown = 'markdown',
1920
}

0 commit comments

Comments
 (0)