Beispiel #1
0
        private static void RemoveUnusedNewOptions(ProjectEditOptionsModel options, List <PortfolioLabelConfig> optionListLabels, List <_jsonProperty> editOptionProperties)
        {
            var query = from l in optionListLabels
                        join eop in editOptionProperties on l.FieldName equals eop.json.PropertyName
                        select new _projectProperty()
            {
                label = l, editOptionProperty = eop.property
            }
            ;

            foreach (var property in query)
            {
                // Work from array of strings so can accommodate subcat
                List <DropDownItemModel> dropDownOptions = property.editOptionProperty.GetValue(options) as List <DropDownItemModel>;
                if (dropDownOptions != null)
                {
                    dropDownOptions.RemoveAll(o => o.Order == ProjectOptionConstants.HideOrderValue);
                }
                else
                {
                    SelectPickerModel selectPickerOptions = property.editOptionProperty.GetValue(options) as SelectPickerModel;
                    if (selectPickerOptions != null)
                    {
                        selectPickerOptions.Items.RemoveAll(o => o.Order == ProjectOptionConstants.HideOrderValue);
                    }
                }
            }
        }
Beispiel #2
0
 internal _optionsPropertyMap(PropertyInfo property, ProjectEditOptionsModel options) : base(property)
 {
     this.property      = property;
     this.json          = property.GetCustomAttribute <JsonPropertyAttribute>();
     this.optionValue   = this.property.GetValue(options);
     this.dropDownItems = this.optionValue as List <DropDownItemModel>;
     this.selectPicker  = this.optionValue as SelectPickerModel;
 }
Beispiel #3
0
        private static void RemoveUnusedEditOptions(ProjectEditOptionsModel options, ProjectEditViewModel project, List <PortfolioLabelConfig> optionListLabels, List <_jsonProperty> editOptionProperties)
        {
            // Have to add the existing options for project fields where:
            // - field is a string
            // - field is of type OptionList or MultiOptionList

            // Get all members of the <Project, ProjectEditViewModel> where:
            // - json property of field in ProjectEditViewModel

            var projectEditProperites =
                typeof(ProjectEditViewModel)
                .GetProperties()
                .Select(p => new { property = p, json = p.GetCustomAttribute <JsonPropertyAttribute>() })
                .Where(p => p.json != null)
                .ToList();

            var query = from l in optionListLabels
                        join eop in editOptionProperties on l.FieldName equals eop.json.PropertyName
                        join pep in projectEditProperites on l.FieldName equals pep.json.PropertyName
                        select new _projectProperty()
            {
                label = l, editOptionProperty = eop.property, projectEditProperty = pep.property
            }
            ;

            foreach (var property in query)
            {
                // Get value from ProjectEditViewModel
                // Work from array of strings so can accommodate subcat
                if (property.projectEditProperty.PropertyType == typeof(string))
                {
                    var projectValue = property.projectEditProperty.GetValue(project) as string;
                    List <DropDownItemModel> propertyOptions = property.editOptionProperty.GetValue(options) as List <DropDownItemModel>;
                    if (propertyOptions != null)
                    {
                        // Might need to add the value to the list
                        // Note: this could be skipped for IProjectOption collections, but there's no way to tell if this is the case.
                        if (projectValue != null)
                        {
                            if (propertyOptions != null && !propertyOptions.Any(o => o.Value == projectValue))
                            {
                                propertyOptions.Insert(0, LabelDropDownResolver.NewDropDownItem(0, projectValue, projectValue));
                            }
                        }

                        // Now clear out unused hidden options (this does apply to IProjectOption collections!)
                        propertyOptions.RemoveAll(o => o.Order == ProjectOptionConstants.HideOrderValue && projectValue != o.Value);
                    }
                }
                else if (property.projectEditProperty.PropertyType == typeof(string[]))
                {
                    var values = property.projectEditProperty.GetValue(project) as string[];
                    SelectPickerModel propertyOptions = property.editOptionProperty.GetValue(options) as SelectPickerModel;
                    if (propertyOptions != null)
                    {
                        // Note that we don't have to add properties here as this occurs with subcat only: which is an IProjectOption collection.

                        // Now clear out unused hidden options
                        propertyOptions.Items.RemoveAll(o => o.Order == ProjectOptionConstants.HideOrderValue && (values == null || !values.Contains(o.Value)));
                    }
                }
            }
        }