Skip to content

Commit

Permalink
app assets - no leading slash, title is path
Browse files Browse the repository at this point in the history
  • Loading branch information
iJungleboy committed Dec 21, 2024
1 parent 4803f6f commit 9c32154
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public class AppFileDataRaw: AppFileDataRawBase
{
public const string TypeName = "File";

public static DataFactoryOptions Options = new(typeName: TypeName, titleField: nameof(Name));
public static DataFactoryOptions Options = new(typeName: TypeName, titleField: nameof(Path));

/// <summary>
/// The file name with extension.
/// </summary>
[ContentTypeAttributeSpecs(IsTitle = true, Description = "The file name without extension, like my-image")]
[ContentTypeAttributeSpecs(Description = "The file name without extension, like my-image")]
public override string Name { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public abstract class AppFileDataRawBase: IRawEntity, IHasRelationshipKeys
/// <summary>
/// Starting in the App-Root
/// </summary>
[ContentTypeAttributeSpecs(Description = "Full path. It starts at the root of the app or whatever other system you're asking for.")]
[ContentTypeAttributeSpecs(IsTitle = true, Description = "Full path. It starts at the root of the app or whatever other system you're asking for. Always end with slash, so root is `/` and it's easy to distinguish folders and files.")]
public string Path { get; set; }

/// <inheritdoc />
Expand All @@ -50,13 +50,6 @@ public abstract class AppFileDataRawBase: IRawEntity, IHasRelationshipKeys
[ContentTypeAttributeSpecs(Description = "The full url starting at the root of the site. Absolute but without protocol/domain.")]
public string Url { get; set; }

/// <summary>
/// The relative URL based on where the data was requested from. From the App Root or ADAM Root.
/// </summary>
[ContentTypeAttributeSpecs(Description = "The relative URL based on where the data was requested from. From the App Root or ADAM Root.")]
public string UrlRelative { get; set; }


/// <summary>
/// Data but without Id, Guid, Created, Modified
/// </summary>
Expand All @@ -68,12 +61,10 @@ public virtual IDictionary<string, object> Attributes(RawConvertOptions options)
{ nameof(FullName), FullName },
{ nameof(Path), Path },
{ nameof(Url), Url },
{ nameof(UrlRelative), UrlRelative },
{ "Parent", new RawRelationship(key: $"Folder:{ParentFolderInternal}") },

// For debugging
//{ nameof(ParentFolderInternal), ParentFolderInternal },

};

[PrivateApi]
Expand Down
19 changes: 9 additions & 10 deletions Src/Sxc/ToSic.Sxc/DataSources/Internal/CmsData/AppFolderDataRaw.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using ToSic.Eav.Data.Build;
using ToSic.Eav.Data.Internal;
using ToSic.Eav.Data.Raw;
using ToSic.Eav.Plumbing;

namespace ToSic.Sxc.DataSources.Internal;

Expand All @@ -26,20 +25,20 @@ public class AppFolderDataRaw: AppFileDataRawBase
{
public const string TypeName = "Folder";

public static DataFactoryOptions Options = new(typeName: TypeName, titleField: nameof(Title));
public static DataFactoryOptions Options = new(typeName: TypeName, titleField: nameof(Path));

/// <summary>
/// The folder name - or blank when it's the root.
/// </summary>
[ContentTypeAttributeSpecs(IsTitle = true, Description = "The folder name or blank when it's the root.")]
[ContentTypeAttributeSpecs(Description = "The folder name or blank when it's the root.")]
public override string Name { get; set; }

/// <summary>
/// The folder name.
/// </summary>
[ContentTypeAttributeSpecs(IsTitle = true, Description = "The folder name or 'root' when it's the root")]
//public string Title { get => field.NullIfNoValue() ?? "root"; set => field = value; }
public string Title => Name.NullIfNoValue() ?? "root";
///// <summary>
///// The folder name.
///// </summary>
//[ContentTypeAttributeSpecs(IsTitle = true, Description = "The folder name or 'root' when it's the root")]
////public string Title { get => field.NullIfNoValue() ?? "root"; set => field = value; }
//public string Title => Name.NullIfNoValue() ?? "root";


[PrivateApi]
Expand All @@ -48,7 +47,7 @@ public override IDictionary<string, object> Attributes(RawConvertOptions options
{
{ "Folders", new RawRelationship(key: $"FolderIn:{Path}") },
{ "Files", new RawRelationship(key: $"FileIn:{Path}") },
{ nameof(Title), Title }
//{ nameof(Title), Title },
};

[PrivateApi]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,13 @@ public class AdamDataSourceProvider<TFolderId, TFileId> : ServiceBase<AdamDataSo
private readonly MyServices _services;
private IContextOfApp _context;

public class MyServices : MyServicesBase
public class MyServices(
LazySvc<AdamContext<TFolderId, TFileId>> adamContext,
ISxcContextResolver ctxResolver)
: MyServicesBase(connect: [adamContext, ctxResolver])
{
public LazySvc<AdamContext<TFolderId, TFileId>> AdamContext { get; }
public ISxcContextResolver CtxResolver { get; }

/// <summary>
/// Note that we will use Generators for safety, because in rare cases the dependencies could be re-used to create a sub-data-source
/// </summary>
public MyServices(
LazySvc<AdamContext<TFolderId, TFileId>> adamContext,
ISxcContextResolver ctxResolver
)
{
ConnectLogs([
AdamContext = adamContext,
CtxResolver = ctxResolver
]);
}
public LazySvc<AdamContext<TFolderId, TFileId>> AdamContext { get; } = adamContext;
public ISxcContextResolver CtxResolver { get; } = ctxResolver;
}

protected AdamDataSourceProvider(MyServices services) : base(services, $"{SxcLogName}.AdamDs")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,16 @@ public AppAssetsDataSourceProvider Configure(
//var fullName = FullNameWithoutAppFolder(f.FullName, _appPaths, _root);
var fullNameFromAppRoot = FullNameWithoutAppFolder(f.FullName, pathsFromRoot);
var name = Path.GetFileNameWithoutExtension(f.FullName);
var path = fullNameFromAppRoot.TrimPrefixSlash();
return new AppFileDataRaw
{
Name = name,
Extension = f.Extension.TrimStart('.'), // Extension is without the dot
FullName = $"{name}{f.Extension}",
ParentFolderInternal = fullNameFromAppRoot.BeforeLast("/").SuffixSlash(),
Path = fullNameFromAppRoot,
ParentFolderInternal = path.BeforeLast("/").SuffixSlash(),
Path = path,
// TODO convert characters for safe HTML
Url = $"{_appPaths.Path}{fullNameFromAppRoot}",
UrlRelative = fullNameFromAppRoot,


Size = f.Length,
Created = f.CreationTime,
Expand Down Expand Up @@ -125,16 +124,16 @@ private AppFolderDataRaw ToFolderData(DirectoryInfo d, PreparedPaths pathsFromRo
// Name is the name of the folder, but if an alternative name is provided, use that instead
// this is for the root, which should have an "empty" name
var name = altName ?? Path.GetFileName(d.FullName);

return new()
{
Name = altName ?? name,
FullName = name,
ParentFolderInternal = fullNameFromAppRoot.BeforeLast("/").SuffixSlash(),
Path = fullNameFromAppRoot.SuffixSlash(),
ParentFolderInternal = fullNameFromAppRoot.TrimPrefixSlash().BeforeLast("/").SuffixSlash(),
Path = fullNameFromAppRoot.TrimPrefixSlash().SuffixSlash(),
Created = d.CreationTime,
Modified = d.LastWriteTime,
Url = $"{_appPaths.Path}{fullNameFromAppRoot}",
UrlRelative = fullNameFromAppRoot,
};
}

Expand Down

0 comments on commit 9c32154

Please sign in to comment.