Esempio n. 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);
                    }
                }
            }
        }
 public List <DropDownItemModel> Resolve(PortfolioConfiguration source, ProjectEditOptionsModel destination, List <DropDownItemModel> destMember, ResolutionContext context)
 {
     return(source.PriorityGroups.Select(pg => new DropDownItemModel()
     {
         Display = pg.Name, Value = pg.ViewKey, Order = pg.Order
     }).ToList());
 }
Esempio n. 3
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;
 }
        public List <DropDownItemModel> Resolve(PortfolioConfiguration source, ProjectEditOptionsModel destination, IEnumerable <TOption> sourceMember, List <DropDownItemModel> destMember, ResolutionContext context)
        {
            List <DropDownItemModel> items = null;

            if (sourceMember != null)
            {
                items = context.Mapper.Map <List <DropDownItemModel> >(sourceMember);
                if (emptyOption)
                {
                    items.Insert(0, new DropDownItemModel()
                    {
                        Display = "None", Value = null
                    });
                }
            }
            return(items);
        }
        public List <DropDownItemModel> Resolve(PortfolioConfiguration source, ProjectEditOptionsModel destination, List <DropDownItemModel> destMember, ResolutionContext context)
        {
            List <DropDownItemModel> items = null;
            var label = source.Labels.SingleOrDefault(l => l.FieldName == fieldName);

            if (!string.IsNullOrEmpty(label?.FieldOptions))
            {
                items = label.FieldOptions.Split(',').Select((l, i) =>
                {
                    var value   = l.Trim();
                    var display = value;
                    return(NewDropDownItem(i + 1, value, display));
                })
                        .ToList();
                if (emptyOption)
                {
                    items.Insert(0, NewDropDownItem(1, null, "None"));
                }
            }
            return(items);
        }
Esempio n. 6
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)));
                    }
                }
            }
        }
Esempio n. 7
0
        internal static async Task MapAsync(PortfolioContext context, PortfolioConfiguration config, ProjectEditOptionsModel options, ProjectEditViewModel project = null)
        {
            var directorates = await context.Directorates.OrderBy(d => d.Order).ToListAsync();

            var directorateItems = PortfolioMapper.ProjectMapper.Map <List <DropDownItemModel> >(directorates);

            directorateItems.Insert(0, new DropDownItemModel()
            {
                Display = "None", Value = "", Order = 0
            });
            options.Directorates = directorateItems;

            var teams = PortfolioMapper.ProjectMapper.Map <List <DropDownItemModel> >(config.Portfolio.Teams.OrderBy(d => d.Order));

            options.G6Team = teams;

            // Get the OptionList labels...
            var optionListLabels = config.Labels
                                   .Where(l => l.FieldType == PortfolioFieldType.OptionList || l.FieldType == PortfolioFieldType.MultiOptionList || l.FieldType == PortfolioFieldType.PredefinedMultiList)
                                   .ToList();

            // Get the edit option properties that have a json property name in the OptionList labels...
            var editOptionProperties =
                typeof(ProjectEditOptionsModel)
                .GetProperties()
                .Select(p => new _jsonProperty()
            {
                property = p, json = p.GetCustomAttribute <JsonPropertyAttribute>()
            })
                .Where(p => p.json != null)
                .ToList();

            if (project != null)
            {
                RemoveUnusedEditOptions(options, project, optionListLabels, editOptionProperties);
            }
            else
            {
                RemoveUnusedNewOptions(options, optionListLabels, editOptionProperties);
            }
        }
Esempio n. 8
0
        public async Task <List <ProjectUpdateModel> > ImportProjectsAsync(MultipartFormDataStreamProvider files, PortfolioConfiguration config, ProjectEditOptionsModel options)
        {
            var projects          = new List <ProjectUpdateModel>();
            var optionsProperties = typeof(ProjectEditOptionsModel).GetProperties().Select(p => new _optionsPropertyMap(p, options)).ToList();;
            var projectProperties = typeof(ProjectUpdateModel).GetProperties().Select(p => new _projectPropertyMap(p, config)).ToList();

            foreach (var file in files.FileData)
            {
                using (var reader = new StreamReader(file.LocalFileName))
                    using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
                    {
                        if (await csv.ReadAsync())
                        {
                            if (csv.ReadHeader())
                            {
                                // Go through the header and get the properties used in the import
                                List <_projectPropertyMap> headerProperties = new List <_projectPropertyMap>();
                                foreach (var h in csv.HeaderRecord)
                                {
                                    var property = projectProperties.SingleOrDefault(p => h == p.Name);
                                    if (property != null)
                                    {
                                        property.optionsProperty = optionsProperties.SingleOrDefault(op => op.JsonPropertyName == property.JsonPropertyName);
                                        headerProperties.Add(property);
                                    }
                                }

                                // Read in the project records
                                while (await csv.ReadAsync())
                                {
                                    var project = new ProjectUpdateModel();
                                    foreach (var property in headerProperties)
                                    {
                                        MapProperty(csv, project, property);
                                    }
                                    projects.Add(project);
                                }
                            }
                        }
                    }
            }
            return(projects);
        }