public override void Map(Property property, ContentPropertyDto dest, MapperContext context)
        {
            base.Map(property, dest, context);

            dest.IsRequired       = property.PropertyType.Mandatory;
            dest.ValidationRegExp = property.PropertyType.ValidationRegExp;
            dest.Description      = property.PropertyType.Description;
            dest.Label            = property.PropertyType.Name;
            dest.DataType         = DataTypeService.GetDataType(property.PropertyType.DataTypeId);
        }
        public override ContentPropertyDto Convert(Property property, ContentPropertyDto dest, ResolutionContext context)
        {
            var propertyDto = base.Convert(property, dest, context);

            propertyDto.IsRequired       = property.PropertyType.Mandatory;
            propertyDto.ValidationRegExp = property.PropertyType.ValidationRegExp;
            propertyDto.Description      = property.PropertyType.Description;
            propertyDto.Label            = property.PropertyType.Name;
            propertyDto.DataType         = DataTypeService.GetDataType(property.PropertyType.DataTypeId);

            return(propertyDto);
        }
        public override void Map(IProperty property, ContentPropertyDto dest, MapperContext context)
        {
            base.Map(property, dest, context);

            dest.IsRequired              = property.PropertyType?.Mandatory;
            dest.IsRequiredMessage       = property.PropertyType?.MandatoryMessage;
            dest.ValidationRegExp        = property.PropertyType?.ValidationRegExp;
            dest.ValidationRegExpMessage = property.PropertyType?.ValidationRegExpMessage;
            dest.Description             = property.PropertyType?.Description;
            dest.Label      = property.PropertyType?.Name;
            dest.DataType   = property.PropertyType is null ? null : DataTypeService.GetDataType(property.PropertyType.DataTypeId);
            dest.LabelOnTop = property.PropertyType?.LabelOnTop;
        }
    public override void Map(IProperty originalProp, ContentPropertyDisplay dest, MapperContext context)
    {
        base.Map(originalProp, dest, context);

        var config = originalProp.PropertyType is null
            ? null
            : DataTypeService.GetDataType(originalProp.PropertyType.DataTypeId)?.Configuration;

        // TODO: IDataValueEditor configuration - general issue
        // GetValueEditor() returns a non-configured IDataValueEditor
        // - for richtext and nested, configuration determines HideLabel, so we need to configure the value editor
        // - could configuration also determines ValueType, everywhere?
        // - does it make any sense to use a IDataValueEditor without configuring it?

        // configure the editor for display with configuration
        IDataValueEditor?valEditor = dest.PropertyEditor?.GetValueEditor(config);

        // set the display properties after mapping
        dest.Alias       = originalProp.Alias;
        dest.Description = originalProp.PropertyType?.Description;
        dest.Label       = originalProp.PropertyType?.Name;
        dest.HideLabel   = valEditor?.HideLabel ?? false;
        dest.LabelOnTop  = originalProp.PropertyType?.LabelOnTop;

        // add the validation information
        dest.Validation.Mandatory        = originalProp.PropertyType?.Mandatory ?? false;
        dest.Validation.MandatoryMessage = originalProp.PropertyType?.MandatoryMessage;
        dest.Validation.Pattern          = originalProp.PropertyType?.ValidationRegExp;
        dest.Validation.PatternMessage   = originalProp.PropertyType?.ValidationRegExpMessage;

        if (dest.PropertyEditor == null)
        {
            // display.Config = PreValueCollection.AsDictionary(preVals);
            // if there is no property editor it means that it is a legacy data type
            // we cannot support editing with that so we'll just render the readonly value view.
            dest.View = "views/propertyeditors/readonlyvalue/readonlyvalue.html";
        }
        else
        {
            // let the property editor format the pre-values
            dest.Config = dest.PropertyEditor.GetConfigurationEditor().ToValueEditor(config);
            dest.View   = valEditor?.View;
        }

        // Translate
        dest.Label       = _textService.UmbracoDictionaryTranslate(_cultureDictionary, dest.Label);
        dest.Description = _textService.UmbracoDictionaryTranslate(_cultureDictionary, dest.Description);
    }
Esempio n. 5
0
        public override ContentPropertyDisplay Convert(Property originalProp, ContentPropertyDisplay dest, ResolutionContext context)
        {
            var display = base.Convert(originalProp, dest, context);

            var config = DataTypeService.GetDataType(originalProp.PropertyType.DataTypeId).Configuration;

            // fixme - IDataValueEditor configuration - general issue
            // GetValueEditor() returns a non-configured IDataValueEditor
            // - for richtext and nested, configuration determines HideLabel, so we need to configure the value editor
            // - could configuration also determines ValueType, everywhere?
            // - does it make any sense to use a IDataValueEditor without configuring it?

            // configure the editor for display with configuration
            var valEditor = display.PropertyEditor.GetValueEditor(config);

            //set the display properties after mapping
            display.Alias       = originalProp.Alias;
            display.Description = originalProp.PropertyType.Description;
            display.Label       = originalProp.PropertyType.Name;
            display.HideLabel   = valEditor.HideLabel;

            //add the validation information
            display.Validation.Mandatory = originalProp.PropertyType.Mandatory;
            display.Validation.Pattern   = originalProp.PropertyType.ValidationRegExp;

            if (display.PropertyEditor == null)
            {
                //display.Config = PreValueCollection.AsDictionary(preVals);
                //if there is no property editor it means that it is a legacy data type
                // we cannot support editing with that so we'll just render the readonly value view.
                display.View = "views/propertyeditors/readonlyvalue/readonlyvalue.html";
            }
            else
            {
                //let the property editor format the pre-values
                display.Config = display.PropertyEditor.GetConfigurationEditor().ToValueEditor(config);
                display.View   = valEditor.View;
            }

            //Translate
            display.Label       = _textService.UmbracoDictionaryTranslate(display.Label);
            display.Description = _textService.UmbracoDictionaryTranslate(display.Description);

            return(display);
        }
Esempio n. 6
0
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            var dataType = (DataTypeSave)actionContext.ActionArguments["dataType"];

            dataType.Name  = dataType.Name.CleanForXss('[', ']', '(', ')', ':');
            dataType.Alias = dataType.Alias == null ? dataType.Name : dataType.Alias.CleanForXss('[', ']', '(', ')', ':');

            // get the property editor, ensuring that it exits
            if (!PropertyEditors.TryGet(dataType.EditorAlias, out var propertyEditor))
            {
                var message = $"Property editor \"{dataType.EditorAlias}\" was not found.";
                actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.NotFound, message);
                return;
            }

            // assign
            dataType.PropertyEditor = propertyEditor;

            // validate that the data type exists, or create one if required
            IDataType persisted;

            switch (dataType.Action)
            {
            case ContentSaveAction.Save:
                persisted = DataTypeService.GetDataType(Convert.ToInt32(dataType.Id));
                if (persisted == null)
                {
                    var message = $"Data type with id {dataType.Id} was not found.";
                    actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.NotFound, message);
                    return;
                }
                // map the model to the persisted instance
                Current.Mapper.Map(dataType, persisted);
                break;

            case ContentSaveAction.SaveNew:
                // create the persisted model from mapping the saved model
                persisted = Current.Mapper.Map <IDataType>(dataType);
                ((DataType)persisted).ResetIdentity();
                break;

            default:
                actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.NotFound, new ArgumentOutOfRangeException());
                return;
            }

            // assign (so it's available in the action)
            dataType.PersistedDataType = persisted;

            // validate the configuration
            // which is posted as a set of fields with key (string) and value (object)
            var configurationEditor = propertyEditor.GetConfigurationEditor();

            foreach (var field in dataType.ConfigurationFields)
            {
                var editorField = configurationEditor.Fields.SingleOrDefault(x => x.Key == field.Key);
                if (editorField == null)
                {
                    continue;
                }

                // run each IValueValidator (with null valueType and dataTypeConfiguration: not relevant here)
                foreach (var validator in editorField.Validators)
                {
                    foreach (var result in validator.Validate(field.Value, null, null))
                    {
                        actionContext.ModelState.AddValidationError(result, "Properties", field.Key);
                    }
                }
            }

            if (actionContext.ModelState.IsValid == false)
            {
                // if it is not valid, do not continue and return the model state
                actionContext.Response = actionContext.Request.CreateValidationErrorResponse(actionContext.ModelState);
            }
        }