1. Tatham Oddie
  2. Timeline

Commits

Tatham Oddie  committed 7c64603

Start spitting out data from the controller instead of just static

  • Participants
  • Parent commits 70162d5
  • Branches default

Comments (0)

Files changed (6)

File Web/Controllers/TimelineController.cs

View file
  • Ignore whitespace
 using System.Web.Mvc;
+using Web.Models;
 
 namespace Web.Controllers
 {
     {
         public ActionResult Index()
         {
-            return View();
+            var activities = new[]
+            {
+                new ActivityViewModel
+                {
+                    CategoryKey = "flight-arrival",
+                    IntroText = "Landed at",
+                    PrimaryValue = "CNS",
+                    PlotValue = -20,
+                    PlotText = "20° S"
+                },
+                new ActivityViewModel
+                {
+                    CategoryKey = "fitness-run",
+                    IntroText = "Ran",
+                    PrimaryValue = "4.01km",
+                    PlotValue = 297,
+                    PlotText = "297 calories, 84m climb"
+                },
+                new ActivityViewModel
+                {
+                    CategoryKey = "weigh-in",
+                    IntroText = "Weighed in at",
+                    PrimaryValue = "66.1kg",
+                    PlotValue = 11.6,
+                    PlotText = "11.6% fat, 21.6 BMI"
+                },
+                new ActivityViewModel
+                {
+                    CategoryKey = "flight-departure",
+                    IntroText = "Took off from",
+                    PrimaryValue = "SYD",
+                    PlotValue = -33,
+                    PlotText = "33° S"
+                }
+            };
+
+            var timeline = new TimelineViewModel
+            {
+                Locations = new[]
+                {
+                    new LocationViewModel {Name = "Sydney", Activities = activities},
+                    new LocationViewModel {Name = "Cairns", Activities = activities},
+                    new LocationViewModel {Name = "Sydney", Activities = activities},
+                    new LocationViewModel {Name = "Los Angeles", Activities = activities}
+                }
+            };
+
+            return View(timeline);
         }
     }
 }

File Web/Models/ActivityViewModel.cs

View file
  • Ignore whitespace
+namespace Web.Models
+{
+    public class ActivityViewModel
+    {
+        public string CategoryKey { get; set; }
+        public string IntroText { get; set; }
+        public string PrimaryValue { get; set; }
+        public double PlotValue { get; set; }
+        public string PlotText { get; set; }
+    }
+}

File Web/Models/LocationViewModel.cs

View file
  • Ignore whitespace
+using System.Collections.Generic;
+
+namespace Web.Models
+{
+    public class LocationViewModel
+    {
+        public string Name { get; set; }
+        public IEnumerable<ActivityViewModel> Activities { get; set; }
+    }
+}

File Web/Models/TimelineViewModel.cs

View file
  • Ignore whitespace
+using System.Collections.Generic;
+
+namespace Web.Models
+{
+    public class TimelineViewModel
+    {
+        public IEnumerable<LocationViewModel> Locations { get; set; }
+    }
+}

File Web/Views/Timeline/Index.cshtml

View file
  • Ignore whitespace
-@model dynamic
+@model Web.Models.TimelineViewModel
 
 @{
     ViewBag.Title = "Tatham's Timeline";
 
 <div class="timeline-viewport">
     <ol class="timeline">
-        <li>
-            <span class="location-name">Sydney</span>
-            <ol>
-                <li class="fitness-run">
-                    <span class="tile">
-                        <span class="activity">Ran </span> 4.01km
-                    </span>
-                    <data value="297">297 calories, 84m climb</data>
-                </li>
-                <li class="weigh-in">
-                    <span class="tile">
-                        <span class="activity">Weighed in at </span> 66.1kg
-                    </span>
-                    <data value="11.6">11.6% fat, 21.6 BMI</data>
-                </li>
-                <li class="fitness-run">
-                    <span class="tile">
-                        <span class="activity">Ran </span> 4.22km
-                    </span>
-                    <data value="310">310 Cal, 86m climb</data>
-                </li>
-                <li class="fitness-run">
-                    <span class="tile">
-                        <span class="activity">Ran </span> 4.01km
-                    </span>
-                    <data value="297">297 calories, 84m climb</data>
-                </li>
-                <li class="weigh-in">
-                    <span class="tile">
-                        <span class="activity">Weighed in at </span> 66.1kg
-                    </span>
-                    <data value="11.6">11.6% fat, 21.6 BMI</data>
-                </li>
-                <li class="fitness-run">
-                    <span class="tile">
-                        <span class="activity">Ran </span> 4.22km
-                    </span>
-                    <data value="310">310 Cal, 86m climb</data>
-                </li>
-                <li class="flight-departure">
-                    <span class="tile">
-                        <span class="activity">Took off from </span> SYD
-                    </span>
-                    <data value="-33">33° S</data>
-                </li>
-            </ol>
-        </li>
-        <li>
-            <span class="location-name">Cairns</span>
-            <ol>
-                <li class="flight-arrival">
-                    <span class="tile">
-                        <span class="activity">Landed in </span> CNS
-                    </span>
-                    <data value="-17">17° S</data>
-                </li>
-                <li class="fitness-run">
-                    <span class="tile">
-                        <span class="activity">Ran </span> 4.22km
-                    </span>
-                    <data value="310">310 Cal, 86m climb</data>
-                </li>
-                <li class="flight-departure">
-                    <span class="tile">
-                        <span class="activity">Took off from </span> CNS
-                    </span>
-                    <data value="-17">17° S</data>
-                </li>
-            </ol>
-        </li>
-        <li>
-            <span class="location-name">Sydney</span>
-            <ol>
-                <li class="flight-arrival">
-                    <span class="tile">
-                        <span class="activity">Landed in </span> SYD
-                    </span>
-                    <data value="-33">33° S</data>
-                </li>
-                <li class="fitness-run">
-                    <span class="tile">
-                        <span class="activity">Ran </span> 4.01km
-                    </span>
-                    <data value="297">297 calories, 84m climb</data>
-                </li>
-                <li class="weigh-in">
-                    <span class="tile">
-                        <span class="activity">Weighed in at </span> 66.1kg
-                    </span>
-                    <data value="11.6">11.6% fat, 21.6 BMI</data>
-                </li>
-                <li class="flight-departure">
-                    <span class="tile">
-                        <span class="activity">Took off from </span> SYD
-                    </span>
-                    <data value="-33">33° S</data>
-                </li>
-            </ol>
-        </li>
+        @foreach (var location in Model.Locations)
+        {
+            <li>
+                <span class="location-name">@location.Name</span>
+                <ol>
+                    @foreach (var activity in location.Activities)
+                    {
+                        <li class="@activity.CategoryKey">
+                            <span class="tile">
+                                <span class="activity">@activity.IntroText</span> @activity.PrimaryValue
+                            </span>
+                            <data value="@activity.PlotValue">@activity.PlotText</data>
+                        </li>
+                    }
+                </ol>
+            </li>
+        }
         <li>
             <span class="location-name">Los Angeles</span>
             <ol>

File Web/Web.csproj

View file
  • Ignore whitespace
     <Compile Include="Global.asax.cs">
       <DependentUpon>Global.asax</DependentUpon>
     </Compile>
+    <Compile Include="Models\ActivityViewModel.cs" />
+    <Compile Include="Models\LocationViewModel.cs" />
+    <Compile Include="Models\TimelineViewModel.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
   <ItemGroup>
   </ItemGroup>
   <ItemGroup>
     <Folder Include="App_Data\" />
-    <Folder Include="Models\" />
   </ItemGroup>
   <ItemGroup>
     <Content Include="packages.config">