Skip to content

Commit e20718c

Browse files
Added Support of Generic Toast Libraries. (Like DevExtreme Toasts) - Sample Project
1 parent e5c5f14 commit e20718c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+39944
-2
lines changed

NToastNotify.sln

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.29009.5
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.1.31911.260
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NToastNotify", "src\NToastNotify.csproj", "{70FC6753-E13C-4FF0-8FC1-914B9478A11F}"
77
EndProject
@@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Toastr", "samples\Toastr\To
1313
EndProject
1414
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Noty", "samples\Noty\Noty.csproj", "{672B06FE-A2B8-49AF-9424-C4B942E54E8F}"
1515
EndProject
16+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GenericDevExtreme", "samples\GenericDevExtreme\GenericDevExtreme.csproj", "{FB260842-43D1-46B6-B921-8A6C436BC526}"
17+
EndProject
1618
Global
1719
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1820
Debug|Any CPU = Debug|Any CPU
@@ -71,13 +73,26 @@ Global
7173
{672B06FE-A2B8-49AF-9424-C4B942E54E8F}.Release|x64.Build.0 = Release|Any CPU
7274
{672B06FE-A2B8-49AF-9424-C4B942E54E8F}.Release|x86.ActiveCfg = Release|Any CPU
7375
{672B06FE-A2B8-49AF-9424-C4B942E54E8F}.Release|x86.Build.0 = Release|Any CPU
76+
{FB260842-43D1-46B6-B921-8A6C436BC526}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
77+
{FB260842-43D1-46B6-B921-8A6C436BC526}.Debug|Any CPU.Build.0 = Debug|Any CPU
78+
{FB260842-43D1-46B6-B921-8A6C436BC526}.Debug|x64.ActiveCfg = Debug|Any CPU
79+
{FB260842-43D1-46B6-B921-8A6C436BC526}.Debug|x64.Build.0 = Debug|Any CPU
80+
{FB260842-43D1-46B6-B921-8A6C436BC526}.Debug|x86.ActiveCfg = Debug|Any CPU
81+
{FB260842-43D1-46B6-B921-8A6C436BC526}.Debug|x86.Build.0 = Debug|Any CPU
82+
{FB260842-43D1-46B6-B921-8A6C436BC526}.Release|Any CPU.ActiveCfg = Release|Any CPU
83+
{FB260842-43D1-46B6-B921-8A6C436BC526}.Release|Any CPU.Build.0 = Release|Any CPU
84+
{FB260842-43D1-46B6-B921-8A6C436BC526}.Release|x64.ActiveCfg = Release|Any CPU
85+
{FB260842-43D1-46B6-B921-8A6C436BC526}.Release|x64.Build.0 = Release|Any CPU
86+
{FB260842-43D1-46B6-B921-8A6C436BC526}.Release|x86.ActiveCfg = Release|Any CPU
87+
{FB260842-43D1-46B6-B921-8A6C436BC526}.Release|x86.Build.0 = Release|Any CPU
7488
EndGlobalSection
7589
GlobalSection(SolutionProperties) = preSolution
7690
HideSolutionNode = FALSE
7791
EndGlobalSection
7892
GlobalSection(NestedProjects) = preSolution
7993
{2325625E-C8BC-44DF-88FB-DF4FA0E41765} = {02286F62-91A5-4704-ABA3-F46D1B445717}
8094
{672B06FE-A2B8-49AF-9424-C4B942E54E8F} = {02286F62-91A5-4704-ABA3-F46D1B445717}
95+
{FB260842-43D1-46B6-B921-8A6C436BC526} = {02286F62-91A5-4704-ABA3-F46D1B445717}
8196
EndGlobalSection
8297
GlobalSection(ExtensibilityGlobals) = postSolution
8398
SolutionGuid = {D4720901-6BAC-48CE-A03E-85759AC6B66E}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using NToastNotify;
2+
using NToastNotify.Helpers;
3+
4+
namespace GenericDevExtreme
5+
{
6+
public class DevExtremeToastOptions : GenericOptions
7+
{
8+
public int DisplayTime { get; set; }
9+
10+
public override string Json => this.ToJson();
11+
}
12+
}

samples/GenericDevExtreme/Dockerfile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
2+
WORKDIR /app
3+
EXPOSE 80
4+
EXPOSE 443
5+
6+
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
7+
WORKDIR /src
8+
COPY ["GenericDevExtreme.csproj", "."]
9+
RUN dotnet restore "GenericDevExtreme.csproj"
10+
COPY . .
11+
RUN dotnet build "GenericDevExtreme.csproj" -c Release -o /app/build
12+
13+
FROM build AS publish
14+
RUN dotnet publish "GenericDevExtreme.csproj" -c Release -o /app/publish
15+
16+
FROM base AS final
17+
WORKDIR /app
18+
COPY --from=publish /app/publish .
19+
ENTRYPOINT ["dotnet", "GenericDevExtreme.dll"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<Nullable>enable</Nullable>
5+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
6+
<LangVersion>latest</LangVersion>
7+
<TargetFramework>net6.0</TargetFramework>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="NToastNotify" Version="7.0.0" />
12+
</ItemGroup>
13+
14+
<!--Comment before pushing changes-->
15+
<ItemGroup>
16+
<ProjectReference Include="..\..\src\NToastNotify.csproj" />
17+
</ItemGroup>
18+
19+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@page
2+
@model AboutModel
3+
@{
4+
ViewData["Title"] = "Privacy Policy";
5+
}
6+
<h2>Should simply be redirected to /privacy</h2>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
using NToastNotify;
4+
5+
namespace GenericDevExtreme.Pages
6+
{
7+
public class AboutModel : PageModel
8+
{
9+
private readonly IToastNotification _toastNotification;
10+
11+
public AboutModel(IToastNotification toastNotification)
12+
{
13+
_toastNotification = toastNotification;
14+
}
15+
public IActionResult OnGet()
16+
{
17+
_toastNotification.AddWarningToastMessage("This message is from About page before being redirected to Privacy page");
18+
return RedirectToPage("/Privacy");
19+
}
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@page
2+
@model AjaxModel
3+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.AspNetCore.Mvc.RazorPages;
4+
using NToastNotify;
5+
6+
namespace GenericDevExtreme.Pages
7+
{
8+
public class AjaxModel : PageModel
9+
{
10+
private readonly IToastNotification _toastNotification;
11+
12+
public AjaxModel(IToastNotification toastNotification)
13+
{
14+
_toastNotification = toastNotification;
15+
}
16+
public JsonResult OnGet(string type)
17+
{
18+
System.Threading.Thread.Sleep(2000);
19+
_toastNotification.AddSuccessToastMessage($"This toast is shown on Ajax request. Type: {type} " + DateTime.Now.ToLongTimeString());
20+
return new JsonResult(new { ok = true });
21+
}
22+
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@page
2+
@model ErrorModel
3+
@{
4+
ViewData["Title"] = "Error";
5+
}
6+
7+
<h1 class="text-danger">Error.</h1>
8+
<h2 class="text-danger">An error occurred while processing your request.</h2>
9+
10+
@if (Model.ShowRequestId)
11+
{
12+
<p>
13+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
14+
</p>
15+
}
16+
17+
<h3>Development Mode</h3>
18+
<p>
19+
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
20+
</p>
21+
<p>
22+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
23+
It can result in displaying sensitive information from exceptions to end users.
24+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
25+
and restarting the app.
26+
</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.AspNetCore.Mvc.RazorPages;
8+
9+
namespace GenericDevExtreme.Pages
10+
{
11+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
12+
public class ErrorModel : PageModel
13+
{
14+
public string? RequestId { get; set; }
15+
16+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
17+
18+
public void OnGet()
19+
{
20+
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
21+
}
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@page
2+
@model GenericDevExtreme.Pages.FormPostModel
3+
@{
4+
ViewData["Title"] = "FormPost";
5+
Layout = "~/Pages/Shared/_Layout.cshtml";
6+
}
7+
8+
<h1>FormPost</h1>
9+
<form method="post">
10+
<div>
11+
<label>Input</label>
12+
<input name="input" type="text" />
13+
</div>
14+
<div>
15+
<label>Redirect after post</label>
16+
<input name="redirect" type="checkbox" />
17+
</div>
18+
<button type="submit">Submit</button>
19+
</form>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
6+
using Microsoft.AspNetCore.Mvc.RazorPages;
7+
using NToastNotify;
8+
using NToastNotify.Helpers;
9+
10+
namespace GenericDevExtreme.Pages
11+
{
12+
public class FormPostModel : PageModel
13+
{
14+
private readonly IToastNotification _toastNotification;
15+
16+
public FormPostModel(IToastNotification toastNotification)
17+
{
18+
_toastNotification = toastNotification;
19+
}
20+
public void OnGet()
21+
{
22+
23+
}
24+
public IActionResult OnPost(string input, string redirect)
25+
{
26+
_toastNotification.AddSuccessToastMessage("Input received: " + input, new DevExtremeToastOptions { DisplayTime = 3000 });
27+
if (redirect == "on")
28+
return RedirectToPage("/Privacy");
29+
return Page();
30+
}
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@page
2+
@model IndexModel
3+
@{
4+
ViewData["Title"] = "Home page";
5+
}
6+
7+
<div class="text-center">
8+
<h1 class="display-4">Welcome</h1>
9+
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
10+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Reflection;
3+
using Microsoft.AspNetCore.Mvc.RazorPages;
4+
using NToastNotify;
5+
6+
namespace GenericDevExtreme.Pages
7+
{
8+
public class IndexModel : PageModel
9+
{
10+
private readonly string? _version;
11+
private readonly IToastNotification _toastNotification;
12+
//private readonly ToastrNotification _toastNotification;
13+
14+
public IndexModel(IToastNotification toastNotification)
15+
{
16+
_version = Assembly.GetAssembly(typeof(IToastNotification))?.GetName().Version?.ToString() ?? throw new Exception("Version not found");
17+
_toastNotification = toastNotification;
18+
//_toastNotification = toastNotification as ToastrNotification;
19+
}
20+
public void OnGet()
21+
{
22+
//Success
23+
_toastNotification.AddSuccessToastMessage("Same for success message. Version: " + _version, new DevExtremeToastOptions()
24+
{
25+
DisplayTime = 6000
26+
});
27+
// Success with default options (taking into account the overwritten defaults when initializing in Startup.cs)
28+
_toastNotification.AddSuccessToastMessage();
29+
30+
//Info
31+
_toastNotification.AddInfoToastMessage();
32+
_toastNotification.AddInfoToastMessage("This is an info toast. Version: " + _version, new DevExtremeToastOptions()
33+
{
34+
DisplayTime = 8000
35+
});
36+
37+
//Warning
38+
_toastNotification.AddWarningToastMessage();
39+
40+
//Error
41+
_toastNotification.AddErrorToastMessage("Custom Error Message. Version: " + _version, new DevExtremeToastOptions() { DisplayTime = 3000 });
42+
}
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
@page
2+
@model PrivacyModel
3+
@{
4+
ViewData["Title"] = "Privacy Policy";
5+
}
6+
<h1>@ViewData["Title"]</h1>
7+
8+
<p>Use this page to detail your site's privacy policy.</p>
9+
10+
<h4 id="message">AJAX Messages</h4>
11+
12+
<script>
13+
window.addEventListener('load', function () {
14+
setTimeout(function () {
15+
$('#message').text('Making a native fetch request and show notification.');
16+
fetch('/Ajax?type=fetch').then(function (response) {
17+
var messages = nToastNotify.getMessagesFromFetchResponse(response);
18+
nToastNotify.showMessages(messages);
19+
$('#message').text('Making an XMLHTTPRequest (AJAX) and show notification.');
20+
$.ajax({
21+
url: '/Ajax?type=xmlhttp',
22+
}).then(function () {
23+
$('#message').text('Again : Making an XMLHTTPRequest (AJAX) and show notification.');
24+
$.ajax({
25+
url: '/Ajax?type=xmlhttp'
26+
}).then(function () {
27+
$('#message').text('Again : native fetch request and show notification.');
28+
fetch('/Ajax?type=fetch').then(function (response) {
29+
var messages = nToastNotify.getMessagesFromFetchResponse(response);
30+
nToastNotify.showMessages(messages);
31+
});
32+
})
33+
});
34+
});
35+
}, 2000)
36+
})
37+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
6+
using Microsoft.AspNetCore.Mvc.RazorPages;
7+
using NToastNotify;
8+
9+
namespace GenericDevExtreme.Pages
10+
{
11+
public class PrivacyModel : PageModel
12+
{
13+
private readonly IToastNotification _toastNotification;
14+
15+
public PrivacyModel(IToastNotification toastNotification)
16+
{
17+
_toastNotification = toastNotification;
18+
}
19+
public void OnGet()
20+
{
21+
_toastNotification.AddInfoToastMessage("Privacy is important");
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)