mirror of https://github.com/abpframework/abp.git
12 changed files with 532 additions and 75 deletions
@ -0,0 +1,46 @@ |
|||
using System; |
|||
using System.Reflection; |
|||
using JetBrains.Annotations; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Widgets |
|||
{ |
|||
[AttributeUsage(AttributeTargets.Class)] |
|||
public class WidgetAttribute : Attribute |
|||
{ |
|||
[CanBeNull] |
|||
public string[] StyleSrcs { get; set; } |
|||
|
|||
[CanBeNull] |
|||
public Type[] StyleTypes { get; set; } |
|||
|
|||
[CanBeNull] |
|||
public string[] ScriptSrcs { get; set; } |
|||
|
|||
[CanBeNull] |
|||
public Type[] ScriptTypes { get; set; } |
|||
|
|||
[CanBeNull] |
|||
public string DisplayName { get; set; } |
|||
|
|||
[CanBeNull] |
|||
public Type DisplayNameResource { get; set; } |
|||
|
|||
[CanBeNull] |
|||
public string[] RequiredPolicies { get; set; } |
|||
|
|||
public bool RequiresAuthentication { get; set; } |
|||
|
|||
public static bool IsWidget(Type type) |
|||
{ |
|||
return type.IsSubclassOf(typeof(ViewComponent)) && |
|||
type.IsDefined(typeof(WidgetAttribute), true); |
|||
} |
|||
|
|||
public static WidgetAttribute Get(Type viewComponentType) |
|||
{ |
|||
return viewComponentType.GetCustomAttribute<WidgetAttribute>(true) |
|||
?? throw new AbpException($"Given type '{viewComponentType.AssemblyQualifiedName}' does not declare a {typeof(WidgetAttribute).AssemblyQualifiedName}"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,70 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Collections.Immutable; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Localization; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Widgets |
|||
{ |
|||
public class WidgetDefinitionCollection |
|||
{ |
|||
private readonly Dictionary<string, WidgetDefinition> _widgetsByName; |
|||
private readonly Dictionary<Type, WidgetDefinition> _widgetsByType; |
|||
|
|||
public WidgetDefinitionCollection() |
|||
{ |
|||
_widgetsByName = new Dictionary<string, WidgetDefinition>(); |
|||
_widgetsByType = new Dictionary<Type, WidgetDefinition>(); |
|||
} |
|||
|
|||
public void Add(WidgetDefinition widget) |
|||
{ |
|||
var existingWidget = _widgetsByName.GetOrDefault(widget.Name); |
|||
if (existingWidget != null) |
|||
{ |
|||
_widgetsByType[existingWidget.ViewComponentType] = widget; |
|||
} |
|||
|
|||
_widgetsByName[widget.Name] = widget; |
|||
_widgetsByType[widget.ViewComponentType] = widget; |
|||
} |
|||
|
|||
public WidgetDefinition Add<TViewComponent>( |
|||
[CanBeNull] ILocalizableString displayName = null) |
|||
{ |
|||
return Add(typeof(TViewComponent), displayName); |
|||
} |
|||
|
|||
public WidgetDefinition Add( |
|||
[NotNull] Type viewComponentType, |
|||
[CanBeNull] ILocalizableString displayName = null) |
|||
{ |
|||
var widget = new WidgetDefinition(viewComponentType, displayName); |
|||
Add(widget); |
|||
return widget; |
|||
} |
|||
|
|||
[CanBeNull] |
|||
public WidgetDefinition Find(string name) |
|||
{ |
|||
return _widgetsByName.GetOrDefault(name); |
|||
} |
|||
|
|||
[CanBeNull] |
|||
public WidgetDefinition Find<TViewComponent>() |
|||
{ |
|||
return Find(typeof(TViewComponent)); |
|||
} |
|||
|
|||
[CanBeNull] |
|||
public WidgetDefinition Find(Type viewComponentType) |
|||
{ |
|||
return _widgetsByType.GetOrDefault(viewComponentType); |
|||
} |
|||
|
|||
public IReadOnlyCollection<WidgetDefinition> GetAll() |
|||
{ |
|||
return _widgetsByName.Values.ToImmutableArray(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,14 +1,12 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Widgets |
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Widgets |
|||
{ |
|||
public class WidgetOptions |
|||
{ |
|||
public List<WidgetDefinition> Widgets { get; } |
|||
public WidgetDefinitionCollection Widgets { get; } |
|||
|
|||
public WidgetOptions() |
|||
{ |
|||
Widgets = new List<WidgetDefinition>(); |
|||
Widgets = new WidgetDefinitionCollection(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
Loading…
Reference in new issue