mirror of https://github.com/abpframework/abp.git
62 changed files with 449 additions and 209 deletions
@ -1,16 +0,0 @@ |
|||
$(function () { |
|||
$('.dropdown-menu a.dropdown-toggle').on('click', function (e) { |
|||
if (!$(this).next().hasClass('show')) { |
|||
$(this).parents('.dropdown-menu').first().find('.show').removeClass("show"); |
|||
} |
|||
|
|||
var $subMenu = $(this).next(".dropdown-menu"); |
|||
$subMenu.toggleClass('show'); |
|||
|
|||
$(this).parents('li.nav-item.dropdown.show').on('hidden.bs.dropdown', function (e) { |
|||
$('.dropdown-submenu .show').removeClass("show"); |
|||
}); |
|||
|
|||
return false; |
|||
}); |
|||
}); |
|||
@ -0,0 +1,11 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly |
|||
{ |
|||
public class CookieOptions |
|||
{ |
|||
public DateTimeOffset? ExpireDate { get; set; } |
|||
public string Path { get; set; } |
|||
public bool Secure { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
using System.Threading.Tasks; |
|||
using Microsoft.JSInterop; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly |
|||
{ |
|||
[Dependency(ReplaceServices = true)] |
|||
public class CookieService : ICookieService, ITransientDependency |
|||
{ |
|||
public IJSRuntime JsRuntime { get; } |
|||
|
|||
public CookieService(IJSRuntime jsRuntime) |
|||
{ |
|||
JsRuntime = jsRuntime; |
|||
} |
|||
|
|||
public async ValueTask SetAsync(string key, string value, CookieOptions options) |
|||
{ |
|||
await JsRuntime.InvokeVoidAsync("abp.utils.setCookieValue", key, value, options?.ExpireDate?.ToString("r"), options?.Path, options?.Secure); |
|||
} |
|||
|
|||
public async ValueTask<string> GetAsync(string key) |
|||
{ |
|||
return await JsRuntime.InvokeAsync<string>("abp.utils.getCookieValue", key); |
|||
} |
|||
|
|||
public async ValueTask DeleteAsync(string key, string path = null) |
|||
{ |
|||
await JsRuntime.InvokeVoidAsync("abp.utils.deleteCookie", key); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly |
|||
{ |
|||
public interface ICookieService |
|||
{ |
|||
public ValueTask SetAsync(string key, string value, CookieOptions options = null); |
|||
public ValueTask<string> GetAsync(string key); |
|||
public ValueTask DeleteAsync(string key, string path = null); |
|||
} |
|||
} |
|||
@ -0,0 +1,80 @@ |
|||
var abp = abp || {}; |
|||
(function () { |
|||
abp.utils = abp.utils || {}; |
|||
/** |
|||
* Sets a cookie value for given key. |
|||
* This is a simple implementation created to be used by ABP. |
|||
* Please use a complete cookie library if you need. |
|||
* @param {string} key |
|||
* @param {string} value |
|||
* @param {string} expireDate (optional). If not specified the cookie will expire at the end of session. |
|||
* @param {string} path (optional) |
|||
* @param {bool} secure (optional) |
|||
*/ |
|||
abp.utils.setCookieValue = function (key, value, expireDate, path, secure) { |
|||
var cookieValue = encodeURIComponent(key) + '='; |
|||
if (value) { |
|||
cookieValue = cookieValue + encodeURIComponent(value); |
|||
} |
|||
|
|||
if (expireDate) { |
|||
cookieValue = cookieValue + "; expires=" + expireDate; |
|||
} |
|||
|
|||
if (path) { |
|||
cookieValue = cookieValue + "; path=" + path; |
|||
} |
|||
|
|||
if (secure) { |
|||
cookieValue = cookieValue + "; secure"; |
|||
} |
|||
|
|||
document.cookie = cookieValue; |
|||
}; |
|||
|
|||
/** |
|||
* Gets a cookie with given key. |
|||
* This is a simple implementation created to be used by ABP. |
|||
* Please use a complete cookie library if you need. |
|||
* @param {string} key |
|||
* @returns {string} Cookie value or null |
|||
*/ |
|||
abp.utils.getCookieValue = function (key) { |
|||
var equalities = document.cookie.split('; '); |
|||
for (var i = 0; i < equalities.length; i++) { |
|||
if (!equalities[i]) { |
|||
continue; |
|||
} |
|||
|
|||
var splitted = equalities[i].split('='); |
|||
if (splitted.length != 2) { |
|||
continue; |
|||
} |
|||
|
|||
if (decodeURIComponent(splitted[0]) === key) { |
|||
return decodeURIComponent(splitted[1] || ''); |
|||
} |
|||
} |
|||
|
|||
return null; |
|||
}; |
|||
|
|||
/** |
|||
* Deletes cookie for given key. |
|||
* This is a simple implementation created to be used by ABP. |
|||
* Please use a complete cookie library if you need. |
|||
* @param {string} key |
|||
* @param {string} path (optional) |
|||
*/ |
|||
abp.utils.deleteCookie = function (key, path) { |
|||
var cookieValue = encodeURIComponent(key) + '='; |
|||
|
|||
cookieValue = cookieValue + "; expires=" + (new Date(new Date().getTime() - 86400000)).toUTCString(); |
|||
|
|||
if (path) { |
|||
cookieValue = cookieValue + "; path=" + path; |
|||
} |
|||
|
|||
document.cookie = cookieValue; |
|||
} |
|||
})(); |
|||
@ -0,0 +1,20 @@ |
|||
using Blazorise; |
|||
|
|||
namespace Volo.Abp.BlazoriseUI |
|||
{ |
|||
public class BreadcrumbItem |
|||
{ |
|||
public string Text { get; set; } |
|||
|
|||
public object Icon { get; set; } |
|||
|
|||
public string Url { get; set; } |
|||
|
|||
public BreadcrumbItem(string text, string url = null, object icon = null) |
|||
{ |
|||
Text = text; |
|||
Url = url; |
|||
Icon = icon; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
<Row Class="entry-row"> |
|||
<Column ColumnSize="ColumnSize.IsAuto"> |
|||
<h1 class="content-header-title">@Title</h1> |
|||
</Column> |
|||
@if (BreadcrumbItems.Any()) |
|||
{ |
|||
<Column ColumnSize="ColumnSize.IsAuto.OnWidescreen" Padding="Padding.Is0.FromLeft.OnWidescreen"> |
|||
<Breadcrumb Mode="@(BreadcrumbShowCurrent ? BreadcrumbMode.Auto : BreadcrumbMode.None)"> |
|||
@if (BreadcrumbShowHome) |
|||
{ |
|||
<BreadcrumbItem> |
|||
<BreadcrumbLink To="/"> |
|||
<Icon Name="IconName.Home" /> |
|||
</BreadcrumbLink> |
|||
</BreadcrumbItem> |
|||
} |
|||
@foreach (var item in BreadcrumbItems) |
|||
{ |
|||
<BreadcrumbItem> |
|||
<BreadcrumbLink To="@item.Url"> |
|||
@if (item.Icon != null) |
|||
{ |
|||
<Icon Name="@item.Icon" /> |
|||
} |
|||
@item.Text |
|||
</BreadcrumbLink> |
|||
</BreadcrumbItem> |
|||
} |
|||
</Breadcrumb> |
|||
</Column> |
|||
} |
|||
<Column> |
|||
<Row Class="justify-content-end mx-n1"> |
|||
@ChildContent |
|||
</Row> |
|||
</Column> |
|||
</Row> |
|||
@ -0,0 +1,29 @@ |
|||
using System.Collections.Generic; |
|||
using Blazorise; |
|||
using Microsoft.AspNetCore.Components; |
|||
|
|||
namespace Volo.Abp.BlazoriseUI.Components |
|||
{ |
|||
public partial class PageHeader : ComponentBase |
|||
{ |
|||
[Parameter] |
|||
public string Title { get; set; } |
|||
|
|||
[Parameter] |
|||
public bool BreadcrumbShowHome { get; set; } = true; |
|||
|
|||
[Parameter] |
|||
public bool BreadcrumbShowCurrent { get; set; } = true; |
|||
|
|||
[Parameter] |
|||
public RenderFragment ChildContent { get; set; } |
|||
|
|||
[Parameter] |
|||
public List<BreadcrumbItem> BreadcrumbItems { get; set; } |
|||
|
|||
public PageHeader() |
|||
{ |
|||
BreadcrumbItems = new List<BreadcrumbItem>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,90 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Shouldly; |
|||
using Volo.Abp.Domain.Repositories; |
|||
using Volo.Abp.TestApp.Domain; |
|||
using Volo.Abp.TestApp.Testing; |
|||
using Volo.Abp.Uow; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.MongoDB.Transactions |
|||
{ |
|||
public class Transaction_Tests : TestAppTestBase<AbpMongoDbTestModule> |
|||
{ |
|||
private readonly IBasicRepository<Person, Guid> _personRepository; |
|||
private readonly IUnitOfWorkManager _unitOfWorkManager; |
|||
|
|||
public Transaction_Tests() |
|||
{ |
|||
_personRepository = GetRequiredService<IBasicRepository<Person, Guid>>(); |
|||
_unitOfWorkManager = GetRequiredService<IUnitOfWorkManager>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Rollback_Transaction_When_An_Exception_Is_Thrown() |
|||
{ |
|||
var personId = Guid.NewGuid(); |
|||
const string exceptionMessage = "thrown to rollback the transaction!"; |
|||
|
|||
try |
|||
{ |
|||
await WithUnitOfWorkAsync(new AbpUnitOfWorkOptions { IsTransactional = true }, async () => |
|||
{ |
|||
await _personRepository.InsertAsync(new Person(personId, "Adam", 42)); |
|||
throw new Exception(exceptionMessage); |
|||
}); |
|||
} |
|||
catch (Exception e) when (e.Message == exceptionMessage) |
|||
{ |
|||
|
|||
} |
|||
|
|||
var person = await _personRepository.FindAsync(personId); |
|||
person.ShouldBeNull(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Rollback_Transaction_Manually() |
|||
{ |
|||
var personId = Guid.NewGuid(); |
|||
|
|||
await WithUnitOfWorkAsync(new AbpUnitOfWorkOptions { IsTransactional = true }, async () => |
|||
{ |
|||
_unitOfWorkManager.Current.ShouldNotBeNull(); |
|||
|
|||
await _personRepository.InsertAsync(new Person(personId, "Adam", 42)); |
|||
|
|||
await _unitOfWorkManager.Current.RollbackAsync(); |
|||
}); |
|||
|
|||
var person = await _personRepository.FindAsync(personId); |
|||
person.ShouldBeNull(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Rollback_Transaction_Manually_With_Double_DbContext_Transaction() |
|||
{ |
|||
var personId = Guid.NewGuid(); |
|||
var bookId = Guid.NewGuid(); |
|||
|
|||
using (var scope = ServiceProvider.CreateScope()) |
|||
{ |
|||
var uowManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>(); |
|||
|
|||
using (uowManager.Begin(new AbpUnitOfWorkOptions { IsTransactional = true })) |
|||
{ |
|||
_unitOfWorkManager.Current.ShouldNotBeNull(); |
|||
|
|||
await _personRepository.InsertAsync(new Person(personId, "Adam", 42)); |
|||
|
|||
await _unitOfWorkManager.Current.SaveChangesAsync(); |
|||
|
|||
//Will automatically rollback since not called the Complete!
|
|||
} |
|||
} |
|||
|
|||
(await _personRepository.FindAsync(personId)).ShouldBeNull(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,5 +1,6 @@ |
|||
@using Microsoft.AspNetCore.Components.Web |
|||
@using Volo.Abp.AspNetCore.Components.WebAssembly |
|||
@using Volo.Abp.BlazoriseUI |
|||
@using Volo.Abp.BlazoriseUI.Components |
|||
@using Blazorise |
|||
@using Blazorise.DataGrid |
|||
Loading…
Reference in new issue