diff --git a/Core.Tests/Parsers/LeafInputCsvParserTests.cs b/Core.Tests/Parsers/LeafInputCsvParserTests.cs index 5b30bf5..284aecb 100644 --- a/Core.Tests/Parsers/LeafInputCsvParserTests.cs +++ b/Core.Tests/Parsers/LeafInputCsvParserTests.cs @@ -140,8 +140,9 @@ namespace LeafWeb.Core.Tests.Parsers public void Parse_FindIssues() { var dir = @"C:\Users\poprhythm\Documents\code\LeafWeb\Notes\leafweb database work\newcurves\RemovableDisk\curves"; - var files = Directory.GetFiles(dir, "*.csv").Select(f => new FileInfo(f)); + var files = Directory.GetFiles(dir, "*.csv").Select(f => new FileInfo(f)).ToList(); var leafInputs = new List(); + var num = 1; foreach (var file in files) { try @@ -149,10 +150,11 @@ namespace LeafWeb.Core.Tests.Parsers var parser = new LeafInputCsvParser(file); var leafInput = parser.Parse(); leafInputs.Add(leafInput); - //Console.WriteLine("{0}, {1}, {2}", leafInput.FileName, leafInput.InvestigatorName, leafInput.ContactInformation); + Console.WriteLine("{3}/{4}, {0}, {1}, {2}", leafInput.FileName, leafInput.InvestigatorName, leafInput.ContactInformation, num++, files.Count); } catch (Exception ex) { + File.AppendAllLines(@"C:\Temp\errors.txt", new[] { string.Format("{1} : {0}", ex.Message, file.Name) }); Console.WriteLine("{1} : {0}", ex.Message, file.Name); } } diff --git a/Core/Models/CntrlComparison.cs b/Core/Models/CntrlComparison.cs index 09c363f..e41a538 100644 --- a/Core/Models/CntrlComparison.cs +++ b/Core/Models/CntrlComparison.cs @@ -4,6 +4,7 @@ using System.Linq; namespace LeafWeb.Core.Models { /// + /// Part of LeafOutput /// The file 'cntrlcomparison.csv', which is in comma-separated-value format, contains outputs from PISCAL that /// facilitates examination of how well the fitting is. /// diff --git a/Core/Parsers/CsvParserBase.cs b/Core/Parsers/CsvParserBase.cs index a71f428..53ca7c0 100644 --- a/Core/Parsers/CsvParserBase.cs +++ b/Core/Parsers/CsvParserBase.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.IO; using CsvHelper; using CsvHelper.Configuration; diff --git a/Core/Utility/StringExtensions.cs b/Core/Utility/StringExtensions.cs index 2a8b942..fe892eb 100644 --- a/Core/Utility/StringExtensions.cs +++ b/Core/Utility/StringExtensions.cs @@ -1,4 +1,5 @@ -using System.Globalization; +using System; +using System.Globalization; using System.Linq; namespace LeafWeb.Core.Utility @@ -12,5 +13,16 @@ namespace LeafWeb.Core.Utility (current, c) => current + (char.IsUpper(c) && current.Length > 0 ? " " + c : c.ToString(CultureInfo.InvariantCulture))); } + + public static string LowercaseFirst(string s) + { + // Check for empty string. + if (string.IsNullOrEmpty(s)) + { + return string.Empty; + } + // Return char and concat substring. + return char.ToLowerInvariant(s[0]) + s.Substring(1); + } } } diff --git a/Web/Controllers/LeafInputController.cs b/Web/Controllers/LeafInputController.cs new file mode 100644 index 0000000..6fb134d --- /dev/null +++ b/Web/Controllers/LeafInputController.cs @@ -0,0 +1,19 @@ +using System.Web.Mvc; +using LeafWeb.Web.ViewModels.LeafInput; + +namespace LeafWeb.Web.Controllers +{ + public class LeafInputController : Controller + { + public ActionResult Index() + { + return View(); + } + + [HttpPost] + public ActionResult Index(CreateViewModel viewModel) + { + return View(); + } + } +} \ No newline at end of file diff --git a/Web/ViewModels/LeafInput/CreateViewModel.cs b/Web/ViewModels/LeafInput/CreateViewModel.cs new file mode 100644 index 0000000..719c865 --- /dev/null +++ b/Web/ViewModels/LeafInput/CreateViewModel.cs @@ -0,0 +1,30 @@ +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Web; + +namespace LeafWeb.Web.ViewModels.LeafInput +{ + public class CreateViewModel + { + [Required] + [Display(Name = "Your name")] + public string Name { get; set; } + + [Required] + [Display(Name = "Your email address")] + public string Email { get; set; } + + [Required] + [Display(Name = "A unique identifier for this data")] + public string LeafInputId { get; set; } + + [Required] + [Display(Name = "The site's name/Fluxnet ID, if known")] + public string SiteID { get; set; } + + [Required] + [UIHint("HttpPostedFileBase")] + public HttpPostedFileBase Files { get; set; } + } +} \ No newline at end of file diff --git a/Web/Views/LeafInput/Index.cshtml b/Web/Views/LeafInput/Index.cshtml new file mode 100644 index 0000000..90e94f3 --- /dev/null +++ b/Web/Views/LeafInput/Index.cshtml @@ -0,0 +1,17 @@ +@model LeafWeb.Web.ViewModels.LeafInput.CreateViewModel + +

Submitting Data and Retrieving EDO Results

+

+ There is no limit on the number of files you may submit for analysis. Keep selecting files and hitting the Add button until all of the files you need to upload are shown in the list. Then enter an identifier for this set of data and click the Upload button. +

+@using (Html.BeginForm("Index", "LeafInput", FormMethod.Post, new { @class = "form-horizontal well" })) +{ + @Html.Partial("_ValidationSummary") +
+ + @Html.EditorForModel() +
+ +
+
+} diff --git a/Web/Views/Shared/EditorTemplates/HttpPostedFileBase.cshtml b/Web/Views/Shared/EditorTemplates/HttpPostedFileBase.cshtml new file mode 100644 index 0000000..847c40d --- /dev/null +++ b/Web/Views/Shared/EditorTemplates/HttpPostedFileBase.cshtml @@ -0,0 +1,5 @@ +@model HttpPostedFileBase +@{ + Layout = "~/Views/Shared/EditorTemplates/_FieldLayout.cshtml"; +} + \ No newline at end of file diff --git a/Web/Views/Shared/EditorTemplates/String.cshtml b/Web/Views/Shared/EditorTemplates/String.cshtml new file mode 100644 index 0000000..fb44cf9 --- /dev/null +++ b/Web/Views/Shared/EditorTemplates/String.cshtml @@ -0,0 +1,5 @@ +@{ + Layout = "~/Views/Shared/EditorTemplates/_FieldLayout.cshtml"; +} + +@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue) diff --git a/Web/Views/Shared/EditorTemplates/_FieldLayout.cshtml b/Web/Views/Shared/EditorTemplates/_FieldLayout.cshtml new file mode 100644 index 0000000..c129753 --- /dev/null +++ b/Web/Views/Shared/EditorTemplates/_FieldLayout.cshtml @@ -0,0 +1,41 @@ +@{ + Layout = null; + var lowerPropertyName = @LeafWeb.Core.Utility.StringExtensions.LowercaseFirst(ViewData.ModelMetadata.PropertyName); + var values = ViewData.ModelMetadata.AdditionalValues; + var units = values.ContainsKey("Units") ? (string)values["Units"] : null; + var currency = values.ContainsKey("Currency") ? (string)values["Currency"] : null; + var formatHint = values.ContainsKey("FormatHint") ? (string)values["FormatHint"] : null; + var editLabel = values.ContainsKey("EditLabel") ? (bool)values["EditLabel"] : true; +} +@RenderBody() +@*
+ @if (editLabel) + { + @Html.LabelForModel() + } +
+ @if (!string.IsNullOrEmpty(units)) + { +
+ @RenderBody() + @units +
+ } + else if (!string.IsNullOrEmpty(currency)) + { +
+ @currency + @RenderBody() +
+ } + else + { + @RenderBody() + } + @if (!string.IsNullOrEmpty(formatHint)) + { +
@formatHint
+ } + @Html.ValidationMessage("") +
+
*@ diff --git a/Web/Views/Shared/_Layout.cshtml b/Web/Views/Shared/_Layout.cshtml index 1a21dfc..b6aa8d8 100644 --- a/Web/Views/Shared/_Layout.cshtml +++ b/Web/Views/Shared/_Layout.cshtml @@ -30,9 +30,9 @@