Resolve "Custom Repositories" #72
87
.idea/.idea.HopFrame/.idea/workspace.xml
generated
87
.idea/.idea.HopFrame/.idea/workspace.xml
generated
@@ -11,26 +11,7 @@
|
|||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="0648788e-7696-4e60-bf12-5d5601f33d8c" name="Changes" comment="">
|
<list default="true" id="0648788e-7696-4e60-bf12-5d5601f33d8c" name="Changes" comment="" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/HopFrame.Core/Config/RepositoryGroupConfig.cs" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/src/HopFrame.Core/Repositories/IHopFrameRepository.cs" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/src/HopFrame.Core/Services/Implementations/RepositoryTableManager.cs" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/Models/Guest.cs" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/Models/Message.cs" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/.idea.HopFrame/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.HopFrame/.idea/workspace.xml" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/HopFrame.Core/Config/DbContextConfig.cs" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Core/Config/DbContextConfig.cs" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/HopFrame.Core/Config/HopFrameConfig.cs" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Core/Config/HopFrameConfig.cs" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/HopFrame.Core/Config/TableConfig.cs" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Core/Config/TableConfig.cs" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/HopFrame.Core/Services/ITableManager.cs" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Core/Services/ITableManager.cs" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/HopFrame.Core/Services/Implementations/ContextExplorer.cs" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Core/Services/Implementations/ContextExplorer.cs" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/HopFrame.Core/Services/Implementations/TableManager.cs" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Core/Services/Implementations/TableManager.cs" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/HopFrame.Web/Components/Dialogs/HopFrameEditor.razor" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Web/Components/Dialogs/HopFrameEditor.razor" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/HopFrame.Web/Components/Pages/HopFrameTablePage.razor" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Web/Components/Pages/HopFrameTablePage.razor" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/HopFrame.Web/Plugins/Internal/ExporterPlugin.cs" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Web/Plugins/Internal/ExporterPlugin.cs" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/testing/HopFrame.Testing/Program.cs" beforeDir="false" afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/Program.cs" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/tests/HopFrame.Tests.Core/Services/TableManagerTests.cs" beforeDir="false" afterPath="$PROJECT_DIR$/tests/HopFrame.Tests.Core/Services/TableManagerTests.cs" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/tests/HopFrame.Tests.Web/Components/Pages/HopFrameTablePageTests.cs" beforeDir="false" afterPath="$PROJECT_DIR$/tests/HopFrame.Tests.Web/Components/Pages/HopFrameTablePageTests.cs" afterDir="false" />
|
|
||||||
</list>
|
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
@@ -136,28 +117,28 @@
|
|||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent"><![CDATA[{
|
<component name="PropertiesComponent">{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
".NET Launch Settings Profile.HopFrame.Testing.Api: https.executor": "Run",
|
".NET Launch Settings Profile.HopFrame.Testing.Api: https.executor": "Run",
|
||||||
".NET Launch Settings Profile.HopFrame.Testing.executor": "Run",
|
".NET Launch Settings Profile.HopFrame.Testing.executor": "Run",
|
||||||
".NET Launch Settings Profile.HopFrame.Testing: https.executor": "Run",
|
".NET Launch Settings Profile.HopFrame.Testing: https.executor": "Run",
|
||||||
".NET Project.HopFrame.Testing.executor": "Run",
|
".NET Project.HopFrame.Testing.executor": "Run",
|
||||||
"72b118b0-a6fc-4561-acdf-74f0b454dbb8.executor": "Debug",
|
"72b118b0-a6fc-4561-acdf-74f0b454dbb8.executor": "Debug",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"RunOnceActivity.git.unshallow": "true",
|
"RunOnceActivity.git.unshallow": "true",
|
||||||
"b5f11219-dfc4-47a1-b02c-90ab603034fb.executor": "Debug",
|
"b5f11219-dfc4-47a1-b02c-90ab603034fb.executor": "Debug",
|
||||||
"dcdf1689-dc07-47e4-8824-2e60a4fbf301.executor": "Debug",
|
"dcdf1689-dc07-47e4-8824-2e60a4fbf301.executor": "Debug",
|
||||||
"git-widget-placeholder": "!34 on feature/repositories",
|
"git-widget-placeholder": "!34 on feature/repositories",
|
||||||
"list.type.of.created.stylesheet": "CSS",
|
"list.type.of.created.stylesheet": "CSS",
|
||||||
"node.js.detected.package.eslint": "true",
|
"node.js.detected.package.eslint": "true",
|
||||||
"node.js.detected.package.tslint": "true",
|
"node.js.detected.package.tslint": "true",
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
"node.js.selected.package.tslint": "(autodetect)",
|
"node.js.selected.package.tslint": "(autodetect)",
|
||||||
"nodejs_package_manager_path": "npm",
|
"nodejs_package_manager_path": "npm",
|
||||||
"settings.editor.selected.configurable": "preferences.pluginManager",
|
"settings.editor.selected.configurable": "preferences.pluginManager",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"vue.rearranger.settings.migration": "true"
|
||||||
}
|
}
|
||||||
}]]></component>
|
}</component>
|
||||||
<component name="RunManager" selected=".NET Launch Settings Profile.HopFrame.Testing: https">
|
<component name="RunManager" selected=".NET Launch Settings Profile.HopFrame.Testing: https">
|
||||||
<configuration name="HopFrame.Testing: http" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
|
<configuration name="HopFrame.Testing: http" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
|
||||||
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/testing/HopFrame.Testing/HopFrame.Testing.csproj" />
|
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/testing/HopFrame.Testing/HopFrame.Testing.csproj" />
|
||||||
@@ -277,15 +258,7 @@
|
|||||||
<workItem from="1740741585276" duration="17000" />
|
<workItem from="1740741585276" duration="17000" />
|
||||||
<workItem from="1740742098571" duration="78000" />
|
<workItem from="1740742098571" duration="78000" />
|
||||||
<workItem from="1740742471317" duration="672000" />
|
<workItem from="1740742471317" duration="672000" />
|
||||||
<workItem from="1741974241977" duration="10362000" />
|
<workItem from="1741974241977" duration="10854000" />
|
||||||
</task>
|
|
||||||
<task id="LOCAL-00001" summary="Added basic configuration">
|
|
||||||
<option name="closed" value="true" />
|
|
||||||
<created>1736850899254</created>
|
|
||||||
<option name="number" value="00001" />
|
|
||||||
<option name="presentableId" value="LOCAL-00001" />
|
|
||||||
<option name="project" value="LOCAL" />
|
|
||||||
<updated>1736850899254</updated>
|
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00002" summary="Added admin page navigation">
|
<task id="LOCAL-00002" summary="Added admin page navigation">
|
||||||
<option name="closed" value="true" />
|
<option name="closed" value="true" />
|
||||||
@@ -671,7 +644,15 @@
|
|||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1740743139064</updated>
|
<updated>1740743139064</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="50" />
|
<task id="LOCAL-00050" summary="Added support for custom repositories">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1741985203179</created>
|
||||||
|
<option name="number" value="00050" />
|
||||||
|
<option name="presentableId" value="LOCAL-00050" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1741985203179</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="51" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
@@ -722,7 +703,6 @@
|
|||||||
<component name="UnityProjectConfiguration" hasMinimizedUI="false" />
|
<component name="UnityProjectConfiguration" hasMinimizedUI="false" />
|
||||||
<component name="VcsManagerConfiguration">
|
<component name="VcsManagerConfiguration">
|
||||||
<option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="true" />
|
<option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="true" />
|
||||||
<MESSAGE value="Implemented async delegates" />
|
|
||||||
<MESSAGE value="Added maximum display length" />
|
<MESSAGE value="Added maximum display length" />
|
||||||
<MESSAGE value="Fixed test for table view" />
|
<MESSAGE value="Fixed test for table view" />
|
||||||
<MESSAGE value="Added n-m relation mapping" />
|
<MESSAGE value="Added n-m relation mapping" />
|
||||||
@@ -747,6 +727,7 @@
|
|||||||
<MESSAGE value="Removed unused dependency" />
|
<MESSAGE value="Removed unused dependency" />
|
||||||
<MESSAGE value="Fixed directory in pipeline" />
|
<MESSAGE value="Fixed directory in pipeline" />
|
||||||
<MESSAGE value="Reverted pipeline to include all jobs" />
|
<MESSAGE value="Reverted pipeline to include all jobs" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="Reverted pipeline to include all jobs" />
|
<MESSAGE value="Added support for custom repositories" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="Added support for custom repositories" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
<toc-element topic="PropertyConfig.md"/>
|
<toc-element topic="PropertyConfig.md"/>
|
||||||
</toc-element>
|
</toc-element>
|
||||||
<toc-element topic="Callbacks.md"/>
|
<toc-element topic="Callbacks.md"/>
|
||||||
|
<toc-element topic="Custom-Repositories.md"/>
|
||||||
</toc-element>
|
</toc-element>
|
||||||
<toc-element toc-title="Web Module">
|
<toc-element toc-title="Web Module">
|
||||||
<toc-element toc-title="Interface">
|
<toc-element toc-title="Interface">
|
||||||
@@ -27,6 +28,10 @@
|
|||||||
<toc-element topic="Plugins.md">
|
<toc-element topic="Plugins.md">
|
||||||
<toc-element topic="Events.md">
|
<toc-element topic="Events.md">
|
||||||
</toc-element>
|
</toc-element>
|
||||||
|
<toc-element topic="Exporter-Plugin.md"/>
|
||||||
</toc-element>
|
</toc-element>
|
||||||
</toc-element>
|
</toc-element>
|
||||||
|
<toc-element toc-title="Services">
|
||||||
|
<toc-element topic="IFileService.md"/>
|
||||||
|
</toc-element>
|
||||||
</instance-profile>
|
</instance-profile>
|
||||||
132
docs/Writerside/topics/Custom-Repositories.md
Normal file
132
docs/Writerside/topics/Custom-Repositories.md
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
# Custom Repositories
|
||||||
|
|
||||||
|
Custom repositories in HopFrame allow you to define and integrate custom logic for managing database entities. By implementing the `IHopFrameRepository<TModel, TKey>` interface, you can gain full control over how data is retrieved, modified, and managed. This feature is ideal for scenarios where the default behavior does not meet specific business requirements.
|
||||||
|
|
||||||
|
## IHopFrameRepository<TModel, TKey> Interface
|
||||||
|
|
||||||
|
The `IHopFrameRepository<TModel, TKey>` interface defines a contract for a repository that works with a specific model (`TModel`) and its primary key (`TKey`). The interface provides the following methods:
|
||||||
|
|
||||||
|
- **LoadPage**
|
||||||
|
Loads a paginated set of items.
|
||||||
|
|
||||||
|
```c#
|
||||||
|
Task<IEnumerable<TModel>> LoadPage(int page, int perPage);
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Parameters:**
|
||||||
|
- `page`: The page number to load.
|
||||||
|
- `perPage`: The number of items per page.
|
||||||
|
- **Returns:** A collection of items for the specified page.
|
||||||
|
|
||||||
|
- **Search**
|
||||||
|
Performs a search query on the repository.
|
||||||
|
|
||||||
|
```c#
|
||||||
|
Task<SearchResult<TModel>> Search(string searchTerm, int page, int perPage);
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Parameters:**
|
||||||
|
- `searchTerm`: The term to search for.
|
||||||
|
- `page`: The page number to load.
|
||||||
|
- `perPage`: The number of items per page.
|
||||||
|
- **Returns:** A `SearchResult` containing matching items and the total number of pages.
|
||||||
|
|
||||||
|
- **GetTotalPageCount**
|
||||||
|
Retrieves the total number of pages based on the items per page.
|
||||||
|
|
||||||
|
```c#
|
||||||
|
Task<int> GetTotalPageCount(int perPage);
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Parameters:**
|
||||||
|
- `perPage`: The number of items per page.
|
||||||
|
- **Returns:** The total number of pages.
|
||||||
|
|
||||||
|
- **CreateItem**
|
||||||
|
Adds a new item to the repository.
|
||||||
|
|
||||||
|
```c#
|
||||||
|
Task CreateItem(TModel item);
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Parameters:**
|
||||||
|
- `item`: The item to create.
|
||||||
|
|
||||||
|
- **EditItem**
|
||||||
|
Updates an existing item in the repository.
|
||||||
|
|
||||||
|
```c#
|
||||||
|
Task EditItem(TModel item);
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Parameters:**
|
||||||
|
- `item`: The item to update.
|
||||||
|
|
||||||
|
- **DeleteItem**
|
||||||
|
Removes an item from the repository.
|
||||||
|
|
||||||
|
```c#
|
||||||
|
Task DeleteItem(TModel item);
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Parameters:**
|
||||||
|
- `item`: The item to delete.
|
||||||
|
|
||||||
|
- **GetOne**
|
||||||
|
Retrieves a single item based on its primary key.
|
||||||
|
|
||||||
|
```c#
|
||||||
|
Task<TModel?> GetOne(TKey key);
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Parameters:**
|
||||||
|
- `key`: The primary key of the item to retrieve.
|
||||||
|
- **Returns:** The item if found, or `null` if not.
|
||||||
|
|
||||||
|
## `SearchResult<TModel>` Struct
|
||||||
|
|
||||||
|
The `SearchResult<TModel>` struct is used to encapsulate the results of a search query.
|
||||||
|
|
||||||
|
- **Properties:**
|
||||||
|
- `Items`: The items retrieved from the search query.
|
||||||
|
- `PageCount`: The total number of pages based on the search results.
|
||||||
|
|
||||||
|
```c#
|
||||||
|
public readonly struct SearchResult<TModel>(IEnumerable<TModel> items, int pageCount) {
|
||||||
|
public IEnumerable<TModel> Items { get; init; }
|
||||||
|
public int PageCount { get; init; }
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Adding Custom Repositories
|
||||||
|
|
||||||
|
To add and configure a custom repository in HopFrame, use the `AddCustomRepository` methods. These methods allow you to specify a repository class (`TRepository`) implementing `IHopFrameRepository<TModel, TKey>` and define configurations for the associated table.
|
||||||
|
|
||||||
|
- **With Configurator**
|
||||||
|
|
||||||
|
```c#
|
||||||
|
HopFrameConfigurator AddCustomRepository<TRepository, TModel, TKey>(
|
||||||
|
Expression<Func<TModel, TKey>> keyExpression,
|
||||||
|
Action<TableConfigurator<TModel>> configurator
|
||||||
|
)
|
||||||
|
where TRepository : IHopFrameRepository<TModel, TKey>;
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Parameters:**
|
||||||
|
- `keyExpression`: The key of the model.
|
||||||
|
- `configurator`: Configures the table page.
|
||||||
|
|
||||||
|
- **Without Configurator**
|
||||||
|
|
||||||
|
```c#
|
||||||
|
TableConfigurator<TModel> AddCustomRepository<TRepository, TModel, TKey>(
|
||||||
|
Expression<Func<TModel, TKey>> keyExpression
|
||||||
|
)
|
||||||
|
where TRepository : IHopFrameRepository<TModel, TKey>;
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Parameters:**
|
||||||
|
- `keyExpression`: The key of the model.
|
||||||
|
- **Returns:** A `TableConfigurator` to configure the table.
|
||||||
|
|
||||||
|
By implementing custom repositories and using these methods, you can fully leverage the flexibility of HopFrame for your data management needs. Let me know if you'd like further elaboration!
|
||||||
51
docs/Writerside/topics/Exporter-Plugin.md
Normal file
51
docs/Writerside/topics/Exporter-Plugin.md
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
# Exporter Plugin
|
||||||
|
|
||||||
|
The Exporter Plugin is a tool for managing the import and export of data from the HopFrame UI. It provides functionality for exporting table data into a CSV file and importing data back into the system, making data manipulation and backups more seamless.
|
||||||
|
|
||||||
|
## What the Exporter Plugin Does
|
||||||
|
|
||||||
|
1. **Export Table Data to CSV**
|
||||||
|
- The plugin allows users to export all data from a table as a CSV file.
|
||||||
|
- The exported file includes all non-virtual properties as table headers.
|
||||||
|
- The export process dynamically constructs rows for each entry in the table.
|
||||||
|
|
||||||
|
2. **Import Data from CSV**
|
||||||
|
- Users can import a CSV file to populate or update a table.
|
||||||
|
- The import process reads the file, validates the headers, and creates new entries or updates existing ones.
|
||||||
|
- Relationships and enumerable properties are also resolved using the appropriate managers.
|
||||||
|
|
||||||
|
3. **User Interface Integration**
|
||||||
|
- Adds two buttons, "Export" and "Import," to the page header of each table.
|
||||||
|
- **Export Button:** Initiates the export functionality.
|
||||||
|
- **Import Button:** Allows users to upload a CSV file for import.
|
||||||
|
|
||||||
|
4. **Error Handling**
|
||||||
|
- Ensures errors during import or export (e.g., invalid file format, missing data, or system issues) are shown to the user as toast messages.
|
||||||
|
|
||||||
|
## Adding the Exporter Plugin
|
||||||
|
|
||||||
|
To include the Exporter Plugin in your HopFrame setup, use the `AddExporters` method provided by the `HopFrameConfiguratorExtensions`.
|
||||||
|
|
||||||
|
Here’s how to register the Exporter Plugin in your application configuration:
|
||||||
|
|
||||||
|
```c#
|
||||||
|
builder.Services.AddHopFrame(options => {
|
||||||
|
options.AddExporters();
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
The `AddExporters` method internally registers the `ExporterPlugin` and attaches its functionality to the HopFrame.
|
||||||
|
|
||||||
|
## Key Features of the Export Process
|
||||||
|
|
||||||
|
- **Dynamic Header Creation:** Automatically generates headers based on the table's non-virtual properties.
|
||||||
|
- **Data Transformation:** Transforms property values into CSV-compatible formats.
|
||||||
|
- **File Download:** Saves the generated CSV file with the table’s display name.
|
||||||
|
|
||||||
|
## Key Features of the Import Process
|
||||||
|
|
||||||
|
- **Header Validation:** Validates that the CSV file headers match the table's properties.
|
||||||
|
- **Type Conversion:** Converts values in the CSV file to their respective data types.
|
||||||
|
- **Relationship Management:** Resolves relationships and enumerable properties during import.
|
||||||
|
|
||||||
|
This plugin streamlines data operations, reducing manual effort and enabling quick data migration or updates. Let me know if you’d like to dive deeper into any specific aspect!
|
||||||
@@ -118,6 +118,50 @@ DbContextConfigurator<TDbContext>? GetDbContext<TDbContext>() where TDbContext :
|
|||||||
|
|
||||||
- **Returns:** The configurator of the context if it already was defined, `null` if not.
|
- **Returns:** The configurator of the context if it already was defined, `null` if not.
|
||||||
|
|
||||||
|
### AddCustomRepository (With configurator)
|
||||||
|
|
||||||
|
Adds a table of the desired type and configures it to use a custom repository.
|
||||||
|
|
||||||
|
```c#
|
||||||
|
HopFrameConfigurator AddCustomRepository<TRepository, TModel, TKey>(
|
||||||
|
Expression<Func<TModel, TKey>> keyExpression,
|
||||||
|
Action<TableConfigurator<TModel>> configurator
|
||||||
|
)
|
||||||
|
where TRepository : IHopFrameRepository<TModel, TKey>
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Type Parameters:**
|
||||||
|
- `TRepository`: The repository class that inherits from `IHopFrameRepository<TModel, TKey>` (needs to be registered as a service).
|
||||||
|
- `TModel`: The model of the table.
|
||||||
|
- `TKey`: The type of the primary key.
|
||||||
|
|
||||||
|
- **Parameters:**
|
||||||
|
- `keyExpression`: The key of the model.
|
||||||
|
- `configurator`: The configurator used for configuring the table page.
|
||||||
|
|
||||||
|
- **Returns:** `HopFrameConfigurator`
|
||||||
|
|
||||||
|
### AddCustomRepository (Without configurator)
|
||||||
|
|
||||||
|
Adds a table of the desired type and configures it to use a custom repository.
|
||||||
|
|
||||||
|
```c#
|
||||||
|
TableConfigurator<TModel> AddCustomRepository<TRepository, TModel, TKey>(
|
||||||
|
Expression<Func<TModel, TKey>> keyExpression
|
||||||
|
)
|
||||||
|
where TRepository : IHopFrameRepository<TModel, TKey>
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Type Parameters:**
|
||||||
|
- `TRepository`: The repository class that inherits from `IHopFrameRepository<TModel, TKey>` (needs to be registered as a service).
|
||||||
|
- `TModel`: The model of the table.
|
||||||
|
- `TKey`: The type of the primary key.
|
||||||
|
|
||||||
|
- **Parameters:**
|
||||||
|
- `keyExpression`: The key of the model.
|
||||||
|
|
||||||
|
- **Returns:** The configurator used for configuring the table page: `TableConfigurator<TModel>`.
|
||||||
|
|
||||||
### DisplayUserInfo
|
### DisplayUserInfo
|
||||||
|
|
||||||
Determines if the name of the currently logged-in user should be displayed in the top right corner of the admin UI.
|
Determines if the name of the currently logged-in user should be displayed in the top right corner of the admin UI.
|
||||||
|
|||||||
41
docs/Writerside/topics/IFileService.md
Normal file
41
docs/Writerside/topics/IFileService.md
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
# IFileService
|
||||||
|
|
||||||
|
The `IFileService` interface provides methods for handling file operations, such as downloading and uploading files within the HopFrame web application. It abstracts file-related operations to ensure a smooth and consistent user experience.
|
||||||
|
|
||||||
|
## Methods
|
||||||
|
|
||||||
|
1. **DownloadFile**
|
||||||
|
- Initiates the download of a file with the given name and data.
|
||||||
|
- Suitable for dynamically generating and offering files to the user, such as CSV exports or reports.
|
||||||
|
|
||||||
|
```c#
|
||||||
|
Task DownloadFile(string name, byte[] data);
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Parameters:**
|
||||||
|
- `name`: The name of the file to be downloaded (including the extension, e.g., "example.csv").
|
||||||
|
- `data`: The byte array representing the content of the file.
|
||||||
|
- **Usage Example:** Exporting table data as a CSV file for download.
|
||||||
|
|
||||||
|
2. **UploadFile**
|
||||||
|
- Allows the user to upload a file through the web interface and returns the uploaded file for further processing.
|
||||||
|
- This method provides integration with Blazor's `IBrowserFile` for easy file handling.
|
||||||
|
|
||||||
|
```c#
|
||||||
|
Task<IBrowserFile> UploadFile();
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Returns:** An `IBrowserFile` instance representing the uploaded file.
|
||||||
|
- **Usage Example:** Importing data from a CSV file to populate or update a table.
|
||||||
|
|
||||||
|
## Integration
|
||||||
|
|
||||||
|
The `IFileService` is commonly used in conjunction with plugins or components that require file operations, such as the Exporter Plugin, which leverages this service to enable data export and import functionality.
|
||||||
|
|
||||||
|
## Key Features
|
||||||
|
|
||||||
|
- Streamlines file handling for web applications.
|
||||||
|
- Simplifies both download and upload processes with minimal code.
|
||||||
|
- Ensures compatibility with Blazor's file-handling capabilities.
|
||||||
|
|
||||||
|
By implementing or extending the `IFileService`, developers can customize the file-handling behavior to suit specific application needs. Let me know if you'd like more examples or details!
|
||||||
@@ -56,6 +56,10 @@ public static class HopFrameConfiguratorExtensions {
|
|||||||
return configurator;
|
return configurator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Registers the Exporter Plugin for data import/export functionality.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="configurator">The configurator for the HopFrame configuration.</param>
|
||||||
public static HopFrameConfigurator AddExporters(this HopFrameConfigurator configurator) {
|
public static HopFrameConfigurator AddExporters(this HopFrameConfigurator configurator) {
|
||||||
configurator.AddPlugin<ExporterPlugin>();
|
configurator.AddPlugin<ExporterPlugin>();
|
||||||
return configurator;
|
return configurator;
|
||||||
|
|||||||
@@ -2,10 +2,22 @@
|
|||||||
|
|
||||||
namespace HopFrame.Web.Services;
|
namespace HopFrame.Web.Services;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides file handling capabilities for downloading and uploading files.
|
||||||
|
/// </summary>
|
||||||
public interface IFileService {
|
public interface IFileService {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initiates a file download with the specified name and data.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The name of the file to be downloaded.</param>
|
||||||
|
/// <param name="data">The byte array representing the file's content.</param>
|
||||||
public Task DownloadFile(string name, byte[] data);
|
public Task DownloadFile(string name, byte[] data);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Allows the user to upload a file and returns the uploaded file for processing.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A task that returns an IBrowserFile representing the uploaded file.</returns>
|
||||||
public Task<IBrowserFile> UploadFile();
|
public Task<IBrowserFile> UploadFile();
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user