/
ViewHelpers.cshtml
171 lines (157 loc) · 5.44 KB
/
ViewHelpers.cshtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
@using System.Configuration
@using System.Web.Mvc
@using Microsoft.Web.Helpers
@using Microsoft.WindowsAzure.ServiceRuntime
@using NuGetGallery
@using Ninject
@* Generator: MvcHelper Namespace: NuGetGallery*@
@functions {
public static IConfiguration Configuration
{
get { return Container.Kernel.Get<IConfiguration>(); }
}
private static Dictionary<string, string> EnvironmentMessages = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
{ "Development", "This is a development environment. No data will be preserved." },
{ "QA", "This is an internal test environment. User accounts from the main site will NOT work." },
{ "Staging", "This is a staging environment. Some data from the main site may exist but data added here will be lost." }
};
}
@helper NonProductionBanner() {
string message;
if (EnvironmentMessages.TryGetValue(Configuration.EnvironmentName, out message))
{
<div class="banner-yellow">
@message
</div>
}
}
@helper PreviousNextPager(IPreviousNextPager pager)
{
if (pager.HasNextPage || pager.HasPreviousPage)
{
<ul class="pager">
<li class="previous">
@if (pager.HasPreviousPage)
{
<a href="@pager.PreviousPageUrl" title="Go to the previous page.">Previous</a>
}
else
{
<text>Previous</text>
}
</li>
<li class="next">
@if (pager.HasNextPage)
{
<a href="@pager.NextPageUrl" title="Go to the next page.">Next</a>
}
else
{
<text>Next</text>
}
</li>
</ul>
}
}
@helper Option(string value, string label, string currentValue)
{
<option value="@value" @if (value == currentValue)
{
<text>selected="selected"</text>
}>@label</option>
}
@helper UploadSequence(int currentStep)
{
<ol class="sequence">
@SequenceStep(1, "Upload", currentStep)
@SequenceStep(2, "Verify Details", currentStep)
@SequenceStep(3, "Enjoy", currentStep)
</ol>
<div class="clear-fix"><!--Sad Panda--></div>
}
@helper SequenceStep(int step, string caption, int currentStep)
{
if (currentStep > step)
{
<li class="past">@caption</li>
}
else if (currentStep == step)
{
<li class="current">@caption</li>
}
else
{
<li>@caption</li>
}
}
@helper OwnersGravatar(IEnumerable<User> owners, int size, UrlHelper url, bool showName = true)
{
<ul class="owners">
@foreach (var owner in owners)
{
<li>
@OwnerGravatar(owner, size, url, showName)
</li>
}
</ul>
}
@helper OwnerGravatar(User owner, int size, UrlHelper url, bool showName = true)
{
<a class="owner" href="@url.User(owner)" title="@owner.Username">
@GravatarImage(owner.EmailAddress, owner.Username, size)
@if (showName)
{<text>@owner.Username</text>
}
</a>
}
@helper GravatarImage(string email, string username, int size)
{
if (!String.IsNullOrWhiteSpace(email))
{
var gravatarHtml = Gravatar.GetHtml(email, size, "retro", GravatarRating.G, attributes: new { width = size, height = size, title = username, @class = "owner-image" });
if (gravatarHtml != null && Request.IsSecureConnection)
{
gravatarHtml = new HtmlString(gravatarHtml.ToHtmlString().Replace("http://www.gravatar.com/", "https://secure.gravatar.com/"));
}
@gravatarHtml
}
}
@helper ReleaseTag()
{
// Using ConfigurationManager because these settings are part of the cspkg itself and thus are always in web.config.
string sha = ConfigurationManager.AppSettings["Gallery.ReleaseSha"];
string branch = ConfigurationManager.AppSettings["Gallery.ReleaseBranch"];
string time = ConfigurationManager.AppSettings["Gallery.ReleaseTime"];
<p id="releaseTag">
This is the NuGet Gallery.
@if (!String.IsNullOrEmpty(sha) && !String.IsNullOrEmpty(branch) && !String.IsNullOrEmpty(time))
{
<text>
Deployed from <a href="https://github.com/NuGet/NuGetGallery/commit/@sha" title="View the commit.">@sha.Substring(0, Math.Min(sha.Length, 10))</a>.
Originally built on <a href="https://github.com/NuGet/NuGetGallery/branches/@branch" title="View the branch.">@branch</a>
at @time.
</text>
}
@* A little quick-n-dirty code to display the current machine *@
@* In Azure, we want the Instance ID. The Machine Name is total garbage *@
@try {
if(RoleEnvironment.IsAvailable) {
<text>You are on @RoleEnvironment.CurrentRoleInstance.Id.</text>
} else {
<text>You are on @Environment.MachineName.</text>
}
} catch(Exception) {
@* Azure SDK not installed so we can't even run RoleEnvironment.IsAvailable. Just use Machine Name *@
<text>You are on @Environment.MachineName.</text>
}
</p>
}
@helper AnalyticsScript()
{
var propertyId = ConfigurationManager.AppSettings["Gallery:GoogleAnalyticsPropertyId"];
if (propertyId != null)
{
@Analytics.GetGoogleHtml(propertyId)
}
}