-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
256 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.IO; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
|
||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
using Witsml.ServiceReference; | ||
|
||
using WitsmlExplorer.Api.Extensions; | ||
using WitsmlExplorer.Api.Models; | ||
using WitsmlExplorer.Api.Services; | ||
|
||
namespace WitsmlExplorer.Api.HttpHandlers | ||
{ | ||
public static class WitsmlQueryHandler | ||
{ | ||
|
||
[Produces(typeof(string))] | ||
public static async Task<IResult> PostQuery(IWitsmlClientProvider witsmlClientProvider, HttpRequest httpRequest) | ||
{ | ||
try | ||
{ | ||
WitsmlQuery query = await httpRequest.Body.Deserialize<WitsmlQuery>(); | ||
// file deepcode ignore XmlInjection: the body is only used to retrieve the query type that is sent further to the WITSML server | ||
string result = await witsmlClientProvider.GetClient().GetFromStoreAsync(query.Body, new OptionsIn(query.ReturnElements)); | ||
return TypedResults.Ok(result); | ||
} | ||
catch (Exception e) | ||
{ | ||
return TypedResults.Ok(e.Message); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
using Witsml.ServiceReference; | ||
|
||
namespace WitsmlExplorer.Api.Models | ||
{ | ||
public class WitsmlQuery | ||
{ | ||
[JsonConverter(typeof(JsonStringEnumConverter))] | ||
public ReturnElements ReturnElements { get; init; } | ||
public string Body { get; init; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
Src/WitsmlExplorer.Frontend/components/ContentViews/QueryView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { Button, TextField } from "@equinor/eds-core-react"; | ||
import React, { useContext, useState } from "react"; | ||
import styled from "styled-components"; | ||
import OperationContext from "../../contexts/operationContext"; | ||
import QueryService from "../../services/queryService"; | ||
import { Colors } from "../../styles/Colors"; | ||
import { StyledNativeSelect } from "../Select"; | ||
|
||
export enum ReturnElements { | ||
All = "all", | ||
IdOnly = "idOnly", | ||
HeaderOnly = "headerOnly", | ||
DataOnly = "dataOnly", | ||
StationLocationOnly = "stationLocationOnly", | ||
LatestChangeOnly = "latestChangeOnly", | ||
Requested = "requested" | ||
} | ||
|
||
const QueryView = (): React.ReactElement => { | ||
const { | ||
operationState: { colors } | ||
} = useContext(OperationContext); | ||
const [query, setQuery] = useState(""); | ||
const [result, setResult] = useState(""); | ||
const [isLoading, setIsLoading] = useState(false); | ||
const [returnElements, setReturnElements] = useState(ReturnElements.All); | ||
|
||
const onChangeReturnElements = (event: any) => { | ||
setReturnElements(event.target.value); | ||
}; | ||
|
||
const sendQuery = () => { | ||
const getResult = async () => { | ||
setIsLoading(true); | ||
let response = await QueryService.postQuery(query, returnElements); | ||
if (response.startsWith("<")) { | ||
//https://stackoverflow.com/questions/376373/pretty-printing-xml-with-javascript | ||
const xmlDoc = new DOMParser().parseFromString(response, "application/xml"); | ||
const xsltDoc = new DOMParser().parseFromString( | ||
[ | ||
'<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">', | ||
' <xsl:strip-space elements="*"/>', | ||
' <xsl:template match="para[content-style][not(text())]">', | ||
' <xsl:value-of select="normalize-space(.)"/>', | ||
" </xsl:template>", | ||
' <xsl:template match="node()|@*">', | ||
' <xsl:copy><xsl:apply-templates select="node()|@*"/></xsl:copy>', | ||
" </xsl:template>", | ||
' <xsl:output indent="yes"/>', | ||
"</xsl:stylesheet>" | ||
].join("\n"), | ||
"application/xml" | ||
); | ||
|
||
const xsltProcessor = new XSLTProcessor(); | ||
xsltProcessor.importStylesheet(xsltDoc); | ||
const resultDoc = xsltProcessor.transformToDocument(xmlDoc); | ||
response = new XMLSerializer().serializeToString(resultDoc); | ||
} | ||
|
||
setResult(response); | ||
setIsLoading(false); | ||
}; | ||
getResult(); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: "1rem", height: "100%", padding: "1rem" }}> | ||
<div style={{ display: "grid", gridTemplateRows: "1fr auto", gap: "1rem", height: "100%" }}> | ||
<StyledTextField id="input" multiline colors={colors} onChange={(e: any) => setQuery(e.target.value)} /> | ||
<div style={{ display: "flex", alignItems: "flex-end", gap: "1rem" }}> | ||
<StyledNativeSelect label="Return elements" id="return-elements" onChange={onChangeReturnElements} defaultValue={ReturnElements.All} colors={colors}> | ||
{Object.values(ReturnElements).map((value) => { | ||
return ( | ||
<option key={value} value={value}> | ||
{value} | ||
</option> | ||
); | ||
})} | ||
</StyledNativeSelect> | ||
<Button onClick={sendQuery} disabled={isLoading}> | ||
Execute | ||
</Button> | ||
</div> | ||
</div> | ||
<div> | ||
<StyledTextField id="output" multiline colors={colors} readOnly value={result} /> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}; | ||
const StyledTextField = styled(TextField)<{ colors: Colors }>` | ||
${(props) => `border: 1px solid ${props.colors.interactive.tableBorder};`} | ||
height: 100%; | ||
&&& > div { | ||
${(props) => `background-color: ${props.colors.ui.backgroundLight};`} | ||
height: 100% !important; | ||
border: 0; | ||
box-shadow: none; | ||
} | ||
div > textarea { | ||
height: 100%; | ||
overflow: scroll; | ||
text-wrap: nowrap; | ||
line-height: 15px; | ||
font-size: 13px; | ||
font-family: monospace; | ||
} | ||
div > div { | ||
display: none; /* disable input adornment */ | ||
} | ||
`; | ||
|
||
export default QueryView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { NativeSelect } from "@equinor/eds-core-react"; | ||
import styled from "styled-components"; | ||
import { Colors } from "../styles/Colors"; | ||
|
||
export const StyledNativeSelect = styled(NativeSelect)<{ colors: Colors }>` | ||
select { | ||
background: ${(props) => props.colors.text.staticTextFeildDefault}; | ||
color: ${(props) => props.colors.text.staticIconsDefault}; | ||
option { | ||
background: ${(props) => props.colors.ui.backgroundLight}; | ||
color: ${(props) => props.colors.text.staticIconsDefault}; | ||
} | ||
} | ||
label { | ||
color: ${(props) => props.colors.text.staticIconsDefault}; | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.