diff --git a/DotnetViewComponents/ViewComponents/TaskListViewComponent.cs b/DotnetViewComponents/ViewComponents/TaskListViewComponent.cs new file mode 100644 index 0000000000..6f4f3a7811 --- /dev/null +++ b/DotnetViewComponents/ViewComponents/TaskListViewComponent.cs @@ -0,0 +1,17 @@ +namespace DotnetViewComponents.ViewComponents +{ + using System.Collections.Generic; + using Microsoft.AspNetCore.Mvc; + using DotnetViewComponents.ViewModels; + + public class TaskListViewComponent : ViewComponent + { + public IViewComponentResult Invoke( + IEnumerable listItems) + { + var model = new TaskListViewModel(listItems); + + return View(model); + } + } +} diff --git a/DotnetViewComponents/ViewModels/TaskListItemViewModel.cs b/DotnetViewComponents/ViewModels/TaskListItemViewModel.cs new file mode 100644 index 0000000000..b9ad1877db --- /dev/null +++ b/DotnetViewComponents/ViewModels/TaskListItemViewModel.cs @@ -0,0 +1,86 @@ +namespace DotnetViewComponents.ViewModels +{ + public class TaskListItemViewModel + { + /// + /// Creates a new instance of the class. + /// STATE: Choose between "Completed", "Incomplete" and "Cannot start yet". + /// STATESTYLE: The style should match the state. (e.g. "TaskStateStyle.INCOMPLETE" for "Incomplete", "TaskStateStyle.COMPLETED" for "Completed", "TaskStateStyle.UNSTARTED" for "Cannot start yet") + /// + /// The unique identifier for the task. + /// The name of the task. + /// The asp-controller associated with the task's action. + /// The asp-action action associated with the task's action. + /// An asp-all-data-route dictionary containing route data for the task's action. + /// Choose between "Completed", "Incomplete" and "Cannot start yet". + /// The style should match the state. (e.g. "TaskStateStyle.INCOMPLETE" for "Incomplete", "TaskStateStyle.COMPLETED" for "Completed", "TaskStateStyle.UNSTARTED" for "Cannot start yet") + /// Additional text providing hints about the task. + public TaskListItemViewModel( + string id, + string name, + string aspController, + string aspAction, + Dictionary aspRouteData, + string state, + TaskStateStyle stateStyle, + string hintText) + { + Id = id; + Name = name; + AspController = aspController; + AspAction = aspAction; + AspRouteData = aspRouteData; + State = state; + StateStyle = stateStyle; + HintText = hintText; + } + + /// + /// Gets or sets the unique identifier for the task. + /// + public string Id { get; set; } + + /// + /// Gets or sets the name of the task. + /// + public string Name { get; set; } + + /// + /// Gets or sets the asp-controller of the link. + /// + public string AspController { get; set; } + + /// + /// Gets or sets the as-action of the link. + /// + public string AspAction { get; set; } + + /// + /// Gets or sets the asp-all-route-data of the link. + /// + public Dictionary AspRouteData { get; set; } + + /// + /// Gets or sets the current state of the task. + /// + public string State { get; set; } + + /// + /// Gets or sets the style that matches the state of the task. + /// + public TaskStateStyle StateStyle { get; set; } + + /// + /// Gets or sets additional text providing hints about the task. + /// + public string HintText { get; set; } + } + + + public enum TaskStateStyle + { + COMPLETED, + INCOMPLETE, + UNSTARTED + } +} diff --git a/DotnetViewComponents/ViewModels/TaskListViewModel.cs b/DotnetViewComponents/ViewModels/TaskListViewModel.cs new file mode 100644 index 0000000000..1de7a2e5bb --- /dev/null +++ b/DotnetViewComponents/ViewModels/TaskListViewModel.cs @@ -0,0 +1,20 @@ +namespace DotnetViewComponents.ViewModels +{ + public class TaskListViewModel + { + /// + /// Initializes a new instance of the class. + /// + /// A collection of task list items. + public TaskListViewModel( + IEnumerable listItems) + { + ListItems = listItems; + } + + /// + /// Gets or sets the collection of task list items. + /// + public IEnumerable ListItems { get; set; } + } +} diff --git a/DotnetViewComponents/Views/Shared/Components/TaskList/Default.cshtml b/DotnetViewComponents/Views/Shared/Components/TaskList/Default.cshtml new file mode 100644 index 0000000000..0a33cf0359 --- /dev/null +++ b/DotnetViewComponents/Views/Shared/Components/TaskList/Default.cshtml @@ -0,0 +1,49 @@ +@using DotnetViewComponents.ViewModels +@model TaskListViewModel + +
    + @foreach (var task in Model.ListItems) + { + var hasLink = task.StateStyle != TaskStateStyle.UNSTARTED; + var statusClass = task.StateStyle switch + { + TaskStateStyle.COMPLETED => "nhsuk-task-list__status nhsuk-task-list__status--completed", + TaskStateStyle.INCOMPLETE => "nhsuk-task-list__status", + TaskStateStyle.UNSTARTED => "nhsuk-task-list__status nhsuk-task-list__status--cannot-start-yet", + _ => "nhsuk-task-list__status" + }; + var statusId = task.StateStyle == TaskStateStyle.UNSTARTED + ? $"task-list-{task.Id}-status" + : task.Id; + + + + } +