Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
fakefeik committed Jan 7, 2023
1 parent 027eeab commit d7e0cfe
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 20 deletions.
8 changes: 4 additions & 4 deletions DbViewer.TestApi/Controllers/DbViewerApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public DbViewerApiController(SchemaRegistryProvider schemaRegistryProvider)
[Route("{objectIdentifier}/count")]
public Task<CountResult> CountObjects(string objectIdentifier, [FromBody] ObjectSearchRequest query) => impl.CountObjects(objectIdentifier, query, IsSuperUser());

[HttpGet]
[Route("{objectIdentifier}/download/{queryString}")]
public async Task<IActionResult> DownloadObjects(string objectIdentifier, string queryString)
[HttpPost]
[Route("{objectIdentifier}/download")]
public async Task<IActionResult> DownloadObjects(string objectIdentifier, [FromForm] string data)
{
var fileInfo = await impl.DownloadObjects(objectIdentifier, queryString, IsSuperUser()).ConfigureAwait(false);
var fileInfo = await impl.DownloadObjects(objectIdentifier, data, IsSuperUser()).ConfigureAwait(false);
return File(fileInfo.Content, fileInfo.ContentType, fileInfo.Name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,7 @@ private static TypeScriptClassMemberDefinition BuildApiImplMember(IMethodInfo me
Result = GetMethodResult(methodInfo, buildAndImportType),
Body = {isUrlMethod ? GenerateGetUrlCall(methodInfo) : CreateCall(methodInfo)}
};
functionDefinition.Arguments.AddRange(
methodInfo.GetParameters().Select(x => new TypeScriptArgumentDeclaration
{
Name = x.Name,
Type = buildAndImportType(x.ParameterType)
})
);
functionDefinition.Arguments.AddRange(GetArguments(methodInfo, buildAndImportType));
return new TypeScriptClassMemberDefinition
{
Name = GetMethodName(methodInfo),
Expand Down Expand Up @@ -224,14 +218,21 @@ private static TypeScriptExpression GenerateConstructGetParams(IParameterInfo[]
private static TypeScriptInterfaceFunctionMember BuildApiInterfaceMember(IMethodInfo methodInfo, Func<ITypeInfo, TypeScriptType> buildAndImportType)
{
var result = new TypeScriptInterfaceFunctionMember(GetMethodName(methodInfo), GetMethodResult(methodInfo, buildAndImportType));
result.Arguments.AddRange(
methodInfo.GetParameters().Select(x => new TypeScriptArgumentDeclaration
{
Name = x.Name,
Type = buildAndImportType(x.ParameterType)
})
);
result.Arguments.AddRange(GetArguments(methodInfo, buildAndImportType));
return result;
}

private static TypeScriptArgumentDeclaration[] GetArguments(IMethodInfo methodInfo, Func<ITypeInfo, TypeScriptType> buildAndImportType)
{
var isUrlMethod = IsUrlMethod(methodInfo);
return methodInfo.GetParameters()
.Where(x => !isUrlMethod || !x.ParameterType.GetAttributes(TypeInfo.From<FromFormAttribute>()).Any())
.Select(x => new TypeScriptArgumentDeclaration
{
Name = x.Name,
Type = buildAndImportType(x.ParameterType)
})
.ToArray();
}
}
}
29 changes: 27 additions & 2 deletions db-viewer-ui/src/Containers/ObjectTableContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ColumnStack, Fit, RowStack } from "@skbkontur/react-stack-layout";
import { Link, Loader, Paging } from "@skbkontur/react-ui";
import { Button, Link, Loader, Paging } from "@skbkontur/react-ui";
import isEqual from "lodash/isEqual";
import qs from "qs";
import React from "react";
Expand Down Expand Up @@ -99,7 +99,7 @@ class ObjectTableContainerInternal extends React.Component<ObjectTableProps, Obj
loading,
objects,
metaInformation,
query: { offset, count, sorts },
query: { offset, count, sorts, conditions, hiddenColumns },
downloading,
showDownloadModal,
downloadCount,
Expand Down Expand Up @@ -139,6 +139,31 @@ class ObjectTableContainerInternal extends React.Component<ObjectTableProps, Obj
}
/>
<CommonLayout.Content>
{metaInformation && (
<form
method="post"
action={this.props.dbViewerApi.getDownloadObjectsUrl(
metaInformation.identifier,
JSON.stringify({
conditions: conditions,
sorts: sorts,
excludedFields: hiddenColumns,
})
)}>
<input
type="hidden"
name="data"
value={JSON.stringify({
conditions: conditions,
sorts: sorts,
excludedFields: hiddenColumns,
})}
/>
<Button use="link" type="submit">
Download
</Button>
</form>
)}
<Loader type="big" active={loading}>
<ColumnStack gap={4}>
<Fit>
Expand Down

0 comments on commit d7e0cfe

Please sign in to comment.