Skip to content

Commit

Permalink
Added master page
Browse files Browse the repository at this point in the history
added ugly ui mapping code to hunt down a null ref exception.
  • Loading branch information
davidwhitney committed Mar 26, 2012
1 parent 0ff93aa commit 2091f7a
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 158 deletions.
1 change: 1 addition & 0 deletions DeployD/Deployd.Agent/Deployd.Agent.csproj
Expand Up @@ -139,6 +139,7 @@
<SubType>Component</SubType>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WebUi\Converters\RunningTasksToPackageListViewModelConverter.cs" />
<Compile Include="WebUi\Models\InstallationsViewModel.cs" />
<Compile Include="WebUi\Models\InstallTaskViewModel.cs" />
<Compile Include="WebUi\Models\PackageListViewModel.cs" />
Expand Down
@@ -0,0 +1,70 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Deployd.Agent.WebUi.Models;
using Deployd.Core.Caching;
using Deployd.Core.Installation;

namespace Deployd.Agent.WebUi.Converters
{
public static class RunningTasksToPackageListViewModelConverter
{
public static PackageListViewModel Convert(INuGetPackageCache cache, RunningInstallationTaskList runningTasks, ICurrentInstalledCache installCache)
{
var model = new PackageListViewModel();

foreach(var packageId in cache.AvailablePackages)
{
var package = new LocalPackageInformation
{
PackageId = packageId,
LatestAvailableVersion = cache.GetLatestVersion(packageId).ToString()
};

var installedPackage = installCache.GetCurrentInstalledVersion(packageId);
package.InstalledVersion = installedPackage == null ? "" : installedPackage.ToString();

package.CurrentTask = runningTasks.Count > 0 ? runningTasks
.Where(t => t.PackageId == packageId)
.Select(t =>
{
var lastOrDefault = t.ProgressReports.LastOrDefault();
return lastOrDefault != null ? new InstallTaskViewModel
{
Messages = t.ProgressReports.Select(pr => pr.Message).ToArray(),
Status = Enum.GetName(typeof(TaskStatus), t.Task.Status),
PackageId = t.PackageId,
Version = t.Version,
LastMessage = t.ProgressReports.Count > 0 ? lastOrDefault.Message : ""
} : null;
}).FirstOrDefault()
: null;

model.Packages.Add(package);
}

model.CurrentTasks = runningTasks
.Select(t =>
{
var progressReport = t.ProgressReports.LastOrDefault();
return progressReport != null
? new InstallTaskViewModel
{
Messages = t.ProgressReports.Select(pr => pr.Message).ToArray(),
Status = Enum.GetName(typeof (TaskStatus), t.Task.Status),
PackageId = t.PackageId,
Version = t.Version,
LastMessage =
t.ProgressReports.Count > 0 ? progressReport.Message : ""
}
: null;
}).ToList();


model.AvailableVersions =
cache.AllCachedPackages().Select(p => p.Version.ToString()).Distinct().OrderByDescending(s => s);

return model;
}
}
}
13 changes: 7 additions & 6 deletions DeployD/Deployd.Agent/WebUi/Models/PackageListViewModel.cs
@@ -1,21 +1,18 @@
using System.Collections.Generic;
using System.Linq;
using Deployd.Core.Installation;
using NuGet;

namespace Deployd.Agent.WebUi.Models
{
public class PackageListViewModel
{
public IList<LocalPackageInformation> Packages { get; set; }

public IList<InstallTaskViewModel> CurrentTasks { get; set; }

public IEnumerable<string> AvailableVersions { get; set; }

public PackageListViewModel()
{
Packages = new List<LocalPackageInformation>();
CurrentTasks = new List<InstallTaskViewModel>();
AvailableVersions = new List<string>();
}
}

Expand All @@ -25,7 +22,11 @@ public class LocalPackageInformation
public string InstalledVersion { get; set; }
public string LatestAvailableVersion { get; set; }
public List<string> AvailableVersions { get; set; }

public InstallTaskViewModel CurrentTask { get; set; }

public LocalPackageInformation()
{
AvailableVersions = new List<string>();
}
}
}
41 changes: 4 additions & 37 deletions DeployD/Deployd.Agent/WebUi/Modules/PackagesModule.cs
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Linq;
using Deployd.Agent.WebUi.Converters;
using Deployd.Agent.WebUi.Models;
using Deployd.Core.Caching;
using Deployd.Core.Hosting;
Expand All @@ -24,41 +24,8 @@ public PackagesModule(): base("/packages")
{
var cache = Container().GetType<INuGetPackageCache>();
var runningTasks = Container().GetType<RunningInstallationTaskList>();
var installCache = Container().GetType<ICurrentInstalledCache>();
var model =
new PackageListViewModel
{
Packages = cache.AvailablePackages.Select(name => new LocalPackageInformation()
{
PackageId = name,
InstalledVersion = installCache.GetCurrentInstalledVersion(name).ToString(),
LatestAvailableVersion = cache.GetLatestVersion(name).ToString(),
CurrentTask = runningTasks.Count > 0 ? runningTasks
.Where(t => t.PackageId == name)
.Select(t => new InstallTaskViewModel()
{
Messages = t.ProgressReports.Select(pr => pr.Message).ToArray(),
Status = Enum.GetName(typeof(TaskStatus), t.Task.Status),
PackageId = t.PackageId,
Version = t.Version,
LastMessage = t.ProgressReports.Count > 0 ? t.ProgressReports.LastOrDefault().Message : ""
}).FirstOrDefault()
: null
}).ToArray(),
CurrentTasks = runningTasks
.Select(t => new InstallTaskViewModel()
{
Messages = t.ProgressReports.Select(pr => pr.Message).ToArray(),
Status = Enum.GetName(typeof(TaskStatus), t.Task.Status),
PackageId = t.PackageId,
Version = t.Version,
LastMessage = t.ProgressReports.Count > 0 ? t.ProgressReports.LastOrDefault().Message : ""
}).ToList(),
AvailableVersions = cache.AllCachedPackages().Select(p=>p.Version.ToString()).Distinct().OrderByDescending(s=>s)
};
var installCache = Container().GetType<ICurrentInstalledCache>();
var model = RunningTasksToPackageListViewModelConverter.Convert(cache, runningTasks, installCache);
return this.ViewOrJson("packages.cshtml", model);
};

Expand Down
15 changes: 3 additions & 12 deletions DeployD/Deployd.Agent/WebUi/Views/index.cshtml
@@ -1,12 +1,3 @@
<!DOCTYPE html>
<html>
<head>
<title>Deployd.Agent</title>
</head>
<body>
<h1>Deployd.Agent</h1>

<a href="/packages">Packages</a>

</body>
</html>
@{
Layout = "layout.cshtml";
}
42 changes: 15 additions & 27 deletions DeployD/Deployd.Agent/WebUi/Views/installations.cshtml
@@ -1,29 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title>Deployd.Agent</title>
<meta http-equiv="refresh" content="3">
</head>
<body>
<h1>Deployd.Agent - @Environment.MachineName</h1>

<ul>
<li><a href="/packages">Packages</a></li>
<li><a href="/installations">Installations</a></li>
</ul>
@{
Layout = "layout.cshtml";
}

<h2>Task Queue</h2>

@foreach (var task in Model.TaskQueue)
{
<p>@task.PackageId @task.Version</p>
}

<h2>Running Tasks</h2>
<h2>Task Queue</h2>

@foreach (var task in Model.RunningTasks)
{
<p>@task.PackageId @task.Version @task.LastMessage</p>
}
</body>
</html>
@foreach (var task in Model.TaskQueue)
{
<p>@task.PackageId @task.Version</p>
}

<h2>Running Tasks</h2>

@foreach (var task in Model.RunningTasks)
{
<p>@task.PackageId @task.Version @task.LastMessage</p>
}
2 changes: 1 addition & 1 deletion DeployD/Deployd.Agent/WebUi/Views/layout.cshtml
Expand Up @@ -4,7 +4,7 @@
<title>Deployd.Agent</title>
</head>
<body>
<h1>Deployd.Agent</h1>
<h1>Deployd.Agent - @Environment.MachineName</h1>

<ul>
<li><a href="/packages">Packages</a></li>
Expand Down
37 changes: 15 additions & 22 deletions DeployD/Deployd.Agent/WebUi/Views/package-details.cshtml
@@ -1,24 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title>Deployd.Agent</title>
</head>
<body>
<h1>Deployd.Agent</h1>

<form action="/packages/@Model.PackageName/install" method="POST">
<input type="submit" value="Install Latest"></input>
</form>
@{
Layout = "layout.cshtml";
}

<h2>Available Package Versions for @Model.PackageName</h2>
<form method="post" action="/packages/@Model.PackageName/install">
<input type="submit" value="Update to:"/> <select name="specificVersion">
@foreach(string version in Model.CachedVersions)
{
<option>@version</option>
}
</select>
</form>
<form action="/packages/@Model.PackageName/install" method="POST">
<input type="submit" value="Install Latest"></input>
</form>

</body>
</html>
<h2>Available Package Versions for @Model.PackageName</h2>
<form method="post" action="/packages/@Model.PackageName/install">
<input type="submit" value="Update to:"/> <select name="specificVersion">
@foreach(string version in Model.CachedVersions)
{
<option>@version</option>
}
</select>
</form>
92 changes: 39 additions & 53 deletions DeployD/Deployd.Agent/WebUi/Views/packages.cshtml
@@ -1,60 +1,46 @@
@using Deployd.Agent.WebUi.Models
@{
Layout = "layout.cshtml";
}

<h2>Available Packages</h2>

<!DOCTYPE html>
<html>
<head>
<title>Deployd.Agent</title>
</head>
<body>
<h1>Deployd.Agent - @Environment.MachineName</h1>

<ul>
<li><a href="/packages">Packages</a></li>
<li><a href="/installations">Installations</a></li>
</ul>
<form method="post" action="/packages/UpdateAllTo">
<input type="submit" value="Update all to:"/> <select name="specificVersion">
@foreach(string version in Model.AvailableVersions)
{
<option>@version</option>
}
</select>
</form>

<h2>Available Packages</h2>

<form method="post" action="/packages/UpdateAllTo">
<input type="submit" value="Update all to:"/> <select name="specificVersion">
@foreach(string version in Model.AvailableVersions)
{
<option>@version</option>
}
</select>
</form>
@foreach(LocalPackageInformation package in Model.Packages)
{
<div style="clear:both">
<a href="/packages/@package.PackageId">@package.PackageId</a><div style="float:right;margin-right:80px"><form style="display:inline" action="/packages/@package.PackageId/install" method="POST"><input type="submit" value="Install Latest"></input></form></div><br/>
@if (package.CurrentTask != null)
{
<text>@package.CurrentTask.Status: @package.CurrentTask.LastMessage<br/></text>
}

@foreach(LocalPackageInformation package in Model.Packages)
{
<div style="clear:both">
<a href="/packages/@package.PackageId">@package.PackageId</a><div style="float:right;margin-right:80px"><form style="display:inline" action="/packages/@package.PackageId/install" method="POST"><input type="submit" value="Install Latest"></input></form></div><br/>
@if (package.CurrentTask != null)
{
<text>@package.CurrentTask.Status: @package.CurrentTask.LastMessage<br/></text>
}
@if(!string.IsNullOrWhiteSpace(package.LatestAvailableVersion))
{
<text>Latest: @package.LatestAvailableVersion<br/></text>
}
@if (!string.IsNullOrWhiteSpace(package.InstalledVersion))
{
<text>Installed: @package.InstalledVersion</text>
}
else
{
<text>Not installed</text>
}
<br/>
</div>

}

@if(!string.IsNullOrWhiteSpace(package.LatestAvailableVersion))
{
<text>Latest: @package.LatestAvailableVersion<br/></text>
}
@if (!string.IsNullOrWhiteSpace(package.InstalledVersion))
{
<text>Installed: @package.InstalledVersion</text>
}
else
{
<text>Not installed</text>
}
<br/>
</div>

}

@foreach (InstallTaskViewModel task in Model.CurrentTasks)
{
<p>@task.PackageId @task.Version @task.Status @task.LastMessage</p>
}
</body>
</html>
@foreach (InstallTaskViewModel task in Model.CurrentTasks)
{
<p>@task.PackageId @task.Version @task.Status @task.LastMessage</p>
}

0 comments on commit 2091f7a

Please sign in to comment.