protected List <PresetItem> GetUserStatesWithUniqueDisplayNames(UserStateAttributeValueToken target) { var allUserState = _context.GetUserStates().Select(x => new UserStateSearchItem(x)).ToList(); var suggestibleUserStates = GetValidUserStatesList(target); var userStatesWithUniqueDisplayNames = GetObjectsWithUniqueNames(allUserState, x => x.State.Title, x => x.State.Name); var resultUserStates = userStatesWithUniqueDisplayNames.Where(x => !string.IsNullOrEmpty(x.Key)) .Select(x => { var suggestibleUserState = suggestibleUserStates.FirstOrDefault(ss => ss.State.Name.Equals(x.Value.State.Name, StringComparison.OrdinalIgnoreCase)); var presetItem = new PresetItem( id: x.Value.State.Id.ToString(), displayValue: x.Key, hint: x.Value.State.IsDeleted ? "Deleted state" : null, isVisible: suggestibleUserState != null, isDeleted: x.Value.State.IsDeleted) { Tooltip = suggestibleUserState?.Tooltip }; return(presetItem); }) .ToList(); return(resultUserStates); }
protected List <PresetItem> GetValidAttributesList(AttributeNameTokenBase target) { var specifiedTypesNames = target.Context[nameof(TypeArgumentToken)].Value as List <string> ?? new List <string>(); specifiedTypesNames = specifiedTypesNames.Where(x => !string.IsNullOrEmpty(x)).ToList(); var types = GetSearchBrowsableTypes() .OrderBy(x => x.IsDeleted) .ThenBy(x => x.Sort) .Where(x => IsUserType(x) && (!specifiedTypesNames.Any() || specifiedTypesNames.Contains(x.Id.ToString()))) .ToList(); var complimentaryTypes = GetComplimentaryAttrTypes(target); var validAttributesList = BuildItemsIntersection( sourceElements: types, intersect: specifiedTypesNames.Count > 1, buildItemsForElement: type => { var currentTypePresetItems = new Dictionary <string, PresetItem>(); var typeAttrs = type.Attributes.Where(x => complimentaryTypes.Contains(x.Type)).OrderBy(x => x.DisplaySortOrder); foreach (var nAttribute in typeAttrs) { var key = $"{nAttribute.Name}\\{nAttribute.Title}\\{AttrTypeToString(nAttribute.Type)}"; var hint = AttrTypeToString(nAttribute.Type); var tooltip = specifiedTypesNames.Count == 1 ? null : GetTooltipEntryForType(type); var presetItem = new PresetItem(nAttribute.Title, nAttribute.Title, nAttribute.Name, hint, true, type.IsDeleted) { Tooltip = tooltip != null ? $"Belongs to following types: {tooltip}" : null, Sort = nAttribute.DisplaySortOrder + type.Sort * 100 + (type.IsDeleted ? 10000 : 0) }; currentTypePresetItems.Add(key, presetItem); } return(currentTypePresetItems); }, onItemDuplicated: (presetItem, type) => { presetItem.Tooltip += GetTooltipEntryForType(type); }); return(validAttributesList); }