module creator templates need to be in the server project in order to be distributed with application
This commit is contained in:
		
							
								
								
									
										75
									
								
								Oqtane.Server/wwwroot/Modules/Templates/External/Server/Controllers/[Module]Controller.cs
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										75
									
								
								Oqtane.Server/wwwroot/Modules/Templates/External/Server/Controllers/[Module]Controller.cs
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,75 @@ | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
| using Microsoft.AspNetCore.Authorization; | ||||
| using System.Collections.Generic; | ||||
| using Oqtane.Shared; | ||||
| using Oqtane.Enums; | ||||
| using Oqtane.Infrastructure; | ||||
| using [Owner].[Module]s.Models; | ||||
| using [Owner].[Module]s.Repository; | ||||
|  | ||||
| namespace [Owner].[Module]s.Controllers | ||||
| { | ||||
|     [Route("{site}/api/[controller]")] | ||||
|     public class [Module]Controller : Controller | ||||
|     { | ||||
|         private readonly I[Module]Repository _[Module]s; | ||||
|         private readonly ILogManager _logger; | ||||
|  | ||||
|         public [Module]Controller(I[Module]Repository [Module]s, ILogManager logger) | ||||
|         { | ||||
|             _[Module]s = [Module]s; | ||||
|             _logger = logger; | ||||
|         } | ||||
|  | ||||
|         // GET: api/<controller>?moduleid=x | ||||
|         [HttpGet] | ||||
|         [Authorize(Roles = Constants.RegisteredRole)] | ||||
|         public IEnumerable<[Module]> Get(string moduleid) | ||||
|         { | ||||
|             return _[Module]s.Get[Module]s(int.Parse(moduleid)); | ||||
|         } | ||||
|  | ||||
|         // GET api/<controller>/5 | ||||
|         [HttpGet("{id}")] | ||||
|         [Authorize(Roles = Constants.RegisteredRole)] | ||||
|         public [Module] Get(int id) | ||||
|         { | ||||
|             return _[Module]s.Get[Module](id); | ||||
|         } | ||||
|  | ||||
|         // POST api/<controller> | ||||
|         [HttpPost] | ||||
|         [Authorize(Roles = Constants.AdminRole)] | ||||
|         public [Module] Post([FromBody] [Module] [Module]) | ||||
|         { | ||||
|             if (ModelState.IsValid) | ||||
|             { | ||||
|                 [Module] = _[Module]s.Add[Module]([Module]); | ||||
|                 _logger.Log(LogLevel.Information, this, LogFunction.Create, "[Module] Added {[Module]}", [Module]); | ||||
|             } | ||||
|             return [Module]; | ||||
|         } | ||||
|  | ||||
|         // PUT api/<controller>/5 | ||||
|         [HttpPut("{id}")] | ||||
|         [Authorize(Roles = Constants.AdminRole)] | ||||
|         public [Module] Put(int id, [FromBody] [Module] [Module]) | ||||
|         { | ||||
|             if (ModelState.IsValid) | ||||
|             { | ||||
|                 [Module] = _[Module]s.Update[Module]([Module]); | ||||
|                 _logger.Log(LogLevel.Information, this, LogFunction.Update, "[Module] Updated {[Module]}", [Module]); | ||||
|             } | ||||
|             return [Module]; | ||||
|         } | ||||
|  | ||||
|         // DELETE api/<controller>/5 | ||||
|         [HttpDelete("{id}")] | ||||
|         [Authorize(Roles = Constants.AdminRole)] | ||||
|         public void Delete(int id) | ||||
|         { | ||||
|             _[Module]s.Delete[Module](id); | ||||
|             _logger.Log(LogLevel.Information, this, LogFunction.Delete, "[Module] Deleted {[Module]Id}", id); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										64
									
								
								Oqtane.Server/wwwroot/Modules/Templates/External/Server/Manager/[Module]Manager.cs
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								Oqtane.Server/wwwroot/Modules/Templates/External/Server/Manager/[Module]Manager.cs
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,64 @@ | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text.Json; | ||||
| using Oqtane.Modules; | ||||
| using Oqtane.Models; | ||||
| using Oqtane.Infrastructure; | ||||
| using Oqtane.Repository; | ||||
| using [Owner].[Module]s.Models; | ||||
| using [Owner].[Module]s.Repository; | ||||
|  | ||||
| namespace [Owner].[Module]s.Manager | ||||
| { | ||||
|     public class [Module]Manager : IInstallable, IPortable | ||||
|     { | ||||
|         private I[Module]Repository _[Module]s; | ||||
|         private ISqlRepository _sql; | ||||
|  | ||||
|         public [Module]Manager(I[Module]Repository [Module]s, ISqlRepository sql) | ||||
|         { | ||||
|             _[Module]s = [Module]s; | ||||
|             _sql = sql; | ||||
|         } | ||||
|  | ||||
|         public bool Install(Tenant tenant, string version) | ||||
|         { | ||||
|             return _sql.ExecuteScript(tenant, GetType().Assembly, "[Owner].[Module]s." + version + ".sql"); | ||||
|         } | ||||
|  | ||||
|         public bool Uninstall(Tenant tenant) | ||||
|         { | ||||
|             return _sql.ExecuteScript(tenant, GetType().Assembly, "[Owner].[Module]s.Uninstall.sql"); | ||||
|         } | ||||
|  | ||||
|         public string ExportModule(Module module) | ||||
|         { | ||||
|             string content = ""; | ||||
|             List<[Module]> [Module]s = _[Module]s.Get[Module]s(module.ModuleId).ToList(); | ||||
|             if ([Module]s != null) | ||||
|             { | ||||
|                 content = JsonSerializer.Serialize([Module]s); | ||||
|             } | ||||
|             return content; | ||||
|         } | ||||
|  | ||||
|         public void ImportModule(Module module, string content, string version) | ||||
|         { | ||||
|             List<[Module]> [Module]s = null; | ||||
|             if (!string.IsNullOrEmpty(content)) | ||||
|             { | ||||
|                 [Module]s = JsonSerializer.Deserialize<List<[Module]>>(content); | ||||
|             } | ||||
|             if ([Module]s != null) | ||||
|             { | ||||
|                 foreach([Module] [Module] in [Module]s) | ||||
|                 { | ||||
|                     [Module] _[Module] = new [Module](); | ||||
|                     _[Module].ModuleId = module.ModuleId; | ||||
|                     _[Module].Name = [Module].Name; | ||||
|                     _[Module]s.Add[Module](_[Module]); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										14
									
								
								Oqtane.Server/wwwroot/Modules/Templates/External/Server/Repository/I[Module]Repository.cs
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								Oqtane.Server/wwwroot/Modules/Templates/External/Server/Repository/I[Module]Repository.cs
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,14 @@ | ||||
| using System.Collections.Generic; | ||||
| using [Owner].[Module]s.Models; | ||||
|  | ||||
| namespace [Owner].[Module]s.Repository | ||||
| { | ||||
|     public interface I[Module]Repository | ||||
|     { | ||||
|         IEnumerable<[Module]> Get[Module]s(int ModuleId); | ||||
|         [Module] Get[Module](int [Module]Id); | ||||
|         [Module] Add[Module]([Module] [Module]); | ||||
|         [Module] Update[Module]([Module] [Module]); | ||||
|         void Delete[Module](int [Module]Id); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										18
									
								
								Oqtane.Server/wwwroot/Modules/Templates/External/Server/Repository/[Module]Context.cs
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								Oqtane.Server/wwwroot/Modules/Templates/External/Server/Repository/[Module]Context.cs
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,18 @@ | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.AspNetCore.Http; | ||||
| using Oqtane.Modules; | ||||
| using Oqtane.Repository; | ||||
| using [Owner].[Module]s.Models; | ||||
|  | ||||
| namespace [Owner].[Module]s.Repository | ||||
| { | ||||
|     public class [Module]Context : DBContextBase, IService | ||||
|     { | ||||
|         public virtual DbSet<[Module]> [Module] { get; set; } | ||||
|  | ||||
|         public [Module]Context(ITenantResolver tenantResolver, IHttpContextAccessor accessor) : base(tenantResolver, accessor) | ||||
|         { | ||||
|             // ContextBase handles multi-tenant database connections | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										49
									
								
								Oqtane.Server/wwwroot/Modules/Templates/External/Server/Repository/[Module]Repository.cs
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								Oqtane.Server/wwwroot/Modules/Templates/External/Server/Repository/[Module]Repository.cs
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,49 @@ | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using System.Linq; | ||||
| using System.Collections.Generic; | ||||
| using Oqtane.Modules; | ||||
| using [Owner].[Module]s.Models; | ||||
|  | ||||
| namespace [Owner].[Module]s.Repository | ||||
| { | ||||
|     public class [Module]Repository : I[Module]Repository, IService | ||||
|     { | ||||
|         private readonly [Module]Context _db; | ||||
|  | ||||
|         public [Module]Repository([Module]Context context) | ||||
|         { | ||||
|             _db = context; | ||||
|         } | ||||
|  | ||||
|         public IEnumerable<[Module]> Get[Module]s(int ModuleId) | ||||
|         { | ||||
|             return _db.[Module].Where(item => item.ModuleId == ModuleId); | ||||
|         } | ||||
|  | ||||
|         public [Module] Get[Module](int [Module]Id) | ||||
|         { | ||||
|             return _db.[Module].Find([Module]Id); | ||||
|         } | ||||
|  | ||||
|         public [Module] Add[Module]([Module] [Module]) | ||||
|         { | ||||
|             _db.[Module].Add([Module]); | ||||
|             _db.SaveChanges(); | ||||
|             return [Module]; | ||||
|         } | ||||
|  | ||||
|         public [Module] Update[Module]([Module] [Module]) | ||||
|         { | ||||
|             _db.Entry([Module]).State = EntityState.Modified; | ||||
|             _db.SaveChanges(); | ||||
|             return [Module]; | ||||
|         } | ||||
|  | ||||
|         public void Delete[Module](int [Module]Id) | ||||
|         { | ||||
|             [Module] [Module] = _db.[Module].Find([Module]Id); | ||||
|             _db.[Module].Remove([Module]); | ||||
|             _db.SaveChanges(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										26
									
								
								Oqtane.Server/wwwroot/Modules/Templates/External/Server/Scripts/[Owner].[Module]s.1.0.0.sql
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								Oqtane.Server/wwwroot/Modules/Templates/External/Server/Scripts/[Owner].[Module]s.1.0.0.sql
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,26 @@ | ||||
| /*   | ||||
| Create [Owner][Module] table | ||||
| */ | ||||
|  | ||||
| CREATE TABLE [dbo].[[Owner][Module]]( | ||||
| 	[[Module]Id] [int] IDENTITY(1,1) NOT NULL, | ||||
| 	[ModuleId] [int] NOT NULL, | ||||
| 	[Name] [nvarchar](256) NOT NULL, | ||||
| 	[CreatedBy] [nvarchar](256) NOT NULL, | ||||
| 	[CreatedOn] [datetime] NOT NULL, | ||||
| 	[ModifiedBy] [nvarchar](256) NOT NULL, | ||||
| 	[ModifiedOn] [datetime] NOT NULL, | ||||
|   CONSTRAINT [PK_[Owner][Module]] PRIMARY KEY CLUSTERED  | ||||
|   ( | ||||
| 	[[Module]Id] ASC | ||||
|   ) | ||||
| ) | ||||
| GO | ||||
|  | ||||
| /*   | ||||
| Create foreign key relationships | ||||
| */ | ||||
| ALTER TABLE [dbo].[[Owner][Module]]  WITH CHECK ADD  CONSTRAINT [FK_[Owner][Module]_Module] FOREIGN KEY([ModuleId]) | ||||
| REFERENCES [dbo].Module ([ModuleId]) | ||||
| ON DELETE CASCADE | ||||
| GO | ||||
| @ -0,0 +1,6 @@ | ||||
| /*   | ||||
| Remove [Owner][Module] table | ||||
| */ | ||||
|  | ||||
| DROP TABLE [dbo].[[Owner][Module]] | ||||
| GO | ||||
							
								
								
									
										42
									
								
								Oqtane.Server/wwwroot/Modules/Templates/External/Server/[Owner].[Module]s.Server.csproj
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								Oqtane.Server/wwwroot/Modules/Templates/External/Server/[Owner].[Module]s.Server.csproj
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,42 @@ | ||||
| <Project Sdk="Microsoft.NET.Sdk.Razor"> | ||||
|  | ||||
|   <PropertyGroup> | ||||
|     <TargetFramework>netcoreapp3.1</TargetFramework> | ||||
|     <LangVersion>7.3</LangVersion> | ||||
|     <AddRazorSupportForMvc>true</AddRazorSupportForMvc> | ||||
|     <Version>1.0.0</Version> | ||||
|     <Product>[Owner].[Module]s</Product> | ||||
|     <Authors>[Owner]</Authors> | ||||
|     <Company>[Owner]</Company> | ||||
|     <Description>[Description]</Description> | ||||
|     <Copyright>[Owner]</Copyright> | ||||
|     <AssemblyName>[Owner].[Module]s.Server.Oqtane</AssemblyName> | ||||
|   </PropertyGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <EmbeddedResource Include="Scripts\[Owner].[Module]s.1.0.0.sql" /> | ||||
|     <EmbeddedResource Include="Scripts\[Owner].[Module]s.Uninstall.sql" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="3.2.0" /> | ||||
|     <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.4" /> | ||||
|     <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.4" /> | ||||
|     <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.4" /> | ||||
|     <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.4" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <ProjectReference Include="..\Shared\[Owner].[Module]s.Shared.csproj" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <Reference Include="Oqtane.Server"> | ||||
|       <HintPath>..\..\[RootFolder]\Oqtane.Server\bin\Debug\netcoreapp3.1\Oqtane.Server.dll</HintPath> | ||||
|     </Reference> | ||||
|     <Reference Include="Oqtane.Shared"> | ||||
|       <HintPath>..\..\[RootFolder]\Oqtane.Server\bin\Debug\netcoreapp3.1\Oqtane.Shared.dll</HintPath> | ||||
|     </Reference> | ||||
|   </ItemGroup> | ||||
|  | ||||
| </Project> | ||||
							
								
								
									
										1
									
								
								Oqtane.Server/wwwroot/Modules/Templates/External/Server/content/resources.txt
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								Oqtane.Server/wwwroot/Modules/Templates/External/Server/content/resources.txt
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | ||||
| This is the location where static resources for third party libraries should be located ( the third party library assemblies will be included in the /lib folder ). They should be placed in subfolders which match the naming convention of the third party library. When the module package is deployed the static resource subfolders will be extracted under the web root. | ||||
							
								
								
									
										1
									
								
								Oqtane.Server/wwwroot/Modules/Templates/External/Server/wwwroot/Module.css
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								Oqtane.Server/wwwroot/Modules/Templates/External/Server/wwwroot/Module.css
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | ||||
| /* Module Custom Styles */ | ||||
							
								
								
									
										1
									
								
								Oqtane.Server/wwwroot/Modules/Templates/External/Server/wwwroot/resources.txt
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								Oqtane.Server/wwwroot/Modules/Templates/External/Server/wwwroot/resources.txt
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | ||||
| This is the location where static resources such as images, style sheets, or scripts for this module will be located. Static assets can be organized in subfolders. When the module package is deployed the assets will be extracted under the web root in a folder that matches the module namespace. | ||||
		Reference in New Issue
	
	Block a user
	 Shaun Walker
					Shaun Walker