Skip to content

Commit

Permalink
Feature/addingnewdemosite (#372)
Browse files Browse the repository at this point in the history
* Added new demo web project

* FIxed demo project to be MVC

* Added feature flags to demo website

* Hid unneeded feature flag

* Enabled CORS again

* Cors update

* removed credentials

* tweak to any origin

* Fixed typo in service

* Added feature flag for vertical products to demo
  • Loading branch information
samsmithnz committed Aug 2, 2021
1 parent b83e6dc commit 935c3f4
Show file tree
Hide file tree
Showing 65 changed files with 40,460 additions and 78 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/aspnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ jobs:
run: dotnet publish FeatureFlags/FeatureFlags.Service/FeatureFlags.Service.csproj --configuration ${{ env.dotNetConfiguration }} -p:Version=${{ steps.gitversion.outputs.nuGetVersionV2 }} --output ${{ github.workspace }}/webservice --runtime ${{env.runtimeTarget}} --self-contained false # --self-contained true --runtime ${{env.runtimeTarget}}
- name: DotNet Publish Web Site
run: dotnet publish FeatureFlags/FeatureFlags.Web/FeatureFlags.Web.csproj --configuration ${{ env.dotNetConfiguration }} -p:Version=${{ steps.gitversion.outputs.nuGetVersionV2 }} --output ${{ github.workspace }}/web --runtime ${{env.runtimeTarget}} --self-contained false # --self-contained true --runtime ${{env.runtimeTarget}}
- name: DotNet Publish Demo Web Site
run: dotnet publish FeatureFlags/FeatureFlagsDemo.Web/FeatureFlagsDemo.Web.csproj --configuration ${{ env.dotNetConfiguration }} -p:Version=${{ steps.gitversion.outputs.nuGetVersionV2 }} --output ${{ github.workspace }}/webDemo --runtime ${{env.runtimeTarget}} --self-contained false # --self-contained true --runtime ${{env.runtimeTarget}}

#Publish functional tests
- name: DotNet build functional tests
Expand All @@ -57,7 +59,7 @@ jobs:
- name: Copy chromedriver for functional test
run: copy "FeatureFlags/FeatureFlags.FunctionalTests/bin/${{ env.dotNetConfiguration }}/${{ env.dotNetVersion }}/${{env.runtimeTarget}}/chromedriver.exe" "${{ github.workspace }}/functionalTests"
shell: powershell
- name: DotNet restore functional tests to get correct NewtonSoft version
- name: DotNet restore functional tests to get correct Newtonsoft version
run: dotnet restore FeatureFlags/FeatureFlags.FunctionalTests/FeatureFlags.FunctionalTests.csproj
- name: Copy new NewtonSoft version for functional test
run: copy "FeatureFlags/FeatureFlags.FunctionalTests/bin/${{ env.dotNetConfiguration }}/${{ env.dotNetVersion }}/${{env.runtimeTarget}}/Newtonsoft.Json.dll" "${{ github.workspace }}/functionalTests"
Expand All @@ -75,6 +77,11 @@ jobs:
with:
name: webapp
path: ${{ github.workspace }}/web
- name: Upload website build artifacts back to GitHub
uses: actions/upload-artifact@master
with:
name: webappDemo
path: ${{ github.workspace }}/webDemo
- name: Upload function test build artifacts back to GitHub
uses: actions/upload-artifact@master
with:
Expand Down Expand Up @@ -142,6 +149,10 @@ jobs:
uses: actions/download-artifact@v1.0.0
with:
name: webapp
- name: Download webappDemo artifact
uses: actions/download-artifact@v1.0.0
with:
name: webappDemo
- name: Download functionaltests artifact
uses: actions/download-artifact@v1.0.0
with:
Expand All @@ -162,6 +173,12 @@ jobs:
app-name: featureflags-prod-eu-web
package: webapp
#slot-name: staging
- name: Deploy website demo to Azure WebApp
uses: Azure/webapps-deploy@v1
with:
app-name: featureflagsdemo-prod-eu-web
package: webappDemo
#slot-name: staging

# Run functional tests on staging slots
- name: Functional Tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void GotoFeatureFlagsWebAboutPageTest()
[TestInitialize]
public void SetupTests()
{
ChromeOptions chromeOptions = new ChromeOptions();
ChromeOptions chromeOptions = new();
chromeOptions.AddArguments("headless");
//_driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), chromeOptions);
_driver = new ChromeDriver(chromeOptions);
Expand Down
8 changes: 6 additions & 2 deletions FeatureFlags/FeatureFlags.Service/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using FeatureFlags.Service.DataAccess;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;
Expand Down Expand Up @@ -46,7 +45,12 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseHttpsRedirection();

app.UseRouting();
app.UseCors();

// global cors policy
app.UseCors(x => x
.AllowAnyMethod()
.AllowAnyHeader()
.AllowAnyOrigin());

app.UseEndpoints(endpoints =>
{
Expand Down
8 changes: 1 addition & 7 deletions FeatureFlags/FeatureFlags.Web/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using FeatureFlags.Web.Controllers;
using FeatureFlags.Web.Controllers;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand Down
133 changes: 68 additions & 65 deletions FeatureFlags/FeatureFlags.Web/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -36,90 +36,93 @@ else
{
foreach (FeatureFlag item in Model.Data)
{
<tr>
<td>@item.Name</td>
<td>@item.Description</td>
<td>
@Html.CheckBoxFor(x => item.PRIsEnabled, new { id = item.Name + "_pr", data_toggle = "toggle", data_onstyle = "success", onchange = "updateToggle(this)" })<br />
<span>@item.PRViewCount views</span><br />
@if (item.PRViewCount > 0 && item.PRLastViewDate != null)
{
double totalPRDays = Math.Round((DateTime.Now - (DateTime)item.PRLastViewDate).TotalDays, 0);
if (totalPRDays == 0)
if (item.Name != "UnitTestFeatureFlag01")
{
<tr>
<td>@item.Name</td>
<td>@item.Description</td>
<td>
@Html.CheckBoxFor(x => item.PRIsEnabled, new { id = item.Name + "_pr", data_toggle = "toggle", data_onstyle = "success", onchange = "updateToggle(this)" })<br />
<span>@item.PRViewCount views</span><br />
@if (item.PRViewCount > 0 && item.PRLastViewDate != null)
{
<span>(last used today)</span>
double totalPRDays = Math.Round((DateTime.Now - (DateTime)item.PRLastViewDate).TotalDays, 0);
if (totalPRDays == 0)
{
<span>(last used today)</span>
}
else
{
<span>(last used @(totalPRDays.ToString("0")) days ago)</span>
}
}
else
{
<span>(last used @(totalPRDays.ToString("0")) days ago)</span>
<span>(never used)</span>
}
}
else
{
<span>(never used)</span>
}
</td>
<td>
@Html.CheckBoxFor(x => item.DevIsEnabled, new { id = item.Name + "_dev", data_toggle = "toggle", data_onstyle = "success", onchange = "updateToggle(this)" })<br />
<span>@item.DevViewCount views</span><br />
@if (item.DevViewCount > 0 && item.DevLastViewDate != null)
{
double totalDevDays = Math.Round((DateTime.Now - (DateTime)item.DevLastViewDate).TotalDays, 0);
if (totalDevDays == 0)
</td>
<td>
@Html.CheckBoxFor(x => item.DevIsEnabled, new { id = item.Name + "_dev", data_toggle = "toggle", data_onstyle = "success", onchange = "updateToggle(this)" })<br />
<span>@item.DevViewCount views</span><br />
@if (item.DevViewCount > 0 && item.DevLastViewDate != null)
{
<span>(last used today)</span>
double totalDevDays = Math.Round((DateTime.Now - (DateTime)item.DevLastViewDate).TotalDays, 0);
if (totalDevDays == 0)
{
<span>(last used today)</span>
}
else
{
<span>(last used @(totalDevDays.ToString("0")) days ago)</span>
}
}
else
{
<span>(last used @(totalDevDays.ToString("0")) days ago)</span>
<span>(never used)</span>
}
}
else
{
<span>(never used)</span>
}
</td>
<td>
@Html.CheckBoxFor(x => item.QAIsEnabled, new { id = item.Name + "_qa", data_toggle = "toggle", data_onstyle = "success", onchange = "updateToggle(this)" })<br />
<span>@item.QAViewCount views</span><br />
@if (item.QAViewCount > 0 && item.QALastViewDate != null)
{
double totalQADays = Math.Round((DateTime.Now - (DateTime)item.QALastViewDate).TotalDays, 0);
if (totalQADays == 0)
</td>
<td>
@Html.CheckBoxFor(x => item.QAIsEnabled, new { id = item.Name + "_qa", data_toggle = "toggle", data_onstyle = "success", onchange = "updateToggle(this)" })<br />
<span>@item.QAViewCount views</span><br />
@if (item.QAViewCount > 0 && item.QALastViewDate != null)
{
<span>(last used today)</span>
double totalQADays = Math.Round((DateTime.Now - (DateTime)item.QALastViewDate).TotalDays, 0);
if (totalQADays == 0)
{
<span>(last used today)</span>
}
else
{
<span>(last used @(totalQADays.ToString("0")) days ago)</span>
}
}
else
{
<span>(last used @(totalQADays.ToString("0")) days ago)</span>
<span>(never used)</span>
}
}
else
{
<span>(never used)</span>
}
</td>
<td>
@Html.CheckBoxFor(x => item.ProdIsEnabled, new { id = item.Name + "_prod", data_toggle = "toggle", data_onstyle = "success", onchange = "updateToggle(this)" })<br />
<span>@item.ProdViewCount views</span><br />
@if (item.ProdViewCount > 0 && item.ProdLastViewDate != null)
{
double totalProdDays = Math.Round((DateTime.Now - (DateTime)item.ProdLastViewDate).TotalDays, 0);
if (totalProdDays == 0)
</td>
<td>
@Html.CheckBoxFor(x => item.ProdIsEnabled, new { id = item.Name + "_prod", data_toggle = "toggle", data_onstyle = "success", onchange = "updateToggle(this)" })<br />
<span>@item.ProdViewCount views</span><br />
@if (item.ProdViewCount > 0 && item.ProdLastViewDate != null)
{
<span>(last used today)</span>
double totalProdDays = Math.Round((DateTime.Now - (DateTime)item.ProdLastViewDate).TotalDays, 0);
if (totalProdDays == 0)
{
<span>(last used today)</span>
}
else
{
<span>(last used @(totalProdDays.ToString("0")) days ago)</span>
}
}
else
{
<span>(last used @(totalProdDays.ToString("0")) days ago)</span>
<span>(never used)</span>
}
}
else
{
<span>(never used)</span>
}
</td>
</tr>
</td>
</tr>
}
}
}
</table>
Expand All @@ -132,7 +135,7 @@ else
var environment = featureDetails[1]
var isEnabled = item.checked;
$.ajax({
url: "https://featureflags-data-eu-service.azurewebsites.net/api/FeatureFlags/SaveFeatureFlagState?name=" + name + "&environment=" + environment + "&isEnabled=" + isEnabled,
url: "https://featureflags-prod-eu-service.azurewebsites.net/api/FeatureFlags/SaveFeatureFlagState?name=" + name + "&environment=" + environment + "&isEnabled=" + isEnabled,
success: function (resultData) {
location.reload();
}
Expand Down
10 changes: 8 additions & 2 deletions FeatureFlags/FeatureFlags.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29230.47
# Visual Studio Version 17
VisualStudioVersion = 17.0.31521.260
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FeatureFlags.Tests", "FeatureFlags.Tests\FeatureFlags.Tests.csproj", "{C3D05BC7-FCD1-4FD8-9FF2-CB04D1F382DE}"
EndProject
Expand All @@ -24,6 +24,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FeatureFlags.Service", "FeatureFlags.Service\FeatureFlags.Service.csproj", "{9B9CCB54-5594-44C0-962A-92C92366B007}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FeatureFlagsDemo.Web", "FeatureFlagsDemo.Web\FeatureFlagsDemo.Web.csproj", "{681EF0A2-9CF3-4435-898F-510AE0720060}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -54,6 +56,10 @@ Global
{9B9CCB54-5594-44C0-962A-92C92366B007}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B9CCB54-5594-44C0-962A-92C92366B007}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B9CCB54-5594-44C0-962A-92C92366B007}.Release|Any CPU.Build.0 = Release|Any CPU
{681EF0A2-9CF3-4435-898F-510AE0720060}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{681EF0A2-9CF3-4435-898F-510AE0720060}.Debug|Any CPU.Build.0 = Debug|Any CPU
{681EF0A2-9CF3-4435-898F-510AE0720060}.Release|Any CPU.ActiveCfg = Release|Any CPU
{681EF0A2-9CF3-4435-898F-510AE0720060}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace FeatureFlagsDemo.Web.Controllers
{
public class FeatureFlagsServiceApiClient : IFeatureFlagsServiceApiClient
{
private readonly IConfiguration _configuration;
private readonly HttpClient _client;

public FeatureFlagsServiceApiClient(IConfiguration configuration)
{
_configuration = configuration;
_client = new HttpClient
{
BaseAddress = new Uri(_configuration["AppSettings:FeatureFlagsWebServiceURL"])
};
}

public async Task<bool> CheckFeatureFlag(string name, string environment)
{
if (environment.ToLower().StartsWith("dev") == true)
{
environment = "dev";
}
else if (environment.ToLower().StartsWith("qa") == true || environment.ToLower().StartsWith("test") == true) //sometimes we have a test environment that we want to use qa settings
{
environment = "qa";
}
else if (environment.ToLower().StartsWith("prod") == true)
{
environment = "prod";
}
else if (environment.ToLower().StartsWith("pr") == true) //last so that it doesn't trigger with prod. :P
{
environment = "pr";
}
Uri url = new($"api/FeatureFlags/CheckFeatureFlag?name=" + name + "&environment=" + environment, UriKind.Relative);
return await ReadMessageItem(url);
}

private async Task<bool> ReadMessageItem(Uri url)
{
HttpResponseMessage response = await _client.GetAsync(url);
if (response.IsSuccessStatusCode == false)
{
return (bool)false;
}
else
{
string bodyContent = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<bool>(bodyContent);
}
}
}
}
Loading

0 comments on commit 935c3f4

Please sign in to comment.