handle add column request (#1272)

* handle add column request

* comments

* rename data to ViewModel
This commit is contained in:
Alan Ren
2021-10-19 09:54:57 -07:00
committed by GitHub
parent 791c3594a9
commit 192f7fccd4
18 changed files with 310 additions and 83 deletions

View File

@@ -4,6 +4,7 @@
//
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.SqlTools.Hosting.Protocol;
using Microsoft.SqlTools.ServiceLayer.Hosting;
@@ -57,15 +58,15 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
{
try
{
// TODO
TableDataModel tableModel = new TableDataModel();
// TODO: populate the data and view information
TableViewModel tableModel = new TableViewModel();
TableDesignerView view = new TableDesignerView();
await requestContext.SendResult(new TableDesignerInfo()
{
Data = tableModel,
ViewModel = tableModel,
View = view,
ColumnTypes = new string[] { },
Schemas = new string[] { }
ColumnTypes = this.GetSupportedColumnTypes(tableInfo),
Schemas = this.GetSchemas(tableInfo)
});
}
catch (Exception e)
@@ -81,10 +82,21 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
{
try
{
// TODO
switch (requestParams.TableChangeInfo.Type)
{
case DesignerEditType.Add:
this.HandleAddItemRequest(requestParams);
break;
case DesignerEditType.Remove:
// TODO: Handle 'Remove' request
break;
default:
// TODO: Handle 'Update' request
break;
}
await requestContext.SendResult(new ProcessTableDesignerEditResponse()
{
Data = requestParams.Data,
ViewModel = requestParams.ViewModel,
IsValid = true
});
}
@@ -101,7 +113,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
{
try
{
// TODO
// TODO: Handle the save changes request.
await requestContext.SendResult(new SaveTableChangesResponse());
}
catch (Exception e)
@@ -111,6 +123,40 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
});
}
private void HandleAddItemRequest(ProcessTableDesignerEditRequestParams requestParams)
{
var property = requestParams.TableChangeInfo.Property;
// Handle the add item request on top level table properties, e.g. Columns, Indexes.
if (property.GetType() == typeof(string))
{
string propertyName = property as string;
switch (propertyName)
{
case TablePropertyNames.Columns:
requestParams.ViewModel.Columns.AddNew();
break;
default:
break;
}
} else {
// TODO: Handle the add item request on second level properties, e.g. Adding a column to an index
}
}
private List<string> GetSupportedColumnTypes(TableInfo tableInfo)
{
//TODO: get the supported column types.
var columnTypes = new List<string>();
return columnTypes;
}
private List<string> GetSchemas(TableInfo tableInfo)
{
//TODO: get the schemas.
var schemas = new List<string>();
return schemas;
}
/// <summary>
/// Disposes the table designer Service
/// </summary>