Browse Source

Allow replace & delete BundleContributor.

pull/2972/head
maliming 7 years ago
parent
commit
797695ceb4
  1. 47
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollection.cs
  2. 7
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/BootstrapDatepicker/BootstrapDatepickerScriptContributor.cs
  3. 9
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/JQueryValidation/JQueryValidationScriptContributor.cs

47
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollection.cs

@ -39,6 +39,43 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
AddWithDependencies(contributorType); AddWithDependencies(contributorType);
} }
public void Replace<TSourceContributor, TDestContributorType>(bool includeDependencies = false)
where TSourceContributor : IBundleContributor, new()
where TDestContributorType : IBundleContributor, new()
{
Replace(typeof(TSourceContributor), typeof(TDestContributorType), includeDependencies);
}
public void Replace([NotNull] Type sourceContributorType, [NotNull] Type destContributorType, bool includeDependencies = false)
{
Check.NotNull(sourceContributorType, nameof(sourceContributorType));
Check.NotNull(destContributorType, nameof(destContributorType));
if (!includeDependencies)
{
_contributors.ReplaceOne(x => x.GetType() == sourceContributorType,
contributor => (IBundleContributor) Activator.CreateInstance(destContributorType));
}
else
{
RemoveWithDependencies(sourceContributorType);
Add(destContributorType);
}
}
public void Remove<TContributor>(bool includeDependencies = false)
where TContributor : IBundleContributor, new()
{
if (!includeDependencies)
{
_contributors.RemoveAll(x => x.GetType() == typeof(TContributor));
}
else
{
RemoveWithDependencies(typeof(TContributor));
}
}
public IReadOnlyList<IBundleContributor> GetAll() public IReadOnlyList<IBundleContributor> GetAll()
{ {
return _contributors.ToImmutableList(); return _contributors.ToImmutableList();
@ -58,6 +95,16 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
AddInstanceToContributors(contributorType); AddInstanceToContributors(contributorType);
} }
private void RemoveWithDependencies(Type contributorType)
{
foreach (var dependedType in GetDirectDependencies(contributorType))
{
RemoveWithDependencies(dependedType); //Recursive call
}
_contributors.RemoveAll(x => x.GetType() == contributorType);
}
private IEnumerable<Type> GetDirectDependencies(Type contributorType) private IEnumerable<Type> GetDirectDependencies(Type contributorType)
{ {

7
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/BootstrapDatepicker/BootstrapDatepickerScriptContributor.cs

@ -21,7 +21,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Packages.Timeago
? "en" ? "en"
: CultureInfo.CurrentUICulture.Name; : CultureInfo.CurrentUICulture.Name;
if (TryAddCultureFile(context, cultureName)) if (TryAddCultureFile(context, MapCultureName(cultureName)))
{ {
return; return;
} }
@ -39,5 +39,10 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Packages.Timeago
context.Files.AddIfNotContains(filePath); context.Files.AddIfNotContains(filePath);
return true; return true;
} }
protected virtual string MapCultureName(string cultureName)
{
return cultureName;
}
} }
} }

9
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/JQueryValidation/JQueryValidationScriptContributor.cs

@ -25,7 +25,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Packages.JQueryValidation
var cultureName = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName.Replace('-', '_'); var cultureName = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName.Replace('-', '_');
if (TryAddCultureFile(context, cultureName)) if (TryAddCultureFile(context, MapCultureName(cultureName)))
{ {
return; return;
} }
@ -35,7 +35,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Packages.JQueryValidation
return; return;
} }
TryAddCultureFile(context, cultureName.Substring(0, cultureName.IndexOf('_'))); TryAddCultureFile(context, MapCultureName(cultureName.Substring(0, cultureName.IndexOf('_'))));
} }
protected virtual bool TryAddCultureFile(BundleConfigurationContext context, string cultureName) protected virtual bool TryAddCultureFile(BundleConfigurationContext context, string cultureName)
@ -51,5 +51,10 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Packages.JQueryValidation
context.Files.AddIfNotContains(filePath); context.Files.AddIfNotContains(filePath);
return true; return true;
} }
protected virtual string MapCultureName(string cultureName)
{
return cultureName;
}
} }
} }

Loading…
Cancel
Save