Skip to content

Commit

Permalink
Lots of changes
Browse files Browse the repository at this point in the history
- Introduced new "GetSearchableText" method in the "IGridControlValue" interface
- Introduced new "GridControlValueBase" class
- etc.
  • Loading branch information
abjerner committed Nov 29, 2016
1 parent da34e6b commit ccede77
Show file tree
Hide file tree
Showing 22 changed files with 258 additions and 96 deletions.
26 changes: 21 additions & 5 deletions src/Skybrud.Umbraco.GridData/GridArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class GridArea : GridJsonObject {
#region Properties

/// <summary>
/// Gets a reference to the parent <code>GridRow</code>.
/// Gets a reference to the parent <see cref="GridRow"/>.
/// </summary>
[JsonIgnore]
public GridRow Row { get; private set; }
Expand All @@ -31,7 +31,7 @@ public class GridArea : GridJsonObject {
public bool AllowAll { get; private set; }

/// <summary>
/// Gets an array of all editors allowed for this area. If <code>AllowAll</code> is <code>TRUE</code>, this
/// Gets an array of all editors allowed for this area. If <see cref="AllowAll"/> is <code>true</code>, this
/// array may be empty.
/// </summary>
public string[] Allowed { get; private set; }
Expand All @@ -47,7 +47,7 @@ public class GridArea : GridJsonObject {
public GridDictionary Styles { get; private set; }

/// <summary>
/// Gets a dictionary representing the configuration (called Settings in the backoffice) of the area.
/// Gets a dictionary representing the configuration (called <strong>Settings</strong> in the backoffice) of the area.
/// </summary>
public GridDictionary Config { get; private set; }

Expand All @@ -70,15 +70,15 @@ public bool HasControls {

/// <summary>
/// Gets the first control of the area. If the area doesn't contain
/// any controls, this property will return <code>NULL</code>.
/// any controls, this property will return <code>null</code>.
/// </summary>
public GridControl FirstControl {
get { return Controls.FirstOrDefault(); }
}

/// <summary>
/// Gets the last control of the area. If the area doesn't contain
/// any controls, this property will return <code>NULL</code>.
/// any controls, this property will return <code>null</code>.
/// </summary>
public GridControl LastControl {
get { return Controls.LastOrDefault(); }
Expand All @@ -88,10 +88,26 @@ public GridControl LastControl {

#region Constructors

/// <summary>
/// Initializes a new instance based on the specified <see cref="JObject"/>.
/// </summary>
/// <param name="obj">An instance of <see cref="JObject"/> representing the area.</param>
protected GridArea(JObject obj) : base(obj) { }

#endregion

#region Member methods

/// <summary>
/// Gets a textual representation of the area - eg. to be used in Examine.
/// </summary>
/// <returns>Returns an instance of <see cref="System.String"/> representing the value of the area.</returns>
public virtual string GetSearchableText() {
return Controls.Aggregate("", (current, control) => current + control.GetSearchableText());
}

#endregion

#region Static methods

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Skybrud.Umbraco.GridData/GridContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class GridContext {
#region Properties

/// <summary>
/// Gets the singleton instance of the <code>GridContext</code> class.
/// Gets the singleton instance of the <see cref="GridContext"/> class.
/// </summary>
public static readonly GridContext Current = new GridContext();

Expand All @@ -42,7 +42,7 @@ private GridContext() { }
#region Member methods

/// <summary>
/// Gets an instance of <code>GridControlWrapper</code> based on the specified <code>control</code>.
/// Gets an instance of <see cref="GridControlWrapper"/> based on the specified <code>control</code>.
/// </summary>
/// <param name="control">The control to wrap.</param>
public GridControlWrapper GetControlWrapper(GridControl control) {
Expand Down
16 changes: 14 additions & 2 deletions src/Skybrud.Umbraco.GridData/GridControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class GridControl : GridJsonObject {
#region Properties

/// <summary>
/// Gets a reference to the parent <code>GridArea</code>.
/// Gets a reference to the parent <see cref="GridArea"/>.
/// </summary>
[JsonIgnore]
public GridArea Area { get; private set; }
Expand Down Expand Up @@ -70,6 +70,18 @@ public T GetValue<T>() where T : IGridControlValue {
return (T) Value;
}

#region Member methods

/// <summary>
/// Gets the value of the control as a searchable text - eg. to be used in Examine.
/// </summary>
/// <returns>Returns an instance of <see cref="System.String"/> with the value as a searchable text.</returns>
public virtual string GetSearchableText() {
return IsValid ? Value.GetSearchableText() : "";
}

#endregion

#endregion

#region Static methods
Expand All @@ -78,7 +90,7 @@ public T GetValue<T>() where T : IGridControlValue {
/// Parses a control from the specified <code>obj</code>.
/// </summary>
/// <param name="area">The parent area of the control.</param>
/// <param name="obj">The instance of <code>JObject</code> to be parsed.</param>
/// <param name="obj">The instance of <see cref="JObject"/> to be parsed.</param>
public static GridControl Parse(GridArea area, JObject obj) {

// Set basic properties
Expand Down
23 changes: 16 additions & 7 deletions src/Skybrud.Umbraco.GridData/GridDataModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ namespace Skybrud.Umbraco.GridData {
public class GridDataModel : GridJsonObject {

#region Properties

/// <summary>
/// Gets whether the model is valid.
/// Gets whether the model is valid. The model is considered valid if it has been parsed from a JSON value and
/// has at least one valid control.
/// </summary>
public bool IsValid { get; private set; }
public bool IsValid {
get { return JObject != null && GetAllControls().All(x => x.IsValid); }
}

/// <summary>
/// Gets the raw JSON value this model was parsed from.
Expand Down Expand Up @@ -78,7 +81,6 @@ public dynamic sections {

private GridDataModel(JObject obj) : base(obj) {
Sections = new GridSection[0];
IsValid = false;
}

#endregion
Expand Down Expand Up @@ -138,6 +140,14 @@ public HtmlString GetHtml(HtmlHelper helper, string framework) {
return helper.GetTypedGridHtml(this, framework);
}

/// <summary>
/// Gets a textual representation of the grid model - eg. to be used in Examine.
/// </summary>
/// <returns>Returns an instance of <see cref="System.String"/> representing the value of the grid model.</returns>
public virtual string GetSearchableText() {
return Sections.Aggregate("", (current, section) => current + section.GetSearchableText());
}

#endregion

#region Static methods
Expand Down Expand Up @@ -188,7 +198,6 @@ public static GridDataModel Deserialize(string json, string propertyTypeAlias) {
GridDataModel model = new GridDataModel(obj) {
Raw = json,
Name = obj.GetString("name"),
IsValid = true,
PropertyAlias = propertyTypeAlias
};

Expand All @@ -201,9 +210,9 @@ public static GridDataModel Deserialize(string json, string propertyTypeAlias) {
}

/// <summary>
/// Parses the specified <code>JObject</code> into an instance of <code>GridDataModel</code>.
/// Parses the specified <see cref="JObject"/> into an instance of <see cref="GridDataModel"/>.
/// </summary>
/// <param name="obj">The instance of <code>JObject</code> to be parsed.</param>
/// <param name="obj">The instance of <see cref="JObject"/> to be parsed.</param>
[Obsolete("Use Deserialize method instead")]
public static GridDataModel Parse(JObject obj) {
if (obj == null) return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Skybrud.Umbraco.GridData/GridDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public bool ContainsKey(string key) {
/// <summary>
/// Parses a dictionary from the specified <code>obj</code>.
/// </summary>
/// <param name="obj">The instance of <code>JObject</code> to be parsed.</param>
/// <param name="obj">The instance of <see cref="JObject"/> to be parsed.</param>
public static GridDictionary Parse(JObject obj) {

// Initialize an empty dictionary
Expand Down
8 changes: 4 additions & 4 deletions src/Skybrud.Umbraco.GridData/GridEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class GridEditor : GridJsonObject {
#region Properties

/// <summary>
/// Gets a reference to the parent <code>GridControl</code>.
/// Gets a reference to the parent <see cref="GridControl"/>.
/// </summary>
[JsonIgnore]
public GridControl Control { get; private set; }
Expand Down Expand Up @@ -53,8 +53,8 @@ public class GridEditor : GridJsonObject {
public string Icon { get; private set; }

/// <summary>
/// Gets the configuration object for the editor. This property will return <code>NULL</code> if the
/// corresponding property in the underlying JSON is also <code>NULL</code>.
/// Gets the configuration object for the editor. This property will return <code>null</code> if the
/// corresponding property in the underlying JSON is also <code>null</code>.
/// </summary>
[JsonProperty("config", NullValueHandling = NullValueHandling.Ignore)]
public IGridEditorConfig Config { get; set; }
Expand Down Expand Up @@ -85,7 +85,7 @@ public T GetConfig<T>() where T : IGridEditorConfig {
/// Parses an editor from the specified <code>obj</code>.
/// </summary>
/// <param name="control">The parent control of the editor.</param>
/// <param name="obj">The instance of <code>JObject</code> to be parsed.</param>
/// <param name="obj">The instance of <see cref="JObject"/> to be parsed.</param>
public static GridEditor Parse(GridControl control, JObject obj) {

// Parse basic properties
Expand Down
2 changes: 1 addition & 1 deletion src/Skybrud.Umbraco.GridData/GridHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class GridHelpers {
/// <summary>
/// Parses the specified <code>obj</code> into a dictionary.
/// </summary>
/// <param name="obj">The instance of <code>JObject</code> to be parsed.</param>
/// <param name="obj">The instance of <see cref="JObject"/> to be parsed.</param>
/// <returns></returns>
public static Dictionary<string, string> ParseDictionary(JObject obj) {
Dictionary<string, string> settings = new Dictionary<string, string>();
Expand Down
24 changes: 18 additions & 6 deletions src/Skybrud.Umbraco.GridData/GridRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class GridRow : GridJsonObject {
#region Properties

/// <summary>
/// Gets a reference to the parent <code>GridSection</code>.
/// Gets a reference to the parent <see cref="GridSection"/>.
/// </summary>
public GridSection Section { get; private set; }

Expand Down Expand Up @@ -67,16 +67,16 @@ public bool HasAreas {
}

/// <summary>
/// Gets the first area of the row. If the row doesn't contain
/// any areas, this property will return <code>NULL</code>.
/// Gets the first area of the row. If the row doesn't contain any areas, this property will return
/// <code>null</code>.
/// </summary>
public GridArea FirstRow {
get { return Areas.FirstOrDefault(); }
}

/// <summary>
/// Gets the last area of the row. If the row doesn't contain
/// any areas, this property will return <code>NULL</code>.
/// Gets the last area of the row. If the row doesn't contain any areas, this property will return
/// <code>null</code>.
/// </summary>
public GridArea LastRow {
get { return Areas.LastOrDefault(); }
Expand All @@ -86,6 +86,10 @@ public GridArea LastRow {

#region Constructors

/// <summary>
/// Initializes a new instance based on the specified <see cref="JObject"/>.
/// </summary>
/// <param name="obj">An instance of <see cref="JObject"/> representing the row.</param>
protected GridRow(JObject obj) : base(obj) { }

#endregion
Expand Down Expand Up @@ -124,6 +128,14 @@ select control
).ToArray();
}

/// <summary>
/// Gets a textual representation of the row - eg. to be used in Examine.
/// </summary>
/// <returns>Returns an instance of <see cref="System.String"/> representing the value of the row.</returns>
public virtual string GetSearchableText() {
return Areas.Aggregate("", (current, area) => current + area.GetSearchableText());
}

#endregion

#region Static methods
Expand All @@ -132,7 +144,7 @@ select control
/// Parses a row from the specified <code>obj</code>.
/// </summary>
/// <param name="section">The parent section of the row.</param>
/// <param name="obj">The instance of <code>JObject</code> to be parsed.</param>
/// <param name="obj">The instance of <see cref="JObject"/> to be parsed.</param>
public static GridRow Parse(GridSection section, JObject obj) {

// Some input validation
Expand Down
27 changes: 22 additions & 5 deletions src/Skybrud.Umbraco.GridData/GridSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class GridSection : GridJsonObject {
#region Properties

/// <summary>
/// Gets a reference to the parent <code>GridDataModel</code>.
/// Gets a reference to the parent <see cref="GridDataModel"/>.
/// </summary>
public GridDataModel Model { get; private set; }

Expand All @@ -36,15 +36,16 @@ public bool HasRows {
}

/// <summary>
/// Gets the first row of the section. If the section doesn't contain
/// any rows, this property will return <code>NULL</code>.
/// Gets the first row of the section. If the section doesn't contain any rows, this property will return
/// <code>null</code>.
/// </summary>
public GridRow FirstRow {
get { return Rows.FirstOrDefault(); }
}

/// <summary>
/// Gets the last row of the section. If the section doesn't contain any rows, this property will return <code>NULL</code>.
/// Gets the last row of the section. If the section doesn't contain any rows, this property will return
/// <code>null</code>.
/// </summary>
public GridRow LastRow {
get { return Rows.LastOrDefault(); }
Expand All @@ -54,17 +55,33 @@ public GridRow LastRow {

#region Constructors

/// <summary>
/// Initializes a new instance based on the specified <see cref="JObject"/>.
/// </summary>
/// <param name="obj">An instance of <see cref="JObject"/> representing the section.</param>
protected GridSection(JObject obj) : base(obj) { }

#endregion

#region Member methods

/// <summary>
/// Gets a textual representation of the section - eg. to be used in Examine.
/// </summary>
/// <returns>Returns an instance of <see cref="System.String"/> representing the value of the section.</returns>
public virtual string GetSearchableText() {
return Rows.Aggregate("", (current, row) => current + row.GetSearchableText());
}

#endregion

#region Static methods

/// <summary>
/// Parses a section from the specified <code>obj</code>.
/// </summary>
/// <param name="model">The parent model of the section.</param>
/// <param name="obj">The instance of <code>JObject</code> to be parsed.</param>
/// <param name="obj">The instance of <see cref="JObject"/> to be parsed.</param>
public static GridSection Parse(GridDataModel model, JObject obj) {

// Some input validation
Expand Down
2 changes: 1 addition & 1 deletion src/Skybrud.Umbraco.GridData/GridUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static string GetVersion() {
/// <returns></returns>
public static string GetFileVersion() {
Assembly assembly = typeof(GridUtils).Assembly;
return FileVersionInfo.GetVersionInfo(assembly.Location).FileVersion;
return assembly.Location == null ? null : FileVersionInfo.GetVersionInfo(assembly.Location).FileVersion;
}

/// <summary>
Expand Down
8 changes: 7 additions & 1 deletion src/Skybrud.Umbraco.GridData/Interfaces/IGridControlValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ public interface IGridControlValue {
/// </summary>
[JsonIgnore]
bool IsValid { get; }


/// <summary>
/// Gets the value of the control as a searchable text - eg. to be used in Examine.
/// </summary>
/// <returns>Returns an instance of <see cref="System.String"/> with the value as a searchable text.</returns>
string GetSearchableText();

}

}
2 changes: 1 addition & 1 deletion src/Skybrud.Umbraco.GridData/Properties/AssemblyInfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"copyright": "Copyright © 2016",
"version": "1.5.2.0",
"informationalVersion": "1.5.2",
"fileVersion": "0.0.730.1"
"fileVersion": "0.0.803.7"
}
Loading

0 comments on commit ccede77

Please sign in to comment.