Giter Site home page Giter Site logo

abp.trees's Introduction

Abp.Trees

ABP version NuGet NuGet Download Discord online GitHub stars

An abp module that provides standard tree structure entity implement.

Installation

  1. Install the following NuGet packages. (see how)

    • EasyAbp.Abp.Trees.Domain
    • EasyAbp.Abp.Trees.Domain.Shared
    • EasyAbp.Abp.Trees.EntityFrameworkCore
  2. Add DependsOn(typeof(AbpTreesXxxModule)) attribute to configure the module dependencies. (see how)

Usage

  1. Create a entity and implement ITree<TEntity>.

  2. Create a Repository for the entity. EfCoreTreeRepository<TDbContext, TEntity> override some function of EfCoreRepository<TDbContext, TEntity, TKey> to match tree structure:

    • InsertAsync :Auto Append node Code and Calc Level property when insert

    • UpdateAsync :Auto Move node when update a Entity that parentId is modified

    • DeleteAsync :Also delete Children nodes

  3. You have two ways to use this Repository

    • Way 1 : Default Repository(ITreeRepository<>),
      Add context.Services.AddTreeRepository<MyProjectNameDbContext>(); to ConfigureServices method in MyProjectNameEntityFrameworkCoreModule.cs.

    • Way 2 : Create a CustomRepository that base on EfCoreTreeRepository<TDbContext, TEntity>

    • Example:

    context.Services.AddAbpDbContext<TestDbContext>(options =>
    {
    	options.AddDefaultRepositories(includeAllEntities: true);//add Abp's `IRepository<TEntity>`
    	options.AddDefaultTreeRepositories();//add `ITreeRepository<TEntity>` for all Entity with implement `ITree<TEntity>`
    	options.TreeEntity<Resource>(x => x.CodeLength = 10);//set CodeLength for each Entity(Default:5)
    });

Sample

It works fine with Volo.Abp.Application.Services.CrudAppService.

After replacing IRepository<> with ITreeRepository<Domain.OrganizationUnit>, the repository will handle the tree structure of the entity during creating, updating, and deleting.

    public class OrganizationUnitAppService:
        Volo.Abp.Application.Services.CrudAppService<
            Domain.OrganizationUnit, Application.OrganizationUnitDto,
            Application.OrganizationUnitDto,Guid, Volo.Abp.Application.Dtos.IPagedAndSortedResultRequest,
            Application.CreateOrganizationUnitDto,Application.UpdateOrganizationUnitDto>,
        IOrganizationUnitAppService
        
    {
        public OrganizationUnitAppService(
            EasyAbp.Abp.Trees.ITreeRepository<Domain.OrganizationUnit> organizationUnitRepository
            ):base(organizationUnitRepository)
        {
            
        }

    }

Roadmap

  • Widget of tree operation for MVC UI.
  • Create a TreeManager to provides more function,example: Sort(reassigned code), Ui Pagination...
  • More Unit tests.

abp.trees's People

Contributors

yinchang0626 avatar gdlcf88 avatar ericeric284 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.