/// <summary>
        /// Deserialize the configuration for a radio button list field.
        /// </summary>
        /// <param name="configuration">
        /// The serialized configuration.
        /// </param>
        /// <returns>
        /// The deserialized configuration.
        /// </returns>
        public object DeserializeConfiguration(string configuration)
        {
            // Variables.
            var items  = new List <ExtendedRadioButtonListItem>();
            var config = new ExtendedRadioButtonListConfiguration()
            {
                Items = items
            };
            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);


            // A data value is selected?
            if (propertySet.Contains("dataValue"))
            {
                // Get info about the data value.
                var dataValueId = GuidHelper.GetGuid(dynamicConfig.dataValue.Value as string);
                var dataValue   = DataValues.Retrieve(dataValueId);
                if (dataValue != null)
                {
                    // Extract list items from the data value.
                    var kinds            = DataValueHelper.GetAllDataValueKinds();
                    var kind             = kinds.FirstOrDefault(x => x.Id == dataValue.KindId);
                    var pairCollection   = kind as IGetValueAndLabelCollection;
                    var stringCollection = kind as IGetStringCollection;


                    // Check type of collection returned by the data value kind.
                    if (pairCollection != null)
                    {
                        // Create radio buttons from values and labels.
                        var pairs = pairCollection.GetValues(dataValue.Data);
                        items.AddRange(pairs.Select(x => new ExtendedRadioButtonListItem()
                        {
                            Selected  = false,
                            Primary   = x.Value,
                            Secondary = x.Label
                        }));
                    }
                    else if (stringCollection != null)
                    {
                        // Create radio buttons from strings.
                        var strings = stringCollection.GetValues(dataValue.Data);
                        items.AddRange(strings.Select(x => new ExtendedRadioButtonListItem()
                        {
                            Selected  = false,
                            Primary   = x,
                            Secondary = null
                        }));
                    }
                }
            }


            // Return the data value configuration.
            return(config);
        }
 public FormulateTreeController()
 {
     Persistence = EntityPersistence.Current.Manager;
     FolderHelper = new FolderHelper(Persistence, this);
     FormHelper = new FormHelper(this, FolderHelper);
     LayoutHelper = new LayoutHelper(this, FolderHelper);
     ValidationHelper = new ValidationHelper(this, FolderHelper);
     DataValueHelper = new DataValueHelper(this, FolderHelper);
 }
        public object GetDataValueInfo(
            [FromUri] GetDataValueInfoRequest request)
        {
            // Variables.
            var result = default(object);
            var rootId = CoreConstants.System.Root.ToInvariantString();


            // Catch all errors.
            try
            {
                // Variables.
                var id        = GuidHelper.GetGuid(request.DataValueId);
                var dataValue = Persistence.Retrieve(id);
                var fullPath  = new[] { rootId }
                .Concat(dataValue.Path.Select(x => GuidHelper.GetString(x)))
                .ToArray();
                var kinds     = DataValueHelper.GetAllDataValueKinds();
                var directive = kinds.Where(x => x.Id == dataValue.KindId)
                                .Select(x => x.Directive).FirstOrDefault();


                // Set result.
                result = new
                {
                    Success     = true,
                    DataValueId = GuidHelper.GetString(dataValue.Id),
                    KindId      = GuidHelper.GetString(dataValue.KindId),
                    Path        = fullPath,
                    Alias       = dataValue.Alias,
                    Name        = dataValue.Name,
                    Directive   = directive,
                    Data        = JsonHelper.Deserialize <object>(dataValue.Data)
                };
            }
            catch (Exception ex)
            {
                // Error.
                LogHelper.Error <DataValuesController>(
                    GetDataValueInfoError, ex);
                result = new
                {
                    Success = false,
                    Reason  = UnhandledError
                };
            }


            // Return result.
            return(result);
        }
        public object GetDataValueKinds()
        {
            // Variables.
            var result = default(object);


            // Catch all errors.
            try
            {
                // Variables.
                var kinds = DataValueHelper.GetAllDataValueKinds();


                // Return results.
                result = new
                {
                    Success = true,
                    Kinds   = kinds.Select(x => new
                    {
                        Id        = GuidHelper.GetString(x.Id),
                        Name      = x.Name,
                        Directive = x.Directive
                    }).ToArray()
                };
            }
            catch (Exception ex)
            {
                // Error.
                LogHelper.Error <DataValuesController>(GetKindsError, ex);
                result = new
                {
                    Success = false,
                    Reason  = UnhandledError
                };
            }


            // Return result.
            return(result);
        }
示例#5
0
        /// <summary>
        /// Deserialize the configuration for a drop down field.
        /// </summary>
        /// <param name="configuration">
        /// The serialized configuration.
        /// </param>
        /// <returns>
        /// The deserialized configuration.
        /// </returns>
        public object DeserializeConfiguration(string configuration)
        {
            // Variables.
            var items  = new List <DropDownItem>();
            var config = new DropDownConfiguration()
            {
                Items = items
            };
            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);


            // A data value is selected?
            if (propertySet.Contains("dataValue"))
            {
                // Get info about the data value.
                var dataValueId = GuidHelper.GetGuid(dynamicConfig.dataValue.Value as string);
                var dataValue   = DataValues.Retrieve(dataValueId);
                if (dataValue != null)
                {
                    // Extract list items from the data value.
                    var kinds    = DataValueHelper.GetAllDataValueKinds();
                    var kind     = kinds.FirstOrDefault(x => x.Id == dataValue.KindId);
                    var strItems = kind is DataValueList?ExtractList(dataValue.Data) : new List <string>();

                    items.AddRange(strItems.Select(x => new DropDownItem()
                    {
                        Label    = x,
                        Selected = false,
                        Value    = x
                    }));
                }
            }


            // Return the data value configuration.
            return(config);
        }
        public object GetDataValuesInfo(
            [FromUri] GetDataValuesInfoRequest request)
        {
            // Variables.
            var result = default(object);
            var rootId = CoreConstants.System.Root.ToInvariantString();


            // Catch all errors.
            try
            {
                // Variables.
                var ids = request.DataValueIds
                          .Select(x => GuidHelper.GetGuid(x));
                var dataValues = ids.Select(x => Persistence.Retrieve(x))
                                 .WithoutNulls();
                var kinds    = DataValueHelper.GetAllDataValueKinds();
                var combined = dataValues.Join(kinds,
                                               x => x.KindId,
                                               y => y.Id,
                                               (x, y) => new
                {
                    Value = x,
                    Kind  = y
                });


                // Set result.
                result = new
                {
                    Success    = true,
                    DataValues = combined.Select(x => new
                    {
                        DataValueId = GuidHelper.GetString(x.Value.Id),
                        KindId      = GuidHelper.GetString(x.Value.KindId),
                        Path        = new[] { rootId }
                        .Concat(GuidHelper.GetStrings(x.Value.Path))
                        .ToArray(),
                        Alias     = x.Value.Alias,
                        Name      = x.Value.Name,
                        Directive = x.Kind.Directive,
                        Data      = JsonHelper.Deserialize <object>(x.Value.Data)
                    }),
                };
            }
            catch (Exception ex)
            {
                // Error.
                LogHelper.Error <DataValuesController>(
                    GetDataValueInfoError, ex);
                result = new
                {
                    Success = false,
                    Reason  = UnhandledError
                };
            }


            // Return result.
            return(result);
        }