This commit is contained in:
Hananiel Sarella 2019-12-11 16:36:57 -05:00
Родитель e7bfd31b2f
Коммит 8d3673a929
5 изменённых файлов: 69 добавлений и 41 удалений

Просмотреть файл

@ -10,25 +10,29 @@ import ReactGA from 'react-ga';
export class Home extends Component { export class Home extends Component {
static displayName = Home.name; static displayName = Home.name;
static initialState = {
showMore: false,
templateType: ".NET Templates",
level2SelectorType: "net",
lang: "C#",
steeltoeVersion: "2.4.0",
steeltoeVersionInvalid: "",
targetFrameworkVersion: "netcoreapp2.2"
};
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = Home.initialState;
showMore: false,
templateType: ".NET Templates",
level2SelectorType: "net",
lang: "C#",
steeltoeVersion: "2.4.0",
targetFrameworkVersion: "netcoreapp2.2"
}
this.toggleMore = this.toggleMore.bind(this); this.toggleMore = this.toggleMore.bind(this);
this.handleInputChange = this.handleInputChange.bind(this); this.handleInputChange = this.handleInputChange.bind(this);
this.trackSubmitEvent = this.trackSubmitEvent.bind(this); this.OnSubmit = this.OnSubmit.bind(this);
} }
OnSubmit(e){
this.setState(Home.initialState);
this.trackSubmitEvent(e);
}
trackSubmitEvent(e) { trackSubmitEvent(e) {
let i; let i;
const elements = e.target.elements; const elements = e.target.elements;
@ -68,16 +72,27 @@ export class Home extends Component {
//if (name === "templateType") { //if (name === "templateType") {
// this.setState({ level2SelectorType: selectedValue === ".NET Templates" ? "net" : "steeltoe"}) // this.setState({ level2SelectorType: selectedValue === ".NET Templates" ? "net" : "steeltoe"})
//} //}
if (name == "targetFrameworkVersion" && selectedValue == "netcoreapp3.1" && this.state.steeltoeVersion == "2.3.0") {
if (name === "targetFrameworkVersion" && selectedValue === "netcoreapp3.1" && this.state.steeltoeVersion === "2.3.0") {
this.setState({ this.setState({
"steeltoeVersion": "2.4.0", "steeltoeVersion": "2.4.0",
[name]: selectedValue [name]: selectedValue,
"steeltoeVersionInvalid": ""
})
}
else if(name === "steeltoeVersion" && selectedValue === "2.3.0" && this.state.targetFrameworkVersion === "netcoreapp3.1"){
this.setState({
"steeltoeVersion": "2.4.0",
"steeltoeVersionInvalid": "2.4.0 is the lowest version compatible with netcoreapp3.1",
}) })
} }
else { else {
this.setState({ [name]: selectedValue }); this.setState({
[name]: selectedValue,
"steeltoeVersionInvalid": ""
});
} }
console.log("parent setting hanglechange" , name, selectedValue) // console.log("parent setting hanglechange" , name, selectedValue)
} }
@ -86,10 +101,9 @@ export class Home extends Component {
return ( return (
<div> <div>
<form name="form" action="/starter.zip" method="post" autoComplete="off" onSubmit={this.trackSubmitEvent} > <form name="form" action="/starter.zip" method="post" autoComplete="off" onSubmit={this.OnSubmit} >
<div> <div>
<InputSelector id="steeltoeVersion" title="Steeltoe Version" name="steeltoeVersion" values={["2.3.0", "2.4.0"]} defaultValue="2.4.0" selectedValue={this.state.steeltoeVersion} onChange={this.handleInputChange} /> <InputSelector id="steeltoeVersion" title="Steeltoe Version" name="steeltoeVersion" values={["2.3.0", "2.4.0"]} defaultValue="2.4.0" selectedValue={this.state.steeltoeVersion} onChange={this.handleInputChange} invalidText={this.state.steeltoeVersionInvalid} />
<div className="line"> <div className="line">
<div className="left">Project Metadata</div> <div className="left">Project Metadata</div>
<div className="right"> <div className="right">

Просмотреть файл

@ -8,7 +8,7 @@ export class InputSelector extends Component {
} }
handleChange(e) { handleChange(e) {
this.props.onChange(this.props.name, e.target.attributes['data-value'].value) this.props.onChange(this.props.name, e.target.attributes['data-value'].value);
} }
@ -26,9 +26,11 @@ export class InputSelector extends Component {
</div> </div>
}) })
} }
<input type="hidden" name={this.props.name} value={this.props.selectedValue} /> <input type="hidden" name={this.props.name} value={this.props.selectedValue} />
</div> </div>
<span style={{display: this.props.invalidText? "block": "none" , "color": "red"}} > {this.props.invalidText} </span>
</div> </div>
</div> </div>
); );

Просмотреть файл

@ -1,19 +0,0 @@
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ActionConstraints;
using Microsoft.AspNetCore.Routing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Steeltoe.Initializr.Controllers
{
public class IsCurlRequestAttribute : ActionMethodSelectorAttribute
{
public override bool IsValidForRequest(RouteContext routeContext, ActionDescriptor action)
{
var headers = routeContext.HttpContext.Request.Headers;
return headers["User-Agent"].Any(h => h.ToLower().Contains("curl"));
}
}
}

Просмотреть файл

@ -51,8 +51,6 @@ namespace Steeltoe.Initializr.Controllers
[IsCurlRequest] [IsCurlRequest]
public ActionResult<string> CurlHelp() public ActionResult<string> CurlHelp()
{ {
// get dependencies
var result = new StringBuilder(); var result = new StringBuilder();
result.Append(LOGO); result.Append(LOGO);
result.Append(GetDependencies()); result.Append(GetDependencies());
@ -99,7 +97,7 @@ Get project:
private string GetRow(string title, string description, int[] fieldWidths) private string GetRow(string title, string description, int[] fieldWidths)
{ {
return string.Format("+ {0}+ {1}+\n", title.PadRight(fieldWidths[0] - 1), description.PadRight(fieldWidths[1] - 1)); return $"| {title.PadRight(fieldWidths[0] - 1)}| {description.PadRight(fieldWidths[1] - 1)}|\n";
} }
private string GetHorizontalBorder(int[] widths) private string GetHorizontalBorder(int[] widths)

Просмотреть файл

@ -0,0 +1,33 @@
// Copyright 2017 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ActionConstraints;
using Microsoft.AspNetCore.Routing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Steeltoe.Initializr.Controllers
{
public class IsCurlRequestAttribute : ActionMethodSelectorAttribute
{
public override bool IsValidForRequest(RouteContext routeContext, ActionDescriptor action)
{
var headers = routeContext.HttpContext.Request.Headers;
return headers["User-Agent"].Any(h => h.ToLower().Contains("curl"));
}
}
}