remove Module Creator in favor of using Create Module in Module Management
This commit is contained in:
		| @ -1,203 +0,0 @@ | ||||
| @namespace Oqtane.Modules.Admin.ModuleCreator | ||||
| @inherits ModuleBase | ||||
| @using System.Text.RegularExpressions | ||||
| @inject NavigationManager NavigationManager | ||||
| @inject IModuleDefinitionService ModuleDefinitionService | ||||
| @inject IModuleService ModuleService | ||||
| @inject ISettingService SettingService | ||||
| @inject IStringLocalizer<Index> Localizer | ||||
| @inject IStringLocalizer<SharedResources> SharedLocalizer | ||||
|  | ||||
| @if (string.IsNullOrEmpty(_moduledefinitionname) && _templates != null) | ||||
| { | ||||
| 	<form @ref="form" class="@(validated ? "was-validated" : "needs-validation")" novalidate> | ||||
| 		<div class="container"> | ||||
| 			<div class="row mb-1 align-items-center"> | ||||
| 				<Label Class="col-sm-3" For="owner" HelpText="Enter the name of the organization who is developing this module. It should not contain spaces or punctuation." ResourceKey="OwnerName">Owner Name: </Label> | ||||
| 				<div class="col-sm-9"> | ||||
| 					<input id="owner" class="form-control" @bind="@_owner" required /> | ||||
| 				</div> | ||||
| 			</div> | ||||
| 			<div class="row mb-1 align-items-center"> | ||||
| 				<Label Class="col-sm-3" For="module" HelpText="Enter a name for this module. It should not contain spaces or punctuation." ResourceKey="ModuleName">Module Name: </Label> | ||||
| 				<div class="col-sm-9"> | ||||
| 					<input id="module" class="form-control" @bind="@_module" required /> | ||||
| 				</div> | ||||
| 			</div> | ||||
| 			<div class="row mb-1 align-items-center"> | ||||
| 				<Label Class="col-sm-3" For="description" HelpText="Enter a short description for the module" ResourceKey="Description">Description: </Label> | ||||
| 				<div class="col-sm-9"> | ||||
| 					<textarea id="description" class="form-control" @bind="@_description" rows="3" ></textarea> | ||||
| 				</div> | ||||
| 			</div> | ||||
| 			<div class="row mb-1 align-items-center"> | ||||
| 				<Label Class="col-sm-3" For="template" HelpText="Select a module template. Templates are located in the wwwroot/Modules/Templates folder on the server." ResourceKey="Template">Template: </Label> | ||||
| 				<div class="col-sm-9"> | ||||
| 					<select id="template" class="form-select" @onchange="(e => TemplateChanged(e))" required> | ||||
| 						<option value="-"><@Localizer["Template.Select"]></option> | ||||
| 						@foreach (Template template in _templates) | ||||
| 						{ | ||||
| 							<option value="@template.Name">@template.Title</option> | ||||
| 						} | ||||
| 					</select> | ||||
| 				</div> | ||||
| 			</div> | ||||
| 			<div class="row mb-1 align-items-center"> | ||||
| 				<Label Class="col-sm-3" For="reference" HelpText="Select a framework reference version" ResourceKey="FrameworkReference">Framework Reference: </Label> | ||||
| 				<div class="col-sm-9"> | ||||
| 					<select id="reference" class="form-select" @bind="@_reference" required> | ||||
| 						@foreach (string version in _versions) | ||||
| 						{ | ||||
| 							if (Version.Parse(version).CompareTo(Version.Parse(_minversion)) >= 0) | ||||
| 							{ | ||||
| 								<option value="@(version)">@(version)</option> | ||||
| 							} | ||||
| 						} | ||||
| 						<option value="local">@SharedLocalizer["LocalVersion"]</option> | ||||
| 					</select> | ||||
| 				</div> | ||||
| 			</div> | ||||
| 			@if (!string.IsNullOrEmpty(_location)) | ||||
| 			{ | ||||
| 				<div class="row mb-1 align-items-center"> | ||||
| 					<Label Class="col-sm-3" For="location" HelpText="Location where the module will be created" ResourceKey="Location">Location: </Label> | ||||
| 					<div class="col-sm-9"> | ||||
| 						<input id="module" class="form-control" @bind="@_location" readonly /> | ||||
| 					</div> | ||||
| 				</div> | ||||
| 			} | ||||
| 		</div> | ||||
| 	</form> | ||||
| 	<button type="button" class="btn btn-success" @onclick="CreateModule">@Localizer["Module.Create"]</button> | ||||
| } | ||||
| else | ||||
| { | ||||
|     <button type="button" class="btn btn-success" @onclick="ActivateModule">@Localizer["Module.Activate"]</button> | ||||
| } | ||||
|  | ||||
| @code { | ||||
| 	private ElementReference form; | ||||
| 	private bool validated = false; | ||||
| 	private string _moduledefinitionname = string.Empty; | ||||
| 	private string _owner = string.Empty; | ||||
| 	private string _module = string.Empty; | ||||
| 	private string _description = string.Empty; | ||||
| 	private List<Template> _templates; | ||||
| 	private string _template = "-"; | ||||
| 	private string[] _versions; | ||||
| 	private string _reference = "local"; | ||||
| 	private string _minversion = "2.0.0"; | ||||
| 	private string _location = string.Empty; | ||||
|  | ||||
| 	public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host; | ||||
|  | ||||
| 	protected override void OnInitialized() | ||||
| 	{ | ||||
| 		_moduledefinitionname = SettingService.GetSetting(ModuleState.Settings, "ModuleDefinitionName", ""); | ||||
| 		if (string.IsNullOrEmpty(_moduledefinitionname)) | ||||
| 		{ | ||||
| 			AddModuleMessage(Localizer["Info.Module.Creator"], MessageType.Info); | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			AddModuleMessage(Localizer["Info.Module.Activate"], MessageType.Info); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	protected override async Task OnParametersSetAsync() | ||||
| 	{ | ||||
| 		try | ||||
| 		{ | ||||
| 			_templates = await ModuleDefinitionService.GetModuleDefinitionTemplatesAsync(); | ||||
| 			_versions = Constants.ReleaseVersions.Split(',').Where(item => Version.Parse(item).CompareTo(Version.Parse("2.0.0")) >= 0).ToArray(); | ||||
| 		} | ||||
| 		catch (Exception ex) | ||||
| 		{ | ||||
| 			await logger.LogError(ex, "Error Loading Module Creator"); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	private async Task CreateModule() | ||||
| 	{ | ||||
| 		validated = true; | ||||
| 		var interop = new Interop(JSRuntime); | ||||
| 		if (await interop.FormValid(form)) | ||||
| 		{ | ||||
| 			try | ||||
| 			{ | ||||
| 				if (IsValid(_owner) && IsValid(_module) && _owner != _module && _template != "-") | ||||
| 				{ | ||||
| 					var moduleDefinition = new ModuleDefinition { Owner = _owner, Name = _module, Description = _description, Template = _template, Version = _reference }; | ||||
| 					moduleDefinition = await ModuleDefinitionService.CreateModuleDefinitionAsync(moduleDefinition); | ||||
|  | ||||
| 					var settings = await SettingService.GetModuleSettingsAsync(ModuleState.ModuleId); | ||||
| 					settings = SettingService.SetSetting(settings, "ModuleDefinitionName", moduleDefinition.ModuleDefinitionName); | ||||
| 					await SettingService.UpdateModuleSettingsAsync(settings, ModuleState.ModuleId); | ||||
|  | ||||
| 					GetLocation(); | ||||
| 					AddModuleMessage(string.Format(Localizer["Success.Module.Create"], NavigateUrl("admin/system")), MessageType.Success); | ||||
| 				} | ||||
|                 else | ||||
|                 { | ||||
|                     AddModuleMessage(Localizer["Message.Require.ValidName"], MessageType.Warning); | ||||
|                 } | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 await logger.LogError(ex, "Error Creating Module"); | ||||
|             } | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             AddModuleMessage(SharedLocalizer["Message.InfoRequired"], MessageType.Warning); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private async Task ActivateModule() | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             if (!string.IsNullOrEmpty(_moduledefinitionname)) | ||||
|             { | ||||
|                 Module module = await ModuleService.GetModuleAsync(ModuleState.ModuleId); | ||||
|                 module.ModuleDefinitionName = _moduledefinitionname; | ||||
|                 await ModuleService.UpdateModuleAsync(module); | ||||
|                 NavigationManager.NavigateTo(NavigateUrl(), true); | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             await logger.LogError(ex, "Error Activating Module"); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private bool IsValid(string name) | ||||
|     { | ||||
|         // must contain letters, underscores and digits and first character must be letter or underscore | ||||
| 		return !string.IsNullOrEmpty(name) && name.ToLower() != "module" && !name.ToLower().Contains("oqtane") && Regex.IsMatch(name, "^[A-Za-z_][A-Za-z0-9_]*$"); | ||||
|     } | ||||
|  | ||||
|     private void TemplateChanged(ChangeEventArgs e) | ||||
|     { | ||||
|         _template = (string)e.Value; | ||||
|         _minversion = "2.0.0"; | ||||
|         if (_template != "-") | ||||
|         { | ||||
|             var template = _templates.FirstOrDefault(item => item.Name == _template); | ||||
|             _minversion = template.Version; | ||||
|         } | ||||
|         GetLocation(); | ||||
|     } | ||||
|  | ||||
|     private void GetLocation() | ||||
|     { | ||||
|         _location = string.Empty; | ||||
|         if (_owner != "" && _module != "" && _template != "-") | ||||
|         { | ||||
|             var template = _templates.FirstOrDefault(item => item.Name == _template); | ||||
|             _location = template.Location + _owner + ".Module." + _module; | ||||
|  | ||||
|         } | ||||
|         StateHasChanged(); | ||||
|     } | ||||
| } | ||||
| @ -1,17 +0,0 @@ | ||||
| using Oqtane.Documentation; | ||||
| using Oqtane.Models; | ||||
|  | ||||
| namespace Oqtane.Modules.Admin.ModuleCreator | ||||
| { | ||||
|     [PrivateApi("Mark this as private, since it's not very useful in the public docs")] | ||||
|     public class ModuleInfo : IModule | ||||
|     { | ||||
|         public ModuleDefinition ModuleDefinition => new ModuleDefinition | ||||
|         { | ||||
|             Name = "Module Creator", | ||||
|             Description = "Enables software developers to quickly create modules by automating many of the initial module creation tasks", | ||||
|             Version = "1.0.0", | ||||
|             Categories = "Developer" | ||||
|         }; | ||||
|     } | ||||
| } | ||||
| @ -160,7 +160,7 @@ | ||||
|         if (_owner != "" && _module != "" && _template != "-") | ||||
|         { | ||||
|             var template = _templates.FirstOrDefault(item => item.Name == _template); | ||||
|             _location = template.Location + _owner + "." + _module; | ||||
|             _location = template.Location + _owner + ".Module." + _module; | ||||
|  | ||||
|         } | ||||
|         StateHasChanged(); | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 sbwalker
					sbwalker