mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Adding filtering for group by schema (#2059)
This commit is contained in:
@@ -142,7 +142,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Contracts
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The name of the filter property
|
/// The name of the filter property
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string DisplayName { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The operator of the filter property
|
/// The operator of the filter property
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
|||||||
{
|
{
|
||||||
foreach (var f in appliedFilters)
|
foreach (var f in appliedFilters)
|
||||||
{
|
{
|
||||||
NodeFilterProperty filterProperty = filterDefinitions.FirstOrDefault(x => x.DisplayName == f.DisplayName);
|
NodeFilterProperty filterProperty = filterDefinitions.FirstOrDefault(x => x.Name == f.Name);
|
||||||
filters.Add(ObjectExplorerUtils.ConvertExpandNodeFilterToNodeFilter(f, filterProperty));
|
filters.Add(ObjectExplorerUtils.ConvertExpandNodeFilterToNodeFilter(f, filterProperty));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,26 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
|||||||
NodeValue = string.Empty;
|
NodeValue = string.Empty;
|
||||||
this.NodeType = "Database";
|
this.NodeType = "Database";
|
||||||
this.NodeTypeId = NodeTypes.Database;
|
this.NodeTypeId = NodeTypes.Database;
|
||||||
|
if(WorkspaceService<SqlToolsSettings>.Instance.CurrentSettings.SqlTools.ObjectExplorer.GroupBySchema)
|
||||||
|
{
|
||||||
|
this.FilterProperties = new NodeFilterProperty[]
|
||||||
|
{
|
||||||
|
new NodeFilterProperty
|
||||||
|
{
|
||||||
|
Name = "Name",
|
||||||
|
DisplayName = SR.FilterName,
|
||||||
|
Type = NodeFilterPropertyDataType.String,
|
||||||
|
Description = SR.FilterNameDescription,
|
||||||
|
},
|
||||||
|
new NodeFilterProperty
|
||||||
|
{
|
||||||
|
Name = "Owner",
|
||||||
|
DisplayName = SR.FilterOwner,
|
||||||
|
Type = NodeFilterPropertyDataType.String,
|
||||||
|
Description = SR.FilterOwnerDescription,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
OnInitialize();
|
OnInitialize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,6 +86,69 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
|||||||
WriteLine(" NodeValue = string.Empty;");
|
WriteLine(" NodeValue = string.Empty;");
|
||||||
WriteLine(" this.NodeType = \"{0}\";", type.Replace("TreeNode", string.Empty));
|
WriteLine(" this.NodeType = \"{0}\";", type.Replace("TreeNode", string.Empty));
|
||||||
WriteLine(" this.NodeTypeId = NodeTypes.{0};", name.Replace("TreeNode", string.Empty));
|
WriteLine(" this.NodeTypeId = NodeTypes.{0};", name.Replace("TreeNode", string.Empty));
|
||||||
|
List<XmlElement> filterProperties = GetFilterProperties(xmlFile, type.Replace("TreeNode", string.Empty));
|
||||||
|
string settingsFlag = GetFilterSettingsFlag(xmlFile, type.Replace("TreeNode", string.Empty));
|
||||||
|
if(!String.IsNullOrEmpty(settingsFlag))
|
||||||
|
{
|
||||||
|
WriteLine(" if({0})", GetSettingsString(settingsFlag));
|
||||||
|
WriteLine(" {");
|
||||||
|
}
|
||||||
|
if(filterProperties.Count > 0){
|
||||||
|
WriteLine(" this.FilterProperties = new NodeFilterProperty[]");
|
||||||
|
WriteLine(" {");
|
||||||
|
foreach (var filterDef in filterProperties)
|
||||||
|
{
|
||||||
|
var filterName = filterDef.GetAttribute("Name");
|
||||||
|
var filterDisplayName = filterDef.GetAttribute("LocLabel");
|
||||||
|
var filterType = filterDef.GetAttribute("Type");
|
||||||
|
var enumString = "NodeFilterPropertyDataType";
|
||||||
|
switch (filterType)
|
||||||
|
{
|
||||||
|
case "string":
|
||||||
|
enumString += ".String";
|
||||||
|
break;
|
||||||
|
case "bool":
|
||||||
|
enumString += ".Boolean";
|
||||||
|
break;
|
||||||
|
case "date":
|
||||||
|
enumString += ".Date";
|
||||||
|
break;
|
||||||
|
case "choice":
|
||||||
|
enumString += ".Choice";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
var filterDescription = filterDef.GetAttribute("Description");
|
||||||
|
WriteLine(" new NodeFilterProperty");
|
||||||
|
WriteLine(" {");
|
||||||
|
WriteLine(" Name = \"{0}\",", filterName);
|
||||||
|
WriteLine(" DisplayName = {0},", filterDisplayName);
|
||||||
|
WriteLine(" Type = {0},", enumString);
|
||||||
|
WriteLine(" Description = {0},", filterDescription);
|
||||||
|
if(filterType == "choice")
|
||||||
|
{
|
||||||
|
var choiceValues = filterDef.ChildNodes;
|
||||||
|
WriteLine(" Choices = new NodeFilterPropertyChoice[] {");
|
||||||
|
foreach (XmlElement choice in choiceValues)
|
||||||
|
{
|
||||||
|
var choiceName = choice.GetAttribute("LocLabel");
|
||||||
|
var choiceValue = choice.GetAttribute("Value");
|
||||||
|
WriteLine(" new NodeFilterPropertyChoice {");
|
||||||
|
WriteLine(" DisplayName = {0},", choiceName);
|
||||||
|
WriteLine(" Value = \"{0}\",", choiceValue);
|
||||||
|
WriteLine(" },");
|
||||||
|
|
||||||
|
}
|
||||||
|
WriteLine(" }");
|
||||||
|
}
|
||||||
|
WriteLine(" },");
|
||||||
|
|
||||||
|
}
|
||||||
|
WriteLine(" };");
|
||||||
|
}
|
||||||
|
if(!String.IsNullOrEmpty(settingsFlag))
|
||||||
|
{
|
||||||
|
WriteLine(" }");
|
||||||
|
}
|
||||||
WriteLine(" OnInitialize();");
|
WriteLine(" OnInitialize();");
|
||||||
WriteLine(" }");
|
WriteLine(" }");
|
||||||
WriteLine(" }");
|
WriteLine(" }");
|
||||||
@@ -636,6 +699,18 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
|||||||
return retElements;
|
return retElements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetFilterSettingsFlag(string xmlFile, string nodeType)
|
||||||
|
{
|
||||||
|
XmlDocument doc = new XmlDocument();
|
||||||
|
doc.Load(xmlFile);
|
||||||
|
XmlNodeList nodeList = doc.SelectNodes(string.Format("/ServerExplorerTree/FilterProperties[@NodeName='{0}']", nodeType));
|
||||||
|
if(nodeList.Count > 0)
|
||||||
|
{
|
||||||
|
return (nodeList[0] as XmlElement).Attributes["SettingsFlag"].Value;
|
||||||
|
}
|
||||||
|
return String.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static List<XmlElement> GetFilterProperties(string xmlFile, string nodeType)
|
public static List<XmlElement> GetFilterProperties(string xmlFile, string nodeType)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -661,6 +661,11 @@
|
|||||||
<Property>InPrimaryKey</Property>
|
<Property>InPrimaryKey</Property>
|
||||||
</FilterProperties>
|
</FilterProperties>
|
||||||
|
|
||||||
|
<FilterProperties NodeName="Database" SettingsFlag="GroupBySchema">
|
||||||
|
<Property>Name</Property>
|
||||||
|
<Property>Owner</Property>
|
||||||
|
</FilterProperties>
|
||||||
|
|
||||||
|
|
||||||
<FilterProperty Name="Name" LocLabel="SR.FilterName" Type="string" Description="SR.FilterNameDescription"/>
|
<FilterProperty Name="Name" LocLabel="SR.FilterName" Type="string" Description="SR.FilterNameDescription"/>
|
||||||
<FilterProperty Name="Schema" LocLabel="SR.FilterSchema" Type="string" Description="SR.FilterSchemaDescription"/>
|
<FilterProperty Name="Schema" LocLabel="SR.FilterSchema" Type="string" Description="SR.FilterSchemaDescription"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user