Ejemplo n.º 1
0
        public List <FormFieldType> GetFieldTypes()
        {
            if (mFieldTypes == null)
            {
                mFieldTypes = new List <FormFieldType>();
                mFieldTypes.Add(new FormFieldType());

                var fieldTypes = typeof(FormField).Assembly.GetTypes()
                                 .Where(t => t.IsSubclassOf(typeof(FormField)) &&
                                        !t.CustomAttributes.Where(a => a.AttributeType.IsAssignableFrom(typeof(CFIgnoreAttribute))).Any())
                                 .ToList();

                foreach (var t in fieldTypes)
                {
                    CFTypeLabelAttribute att = Attribute.GetCustomAttribute(t, typeof(CFTypeLabelAttribute)) as CFTypeLabelAttribute;

                    //We expect Metadata Fields that are usable by the interface
                    //to have a TypeLabel attribute to be defined (and labeled)
                    if (att != null)
                    {
                        mFieldTypes.Add(new FormFieldType()
                        {
                            FieldType = t.AssemblyQualifiedName,
                            Label     = att.Name
                        });
                    }
                }
            }

            return(mFieldTypes);
        }
Ejemplo n.º 2
0
        public FormFieldViewModel(FormField formField, int abstractFormId)
        {
            Name        = formField.MultilingualName.ToList();
            Description = formField.MultilingualDescription.ToList();
            IsRequired  = formField.IsRequired;
            FieldType   = formField.GetType().AssemblyQualifiedName;
            Guid        = formField.Guid;
            Rank        = formField.Rank;
            Page        = formField.Page;
            IsPageBreak = formField.IsPageBreak();
            Files       = formField.Files.Select(m => new FileViewModel(m, abstractFormId)).ToList();
            //FieldFileGuids = src.FieldFileGuidsArray;
            //Files = src.Files;

            CFTypeLabelAttribute att = Attribute.GetCustomAttribute(formField.GetType(), typeof(CFTypeLabelAttribute)) as CFTypeLabelAttribute;

            TypeLabel = att == null?formField.GetType().ToString() : att.Name;

            IsOptionField = typeof(OptionsField).IsAssignableFrom(formField.GetType());
            if (IsOptionField)
            {
                MultilingualOptionSet = new List <TextValue>();

                //making sure we have an option-list editor for each language defined in the configuration settings.
                foreach (var lang in ConfigHelper.Languages)
                {
                    MultilingualOptionSet.Add(new TextValue(lang.TwoLetterISOLanguageName, lang.NativeName, ""));
                }

                IReadOnlyList <Option> options = (formField as OptionsField).Options;
                foreach (Option op in options)
                {
                    foreach (TextValue txt in op.Value)
                    {
                        TextValue editorData = MultilingualOptionSet.Where(x => x.LanguageCode == txt.LanguageCode).FirstOrDefault();

                        //Accommodating odd situations where data has a language that is not specified in the configuration
                        if (editorData == null)
                        {
                            MultilingualOptionSet.Add(editorData = new TextValue(txt.LanguageCode, txt.LanguageLabel, ""));
                        }

                        if (string.IsNullOrEmpty(editorData.Value))
                        {
                            editorData.Value = txt.Value;
                        }
                        else
                        {
                            editorData.Value = editorData.Value + "\n" + txt.Value;
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        protected override ModelMetadata CreateMetadata(IEnumerable <Attribute> attributes, Type containerType, Func <object> modelAccessor, Type modelType, string propertyName)
        {
            var metadata = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);

            CFTypeLabelAttribute attr = attributes.OfType <CFTypeLabelAttribute>().FirstOrDefault();

            if (attr != null)
            {
                metadata.AdditionalValues.Add("TypeLabel", attr.Name);
            }

            return(metadata);
        }
Ejemplo n.º 4
0
        public FormBuilderViewModel(AbstractForm src)
        {
            Id = src.Id;
            CFTypeLabelAttribute att = Attribute.GetCustomAttribute(src.GetType(), typeof(CFTypeLabelAttribute)) as CFTypeLabelAttribute;

            TypeLabel = att == null?src.GetType().ToString() : att.Name;

            Name        = src.Name;
            Description = src.Description;
            Guid        = src.Guid;

            Fields = new List <FormFieldViewModel>();
            foreach (var field in src.Fields)
            {
                Fields.Add(new FormFieldViewModel(field, src.Id));
            }

            Fields = Fields.OrderBy(f => f.Rank).ToList();
        }
        public void CreateMetadataSet(string name, string description, FormField[] fields, bool isMultiple = false, bool required = false)
        {
            Driver.Navigate().GoToUrl(ManagerUrl);
            Driver.FindElement(By.LinkText(SettingsLinkText)).Click();
            Driver.FindElement(By.LinkText(MetadataSetsLinkText)).Click();
            Driver.FindElement(By.Id(ToolBarAddButtonId)).Click();
            Driver.FindElement(By.Id(NameId)).SendKeys(name);
            Driver.FindElement(By.Id(DescriptionId)).SendKeys(description);

            // Add metadata set fields

            // id field-type-selector
            IWebElement   fieldTypeSelectorElement = Driver.FindElement(By.Id("field-type-selector"));
            SelectElement fieldTypeSelector        = new SelectElement(fieldTypeSelectorElement);

            int i = 1;

            foreach (FormField field in fields)
            {
                //field.GetType();
                CFTypeLabelAttribute typeLabelAttribute = (CFTypeLabelAttribute)field.GetType()
                                                          .GetCustomAttributes(typeof(CFTypeLabelAttribute), true)
                                                          .First();

                // select option by label
                fieldTypeSelector.SelectByText(typeLabelAttribute.Name);
                // click on id add-field

                Driver.FindElement(By.Id("add-field")).Click();

                // fill values on last field-entry
                IWebElement lastFieldEntry = Driver.FindElement(By.XPath("(//div[contains(@class, 'field-entry')])[last()]"), 10);

                // fill class field-is-required with fields[0].IsRequired

                // XXX generalize to use all language codes Name_sp, Name_fr
                lastFieldEntry.FindElement(By.Name("Name_en")).SendKeys(field.Name);

                //make the 1st field mandatory
                if (i == 1)
                {
                    field.IsRequired = required;
                }

                // XXX need to add options ?

                if (field.IsRequired)
                {
                    lastFieldEntry.FindElement(By.ClassName("field-is-required")).Click();
                }

                if (isMultiple)
                {
                    //only make the first field multiple
                    if (i == 1)
                    {
                        lastFieldEntry.FindElement(By.ClassName("field-is-multiple")).Click();
                        i++;
                    }
                }

                // Add options
                if (typeof(OptionsField).IsAssignableFrom(field.GetType()))
                {
                    IEnumerable <Option> options = ((OptionsField)field).Options;

                    IEnumerable <IWebElement> elements = lastFieldEntry.FindElements(By.CssSelector(".languageInputField > textarea"));

                    for (int f = 0; f < elements.Count(); ++f)
                    {
                        elements.ElementAt(f).SendKeys(string.Join("\n", options.Select(o => o.Value.Count > f ? o.Value.ElementAt(f).Value : " ")));
                    }
                }
            }

            Driver.FindElement(By.Id(ToolBarSaveButtonId), 10).Click();
        }
        public FormFieldViewModel(FormField formField, int abstractFormId)
        {
            Name = formField.MultilingualName.ToList();
            Description = formField.MultilingualDescription.ToList();
            IsRequired = formField.IsRequired;
            FieldType = formField.GetType().AssemblyQualifiedName;
            Guid = formField.Guid;
            Rank = formField.Rank;
            Page = formField.Page;
            IsPageBreak = formField.IsPageBreak();
            Files = formField.Files.Select( m => new FileViewModel(m, abstractFormId)).ToList();
            //FieldFileGuids = src.FieldFileGuidsArray;
            //Files = src.Files;

            CFTypeLabelAttribute att = Attribute.GetCustomAttribute(formField.GetType(), typeof(CFTypeLabelAttribute)) as CFTypeLabelAttribute;
            TypeLabel = att == null ? formField.GetType().ToString() : att.Name;

            IsSliderField = typeof(SliderField).IsAssignableFrom(formField.GetType());
            if (IsSliderField)
            {
                Min = ((SliderField)formField).Min;
                Max = ((SliderField)formField).Max;
                Step = ((SliderField)formField).Step;
                MinLabel = ((SliderField)formField).MinLabel;
                MaxLabel = ((SliderField)formField).MaxLabel;
            }

            IsExternalMediaField = typeof(ExternalMediaField).IsAssignableFrom(formField.GetType());
            MediaProperties = new List<KeyValuePair<string, ViewModelTuple<IEnumerable<string>, bool>>>();
            if (IsExternalMediaField)
            {
                Source = ((ExternalMediaField)formField).Source;
                MimeType = Enum.GetName(typeof(CFDataFile.MimeType), ((ExternalMediaField)formField).MediaType);

                var mediaTypeProperties = formField.GetType().GetProperties().Where(p => Attribute.IsDefined(p, typeof(MediaTypeAttribute)));

                foreach (var p in mediaTypeProperties)
                {
                    MediaProperties.Add(new KeyValuePair<string, ViewModelTuple<IEnumerable<string>, bool>>(p.Name, new ViewModelTuple<IEnumerable<string>, bool>(p.GetCustomAttribute<MediaTypeAttribute>(true)
                        .MimeTypes.Select(m => Enum.GetName(typeof(CFDataFile.MimeType), m)),
                        (bool)p.GetValue(formField))));
                }
            }
            

            IsOptionField = typeof(OptionsField).IsAssignableFrom(formField.GetType());
            if (IsOptionField)
            {
                MultilingualOptionSet = new List<TextValue>();

                //making sure we have an option-list editor for each language defined in the configuration settings.
                foreach (var lang in ConfigHelper.Languages)
                    MultilingualOptionSet.Add(new TextValue(lang.TwoLetterISOLanguageName, lang.NativeName, ""));

                IReadOnlyList<Option> options = (formField as OptionsField).Options;
                foreach (Option op in options)
                {
                    foreach (TextValue txt in op.Value)
                    {
                        TextValue editorData = MultilingualOptionSet.Where(x => x.LanguageCode == txt.LanguageCode).FirstOrDefault();

                        //Accommodating odd situations where data has a language that is not specified in the configuration
                        if (editorData == null)
                            MultilingualOptionSet.Add(editorData = new TextValue(txt.LanguageCode, txt.LanguageLabel, ""));

                        if (string.IsNullOrEmpty(editorData.Value))
                            editorData.Value = txt.Value;
                        else
                            editorData.Value = editorData.Value + "\n" + txt.Value;
                    }
                }
            }

            IsTextArea = typeof(TextArea).IsAssignableFrom(formField.GetType());
            if(IsTextArea){
                IsRichText = ((TextArea)formField).IsRichText;
            }
            IsTextField = typeof(TextField).IsAssignableFrom(formField.GetType());
            if (IsTextField)
                IsMultiple = ((TextField)formField).IsMultiple; //Nov 19 2016
        }
        public void UpdateViewModel(object dataModel, CatfishDbContext db)
        {
            CFEntityType model = dataModel as CFEntityType;

            Id   = model.Id;
            Name = model.Name;
            if (!string.IsNullOrEmpty(Name))
            {
                ErrorMessage = "";
            }
            Description = model.Description;
            // TargetType = model.TargetType.ToString();

            foreach (var tt in model.TargetTypesList)  //MR jan 15 2018
            {
                TargetType[(int)tt] = true;
            }

            CFTypeLabelAttribute att = Attribute.GetCustomAttribute(model.GetType(), typeof(CFTypeLabelAttribute)) as CFTypeLabelAttribute;

            TypeLabel = att == null?model.GetType().ToString() : att.Name;

            //populating the available metadata sets array
            MetadataService srv          = new MetadataService(db);
            var             metadataSets = srv.GetMetadataSets();

            AvailableMetadataSets.Clear();
            AvailableMetadataSets.Add(new MetadataSetListItem(0, ""));
            foreach (var ms in metadataSets)
            {
                if (!string.IsNullOrEmpty(ms.Name))
                {
                    AvailableMetadataSets.Add(new MetadataSetListItem(ms.Id, ms.Name));

                    List <string> addList = new List <string>();
                    addList.Add("");
                    addList = addList.Concat((ms.Fields.Select(f => f.Name).ToList())).ToList();

                    if (!MetadataSetFields.ContainsKey(ms.Id.ToString()))
                    {
                        MetadataSetFields.Add(ms.Id.ToString(), addList);
                    }
                }
            }

            //populating the associated metadata sets array
            AssociatedMetadataSets.Clear();
            foreach (var ms in model.MetadataSets)
            {
                AssociatedMetadataSets.Add(new MetadataSetListItem(ms.Id, ms.Name));
            }


            AttributeMappings.Clear();
            if (model.AttributeMappings.Count > 0)
            {
                foreach (CFEntityTypeAttributeMapping map in model.AttributeMappings)
                {
                    if (map.Name.Equals("Name Mapping"))// || map.Name.Equals("Description Mapping"))
                    {
                        map.Deletable = false;
                    }

                    AttributeMappings.Add(new AttributeMapping
                    {
                        Id    = map.Id,
                        Name  = map.Name,
                        Field = map.FieldName,
                        MetadataSetFieldId = map.MetadataSetId,
                        Label     = map.Label,
                        Deletable = map.Deletable
                    });
                }
            }
            else
            {
                AttributeMappings.Add(new AttributeMapping {
                    Id = 0, Name = "Name Mapping", Deletable = false
                });
                AttributeMappings.Add(new AttributeMapping {
                    Id = 0, Name = "Description Mapping", Deletable = true, ErrorMessage = ""
                });
            }
        }