Browse Source

Merge branch 'master' into dev

pull/4617/head
mehmet-erim 6 years ago
parent
commit
30fbd67aa2
  1. 51
      docs/en/UI/Angular/Custom-Setting-Page.md
  2. BIN
      docs/en/UI/Angular/images/custom-settings.png
  3. 38
      framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs
  4. 7
      framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoDbAsyncQueryableProvider.cs
  5. 76
      framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Repositories/MongoDbAsyncQueryableProvider_Tests.cs
  6. 10
      framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Repositories/Repository_Basic_Tests.cs
  7. 3
      nupkg/common.ps1

51
docs/en/UI/Angular/Custom-Setting-Page.md

@ -1,39 +1,34 @@
# Custom Setting Page # Custom Setting Page
There are several settings tabs from different modules. You can add custom settings page to your project in 3 steps. There are several settings tabs from different modules. You can add a custom setting page to your project.
1. Create a Component 1. Create a component with the following command:
```js ```bash
import { Select } from '@ngxs/store'; yarn ng generate component my-settings
import { Component } from '@angular/core';
@Component({
selector: 'app-your-custom-settings',
template: `
custom-settings works!
`,
})
export class YourCustomSettingsComponent {
// Your component logic
}
``` ```
2. Add the `YourCustomSettingsComponent` to `declarations` and the `entryComponents` arrays in the `AppModule`. 2. Open the `app.component.ts` and modify the file as shown below:
3. Open the `app.component.ts` and add the below content to the `ngOnInit`
```js ```js
import { addSettingTab } from '@abp/ng.theme.shared'; import { Component } from '@angular/core';
// ... import { SettingTabsService } from '@abp/ng.core'; // imported SettingTabsService
import { MySettingsComponent } from './my-settings/my-settings.component'; // imported MySettingsComponent
ngOnInit() {
addSettingTab({ @Component(/* component metadata */)
component: YourCustomSettingsComponent, export class AppComponent {
name: 'Type here the setting tab title (you can type a localization key, e.g: AbpAccount::Login', constructor(private settingTabs: SettingTabsService) // injected MySettingsComponent
order: 4, {
requiredPolicy: 'type here a policy key' // added below
}); settingTabs.add([
{
name: 'MySettings',
order: 1,
requiredPolicy: 'policy key here',
component: MySettingsComponent,
},
]);
}
} }
``` ```

BIN
docs/en/UI/Angular/images/custom-settings.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

After

Width:  |  Height:  |  Size: 106 KiB

38
framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs

@ -19,7 +19,8 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
{ {
public class MongoDbRepository<TMongoDbContext, TEntity> public class MongoDbRepository<TMongoDbContext, TEntity>
: RepositoryBase<TEntity>, : RepositoryBase<TEntity>,
IMongoDbRepository<TEntity> IMongoDbRepository<TEntity>,
IMongoQueryable<TEntity>
where TMongoDbContext : IAbpMongoDbContext where TMongoDbContext : IAbpMongoDbContext
where TEntity : class, IEntity where TEntity : class, IEntity
{ {
@ -167,7 +168,7 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
} }
public override async Task<TEntity> FindAsync( public override async Task<TEntity> FindAsync(
Expression<Func<TEntity, bool>> predicate, Expression<Func<TEntity, bool>> predicate,
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
@ -322,6 +323,35 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
{ {
throw new AbpDbConcurrencyException("Database operation expected to affect 1 row but actually affected 0 row. Data may have been modified or deleted since entities were loaded. This exception has been thrown on optimistic concurrency check."); throw new AbpDbConcurrencyException("Database operation expected to affect 1 row but actually affected 0 row. Data may have been modified or deleted since entities were loaded. This exception has been thrown on optimistic concurrency check.");
} }
/// <summary>
/// IMongoQueryable<TEntity>
/// </summary>
/// <returns></returns>
public QueryableExecutionModel GetExecutionModel()
{
return GetMongoQueryable().GetExecutionModel();
}
/// <summary>
/// IMongoQueryable<TEntity>
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public IAsyncCursor<TEntity> ToCursor(CancellationToken cancellationToken = new CancellationToken())
{
return GetMongoQueryable().ToCursor(cancellationToken);
}
/// <summary>
/// IMongoQueryable<TEntity>
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<IAsyncCursor<TEntity>> ToCursorAsync(CancellationToken cancellationToken = new CancellationToken())
{
return GetMongoQueryable().ToCursorAsync(cancellationToken);
}
} }
public class MongoDbRepository<TMongoDbContext, TEntity, TKey> public class MongoDbRepository<TMongoDbContext, TEntity, TKey>
@ -331,7 +361,7 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
where TEntity : class, IEntity<TKey> where TEntity : class, IEntity<TKey>
{ {
public IMongoDbRepositoryFilterer<TEntity, TKey> RepositoryFilterer { get; set; } public IMongoDbRepositoryFilterer<TEntity, TKey> RepositoryFilterer { get; set; }
public MongoDbRepository(IMongoDbContextProvider<TMongoDbContext> dbContextProvider) public MongoDbRepository(IMongoDbContextProvider<TMongoDbContext> dbContextProvider)
: base(dbContextProvider) : base(dbContextProvider)
{ {
@ -376,4 +406,4 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
return RepositoryFilterer.CreateEntityFilter(entity, withConcurrencyStamp, concurrencyStamp); return RepositoryFilterer.CreateEntityFilter(entity, withConcurrencyStamp, concurrencyStamp);
} }
} }
} }

7
framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoDbAsyncQueryableProvider.cs

@ -8,6 +8,7 @@ using Volo.Abp.DependencyInjection;
using Volo.Abp.Linq; using Volo.Abp.Linq;
using MongoDB.Driver; using MongoDB.Driver;
using MongoDB.Driver.Linq; using MongoDB.Driver.Linq;
using Volo.Abp.DynamicProxy;
namespace Volo.Abp.MongoDB namespace Volo.Abp.MongoDB
{ {
@ -15,12 +16,12 @@ namespace Volo.Abp.MongoDB
{ {
public bool CanExecute<T>(IQueryable<T> queryable) public bool CanExecute<T>(IQueryable<T> queryable)
{ {
return queryable.Provider.GetType().Namespace?.StartsWith("MongoDB") ?? false; return ProxyHelper.UnProxy(queryable) is IMongoQueryable<T>;
} }
protected IMongoQueryable<T> GetMongoQueryable<T>(IQueryable<T> queryable) protected virtual IMongoQueryable<T> GetMongoQueryable<T>(IQueryable<T> queryable)
{ {
return (IMongoQueryable<T>) queryable; return ProxyHelper.UnProxy(queryable).As<IMongoQueryable<T>>();
} }
public Task<bool> ContainsAsync<T>(IQueryable<T> queryable, T item, CancellationToken cancellationToken = default) public Task<bool> ContainsAsync<T>(IQueryable<T> queryable, T item, CancellationToken cancellationToken = default)

76
framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Repositories/MongoDbAsyncQueryableProvider_Tests.cs

@ -0,0 +1,76 @@
using System;
using System.Linq;
using System.Threading.Tasks;
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.Repositories
{
[Collection(MongoTestCollection.Name)]
public class MongoDbAsyncQueryableProvider_Tests : TestAppTestBase<AbpMongoDbTestModule>
{
private readonly IUnitOfWorkManager _unitOfWorkManager;
private readonly IRepository<Person, Guid> _personRepository;
private readonly MongoDbAsyncQueryableProvider _mongoDbAsyncQueryableProvider;
public MongoDbAsyncQueryableProvider_Tests()
{
_unitOfWorkManager = GetRequiredService<IUnitOfWorkManager>();
_personRepository = GetRequiredService<IRepository<Person, Guid>>();
_mongoDbAsyncQueryableProvider = GetRequiredService<MongoDbAsyncQueryableProvider>();
}
[Fact]
public void CanExecute()
{
_mongoDbAsyncQueryableProvider.CanExecute(_personRepository).ShouldBeTrue();
_mongoDbAsyncQueryableProvider.CanExecute(_personRepository.WithDetails()).ShouldBeTrue();
}
[Fact]
public async Task FirstOrDefaultAsync()
{
using (var uow = _unitOfWorkManager.Begin())
{
(await _mongoDbAsyncQueryableProvider.FirstOrDefaultAsync(_personRepository.Where(p => p.Name == "Douglas"))).ShouldNotBeNull();
await uow.CompleteAsync();
}
}
[Fact]
public async Task AnyAsync()
{
using (var uow = _unitOfWorkManager.Begin())
{
(await _mongoDbAsyncQueryableProvider.AnyAsync(_personRepository, p => p.Name == "Douglas")).ShouldBeTrue();
await uow.CompleteAsync();
}
}
[Fact]
public async Task CountAsync()
{
using (var uow = _unitOfWorkManager.Begin())
{
(await _mongoDbAsyncQueryableProvider.CountAsync(_personRepository.Where(p => p.Name == "Douglas"))).ShouldBeGreaterThan(0);
await uow.CompleteAsync();
}
}
[Fact]
public async Task LongCountAsync()
{
using (var uow = _unitOfWorkManager.Begin())
{
(await _mongoDbAsyncQueryableProvider.LongCountAsync(_personRepository)).ShouldBeGreaterThan(0);
await uow.CompleteAsync();
}
}
//More MongoDbAsyncQueryableProvider's method test.
}
}

10
framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Repositories/Repository_Basic_Tests.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using MongoDB.Driver.Linq;
using Shouldly; using Shouldly;
using Volo.Abp.TestApp; using Volo.Abp.TestApp;
using Volo.Abp.TestApp.Domain; using Volo.Abp.TestApp.Domain;
@ -12,6 +13,15 @@ namespace Volo.Abp.MongoDB.Repositories
[Collection(MongoTestCollection.Name)] [Collection(MongoTestCollection.Name)]
public class Repository_Basic_Tests : Repository_Basic_Tests<AbpMongoDbTestModule> public class Repository_Basic_Tests : Repository_Basic_Tests<AbpMongoDbTestModule>
{ {
[Fact]
public void ToMongoQueryable_Test()
{
((IMongoQueryable<Person>) PersonRepository).ShouldNotBeNull();
PersonRepository.As<IMongoQueryable<Person>>().ShouldNotBeNull();
((IMongoQueryable<Person>) PersonRepository.Where(p => p.Name == "Douglas")).ShouldNotBeNull();
PersonRepository.Where(p => p.Name == "Douglas").As<IMongoQueryable<Person>>().ShouldNotBeNull();
}
[Fact] [Fact]
public async Task Linq_Queries() public async Task Linq_Queries()
{ {

3
nupkg/common.ps1

@ -58,6 +58,7 @@ $projects = (
"framework/src/Volo.Abp.BackgroundWorkers.Quartz", "framework/src/Volo.Abp.BackgroundWorkers.Quartz",
"framework/src/Volo.Abp.BlobStoring", "framework/src/Volo.Abp.BlobStoring",
"framework/src/Volo.Abp.BlobStoring.FileSystem", "framework/src/Volo.Abp.BlobStoring.FileSystem",
"framework/src/Volo.Abp.BlobStoring.Azure",
"framework/src/Volo.Abp.Caching", "framework/src/Volo.Abp.Caching",
"framework/src/Volo.Abp.Caching.StackExchangeRedis", "framework/src/Volo.Abp.Caching.StackExchangeRedis",
"framework/src/Volo.Abp.Castle.Core", "framework/src/Volo.Abp.Castle.Core",
@ -250,4 +251,4 @@ $projects = (
"modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.Domain.Shared", "modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.Domain.Shared",
"modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.EntityFrameworkCore", "modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.EntityFrameworkCore",
"modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.MongoDB" "modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.MongoDB"
) )

Loading…
Cancel
Save