The configuration for a basic layout.
Exemplo n.º 1
0
        /// <summary>
        /// Deserializes the layout.
        /// </summary>
        /// <param name="configuration">
        /// The serialized layout data.
        /// </param>
        /// <returns>
        /// The deserialized layout.
        /// </returns>
        public object DeserializeConfiguration(string configuration)
        {
            // Variables.
            var layout        = new LayoutBasicConfiguration();
            var configData    = JsonHelper.Deserialize <JObject>(configuration);
            var dynamicConfig = configData as dynamic;
            var properties    = configData.Properties().Select(x => x.Name);
            var propertySet   = new HashSet <string>(properties);
            var rows          = new List <LayoutRow>();

            layout.Rows = rows;


            // Process each row?
            if (propertySet.Contains("rows"))
            {
                foreach (var rowData in dynamicConfig.rows)
                {
                    // Variables.
                    var row   = new LayoutRow();
                    var cells = new List <LayoutCell>();
                    row.Cells = cells;
                    rows.Add(row);


                    // Process each cell.
                    foreach (var cellData in rowData.cells)
                    {
                        // Variables.
                        var cell   = new LayoutCell();
                        var fields = new List <LayoutField>();
                        cell.Fields = fields;
                        cells.Add(cell);


                        // Process each field.
                        foreach (var fieldData in cellData.fields)
                        {
                            var field = new LayoutField();
                            fields.Add(field);
                            var fieldId = GuidHelper.GetGuid(fieldData.id.Value as string);
                            field.FieldId = fieldId;
                        }
                    }


                    // Set column span for each cell.
                    var columnSpan = 12 / cells.Count;
                    foreach (var cell in cells)
                    {
                        cell.ColumnSpan = columnSpan;
                    }
                }
            }


            // Return deserialized layout configuration.
            return(layout);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Deserializes the layout.
        /// </summary>
        /// <param name="configuration">
        /// The serialized layout data.
        /// </param>
        /// <returns>
        /// The deserialized layout.
        /// </returns>
        public object DeserializeConfiguration(string configuration)
        {
            // Variables.
            var configData    = JsonHelper.Deserialize <JObject>(configuration);
            var dynamicConfig = configData as dynamic;
            var properties    = configData.Properties().Select(x => x.Name);
            var propertySet   = new HashSet <string>(properties);
            var rows          = new List <LayoutRow>();
            var layout        = new LayoutBasicConfiguration()
            {
                Rows = rows
            };


            // Process each row?
            if (propertySet.Contains("rows"))
            {
                foreach (var rowData in dynamicConfig.rows)
                {
                    // Variables.
                    var row   = new LayoutRow();
                    var cells = new List <LayoutCell>();
                    row.Cells = cells;
                    rows.Add(row);


                    // Process each cell.
                    foreach (var cellData in rowData.cells)
                    {
                        // Variables.
                        var cell   = new LayoutCell();
                        var fields = new List <LayoutField>();
                        cell.Fields     = fields;
                        cell.ColumnSpan = TryGetColumnSpan(cellData);
                        cells.Add(cell);


                        // Process each field.
                        foreach (var fieldData in cellData.fields)
                        {
                            var field = new LayoutField();
                            fields.Add(field);
                            var fieldId = GuidHelper.GetGuid(fieldData.id.Value as string);
                            field.FieldId = fieldId;
                        }
                    }


                    // Set column span for each cell that doesn't have one specified explicitly.
                    // This is for forms created in older versions of Formulate.
                    SetFallbackColumnSpans(cells);
                }
            }


            // Return deserialized layout configuration.
            return(layout);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Deserializes the layout.
        /// </summary>
        /// <param name="configuration">
        /// The serialized layout data.
        /// </param>
        /// <returns>
        /// The deserialized layout.
        /// </returns>
        public object DeserializeConfiguration(string configuration)
        {
            // Variables.
            var configData = JsonHelper.Deserialize<JObject>(configuration);
            var dynamicConfig = configData as dynamic;
            var properties = configData.Properties().Select(x => x.Name);
            var propertySet = new HashSet<string>(properties);
            var rows = new List<LayoutRow>();
            var layout = new LayoutBasicConfiguration()
            {
                Rows = rows
            };

            // Process each row?
            if (propertySet.Contains("rows"))
            {
                foreach (var rowData in dynamicConfig.rows)
                {

                    // Variables.
                    var row = new LayoutRow();
                    var cells = new List<LayoutCell>();
                    row.Cells = cells;
                    rows.Add(row);

                    // Process each cell.
                    foreach (var cellData in rowData.cells)
                    {

                        // Variables.
                        var cell = new LayoutCell();
                        var fields = new List<LayoutField>();
                        cell.Fields = fields;
                        cell.ColumnSpan = TryGetColumnSpan(cellData);
                        cells.Add(cell);

                        // Process each field.
                        foreach (var fieldData in cellData.fields)
                        {
                            var field = new LayoutField();
                            fields.Add(field);
                            var fieldId = GuidHelper.GetGuid(fieldData.id.Value as string);
                            field.FieldId = fieldId;
                        }

                    }

                    // Set column span for each cell that doesn't have one specified explicitly.
                    // This is for forms created in older versions of Formulate.
                    SetFallbackColumnSpans(cells);

                }
            }

            // Return deserialized layout configuration.
            return layout;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Deserializes the layout.
        /// </summary>
        /// <param name="configuration">
        /// The serialized layout data.
        /// </param>
        /// <returns>
        /// The deserialized layout.
        /// </returns>
        public object DeserializeConfiguration(string configuration)
        {
            // Variables.
            var configData    = JsonHelper.Deserialize <JObject>(configuration);
            var dynamicConfig = configData as dynamic;
            var properties    = configData.Properties().Select(x => x.Name);
            var propertySet   = new HashSet <string>(properties);
            var rows          = new List <LayoutRow>();
            var layout        = new LayoutBasicConfiguration()
            {
                Rows = rows
            };


            // Get the autopopulate value.
            if (propertySet.Contains("autopopulate"))
            {
                var autopopulate = dynamicConfig.autopopulate.Value as bool?;
                layout.Autopopulate = autopopulate.GetValueOrDefault();
            }


            // Get the form ID.
            if (propertySet.Contains("formId"))
            {
                layout.FormId = GuidHelper.GetGuid(dynamicConfig.formId.Value as string);
            }


            // Process each row?
            if (propertySet.Contains("rows"))
            {
                foreach (var rowData in dynamicConfig.rows)
                {
                    // Variables.
                    var castedRowData  = rowData as JObject;
                    var rowProperties  = castedRowData.Properties().Select(x => x.Name);
                    var rowPropertySet = new HashSet <string>(rowProperties);
                    var row            = new LayoutRow();
                    var cells          = new List <LayoutCell>();
                    row.Cells = cells;
                    rows.Add(row);


                    // Is this a row that indicates a new step has started?
                    if (rowPropertySet.Contains("isStep"))
                    {
                        row.IsStep = (rowData.isStep.Value as bool?).GetValueOrDefault();
                    }


                    // Process each cell.
                    foreach (var cellData in rowData.cells)
                    {
                        // Variables.
                        var cell   = new LayoutCell();
                        var fields = new List <LayoutField>();
                        cell.Fields     = fields;
                        cell.ColumnSpan = TryGetColumnSpan(cellData);
                        cells.Add(cell);


                        // Process each field.
                        foreach (var fieldData in cellData.fields)
                        {
                            var field = new LayoutField();
                            fields.Add(field);
                            var fieldId = GuidHelper.GetGuid(fieldData.id.Value as string);
                            field.FieldId = fieldId;
                        }
                    }


                    // Set column span for each cell that doesn't have one specified explicitly.
                    // This is for forms created in older versions of Formulate.
                    SetFallbackColumnSpans(cells);
                }
            }


            // Return deserialized layout configuration.
            return(layout);
        }