Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make all template field info fields available. #28

Merged
merged 1 commit into from
Oct 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Leprechaun/Model/TemplateFieldCodeGenerationMetadata.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace Leprechaun.Model
Expand Down Expand Up @@ -32,6 +33,8 @@ public TemplateFieldCodeGenerationMetadata(TemplateFieldInfo field, string codeN

public virtual int SortOrder => Field.SortOrder;

public virtual Dictionary<Guid, string> AllFields => Field.AllFields;

/// <summary>
/// A unique name for this template field, usable as a C# identifier (e.g. property name)
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions src/Leprechaun/Model/TemplateFieldInfo.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace Leprechaun.Model
{
[DebuggerDisplay("{Path} ({Id})")]
public class TemplateFieldInfo
{
public TemplateFieldInfo()
{
AllFields = new Dictionary<Guid, string>();
}

public Guid Id { get; set; }

public string Name { get; set; }
Expand All @@ -23,5 +29,7 @@ public class TemplateFieldInfo
public string Section { get; set; }

public int SortOrder { get; set; }

public Dictionary<Guid, string> AllFields { get; set; }
}
}
40 changes: 39 additions & 1 deletion src/Leprechaun/TemplateReaders/DataStoreTemplateReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ protected virtual TemplateFieldInfo[] ParseTemplateFields(IItemData templateItem
Section = section.Name,
SortOrder = GetFieldValueAsInt(field, SortOrderFieldId, 100),
Source = GetFieldValue(field, SourceFieldId, string.Empty),
Type = GetFieldValue(field, FieldTypeFieldId, string.Empty)
Type = GetFieldValue(field, FieldTypeFieldId, string.Empty),
AllFields = GetAllFields(field)
});
}
}
Expand Down Expand Up @@ -180,5 +181,42 @@ protected virtual Guid[] ParseMultilistValue(string value)
}

protected virtual ICollection<Guid> IgnoredBaseTemplateIds => new HashSet<Guid> { TemplateIDs.StandardTemplate.Guid, TemplateIDs.Folder.Guid };

protected virtual Dictionary<Guid, string> GetAllFields(IItemData item)
{
var allFields = new Dictionary<Guid, string>();

foreach (var field in item.SharedFields)
{
if (!allFields.ContainsKey(field.FieldId))
{
allFields.Add(field.FieldId, field.Value);
}
}

foreach (var language in item.UnversionedFields)
{
foreach (var field in language.Fields)
{
if (!allFields.ContainsKey(field.FieldId))
{
allFields.Add(field.FieldId, field.Value);
}
}
}

foreach (var version in item.Versions)
{
foreach (var field in version.Fields)
{
if (!allFields.ContainsKey(field.FieldId))
{
allFields.Add(field.FieldId, field.Value);
}
}
}

return allFields;
}
}
}