Add Photosynthesis Type
This commit is contained in:
@@ -60,5 +60,15 @@ namespace LeafWeb.Core.DAL
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
public IQueryable<PhotosynthesisType> GetPhotosynthesisTypes()
|
||||||
|
{
|
||||||
|
return _db.PhotosynthesisTypes.OrderBy(pt => pt.SortOrder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PhotosynthesisType GetPhotosynthesisType(string id)
|
||||||
|
{
|
||||||
|
return _db.PhotosynthesisTypes.Find(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ namespace LeafWeb.Core.DAL
|
|||||||
|
|
||||||
var photosynthesisTypes = new []
|
var photosynthesisTypes = new []
|
||||||
{
|
{
|
||||||
new PhotosynthesisType {Id = "C3_photosynthesis_leafweb", Name = "C3 Photosynthesis"},
|
new PhotosynthesisType {Id = "C3_photosynthesis_leafweb", Name = "C3 Photosynthesis", SortOrder = 1},
|
||||||
new PhotosynthesisType {Id = "C4_photosynthesis_leafweb", Name = "C4 Photosynthesis"},
|
new PhotosynthesisType {Id = "C4_photosynthesis_leafweb", Name = "C4 Photosynthesis", SortOrder = 2},
|
||||||
new PhotosynthesisType {Id = "CAM_photosynthesis_leafweb", Name = "CAM Photosynthesis"}
|
new PhotosynthesisType {Id = "CAM_photosynthesis_leafweb", Name = "CAM Photosynthesis", SortOrder = 3}
|
||||||
};
|
};
|
||||||
|
|
||||||
context.PhotosynthesisTypes.AddRange(photosynthesisTypes);
|
context.PhotosynthesisTypes.AddRange(photosynthesisTypes);
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ namespace LeafWeb.Core.Models
|
|||||||
[Required(ErrorMessage = "")]
|
[Required(ErrorMessage = "")]
|
||||||
public string SiteId { get; set; }
|
public string SiteId { get; set; }
|
||||||
|
|
||||||
public virtual PhotosynthesisType Photosynthesis { get; set; }
|
[Required(ErrorMessage = "PhotosynthesisType required")]
|
||||||
|
public virtual PhotosynthesisType PhotosynthesisType { get; set; }
|
||||||
|
|
||||||
[DataType(DataType.Date)]
|
[DataType(DataType.Date)]
|
||||||
[Required]
|
[Required]
|
||||||
|
|||||||
@@ -10,5 +10,7 @@ namespace LeafWeb.Core.Models
|
|||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public int SortOrder { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,5 +44,10 @@ namespace LeafWeb.Web.Controllers
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected SelectList GetPhotosynthesisTypeSelectList()
|
||||||
|
{
|
||||||
|
return new SelectList(DataService.GetPhotosynthesisTypes().ToList(), "Id", "Name");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@ using System.Web;
|
|||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using LeafWeb.Core.Models;
|
using LeafWeb.Core.Models;
|
||||||
using LeafWeb.Web.Attributes;
|
using LeafWeb.Web.Attributes;
|
||||||
|
using LeafWeb.Web.ViewModels;
|
||||||
using LeafWeb.Web.ViewModels.LeafInput;
|
using LeafWeb.Web.ViewModels.LeafInput;
|
||||||
|
|
||||||
namespace LeafWeb.Web.Controllers
|
namespace LeafWeb.Web.Controllers
|
||||||
@@ -15,7 +16,79 @@ namespace LeafWeb.Web.Controllers
|
|||||||
{
|
{
|
||||||
// initialize the session storage to retain SessionID between requests
|
// initialize the session storage to retain SessionID between requests
|
||||||
Session["placeholder"] = 0;
|
Session["placeholder"] = 0;
|
||||||
return View();
|
var viewModel = new CreateViewModel();
|
||||||
|
HydrateCreateViewModel(viewModel);
|
||||||
|
return View(viewModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpParamAction]
|
||||||
|
[HttpPost]
|
||||||
|
public ActionResult Index(CreateViewModel viewModel)
|
||||||
|
{
|
||||||
|
// directory name is the sessionID
|
||||||
|
var files = GetBackloadDirectoryFiles(Session.SessionID);
|
||||||
|
|
||||||
|
if (!files.Any())
|
||||||
|
ModelState.AddModelError("Files", "Must select at least one file");
|
||||||
|
|
||||||
|
if (ModelState.IsValid && !IsHttpParamActionMatch()) // HttpParamMatch indicates it's backing out from Confirm
|
||||||
|
{
|
||||||
|
// Go to confirmation
|
||||||
|
var confirmViewModel = new ConfirmViewModel(viewModel, files.Select(f => f.Name).ToArray());
|
||||||
|
HydrateCreateViewModel(confirmViewModel);
|
||||||
|
|
||||||
|
return View("Confirm", confirmViewModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
HydrateCreateViewModel(viewModel);
|
||||||
|
return View("Index", viewModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HydrateCreateViewModel(dynamic viewModel)
|
||||||
|
{
|
||||||
|
if (viewModel.PhotosynthesisType == null)
|
||||||
|
viewModel.PhotosynthesisType = new SelectListViewModel();
|
||||||
|
if (viewModel.PhotosynthesisType.ListItems == null)
|
||||||
|
viewModel.PhotosynthesisType.ListItems = GetPhotosynthesisTypeSelectList();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpParamAction]
|
||||||
|
[HttpPost]
|
||||||
|
public ActionResult Confirm(CreateViewModel viewModel)
|
||||||
|
{
|
||||||
|
// directory name is the sessionID
|
||||||
|
var files = GetBackloadDirectoryFiles(Session.SessionID);
|
||||||
|
|
||||||
|
if (!files.Any())
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("Files", "Must select at least one file");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ModelState.IsValid)
|
||||||
|
{
|
||||||
|
// convert viewModel into Model
|
||||||
|
var leafInput = viewModel.GetFileInput(DataService);
|
||||||
|
// load files into LeafInputFile
|
||||||
|
leafInput.LeafInputFiles =
|
||||||
|
(from f in files
|
||||||
|
let bytes = System.IO.File.ReadAllBytes(f.FullName)
|
||||||
|
select new LeafInputFile {Filename = f.Name, Contents = bytes}).ToList();
|
||||||
|
|
||||||
|
// Save to db
|
||||||
|
DataService.AddLeafInput(leafInput);
|
||||||
|
|
||||||
|
DeleteBackloadDirectory(Session.SessionID);
|
||||||
|
|
||||||
|
SetStatusMessage(
|
||||||
|
HttpUtility.HtmlEncode(
|
||||||
|
$"A data set has submitted for '{viewModel.Identifier}' from '{viewModel.SiteId}'. " + Environment.NewLine
|
||||||
|
+ $"When complete, an email will be delivered to {viewModel.Name} <{viewModel.Email}> with results."),
|
||||||
|
StatusType.Success);
|
||||||
|
return RedirectToAction("Index");
|
||||||
|
}
|
||||||
|
|
||||||
|
HydrateCreateViewModel(viewModel);
|
||||||
|
return View("Index", viewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private FileInfo[] GetBackloadDirectoryFiles(string directoryName)
|
private FileInfo[] GetBackloadDirectoryFiles(string directoryName)
|
||||||
@@ -35,61 +108,5 @@ namespace LeafWeb.Web.Controllers
|
|||||||
if (directory.Exists)
|
if (directory.Exists)
|
||||||
directory.Delete(true);
|
directory.Delete(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpParamAction]
|
|
||||||
[HttpPost]
|
|
||||||
public ActionResult Index(CreateViewModel viewModel)
|
|
||||||
{
|
|
||||||
// directory name is the sessionID
|
|
||||||
var files = GetBackloadDirectoryFiles(Session.SessionID);
|
|
||||||
|
|
||||||
if (!files.Any())
|
|
||||||
ModelState.AddModelError("Files", "Must select at least one file");
|
|
||||||
|
|
||||||
if (ModelState.IsValid && !IsHttpParamActionMatch()) // HttpParamMatch indicates it's backing out from Confirm
|
|
||||||
{
|
|
||||||
// Go to confirmation
|
|
||||||
var confirmViewModel = new ConfirmViewModel(viewModel, files.Select(f => f.Name).ToArray());
|
|
||||||
return View("Confirm", confirmViewModel);
|
|
||||||
}
|
|
||||||
return View("Index");
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpParamAction]
|
|
||||||
[HttpPost]
|
|
||||||
public ActionResult Confirm(CreateViewModel viewModel)
|
|
||||||
{
|
|
||||||
// directory name is the sessionID
|
|
||||||
var files = GetBackloadDirectoryFiles(Session.SessionID);
|
|
||||||
|
|
||||||
if (!files.Any())
|
|
||||||
{
|
|
||||||
ModelState.AddModelError("Files", "Must select at least one file");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ModelState.IsValid)
|
|
||||||
{
|
|
||||||
// convert viewModel into Model
|
|
||||||
var leafInput = viewModel.GetFileInput();
|
|
||||||
// load files into LeafInputFile
|
|
||||||
leafInput.LeafInputFiles =
|
|
||||||
(from f in files
|
|
||||||
let bytes = System.IO.File.ReadAllBytes(f.FullName)
|
|
||||||
select new LeafInputFile {Filename = f.Name, Contents = bytes}).ToList();
|
|
||||||
|
|
||||||
// Save to db
|
|
||||||
DataService.AddLeafInput(leafInput);
|
|
||||||
|
|
||||||
DeleteBackloadDirectory(Session.SessionID);
|
|
||||||
|
|
||||||
SetStatusMessage(
|
|
||||||
HttpUtility.HtmlEncode(
|
|
||||||
$"A data set has submitted for '{viewModel.Identifier}' from '{viewModel.SiteId}'. " + Environment.NewLine
|
|
||||||
+ $"When complete, an email will be delivered to {viewModel.Name} <{viewModel.Email}> with results."),
|
|
||||||
StatusType.Success);
|
|
||||||
return RedirectToAction("Index");
|
|
||||||
}
|
|
||||||
return View("Index", viewModel);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,10 +7,16 @@ namespace LeafWeb.Web.ViewModels.LeafInput
|
|||||||
{
|
{
|
||||||
private static readonly IMapper Mapper;
|
private static readonly IMapper Mapper;
|
||||||
|
|
||||||
|
[Display(Name = "Your name")]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
[Display(Name = "Your email")]
|
||||||
public string Email { get; set; }
|
public string Email { get; set; }
|
||||||
|
[Display(Name = "Data identifier")]
|
||||||
public string Identifier { get; set; }
|
public string Identifier { get; set; }
|
||||||
|
[Display(Name = "Site Id")]
|
||||||
public string SiteId { get; set; }
|
public string SiteId { get; set; }
|
||||||
|
[Display(Name = "Photosynthetic Pathway")]
|
||||||
|
public SelectListViewModel PhotosynthesisType { get; set; }
|
||||||
public string[] Files { get; set; }
|
public string[] Files { get; set; }
|
||||||
|
|
||||||
static ConfirmViewModel()
|
static ConfirmViewModel()
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
|
using LeafWeb.Core.DAL;
|
||||||
|
|
||||||
namespace LeafWeb.Web.ViewModels.LeafInput
|
namespace LeafWeb.Web.ViewModels.LeafInput
|
||||||
{
|
{
|
||||||
@@ -31,21 +32,28 @@ namespace LeafWeb.Web.ViewModels.LeafInput
|
|||||||
[Required(ErrorMessage = "The site's name is required")]
|
[Required(ErrorMessage = "The site's name is required")]
|
||||||
public string SiteId { get; set; }
|
public string SiteId { get; set; }
|
||||||
|
|
||||||
|
[Display(Name = "Photosynthetic Pathways")]
|
||||||
|
[Required(ErrorMessage = "A photosynthesis pathway must be chosen")]
|
||||||
|
public SelectListViewModel PhotosynthesisType { get; set; }
|
||||||
|
|
||||||
static CreateViewModel()
|
static CreateViewModel()
|
||||||
{
|
{
|
||||||
var config =
|
var config =
|
||||||
new MapperConfiguration(cfg =>
|
new MapperConfiguration(cfg =>
|
||||||
{
|
{
|
||||||
cfg.CreateMap<CreateViewModel, Core.Models.LeafInput>();
|
cfg.CreateMap<CreateViewModel, Core.Models.LeafInput>()
|
||||||
|
.ForMember(dest => dest.PhotosynthesisType, opt => opt.Ignore());
|
||||||
});
|
});
|
||||||
Mapper = config.CreateMapper();
|
Mapper = config.CreateMapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Core.Models.LeafInput GetFileInput()
|
public Core.Models.LeafInput GetFileInput(DataService db)
|
||||||
{
|
{
|
||||||
var leafInput = new Core.Models.LeafInput();
|
var leafInput = new Core.Models.LeafInput();
|
||||||
Mapper.Map(this, leafInput);
|
Mapper.Map(this, leafInput);
|
||||||
|
|
||||||
|
leafInput.PhotosynthesisType = db.GetPhotosynthesisType(PhotosynthesisType.Selected);
|
||||||
|
|
||||||
return leafInput;
|
return leafInput;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
|
||||||
|
namespace LeafWeb.Web.ViewModels
|
||||||
|
{
|
||||||
|
public class SelectListViewModel
|
||||||
|
{
|
||||||
|
public SelectList ListItems { get; set; }
|
||||||
|
public string Selected { get; set; }
|
||||||
|
|
||||||
|
public SelectListItem SelectedItem
|
||||||
|
{
|
||||||
|
get { return ListItems.FirstOrDefault(li => li.Value == Selected); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return Selected;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -48,6 +48,16 @@
|
|||||||
</dl>
|
</dl>
|
||||||
@Html.HiddenFor(m => m.SiteId)
|
@Html.HiddenFor(m => m.SiteId)
|
||||||
|
|
||||||
|
<dl class="dl-horizontal siteId">
|
||||||
|
<dt class="small">
|
||||||
|
@Html.DisplayNameFor(m => m.PhotosynthesisType)
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
@Html.DisplayTextFor(m => m.PhotosynthesisType.SelectedItem.Text)
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
<input type="hidden" name="PhotosynthesisType.Selected" value="@Model.PhotosynthesisType.Selected" />
|
||||||
|
|
||||||
<dl class="dl-horizontal files">
|
<dl class="dl-horizontal files">
|
||||||
<dt>
|
<dt>
|
||||||
Files
|
Files
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
@Html.EditorFor(m => m.EmailConfirm)
|
@Html.EditorFor(m => m.EmailConfirm)
|
||||||
@Html.EditorFor(m => m.Identifier)
|
@Html.EditorFor(m => m.Identifier)
|
||||||
@Html.EditorFor(m => m.SiteId)
|
@Html.EditorFor(m => m.SiteId)
|
||||||
|
@Html.EditorFor(m => m.PhotosynthesisType)
|
||||||
<input type="submit" id="submit-form" class="hidden" />
|
<input type="submit" id="submit-form" class="hidden" />
|
||||||
}
|
}
|
||||||
<!-- The file upload form used as target for the file upload widget -->
|
<!-- The file upload form used as target for the file upload widget -->
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
@model LeafWeb.Web.ViewModels.SelectListViewModel
|
||||||
|
@{
|
||||||
|
Layout = "~/Views/Shared/EditorTemplates/_FieldLayout.cshtml";
|
||||||
|
}
|
||||||
|
@{
|
||||||
|
var prefix = ViewData.TemplateInfo.HtmlFieldPrefix;
|
||||||
|
ViewData.TemplateInfo.HtmlFieldPrefix = string.Empty;
|
||||||
|
|
||||||
|
foreach (var li in Model.ListItems)
|
||||||
|
{
|
||||||
|
<div class="radio">
|
||||||
|
<label class="radio">
|
||||||
|
@Html.RadioButton(prefix + ".Selected", li.Value, li.Selected) @li.Text
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
ViewData.TemplateInfo.HtmlFieldPrefix = prefix;
|
||||||
|
}
|
||||||
@@ -2,14 +2,17 @@
|
|||||||
@model object
|
@model object
|
||||||
@{
|
@{
|
||||||
Layout = null;
|
Layout = null;
|
||||||
var lowerPropertyName = @LeafWeb.Core.Utility.StringExtensions.LowercaseFirst(ViewData.ModelMetadata.PropertyName);
|
var propertyName = ViewData.ModelMetadata.PropertyName;
|
||||||
|
var lowerPropertyName = @LeafWeb.Core.Utility.StringExtensions.LowercaseFirst(propertyName);
|
||||||
var values = ViewData.ModelMetadata.AdditionalValues;
|
var values = ViewData.ModelMetadata.AdditionalValues;
|
||||||
var units = values.ContainsKey("Units") ? (string)values["Units"] : null;
|
var units = values.ContainsKey("Units") ? (string)values["Units"] : null;
|
||||||
var currency = values.ContainsKey("Currency") ? (string)values["Currency"] : null;
|
var currency = values.ContainsKey("Currency") ? (string)values["Currency"] : null;
|
||||||
var formatHint = values.ContainsKey("FormatHint") ? (string)values["FormatHint"] : null;
|
var formatHint = values.ContainsKey("FormatHint") ? (string)values["FormatHint"] : null;
|
||||||
var editLabel = values.ContainsKey("EditLabel") ? (bool)values["EditLabel"] : true;
|
var editLabel = values.ContainsKey("EditLabel") ? (bool)values["EditLabel"] : true;
|
||||||
|
var hasError = ViewData.ModelState[propertyName] != null && ViewData.ModelState[propertyName].Errors.Any();
|
||||||
|
var hasErrorClass = hasError ? "has-error" : string.Empty;
|
||||||
}
|
}
|
||||||
<div class="form-group @lowerPropertyName">
|
<div class="form-group @lowerPropertyName @hasErrorClass">
|
||||||
@Html.LabelForModel(new { @class = "control-label" })
|
@Html.LabelForModel(new { @class = "control-label" })
|
||||||
@RenderBody()
|
@RenderBody()
|
||||||
@Html.ValidationMessage("", new { @class = "help-block"})
|
@Html.ValidationMessage("", new { @class = "help-block"})
|
||||||
|
|||||||
@@ -905,6 +905,7 @@
|
|||||||
<Compile Include="Utility\Validation.cs" />
|
<Compile Include="Utility\Validation.cs" />
|
||||||
<Compile Include="ViewModels\LeafInput\ConfirmViewModel.cs" />
|
<Compile Include="ViewModels\LeafInput\ConfirmViewModel.cs" />
|
||||||
<Compile Include="ViewModels\LeafInput\CreateViewModel.cs" />
|
<Compile Include="ViewModels\LeafInput\CreateViewModel.cs" />
|
||||||
|
<Compile Include="ViewModels\SelectListViewModel.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Views\web.config" />
|
<Content Include="Views\web.config" />
|
||||||
@@ -940,6 +941,7 @@
|
|||||||
<Content Include="Views\LeafInput\Confirm.cshtml" />
|
<Content Include="Views\LeafInput\Confirm.cshtml" />
|
||||||
<Content Include="Views\Shared\_StatusMessage.cshtml" />
|
<Content Include="Views\Shared\_StatusMessage.cshtml" />
|
||||||
<Content Include="Views\Shared\_ValidationField.cshtml" />
|
<Content Include="Views\Shared\_ValidationField.cshtml" />
|
||||||
|
<Content Include="Views\Shared\EditorTemplates\SelectListViewModel.cshtml" />
|
||||||
<None Include="Web.Debug.config">
|
<None Include="Web.Debug.config">
|
||||||
<DependentUpon>Web.config</DependentUpon>
|
<DependentUpon>Web.config</DependentUpon>
|
||||||
</None>
|
</None>
|
||||||
|
|||||||
Reference in New Issue
Block a user