Пример #1
0
        /// <summary>
        /// Get file content
        /// </summary>
        public string GetFileContent()
        {
            var imports   = new List <string>();
            var constants = new List <string>();

            var formSection = new CreateFormSectionPartialTemplate(Screen, ScreenSection);

            constants.AddRange(formSection.Constants);

            if (formSection.Blank)
            {
                return(null);
            }

            imports.AddRange(formSection.Imports);

            var source = "";

            if (ScreenSection.ParentScreenSectionId.HasValue)
            {
                source = $@" source=""{ScreenSection.Entity.InternalName.Camelize()}""";
            }

            return($@"import React from 'react';
import {{ {string.Join(", ", imports.Distinct().OrderBy(a => a))} }} from 'react-admin';

{string.Join(Environment.NewLine, constants)}

const {ScreenSection.InternalName} = ({(formSection.Content.Contains("{...props}") ? "props" : "")}) => (
    <div>
{formSection.Content.IndentLines(8)}
    </div>
);

export default {ScreenSection.InternalName};");
        }
Пример #2
0
        /// <summary>
        /// Get file content
        /// </summary>
        public string GetFileContent()
        {
            var imports = new List <string> {
                "Edit", "SimpleForm", "Create"
            };

            var screenSections   = new List <string>();
            var componentImports = new List <string>();
            var constants        = new List <string>();

            ScreenSection rootScreenSection = null;

            foreach (var section in Screen.ScreenSections)
            {
                switch (section.ScreenSectionType)
                {
                case ScreenSectionType.Form:
                    if (rootScreenSection == null)
                    {
                        rootScreenSection = section;
                        var formSection = new CreateFormSectionPartialTemplate(Screen, section);
                        imports.AddRange(formSection.Imports);
                        constants.AddRange(formSection.Constants);
                        if (!formSection.Blank)
                        {
                            screenSections.Add(formSection.Content);
                        }
                    }
                    else
                    {
                        var formSection = new CreateFormSectionPartialTemplate(Screen, section);
                        constants.AddRange(formSection.Constants);
                        if (formSection.Blank)
                        {
                            continue;
                        }
                        if (section.VisibilityExpression == null)
                        {
                            screenSections.Add($@"<{section.InternalName} {{...props}} />");
                        }
                        else
                        {
                            var expressionHelper = new Helpers.ExpressionHelper(Screen);
                            var expression       = expressionHelper.GetExpression(section.VisibilityExpression, "formData");
                            screenSections.Add($@"<FormDataConsumer>
    {{({{ formData, ...rest }}) => 
        {expression} &&
            <{section.InternalName} {{...props}} {{...rest}} />
    }}
</FormDataConsumer>");
                            imports.Add("FormDataConsumer");
                        }
                        componentImports.Add($@"import {section.InternalName} from './{section.InternalName}';");
                    }
                    break;

                case ScreenSectionType.Search:
                {
                    var expression = "formData.id";
                    if (section.VisibilityExpression != null)
                    {
                        var expressionHelper = new Helpers.ExpressionHelper(Screen);
                        expression = string.Concat(expression, " && ", expressionHelper.GetExpression(section.VisibilityExpression, "formData"));
                    }

                    screenSections.Add($@"<FormDataConsumer>
    {{({{ formData, ...rest }}) => 
        {expression} &&
            <{section.InternalName} {{...props}} {{...rest}} />
    }}
</FormDataConsumer>");
                    imports.Add("FormDataConsumer");

                    componentImports.Add($@"import {section.InternalName} from './{section.InternalName}';");
                }
                break;

                case ScreenSectionType.MenuList:
                    break;

                case ScreenSectionType.Html:
                    break;

                default:
                    break;
                }
            }

            return($@"import React from 'react';
import {{ {string.Join(", ", imports.Distinct().OrderBy(a => a))} }} from 'react-admin';
{string.Join(Environment.NewLine, componentImports)}

{string.Join(Environment.NewLine, constants)}
const DynamicTitle = ({{ record }}) => {{
    return <span>{Screen.Title} {{record ? ` - ${{record.title}}` : ''}}</span>;
}};

const {Screen.Entity.InternalName}Edit = (props) => (
    <Edit undoable={{ false }} {{...props}} title={{< DynamicTitle />}}>
        <SimpleForm>
{screenSections.IndentLines(3)}
        </SimpleForm>
    </Edit>
);

const {Screen.Entity.InternalName}Create = (props) => (
    <Create {{...props}} title=""Create {Screen.Title}"">
        <SimpleForm redirect=""list"">
{screenSections.IndentLines(3)}
        </SimpleForm>
    </Create>
);

export {{ {Screen.Entity.InternalName}Edit, {Screen.Entity.InternalName}Create }};");
        }