Skip to content

Commit

Permalink
- Updates to Obsidian block Code Generation tool.
Browse files Browse the repository at this point in the history
  • Loading branch information
cabal95 committed Jun 20, 2022
1 parent 7a62993 commit 89ca4df
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Rock.Blocks/RockObsidianDetailBlockType.cs
Expand Up @@ -45,7 +45,7 @@ public abstract class RockObsidianDetailBlockType : RockObsidianBlockType
var entityService = ( Service<TEntity> ) Activator.CreateInstance( typeof( TService ), rockContext );

// If a zero identifier is specified then create a new entity.
if ( ( id.HasValue && id.Value == 0 ) || ( !id.HasValue && !guid.HasValue ) )
if ( ( id.HasValue && id.Value == 0 ) || ( guid.HasValue && guid.Value == Guid.Empty ) || ( !id.HasValue && !guid.HasValue && entityId.IsNullOrWhiteSpace() ) )
{
return new TEntity
{
Expand Down
46 changes: 46 additions & 0 deletions Rock.CodeGeneration/FileGenerators/CSharpViewModelGenerator.cs
@@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

using Rock.CodeGeneration.Utility;
using Rock.CodeGeneration.XmlDoc;

namespace Rock.CodeGeneration.FileGenerators
{
Expand All @@ -12,6 +14,15 @@ namespace Rock.CodeGeneration.FileGenerators
/// </summary>
public class CSharpViewModelGenerator : Generator
{
#region Fields

/// <summary>
/// The XML document reader for documentation.
/// </summary>
private readonly XmlDocReader _xmlDoc = SupportTools.GetXmlDocReader();

#endregion

#region Methods

/// <summary>
Expand Down Expand Up @@ -63,6 +74,8 @@ public string GenerateEntityBag( string entityName, string bagNamespace, List<En
var declaration = GetCSharpPropertyTypeDeclaration( property.PropertyType );

usings.AddRange( declaration.RequiredUsings );

AppendCommentBlock( sb, property.PropertyInfo, 8 );
sb.AppendLine( $" public {declaration.TypeName} {property.Name} {{ get; set; }}" );
}

Expand Down Expand Up @@ -103,6 +116,39 @@ private static PropertyDeclaration GetCSharpPropertyTypeDeclaration( Type type )
return type.GetCSharpPropertyDeclaration();
}

/// <summary>
/// Appends the comment block for the member to the StringBuilder.
/// </summary>
/// <param name="sb">The StringBuilder to append the comment to.</param>
/// <param name="memberInfo">The member information to get comments for.</param>
/// <param name="indentationSize">Size of the indentation for the comment block.</param>
private void AppendCommentBlock( StringBuilder sb, MemberInfo memberInfo, int indentationSize )
{
var xdoc = _xmlDoc.GetMemberComments( memberInfo )?.Summary?.PlainText;

AppendCommentBlock( sb, xdoc, indentationSize );
}

/// <summary>
/// Appends the comment block to the StringBuilder.
/// </summary>
/// <param name="sb">The StringBuilder to append the comment to.</param>
/// <param name="comment">The comment to append.</param>
/// <param name="indentationSize">Size of the indentation for the comment block.</param>
private void AppendCommentBlock( StringBuilder sb, string comment, int indentationSize )
{
if ( comment.IsNullOrWhiteSpace() )
{
return;
}

comment = comment.Replace( "\r\n", $"\r\n{new string( ' ', indentationSize )} * " );

sb.AppendLine( $"{new string( ' ', indentationSize )}/// <summary>" );
sb.AppendLine( $"{new string( ' ', indentationSize )}/// {comment}" );
sb.AppendLine( $"{new string( ' ', indentationSize )}/// </summary>" );
}

#endregion
}
}
6 changes: 3 additions & 3 deletions Rock.CodeGeneration/Resources/EditPanel-ts.lava
Expand Up @@ -21,11 +21,11 @@ import CheckBox from "@Obsidian/Controls/checkBox";{% endif %}{% if UseDescripti
import TextBox from "@Obsidian/Controls/textBox";{% endif %}
import { watchPropertyChanges } from "@Obsidian/Utility/block";
import { propertyRef, updateRefValue } from "@Obsidian/Utility/component";
import { {{ EntityName }}Bag } from "@Obsidian/ViewModels/Blocks/Core/{{ EntityName }}Detail/{{ EntityName | CamelCase }}Bag";
import { {{ EntityName }}DetailOptionsBag } from "@Obsidian/ViewModels/Blocks/Core/{{ EntityName }}Detail/{{ EntityName | CamelCase }}DetailOptionsBag";
import { {{ EntityName }}Bag } from "@Obsidian/ViewModels/Blocks/{{ Domain }}/{{ EntityName }}Detail/{{ EntityName | CamelCase }}Bag";
import { {{ EntityName }}DetailOptionsBag } from "@Obsidian/ViewModels/Blocks/{{ Domain }}/{{ EntityName }}Detail/{{ EntityName | CamelCase }}DetailOptionsBag";

export default defineComponent({
name: "Core.{{ EntityName }}Detail.EditPanel",
name: "{{ Domain }}.{{ EntityName }}Detail.EditPanel",

props: {
modelValue: {
Expand Down
4 changes: 2 additions & 2 deletions Rock.CodeGeneration/Resources/EntityDetailBlock-cs.lava
Expand Up @@ -25,7 +25,7 @@ using Rock.Constants;
using Rock.Data;
using Rock.Model;
using Rock.ViewModels.Blocks;
using Rock.ViewModels.Blocks.Core.{{ EntityName }}Detail;
using Rock.ViewModels.Blocks.{{ Domain }}.{{ EntityName }}Detail;

namespace Rock.Blocks.{{ Domain }}
{
Expand All @@ -35,7 +35,7 @@ namespace Rock.Blocks.{{ Domain }}
/// <seealso cref="Rock.Blocks.RockObsidianDetailBlockType" />

[DisplayName( "{{ EntityName | SplitCase }} Detail" )]
[Category( "Obsidian > {{ Domain }}" )]
[Category( "{{ Domain }}" )]
[Description( "Displays the details of a particular {{ EntityName | SplitCase | Downcase }}." )]
[IconCssClass( "fa fa-building" )]

Expand Down
6 changes: 3 additions & 3 deletions Rock.CodeGeneration/Resources/EntityDetailBlock-ts.lava
Expand Up @@ -27,11 +27,11 @@ import { getSecurityGrant, provideSecurityGrant{% if UseAttributeValues == true
import { debounce } from "@Obsidian/Utility/util";{% endif %}
import { NavigationUrlKey } from "./{{ EntityName }}Detail/types";
import { DetailBlockBox } from "@Obsidian/ViewModels/Blocks/detailBlockBox";
import { {{ EntityName }}Bag } from "@Obsidian/ViewModels/Blocks/Core/{{ EntityName }}Detail/{{ EntityName | CamelCase }}Bag";
import { {{ EntityName }}DetailOptionsBag } from "@Obsidian/ViewModels/Blocks/Core/{{ EntityName }}Detail/{{ EntityName | CamelCase }}DetailOptionsBag";
import { {{ EntityName }}Bag } from "@Obsidian/ViewModels/Blocks/{{ Domain }}/{{ EntityName }}Detail/{{ EntityName | CamelCase }}Bag";
import { {{ EntityName }}DetailOptionsBag } from "@Obsidian/ViewModels/Blocks/{{ Domain }}/{{ EntityName }}Detail/{{ EntityName | CamelCase }}DetailOptionsBag";

export default defineComponent({
name: "Core.{{ EntityName }}Detail",
name: "{{ Domain }}.{{ EntityName }}Detail",

components: {
Alert,
Expand Down
6 changes: 3 additions & 3 deletions Rock.CodeGeneration/Resources/ViewPanel-ts.lava
Expand Up @@ -21,11 +21,11 @@ import AttributeValuesContainer from "@Obsidian/Controls/attributeValuesContaine
import ValueDetailList from "@Obsidian/Controls/valueDetailList";
import { ValueDetailListItemBuilder } from "@Obsidian/Core/Controls/valueDetailListItemBuilder";
import { ValueDetailListItem } from "@Obsidian/Types/Controls/valueDetailListItem";
import { {{ EntityName }}Bag } from "@Obsidian/ViewModels/Blocks/Core/{{ EntityName }}Detail/{{ EntityName | CamelCase }}Bag";
import { {{ EntityName }}DetailOptionsBag } from "@Obsidian/ViewModels/Blocks/Core/{{ EntityName }}Detail/{{ EntityName | CamelCase }}DetailOptionsBag";
import { {{ EntityName }}Bag } from "@Obsidian/ViewModels/Blocks/{{ Domain }}/{{ EntityName }}Detail/{{ EntityName | CamelCase }}Bag";
import { {{ EntityName }}DetailOptionsBag } from "@Obsidian/ViewModels/Blocks/{{ Domain }}/{{ EntityName }}Detail/{{ EntityName | CamelCase }}DetailOptionsBag";

export default defineComponent({
name: "Core.{{ EntityName }}Detail.ViewPanel",
name: "{{ Domain }}.{{ EntityName }}Detail.ViewPanel",

props: {
modelValue: {
Expand Down
2 changes: 1 addition & 1 deletion Rock.CodeGeneration/Utility/EntityProperty.cs
Expand Up @@ -47,7 +47,7 @@ public class EntityProperty : LavaDynamic
/// Gets the property information.
/// </summary>
/// <value>The property information.</value>
protected PropertyInfo PropertyInfo { get; }
public PropertyInfo PropertyInfo { get; }

/// <summary>
/// Gets the type of the property.
Expand Down

0 comments on commit 89ca4df

Please sign in to comment.