mirror of https://github.com/abpframework/abp.git
36 changed files with 414 additions and 185 deletions
@ -0,0 +1,37 @@ |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling.Libraries.Bootstrap; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Bundling |
|||
{ |
|||
[DependsOn( |
|||
typeof(BootstrapScriptBundleContributor) |
|||
)] |
|||
public class SharedThemeGlobalScriptContributor : BundleContributor |
|||
{ |
|||
public override void ConfigureBundle(BundleConfigurationContext context) |
|||
{ |
|||
context.Files.AddRange(new[] |
|||
{ //TODO: Create seperated contributors!
|
|||
"/libs/jquery-validation/jquery.validate.js", |
|||
"/libs/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js", |
|||
"/libs/jquery-form/jquery.form.min.js", |
|||
"/libs/datatables.net/js/jquery.dataTables.js", |
|||
"/libs/datatables.net-bs4/js/dataTables.bootstrap4.js", |
|||
"/libs/sweetalert/sweetalert.min.js", |
|||
"/libs/toastr/toastr.min.js", |
|||
"/libs/abp/core/abp.js", |
|||
"/libs/abp/jquery/abp.dom.js", |
|||
"/libs/abp/jquery/abp.ajax.js", |
|||
"/libs/abp/jquery/abp.resource-loader.js", |
|||
"/libs/abp/aspnetcore.mvc.ui.theme.shared/jquery/jquery-extensions.js", |
|||
"/libs/abp/aspnetcore.mvc.ui.theme.shared/jquery-form/jquery-form-extensions.js", |
|||
"/libs/abp/aspnetcore.mvc.ui.theme.shared/bootstrap/dom-event-handlers.js", |
|||
"/libs/abp/aspnetcore.mvc.ui.theme.shared/bootstrap/modal-manager.js", |
|||
"/libs/abp/aspnetcore.mvc.ui.theme.shared/datatables/datatables-extensions.js", |
|||
"/libs/abp/aspnetcore.mvc.ui.theme.shared/sweetalert/abp-sweetalert.js", |
|||
"/libs/abp/aspnetcore.mvc.ui.theme.shared/toastr/abp-toastr.js" |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling.Libraries.Bootstrap; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling.Libraries.DatatablesNetBs4; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling.Libraries.FontAwesome; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling.Libraries.Toastr; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Bundling |
|||
{ |
|||
[DependsOn( |
|||
typeof(BootstrapStyleBundleContributor), |
|||
typeof(FontAwesomeStyleBundleContributor), |
|||
typeof(ToastrStyleBundleContributor), |
|||
typeof(DatatablesNetBs4StyleBundleContributor) |
|||
)] |
|||
public class SharedThemeGlobalStyleContributor : BundleContributor |
|||
{ |
|||
public override void ConfigureBundle(BundleConfigurationContext context) |
|||
{ |
|||
context.Files.Add("/libs/abp/aspnetcore.mvc.ui.theme.shared/datatables/datatables.css"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Bundling |
|||
{ |
|||
public class StandardBundles |
|||
{ |
|||
public static class Styles |
|||
{ |
|||
public static string Global = "Global"; |
|||
} |
|||
|
|||
public static class Scripts |
|||
{ |
|||
public static string Global = "Global"; |
|||
} |
|||
} |
|||
} |
|||
@ -1,12 +1,40 @@ |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling.Contributors; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling |
|||
{ |
|||
public static class BundleConfigurationExtensions |
|||
{ |
|||
public static void AddFiles(this BundleConfiguration bundleConfiguration, params string[] files) |
|||
public static BundleConfiguration AddFiles(this BundleConfiguration bundleConfiguration, params string[] files) |
|||
{ |
|||
bundleConfiguration.Contributors.Add(new SimpleBundleContributor(files)); |
|||
bundleConfiguration.Contributors.AddFiles(files); |
|||
return bundleConfiguration; |
|||
} |
|||
|
|||
public static BundleConfiguration AddContributors(this BundleConfiguration bundleConfiguration, params IBundleContributor[] contributors) |
|||
{ |
|||
if (!contributors.IsNullOrEmpty()) |
|||
{ |
|||
foreach (var contributor in contributors) |
|||
{ |
|||
bundleConfiguration.Contributors.Add(contributor); |
|||
} |
|||
} |
|||
|
|||
return bundleConfiguration; |
|||
} |
|||
|
|||
public static BundleConfiguration AddContributors(this BundleConfiguration bundleConfiguration, params Type[] contributorTypes) |
|||
{ |
|||
if (!contributorTypes.IsNullOrEmpty()) |
|||
{ |
|||
foreach (var contributorType in contributorTypes) |
|||
{ |
|||
bundleConfiguration.Contributors.Add(contributorType); |
|||
} |
|||
} |
|||
|
|||
return bundleConfiguration; |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,20 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Theming; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling |
|||
{ |
|||
public class BundleConfigurationContext : IBundleConfigurationContext |
|||
{ |
|||
public List<string> Files { get; } |
|||
public ITheme Theme { get; } |
|||
public IServiceProvider ServiceProvider { get; } |
|||
|
|||
public BundleConfigurationContext(List<string> files, ITheme theme, IServiceProvider serviceProvider) |
|||
{ |
|||
Files = files; |
|||
Theme = theme; |
|||
ServiceProvider = serviceProvider; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling |
|||
{ |
|||
public abstract class BundleContributor : IBundleContributor |
|||
{ |
|||
public abstract void ConfigureBundle(BundleConfigurationContext context); |
|||
} |
|||
} |
|||
@ -0,0 +1,91 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Collections.Immutable; |
|||
using System.Linq; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling |
|||
{ |
|||
public class BundleContributorCollection |
|||
{ |
|||
private readonly List<IBundleContributor> _contributors; |
|||
|
|||
public BundleContributorCollection() |
|||
{ |
|||
_contributors = new List<IBundleContributor>(); |
|||
} |
|||
|
|||
public void Add(IBundleContributor contributor) |
|||
{ |
|||
_contributors.Add(contributor); |
|||
} |
|||
|
|||
public void Add<TContributor>() |
|||
where TContributor : IBundleContributor, new() |
|||
{ |
|||
Add(typeof(TContributor)); |
|||
} |
|||
|
|||
public void Add([NotNull] Type contributorType) |
|||
{ |
|||
Check.NotNull(contributorType, nameof(contributorType)); |
|||
if (!typeof(IBundleContributor).IsAssignableFrom(contributorType)) |
|||
{ |
|||
throw new AbpException($"Given {nameof(contributorType)} ({contributorType.AssemblyQualifiedName}) should implement the {typeof(IBundleContributor).AssemblyQualifiedName} interface!"); |
|||
} |
|||
|
|||
if (IsAlreadyAdded(contributorType)) |
|||
{ |
|||
throw new AbpException($"Given {nameof(contributorType)} ({contributorType.AssemblyQualifiedName}) is already added before! If you want to ensure that a contributor is added, create your own contributor and depend on the contributor you want to ensure that it's added."); |
|||
} |
|||
|
|||
AddWithDependencies(contributorType); |
|||
} |
|||
|
|||
public IReadOnlyList<IBundleContributor> GetAll() |
|||
{ |
|||
return _contributors.ToImmutableList(); |
|||
} |
|||
|
|||
private bool IsAlreadyAdded(Type contributorType) |
|||
{ |
|||
return _contributors.Any(c => c.GetType() == contributorType); |
|||
} |
|||
|
|||
private void AddWithDependencies(Type contributorType) |
|||
{ |
|||
var dependsOnAttributes = contributorType |
|||
.GetCustomAttributes(true) |
|||
.OfType<IDependedTypesProvider>() |
|||
.ToList(); |
|||
|
|||
foreach (var dependsOnAttribute in dependsOnAttributes) |
|||
{ |
|||
foreach (var dependedType in dependsOnAttribute.GetDependedTypes()) |
|||
{ |
|||
AddWithDependencies(dependedType); //Recursive call
|
|||
|
|||
if (!IsAlreadyAdded(dependedType)) |
|||
{ |
|||
AddInstanceToContributors(dependedType); |
|||
} |
|||
} |
|||
} |
|||
|
|||
AddInstanceToContributors(contributorType); |
|||
} |
|||
|
|||
private void AddInstanceToContributors(Type contributorType) |
|||
{ |
|||
try |
|||
{ |
|||
_contributors.Add((IBundleContributor)Activator.CreateInstance(contributorType)); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
throw new AbpException($"Can not instantiate {contributorType.AssemblyQualifiedName}", ex); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,9 +0,0 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling |
|||
{ |
|||
public class BundleContributorList : List<IBundleContributor> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling |
|||
{ |
|||
public static class BundleContributorListExtensions |
|||
{ |
|||
public static void AddFiles(this BundleContributorCollection contributors, params string[] files) |
|||
{ |
|||
contributors.Add(new SimpleBundleContributor(files)); |
|||
} |
|||
} |
|||
} |
|||
@ -1,20 +0,0 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.Contributors |
|||
{ |
|||
public class SimpleBundleContributor : IBundleContributor |
|||
{ |
|||
public string[] Files { get; } |
|||
|
|||
public SimpleBundleContributor(params string[] files) |
|||
{ |
|||
Files = files ?? Array.Empty<string>(); |
|||
} |
|||
|
|||
public void Contribute(List<string> files) |
|||
{ |
|||
files.AddRange(Files); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Theming; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling |
|||
{ |
|||
public interface IBundleConfigurationContext : IServiceProviderAccessor |
|||
{ |
|||
List<string> Files { get; } |
|||
|
|||
ITheme Theme { get; } |
|||
} |
|||
} |
|||
@ -1,9 +1,7 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling |
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling |
|||
{ |
|||
public interface IBundleContributor |
|||
{ |
|||
void Contribute(List<string> files); |
|||
void ConfigureBundle(BundleConfigurationContext context); |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,14 @@ |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling.Libraries.JQuery; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.Libraries.Bootstrap |
|||
{ |
|||
[DependsOn(typeof(JQueryScriptBundleContributor))] |
|||
public class BootstrapScriptBundleContributor : BundleContributor |
|||
{ |
|||
public override void ConfigureBundle(BundleConfigurationContext context) |
|||
{ |
|||
context.Files.Add("/libs/bootstrap/js/bootstrap.bundle.js"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.Libraries.Bootstrap |
|||
{ |
|||
public class BootstrapStyleBundleContributor : BundleContributor |
|||
{ |
|||
public override void ConfigureBundle(BundleConfigurationContext context) |
|||
{ |
|||
context.Files.Add("/libs/bootstrap/css/bootstrap.css"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling.Libraries.Bootstrap; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.Libraries.DatatablesNetBs4 |
|||
{ |
|||
[DependsOn(typeof(BootstrapStyleBundleContributor))] |
|||
public class DatatablesNetBs4StyleBundleContributor : BundleContributor |
|||
{ |
|||
public override void ConfigureBundle(BundleConfigurationContext context) |
|||
{ |
|||
context.Files.Add("/libs/datatables.net-bs4/css/dataTables.bootstrap4.css"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.Libraries.FontAwesome |
|||
{ |
|||
public class FontAwesomeStyleBundleContributor : BundleContributor |
|||
{ |
|||
public override void ConfigureBundle(BundleConfigurationContext context) |
|||
{ |
|||
context.Files.Add("/libs/font-awesome/css/font-awesome.css"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.Libraries.JQuery |
|||
{ |
|||
public class JQueryScriptBundleContributor : BundleContributor |
|||
{ |
|||
public override void ConfigureBundle(BundleConfigurationContext context) |
|||
{ |
|||
context.Files.Add("/libs/jquery/jquery.js"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.Libraries.Toastr |
|||
{ |
|||
public class ToastrStyleBundleContributor : BundleContributor |
|||
{ |
|||
public override void ConfigureBundle(BundleConfigurationContext context) |
|||
{ |
|||
context.Files.Add("/libs/toastr/toastr.min.css"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling |
|||
{ |
|||
public class SimpleBundleContributor : BundleContributor |
|||
{ |
|||
public string[] Files { get; } |
|||
|
|||
public SimpleBundleContributor(params string[] files) |
|||
{ |
|||
Files = files ?? Array.Empty<string>(); |
|||
} |
|||
|
|||
public override void ConfigureBundle(BundleConfigurationContext context) |
|||
{ |
|||
context.Files.AddRange(Files); |
|||
} |
|||
} |
|||
} |
|||
@ -1,21 +0,0 @@ |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.Views.Shared.Components.AbpScriptBundle |
|||
{ |
|||
public class AbpScriptBundleViewComponent : AbpViewComponent |
|||
{ |
|||
private readonly IBundleManager _bundleManager; |
|||
|
|||
public AbpScriptBundleViewComponent(IBundleManager bundleManager) |
|||
{ |
|||
_bundleManager = bundleManager; |
|||
} |
|||
|
|||
public IViewComponentResult Invoke(string name) |
|||
{ |
|||
var files = _bundleManager.GetScriptBundleFiles(name); |
|||
return View(files); |
|||
} |
|||
} |
|||
} |
|||
@ -1,5 +0,0 @@ |
|||
@model List<string> |
|||
@foreach (var scriptFile in Model) |
|||
{ |
|||
<script src="@scriptFile" type="text/javascript"></script> |
|||
} |
|||
@ -1,21 +0,0 @@ |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.Views.Shared.Components.AbpStyleBundle |
|||
{ |
|||
public class AbpStyleBundleViewComponent : AbpViewComponent |
|||
{ |
|||
private readonly IBundleManager _bundleManager; |
|||
|
|||
public AbpStyleBundleViewComponent(IBundleManager bundleManager) |
|||
{ |
|||
_bundleManager = bundleManager; |
|||
} |
|||
|
|||
public IViewComponentResult Invoke(string name) |
|||
{ |
|||
var files = _bundleManager.GetStyleBundleFiles(name); |
|||
return View(files); |
|||
} |
|||
} |
|||
} |
|||
@ -1,5 +0,0 @@ |
|||
@model List<string> |
|||
@foreach (var styleFile in Model) |
|||
{ |
|||
<link rel="stylesheet" type="text/css" href="@styleFile" /> |
|||
} |
|||
Loading…
Reference in new issue