Add ResultsAdmin, delete action
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using LeafWeb.Web.Attributes;
|
||||
using LeafWeb.Web.ViewModels.LeafInput;
|
||||
using LeafWeb.Web.ViewModels.Results;
|
||||
using LeafWeb.Web.ViewModels.ResultsAdmin;
|
||||
|
||||
namespace LeafWeb.Web.Controllers
|
||||
{
|
||||
public class ResultsAdminController : ControllerBase
|
||||
{
|
||||
public ActionResult Index()
|
||||
{
|
||||
var viewModel =
|
||||
DataService.GetLeafInputs()
|
||||
.OrderByDescending(f => f.Id)
|
||||
.ToList()
|
||||
.Select(leafInput => new ResultStatusViewModel(leafInput));
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
public ActionResult Delete(int id)
|
||||
{
|
||||
var leafInput = DataService.GetLeafInput(id);
|
||||
var viewModel = new LeafInputViewModel(leafInput);
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("Delete")]
|
||||
[ActionLog]
|
||||
public ActionResult DeleteConfirmed(int id)
|
||||
{
|
||||
// TODO: don't allow currently running LeafInput to be deleted
|
||||
var leafInput = DataService.GetLeafInput(id);
|
||||
DataService.DeleteLeafInput(leafInput);
|
||||
|
||||
SetStatusMessage($"LeafInput '{leafInput.Identifier}' deleted");
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using System.Linq;
|
||||
using AutoMapper;
|
||||
|
||||
namespace LeafWeb.Web.ViewModels.ResultsAdmin
|
||||
{
|
||||
public class LeafInputViewModel
|
||||
{
|
||||
private static readonly IMapper Mapper;
|
||||
|
||||
public int LeafInputId { get; set; }
|
||||
public string LeafInputName { get; set; }
|
||||
public string LeafInputIdentifier { get; set; }
|
||||
public string LeafInputSiteId { get; set; }
|
||||
public string LeafInputPhotosynthesisType { get; set; }
|
||||
public bool HasLeafChart { get; set; }
|
||||
public string CurrentStatus { get; set; }
|
||||
//public string[] ErrorMessages { get; set; }
|
||||
//public string[] LeafOutputFilenames { get; set; }
|
||||
//public bool HasLeafChartOutputFile { get; set; }
|
||||
|
||||
static LeafInputViewModel()
|
||||
{
|
||||
var config =
|
||||
new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Core.Entities.LeafInput, LeafInputViewModel>()
|
||||
.ForMember(dest => dest.LeafInputId, opt => opt.MapFrom(src => src.Id))
|
||||
.ForMember(dest => dest.HasLeafChart, opt => opt.ResolveUsing(src => src.OutputFiles.Any(o => o.IsLeafChartFile)))
|
||||
.ForMember(dest => dest.LeafInputName, opt => opt.MapFrom(src => src.Name))
|
||||
.ForMember(dest => dest.LeafInputIdentifier, opt => opt.MapFrom(src => src.Identifier))
|
||||
.ForMember(dest => dest.LeafInputSiteId, opt => opt.MapFrom(src => src.SiteId))
|
||||
.ForMember(dest => dest.LeafInputPhotosynthesisType, opt => opt.MapFrom(src => src.PhotosynthesisType.Name))
|
||||
//.ForMember(dest => dest.ErrorMessages,
|
||||
// opt => opt.ResolveUsing(
|
||||
// src =>
|
||||
// src.StatusHistory?
|
||||
// .Where(sh => sh.Status == LeafInputStatusType.Exception)
|
||||
// .Select(sh => sh.Description)
|
||||
// .ToArray()
|
||||
// ?? new string[] {}))
|
||||
;
|
||||
});
|
||||
Mapper = config.CreateMapper();
|
||||
}
|
||||
|
||||
public LeafInputViewModel(Core.Entities.LeafInput leafInput)
|
||||
{
|
||||
Mapper.Map(leafInput, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
@model LeafWeb.Web.ViewModels.ResultsAdmin.LeafInputViewModel
|
||||
|
||||
@{
|
||||
ViewBag.Title = "Delete LeafInput";
|
||||
}
|
||||
|
||||
<h1>@ViewBag.Title</h1>
|
||||
|
||||
<div class="center-content label label-warning">Are you sure you wish to delete this LeafInput?</div>
|
||||
|
||||
<div class="center-content well">
|
||||
|
||||
@Html.DisplayForModel()
|
||||
|
||||
@using (Html.BeginForm("Delete", "ResultsAdmin", FormMethod.Post, new { @class = "form-horizontal" }))
|
||||
{
|
||||
<div class="form-actions">
|
||||
<input type="submit" value="Delete" class="btn btn-warning" />
|
||||
@Html.ActionLink("Cancel", "Details", new { id = Model.LeafInputId }, new { @class = "btn" })
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@@ -0,0 +1,28 @@
|
||||
@model IEnumerable<LeafWeb.Web.ViewModels.Results.ResultStatusViewModel>
|
||||
|
||||
@{
|
||||
ViewBag.Title = "Results Administration";
|
||||
var grid = new WebGrid(Model, rowsPerPage: 45);
|
||||
}
|
||||
|
||||
<h1>@ViewBag.Title</h1>
|
||||
|
||||
@grid.GetHtml(columns:
|
||||
grid.Columns(
|
||||
grid.Column("LeafInputIdentifier", "Identifier"),
|
||||
grid.Column("LeafInputSiteId", "Site Id"),
|
||||
grid.Column("LeafInputName", "Submitted By"),
|
||||
grid.Column("CurrentStatus", "Status"),
|
||||
grid.Column("Chart", "Chart", item =>
|
||||
item.HasLeafChart
|
||||
? Html.ActionLink("Chart", "Index", "Chart", new { leafInputId = item.LeafInputId }, new { })
|
||||
: Html.Raw("")),
|
||||
grid.Column("Total Results: " + Model.Count(), format:
|
||||
@<div class="btn-group" role="group">
|
||||
@Html.ActionLink("Edit", "Edit", new { id = item.LeafInputId }, new { @class = "btn btn-default btn-xs", role = "button" })
|
||||
@Html.ActionLink("Details", "Details", new { id = item.LeafInputId }, new { @class = "btn btn-default btn-xs", role = "button" })
|
||||
@Html.ActionLink("Delete", "Delete", new { id = item.LeafInputId }, new { @class = "btn btn-default btn-xs", role="button" })
|
||||
</div>)
|
||||
),
|
||||
htmlAttributes: new { @class = "table table-striped table-bordered table-hover table-condensed" }
|
||||
)
|
||||
@@ -636,6 +636,7 @@
|
||||
<Compile Include="Backload\Controller\BackloadController.obsolete.cs" />
|
||||
<Compile Include="Backload\Helper\ResultCreator.Classic.cs" />
|
||||
<Compile Include="Backload\Helper\ResultCreator.cs" />
|
||||
<Compile Include="Controllers\ResultsAdminController.cs" />
|
||||
<Compile Include="Services\DownloadUrlService.cs" />
|
||||
<Compile Include="Services\LeafGasCharter.cs" />
|
||||
<Compile Include="Controllers\ControllerBase.cs" />
|
||||
@@ -662,6 +663,7 @@
|
||||
<Compile Include="ViewModels\Chart\ChartViewModel.cs" />
|
||||
<Compile Include="ViewModels\LeafInput\ConfirmViewModel.cs" />
|
||||
<Compile Include="ViewModels\LeafInput\CreateViewModel.cs" />
|
||||
<Compile Include="ViewModels\ResultsAdmin\ResultStatusViewModel.cs" />
|
||||
<Compile Include="ViewModels\Results\ResultStatusViewModel.cs" />
|
||||
<Compile Include="ViewModels\SelectListViewModel.cs" />
|
||||
</ItemGroup>
|
||||
@@ -699,6 +701,8 @@
|
||||
<Content Include="Views\Pages\Information.cshtml" />
|
||||
<Content Include="Views\Results\DownloadNotFound.cshtml" />
|
||||
<Content Include="Views\Chart\DataError.cshtml" />
|
||||
<Content Include="Views\ResultsAdmin\Index.cshtml" />
|
||||
<Content Include="Views\ResultsAdmin\Delete.cshtml" />
|
||||
<None Include="Web.Debug.config">
|
||||
<DependentUpon>Web.config</DependentUpon>
|
||||
</None>
|
||||
|
||||
Reference in New Issue
Block a user