Skip to content

Commit

Permalink
Merge pull request #5 from symptum/dev
Browse files Browse the repository at this point in the history
Editor v0.0.4
ShankarBUS authored Dec 8, 2024
2 parents 6cdb23e + cb2b770 commit 72fa7d8
Showing 167 changed files with 4,875 additions and 2,880 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/web-editor-deploy.yml
Original file line number Diff line number Diff line change
@@ -24,11 +24,11 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
dotnet-version: 9.0.x
- name: Restore Dependencies
run: dotnet restore ./main/src/Symptum.Editor/Symptum.Editor.csproj
- name: Publish
run: dotnet publish ./main/src/Symptum.Editor/Symptum.Editor.csproj "-p:WasmShellWebAppBasePath=/editor/" --no-restore -f net8.0-browserwasm -c Release -o out
run: dotnet publish ./main/src/Symptum.Editor/Symptum.Editor.csproj "-p:WasmShellWebAppBasePath=/editor/" --no-restore -f net9.0-browserwasm -c Release -o out
- name: Create Editor Folder
run: mkdir editor
- name: Copy Files to Editor Folder
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>

<LangVersion>preview</LangVersion>
<!--
Adding NoWarn to remove build warnings
NU1507: Warning when there are multiple package sources when using CPM with no source mapping
19 changes: 12 additions & 7 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -6,19 +6,24 @@
-->
<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.3.2" />
<PackageVersion Include="CommunityToolkit.WinUI.Controls.Primitives" Version="8.1.240916" />
<PackageVersion Include="ColorCode.Core" Version="2.0.15" />
<PackageVersion Include="CommunityToolkit.Labs.WinUI.Ribbon" Version="0.1.241129-build.1830" />
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.4.0-preview3" />
<PackageVersion Include="CommunityToolkit.WinUI.Controls.HeaderedControls" Version="8.2.241112-preview1" />
<PackageVersion Include="CommunityToolkit.WinUI.Controls.Primitives" Version="8.2.241112-preview1" />
<PackageVersion Include="CommunityToolkit.WinUI.Controls.Segmented" Version="8.2.241112-preview1" />
<PackageVersion Include="CommunityToolkit.WinUI.Controls.Sizers" Version="8.2.241112-preview1" />
<PackageVersion Include="CsvHelper" Version="33.0.1" />
<PackageVersion Include="CommunityToolkit.WinUI.UI.Controls.DataGrid" Version="7.1.2" />
<PackageVersion Include="HtmlAgilityPack" Version="1.11.70" />
<PackageVersion Include="HtmlAgilityPack" Version="1.11.71" />
<PackageVersion Include="Markdig" Version="0.38.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0-3.final" />
<PackageVersion Include="Roman-Numerals" Version="2.0.1" />
<PackageVersion Include="Uno.CommunityToolkit.WinUI.UI.Controls.DataGrid" Version="7.1.203" />
<PackageVersion Include="Uno.CommunityToolkit.WinUI.UI.Controls.DataGrid" Version="7.1.204" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.6.2" />
<PackageVersion Include="MSTest.TestFramework" Version="3.6.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.6.3" />
<PackageVersion Include="MSTest.TestFramework" Version="3.6.3" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
// To update the version of Uno please update the version of the Uno.Sdk here. See https://aka.platform.uno/upgrade-uno-packages for more information.
"msbuild-sdks": {
"Uno.Sdk": "5.6.0-dev.144"
"Uno.Sdk": "5.6.0-dev.264"
}
}
1 change: 1 addition & 0 deletions src/Symptum.Common/Helpers/PackageHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO.Compression;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text.Json;
using CsvHelper;
using Symptum.Core.Management.Deployment;
111 changes: 92 additions & 19 deletions src/Symptum.Common/Helpers/ResourceHelper.cs
Original file line number Diff line number Diff line change
@@ -107,9 +107,13 @@ public static async Task LoadResourcesFromFilesAsync(IEnumerable<StorageFile>? f

public static async Task<IResource?> LoadResourceFromFileAsync(StorageFile file, IResource? parent = null)
{
if (file == null) return null;

if (file.FileType.Equals(CsvFileExtension, StringComparison.InvariantCultureIgnoreCase))
return await LoadCsvFileResourceFromFileAsync(file, parent);
else if (file != null && file.FileType.Equals(JsonFileExtension, StringComparison.InvariantCultureIgnoreCase))
else if (file.FileType.Equals(MarkdownFileExtension, StringComparison.InvariantCultureIgnoreCase))
return await LoadMarkdownFileResourceFromFileAsync(file, parent);
else if (file.FileType.Equals(JsonFileExtension, StringComparison.InvariantCultureIgnoreCase))
return await LoadPackageResourceFromFileAsync(file);

return null;
@@ -138,6 +142,29 @@ public static async Task LoadResourcesFromFilesAsync(IEnumerable<StorageFile>? f
return null;
}

private static async Task<MarkdownFileResource?> LoadMarkdownFileResourceFromFileAsync(StorageFile? file, IResource? parent)
{
if (file != null && file.FileType.Equals(MarkdownFileExtension, StringComparison.InvariantCultureIgnoreCase))
{
string md = await FileIO.ReadTextAsync(file);

MarkdownFileResource markdownFileResource = new()
{
Title = file.DisplayName
};
ResourceManager.LoadResourceFile(markdownFileResource, md);

if (parent != null && parent.CanAddChildResourceType(typeof(MarkdownFileResource)))
parent.AddChildResource(markdownFileResource);
else
ResourceManager.Resources.Add(markdownFileResource);

return markdownFileResource;
}

return null;
}

internal static async Task<PackageResource?> LoadPackageResourceFromFileAsync(StorageFile? file)
{
if (file != null && file.FileType.Equals(JsonFileExtension, StringComparison.InvariantCultureIgnoreCase))
@@ -163,6 +190,11 @@ public static async Task LoadResourceAsync(IResource resource, IResource? parent
await LoadCSVFileResourceAsync(csvResource);
resource.InitializeResource(parent);
}
else if (resource is MarkdownFileResource markdownResource)
{
await LoadMarkdownFileResourceAsync(markdownResource);
resource.InitializeResource(parent);
}
else
{
if (resource is MetadataResource metadataResource && metadataResource.SplitMetadata)
@@ -186,44 +218,43 @@ private static async Task LoadChildrenResourcesAsync(IResource resource)
}
}

private static async Task LoadCSVFileResourceAsync(CsvFileResource csvResource)
private static async Task<StorageFile?> GetResourceFileAsync(string? path)
{
StorageFile? csvFile = null;

(string folderPath, string fileName, string extension) = GetDetailsFromFilePath(csvResource.FilePath);
(string folderPath, string fileName, string extension) = GetDetailsFromFilePath(path);
StorageFolder? folder = await StorageHelper.GetSubFolderAsync(_workFolder, folderPath);
if (folder != null)
{
try
{
csvFile = await folder.GetFileAsync(fileName + extension);
return await folder.GetFileAsync(fileName + extension);
}
catch { }
}

if (csvFile != null)
return null;
}

private static async Task LoadCSVFileResourceAsync(CsvFileResource csvResource)
{
if (await GetResourceFileAsync(csvResource.FilePath) is StorageFile csvFile)
{
string text = await FileIO.ReadTextAsync(csvFile);
ResourceManager.LoadResourceFile(csvResource, text);
}
}

private static async Task LoadMetadataResourceAsync(MetadataResource resource)
private static async Task LoadMarkdownFileResourceAsync(MarkdownFileResource markdownResource)
{
StorageFile? jsonFile = null;

(string folderPath, string fileName, string extension) = GetDetailsFromFilePath(resource.MetadataPath);
StorageFolder? folder = await StorageHelper.GetSubFolderAsync(_workFolder, folderPath);
if (folder != null)
if (await GetResourceFileAsync(markdownResource.FilePath) is StorageFile mdFile)
{
try
{
jsonFile = await folder.GetFileAsync(fileName + extension);
}
catch { }
string text = await FileIO.ReadTextAsync(mdFile);
ResourceManager.LoadResourceFile(markdownResource, text);
}
}

if (jsonFile != null)
private static async Task LoadMetadataResourceAsync(MetadataResource resource)
{
if (await GetResourceFileAsync(resource.MetadataPath) is StorageFile jsonFile)
{
string text = await FileIO.ReadTextAsync(jsonFile);
ResourceManager.LoadResourceMetadata(resource, text);
@@ -257,6 +288,10 @@ public static async Task<bool> SaveResourceAsync(IResource resource, StorageFold
{
return await SaveCSVFileAsync(csvResource, targetFolder);
}
else if (resource is MarkdownFileResource markdownResource)
{
return await SaveMarkdownFileAsync(markdownResource, targetFolder);
}
else
{
bool result = await SaveChildrenAsync(resource, targetFolder);
@@ -294,6 +329,26 @@ private static async Task<bool> SaveCSVFileAsync(CsvFileResource csvResource, St
return false;
}

private static async Task<bool> SaveMarkdownFileAsync(MarkdownFileResource markdownResource, StorageFolder? targetFolder = null)
{
if (markdownResource == null) return false;
//bool pathExists = await VerifyWorkFolderAsync(targetFolder);
//if (!pathExists) return false;

string subFolderPath = ResourceManager.GetResourceFolderPath(markdownResource);
string? fileName = ResourceManager.GetResourceFileName(markdownResource);
markdownResource.FilePath = subFolderPath + fileName + MarkdownFileExtension;
StorageFile? saveFile = await PickSaveFileAsync(fileName, MarkdownFileExtension, "Markdown File", targetFolder, subFolderPath);

if (saveFile != null)
{
string? text = ResourceManager.WriteResourceFileText(markdownResource);
return await StorageHelper.WriteToFileAsync(saveFile, text);
}

return false;
}

private static async Task<bool> SaveMetadataAsync<T>(T resource, StorageFolder? targetFolder = null) where T : MetadataResource
{
if (resource == null) return false;
@@ -366,6 +421,8 @@ public static async Task RemoveResourceAsync(IResource? resource, bool delete =

if (delete && resource is CsvFileResource csvResource)
await DeleteCSVFileAsync(csvResource);
else if (delete && resource is MarkdownFileResource markdownResource)
await DeleteMarkdownFileAsync(markdownResource);
else if (delete && resource is MetadataResource metadataResource)
await DeleteMetadataAsync(metadataResource);

@@ -395,6 +452,22 @@ private static async Task DeleteCSVFileAsync(CsvFileResource? csvResource)
}
}

private static async Task DeleteMarkdownFileAsync(MarkdownFileResource? markdownResource)
{
if (markdownResource == null) return;
if (_workFolder != null && StorageHelper.IsFolderPickerSupported)
{
try
{
string path = ResourceManager.GetResourceFolderPath(markdownResource);
var folder = await StorageHelper.GetSubFolderAsync(_workFolder, path);
IStorageItem? file = await folder?.TryGetItemAsync(ResourceManager.GetResourceFileName(markdownResource) + MarkdownFileExtension);
if (file != null) await file.DeleteAsync();
}
catch { }
}
}

private static async Task DeleteMetadataAsync(MetadataResource? resource)
{
if (resource == null) return;
9 changes: 4 additions & 5 deletions src/Symptum.Common/Symptum.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<Project Sdk="Uno.Sdk">
<PropertyGroup>
<TargetFrameworks>net9.0;net9.0-ios;net9.0-maccatalyst;net9.0-android;net9.0-windows10.0.22621;<!--net9.0-browserwasm-->;net9.0-desktop</TargetFrameworks>
<TargetFrameworks>net9.0;net9.0-ios;net9.0-maccatalyst;net9.0-android;net9.0-windows10.0.22621;net9.0-browserwasm;net9.0-desktop</TargetFrameworks>
<UnoSingleProject>true</UnoSingleProject>
<OutputType>Library</OutputType>
<!-- Ensures the .xr.xml files are generated in a proper layout folder -->
<GenerateLibraryLayout>true</GenerateLibraryLayout>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<!--Temp-->
<IsBrowserWasmProject>false</IsBrowserWasmProject>

<!--
UnoFeatures let's you quickly add and manage implicit package references based on the features you want to use.
https://aka.platform.uno/singleproject-features
@@ -32,10 +35,6 @@
<FrameworkReference Update="Microsoft.Windows.SDK.NET.Ref" TargetingPackVersion="10.0.22621.28" /> -->
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Symptum.Core\Symptum.Core.csproj" />
</ItemGroup>
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ private static (string? fieldName, string? propertyName, string? header, string?
public void Execute(GeneratorExecutionContext context)
{
string? nutrientIndexPath = context.AdditionalFiles
.FirstOrDefault(x => Path.GetFileName(x.Path).Equals("NutrientIndex.txt", StringComparison.OrdinalIgnoreCase))?.Path;
.FirstOrDefault(x => Path.GetFileName(x.Path).Equals("NutrientIndex.txt", StringComparison.InvariantCultureIgnoreCase))?.Path;

if (nutrientIndexPath == null) return;

5 changes: 1 addition & 4 deletions src/Symptum.Core/Data/Bibliography/BookReference.cs
Original file line number Diff line number Diff line change
@@ -81,9 +81,6 @@ public override string ToString()
return "@book?" + col.ToString() + ParserHelper.BookReferenceDelimiter + Pages;
}

public override string GetPreviewText()
{
return $"{Title} by {Authors}, " +
public override string GetPreviewText() => $"{Title} by {Authors}, " +
$"Edition: {Edition}, Volume: {Volume}, Pages: {Pages}";
}
}
10 changes: 2 additions & 8 deletions src/Symptum.Core/Data/Nutrition/FoodMeasure.cs
Original file line number Diff line number Diff line change
@@ -52,15 +52,9 @@ public static bool TryParse(string? text, [NotNullWhen(true)] out FoodMeasure? m
return parsed;
}

public override string ToString()
{
return JsonSerializer.Serialize(this, options);
}
public override string ToString() => JsonSerializer.Serialize(this, options);

public string GetPreviewText()
{
return $"{_title}: {_weight}";
}
public string GetPreviewText() => $"{_title}: {_weight}";

private static JsonSerializerOptions options = new()
{
44 changes: 6 additions & 38 deletions src/Symptum.Core/Data/Nutrition/NutritionDataSet.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Collections.ObjectModel;
using Symptum.Core.Management.Resources;
using Symptum.Core.Extensions;
using System.Text.Json.Serialization;

namespace Symptum.Core.Data.Nutrition;

public class NutritionDataSet : MetadataResource
public class NutritionDataSet : CategoryResource<FoodGroup>
{
public NutritionDataSet()
{ }
@@ -16,44 +16,12 @@ public NutritionDataSet(string title)

#region Properties

private ObservableCollection<FoodGroup>? groups;

public ObservableCollection<FoodGroup>? Groups
[JsonPropertyName("Groups")]
public override ObservableCollection<FoodGroup>? Items
{
get => groups;
set
{
UnobserveCollection(groups);
SetProperty(ref groups, value);
SetChildrenResources(groups);
}
get => base.Items;
set => base.Items = value;
}

#endregion

protected override void OnInitializeResource(IResource? parent)
{
SetChildrenResources(groups);
}

public override bool CanHandleChildResourceType(Type childResourceType)
{
return childResourceType == typeof(FoodGroup);
}

public override bool CanAddChildResourceType(Type childResourceType)
{
return childResourceType == typeof(FoodGroup);
}

protected override void OnAddChildResource(IResource? childResource)
{
Groups ??= [];
Groups.AddItemToListIfNotExists(childResource);
}

protected override void OnRemoveChildResource(IResource? childResource)
{
Groups.RemoveItemFromListIfExists(childResource);
}
}
Loading

0 comments on commit 72fa7d8

Please sign in to comment.