- Private?
+ Private?
-
+
Yes
No
@@ -87,19 +87,20 @@
Cancel
@code {
- public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
- public override string Actions { get { return "Add,Edit"; } }
+ private int _profileid = -1;
+ private string _name = string.Empty;
+ private string _title = string.Empty;
+ private string _description = string.Empty;
+ private string _category = string.Empty;
+ private string _vieworder = "0";
+ private string _maxlength = "0";
+ private string _defaultvalue = string.Empty;
+ private string _isrequired = "False";
+ private string _isprivate = "False";
- int profileid = -1;
- string name = "";
- string title = "";
- string description = "";
- string category = "";
- string vieworder = "0";
- string maxlength = "0";
- string defaultvalue = "";
- string isrequired = "False";
- string isprivate = "False";
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin;
+
+ public override string Actions => "Add,Edit";
protected override async Task OnInitializedAsync()
{
@@ -107,25 +108,25 @@
{
if (PageState.QueryString.ContainsKey("id"))
{
- profileid = Int32.Parse(PageState.QueryString["id"]);
- Profile profile = await ProfileService.GetProfileAsync(profileid);
+ _profileid = Int32.Parse(PageState.QueryString["id"]);
+ var profile = await ProfileService.GetProfileAsync(_profileid);
if (profile != null)
{
- name = profile.Name;
- title = profile.Title;
- description = profile.Description;
- category = profile.Category;
- vieworder = profile.ViewOrder.ToString();
- maxlength = profile.MaxLength.ToString();
- defaultvalue = profile.DefaultValue;
- isrequired = profile.IsRequired.ToString();
- isprivate = profile.IsPrivate.ToString();
+ _name = profile.Name;
+ _title = profile.Title;
+ _description = profile.Description;
+ _category = profile.Category;
+ _vieworder = profile.ViewOrder.ToString();
+ _maxlength = profile.MaxLength.ToString();
+ _defaultvalue = profile.DefaultValue;
+ _isrequired = profile.IsRequired.ToString();
+ _isprivate = profile.IsPrivate.ToString();
}
}
}
catch (Exception ex)
{
- await logger.LogError(ex, "Error Loading Profile {ProfileId} {Error}", profileid, ex.Message);
+ await logger.LogError(ex, "Error Loading Profile {ProfileId} {Error}", _profileid, ex.Message);
AddModuleMessage("Error Loading Profile", MessageType.Error);
}
}
@@ -135,30 +136,38 @@
try
{
Profile profile;
- if (profileid != -1)
+ if (_profileid != -1)
{
- profile = await ProfileService.GetProfileAsync(profileid);
+ profile = await ProfileService.GetProfileAsync(_profileid);
}
else
{
profile = new Profile();
}
- profile.Name = name;
- profile.Title = title;
- profile.Description = description;
- profile.Category = category;
- profile.ViewOrder = int.Parse(vieworder);
- profile.MaxLength = int.Parse(maxlength);
- profile.DefaultValue = defaultvalue;
- profile.IsRequired = (isrequired == null ? false : Boolean.Parse(isrequired));
- profile.IsPrivate = (isprivate == null ? false : Boolean.Parse(isprivate));
- profile = await ProfileService.UpdateProfileAsync(profile);
+
+ profile.Name = _name;
+ profile.Title = _title;
+ profile.Description = _description;
+ profile.Category = _category;
+ profile.ViewOrder = int.Parse(_vieworder);
+ profile.MaxLength = int.Parse(_maxlength);
+ profile.DefaultValue = _defaultvalue;
+ profile.IsRequired = (_isrequired == null ? false : Boolean.Parse(_isrequired));
+ profile.IsPrivate = (_isprivate == null ? false : Boolean.Parse(_isprivate));
+ if (_profileid != -1)
+ {
+ profile = await ProfileService.UpdateProfileAsync(profile);
+ }else
+ {
+ profile = await ProfileService.AddProfileAsync(profile);
+ }
+
await logger.LogInformation("Profile Saved {Profile}", profile);
NavigationManager.NavigateTo(NavigateUrl());
}
catch (Exception ex)
{
- await logger.LogError(ex, "Error Saving Profile {ProfleId} {Error}", profileid, ex.Message);
+ await logger.LogError(ex, "Error Saving Profile {ProfleId} {Error}", _profileid, ex.Message);
AddModuleMessage("Error Saving Profile", MessageType.Error);
}
}
diff --git a/Oqtane.Client/Modules/Admin/Profiles/Index.razor b/Oqtane.Client/Modules/Admin/Profiles/Index.razor
index b362895a..e3cefdaa 100644
--- a/Oqtane.Client/Modules/Admin/Profiles/Index.razor
+++ b/Oqtane.Client/Modules/Admin/Profiles/Index.razor
@@ -2,7 +2,7 @@
@inherits ModuleBase
@inject IProfileService ProfileService
-@if (Profiles == null)
+@if (_profiles == null)
{
Loading...
}
@@ -10,7 +10,7 @@ else
{
-
+
@@ -25,27 +25,27 @@ else
}
@code {
- public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
+ private List _profiles;
- List Profiles;
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin;
protected override async Task OnInitializedAsync()
{
- Profiles = await ProfileService.GetProfilesAsync(PageState.Site.SiteId);
+ _profiles = await ProfileService.GetProfilesAsync(PageState.Site.SiteId);
}
- private async Task DeleteProfile(int ProfileId)
+ private async Task DeleteProfile(int profileId)
{
try
{
- await ProfileService.DeleteProfileAsync(ProfileId);
- await logger.LogInformation("Profile Deleted {ProfileId}", ProfileId);
+ await ProfileService.DeleteProfileAsync(profileId);
+ await logger.LogInformation("Profile Deleted {ProfileId}", profileId);
AddModuleMessage("Profile Deleted", MessageType.Success);
}
catch (Exception ex)
{
- await logger.LogError(ex, "Error Deleting Profile {ProfileId} {Error}", ProfileId, ex.Message);
+ await logger.LogError(ex, "Error Deleting Profile {ProfileId} {Error}", profileId, ex.Message);
AddModuleMessage("Error Deleting Profile", MessageType.Error);
}
}
-}
\ No newline at end of file
+}
diff --git a/Oqtane.Client/Modules/Admin/RecycleBin/Index.razor b/Oqtane.Client/Modules/Admin/RecycleBin/Index.razor
index ec7ef28b..d3955307 100644
--- a/Oqtane.Client/Modules/Admin/RecycleBin/Index.razor
+++ b/Oqtane.Client/Modules/Admin/RecycleBin/Index.razor
@@ -5,76 +5,74 @@
@inject IModuleService ModuleService
@inject IPageService PageService
-
-
- @if (pages.Count == 0)
+
+
+ @if (_pages == null)
{
-
+
No Deleted Pages
}
else
{
-
+
+
+
Name
Deleted By
Deleted On
-
-
+ RestorePage(context))" class="btn btn-info" title="Restore">Restore
+
@context.Name
@context.DeletedBy
@context.DeletedOn
- RestorePage(context))" class="btn btn-info" title="Restore">Restore
- DeletePage(context.PageId))" class="btn btn-danger">Delete
}
-
- @if (pageModules.Count == 0)
+
+ @if (_modules == null)
{
-
+
No Deleted Modules
}
else
{
-
+
+
+
Page
Module
Deleted By
Deleted On
-
-
+ RestoreModule(context))" class="btn btn-info" title="Restore">Restore
+
@PageState.Pages.Find(item => item.PageId == context.PageId).Name
@context.Title
@context.DeletedBy
@context.DeletedOn
- RestorePageModule(context))" class="btn btn-info" title="Restore">Restore
- DeletePageModule(context.PageModuleId, context.ModuleId))" class="btn btn-danger">Delete
}
-
+
@code {
- public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
+ private List _pages;
+ private List _modules;
- List pages { get; set; }
- List pageModules { get; set; }
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin;
protected override async Task OnInitializedAsync()
{
try
{
- pages = new List();
- pageModules = new List();
- await LoadEntities();
+ await Load();
}
catch (Exception ex)
{
@@ -83,92 +81,89 @@
}
}
- protected override void OnParametersSet()
+ private async Task Load()
{
- pages = PageState.Pages.Where(item => item.IsDeleted).ToList();
+ _pages = await PageService.GetPagesAsync(PageState.Site.SiteId);
+ _pages = _pages.Where(item => item.IsDeleted).ToList();
+
+ _modules = await ModuleService.GetModulesAsync(PageState.Site.SiteId);
+ _modules = _modules.Where(item => item.IsDeleted).ToList();
}
- private async Task LoadEntities()
- {
- pageModules.Clear();
- foreach (var module in PageState.Modules.Where(item => item.IsDeleted))
- {
- var pageModule = await PageModuleService.GetPageModuleAsync(module.PageModuleId);
- pageModules.Add(pageModule);
- }
- }
-
- private async Task RestorePage(Page Page)
+ private async Task RestorePage(Page page)
{
try
{
- Page.IsDeleted = false;
- await PageService.UpdatePageAsync(Page);
- await logger.LogInformation("Page Restored {Page}", Page);
- NavigationManager.NavigateTo(NavigateUrl(Reload.Site));
+ page.IsDeleted = false;
+ await PageService.UpdatePageAsync(page);
+ await logger.LogInformation("Page Restored {Page}", page);
+ await Load();
+ StateHasChanged();
+ NavigationManager.NavigateTo(NavigateUrl());
}
catch (Exception ex)
{
- await logger.LogError(ex, "Error Restoring Deleted Page {Page} {Error}", Page, ex.Message);
+ await logger.LogError(ex, "Error Restoring Deleted Page {Page} {Error}", page, ex.Message);
AddModuleMessage("Error Restoring Deleted Page", MessageType.Error);
}
}
- private async Task DeletePage(int PageId)
+ private async Task DeletePage(Page page)
{
try
{
- var deletedPageModules = PageState.Modules.Where(item => item.PageId == PageId);
- await PageService.DeletePageAsync(PageId);
- foreach (var module in deletedPageModules)
- {
- await ModuleService.DeleteModuleAsync(module.ModuleId);
- }
- await logger.LogInformation("Page Permanently Deleted {PageId}", PageId);
- NavigationManager.NavigateTo(NavigateUrl(Reload.Site));
+ await PageService.DeletePageAsync(page.PageId);
+ await logger.LogInformation("Page Permanently Deleted {Page}", page);
+ await Load();
+ StateHasChanged();
+ NavigationManager.NavigateTo(NavigateUrl());
}
catch (Exception ex)
{
- await logger.LogError(ex, "Error Permanently Deleting Page {PageId} {Error}", PageId, ex.Message);
+ await logger.LogError(ex, "Error Permanently Deleting Page {Page} {Error}", page, ex.Message);
AddModuleMessage(ex.Message, MessageType.Error);
}
}
- private async Task RestorePageModule(PageModule PageModule)
+ private async Task RestoreModule(Module module)
{
try
{
- PageModule.IsDeleted = false;
- await PageModuleService.UpdatePageModuleAsync(PageModule);
- await LoadEntities();
- await logger.LogInformation("Page Module Restored {PageModule}", PageModule);
- NavigationManager.NavigateTo(NavigateUrl(Reload.Site));
+ var pagemodule = await PageModuleService.GetPageModuleAsync(module.PageModuleId);
+ pagemodule.IsDeleted = false;
+ await PageModuleService.UpdatePageModuleAsync(pagemodule);
+ await logger.LogInformation("Module Restored {Module}", module);
+ await Load();
+ StateHasChanged();
}
catch (Exception ex)
{
- await logger.LogError(ex, "Error Restoring Deleted Page Module {PageModule} {Error}", PageModule, ex.Message);
- AddModuleMessage("Error Restoring Deleted Page Module", MessageType.Error);
+ await logger.LogError(ex, "Error Restoring Deleted Module {Module} {Error}", module, ex.Message);
+ AddModuleMessage("Error Restoring Deleted Module", MessageType.Error);
}
}
- private async Task DeletePageModule(int PageModuleId, int ModuleId)
+ private async Task DeleteModule(Module module)
{
try
{
- await PageModuleService.DeletePageModuleAsync(PageModuleId);
- if (PageState.Modules.Count(item => item.ModuleId == ModuleId) == 1)
+ await PageModuleService.DeletePageModuleAsync(module.PageModuleId);
+ // check if there are any remaining module instances in the site
+ _modules = await ModuleService.GetModulesAsync(PageState.Site.SiteId);
+
+ if (!_modules.Exists(item => item.ModuleId == module.ModuleId))
{
- await ModuleService.DeleteModuleAsync(ModuleId);
+ await ModuleService.DeleteModuleAsync(module.ModuleId);
}
- PageState.Modules.RemoveAt(PageState.Modules.FindIndex(item => item.ModuleId == ModuleId));
- await LoadEntities();
- await logger.LogInformation("Page Module Permanently Deleted {PageModuleId}", PageModuleId);
- NavigationManager.NavigateTo(NavigateUrl(Reload.Site));
+
+ await logger.LogInformation("Module Permanently Deleted {Module}", module);
+ await Load();
+ StateHasChanged();
}
catch (Exception ex)
{
- await logger.LogError(ex, "Error Permanently Deleting Page Module {PageModuleId} {Error}", PageModuleId, ex.Message);
- AddModuleMessage("Error Permanently Deleting Page Module", MessageType.Error);
+ await logger.LogError(ex, "Error Permanently Deleting Module {Module} {Error}", module, ex.Message);
+ AddModuleMessage("Error Permanently Deleting Module", MessageType.Error);
}
}
}
diff --git a/Oqtane.Client/Modules/Admin/Register/Index.razor b/Oqtane.Client/Modules/Admin/Register/Index.razor
index 40b59b89..2ea64944 100644
--- a/Oqtane.Client/Modules/Admin/Register/Index.razor
+++ b/Oqtane.Client/Modules/Admin/Register/Index.razor
@@ -3,71 +3,87 @@
@inject NavigationManager NavigationManager
@inject IUserService UserService
-@if (Message != "")
+@if (PageState.Site.AllowRegistration)
{
-
+
+
+ ...
+
+
+
+
+
+
+
+
+
+
+}
+else
+{
+
}
-
-
@code {
- public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Anonymous; } }
+ private string _username = string.Empty;
+ private string _password = string.Empty;
+ private string _confirm = string.Empty;
+ private string _email = string.Empty;
+ private string _displayName = string.Empty;
- string Message = "Please Note That Registration Requires A Valid Email Address In Order To Verify Your Identity";
- string Username = "";
- string Password = "";
- string Confirm = "";
- string Email = "";
- string DisplayName = "";
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Anonymous;
private async Task Register()
{
try
{
- Message = "";
- if (Username != "" && Password != "" && Confirm != "" && Email != "")
+ bool _isEmailValid = Utilities.IsValidEmail(_email);
+
+ if (_username != "" && _password != "" && _confirm != "" && _isEmailValid)
{
- if (Password == Confirm)
+ if (_password == _confirm)
{
- User user = new User();
- user.SiteId = PageState.Site.SiteId;
- user.Username = Username;
- user.DisplayName = (DisplayName == "" ? Username : DisplayName);
- user.Email = Email;
- user.Password = Password;
+ var user = new User
+ {
+ SiteId = PageState.Site.SiteId,
+ Username = _username,
+ DisplayName = (_displayName == string.Empty ? _username : _displayName),
+ Email = _email,
+ Password = _password
+ };
user = await UserService.AddUserAsync(user);
if (user != null)
{
- await logger.LogInformation("User Created {Username} {Email}", Username, Email);
+ await logger.LogInformation("User Created {Username} {Email}", _username, _email);
AddModuleMessage("User Account Created. Please Check Your Email For Verification Instructions.", MessageType.Info);
}
else
{
- await logger.LogError("Error Adding User {Username} {Email}", Username, Email);
+ await logger.LogError("Error Adding User {Username} {Email}", _username, _email);
AddModuleMessage("Error Adding User. Please Ensure Password Meets Complexity Requirements And Username Is Not Already In Use.", MessageType.Error);
}
}
@@ -83,13 +99,13 @@
}
catch (Exception ex)
{
- await logger.LogError(ex, "Error Adding User {Username} {Email} {Error}", Username, Email, ex.Message);
+ await logger.LogError(ex, "Error Adding User {Username} {Email} {Error}", _username, _email, ex.Message);
AddModuleMessage("Error Adding User", MessageType.Error);
}
}
private void Cancel()
{
- NavigationManager.NavigateTo(NavigateUrl(""));
+ NavigationManager.NavigateTo(NavigateUrl(string.Empty));
}
-}
+}
\ No newline at end of file
diff --git a/Oqtane.Client/Modules/Admin/Reset/Index.razor b/Oqtane.Client/Modules/Admin/Reset/Index.razor
index e7ed6bbe..b6e4eb66 100644
--- a/Oqtane.Client/Modules/Admin/Reset/Index.razor
+++ b/Oqtane.Client/Modules/Admin/Reset/Index.razor
@@ -6,36 +6,36 @@
@code {
- public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Anonymous; } }
+ private string _username = string.Empty;
+ private string _password = string.Empty;
+ private string _confirm = string.Empty;
- string Username = "";
- string Password = "";
- string Confirm = "";
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Anonymous;
protected override void OnInitialized()
{
if (PageState.QueryString.ContainsKey("name") && PageState.QueryString.ContainsKey("token"))
{
- Username = PageState.QueryString["name"];
+ _username = PageState.QueryString["name"];
}
else
{
- NavigationManager.NavigateTo(NavigateUrl(""));
+ NavigationManager.NavigateTo(NavigateUrl(string.Empty));
}
}
@@ -43,24 +43,26 @@
{
try
{
- if (Username != "" && Password != "" && Confirm != "")
+ if (_username != string.Empty && _password != string.Empty && _confirm != string.Empty)
{
- if (Password == Confirm)
+ if (_password == _confirm)
{
- User user = new User();
- user.SiteId = PageState.Site.SiteId;
- user.Username = Username;
- user.Password = Password;
+ var user = new User
+ {
+ SiteId = PageState.Site.SiteId,
+ Username = _username,
+ Password = _password
+ };
user = await UserService.ResetPasswordAsync(user, PageState.QueryString["token"]);
if (user != null)
{
- await logger.LogInformation("User Password Reset {Username}", Username);
+ await logger.LogInformation("User Password Reset {Username}", _username);
NavigationManager.NavigateTo(NavigateUrl("login"));
}
else
{
- await logger.LogError("Error Resetting User Password {Username}", Username);
+ await logger.LogError("Error Resetting User Password {Username}", _username);
AddModuleMessage("Error Resetting User Password. Please Ensure Password Meets Complexity Requirements.", MessageType.Error);
}
}
@@ -76,13 +78,13 @@
}
catch (Exception ex)
{
- await logger.LogError(ex, "Error Resetting User Password {Username} {Error}", Username, ex.Message);
+ await logger.LogError(ex, "Error Resetting User Password {Username} {Error}", _username, ex.Message);
AddModuleMessage("Error Resetting User Password", MessageType.Error);
}
}
private void Cancel()
{
- NavigationManager.NavigateTo(NavigateUrl(""));
+ NavigationManager.NavigateTo(NavigateUrl(string.Empty));
}
}
diff --git a/Oqtane.Client/Modules/Admin/Roles/Add.razor b/Oqtane.Client/Modules/Admin/Roles/Add.razor
index c2bff1da..34e93e2d 100644
--- a/Oqtane.Client/Modules/Admin/Roles/Add.razor
+++ b/Oqtane.Client/Modules/Admin/Roles/Add.razor
@@ -6,37 +6,26 @@
- Name:
+ Name:
-
+
- Description:
+ Description:
-
+
- Auto Assigned?
+ Auto Assigned?
-
- Yes
- No
-
-
-
-
-
- System Role?
-
-
-
+
Yes
No
@@ -46,22 +35,21 @@
Save
Cancel
-@code {
- public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
+@code {
+ private string _name = string.Empty;
+ private string _description = string.Empty;
+ private string _isautoassigned = "False";
- string name = "";
- string description = "";
- string isautoassigned = "False";
- string issystem = "False";
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin;
private async Task SaveRole()
{
- Role role = new Role();
+ var role = new Role();
role.SiteId = PageState.Page.SiteId;
- role.Name = name;
- role.Description = description;
- role.IsAutoAssigned = (isautoassigned == null ? false : Boolean.Parse(isautoassigned));
- role.IsSystem = (issystem == null ? false : Boolean.Parse(issystem));
+ role.Name = _name;
+ role.Description = _description;
+ role.IsAutoAssigned = (_isautoassigned == null ? false : Boolean.Parse(_isautoassigned));
+ role.IsSystem = false;
try
{
diff --git a/Oqtane.Client/Modules/Admin/Roles/Edit.razor b/Oqtane.Client/Modules/Admin/Roles/Edit.razor
index 2557bd44..4b0dd0e0 100644
--- a/Oqtane.Client/Modules/Admin/Roles/Edit.razor
+++ b/Oqtane.Client/Modules/Admin/Roles/Edit.razor
@@ -6,37 +6,26 @@
- Name:
+ Name:
-
+
- Description:
+ Description:
-
+
- Auto Assigned?
+ Auto Assigned?
-
- Yes
- No
-
-
-
-
-
- System Role?
-
-
-
+
Yes
No
@@ -47,42 +36,40 @@
Cancel
@code {
- public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
+ private int _roleid;
+ private string _name = string.Empty;
+ private string _description = string.Empty;
+ private string _isautoassigned = "False";
- int roleid;
- string name = "";
- string description = "";
- string isautoassigned = "False";
- string issystem = "False";
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin;
protected override async Task OnInitializedAsync()
{
try
{
- roleid = Int32.Parse(PageState.QueryString["id"]);
- Role role = await RoleService.GetRoleAsync(roleid);
+ _roleid = Int32.Parse(PageState.QueryString["id"]);
+ var role = await RoleService.GetRoleAsync(_roleid);
if (role != null)
{
- name = role.Name;
- description = role.Description;
- isautoassigned = role.IsAutoAssigned.ToString();
- issystem = role.IsSystem.ToString();
+ _name = role.Name;
+ _description = role.Description;
+ _isautoassigned = role.IsAutoAssigned.ToString();
}
}
catch (Exception ex)
{
- await logger.LogError(ex, "Error Loading Role {RoleId} {Error}", roleid, ex.Message);
+ await logger.LogError(ex, "Error Loading Role {RoleId} {Error}", _roleid, ex.Message);
AddModuleMessage("Error Loading Role", MessageType.Error);
}
}
private async Task SaveRole()
{
- Role role = await RoleService.GetRoleAsync(roleid);
- role.Name = name;
- role.Description = description;
- role.IsAutoAssigned = (isautoassigned == null ? false : Boolean.Parse(isautoassigned));
- role.IsSystem = (issystem == null ? false : Boolean.Parse(issystem));
+ var role = await RoleService.GetRoleAsync(_roleid);
+ role.Name = _name;
+ role.Description = _description;
+ role.IsAutoAssigned = (_isautoassigned != null && Boolean.Parse(_isautoassigned));
+ role.IsSystem = false;
try
{
diff --git a/Oqtane.Client/Modules/Admin/Roles/Index.razor b/Oqtane.Client/Modules/Admin/Roles/Index.razor
index 79124760..881a9348 100644
--- a/Oqtane.Client/Modules/Admin/Roles/Index.razor
+++ b/Oqtane.Client/Modules/Admin/Roles/Index.razor
@@ -2,7 +2,7 @@
@inherits ModuleBase
@inject IRoleService RoleService
-@if (Roles == null)
+@if (_roles == null)
{
Loading...
}
@@ -10,42 +10,44 @@ else
{
-
+
-
-
+
+
+
@context.Name
}
@code {
- public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
+ private List _roles;
- List Roles;
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin;
protected override async Task OnParametersSetAsync()
{
- Roles = await RoleService.GetRolesAsync(PageState.Site.SiteId);
+ _roles = await RoleService.GetRolesAsync(PageState.Site.SiteId);
}
- private async Task DeleteRole(Role Role)
+ private async Task DeleteRole(Role role)
{
try
{
- await RoleService.DeleteRoleAsync(Role.RoleId);
- await logger.LogInformation("Role Deleted {Role}", Role);
+ await RoleService.DeleteRoleAsync(role.RoleId);
+ await logger.LogInformation("Role Deleted {Role}", role);
StateHasChanged();
}
catch (Exception ex)
{
- await logger.LogError(ex, "Error Deleting Role {Role} {Error}", Role, ex.Message);
+ await logger.LogError(ex, "Error Deleting Role {Role} {Error}", role, ex.Message);
AddModuleMessage("Error Deleting Role", MessageType.Error);
}
}
-}
\ No newline at end of file
+}
diff --git a/Oqtane.Client/Modules/Admin/Roles/Users.razor b/Oqtane.Client/Modules/Admin/Roles/Users.razor
new file mode 100644
index 00000000..c292d3d5
--- /dev/null
+++ b/Oqtane.Client/Modules/Admin/Roles/Users.razor
@@ -0,0 +1,201 @@
+@namespace Oqtane.Modules.Admin.Roles
+@inherits ModuleBase
+@inject IRoleService RoleService
+@inject IUserRoleService UserRoleService
+
+@if (userroles == null)
+{
+ Loading...
+}
+else
+{
+
+ Save
+ Cancel
+
+
+
+
+
+
+ @context.User.DisplayName
+
+ await DeleteUserRole(context.UserRoleId))>Delete
+
+
+
+
+}
+
+@code {
+ private int roleid;
+ private string name = string.Empty;
+ private List users;
+ private int userid = -1;
+ private string effectivedate = string.Empty;
+ private string expirydate = string.Empty;
+ private List userroles;
+
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin;
+
+ protected override async Task OnInitializedAsync()
+ {
+ try
+ {
+ roleid = Int32.Parse(PageState.QueryString["id"]);
+ Role role = await RoleService.GetRoleAsync(roleid);
+ name = role.Name;
+ users = await UserRoleService.GetUserRolesAsync(PageState.Site.SiteId);
+ users = users.Where(item => item.Role.Name == Constants.RegisteredRole).ToList();
+ await GetUserRoles();
+ }
+ catch (Exception ex)
+ {
+ await logger.LogError(ex, "Error Loading Users {Error}", ex.Message);
+ AddModuleMessage("Error Loading Users", MessageType.Error);
+ }
+ }
+
+ private async Task GetUserRoles()
+ {
+ try
+ {
+ userroles = await UserRoleService.GetUserRolesAsync(PageState.Site.SiteId);
+ userroles = userroles.Where(item => item.RoleId == roleid).ToList();
+ }
+ catch (Exception ex)
+ {
+ await logger.LogError(ex, "Error Loading User Roles {RoleId} {Error}", roleid, ex.Message);
+ AddModuleMessage("Error Loading User Roles", MessageType.Error);
+ }
+ }
+
+ private async Task SaveUserRole()
+ {
+ try
+ {
+ if (userid != -1)
+ {
+ var userrole = userroles.Where(item => item.UserId == userid && item.RoleId == roleid).FirstOrDefault();
+ if (userrole != null)
+ {
+ if (string.IsNullOrEmpty(effectivedate))
+ {
+ userrole.EffectiveDate = null;
+ }
+ else
+ {
+ userrole.EffectiveDate = DateTime.Parse(effectivedate);
+ }
+
+ if (string.IsNullOrEmpty(expirydate))
+ {
+ userrole.ExpiryDate = null;
+ }
+ else
+ {
+ userrole.ExpiryDate = DateTime.Parse(expirydate);
+ }
+ await UserRoleService.UpdateUserRoleAsync(userrole);
+ }
+ else
+ {
+ userrole = new UserRole();
+ userrole.UserId = userid;
+ userrole.RoleId = roleid;
+
+ if (string.IsNullOrEmpty(effectivedate))
+ {
+ userrole.EffectiveDate = null;
+ }
+ else
+ {
+ userrole.EffectiveDate = DateTime.Parse(effectivedate);
+ }
+
+ if (string.IsNullOrEmpty(expirydate))
+ {
+ userrole.ExpiryDate = null;
+ }
+ else
+ {
+ userrole.ExpiryDate = DateTime.Parse(expirydate);
+ }
+
+ await UserRoleService.AddUserRoleAsync(userrole);
+ }
+
+ await GetUserRoles();
+ await logger.LogInformation("User Assigned To Role {UserRole}", userrole);
+ AddModuleMessage("User Assigned To Role", MessageType.Success);
+ }
+ else
+ {
+ AddModuleMessage("You Must Select A User", MessageType.Warning);
+ }
+ }
+ catch (Exception ex)
+ {
+ await logger.LogError(ex, "Error Saving User Roles {RoleId} {Error}", roleid, ex.Message);
+ AddModuleMessage("Error Saving User Roles", MessageType.Error);
+ }
+ }
+
+ private async Task DeleteUserRole(int UserRoleId)
+ {
+ try
+ {
+ await UserRoleService.DeleteUserRoleAsync(UserRoleId);
+ await GetUserRoles();
+ await logger.LogInformation("User Removed From Role {UserRoleId}", UserRoleId);
+ AddModuleMessage("User Removed From Role", MessageType.Success);
+ }
+ catch (Exception ex)
+ {
+ await logger.LogError(ex, "Error Removing User From Role {UserRoleId} {Error}", UserRoleId, ex.Message);
+ AddModuleMessage("Error Removing User From Role", MessageType.Error);
+ }
+ }
+}
diff --git a/Oqtane.Client/Modules/Admin/Site/Index.razor b/Oqtane.Client/Modules/Admin/Site/Index.razor
new file mode 100644
index 00000000..3f3425f6
--- /dev/null
+++ b/Oqtane.Client/Modules/Admin/Site/Index.razor
@@ -0,0 +1,451 @@
+@namespace Oqtane.Modules.Admin.Site
+@inherits ModuleBase
+@inject NavigationManager NavigationManager
+@inject ISiteService SiteService
+@inject ITenantService TenantService
+@inject IAliasService AliasService
+@inject IThemeService ThemeService
+@inject ISettingService SettingService
+
+@if (_themes != null)
+{
+
+
+
+
+
+
+
+ Is Enabled?
+
+
+
+ Yes
+ No
+
+
+
+
+
+ App Icon:
+
+
+
+
+
+
+
+ Splash Icon:
+
+
+
+
+
+
+
+
+
+ Save
+ Cancel
+
+
+
+}
+
+@code {
+ private Dictionary _themes;
+ private Dictionary _panelayouts;
+ private Dictionary _containers;
+ private List _themeList;
+ private string _name = string.Empty;
+ private List _tenantList;
+ private string _tenant = string.Empty;
+ private List _aliasList;
+ private string _urls = string.Empty;
+ private int _logofileid = -1;
+ private FileManager _logofilemanager;
+ private int _faviconfileid = -1;
+ private FileManager _faviconfilemanager;
+ private string _themetype;
+ private string _layouttype;
+ private string _containertype;
+ private string _allowregistration;
+ private string _smtphost = string.Empty;
+ private string _smtpport = string.Empty;
+ private string _smtpssl = string.Empty;
+ private string _smtpusername = string.Empty;
+ private string _smtppassword = string.Empty;
+ private string _pwaisenabled;
+ private int _pwaappiconfileid = -1;
+ private FileManager _pwaappiconfilemanager;
+ private int _pwasplashiconfileid = -1;
+ private FileManager _pwasplashiconfilemanager;
+ private string _createdby;
+ private DateTime _createdon;
+ private string _modifiedby;
+ private DateTime _modifiedon;
+ private string _deletedby;
+ private DateTime? _deletedon;
+ private string _isdeleted;
+
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin;
+
+ protected override async Task OnInitializedAsync()
+ {
+ try
+ {
+ _themeList = await ThemeService.GetThemesAsync();
+ _aliasList = await AliasService.GetAliasesAsync();
+ Site site = await SiteService.GetSiteAsync(PageState.Site.SiteId);
+ if (site != null)
+ {
+ _name = site.Name;
+ _tenantList = await TenantService.GetTenantsAsync();
+ _tenant = _tenantList.Find(item => item.TenantId == site.TenantId).Name;
+ foreach (Alias alias in _aliasList.Where(item => item.SiteId == site.SiteId && item.TenantId == site.TenantId).ToList())
+ {
+ _urls += alias.Name + "\n";
+ }
+ if (site.LogoFileId != null)
+ {
+ _logofileid = site.LogoFileId.Value;
+ }
+
+ if (site.FaviconFileId != null)
+ {
+ _faviconfileid = site.FaviconFileId.Value;
+ }
+
+ _themetype = site.DefaultThemeType;
+ _panelayouts = ThemeService.GetPaneLayoutTypes(_themeList, _themetype);
+ _layouttype = site.DefaultLayoutType;
+ _containertype = site.DefaultContainerType;
+ _allowregistration = site.AllowRegistration.ToString();
+
+ var settings = await SettingService.GetSiteSettingsAsync(site.SiteId);
+ _smtphost = SettingService.GetSetting(settings, "SMTPHost", string.Empty);
+ _smtpport = SettingService.GetSetting(settings, "SMTPPort", string.Empty);
+ _smtpssl = SettingService.GetSetting(settings, "SMTPSSL", string.Empty);
+ _smtpusername = SettingService.GetSetting(settings, "SMTPUsername", string.Empty);
+ _smtppassword = SettingService.GetSetting(settings, "SMTPPassword", string.Empty);
+
+ _pwaisenabled = site.PwaIsEnabled.ToString();
+
+ if (site.PwaAppIconFileId != null)
+ {
+ _pwaappiconfileid = site.PwaAppIconFileId.Value;
+ }
+
+ if (site.PwaSplashIconFileId != null)
+ {
+ _pwasplashiconfileid = site.PwaSplashIconFileId.Value;
+ }
+
+ _pwaisenabled = site.PwaIsEnabled.ToString();
+ if (site.PwaAppIconFileId != null)
+ {
+ _pwaappiconfileid = site.PwaAppIconFileId.Value;
+ }
+ if (site.PwaSplashIconFileId != null)
+ {
+ _pwasplashiconfileid = site.PwaSplashIconFileId.Value;
+ }
+
+ _createdby = site.CreatedBy;
+ _createdon = site.CreatedOn;
+ _modifiedby = site.ModifiedBy;
+ _modifiedon = site.ModifiedOn;
+ _deletedby = site.DeletedBy;
+ _deletedon = site.DeletedOn;
+ _isdeleted = site.IsDeleted.ToString();
+ }
+
+ _themes = ThemeService.GetThemeTypes(_themeList);
+ _containers = ThemeService.GetContainerTypes(_themeList);
+ }
+ catch (Exception ex)
+ {
+ await logger.LogError(ex, "Error Loading Site {SiteId} {Error}", PageState.Site.SiteId, ex.Message);
+ AddModuleMessage(ex.Message, MessageType.Error);
+ }
+ }
+
+ private async void ThemeChanged(ChangeEventArgs e)
+ {
+ try
+ {
+ _themetype = (string)e.Value;
+ if (_themetype != string.Empty)
+ {
+ _panelayouts = ThemeService.GetPaneLayoutTypes(_themeList, _themetype);
+ }
+ else
+ {
+ _panelayouts = new Dictionary();
+ }
+ StateHasChanged();
+ }
+ catch (Exception ex)
+ {
+ await logger.LogError(ex, "Error Loading Pane Layouts For Theme {ThemeType} {Error}", _themetype, ex.Message);
+ AddModuleMessage("Error Loading Pane Layouts For Theme", MessageType.Error);
+ }
+ }
+
+ private async Task SaveSite()
+ {
+ try
+ {
+ if (_name != string.Empty && _urls != string.Empty && !string.IsNullOrEmpty(_themetype) && (_panelayouts.Count == 0 || !string.IsNullOrEmpty(_layouttype)) && !string.IsNullOrEmpty(_containertype))
+ {
+ var unique = true;
+ foreach (string name in _urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
+ {
+ if (_aliasList.Exists(item => item.Name == name && item.SiteId != PageState.Alias.SiteId && item.TenantId != PageState.Alias.TenantId))
+ {
+ unique = false;
+ }
+ }
+
+ if (unique)
+ {
+ var site = await SiteService.GetSiteAsync(PageState.Site.SiteId);
+ if (site != null)
+ {
+ site.Name = _name;
+ site.LogoFileId = null;
+ var logofileid = _logofilemanager.GetFileId();
+ if (logofileid != -1)
+ {
+ site.LogoFileId = logofileid;
+ }
+
+ site.DefaultThemeType = _themetype;
+ site.DefaultLayoutType = (_layouttype == null ? string.Empty : _layouttype);
+ site.DefaultContainerType = _containertype;
+ site.AllowRegistration = (_allowregistration == null ? true : Boolean.Parse(_allowregistration));
+ site.IsDeleted = (_isdeleted == null ? true : Boolean.Parse(_isdeleted));
+
+ site.PwaIsEnabled = (_pwaisenabled == null ? true : Boolean.Parse(_pwaisenabled));
+
+ var pwaappiconfileid = _pwaappiconfilemanager.GetFileId();
+ if (pwaappiconfileid != -1)
+ {
+ site.PwaAppIconFileId = pwaappiconfileid;
+ }
+
+ var pwasplashiconfileid = _pwasplashiconfilemanager.GetFileId();
+ if (pwasplashiconfileid != -1)
+ {
+ site.PwaSplashIconFileId = pwasplashiconfileid;
+ }
+
+ site = await SiteService.UpdateSiteAsync(site);
+
+ _urls = _urls.Replace("\n", ",");
+ var names = _urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
+ foreach (Alias alias in _aliasList.Where(item => item.SiteId == site.SiteId && item.TenantId == site.TenantId).ToList())
+ {
+ if (!names.Contains(alias.Name))
+ {
+ await AliasService.DeleteAliasAsync(alias.AliasId);
+ }
+ }
+
+ foreach (string name in names)
+ {
+ if (!_aliasList.Exists(item => item.Name == name))
+ {
+ Alias alias = new Alias();
+ alias.Name = name;
+ alias.TenantId = site.TenantId;
+ alias.SiteId = site.SiteId;
+ await AliasService.AddAliasAsync(alias);
+ }
+ }
+
+ var settings = await SettingService.GetSiteSettingsAsync(site.SiteId);
+ SettingService.SetSetting(settings, "SMTPHost", _smtphost);
+ SettingService.SetSetting(settings, "SMTPPort", _smtpport);
+ SettingService.SetSetting(settings, "SMTPSSL", _smtpssl);
+ SettingService.SetSetting(settings, "SMTPUsername", _smtpusername);
+ SettingService.SetSetting(settings, "SMTPPassword", _smtppassword);
+ await SettingService.UpdateSiteSettingsAsync(settings, site.SiteId);
+
+ await logger.LogInformation("Site Saved {Site}", site);
+
+ NavigationManager.NavigateTo(NavigateUrl());
+ }
+ }
+ else
+ {
+ AddModuleMessage("An Alias Specified Has Already Been Used For Another Site", MessageType.Warning);
+ }
+ }
+ else
+ {
+ AddModuleMessage("You Must Provide A Site Name, Alias, And Default Theme/Container", MessageType.Warning);
+ }
+ }
+ catch (Exception ex)
+ {
+ await logger.LogError(ex, "Error Saving Site {SiteId} {Error}", PageState.Site.SiteId, ex.Message);
+ AddModuleMessage("Error Saving Site", MessageType.Error);
+ }
+ }
+}
diff --git a/Oqtane.Client/Modules/Admin/Sites/Add.razor b/Oqtane.Client/Modules/Admin/Sites/Add.razor
index 5c1532cb..40ac6f39 100644
--- a/Oqtane.Client/Modules/Admin/Sites/Add.razor
+++ b/Oqtane.Client/Modules/Admin/Sites/Add.razor
@@ -5,9 +5,11 @@
@inject IAliasService AliasService
@inject ISiteService SiteService
@inject IThemeService ThemeService
+@inject ISiteTemplateService SiteTemplateService
@inject IUserService UserService
+@inject IInstallationService InstallationService
-@if (tenants == null)
+@if (_tenants == null)
{
Loading...
}
@@ -16,50 +18,28 @@ else
- Tenant:
+ Site Name:
- TenantChanged(e))">
- <Select Tenant>
- @foreach (Tenant tenant in tenants)
- {
- @tenant.Name
- }
-
+
- Name:
+ Aliases:
-
+
- Aliases:
+ Default Theme:
-
-
-
-
-
- Logo:
-
-
-
-
-
-
-
- Default Theme:
-
-
- ThemeChanged(e))">
+ ThemeChanged(e))">
<Select Theme>
- @foreach (KeyValuePair item in themes)
+ @foreach (KeyValuePair item in _themes)
{
@item.Value
}
@@ -68,12 +48,12 @@ else
- Default Layout:
+ Default Layout:
-
+
<Select Layout>
- @foreach (KeyValuePair panelayout in panelayouts)
+ @foreach (KeyValuePair panelayout in _panelayouts)
{
@panelayout.Value
}
@@ -82,34 +62,133 @@ else
- Default Container:
+ Default Container:
-
+
<Select Container>
- @foreach (KeyValuePaircontainer in containers)
+ @foreach (KeyValuePair container in _containers)
{
@container.Value
}
- @if (!isinitialized)
+
+
+ Site Template:
+
+
+
+ <Select Site Template>
+ @foreach (SiteTemplate siteTemplate in _siteTemplates)
+ {
+ @siteTemplate.Name
+ }
+
+
+
+
+
+ Tenant:
+
+
+ TenantChanged(e))">
+ <Select Tenant>
+ <Create New Tenant>
+ @foreach (Tenant tenant in _tenants)
+ {
+ @tenant.Name
+ }
+
+
+
+ @if (_tenantid == "+")
{
-
- Host Username:
-
-
-
+
+
- Host Password:
+ Tenant Name:
-
+
+
+
+
+
+ Database Type:
+
+
+
+ Local Database
+ SQL Server
+
+
+
+
+
+ Server:
+
+
+
+
+
+
+
+ Database:
+
+
+
+
+
+
+
+ Integrated Security:
+
+
+
+ True
+ False
+
+
+
+ @if (!_integratedsecurity)
+ {
+
+
+ Database Username:
+
+
+
+
+
+
+
+ Database Password:
+
+
+
+
+
+ }
+
+
+ Host Username:
+
+
+
+
+
+
+
+ Host Password:
+
+
+
}
@@ -119,154 +198,206 @@ else
}
@code {
- public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } }
+ private Dictionary _themes = new Dictionary();
+ private Dictionary _panelayouts = new Dictionary();
+ private Dictionary _containers = new Dictionary();
+ private List _siteTemplates;
+ private List _themeList;
+ private List _tenants;
+ private string _tenantid = "-";
- Dictionary themes = new Dictionary();
- Dictionary panelayouts = new Dictionary();
- Dictionary containers = new Dictionary();
+ private string _tenantname = string.Empty;
+ private string _databasetype = "LocalDB";
+ private string _server = "(LocalDb)\\MSSQLLocalDB";
+ private string _database = "Oqtane-" + DateTime.UtcNow.ToString("yyyyMMddHHmm");
+ private string _username = string.Empty;
+ private string _password = string.Empty;
+ private bool _integratedsecurity = true;
+ private string _hostusername = Constants.HostUser;
+ private string _hostpassword = string.Empty;
- List tenants;
- string tenantid = "-1";
- string name = "";
- string urls = "";
- string logo = "";
- string themetype = "";
- string layouttype = "";
- string containertype = "";
- bool isinitialized = true;
- string username = "";
- string password = "";
+ private string _name = string.Empty;
+ private string _urls = string.Empty;
+ private string _themetype = string.Empty;
+ private string _layouttype = string.Empty;
+ private string _containertype = string.Empty;
+ private string _sitetemplatetype = string.Empty;
+
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host;
protected override async Task OnInitializedAsync()
{
- tenants = await TenantService.GetTenantsAsync();
- urls = PageState.Alias.Name;
- themes = ThemeService.GetThemeTypes(PageState.Themes);
- containers = ThemeService.GetContainerTypes(PageState.Themes);
- username = Constants.HostUser;
+ _themeList = await ThemeService.GetThemesAsync();
+ _tenants = await TenantService.GetTenantsAsync();
+ _urls = PageState.Alias.Name;
+ _themes = ThemeService.GetThemeTypes(_themeList);
+ _containers = ThemeService.GetContainerTypes(_themeList);
+ _siteTemplates = await SiteTemplateService.GetSiteTemplatesAsync();
}
- private async void TenantChanged(ChangeEventArgs e)
+ private void TenantChanged(ChangeEventArgs e)
{
- try
+ _tenantid = (string)e.Value;
+ if (string.IsNullOrEmpty(_tenantname))
{
- tenantid = (string)e.Value;
- if (tenantid != "-1")
- {
- Tenant tenant = tenants.Where(item => item.TenantId == int.Parse(tenantid)).FirstOrDefault();
- if (tenant != null)
- {
- isinitialized = tenant.IsInitialized;
- StateHasChanged();
- }
- }
+ _tenantname = _name;
}
- catch (Exception ex)
+ StateHasChanged();
+ }
+
+ private void SetIntegratedSecurity(ChangeEventArgs e)
+ {
+ if (Convert.ToBoolean((string)e.Value))
{
- await logger.LogError(ex, "Error Loading Tenant {TenantId} {Error}", tenantid, ex.Message);
- AddModuleMessage("Error Loading Tenant", MessageType.Error);
+ _integratedsecurity = true;
}
+ else
+ {
+ _integratedsecurity = false;
+ }
+ StateHasChanged();
}
private async void ThemeChanged(ChangeEventArgs e)
{
try
{
- themetype = (string)e.Value;
- if (themetype != "")
+ _themetype = (string)e.Value;
+ if (_themetype != string.Empty)
{
- panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes, themetype);
+ _panelayouts = ThemeService.GetPaneLayoutTypes(_themeList, _themetype);
}
else
{
- panelayouts = new Dictionary();
+ _panelayouts = new Dictionary();
}
+
StateHasChanged();
}
catch (Exception ex)
{
- await logger.LogError(ex, "Error Loading Pane Layouts For Theme {ThemeType} {Error}", themetype, ex.Message);
+ await logger.LogError(ex, "Error Loading Pane Layouts For Theme {ThemeType} {Error}", _themetype, ex.Message);
AddModuleMessage("Error Loading Pane Layouts For Theme", MessageType.Error);
}
}
private async Task SaveSite()
{
- if (tenantid != "-1" && name != "" && urls != "" && !string.IsNullOrEmpty(themetype) && (panelayouts.Count == 0 || !string.IsNullOrEmpty(layouttype)) && !string.IsNullOrEmpty(containertype))
+ if (_tenantid != "-" && _name != string.Empty && _urls != string.Empty && !string.IsNullOrEmpty(_themetype) && (_panelayouts.Count == 0 || !string.IsNullOrEmpty(_layouttype)) && !string.IsNullOrEmpty(_containertype) && !string.IsNullOrEmpty(_sitetemplatetype))
{
- bool isvalid = true;
-
- if (!isinitialized)
+ var duplicates = new List();
+ var aliases = await AliasService.GetAliasesAsync();
+ foreach (string name in _urls.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
- User user = new User();
- user.SiteId = PageState.Site.SiteId;
- user.Username = username;
- user.Password = password;
- user = await UserService.LoginUserAsync(user, false, false);
- isvalid = user.IsAuthenticated;
+ if (aliases.Exists(item => item.Name == name))
+ {
+ duplicates.Add(name);
+ }
}
- if (isvalid)
+ if (duplicates.Count == 0)
{
- List aliases = new List();
- urls = urls.Replace("\n", ",");
- foreach (string name in urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
+ InstallConfig config = new InstallConfig();
+
+ if (_tenantid == "+")
{
- Alias alias = new Alias();
- alias.Name = name;
- alias.TenantId = int.Parse(tenantid);
- alias.SiteId = -1;
- alias = await AliasService.AddAliasAsync(alias);
- aliases.Add(alias);
- }
-
- Site site = new Site();
- site.TenantId = int.Parse(tenantid);
- site.Name = name;
- site.Logo = (logo == null ? "" : logo);
- site.DefaultThemeType = themetype;
- site.DefaultLayoutType = (layouttype == null ? "" : layouttype);
- site.DefaultContainerType = containertype;
- site = await SiteService.AddSiteAsync(site, aliases[0]);
-
- foreach(Alias alias in aliases)
- {
- alias.SiteId = site.SiteId;
- await AliasService.UpdateAliasAsync(alias);
- }
-
- if (!isinitialized)
- {
- User user = new User();
- user.SiteId = site.SiteId;
- user.Username = username;
- user.Password = password;
- user.Email = PageState.User.Email;
- user.DisplayName = PageState.User.DisplayName;
- user = await UserService.AddUserAsync(user, aliases[0]);
-
- if (user != null)
+ if (!string.IsNullOrEmpty(_tenantname) && _tenants.FirstOrDefault(item => item.Name == _tenantname) == null)
{
- Tenant tenant = tenants.Where(item => item.TenantId == int.Parse(tenantid)).FirstOrDefault();
- tenant.IsInitialized = true;
- await TenantService.UpdateTenantAsync(tenant);
+ // validate host credentials
+ var user = new User();
+ user.SiteId = PageState.Site.SiteId;
+ user.Username = Constants.HostUser;
+ user.Password = _hostpassword;
+ user = await UserService.LoginUserAsync(user, false, false);
+ if (user.IsAuthenticated)
+ {
+ if (!string.IsNullOrEmpty(_server) && !string.IsNullOrEmpty(_database))
+ {
+ var connectionString = string.Empty;
+ if (_databasetype == "LocalDB")
+ {
+ connectionString = "Data Source=" + _server + ";AttachDbFilename=|DataDirectory|\\" + _database + ".mdf;Initial Catalog=" + _database + ";Integrated Security=SSPI;";
+ }
+ else
+ {
+ connectionString = "Data Source=" + _server + ";Initial Catalog=" + _database + ";";
+
+ if (_integratedsecurity)
+ {
+ connectionString += "Integrated Security=SSPI;";
+ }
+ else
+ {
+ connectionString += "User ID=" + _username + ";Password=" + _password;
+ }
+ }
+
+ config.ConnectionString = connectionString;
+ config.HostPassword = _hostpassword;
+ config.HostEmail = user.Email;
+ config.HostName = user.DisplayName;
+ config.TenantName = _tenantname;
+ config.IsNewTenant = true;
+ }
+ else
+ {
+ AddModuleMessage("You Must Specify A Server And Database", MessageType.Error);
+ }
+ }
+ else
+ {
+ AddModuleMessage("Invalid Host Password", MessageType.Error);
+ }
+ }
+ else
+ {
+ AddModuleMessage("Tenant Name Is Missing Or Already Exists", MessageType.Error);
+ }
+ }
+ else
+ {
+ var tenant = _tenants.FirstOrDefault(item => item.TenantId == int.Parse(_tenantid));
+ if (tenant != null)
+ {
+ config.TenantName = tenant.Name;
+ config.ConnectionString= tenant.DBConnectionString;
+ config.IsNewTenant = false;
}
}
- await logger.LogInformation("Site Created {Site}", site);
- Uri uri = new Uri(NavigationManager.Uri);
- NavigationManager.NavigateTo(uri.Scheme + "://" + aliases[0].Name, true);
+ if (!string.IsNullOrEmpty(config.TenantName))
+ {
+ config.SiteName = _name;
+ config.Aliases = _urls.Replace("\n", ",");
+ config.DefaultTheme = _themetype;
+ config.DefaultLayout = _layouttype;
+ config.DefaultContainer = _containertype;
+ config.SiteTemplate = _sitetemplatetype;
+
+ ShowProgressIndicator();
+
+ var installation = await InstallationService.Install(config);
+ if (installation.Success)
+ {
+ var aliasname = config.Aliases.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)[0];
+ var uri = new Uri(NavigationManager.Uri);
+ NavigationManager.NavigateTo(uri.Scheme + "://" + aliasname, true);
+ }
+ else
+ {
+ await logger.LogError("Error Creating Site {Error}", installation.Message);
+ AddModuleMessage(installation.Message, MessageType.Error);
+ }
+ }
}
else
{
- await logger.LogError("Invalid Password Entered For Host {Username}", username);
- AddModuleMessage("Invalid Host Password", MessageType.Error);
+ AddModuleMessage(string.Join(", ", duplicates.ToArray()) + " Already Used For Another Site", MessageType.Warning);
}
}
else
{
- AddModuleMessage("You Must Provide A Tenant, Site Name, Alias, And Default Theme/Container", MessageType.Warning);
+ AddModuleMessage("You Must Provide A Tenant, Site Name, Alias, Default Theme/Container, And Site Template", MessageType.Warning);
}
-
}
}
diff --git a/Oqtane.Client/Modules/Admin/Sites/Edit.razor b/Oqtane.Client/Modules/Admin/Sites/Edit.razor
index 42c0e108..698892a7 100644
--- a/Oqtane.Client/Modules/Admin/Sites/Edit.razor
+++ b/Oqtane.Client/Modules/Admin/Sites/Edit.razor
@@ -2,51 +2,47 @@
@inherits ModuleBase
@inject NavigationManager NavigationManager
@inject ISiteService SiteService
+@inject ITenantService TenantService
@inject IAliasService AliasService
@inject IThemeService ThemeService
-@inject ISettingService SettingService
-@if (themes == null)
-{
- Loading...
-}
-else
+@if (_themes != null)
{
-
-
- SMTP Settings
-
-
-
+
Save
Cancel
-
+
}
@code {
- public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } }
+ private Dictionary _themes;
+ private Dictionary _panelayouts;
+ private Dictionary _containers;
+ private Alias _alias;
+ private List _themeList;
+ private string _name = string.Empty;
+ private List _tenantList;
+ private string _tenant = string.Empty;
+ private List _aliasList;
+ private string _urls = string.Empty;
+ private string _themetype;
+ private string _layouttype;
+ private string _containertype;
+ private string _createdby;
+ private DateTime _createdon;
+ private string _modifiedby;
+ private DateTime _modifiedon;
+ private string _deletedby;
+ private DateTime? _deletedon;
+ private string _isdeleted;
- Dictionary themes = new Dictionary();
- Dictionary panelayouts = new Dictionary();
- Dictionary containers = new Dictionary();
-
- Alias Alias;
- int siteid;
- string name = "";
- List aliases;
- string urls = "";
- string logo = "";
- string themetype;
- string layouttype;
- string containertype;
-
- string smtphost = "";
- string smtpport = "";
- string smtpssl = "";
- string smtpusername = "";
- string smtppassword = "";
-
- string createdby;
- DateTime createdon;
- string modifiedby;
- DateTime modifiedon;
- string deletedby;
- DateTime? deletedon;
- string isdeleted;
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host;
protected override async Task OnInitializedAsync()
{
try
{
- themes = ThemeService.GetThemeTypes(PageState.Themes);
- containers = ThemeService.GetContainerTypes(PageState.Themes);
+ _themeList = await ThemeService.GetThemesAsync();
+ _aliasList = await AliasService.GetAliasesAsync();
- Alias = PageState.Aliases.Where(item => item.AliasId == Int32.Parse(PageState.QueryString["id"])).FirstOrDefault();
- siteid = Alias.SiteId;
- Site site = await SiteService.GetSiteAsync(siteid, Alias);
+ _alias = _aliasList.Find(item => item.AliasId == Int32.Parse(PageState.QueryString["id"]));
+ SiteService.SetAlias(_alias);
+ var site = await SiteService.GetSiteAsync(_alias.SiteId);
if (site != null)
{
- name = site.Name;
- aliases = PageState.Aliases.Where(item => item.SiteId == site.SiteId && item.TenantId == site.TenantId).ToList();
- foreach (Alias alias in aliases)
+ _name = site.Name;
+ _tenantList = await TenantService.GetTenantsAsync();
+ _tenant = _tenantList.Find(item => item.TenantId == site.TenantId).Name;
+
+ foreach (Alias alias in _aliasList.Where(item => item.SiteId == site.SiteId && item.TenantId == site.TenantId).ToList())
{
- urls += alias.Name + "\n";
+ _urls += alias.Name + "\n";
}
- logo = site.Logo;
- themetype = site.DefaultThemeType;
- panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes, themetype);
- layouttype = site.DefaultLayoutType;
- containertype = site.DefaultContainerType;
- Dictionary settings = await SettingService.GetSiteSettingsAsync(site.SiteId);
- smtphost = SettingService.GetSetting(settings, "SMTPHost", "");
- smtpport = SettingService.GetSetting(settings, "SMTPPort", "");
- smtpssl = SettingService.GetSetting(settings, "SMTPSSL", "");
- smtpusername = SettingService.GetSetting(settings, "SMTPUsername", "");
- smtppassword = SettingService.GetSetting(settings, "SMTPPassword", "");
-
- createdby = site.CreatedBy;
- createdon = site.CreatedOn;
- modifiedby = site.ModifiedBy;
- modifiedon = site.ModifiedOn;
- deletedby = site.DeletedBy;
- deletedon = site.DeletedOn;
- isdeleted = site.IsDeleted.ToString();
+ _themetype = site.DefaultThemeType;
+ _panelayouts = ThemeService.GetPaneLayoutTypes(_themeList, _themetype);
+ _layouttype = site.DefaultLayoutType;
+ _containertype = site.DefaultContainerType;
+ _createdby = site.CreatedBy;
+ _createdon = site.CreatedOn;
+ _modifiedby = site.ModifiedBy;
+ _modifiedon = site.ModifiedOn;
+ _deletedby = site.DeletedBy;
+ _deletedon = site.DeletedOn;
+ _isdeleted = site.IsDeleted.ToString();
}
+
+ _themes = ThemeService.GetThemeTypes(_themeList);
+ _containers = ThemeService.GetContainerTypes(_themeList);
}
catch (Exception ex)
{
- await logger.LogError(ex, "Error Loading Site {SiteId} {Error}", siteid, ex.Message);
+ await Log(_alias, LogLevel.Error, string.Empty, ex, "Error Loading Site {SiteId} {Error}", _alias.SiteId, ex.Message);
AddModuleMessage(ex.Message, MessageType.Error);
}
}
@@ -236,20 +174,21 @@ else
{
try
{
- themetype = (string)e.Value;
- if (themetype != "")
+ _themetype = (string)e.Value;
+ if (_themetype != string.Empty)
{
- panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes, themetype);
+ _panelayouts = ThemeService.GetPaneLayoutTypes(_themeList, _themetype);
}
else
{
- panelayouts = new Dictionary();
+ _panelayouts = new Dictionary();
}
+
StateHasChanged();
}
catch (Exception ex)
{
- await logger.LogError(ex, "Error Loading Pane Layouts For Theme {ThemeType} {Error}", themetype, ex.Message);
+ await logger.LogError(ex, "Error Loading Pane Layouts For Theme {ThemeType} {Error}", _themetype, ex.Message);
AddModuleMessage("Error Loading Pane Layouts For Theme", MessageType.Error);
}
}
@@ -258,52 +197,65 @@ else
{
try
{
- if (name != "" && urls != "" && !string.IsNullOrEmpty(themetype) && (panelayouts.Count == 0 || !string.IsNullOrEmpty(layouttype)) && !string.IsNullOrEmpty(containertype))
+ if (_name != string.Empty && _urls != string.Empty && !string.IsNullOrEmpty(_themetype) && (_panelayouts.Count == 0 || !string.IsNullOrEmpty(_layouttype)) && !string.IsNullOrEmpty(_containertype))
{
- Site site = await SiteService.GetSiteAsync(siteid, Alias);
- if (site != null)
+ var unique = true;
+ foreach (string name in _urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
- site.Name = name;
- site.Logo = (logo == null ? "" : logo);
- site.DefaultThemeType = themetype;
- site.DefaultLayoutType = (layouttype == null ? "" : layouttype);
- site.DefaultContainerType = containertype;
- site.IsDeleted = (isdeleted == null ? true : Boolean.Parse(isdeleted));
-
- site = await SiteService.UpdateSiteAsync(site, Alias);
-
- urls = urls.Replace("\n", ",");
- string[] names = urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- foreach (Alias alias in aliases)
+ if (_aliasList.Exists(item => item.Name == name && item.SiteId != _alias.SiteId && item.TenantId != _alias.TenantId))
{
- if (!names.Contains(alias.Name))
- {
- await AliasService.DeleteAliasAsync(alias.AliasId);
- }
+ unique = false;
}
- foreach (string name in names)
+ }
+
+ if (unique)
+ {
+ SiteService.SetAlias(_alias);
+ var site = await SiteService.GetSiteAsync(_alias.SiteId);
+ if (site != null)
{
- if (!aliases.Exists(item => item.Name == name))
+ site.Name = _name;
+ site.LogoFileId = null;
+ site.DefaultThemeType = _themetype;
+ site.DefaultLayoutType = _layouttype ?? string.Empty;
+ site.DefaultContainerType = _containertype;
+ site.IsDeleted = (_isdeleted == null || Boolean.Parse(_isdeleted));
+
+ site = await SiteService.UpdateSiteAsync(site);
+
+ _urls = _urls.Replace("\n", ",");
+ var names = _urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
+
+ foreach (Alias alias in _aliasList.Where(item => item.SiteId == site.SiteId && item.TenantId == site.TenantId).ToList())
{
- Alias alias = new Alias();
- alias.Name = name;
- alias.TenantId = site.TenantId;
- alias.SiteId = site.SiteId;
- await AliasService.AddAliasAsync(alias);
+ if (!names.Contains(alias.Name))
+ {
+ await AliasService.DeleteAliasAsync(alias.AliasId);
+ }
}
+
+ foreach (string name in names)
+ {
+ if (!_aliasList.Exists(item => item.Name == name))
+ {
+ Alias alias = new Alias
+ {
+ Name = name,
+ TenantId = site.TenantId,
+ SiteId = site.SiteId
+ };
+ await AliasService.AddAliasAsync(alias);
+ }
+ }
+
+ await Log(_alias, LogLevel.Information,PermissionNames.Edit, null, "Site Saved {Site}", site);
+
+ NavigationManager.NavigateTo(NavigateUrl());
}
-
- Dictionary settings = await SettingService.GetSiteSettingsAsync(site.SiteId);
- SettingService.SetSetting(settings, "SMTPHost", smtphost);
- SettingService.SetSetting(settings, "SMTPPort", smtpport);
- SettingService.SetSetting(settings, "SMTPSSL", smtpssl);
- SettingService.SetSetting(settings, "SMTPUsername", smtpusername);
- SettingService.SetSetting(settings, "SMTPPassword", smtppassword);
- await SettingService.UpdateModuleSettingsAsync(settings, site.SiteId);
-
- await logger.LogInformation("Site Saved {Site}", site);
-
- NavigationManager.NavigateTo(NavigateUrl(Reload.Site));
+ }
+ else
+ {
+ AddModuleMessage("An Alias Specified Has Already Been Used For Another Site", MessageType.Warning);
}
}
else
@@ -313,8 +265,8 @@ else
}
catch (Exception ex)
{
- await logger.LogError(ex, "Error Saving Site {SiteId} {Error}", siteid, ex.Message);
+ await Log(_alias, LogLevel.Error, string.Empty, ex, "Error Saving Site {SiteId} {Error}", _alias.SiteId, ex.Message);
AddModuleMessage("Error Saving Site", MessageType.Error);
}
}
-}
+ }
diff --git a/Oqtane.Client/Modules/Admin/Sites/Index.razor b/Oqtane.Client/Modules/Admin/Sites/Index.razor
index 46152dee..d8b79632 100644
--- a/Oqtane.Client/Modules/Admin/Sites/Index.razor
+++ b/Oqtane.Client/Modules/Admin/Sites/Index.razor
@@ -4,7 +4,7 @@
@inject IAliasService AliasService
@inject ISiteService SiteService
-@if (sites == null)
+@if (_sites == null)
{
Loading...
}
@@ -12,7 +12,7 @@ else
{
-
+
-
- @context.Name
+
+ @context.Name
}
@code {
- public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } }
+ private List _sites;
+ private string _scheme;
- List sites;
- string scheme;
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host;
- protected override void OnParametersSet()
+ protected override async Task OnParametersSetAsync()
{
- Uri uri = new Uri(NavigationManager.Uri);
- scheme = uri.Scheme + "://";
+ var uri = new Uri(NavigationManager.Uri);
+ _scheme = uri.Scheme + "://";
- sites = new List();
- foreach (Alias alias in PageState.Aliases.OrderBy(item => item.Name))
+ var aliases = await AliasService.GetAliasesAsync();
+ _sites = new List();
+ foreach (Alias alias in aliases)
{
- if (!sites.Exists(item => item.TenantId == alias.TenantId && item.SiteId == alias.SiteId))
+ if (!_sites.Exists(item => item.TenantId == alias.TenantId && item.SiteId == alias.SiteId))
{
- sites.Add(alias);
+ _sites.Add(alias);
}
}
}
- private async Task DeleteSite(Alias Alias)
+ private async Task DeleteSite(Alias alias)
{
try
{
- await SiteService.DeleteSiteAsync(Alias.SiteId, Alias);
- await logger.LogInformation("Sited Deleted {Alias}", Alias);
- StateHasChanged();
+ if (alias.SiteId != PageState.Site.SiteId || alias.TenantId != PageState.Site.TenantId)
+ {
+ SiteService.SetAlias(alias);
+ await SiteService.DeleteSiteAsync(alias.SiteId);
+ await Log(alias, LogLevel.Information, "", null, "Site Deleted {SiteId}", alias.SiteId);
+
+ var aliases = await AliasService.GetAliasesAsync();
+ foreach (Alias a in aliases.Where(item => item.SiteId == alias.SiteId && item.TenantId == alias.TenantId))
+ {
+ await AliasService.DeleteAliasAsync(a.AliasId);
+ }
+
+ NavigationManager.NavigateTo(NavigateUrl());
+ }
+ else
+ {
+ AddModuleMessage("You Can Not Delete The Current Site", MessageType.Warning);
+ }
}
catch (Exception ex)
{
- await logger.LogError(ex, "Error Deleting Site {Error}", ex.Message);
+ await Log(alias, LogLevel.Error, "", ex, "Error Deleting Site {SiteId} {Error}", alias.SiteId, ex.Message);
AddModuleMessage("Error Deleting Site", MessageType.Error);
}
}
-}
\ No newline at end of file
+}
diff --git a/Oqtane.Client/Modules/Admin/Sql/Index.razor b/Oqtane.Client/Modules/Admin/Sql/Index.razor
new file mode 100644
index 00000000..e27350f8
--- /dev/null
+++ b/Oqtane.Client/Modules/Admin/Sql/Index.razor
@@ -0,0 +1,111 @@
+@namespace Oqtane.Modules.Admin.Sql
+@inherits ModuleBase
+@inject NavigationManager NavigationManager
+@inject ITenantService TenantService
+@inject ISqlService SqlService
+
+@if (_tenants == null)
+{
+ Loading...
+}
+else
+{
+
+
+
+ Tenant:
+
+
+
+ <Select Tenant>
+ @foreach (Tenant tenant in _tenants)
+ {
+ @tenant.Name
+ }
+
+
+
+
+
+ SQL Query:
+
+
+
+
+
+
+ Execute
+
+ @if (!string.IsNullOrEmpty(_results))
+ {
+ @((MarkupString)_results)
+ }
+}
+
+@code {
+ private List _tenants;
+ private string _tenantid = "-1";
+ private string _sql = string.Empty;
+ private string _results = string.Empty;
+
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host;
+
+ protected override async Task OnInitializedAsync()
+ {
+ _tenants = await TenantService.GetTenantsAsync();
+ }
+
+ private async Task Execute()
+ {
+ if (_tenantid != "-1" && !string.IsNullOrEmpty(_sql))
+ {
+ var sqlquery = new SqlQuery { TenantId = int.Parse(_tenantid), Query = _sql };
+ sqlquery = await SqlService.ExecuteQueryAsync(sqlquery);
+ _results = DisplayResults(sqlquery.Results);
+ }
+ else
+ {
+ AddModuleMessage("You Must Select A Tenant And Provide A SQL Query", MessageType.Warning);
+ }
+ }
+
+ private string DisplayResults(List> results)
+ {
+ var table = string.Empty;
+ foreach (Dictionary item in results)
+ {
+ if (table == string.Empty)
+ {
+ table = "";
+ table += "
";
+
+ foreach (KeyValuePair kvp in item)
+ {
+ table += "" + kvp.Key + " ";
+ }
+
+ table += " ";
+ }
+
+ table += "";
+
+ foreach (KeyValuePair kvp in item)
+ {
+ table += "" + kvp.Value + " ";
+ }
+
+ table += " ";
+ }
+
+ if (table != string.Empty)
+ {
+ table += "
";
+ }
+ else
+ {
+ table = "No Results Returned";
+ }
+
+ return table;
+ }
+}
diff --git a/Oqtane.Client/Modules/Admin/SystemInfo/Index.razor b/Oqtane.Client/Modules/Admin/SystemInfo/Index.razor
new file mode 100644
index 00000000..ca7c7f2c
--- /dev/null
+++ b/Oqtane.Client/Modules/Admin/SystemInfo/Index.razor
@@ -0,0 +1,81 @@
+@namespace Oqtane.Modules.Admin.SystemInfo
+@inherits ModuleBase
+@inject ISystemService SystemService
+
+
+Access Framework API
+
+@code {
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host;
+
+ private string _version = string.Empty;
+ private string _runtime = string.Empty;
+ private string _clrversion = string.Empty;
+ private string _osversion = string.Empty;
+ private string _serverpath = string.Empty;
+ private string _servertime = string.Empty;
+
+ protected override async Task OnInitializedAsync()
+ {
+ _version = Constants.Version;
+ _runtime = PageState.Runtime.ToString();
+
+ Dictionary systeminfo = await SystemService.GetSystemInfoAsync();
+ if (systeminfo != null)
+ {
+ _clrversion = systeminfo["clrversion"];
+ _osversion = systeminfo["osversion"];
+ _serverpath = systeminfo["serverpath"];
+ _servertime = systeminfo["servertime"];
+ }
+ }
+}
diff --git a/Oqtane.Client/Modules/Admin/Tenants/Add.razor b/Oqtane.Client/Modules/Admin/Tenants/Add.razor
deleted file mode 100644
index e12a27a3..00000000
--- a/Oqtane.Client/Modules/Admin/Tenants/Add.razor
+++ /dev/null
@@ -1,82 +0,0 @@
-@namespace Oqtane.Modules.Admin.Tenants
-@inherits ModuleBase
-@inject NavigationManager NavigationManager
-@inject ITenantService TenantService
-@inject IInstallationService InstallationService
-
-
-Save
-Cancel
-
-@code {
- public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } }
-
- string name = "";
- string connectionstring = "";
- string schema = "";
-
- protected override async Task OnInitializedAsync()
- {
- try
- {
- List tenants = await TenantService.GetTenantsAsync();
- connectionstring = tenants.FirstOrDefault().DBConnectionString;
- schema = tenants.FirstOrDefault().DBSchema;
- }
- catch (Exception ex)
- {
- await logger.LogError(ex, "Error Loading Tenants {Error}", ex.Message);
- AddModuleMessage("Error Loading Tenants", MessageType.Error);
- }
- }
-
- private async Task SaveTenant()
- {
- ShowProgressIndicator();
-
- connectionstring = connectionstring.Replace("\\\\", "\\");
- GenericResponse response = await InstallationService.Install(connectionstring);
- if (response.Success)
- {
- Tenant tenant = new Tenant();
- tenant.Name = name;
- tenant.DBConnectionString = connectionstring;
- tenant.DBSchema = schema;
- tenant.IsInitialized = false;
- await TenantService.AddTenantAsync(tenant);
- await logger.LogInformation("Tenant Created {Tenant}", tenant);
-
- NavigationManager.NavigateTo(NavigateUrl());
- }
- else
- {
- await logger.LogError("Error Creating Tenant {Error}", response.Message);
- AddModuleMessage(response.Message, MessageType.Error);
- }
- }
-}
diff --git a/Oqtane.Client/Modules/Admin/Tenants/Edit.razor b/Oqtane.Client/Modules/Admin/Tenants/Edit.razor
index ca0b8c9c..94ee91d6 100644
--- a/Oqtane.Client/Modules/Admin/Tenants/Edit.razor
+++ b/Oqtane.Client/Modules/Admin/Tenants/Edit.razor
@@ -6,51 +6,50 @@
Save
Cancel
@code {
- public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } }
+ private int tenantid;
+ private string name = string.Empty;
+ private string connectionstring = string.Empty;
+ private string schema = string.Empty;
- int tenantid;
- string name = "";
- string connectionstring = "";
- string schema = "";
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host;
protected override async Task OnInitializedAsync()
{
try
{
tenantid = Int32.Parse(PageState.QueryString["id"]);
- Tenant tenant = await TenantService.GetTenantAsync(tenantid);
+ var tenant = await TenantService.GetTenantAsync(tenantid);
if (tenant != null)
{
name = tenant.Name;
connectionstring = tenant.DBConnectionString;
- schema = tenant.DBSchema;
}
}
catch (Exception ex)
@@ -65,12 +64,12 @@
try
{
connectionstring = connectionstring.Replace("\\\\", "\\");
- Tenant tenant = await TenantService.GetTenantAsync(tenantid);
+ var tenant = await TenantService.GetTenantAsync(tenantid);
if (tenant != null)
{
tenant.Name = name;
tenant.DBConnectionString = connectionstring;
- tenant.DBSchema = schema;
+
await TenantService.UpdateTenantAsync(tenant);
await logger.LogInformation("Tenant Saved {TenantId}", tenantid);
diff --git a/Oqtane.Client/Modules/Admin/Tenants/Index.razor b/Oqtane.Client/Modules/Admin/Tenants/Index.razor
index 5c22fcbf..ead272dc 100644
--- a/Oqtane.Client/Modules/Admin/Tenants/Index.razor
+++ b/Oqtane.Client/Modules/Admin/Tenants/Index.razor
@@ -1,6 +1,7 @@
@namespace Oqtane.Modules.Admin.Tenants
@inherits ModuleBase
@inject ITenantService TenantService
+@inject IAliasService AliasService
@if (tenants == null)
{
@@ -8,8 +9,6 @@
}
else
{
-
-
-
+
@context.Name
@@ -26,9 +25,9 @@ else
}
@code {
- public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } }
+ private List tenants;
- List tenants;
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host;
protected override async Task OnParametersSetAsync()
{
@@ -39,9 +38,25 @@ else
{
try
{
- await TenantService.DeleteTenantAsync(Tenant.TenantId);
- await logger.LogInformation("Tenant Deleted {Tenant}", Tenant);
- StateHasChanged();
+ string message = string.Empty;
+ var aliases = await AliasService.GetAliasesAsync();
+ foreach (var alias in aliases)
+ {
+ if (alias.TenantId == Tenant.TenantId)
+ {
+ message += ", " + alias.Name;
+ }
+ }
+ if (string.IsNullOrEmpty(message))
+ {
+ await TenantService.DeleteTenantAsync(Tenant.TenantId);
+ await logger.LogInformation("Tenant Deleted {Tenant}", Tenant);
+ StateHasChanged();
+ }
+ else
+ {
+ AddModuleMessage("Tenant Cannot Be Deleted Until The Following Sites Are Deleted: " + message.Substring(2), MessageType.Warning);
+ }
}
catch (Exception ex)
{
diff --git a/Oqtane.Client/Modules/Admin/Themes/Add.razor b/Oqtane.Client/Modules/Admin/Themes/Add.razor
index bd243c9e..da47d8a9 100644
--- a/Oqtane.Client/Modules/Admin/Themes/Add.razor
+++ b/Oqtane.Client/Modules/Admin/Themes/Add.razor
@@ -5,117 +5,100 @@
@inject IThemeService ThemeService
@inject IPackageService PackageService
-
-Upload Theme
-
-@if (packages != null)
+@if (_packages != null)
{
-
-
Available Themes
+
+ @if (_packages.Count > 0)
+ {
+
+
+
+
+
+ @context.Name
+ @context.Version
+
+ await DownloadTheme(context.PackageId, context.Version))>Download
+
+
+
+
+ }
+
+
+
+
-
-
-
- @context.Name
- @context.Version
-
- await DownloadTheme(context.PackageId, context.Version))>Download Theme
-
-
-
-}
-
-@if (uploaded)
-{
- Install
-}
+Install
Cancel
+}
@code {
- public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } }
+ private List _packages;
- bool uploaded = false;
- List packages;
- FileUpload fileupload;
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host;
protected override async Task OnInitializedAsync()
{
- List themes = await ThemeService.GetThemesAsync();
- packages = await PackageService.GetPackagesAsync("theme");
- foreach(Package package in packages.ToArray())
+ try
{
- if (themes.Exists(item => Utilities.GetTypeName(item.ThemeName) == package.PackageId))
- {
- packages.Remove(package);
- }
- }
- }
+ var themes = await ThemeService.GetThemesAsync();
+ _packages = await PackageService.GetPackagesAsync("theme");
- private async Task UploadTheme()
- {
- string[] files = await fileupload.GetFiles();
- if (files.Length > 0)
- {
- if (files[0].Contains(".Theme."))
+ foreach (Package package in _packages.ToArray())
{
- try
+ if (themes.Exists(item => Utilities.GetTypeName(item.ThemeName) == package.PackageId))
{
- string result = await FileService.UploadFilesAsync("Themes", files, "");
- if (result == "")
- {
- await logger.LogInformation("Theme Uploaded {Package}", files[0]);
- AddModuleMessage("Theme Uploaded Successfully. Click Install To Complete Installation.", MessageType.Success);
- uploaded = true;
- StateHasChanged();
- }
- else
- {
- await logger.LogInformation("Theme Upload Failed For {Package}", result.Replace(",",", "));
- AddModuleMessage("Upload Failed For " + result.Replace(",",", ") + ". This Could Be Due To A Network Error Or Because A File Type Is Restricted.", MessageType.Error);
- }
+ _packages.Remove(package);
}
- catch (Exception ex)
- {
- await logger.LogError(ex, "Theme Upload Failed {Package} {Error}", files[0], ex.Message);
- AddModuleMessage("Theme Upload Failed", MessageType.Error);
- }
- }
- else
- {
- await logger.LogError("Invalid Theme Package {Package}", files[0]);
- AddModuleMessage("Invalid Theme Package", MessageType.Error);
}
}
- else
+ catch (Exception ex)
{
- AddModuleMessage("You Must Select A Theme To Upload", MessageType.Warning);
+ await logger.LogError(ex, "Error Loading Packages {Error}", ex.Message);
+ AddModuleMessage("Error Loading Packages", MessageType.Error);
}
}
private async Task InstallThemes()
{
- await ThemeService.InstallThemesAsync();
- NavigationManager.NavigateTo(NavigateUrl(Reload.Application));
+ try
+ {
+ await ThemeService.InstallThemesAsync();
+ NavigationManager.NavigateTo(NavigateUrl());
+ }
+ catch (Exception ex)
+ {
+ await logger.LogError(ex, "Error Installating Theme");
+ }
}
private async Task DownloadTheme(string packageid, string version)
{
- await PackageService.DownloadPackageAsync(packageid, version, "Themes");
- AddModuleMessage("Theme Downloaded Successfully. Click Install To Complete Installation.", MessageType.Success);
- uploaded = true;
- StateHasChanged();
+ try
+ {
+ await PackageService.DownloadPackageAsync(packageid, version, "Themes");
+ await logger.LogInformation("Theme {ThemeName} {Version} Downloaded Successfully", packageid, version);
+ AddModuleMessage("Themes Downloaded Successfully. Click Install To Complete Installation.", MessageType.Success);
+ StateHasChanged();
+ }
+ catch (Exception ex)
+ {
+ await logger.LogError(ex, "Error Downloading Module {ThemeName} {Version}", packageid, version);
+ AddModuleMessage("Error Downloading Theme", MessageType.Error);
+ }
+ }
}
-}
diff --git a/Oqtane.Client/Modules/Admin/Themes/Index.razor b/Oqtane.Client/Modules/Admin/Themes/Index.razor
index 501dec1b..4a3113b6 100644
--- a/Oqtane.Client/Modules/Admin/Themes/Index.razor
+++ b/Oqtane.Client/Modules/Admin/Themes/Index.razor
@@ -39,10 +39,10 @@ else
}
@code {
- public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } }
+ private List themes;
+ private List packages;
- List themes;
- List packages;
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host;
protected override async Task OnInitializedAsync()
{
@@ -52,12 +52,13 @@ else
private bool UpgradeAvailable(string themename, string version)
{
- bool upgradeavailable = false;
- Package package = packages.Where(item => item.PackageId == Utilities.GetTypeName(themename)).FirstOrDefault();
+ var upgradeavailable = false;
+ var package = packages.Where(item => item.PackageId == Utilities.GetTypeName(themename)).FirstOrDefault();
if (package != null)
{
upgradeavailable = (Version.Parse(package.Version).CompareTo(Version.Parse(version)) > 0);
}
+
return upgradeavailable;
}
@@ -66,13 +67,13 @@ else
await PackageService.DownloadPackageAsync(themename, version, "Themes");
await logger.LogInformation("Theme Downloaded {ThemeName} {Version}", themename, version);
await ThemeService.InstallThemesAsync();
- NavigationManager.NavigateTo(NavigateUrl(Reload.Application));
+ NavigationManager.NavigateTo(NavigateUrl());
}
private async Task DeleteTheme(Theme Theme)
{
await ThemeService.DeleteThemeAsync(Theme.ThemeName);
await logger.LogInformation("Theme Deleted {Theme}", Theme);
- NavigationManager.NavigateTo(NavigateUrl(Reload.Application));
+ NavigationManager.NavigateTo(NavigateUrl());
}
}
\ No newline at end of file
diff --git a/Oqtane.Client/Modules/Admin/Upgrade/Index.razor b/Oqtane.Client/Modules/Admin/Upgrade/Index.razor
index 2ae44820..7ee95e30 100644
--- a/Oqtane.Client/Modules/Admin/Upgrade/Index.razor
+++ b/Oqtane.Client/Modules/Admin/Upgrade/Index.razor
@@ -5,105 +5,66 @@
@inject IPackageService PackageService
@inject IInstallationService InstallationService
-
-
-
- Framework:
-
-
-
-
-
-
-@if (uploaded)
+@if (_package != null)
{
- Upgrade
-}
-else
-{
- Upload
-}
-
-@if (upgradeavailable)
-{
-
-
Upgrade Available
-
- await Download(Constants.PackageId, Constants.Version))>Upgrade Framework
+
+
+ @if (_upgradeavailable)
+ {
+
+ @("Framework") @_package.Version await Download(Constants.PackageId, Constants.Version))>Upgrade
+ }
+ else
+ {
+
+ }
+
+
+
+
+
+ Framework:
+
+
+
+
+
+
+ Install
+
+
}
@code {
- public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } }
+ private Package _package;
+ private bool _upgradeavailable = false;
- bool uploaded = false;
- bool upgradeavailable = false;
- FileUpload fileupload;
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host;
protected override async Task OnInitializedAsync()
{
List packages = await PackageService.GetPackagesAsync("framework");
- Package package = packages.FirstOrDefault();
- if (package != null)
+ _package = packages.FirstOrDefault();
+ if (_package != null)
{
- upgradeavailable = (Version.Parse(package.Version).CompareTo(Version.Parse(Constants.Version)) > 0);
- }
- if (!upgradeavailable)
- {
- AddModuleMessage("Framework Is Up To Date", MessageType.Info);
- }
- }
-
- private async Task UploadFile()
- {
- string[] files = await fileupload.GetFiles();
- if (files.Length > 0)
- {
- if (files[0].Contains(".Framework."))
- {
- try
- {
- string result = await FileService.UploadFilesAsync("Framework", files, "");
- if (result == "")
- {
- await logger.LogInformation("Framework Uploaded {Package}", files[0]);
- AddModuleMessage("Framework Uploaded Successfully. Click Upgrade To Complete Installation.", MessageType.Success);
- uploaded = true;
- StateHasChanged();
- }
- else
- {
- await logger.LogInformation("Framework Upload Failed For {Package}", result.Replace(",",", "));
- AddModuleMessage("Upload Failed For " + result.Replace(",",", ") + ". This Could Be Due To A Network Error Or Because A File Type Is Restricted.", MessageType.Error);
- }
- }
- catch (Exception ex)
- {
- await logger.LogError(ex, "Framework Upload Failed {Package} {Error}", files[0], ex.Message);
- AddModuleMessage("Framework Upload Failed. " + ex.Message, MessageType.Error);
- }
- }
- else
- {
- await logger.LogError("Invalid Framework Package {Package}", files[0]);
- AddModuleMessage("Invalid Framework Package", MessageType.Error);
- }
+ _upgradeavailable = (Version.Parse(_package.Version).CompareTo(Version.Parse(Constants.Version)) > 0);
}
else
{
- AddModuleMessage("You Must Select A Framework Package To Upload", MessageType.Warning);
+ _package = new Package { Name = Constants.PackageId, Version = Constants.Version };
}
}
private async Task Upgrade()
{
await InstallationService.Upgrade();
- NavigationManager.NavigateTo(NavigateUrl(Reload.Application));
+ NavigationManager.NavigateTo(NavigateUrl());
}
private async Task Download(string packageid, string version)
{
await PackageService.DownloadPackageAsync(packageid, version, "Framework");
await InstallationService.Upgrade();
- NavigationManager.NavigateTo(NavigateUrl(Reload.Application));
+ NavigationManager.NavigateTo(NavigateUrl());
}
-}
\ No newline at end of file
+}
diff --git a/Oqtane.Client/Modules/Admin/UserProfile/Add.razor b/Oqtane.Client/Modules/Admin/UserProfile/Add.razor
index a5c3656f..e6ae6b68 100644
--- a/Oqtane.Client/Modules/Admin/UserProfile/Add.razor
+++ b/Oqtane.Client/Modules/Admin/UserProfile/Add.razor
@@ -9,10 +9,10 @@
@@ -46,13 +46,14 @@
}
@code {
- public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.View; } }
- public override string Title { get { return "Send Notification"; } }
+ private List userroles;
+ private string userid = "-1";
+ private string subject = "";
+ private string body = "";
- List userroles;
- string userid = "-1";
- string subject = "";
- string body = "";
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.View;
+
+ public override string Title => "Send Notification";
protected override async Task OnInitializedAsync()
{
@@ -71,7 +72,7 @@
private async Task Send()
{
- Notification notification = new Notification();
+ var notification = new Notification();
try
{
notification.SiteId = PageState.Site.SiteId;
@@ -81,7 +82,7 @@
notification.Subject = subject;
notification.Body = body;
notification.ParentId = null;
- notification.CreatedOn = DateTime.Now;
+ notification.CreatedOn = DateTime.UtcNow;
notification.IsDelivered = false;
notification.DeliveredOn = null;
diff --git a/Oqtane.Client/Modules/Admin/UserProfile/Index.razor b/Oqtane.Client/Modules/Admin/UserProfile/Index.razor
index b5d76c3c..fec53f62 100644
--- a/Oqtane.Client/Modules/Admin/UserProfile/Index.razor
+++ b/Oqtane.Client/Modules/Admin/UserProfile/Index.razor
@@ -6,169 +6,177 @@
@inject ISettingService SettingService
@inject INotificationService NotificationService
-@if (PageState.User != null && profiles != null)
+@if (PageState.User != null && photofileid != -1)
{
-
+
}
+else
+{
+
+}
+
+
+ @if (PageState.User != null)
+ {
+
+ Save
+ Cancel
+ }
+
+
+ @if (profiles != null)
+ {
+
+ Save
+ Cancel
+ }
+
+
+ @if (notifications != null)
+ {
+
+
+ @if (filter == "to")
+ {
+
+
+
+
+ From
+ Subject
+ Received
+
+
+
+
+ @(context.FromUser == null ? "System" : context.FromUser.DisplayName)
+ @context.Subject
+ @context.CreatedOn
+
+
+
+ @(context.Body.Length > 100 ? context.Body.Substring(0, 100) : context.Body)
+
+
+ }
+ else
+ {
+
+
+
+
+ To
+ Subject
+ Sent
+
+
+
+
+ @(context.ToUser == null ? context.ToEmail : context.ToUser.DisplayName)
+ @context.Subject
+ @context.CreatedOn
+
+
+
+ @(context.Body.Length > 100 ? context.Body.Substring(0, 100) : context.Body)
+
+
+ }
+
+ FilterChanged(e))">
+ Inbox
+ Sent Items
+
+ }
+
+
@code {
- public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.View; } }
+ private string username = string.Empty;
+ private string password = string.Empty;
+ private string confirm = string.Empty;
+ private string email = string.Empty;
+ private string displayname = string.Empty;
+ private FileManager filemanager;
+ private int photofileid = -1;
+ private List profiles;
+ private Dictionary settings;
+ private string category = string.Empty;
+ private string filter = "to";
+ private List notifications;
- string username = "";
- string password = "";
- string confirm = "";
- string email = "";
- string displayname = "";
- List profiles;
- Dictionary settings;
- string category = "";
- string filter = "to";
- List notifications;
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.View;
protected override async Task OnInitializedAsync()
{
@@ -179,8 +187,15 @@
username = PageState.User.Username;
email = PageState.User.Email;
displayname = PageState.User.DisplayName;
+
+ if (PageState.User.PhotoFileId != null)
+ {
+ photofileid = PageState.User.PhotoFileId.Value;
+ }
+
profiles = await ProfileService.GetProfilesAsync(ModuleState.SiteId);
settings = await SettingService.GetUserSettingsAsync(PageState.User.UserId);
+
await LoadNotificationsAsync();
}
else
@@ -202,28 +217,32 @@
}
private string GetProfileValue(string SettingName, string DefaultValue)
- {
- return SettingService.GetSetting(settings, SettingName, DefaultValue);
- }
+ => SettingService.GetSetting(settings, SettingName, DefaultValue);
private async Task Save()
{
try
{
- if (password != "" && confirm != "" && email != "")
+ if (username != string.Empty && email != string.Empty)
{
if (password == confirm)
{
- User user = PageState.User;
+ var user = PageState.User;
user.Username = username;
user.Password = password;
user.Email = email;
- user.DisplayName = (displayname == "" ? username : displayname);
+ user.DisplayName = (displayname == string.Empty ? username : displayname);
+ user.PhotoFileId = null;
+ photofileid = filemanager.GetFileId();
+
+ if (photofileid != -1)
+ {
+ user.PhotoFileId = photofileid;
+ }
+
await UserService.UpdateUserAsync(user);
await SettingService.UpdateUserSettingsAsync(settings, PageState.User.UserId);
await logger.LogInformation("User Profile Saved");
-
- NavigationManager.NavigateTo(NavigateUrl(""));
}
else
{
@@ -232,7 +251,7 @@
}
else
{
- AddModuleMessage("You Must Provide A Username, Password, and Email Address", MessageType.Warning);
+ AddModuleMessage("You Must Provide A Username and Email Address", MessageType.Warning);
}
}
catch (Exception ex)
@@ -244,12 +263,12 @@
private void Cancel()
{
- NavigationManager.NavigateTo(NavigateUrl(""));
+ NavigationManager.NavigateTo(NavigateUrl(string.Empty));
}
private void ProfileChanged(ChangeEventArgs e, string SettingName)
{
- string value = (string)e.Value;
+ var value = (string)e.Value;
settings = SettingService.SetSetting(settings, SettingName, value);
}
@@ -266,6 +285,7 @@
{
await NotificationService.DeleteNotificationAsync(Notification.NotificationId);
}
+
await logger.LogInformation("Notification Deleted {Notification}", Notification);
await LoadNotificationsAsync();
StateHasChanged();
@@ -280,6 +300,7 @@
private async void FilterChanged(ChangeEventArgs e)
{
filter = (string)e.Value;
+
await LoadNotificationsAsync();
StateHasChanged();
}
diff --git a/Oqtane.Client/Modules/Admin/UserProfile/View.razor b/Oqtane.Client/Modules/Admin/UserProfile/View.razor
index 076e55e8..07140f63 100644
--- a/Oqtane.Client/Modules/Admin/UserProfile/View.razor
+++ b/Oqtane.Client/Modules/Admin/UserProfile/View.razor
@@ -9,7 +9,7 @@
- @if (reply != "")
+ @if (reply != string.Empty)
{
Send
}
@@ -70,17 +70,17 @@
}
@code {
- public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.View; } }
- public override string Title { get { return "View Notification"; } }
+ private int notificationid;
+ private string title = string.Empty;
+ private List userroles;
+ private string userid = "-1";
+ private string subject = string.Empty;
+ private string createdon = string.Empty;
+ private string body = string.Empty;
+ private string reply = string.Empty;
- int notificationid;
- string title = "";
- List userroles;
- string userid = "-1";
- string subject = "";
- string createdon = "";
- string body = "";
- string reply = "";
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.View;
+ public override string Title => "View Notification";
protected override async Task OnInitializedAsync()
{
@@ -110,6 +110,7 @@
userid = notification.ToUserId.ToString();
}
}
+
subject = notification.Subject;
createdon = notification.CreatedOn.ToString();
body = notification.Body;
@@ -132,15 +133,15 @@
private async Task Send()
{
- Notification notification = new Notification();
+ var notification = new Notification();
notification.SiteId = PageState.Site.SiteId;
notification.FromUserId = PageState.User.UserId;
notification.ToUserId = int.Parse(userid);
- notification.ToEmail = "";
+ notification.ToEmail = string.Empty;
notification.Subject = subject;
notification.Body = body;
notification.ParentId = notificationid;
- notification.CreatedOn = DateTime.Now;
+ notification.CreatedOn = DateTime.UtcNow;
notification.IsDelivered = false;
notification.DeliveredOn = null;
diff --git a/Oqtane.Client/Modules/Admin/Users/Add.razor b/Oqtane.Client/Modules/Admin/Users/Add.razor
index a687cad4..b6aa116a 100644
--- a/Oqtane.Client/Modules/Admin/Users/Add.razor
+++ b/Oqtane.Client/Modules/Admin/Users/Add.razor
@@ -5,87 +5,98 @@
@inject IProfileService ProfileService
@inject ISettingService SettingService
-@if (profiles != null)
-{
-
- Save
- Cancel
-}
+
+
+ @if (profiles != null)
+ {
+
+ }
+
+
+
+Save
+Cancel
@code {
- public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
+ private string username = string.Empty;
+ private string password = string.Empty;
+ private string confirm = string.Empty;
+ private string email = string.Empty;
+ private string displayname = string.Empty;
+ private List profiles;
+ private Dictionary settings;
+ private string category = string.Empty;
- string username = "";
- string password = "";
- string confirm = "";
- string email = "";
- string displayname = "";
- List profiles;
- Dictionary settings;
- string category = "";
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin;
protected override async Task OnInitializedAsync()
{
@@ -105,16 +116,17 @@
{
try
{
- if (username != "" && password != "" && confirm != "" && email != "")
+ if (username != string.Empty && password != string.Empty && confirm != string.Empty && email != string.Empty)
{
if (password == confirm)
{
- User user = new User();
+ var user = new User();
user.SiteId = PageState.Site.SiteId;
user.Username = username;
user.Password = password;
user.Email = email;
user.DisplayName = string.IsNullOrWhiteSpace(displayname) ? username : displayname;
+ user.PhotoFileId = null;
user = await UserService.AddUserAsync(user);
@@ -149,7 +161,7 @@
private void ProfileChanged(ChangeEventArgs e, string SettingName)
{
- string value = (string)e.Value;
+ var value = (string)e.Value;
settings = SettingService.SetSetting(settings, SettingName, value);
}
diff --git a/Oqtane.Client/Modules/Admin/Users/Edit.razor b/Oqtane.Client/Modules/Admin/Users/Edit.razor
index c3a005de..95449f2d 100644
--- a/Oqtane.Client/Modules/Admin/Users/Edit.razor
+++ b/Oqtane.Client/Modules/Admin/Users/Edit.razor
@@ -5,109 +5,137 @@
@inject IProfileService ProfileService
@inject ISettingService SettingService
-@if (profiles != null)
+@if (PageState.User != null && photofileid != -1)
{
-
- Save
- Cancel
-
-
-
+
}
+else
+{
+
+}
+
+
+ @if (profiles != null)
+ {
+
+ }
+
+
+ @if (profiles != null)
+ {
+
+ }
+
+
+
+Save
+Cancel
+
+
@code {
- public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
+ private int userid;
+ private string username = string.Empty;
+ private string password = string.Empty;
+ private string confirm = string.Empty;
+ private string email = string.Empty;
+ private string displayname = string.Empty;
+ private FileManager filemanager;
+ private int photofileid = -1;
+ private List profiles;
+ private Dictionary settings;
+ private string category = string.Empty;
+ private string createdby;
+ private DateTime createdon;
+ private string modifiedby;
+ private DateTime modifiedon;
+ private string deletedby;
+ private DateTime? deletedon;
+ private string isdeleted;
- int userid;
- string username = "";
- string password = "";
- string confirm = "";
- string email = "";
- string displayname = "";
- List profiles;
- Dictionary settings;
- string category = "";
- string createdby;
- DateTime createdon;
- string modifiedby;
- DateTime modifiedon;
- string deletedby;
- DateTime? deletedon;
- string isdeleted;
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin;
protected override async Task OnInitializedAsync()
{
@@ -116,12 +144,18 @@
profiles = await ProfileService.GetProfilesAsync(PageState.Site.SiteId);
userid = Int32.Parse(PageState.QueryString["id"]);
- User user = await UserService.GetUserAsync(userid, PageState.Site.SiteId);
+ var user = await UserService.GetUserAsync(userid, PageState.Site.SiteId);
if (user != null)
{
username = user.Username;
email = user.Email;
displayname = user.DisplayName;
+
+ if (user.PhotoFileId != null)
+ {
+ photofileid = user.PhotoFileId.Value;
+ }
+
settings = await SettingService.GetUserSettingsAsync(user.UserId);
createdby = user.CreatedBy;
createdon = user.CreatedOn;
@@ -140,24 +174,30 @@
}
private string GetProfileValue(string SettingName, string DefaultValue)
- {
- return SettingService.GetSetting(settings, SettingName, DefaultValue);
- }
+ => SettingService.GetSetting(settings, SettingName, DefaultValue);
private async Task SaveUser()
{
try
{
- if (username != "" && password != "" && confirm != "" && email != "")
+ if (username != string.Empty && email != string.Empty)
{
if (password == confirm)
{
- User user = await UserService.GetUserAsync(userid, PageState.Site.SiteId);
+ var user = await UserService.GetUserAsync(userid, PageState.Site.SiteId);
user.SiteId = PageState.Site.SiteId;
user.Username = username;
user.Password = password;
user.Email = email;
user.DisplayName = string.IsNullOrWhiteSpace(displayname) ? username : displayname;
+ user.PhotoFileId = null;
+ photofileid = filemanager.GetFileId();
+
+ if (photofileid != -1)
+ {
+ user.PhotoFileId = photofileid;
+ }
+
user.IsDeleted = (isdeleted == null ? true : Boolean.Parse(isdeleted));
user = await UserService.UpdateUserAsync(user);
@@ -185,7 +225,7 @@
private void ProfileChanged(ChangeEventArgs e, string SettingName)
{
- string value = (string)e.Value;
+ var value = (string)e.Value;
settings = SettingService.SetSetting(settings, SettingName, value);
}
diff --git a/Oqtane.Client/Modules/Admin/Users/Index.razor b/Oqtane.Client/Modules/Admin/Users/Index.razor
index c6e52c6e..a9d4366f 100644
--- a/Oqtane.Client/Modules/Admin/Users/Index.razor
+++ b/Oqtane.Client/Modules/Admin/Users/Index.razor
@@ -28,9 +28,9 @@ else
}
@code {
- public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
+ private List userroles;
- List userroles;
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin;
protected override async Task OnInitializedAsync()
{
@@ -42,7 +42,7 @@ else
{
try
{
- User user = await UserService.GetUserAsync(UserRole.UserId, PageState.Site.SiteId);
+ var user = await UserService.GetUserAsync(UserRole.UserId, PageState.Site.SiteId);
if (user != null)
{
await UserService.DeleteUserAsync(user.UserId);
diff --git a/Oqtane.Client/Modules/Admin/Users/Roles.razor b/Oqtane.Client/Modules/Admin/Users/Roles.razor
index 94179f86..a4e946df 100644
--- a/Oqtane.Client/Modules/Admin/Users/Roles.razor
+++ b/Oqtane.Client/Modules/Admin/Users/Roles.razor
@@ -1,6 +1,7 @@
@namespace Oqtane.Modules.Admin.Users
@inherits ModuleBase
@inject IRoleService RoleService
+@inject IUserService UserService
@inject IUserRoleService UserRoleService
@if (userroles == null)
@@ -12,10 +13,18 @@ else
@@ -48,16 +57,16 @@ else
@context.Role.Name
- @if (!context.Role.IsSystem)
- {
+ @if (context.Role.Name != Constants.RegisteredRole)
+ {
await DeleteUserRole(context.UserRoleId))>Delete
- }
+ }
@@ -65,20 +74,23 @@ else
}
@code {
- public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
+ private int userid;
+ private string name = string.Empty;
+ private List roles;
+ private int roleid = -1;
+ private string effectivedate = string.Empty;
+ private string expirydate = string.Empty;
+ private List userroles;
- int userid;
- List roles;
- int roleid = -1;
- string effectivedate = "";
- string expirydate = "";
- List userroles;
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin;
protected override async Task OnInitializedAsync()
{
try
{
userid = Int32.Parse(PageState.QueryString["id"]);
+ User user = await UserService.GetUserAsync(userid, PageState.Site.SiteId);
+ name = user.DisplayName;
roles = await RoleService.GetRolesAsync(PageState.Site.SiteId);
await GetUserRoles();
}
@@ -109,7 +121,7 @@ else
{
if (roleid != -1)
{
- UserRole userrole = userroles.Where(item => item.UserId == userid && item.RoleId == roleid).FirstOrDefault();
+ var userrole = userroles.Where(item => item.UserId == userid && item.RoleId == roleid).FirstOrDefault();
if (userrole != null)
{
if (string.IsNullOrEmpty(effectivedate))
@@ -120,6 +132,7 @@ else
{
userrole.EffectiveDate = DateTime.Parse(effectivedate);
}
+
if (string.IsNullOrEmpty(expirydate))
{
userrole.ExpiryDate = null;
@@ -135,6 +148,7 @@ else
userrole = new UserRole();
userrole.UserId = userid;
userrole.RoleId = roleid;
+
if (string.IsNullOrEmpty(effectivedate))
{
userrole.EffectiveDate = null;
@@ -143,6 +157,7 @@ else
{
userrole.EffectiveDate = DateTime.Parse(effectivedate);
}
+
if (string.IsNullOrEmpty(expirydate))
{
userrole.ExpiryDate = null;
@@ -151,8 +166,10 @@ else
{
userrole.ExpiryDate = DateTime.Parse(expirydate);
}
+
await UserRoleService.AddUserRoleAsync(userrole);
}
+
await GetUserRoles();
await logger.LogInformation("User Assigned To Role {UserRole}", userrole);
AddModuleMessage("User Assigned To Role", MessageType.Success);
@@ -184,4 +201,4 @@ else
AddModuleMessage("Error Removing User From Role", MessageType.Error);
}
}
-}
\ No newline at end of file
+}
diff --git a/Oqtane.Client/Modules/Controls/ActionDialog.razor b/Oqtane.Client/Modules/Controls/ActionDialog.razor
index 3a8a94ce..076f1e9d 100644
--- a/Oqtane.Client/Modules/Controls/ActionDialog.razor
+++ b/Oqtane.Client/Modules/Controls/ActionDialog.razor
@@ -1,7 +1,7 @@
@namespace Oqtane.Modules.Controls
@inherits ModuleBase
-
-@if (visible)
+@attribute [OqtaneIgnore]
+@if (_visible)
{
@@ -17,7 +17,7 @@
@@ -26,23 +26,35 @@
}
-@if (authorized)
+@if (_authorized)
{
- @Text
+ if (Disabled)
+ {
+ @((MarkupString)_iconSpan) @Text
+ }
+ else
+ {
+ @((MarkupString)_iconSpan) @Text
+ }
}
@code {
+ private bool _visible = false;
+ private bool _editmode = true;
+ private bool _authorized = false;
+ private string _iconSpan = string.Empty;
+
[Parameter]
public string Header { get; set; } // required
[Parameter]
- public string Message { get; set; } // required
+ public string Message { get; set; } // required
[Parameter]
public string Text { get; set; } // optional - defaults to Action if not specified
[Parameter]
- public string Action { get; set; } // optional
+ public string Action { get; set; } // optional
[Parameter]
public SecurityAccessLevel? Security { get; set; } // optional - can be used to explicitly specify SecurityAccessLevel
@@ -50,15 +62,17 @@
[Parameter]
public string Class { get; set; } // optional
+ [Parameter]
+ public bool Disabled { get; set; } // optional
+
[Parameter]
public string EditMode { get; set; } // optional - specifies if a user must be in edit mode to see the action - default is true
[Parameter]
public Action OnClick { get; set; } // required if an Action is specified - executes a method in the calling component
- bool visible = false;
- bool editmode = true;
- bool authorized = false;
+ [Parameter]
+ public string IconName { get; set; } // optional - specifies an icon for the link - default is no icon
protected override void OnParametersSet()
{
@@ -72,15 +86,21 @@
}
if (!string.IsNullOrEmpty(EditMode))
{
- editmode = bool.Parse(EditMode);
+ _editmode = bool.Parse(EditMode);
}
- authorized = IsAuthorized();
+
+ if (!string.IsNullOrEmpty(IconName))
+ {
+ _iconSpan = $" ";
+ }
+
+ _authorized = IsAuthorized();
}
private bool IsAuthorized()
{
bool authorized = false;
- if (PageState.EditMode || !editmode)
+ if (PageState.EditMode || !_editmode)
{
SecurityAccessLevel security = SecurityAccessLevel.Host;
if (Security == null)
@@ -89,8 +109,8 @@
Type moduleType = Type.GetType(typename);
if (moduleType != null)
{
- var moduleobject = Activator.CreateInstance(moduleType);
- security = (SecurityAccessLevel)moduleType.GetProperty("SecurityAccessLevel").GetValue(moduleobject, null);
+ var moduleobject = Activator.CreateInstance(moduleType) as IModuleControl;
+ security = moduleobject.SecurityAccessLevel;
}
else
{
@@ -107,10 +127,10 @@
authorized = true;
break;
case SecurityAccessLevel.View:
- authorized = UserSecurity.IsAuthorized(PageState.User, "View", ModuleState.Permissions);
+ authorized = UserSecurity.IsAuthorized(PageState.User,PermissionNames.View, ModuleState.Permissions);
break;
case SecurityAccessLevel.Edit:
- authorized = UserSecurity.IsAuthorized(PageState.User, "Edit", ModuleState.Permissions);
+ authorized = UserSecurity.IsAuthorized(PageState.User,PermissionNames.Edit, ModuleState.Permissions);
break;
case SecurityAccessLevel.Admin:
authorized = UserSecurity.IsAuthorized(PageState.User, Constants.AdminRole);
@@ -125,7 +145,7 @@
private void DisplayModal()
{
- visible = !visible;
+ _visible = !_visible;
StateHasChanged();
}
diff --git a/Oqtane.Client/Modules/Controls/ActionLink.razor b/Oqtane.Client/Modules/Controls/ActionLink.razor
index d3c3a08b..d8ed32a6 100644
--- a/Oqtane.Client/Modules/Controls/ActionLink.razor
+++ b/Oqtane.Client/Modules/Controls/ActionLink.razor
@@ -1,13 +1,30 @@
@namespace Oqtane.Modules.Controls
-@inherits ModuleBase
+@inherits ModuleBase
+@attribute [OqtaneIgnore]
@inject IUserService UserService
-@if (authorized)
+@if (_authorized)
{
- @text
+ if (Disabled)
+ {
+ @((MarkupString)_iconSpan) @_text
+ }
+ else
+ {
+ @((MarkupString)_iconSpan) @_text
+ }
}
@code {
+ private string _text = string.Empty;
+ private string _url = string.Empty;
+ private string _parameters = string.Empty;
+ private string _classname = "btn btn-primary";
+ private string _style = string.Empty;
+ private bool _editmode = true;
+ private bool _authorized = false;
+ private string _iconSpan = string.Empty;
+
[Parameter]
public string Action { get; set; } // required
@@ -26,63 +43,66 @@
[Parameter]
public string Style { get; set; } // optional
+ [Parameter]
+ public bool Disabled { get; set; } // optional
+
[Parameter]
public string EditMode { get; set; } // optional - specifies if a user must be in edit mode to see the action - default is true
- string text = "";
- string url = "";
- string parameters = "";
- string classname = "btn btn-primary";
- string style = "";
- bool editmode = true;
- bool authorized = false;
+ [Parameter]
+ public string IconName { get; set; } // optional - specifies an icon for the link - default is no icon
protected override void OnParametersSet()
{
- text = Action;
+ _text = Action;
if (!string.IsNullOrEmpty(Text))
{
- text = Text;
+ _text = Text;
}
if (!string.IsNullOrEmpty(Parameters))
{
- parameters = Parameters;
+ _parameters = Parameters;
}
if (!string.IsNullOrEmpty(Class))
{
- classname = Class;
+ _classname = Class;
}
if (!string.IsNullOrEmpty(Style))
{
- style = Style;
+ _style = Style;
}
if (!string.IsNullOrEmpty(EditMode))
{
- editmode = bool.Parse(EditMode);
+ _editmode = bool.Parse(EditMode);
}
- url = EditUrl(Action, parameters);
- authorized = IsAuthorized();
+ if (!string.IsNullOrEmpty(IconName))
+ {
+ _iconSpan = $" ";
+ }
+
+ _url = EditUrl(Action, _parameters);
+ _authorized = IsAuthorized();
}
private bool IsAuthorized()
{
- bool authorized = false;
- if (PageState.EditMode || !editmode)
+ var authorized = false;
+ if (PageState.EditMode || !_editmode)
{
- SecurityAccessLevel security = SecurityAccessLevel.Host;
+ var security = SecurityAccessLevel.Host;
if (Security == null)
{
- string typename = ModuleState.ModuleType.Replace(Utilities.GetTypeNameLastSegment(ModuleState.ModuleType, 0) + ",", Action + ",");
- Type moduleType = Type.GetType(typename);
+ var typename = ModuleState.ModuleType.Replace(Utilities.GetTypeNameLastSegment(ModuleState.ModuleType, 0) + ",", Action + ",");
+ var moduleType = Type.GetType(typename);
if (moduleType != null)
{
- var moduleobject = Activator.CreateInstance(moduleType);
- security = (SecurityAccessLevel)moduleType.GetProperty("SecurityAccessLevel").GetValue(moduleobject, null);
+ var moduleobject = Activator.CreateInstance(moduleType) as IModuleControl;
+ security = moduleobject.SecurityAccessLevel;
}
else
{
@@ -94,16 +114,17 @@
{
security = Security.Value;
}
+
switch (security)
{
case SecurityAccessLevel.Anonymous:
authorized = true;
break;
case SecurityAccessLevel.View:
- authorized = UserSecurity.IsAuthorized(PageState.User, "View", ModuleState.Permissions);
+ authorized = UserSecurity.IsAuthorized(PageState.User, PermissionNames.View, ModuleState.Permissions);
break;
case SecurityAccessLevel.Edit:
- authorized = UserSecurity.IsAuthorized(PageState.User, "Edit", ModuleState.Permissions);
+ authorized = UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, ModuleState.Permissions);
break;
case SecurityAccessLevel.Admin:
authorized = UserSecurity.IsAuthorized(PageState.User, Constants.AdminRole);
@@ -113,6 +134,7 @@
break;
}
}
+
return authorized;
}
}
diff --git a/Oqtane.Client/Modules/Controls/AuditInfo.razor b/Oqtane.Client/Modules/Controls/AuditInfo.razor
index 40938da3..7c081d3f 100644
--- a/Oqtane.Client/Modules/Controls/AuditInfo.razor
+++ b/Oqtane.Client/Modules/Controls/AuditInfo.razor
@@ -1,12 +1,16 @@
@namespace Oqtane.Modules.Controls
-@inherits ModuleBase
+@inherits ModuleBase
+@attribute [OqtaneIgnore]
-@if (text != "")
+@if (_text != string.Empty)
{
- @((MarkupString)@text)
+ @((MarkupString)_text)
}
@code {
+
+ private string _text = string.Empty;
+
[Parameter]
public string CreatedBy { get; set; }
@@ -31,51 +35,58 @@
[Parameter]
public string Style { get; set; }
- string text = "";
-
protected override void OnParametersSet()
{
- text = "";
+ _text = string.Empty;
if (!String.IsNullOrEmpty(CreatedBy) || CreatedOn != null)
{
- text += "Created ";
+ _text += "
Created ";
+
if (!String.IsNullOrEmpty(CreatedBy))
{
- text += " by " + CreatedBy + " ";
+ _text += " by " + CreatedBy + " ";
}
+
if (CreatedOn != null)
{
- text += " on " + CreatedOn.ToString("MMM dd yyyy HH:mm:ss") + " ";
+ _text += " on " + CreatedOn.ToString("MMM dd yyyy HH:mm:ss") + " ";
}
- text += "
";
+
+ _text += "
";
}
if (!String.IsNullOrEmpty(ModifiedBy) || ModifiedOn != null)
{
- text += "Last modified ";
+ _text += "
Last modified ";
+
if (!String.IsNullOrEmpty(ModifiedBy))
{
- text += " by " + ModifiedBy + " ";
+ _text += " by " + ModifiedBy + " ";
}
+
if (ModifiedOn != null)
{
- text += " on " + ModifiedOn.ToString("MMM dd yyyy HH:mm:ss") + " ";
+ _text += " on " + ModifiedOn.ToString("MMM dd yyyy HH:mm:ss") + " ";
}
- text += "
";
+
+ _text += "";
}
if (!String.IsNullOrEmpty(DeletedBy) || DeletedOn.HasValue)
{
- text += "Deleted ";
+ _text += "
Deleted ";
+
if (!String.IsNullOrEmpty(DeletedBy))
{
- text += " by " + DeletedBy + " ";
+ _text += " by " + DeletedBy + " ";
}
+
if (DeletedOn != null)
{
- text += " on " + DeletedOn.Value.ToString("MMM dd yyyy HH:mm:ss") + " ";
+ _text += " on " + DeletedOn.Value.ToString("MMM dd yyyy HH:mm:ss") + " ";
}
- text += "
";
+
+ _text += "";
}
}
}
diff --git a/Oqtane.Client/Modules/Controls/FileManager.razor b/Oqtane.Client/Modules/Controls/FileManager.razor
new file mode 100644
index 00000000..96196b06
--- /dev/null
+++ b/Oqtane.Client/Modules/Controls/FileManager.razor
@@ -0,0 +1,335 @@
+@namespace Oqtane.Modules.Controls
+@inherits ModuleBase
+
+@attribute [OqtaneIgnore]
+@inject IFolderService FolderService
+@inject IFileService FileService
+@inject IJSRuntime JsRuntime
+
+@if (_folders != null)
+{
+
+
+
+ @if (ShowFolders || FolderId <= 0)
+ {
+
+ FolderChanged(e))">
+ @if (string.IsNullOrEmpty(Folder))
+ {
+ <Select Folder>
+ }
+ @foreach (Folder folder in _folders)
+ {
+ if (folder.FolderId == FolderId)
+ {
+ @(new string('-', folder.Level * 2))@(folder.Name)
+ }
+ else
+ {
+ @(new string('-', folder.Level * 2))@(folder.Name)
+ }
+ }
+
+
+ }
+ @if (ShowFiles)
+ {
+
+ FileChanged(e))">
+ <Select File>
+ @foreach (File file in _files)
+ {
+ if (file.FileId == FileId)
+ {
+ @(file.Name)
+ }
+ else
+ {
+ @(file.Name)
+ }
+ }
+
+
+ }
+ @if (ShowUpload && _haseditpermission)
+ {
+
+ }
+ @((MarkupString) _message)
+
+ @if (_image != string.Empty)
+ {
+
+ @((MarkupString) _image)
+
+ }
+
+
+}
+
+@code {
+ private string _id;
+ private List _folders;
+ private List _files = new List();
+ private bool _showfiles = true;
+ private string _fileinputid = string.Empty;
+ private string _progressinfoid = string.Empty;
+ private string _progressbarid = string.Empty;
+ private string _filter = "*";
+ private bool _haseditpermission = false;
+ private string _message = string.Empty;
+ private string _image = string.Empty;
+ private string _guid;
+
+ [Parameter]
+ public string Id { get; set; } // optional - for setting the id of the FileManager component for accessibility
+
+ [Parameter]
+ public string Folder { get; set; } // optional - for setting a specific folder by default
+
+ [Parameter]
+ public int FolderId { get; set; } = -1; // optional - for setting a specific folderid by default
+
+ [Parameter]
+ public bool ShowFiles { get; set; } = true; // optional - for indicating whether a list of files should be displayed - default is true
+
+ [Parameter]
+ public bool ShowUpload { get; set; } = true; // optional - for indicating whether a Upload controls should be displayed - default is true
+
+ [Parameter]
+ public bool ShowFolders { get; set; } = true; // optional - for indicating whether a list of folders should be displayed - default is true
+
+ [Parameter]
+ public int FileId { get; set; } = -1; // optional - for setting a specific file by default
+
+ [Parameter]
+ public string Filter { get; set; } // optional - comma delimited list of file types that can be selected or uploaded ie. "jpg,gif"
+
+ [Parameter]
+ public bool UploadMultiple { get; set; } = false; // optional - enable multiple file uploads - default false
+
+ protected override async Task OnInitializedAsync()
+ {
+ if (!string.IsNullOrEmpty(Id))
+ {
+ _id = Id;
+ }
+
+ if (!string.IsNullOrEmpty(Folder))
+ {
+ _folders = new List {new Folder {FolderId = -1, Name = Folder}};
+ FolderId = -1;
+ }
+ else
+ {
+ _folders = await FolderService.GetFoldersAsync(ModuleState.SiteId);
+ }
+
+ if (FileId != -1)
+ {
+ File file = await FileService.GetFileAsync(FileId);
+ if (file != null)
+ {
+ FolderId = file.FolderId;
+ }
+ else
+ {
+ FileId = -1; // file does not exist
+ }
+ }
+ await SetImage();
+
+ if (!string.IsNullOrEmpty(Filter))
+ {
+ _filter = "." + Filter.Replace(",", ",.");
+ }
+
+ await GetFiles();
+
+ // create unique id for component
+ _guid = Guid.NewGuid().ToString("N");
+ _fileinputid = _guid + "FileInput";
+ _progressinfoid = _guid + "ProgressInfo";
+ _progressbarid = _guid + "ProgressBar";
+ }
+
+ private async Task GetFiles()
+ {
+ _haseditpermission = false;
+ if (!string.IsNullOrEmpty(Folder))
+ {
+ _haseditpermission = UserSecurity.IsAuthorized(PageState.User, Constants.HostRole);
+ _files = await FileService.GetFilesAsync(Folder);
+ }
+ else
+ {
+ Folder folder = _folders.FirstOrDefault(item => item.FolderId == FolderId);
+ if (folder != null)
+ {
+ _haseditpermission = UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, folder.Permissions);
+ _files = await FileService.GetFilesAsync(FolderId);
+ }
+ else
+ {
+ _haseditpermission = false;
+ _files = new List();
+ }
+ }
+ if (_filter != "*")
+ {
+ List filtered = new List();
+ foreach (File file in _files)
+ {
+ if (_filter.ToUpper().IndexOf("." + file.Extension.ToUpper()) != -1)
+ {
+ filtered.Add(file);
+ }
+ }
+ _files = filtered;
+ }
+ }
+
+ private async Task FolderChanged(ChangeEventArgs e)
+ {
+ _message = string.Empty;
+ try
+ {
+ FolderId = int.Parse((string) e.Value);
+ await GetFiles();
+ FileId = -1;
+ _image = string.Empty;
+ StateHasChanged();
+ }
+ catch (Exception ex)
+ {
+ await logger.LogError(ex, "Error Loading Files {Error}", ex.Message);
+ _message = "Error Loading Files
";
+ }
+ }
+
+ private async Task FileChanged(ChangeEventArgs e)
+ {
+ _message = string.Empty;
+ FileId = int.Parse((string) e.Value);
+
+ await SetImage();
+ StateHasChanged();
+ }
+
+ private async Task SetImage()
+ {
+ _image = string.Empty;
+ if (FileId != -1)
+ {
+ File file = await FileService.GetFileAsync(FileId);
+ if (file != null && file.ImageHeight != 0 && file.ImageWidth != 0)
+ {
+ var maxwidth = 200;
+ var maxheight = 200;
+
+ var ratioX = (double) maxwidth / (double) file.ImageWidth;
+ var ratioY = (double) maxheight / (double) file.ImageHeight;
+ var ratio = ratioX < ratioY ? ratioX : ratioY;
+
+ _image = " ";
+ }
+ }
+ }
+
+ private async Task UploadFile()
+ {
+ var interop = new Interop(JsRuntime);
+ var upload = await interop.GetFiles(_fileinputid);
+ if (upload.Length > 0)
+ {
+ try
+ {
+ string result;
+ if (!string.IsNullOrEmpty(Folder))
+ {
+ result = await FileService.UploadFilesAsync(Folder, upload, _guid);
+ }
+ else
+ {
+ result = await FileService.UploadFilesAsync(FolderId, upload, _guid);
+ }
+
+ if (result == string.Empty)
+ {
+ await logger.LogInformation("File Upload Succeeded {Files}", upload);
+ _message = "File Upload Succeeded
";
+ await GetFiles();
+
+ if (upload.Length == 1)
+ {
+ var file = _files.Where(item => item.Name == upload[0]).FirstOrDefault();
+ if (file != null)
+ {
+ FileId = file.FileId;
+ await SetImage();
+ }
+ }
+ StateHasChanged();
+ }
+ else
+ {
+ await logger.LogError("File Upload Failed For {Files}", result.Replace(",", ", "));
+ _message = "File Upload Failed
";
+ }
+ }
+ catch (Exception ex)
+ {
+ await logger.LogError(ex, "File Upload Failed {Error}", ex.Message);
+ _message = "File Upload Failed
";
+ }
+ }
+ else
+ {
+ _message = "You Have Not Selected A File To Upload
";
+ }
+ }
+
+ private async Task DeleteFile()
+ {
+ _message = string.Empty;
+
+ try
+ {
+ await FileService.DeleteFileAsync(FileId);
+ await logger.LogInformation("File Deleted {File}", FileId);
+ _message = "File Deleted
";
+ await GetFiles();
+ FileId = -1;
+ await SetImage();
+ StateHasChanged();
+ }
+ catch (Exception ex)
+ {
+ await logger.LogError(ex, "Error Deleting File {File} {Error}", FileId, ex.Message);
+ _message = "Error Deleting File
";
+ }
+ }
+
+ public int GetFileId() => FileId;
+
+}
diff --git a/Oqtane.Client/Modules/Controls/FileUpload.razor b/Oqtane.Client/Modules/Controls/FileUpload.razor
deleted file mode 100644
index 43f0228a..00000000
--- a/Oqtane.Client/Modules/Controls/FileUpload.razor
+++ /dev/null
@@ -1,54 +0,0 @@
-@namespace Oqtane.Modules.Controls
-@inject IJSRuntime jsRuntime
-
-@if (multiple)
-{
-
-}
-else
-{
-
-}
-
-
-@code {
- [Parameter]
- public string Name { get; set; } // optional - can be used for managing multiple file upload controls on a page
-
- [Parameter]
- public string Filter { get; set; } // optional - for restricting types of files that can be selected
-
- [Parameter]
- public string Multiple { get; set; } // optional - enable multiple file uploads
-
- string fileid = "";
- string progressinfoid = "";
- string progressbarid = "";
- string filter = "*";
- string files = "";
- bool multiple = false;
-
- protected override void OnInitialized()
- {
- fileid = Name + "FileInput";
- progressinfoid = Name + "ProgressInfo";
- progressbarid = Name + "ProgressBar";
-
- if (!string.IsNullOrEmpty(Filter))
- {
- filter = Filter;
- }
-
- if (!string.IsNullOrEmpty(Multiple))
- {
- multiple = bool.Parse(Multiple);
- }
- }
-
- public async Task GetFiles()
- {
- var interop = new Interop(jsRuntime);
- string[] files = await interop.GetFiles(fileid);
- return files;
- }
-}
diff --git a/Oqtane.Client/Modules/Controls/Label.razor b/Oqtane.Client/Modules/Controls/Label.razor
new file mode 100644
index 00000000..e57d01ec
--- /dev/null
+++ b/Oqtane.Client/Modules/Controls/Label.razor
@@ -0,0 +1,45 @@
+@namespace Oqtane.Modules.Controls
+@inherits ModuleBase
+@attribute [OqtaneIgnore]
+
+@if (!string.IsNullOrEmpty(HelpText))
+{
+ @((MarkupString)_openLabel)@ChildContent@((MarkupString)_closeLabel)
+}
+else
+{
+ @((MarkupString)_openLabel)@ChildContent@((MarkupString)_closeLabel)
+}
+
+@code {
+ private string _openLabel = string.Empty;
+ private string _closeLabel = "";
+
+ [Parameter]
+ public RenderFragment ChildContent { get; set; }
+
+ [Parameter]
+ public string For { get; set; } // optional - the id of the associated input control for accessibility
+
+ [Parameter]
+ public string Class { get; set; } // optional - the class for the label ( ie. control-label )
+
+ [Parameter]
+ public string HelpText { get; set; } // optional - tooltip for this label
+
+ protected override void OnParametersSet()
+ {
+ _openLabel = "";
+ }
+}
diff --git a/Oqtane.Client/Modules/Controls/ModuleMessage.razor b/Oqtane.Client/Modules/Controls/ModuleMessage.razor
index a756e9dd..5e00cb76 100644
--- a/Oqtane.Client/Modules/Controls/ModuleMessage.razor
+++ b/Oqtane.Client/Modules/Controls/ModuleMessage.razor
@@ -1,38 +1,42 @@
@namespace Oqtane.Modules.Controls
-@inherits ModuleBase
+@inherits ModuleBase
+@attribute [OqtaneIgnore]
-@if (!string.IsNullOrEmpty(message))
+@if (!string.IsNullOrEmpty(_message))
{
- @message
+ @_message
}
@code {
+ private string _message = string.Empty;
+ private string _classname = "alert alert-danger";
+
[Parameter]
public string Message { get; set; }
[Parameter]
public MessageType Type { get; set; }
- string message = "";
- string classname = "alert alert-danger";
-
protected override void OnParametersSet()
{
- message = Message;
- classname = GetMessageType(Type);
+ if (!string.IsNullOrEmpty(Message))
+ {
+ _message = Message;
+ _classname = GetMessageType(Type);
+ }
}
public void SetModuleMessage(string message, MessageType type)
{
- this.message = message;
- classname = GetMessageType(type);
+ _message = message;
+ _classname = GetMessageType(type);
StateHasChanged();
}
private string GetMessageType(MessageType type)
{
- string classname = "";
+ var classname = string.Empty;
switch (type)
{
case MessageType.Success:
@@ -48,6 +52,7 @@
classname = "alert alert-danger";
break;
}
+
return classname;
}
}
diff --git a/Oqtane.Client/Modules/Controls/Pager.razor b/Oqtane.Client/Modules/Controls/Pager.razor
index 59547490..ff7e13ee 100644
--- a/Oqtane.Client/Modules/Controls/Pager.razor
+++ b/Oqtane.Client/Modules/Controls/Pager.razor
@@ -1,6 +1,8 @@
@namespace Oqtane.Modules.Controls
@inherits ModuleBase
-@typeparam TableItem
+@attribute [OqtaneIgnore]
+@typeparam TableItem
+
@if(Format == "Table")
@@ -36,40 +38,40 @@
}
- @if (Page > MaxPages)
+ @if (_page > _maxPages)
{
SetPagerSize("back"))>
}
- @if (EndPage > 1)
+ @if (_endPage > 1)
{
NavigateToPage("previous"))>
- @for (int i = StartPage; i <= EndPage; i++)
+ @for (int i = _startPage; i <= _endPage; i++)
{
var pager = i;
-
@code {
- int Pages = 0;
- int Page = 1;
- int MaxItems;
- int MaxPages;
- int StartPage;
- int EndPage;
+ private int _pages = 0;
+ private int _page = 1;
+ private int _maxItems;
+ private int _maxPages;
+ private int _startPage;
+ private int _endPage;
[Parameter]
public string Format { get; set; }
@@ -95,7 +97,7 @@
[Parameter]
public string Class { get; set; }
- IEnumerable ItemList { get; set; }
+ private IEnumerable ItemList { get; set; }
protected override void OnParametersSet()
{
@@ -103,6 +105,7 @@
{
Format = "Table";
}
+
if (string.IsNullOrEmpty(Class))
{
if (Format == "Table")
@@ -114,36 +117,39 @@
Class = "container";
}
}
+
if (string.IsNullOrEmpty(PageSize))
{
- MaxItems = 10;
+ _maxItems = 10;
}
else
{
- MaxItems = int.Parse(PageSize);
+ _maxItems = int.Parse(PageSize);
}
+
if (string.IsNullOrEmpty(DisplayPages))
{
- MaxPages = 5;
+ _maxPages = 5;
}
else
{
- MaxPages = int.Parse(DisplayPages);
+ _maxPages = int.Parse(DisplayPages);
}
if (Items != null)
{
- ItemList = Items.Skip((Page - 1) * MaxItems).Take(MaxItems);
- Pages = (int)Math.Ceiling(Items.Count() / (decimal)MaxItems);
+ ItemList = Items.Skip((_page - 1) * _maxItems).Take(_maxItems);
+ _pages = (int)Math.Ceiling(Items.Count() / (decimal)_maxItems);
}
SetPagerSize("forward");
}
- public void UpdateList(int CurrentPage)
+ public void UpdateList(int currentPage)
{
- ItemList = Items.Skip((CurrentPage - 1) * MaxItems).Take(MaxItems);
- Page = CurrentPage;
+ ItemList = Items.Skip((currentPage - 1) * _maxItems).Take(_maxItems);
+ _page = currentPage;
+
StateHasChanged();
}
@@ -151,29 +157,30 @@
{
if (direction == "forward")
{
- if (EndPage + 1 < Pages)
+ if (_endPage + 1 < _pages)
{
- StartPage = EndPage + 1;
+ _startPage = _endPage + 1;
}
else
{
- StartPage = 1;
+ _startPage = 1;
}
- if (EndPage + MaxPages < Pages)
+ if (_endPage + _maxPages < _pages)
{
- EndPage = StartPage + MaxPages - 1;
+ _endPage = _startPage + _maxPages - 1;
}
else
{
- EndPage = Pages;
+ _endPage = _pages;
}
+
StateHasChanged();
}
else if (direction == "back")
{
- EndPage = StartPage - 1;
- StartPage = StartPage - MaxPages;
+ _endPage = _startPage - 1;
+ _startPage = _startPage - _maxPages;
}
}
@@ -181,26 +188,27 @@
{
if (direction == "next")
{
- if (Page < Pages)
+ if (_page < _pages)
{
- if (Page == EndPage)
+ if (_page == _endPage)
{
SetPagerSize("forward");
}
- Page += 1;
+ _page += 1;
}
}
else if (direction == "previous")
{
- if (Page > 1)
+ if (_page > 1)
{
- if (Page == StartPage)
+ if (_page == _startPage)
{
SetPagerSize("back");
}
- Page -= 1;
+ _page -= 1;
}
}
- UpdateList(Page);
+
+ UpdateList(_page);
}
-}
\ No newline at end of file
+}
diff --git a/Oqtane.Client/Modules/Controls/PermissionGrid.razor b/Oqtane.Client/Modules/Controls/PermissionGrid.razor
index 2345eb37..90954bbe 100644
--- a/Oqtane.Client/Modules/Controls/PermissionGrid.razor
+++ b/Oqtane.Client/Modules/Controls/PermissionGrid.razor
@@ -1,25 +1,26 @@
@namespace Oqtane.Modules.Controls
-@inherits ModuleBase
+@inherits ModuleBase
+@attribute [OqtaneIgnore]
@inject IRoleService RoleService
@inject IUserService UserService
-@if (roles != null)
+@if (_permissions != null)
{
-
+
Role
- @foreach (PermissionString permission in permissions)
+ @foreach (PermissionString permission in _permissions)
{
- @permission.PermissionName @EntityName
+ @permission.PermissionName
}
- @foreach (Role role in roles)
+ @foreach (Role role in _roles)
{
@role.Name
- @foreach (PermissionString permission in permissions)
+ @foreach (PermissionString permission in _permissions)
{
var p = permission;
@@ -30,29 +31,29 @@
}
- @if (@users.Count != 0)
+ @if (_users.Count != 0)
{
-
+
User
- @foreach (PermissionString permission in permissions)
+ @foreach (PermissionString permission in _permissions)
{
- @permission.PermissionName @EntityName
+ @permission.PermissionName
}
- @foreach (User user in users)
+ @foreach (User user in _users)
{
string userid = "[" + user.UserId.ToString() + "]";
@user.DisplayName
- @foreach (PermissionString permission in permissions)
+ @foreach (PermissionString permission in _permissions)
{
var p = permission;
-
+
}
@@ -60,20 +61,27 @@
}
-
+
-
+
}
@code {
+ private string _permissionnames = string.Empty;
+ private List _roles;
+ private List _permissions;
+ private List _users = new List();
+ private string _username = string.Empty;
+ private string _message = string.Empty;
+
[Parameter]
public string EntityName { get; set; }
@@ -83,46 +91,49 @@
[Parameter]
public string Permissions { get; set; }
- string permissionnames = "";
- List roles;
- List permissions = new List();
- List users = new List();
- string username = "";
- string message = "";
-
protected override async Task OnInitializedAsync()
{
if (string.IsNullOrEmpty(PermissionNames))
{
- permissionnames = "View,Edit";
+ _permissionnames = Shared.PermissionNames.View + "," + Shared.PermissionNames.Edit;
}
else
{
- permissionnames = PermissionNames;
+ _permissionnames = PermissionNames;
}
- roles = await RoleService.GetRolesAsync(ModuleState.SiteId);
- roles.Insert(0, new Role { Name = Constants.AllUsersRole });
- foreach (string permissionname in permissionnames.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
+ _roles = await RoleService.GetRolesAsync(ModuleState.SiteId);
+ _roles.Insert(0, new Role { Name = Constants.AllUsersRole });
+
+ _permissions = new List();
+
+ foreach (string permissionname in _permissionnames.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
- permissions.Add(new PermissionString { PermissionName = permissionname, Permissions = "" });
+ // initialize with admin role
+ _permissions.Add(new PermissionString { PermissionName = permissionname, Permissions = Constants.AdminRole });
}
- foreach (PermissionString permissionstring in UserSecurity.GetPermissionStrings(Permissions))
+
+ if (!string.IsNullOrEmpty(Permissions))
{
- if (permissions.Find(item => item.PermissionName == permissionstring.PermissionName) != null)
+ // populate permissions
+ foreach (PermissionString permissionstring in UserSecurity.GetPermissionStrings(Permissions))
{
- permissions[permissions.FindIndex(item => item.PermissionName == permissionstring.PermissionName)].Permissions = permissionstring.Permissions;
- }
- if (permissionstring.Permissions.Contains("["))
- {
- foreach (string user in permissionstring.Permissions.Split(new char[] { '[' }, StringSplitOptions.RemoveEmptyEntries))
+ if (_permissions.Find(item => item.PermissionName == permissionstring.PermissionName) != null)
{
- if (user.Contains("]"))
+ _permissions[_permissions.FindIndex(item => item.PermissionName == permissionstring.PermissionName)].Permissions = permissionstring.Permissions;
+ }
+
+ if (permissionstring.Permissions.Contains("["))
+ {
+ foreach (string user in permissionstring.Permissions.Split(new char[] { '[' }, StringSplitOptions.RemoveEmptyEntries))
{
- int userid = int.Parse(user.Substring(0, user.IndexOf("]")));
- if (users.Where(item => item.UserId == userid).FirstOrDefault() == null)
+ if (user.Contains("]"))
{
- users.Add(await UserService.GetUserAsync(userid, ModuleState.SiteId));
+ var userid = int.Parse(user.Substring(0, user.IndexOf("]")));
+ if (_users.Where(item => item.UserId == userid).FirstOrDefault() == null)
+ {
+ _users.Add(await UserService.GetUserAsync(userid, ModuleState.SiteId));
+ }
}
}
}
@@ -130,15 +141,15 @@
}
}
- private bool? GetPermissionValue(string Permissions, string SecurityKey)
+ private bool? GetPermissionValue(string permissions, string securityKey)
{
- if ((";" + Permissions + ";").Contains(";" + "!" + SecurityKey + ";"))
+ if ((";" + permissions + ";").Contains(";" + "!" + securityKey + ";"))
{
return false; // deny permission
}
else
{
- if ((";" + Permissions + ";").Contains(";" + SecurityKey + ";"))
+ if ((";" + permissions + ";").Contains(";" + securityKey + ";"))
{
return true; // grant permission
}
@@ -149,66 +160,76 @@
}
}
- private bool GetPermissionDisabled(string RoleName)
- {
- if (RoleName == Constants.AdminRole)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
+ private bool GetPermissionDisabled(string roleName)
+ => roleName == Constants.AdminRole
+ ? true
+ : false;
private async Task AddUser()
{
- if (users.Where(item => item.Username == username).FirstOrDefault() == null)
+ if (_users.Where(item => item.Username == _username).FirstOrDefault() == null)
{
try
{
- User user = await UserService.GetUserAsync(username, ModuleState.SiteId);
+ var user = await UserService.GetUserAsync(_username, ModuleState.SiteId);
if (user != null)
{
- users.Add(user);
+ _users.Add(user);
}
}
catch
{
- message = "Username Does Not Exist";
+ _message = "Username Does Not Exist";
}
}
- username = "";
+
+ _username = string.Empty;
}
- private void PermissionChanged(bool? Value, string PermissionName, string SecurityId)
+ private void PermissionChanged(bool? value, string permissionName, string securityId)
{
- bool? selected = Value;
- PermissionString permission = permissions.Find(item => item.PermissionName == PermissionName);
+ var selected = value;
+ var permission = _permissions.Find(item => item.PermissionName == permissionName);
if (permission != null)
{
- List ids = permission.Permissions.Split(';').ToList();
+ var ids = permission.Permissions.Split(';').ToList();
- ids.Remove(SecurityId); // remove grant permission
- ids.Remove("!" + SecurityId); // remove deny permission
+ ids.Remove(securityId); // remove grant permission
+ ids.Remove("!" + securityId); // remove deny permission
switch (selected)
{
case true:
- ids.Add(SecurityId); // add grant permission
+ ids.Add(securityId); // add grant permission
break;
case false:
- ids.Add("!" + SecurityId); // add deny permission
+ ids.Add("!" + securityId); // add deny permission
break;
case null:
break; // permission not specified
}
- permissions[permissions.FindIndex(item => item.PermissionName == PermissionName)].Permissions = string.Join(";", ids.ToArray());
+
+ _permissions[_permissions.FindIndex(item => item.PermissionName == permissionName)].Permissions = string.Join(";", ids.ToArray());
}
}
public string GetPermissions()
{
- return UserSecurity.SetPermissionStrings(permissions);
+ ValidatePermissions();
+ return UserSecurity.SetPermissionStrings(_permissions);
+ }
+
+ private void ValidatePermissions()
+ {
+ PermissionString permission;
+ for (int i = 0; i < _permissions.Count; i++)
+ {
+ permission = _permissions[i];
+ List ids = permission.Permissions.Split(';').ToList();
+ ids.Remove("!" + Constants.AllUsersRole); // remove deny all users
+ ids.Remove("!" + Constants.RegisteredRole); // remove deny registered users
+ permission.Permissions = string.Join(";", ids.ToArray());
+ _permissions[i] = permission;
+ }
}
}
diff --git a/Oqtane.Client/Modules/Controls/RichTextEditor.razor b/Oqtane.Client/Modules/Controls/RichTextEditor.razor
index 33f0b7e0..c588274f 100644
--- a/Oqtane.Client/Modules/Controls/RichTextEditor.razor
+++ b/Oqtane.Client/Modules/Controls/RichTextEditor.razor
@@ -1,91 +1,218 @@
@namespace Oqtane.Modules.Controls
@inherits ModuleBase
-@inject IJSRuntime JSRuntime
+@attribute [OqtaneIgnore]
+@inject IJSRuntime JsRuntime
-
- @ToolbarContent
-
-
+
+
+
+
+ @if (_filemanagervisible)
+ {
+
+ @((MarkupString)_message)
+
+ }
+
+ Synchronize Content
+ Insert Image
+ @if (_filemanagervisible)
+ {
+ @((MarkupString)" ")
+ Close
+ }
+
+
+
+
+ @if (ToolbarContent != null)
+ {
+ @ToolbarContent
+ }
+ else
+ {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ }
+
+
+
+
+
+
+
+
+ Synchronize Content
+
+ @if (ReadOnly)
+ {
+
+ }
+ else
+ {
+
+ }
+
+
+
@code {
+ private ElementReference _editorElement;
+ private ElementReference _toolBar;
+ private bool _filemanagervisible = false;
+ private FileManager _fileManager;
+ private string _content = string.Empty;
+ private string _original = string.Empty;
+ private string _message = string.Empty;
+
+ [Parameter]
+ public string Content { get; set; }
+
+ [Parameter]
+ public bool ReadOnly { get; set; } = false;
+
+ [Parameter]
+ public string Placeholder { get; set; } = "Enter Your Content...";
+
+ // parameters only applicable to rich text editor
[Parameter]
public RenderFragment ToolbarContent { get; set; }
[Parameter]
- public bool ReadOnly { get; set; }
- = false;
+ public string Theme { get; set; } = "snow";
[Parameter]
- public string Placeholder { get; set; }
- = "Compose an epic...";
+ public string DebugLevel { get; set; } = "info";
- [Parameter]
- public string Theme { get; set; }
- = "snow";
+ protected override void OnInitialized()
+ {
+ _content = Content; // raw HTML
+ }
- [Parameter]
- public string DebugLevel { get; set; }
- = "info";
-
- private ElementReference EditorElement;
- private ElementReference ToolBar;
-
- protected override async Task
- OnAfterRenderAsync(bool firstRender)
+ protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
- await RichTextEditorInterop.CreateEditor(
- JSRuntime,
- EditorElement,
- ToolBar,
+ var interop = new RichTextEditorInterop(JsRuntime);
+
+ await interop.CreateEditor(
+ _editorElement,
+ _toolBar,
ReadOnly,
Placeholder,
Theme,
DebugLevel);
+
+ await interop.LoadEditorContent(_editorElement, Content);
+
+ // preserve a copy of the rich text content ( Quill sanitizes content so we need to retrieve it from the editor )
+ _original = await interop.GetHtml(_editorElement);
}
}
- public async Task
GetText()
+ public void CloseFileManager()
{
- return await RichTextEditorInterop.GetText(
- JSRuntime,
- EditorElement);
+ _filemanagervisible = false;
+ _message = string.Empty;
+ StateHasChanged();
}
- public async Task GetHTML()
+ public async Task RefreshRichText()
{
- return await RichTextEditorInterop.GetHTML(
- JSRuntime,
- EditorElement);
+ var interop = new RichTextEditorInterop(JsRuntime);
+ await interop.LoadEditorContent(_editorElement, _content);
+ }
+
+ public async Task RefreshRawHtml()
+ {
+ var interop = new RichTextEditorInterop(JsRuntime);
+ _content = await interop.GetHtml(_editorElement);
+ StateHasChanged();
+ }
+
+ public async Task GetHtml()
+ {
+ // get rich text content
+ var interop = new RichTextEditorInterop(JsRuntime);
+ string content = await interop.GetHtml(_editorElement);
+
+ if (_original != content)
+ {
+ // rich text content has changed - return it
+ return content;
+ }
+ else
+ {
+ // return raw html content
+ return _content;
+ }
+ }
+
+ public async Task InsertImage()
+ {
+ if (_filemanagervisible)
+ {
+ var fileid = _fileManager.GetFileId();
+ if (fileid != -1)
+ {
+ var interop = new RichTextEditorInterop(JsRuntime);
+ await interop.InsertImage(_editorElement, ContentUrl(fileid));
+ _filemanagervisible = false;
+ _message = string.Empty;
+ }
+ else
+ {
+ _message = "You Must Select An Image To Insert
";
+ }
+ }
+ else
+ {
+ _filemanagervisible = true;
+ _message = string.Empty;
+ }
+ StateHasChanged();
+ }
+
+ // other rich text editor methods which can be used by developers
+ public async Task GetText()
+ {
+ var interop = new RichTextEditorInterop(JsRuntime);
+ return await interop.GetText(_editorElement);
}
public async Task GetContent()
{
- return await RichTextEditorInterop.GetContent(
- JSRuntime,
- EditorElement);
- }
-
- public async Task LoadContent(string Content)
- {
- await RichTextEditorInterop.LoadEditorContent(
- JSRuntime,
- EditorElement, Content);
+ var interop = new RichTextEditorInterop(JsRuntime);
+ return await interop.GetContent(_editorElement);
}
public async Task EnableEditor(bool mode)
{
- await RichTextEditorInterop.EnableEditor(
- JSRuntime,
- EditorElement, mode);
+ var interop = new RichTextEditorInterop(JsRuntime);
+ await interop.EnableEditor(_editorElement, mode);
}
-
- public async Task InsertImage(string ImageURL)
- {
- await RichTextEditorInterop.InsertImage(
- JSRuntime,
- EditorElement, ImageURL);
- }
-}
\ No newline at end of file
+}
diff --git a/Oqtane.Client/Modules/Controls/RichTextEditorInterop.cs b/Oqtane.Client/Modules/Controls/RichTextEditorInterop.cs
new file mode 100644
index 00000000..a5bd4ffa
--- /dev/null
+++ b/Oqtane.Client/Modules/Controls/RichTextEditorInterop.cs
@@ -0,0 +1,124 @@
+using Microsoft.AspNetCore.Components;
+using Microsoft.JSInterop;
+using System.Threading.Tasks;
+
+namespace Oqtane.Modules.Controls
+{
+ public class RichTextEditorInterop
+ {
+ private readonly IJSRuntime _jsRuntime;
+
+ public RichTextEditorInterop(IJSRuntime jsRuntime)
+ {
+ _jsRuntime = jsRuntime;
+ }
+
+ public Task CreateEditor(
+ ElementReference quillElement,
+ ElementReference toolbar,
+ bool readOnly,
+ string placeholder,
+ string theme,
+ string debugLevel)
+ {
+ try
+ {
+ _jsRuntime.InvokeAsync(
+ "Oqtane.RichTextEditor.createQuill",
+ quillElement, toolbar, readOnly,
+ placeholder, theme, debugLevel);
+ return Task.CompletedTask;
+ }
+ catch
+ {
+ return Task.CompletedTask;
+ }
+ }
+
+ public ValueTask GetText(ElementReference quillElement)
+ {
+ try
+ {
+ return _jsRuntime.InvokeAsync(
+ "Oqtane.RichTextEditor.getQuillText",
+ quillElement);
+ }
+ catch
+ {
+ return new ValueTask(Task.FromResult(string.Empty));
+ }
+ }
+
+ public ValueTask GetHtml(ElementReference quillElement)
+ {
+ try
+ {
+ return _jsRuntime.InvokeAsync(
+ "Oqtane.RichTextEditor.getQuillHTML",
+ quillElement);
+ }
+ catch
+ {
+ return new ValueTask(Task.FromResult(string.Empty));
+ }
+ }
+
+ public ValueTask GetContent(ElementReference quillElement)
+ {
+ try
+ {
+ return _jsRuntime.InvokeAsync(
+ "Oqtane.RichTextEditor.getQuillContent",
+ quillElement);
+ }
+ catch
+ {
+ return new ValueTask(Task.FromResult(string.Empty));
+ }
+ }
+
+ public Task LoadEditorContent(ElementReference quillElement, string content)
+ {
+ try
+ {
+ _jsRuntime.InvokeAsync(
+ "Oqtane.RichTextEditor.loadQuillContent",
+ quillElement, content);
+ return Task.CompletedTask;
+ }
+ catch
+ {
+ return Task.CompletedTask;
+ }
+ }
+
+ public Task EnableEditor(ElementReference quillElement, bool mode)
+ {
+ try
+ {
+ _jsRuntime.InvokeAsync(
+ "Oqtane.RichTextEditor.enableQuillEditor", quillElement, mode);
+ return Task.CompletedTask;
+ }
+ catch
+ {
+ return Task.CompletedTask;
+ }
+ }
+
+ public Task InsertImage(ElementReference quillElement, string imageUrl)
+ {
+ try
+ {
+ _jsRuntime.InvokeAsync(
+ "Oqtane.RichTextEditor.insertQuillImage",
+ quillElement, imageUrl);
+ return Task.CompletedTask;
+ }
+ catch
+ {
+ return Task.CompletedTask;
+ }
+ }
+ }
+}
diff --git a/Oqtane.Client/Modules/Controls/Section.razor b/Oqtane.Client/Modules/Controls/Section.razor
new file mode 100644
index 00000000..4f33b42f
--- /dev/null
+++ b/Oqtane.Client/Modules/Controls/Section.razor
@@ -0,0 +1,45 @@
+@namespace Oqtane.Modules.Controls
+@inherits ModuleBase
+@attribute [OqtaneIgnore]
+
+
+
+
+
+
+ @ChildContent
+
+
+@code {
+ private string _heading = string.Empty;
+ private string _expanded = string.Empty;
+
+ [Parameter]
+ public RenderFragment ChildContent { get; set; }
+
+ [Parameter]
+ public string Name { get; set; } // required - the name of the section
+
+ [Parameter]
+ public string Heading { get; set; } // optional - will default to Name if not provided
+
+ [Parameter]
+ public string Expanded { get; set; } // optional - will default to false if not provided
+
+ protected override void OnInitialized()
+ {
+ _heading = (!string.IsNullOrEmpty(Heading)) ? Heading : Name;
+ _expanded = (!string.IsNullOrEmpty(Expanded)) ? Expanded : "false";
+ }
+}
diff --git a/Oqtane.Client/Modules/Controls/TabControl.razor b/Oqtane.Client/Modules/Controls/TabControl.razor
deleted file mode 100644
index e6cda943..00000000
--- a/Oqtane.Client/Modules/Controls/TabControl.razor
+++ /dev/null
@@ -1,43 +0,0 @@
-@namespace Oqtane.Modules.Controls
-@inherits ModuleBase
-
-
-
- @foreach (TabPanel tabPanel in TabPanels)
- {
- ActivateTabPanel(tabPanel) )>
- @tabPanel.Text
-
- }
-
- @ChildContent
-
-
-@code {
- // Next line is needed so we are able to add components inside
- [Parameter]
- public RenderFragment ChildContent { get; set; }
-
- public TabPanel ActiveTabPanel { get; set; }
- List TabPanels = new List();
-
- internal void AddTabPanel(TabPanel tabPanel)
- {
- TabPanels.Add(tabPanel);
- if (TabPanels.Count == 1)
- ActiveTabPanel = tabPanel;
- StateHasChanged();
- }
-
- string GetButtonClass(TabPanel tabPanel)
- {
- return tabPanel == ActiveTabPanel ? "btn-primary" : "btn-secondary";
- }
-
- void ActivateTabPanel(TabPanel tabPanel)
- {
- ActiveTabPanel = tabPanel;
- }
-}
diff --git a/Oqtane.Client/Modules/Controls/TabPanel.razor b/Oqtane.Client/Modules/Controls/TabPanel.razor
index 475d6258..bd89ab59 100644
--- a/Oqtane.Client/Modules/Controls/TabPanel.razor
+++ b/Oqtane.Client/Modules/Controls/TabPanel.razor
@@ -1,27 +1,36 @@
@namespace Oqtane.Modules.Controls
-@inherits ModuleBase
+@inherits ModuleBase
+@attribute [OqtaneIgnore]
-@if (Parent.ActiveTabPanel == (TabPanel)(object)this)
+@if (Name == Parent.ActiveTab)
{
- @ChildContent
+
+ @ChildContent
+
+}
+else
+{
+
+ @ChildContent
+
}
@code {
[CascadingParameter]
- private TabControl Parent { get; set; }
+ private TabStrip Parent { get; set; }
[Parameter]
public RenderFragment ChildContent { get; set; }
[Parameter]
- public string Text { get; set; }
+ public string Name { get; set; } // required - name of the TabPanel
+
+ [Parameter]
+ public string Heading { get; set; } // optional - defaults to name if not specified
protected override void OnInitialized()
{
- if (Parent == null)
- throw new ArgumentNullException(nameof(Parent), "TabPanel must exist within a TabControl");
-
base.OnInitialized();
- Parent.AddTabPanel((TabPanel)(object)this);
+ Parent.AddTabPanel((TabPanel)this);
}
}
diff --git a/Oqtane.Client/Modules/Controls/TabStrip.razor b/Oqtane.Client/Modules/Controls/TabStrip.razor
new file mode 100644
index 00000000..8d8d3838
--- /dev/null
+++ b/Oqtane.Client/Modules/Controls/TabStrip.razor
@@ -0,0 +1,66 @@
+@namespace Oqtane.Modules.Controls
+@inherits ModuleBase
+@attribute [OqtaneIgnore]
+
+
+
+
+
+@code {
+ private List _tabPanels = new List();
+
+ [Parameter]
+ public RenderFragment ChildContent { get; set; } // contains the TabPanels
+
+ [Parameter]
+ public string ActiveTab { get; set; } // optional - defaults to first TabPanel if not specified. Can also be set using a "tab=" querystring parameter.
+
+ protected override void OnInitialized()
+ {
+ if (PageState.QueryString.ContainsKey("tab"))
+ {
+ ActiveTab = PageState.QueryString["tab"];
+ }
+ }
+
+ internal void AddTabPanel(TabPanel tabPanel)
+ {
+ _tabPanels.Add(tabPanel);
+ if (string.IsNullOrEmpty(ActiveTab))
+ {
+ ActiveTab = tabPanel.Name;
+ }
+ StateHasChanged();
+ }
+
+ private string DisplayHeading(string Name, string Heading)
+ {
+ return (string.IsNullOrEmpty(Heading)) ? Name : Heading;
+ }
+}
diff --git a/Oqtane.Client/Modules/Controls/TriStateCheckBox.razor b/Oqtane.Client/Modules/Controls/TriStateCheckBox.razor
index c8881f3f..3c056d87 100644
--- a/Oqtane.Client/Modules/Controls/TriStateCheckBox.razor
+++ b/Oqtane.Client/Modules/Controls/TriStateCheckBox.razor
@@ -1,8 +1,12 @@
@namespace Oqtane.Modules.Controls
-
+
@code {
+ private bool? _value = null;
+ private string _title;
+ private string _src = string.Empty;
+
[Parameter]
public bool? Value { get; set; }
@@ -12,51 +16,52 @@
[Parameter]
public Action OnChange { get; set; }
- bool? value = null;
- string title;
- string src = "";
-
protected override void OnInitialized()
{
- value = Value;
+ _value = Value;
SetImage();
}
private void SetValue()
{
- switch (value)
+ if (!Disabled)
{
- case true:
- value = false;
- break;
- case false:
- value = null;
- break;
- case null:
- value = true;
- break;
+ switch (_value)
+ {
+ case true:
+ _value = false;
+ break;
+ case false:
+ _value = null;
+ break;
+ case null:
+ _value = true;
+ break;
+ }
+
+ SetImage();
+ OnChange(_value);
}
- SetImage();
- OnChange(value);
}
private void SetImage()
{
- switch (value)
+ switch (_value)
{
case true:
- src = "images/checked.png";
- title = "Permission Granted";
+ _src = "images/checked.png";
+ _title = "Permission Granted";
break;
case false:
- src = "images/unchecked.png";
- title = "Permission Denied";
+ _src = "images/unchecked.png";
+ _title = "Permission Denied";
break;
case null:
- src = "images/null.png";
- title = "";
+ _src = "images/null.png";
+ _title = string.Empty;
break;
}
+
StateHasChanged();
}
}
diff --git a/Oqtane.Client/Modules/Counter/Index.razor b/Oqtane.Client/Modules/Counter/Index.razor
deleted file mode 100644
index b511cfc0..00000000
--- a/Oqtane.Client/Modules/Counter/Index.razor
+++ /dev/null
@@ -1,16 +0,0 @@
-@namespace Oqtane.Modules.Counter
-@inherits ModuleBase
-Current count: @currentCount
-
-Click me
-
-
-
-@code {
- int currentCount = 0;
-
- void IncrementCount()
- {
- currentCount++;
- }
-}
diff --git a/Oqtane.Client/Modules/Counter/Module.cs b/Oqtane.Client/Modules/Counter/Module.cs
deleted file mode 100644
index 5f509ae2..00000000
--- a/Oqtane.Client/Modules/Counter/Module.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using System.Collections.Generic;
-
-namespace Oqtane.Modules.Counter
-{
- public class Module : IModule
- {
- public Dictionary Properties
- {
- get
- {
- Dictionary properties = new Dictionary
- {
- { "Name", "Counter" },
- { "Description", "Increments a counter" },
- { "Version", "1.0.0" }
- };
- return properties;
- }
- }
- }
-}
diff --git a/Oqtane.Client/Modules/HtmlText/Edit.razor b/Oqtane.Client/Modules/HtmlText/Edit.razor
index 0fb17a96..292706e2 100644
--- a/Oqtane.Client/Modules/HtmlText/Edit.razor
+++ b/Oqtane.Client/Modules/HtmlText/Edit.razor
@@ -3,154 +3,94 @@
@using Oqtane.Modules.Controls
@namespace Oqtane.Modules.HtmlText
@inherits ModuleBase
+@inject IHtmlTextService HtmlTextService
@inject NavigationManager NavigationManager
-@inject HttpClient http
-@inject SiteState sitestate
-
-
-
- Content:
-
-
- @if (!RichTextEditorMode)
+@if (_content != null)
+{
+
+ Save
+ Cancel
+ @if (!string.IsNullOrEmpty(_content))
+ {
+
+
+
+ }
+}
+
+@code {
+ public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Edit;
+
+ public override string Title => "Edit Html/Text";
+
+ public override List Resources => new List()
+ {
+ new Resource { ResourceType = ResourceType.Stylesheet, Url = ModulePath() + "Module.css" },
+ // the following resources should be declared in the RichTextEditor component however the framework currently only supports resource management for modules and themes
+ new Resource { ResourceType = ResourceType.Stylesheet, Url = "css/quill/quill1.3.6.bubble.css" },
+ new Resource { ResourceType = ResourceType.Stylesheet, Url = "css/quill/quill1.3.6.snow.css" },
+ new Resource { ResourceType = ResourceType.Script, Url = "js/quill1.3.6.min.js" },
+ new Resource { ResourceType = ResourceType.Script, Url = "js/quill-blot-formatter.min.js" },
+ new Resource { ResourceType = ResourceType.Script, Url = "js/quill-interop.js" }
+ };
+
+ private RichTextEditor RichTextEditorHtml;
+ private string _content = null;
+ private string _createdby;
+ private DateTime _createdon;
+ private string _modifiedby;
+ private DateTime _modifiedon;
+
+ protected override async Task OnInitializedAsync()
+ {
+ try
+ {
+ var htmltext = await HtmlTextService.GetHtmlTextAsync(ModuleState.ModuleId);
+ if (htmltext != null)
{
-
+ _content = htmltext.Content;
+ _content = _content.Replace(Constants.ContentUrl, "/" + PageState.Alias.AliasId.ToString() + Constants.ContentUrl);
+ _createdby = htmltext.CreatedBy;
+ _createdon = htmltext.CreatedOn;
+ _modifiedby = htmltext.ModifiedBy;
+ _modifiedon = htmltext.ModifiedOn;
}
else
{
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
-
-
-
-@if (!RichTextEditorMode)
-{
- Rich Text Editor
-}
-else
-{
- Raw HTML Editor
-}
-Save
-Cancel
-
-
-
-
-@code {
- public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Edit; } }
- public override string Title { get { return "Edit Html/Text"; } }
-
- RichTextEditor RichTextEditorHtml;
- bool RichTextEditorMode = true;
- string content;
- string createdby;
- DateTime createdon;
- string modifiedby;
- DateTime modifiedon;
-
- protected override async Task OnAfterRenderAsync(bool firstRender)
- {
- if (firstRender)
- {
- try
- {
- await LoadText();
- }
- catch (Exception ex)
- {
- await logger.LogError(ex, "An Error Occurred Loading Html/Text Content. " + ex.Message);
- AddModuleMessage(ex.Message, MessageType.Error);
+ _content = string.Empty;
}
}
- }
-
- private async Task LoadText()
- {
- HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, NavigationManager);
- HtmlTextInfo htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId);
- if (htmltext != null)
+ catch (Exception ex)
{
- content = htmltext.Content;
- createdby = htmltext.CreatedBy;
- createdon = htmltext.CreatedOn;
- modifiedby = htmltext.ModifiedBy;
- modifiedon = htmltext.ModifiedOn;
-
- if (RichTextEditorMode)
- {
- await RichTextEditorHtml.LoadContent(content);
- StateHasChanged();
- }
+ await logger.LogError(ex, "An Error Occurred Loading Html/Text Content. " + ex.Message);
+ AddModuleMessage(ex.Message, MessageType.Error);
}
}
- private async Task RichTextEditor()
- {
- RichTextEditorMode = true;
- await LoadText();
- }
-
- private async Task RawHTMLEditor()
- {
- RichTextEditorMode = false;
- await LoadText();
- }
-
private async Task SaveContent()
{
- if (RichTextEditorMode)
- {
- content = await this.RichTextEditorHtml.GetHTML();
- }
+ string content = await RichTextEditorHtml.GetHtml();
+ content = content.Replace("/" + PageState.Alias.AliasId.ToString() + Constants.ContentUrl, Constants.ContentUrl);
try
{
- HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, NavigationManager);
- HtmlTextInfo htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId);
+ var htmltext = await HtmlTextService.GetHtmlTextAsync(ModuleState.ModuleId);
if (htmltext != null)
{
htmltext.Content = content;
- await htmltextservice.UpdateHtmlTextAsync(htmltext);
+ await HtmlTextService.UpdateHtmlTextAsync(htmltext);
}
else
{
htmltext = new HtmlTextInfo();
htmltext.ModuleId = ModuleState.ModuleId;
htmltext.Content = content;
- await htmltextservice.AddHtmlTextAsync(htmltext);
+ await HtmlTextService.AddHtmlTextAsync(htmltext);
}
+
await logger.LogInformation("Html/Text Content Saved {HtmlText}", htmltext);
- NavigationManager.NavigateTo(NavigateUrl(Reload.Page));
+ NavigationManager.NavigateTo(NavigateUrl());
}
catch (Exception ex)
{
diff --git a/Oqtane.Client/Modules/HtmlText/Index.razor b/Oqtane.Client/Modules/HtmlText/Index.razor
index b1d679c2..8160c19a 100644
--- a/Oqtane.Client/Modules/HtmlText/Index.razor
+++ b/Oqtane.Client/Modules/HtmlText/Index.razor
@@ -1,29 +1,32 @@
@using Oqtane.Modules.HtmlText.Services
-@using Oqtane.Modules.HtmlText.Models
@namespace Oqtane.Modules.HtmlText
@inherits ModuleBase
-@inject NavigationManager NavigationManager
-@inject HttpClient http
-@inject SiteState sitestate
+@inject IHtmlTextService HtmlTextService
@((MarkupString)content)
-
-
-
+@if (PageState.EditMode)
+{
+
+}
@code {
- string content;
+ public override List Resources => new List()
+ {
+ new Resource { ResourceType = ResourceType.Stylesheet, Url = ModulePath() + "Module.css" }
+ };
+
+ private string content = "";
protected override async Task OnParametersSetAsync()
{
try
{
- HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, NavigationManager);
- HtmlTextInfo htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId);
+ var htmltext = await HtmlTextService.GetHtmlTextAsync(ModuleState.ModuleId);
if (htmltext != null)
{
content = htmltext.Content;
+ content = content.Replace(Constants.ContentUrl, "/" + PageState.Alias.AliasId.ToString() + Constants.ContentUrl);
}
}
catch (Exception ex)
diff --git a/Oqtane.Client/Modules/HtmlText/ModuleInfo.cs b/Oqtane.Client/Modules/HtmlText/ModuleInfo.cs
index df585a05..4be90a8b 100644
--- a/Oqtane.Client/Modules/HtmlText/ModuleInfo.cs
+++ b/Oqtane.Client/Modules/HtmlText/ModuleInfo.cs
@@ -1,22 +1,16 @@
-using System.Collections.Generic;
+using Oqtane.Models;
namespace Oqtane.Modules.HtmlText
{
public class ModuleInfo : IModule
{
- public Dictionary Properties
+ public ModuleDefinition ModuleDefinition => new ModuleDefinition
{
- get
- {
- Dictionary properties = new Dictionary
- {
- { "Name", "HtmlText" },
- { "Description", "Renders HTML or Text" },
- { "Version", "1.0.0" },
- { "ServerAssemblyName", "Oqtane.Server" }
- };
- return properties;
- }
- }
+ Name = "HtmlText",
+ Description = "Renders HTML or Text Content",
+ Version = "1.0.0",
+ ServerManagerType = "Oqtane.Modules.HtmlText.Manager.HtmlTextManager, Oqtane.Server",
+ ReleaseVersions = "1.0.0"
+ };
}
}
diff --git a/Oqtane.Client/Modules/HtmlText/Services/HtmlTextService.cs b/Oqtane.Client/Modules/HtmlText/Services/HtmlTextService.cs
index b6336015..51ab7887 100644
--- a/Oqtane.Client/Modules/HtmlText/Services/HtmlTextService.cs
+++ b/Oqtane.Client/Modules/HtmlText/Services/HtmlTextService.cs
@@ -1,60 +1,43 @@
-using System.Threading.Tasks;
+using System.Collections.Generic;
+using System.Linq;
using System.Net.Http;
-using Microsoft.AspNetCore.Components;
-using Oqtane.Services;
+using System.Threading.Tasks;
using Oqtane.Modules.HtmlText.Models;
+using Oqtane.Services;
using Oqtane.Shared;
-using Oqtane.Models;
namespace Oqtane.Modules.HtmlText.Services
{
- public class HtmlTextService : ServiceBase, IHtmlTextService
- {
- private readonly HttpClient http;
- private readonly SiteState sitestate;
- private readonly NavigationManager NavigationManager;
+ public class HtmlTextService : ServiceBase, IHtmlTextService, IService
+ {
+ private readonly SiteState _siteState;
- public HtmlTextService(HttpClient http, SiteState sitestate, NavigationManager NavigationManager)
+ public HtmlTextService(HttpClient http, SiteState siteState) : base(http)
{
- this.http = http;
- this.sitestate = sitestate;
- this.NavigationManager = NavigationManager;
+ _siteState = siteState;
}
- private string apiurl
+ private string ApiUrl => CreateApiUrl(_siteState.Alias, "HtmlText");
+
+ public async Task GetHtmlTextAsync(int moduleId)
{
- get { return CreateApiUrl(sitestate.Alias, NavigationManager.Uri, "HtmlText"); }
+ var htmltext = await GetJsonAsync>($"{ApiUrl}/{moduleId}?entityid={moduleId}");
+ return htmltext.FirstOrDefault();
}
- public async Task GetHtmlTextAsync(int ModuleId)
+ public async Task AddHtmlTextAsync(HtmlTextInfo htmlText)
{
- HtmlTextInfo htmltext;
- try
- {
- // exception handling is required because GetJsonAsync() returns an error if no content exists for the ModuleId ( https://github.com/aspnet/AspNetCore/issues/14041 )
- htmltext = await http.GetJsonAsync(apiurl + "/" + ModuleId.ToString() + "?entityid=" + ModuleId.ToString());
- }
- catch
- {
- htmltext = null;
- }
- return htmltext;
+ await PostJsonAsync($"{ApiUrl}?entityid={htmlText.ModuleId}", htmlText);
}
- public async Task AddHtmlTextAsync(HtmlTextInfo htmltext)
+ public async Task UpdateHtmlTextAsync(HtmlTextInfo htmlText)
{
- await http.PostJsonAsync(apiurl + "?entityid=" + htmltext.ModuleId.ToString(), htmltext);
+ await PutJsonAsync($"{ApiUrl}/{htmlText.HtmlTextId}?entityid={htmlText.ModuleId}", htmlText);
}
- public async Task UpdateHtmlTextAsync(HtmlTextInfo htmltext)
+ public async Task DeleteHtmlTextAsync(int moduleId)
{
- await http.PutJsonAsync(apiurl + "/" + htmltext.HtmlTextId.ToString() + "?entityid=" + htmltext.ModuleId.ToString(), htmltext);
+ await DeleteAsync($"{ApiUrl}/{moduleId}?entityid={moduleId}");
}
-
- public async Task DeleteHtmlTextAsync(int ModuleId)
- {
- await http.DeleteAsync(apiurl + "/" + ModuleId.ToString() + "?entityid=" + ModuleId.ToString());
- }
-
}
}
diff --git a/Oqtane.Client/Modules/IModule.cs b/Oqtane.Client/Modules/IModule.cs
index 675378b8..f0ecfacf 100644
--- a/Oqtane.Client/Modules/IModule.cs
+++ b/Oqtane.Client/Modules/IModule.cs
@@ -1,9 +1,9 @@
-using System.Collections.Generic;
+using Oqtane.Models;
namespace Oqtane.Modules
{
public interface IModule
{
- Dictionary Properties { get; }
+ ModuleDefinition ModuleDefinition { get; }
}
}
diff --git a/Oqtane.Shared/Enums/MessageType.cs b/Oqtane.Client/Modules/MessageType.cs
similarity index 79%
rename from Oqtane.Shared/Enums/MessageType.cs
rename to Oqtane.Client/Modules/MessageType.cs
index 4610fdf4..a78f95f9 100644
--- a/Oqtane.Shared/Enums/MessageType.cs
+++ b/Oqtane.Client/Modules/MessageType.cs
@@ -1,4 +1,4 @@
-namespace Oqtane.Shared
+namespace Oqtane.Modules
{
public enum MessageType
{
diff --git a/Oqtane.Client/Modules/ModuleBase.cs b/Oqtane.Client/Modules/ModuleBase.cs
index 397daa2b..9da4a090 100644
--- a/Oqtane.Client/Modules/ModuleBase.cs
+++ b/Oqtane.Client/Modules/ModuleBase.cs
@@ -2,21 +2,20 @@
using Oqtane.Shared;
using Oqtane.Models;
using System.Threading.Tasks;
-using System.Linq;
using Oqtane.Services;
using System;
+using Oqtane.Enums;
+using Oqtane.UI;
+using System.Collections.Generic;
namespace Oqtane.Modules
{
- public class ModuleBase : ComponentBase, IModuleControl
+ public abstract class ModuleBase : ComponentBase, IModuleControl
{
- public Logger logger { get; set; }
-
- public ModuleBase()
- {
- this.logger = new Logger(this);
- }
+ private Logger _logger;
+ protected Logger logger => _logger ?? (_logger = new Logger(this));
+
[Inject]
protected ILogService LoggingService { get; set; }
@@ -29,13 +28,6 @@ namespace Oqtane.Modules
[CascadingParameter]
protected ModuleInstance ModuleInstance { get; set; }
- protected ModuleDefinition ModuleDefinition
- {
- get
- {
- return PageState.ModuleDefinitions.Where(item => item.ModuleDefinitionName == ModuleState.ModuleDefinitionName).FirstOrDefault();
- }
- }
// optional interface properties
public virtual SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.View; } set { } } // default security
@@ -46,11 +38,14 @@ namespace Oqtane.Modules
public virtual bool UseAdminContainer { get { return true; } }
+ public virtual List Resources { get; set; }
+
+
// path method
public string ModulePath()
{
- return "Modules/" + this.GetType().Namespace + "/";
+ return "Modules/" + GetType().Namespace + "/";
}
// url methods
@@ -59,29 +54,14 @@ namespace Oqtane.Modules
return NavigateUrl(PageState.Page.Path);
}
- public string NavigateUrl(Reload reload)
- {
- return NavigateUrl(PageState.Page.Path, reload);
- }
-
public string NavigateUrl(string path)
{
- return NavigateUrl(path, "", Reload.None);
- }
-
- public string NavigateUrl(string path, Reload reload)
- {
- return NavigateUrl(path, "", reload);
+ return NavigateUrl(path, "");
}
public string NavigateUrl(string path, string parameters)
{
- return Utilities.NavigateUrl(PageState.Alias.Path, path, parameters, Reload.None);
- }
-
- public string NavigateUrl(string path, string parameters, Reload reload)
- {
- return Utilities.NavigateUrl(PageState.Alias.Path, path, parameters, reload);
+ return Utilities.NavigateUrl(PageState.Alias.Path, path, parameters);
}
public string EditUrl(string action)
@@ -94,14 +74,14 @@ namespace Oqtane.Modules
return EditUrl(ModuleState.ModuleId, action, parameters);
}
- public string EditUrl(int moduleid, string action)
+ public string EditUrl(int moduleId, string action)
{
- return EditUrl(moduleid, action, "");
+ return EditUrl(moduleId, action, "");
}
- public string EditUrl(int moduleid, string action, string parameters)
+ public string EditUrl(int moduleId, string action, string parameters)
{
- return EditUrl(PageState.Page.Path, moduleid, action, parameters);
+ return EditUrl(PageState.Page.Path, moduleId, action, parameters);
}
public string EditUrl(string path, int moduleid, string action, string parameters)
@@ -109,6 +89,11 @@ namespace Oqtane.Modules
return Utilities.EditUrl(PageState.Alias.Path, path, moduleid, action, parameters);
}
+ public string ContentUrl(int fileid)
+ {
+ return Utilities.ContentUrl(PageState.Alias, fileid);
+ }
+
// user feedback methods
public void AddModuleMessage(string message, MessageType type)
{
@@ -126,107 +111,111 @@ namespace Oqtane.Modules
}
// logging methods
- public async Task Log(LogLevel level, Exception exception, string message, params object[] args)
+ public async Task Log(Alias alias, LogLevel level, string function, Exception exception, string message, params object[] args)
{
- int PageId = PageState.Page.PageId;
- int ModuleId = ModuleState.ModuleId;
- int? UserId = null;
+ int pageId = ModuleState.PageId;
+ int moduleId = ModuleState.ModuleId;
+ int? userId = null;
if (PageState.User != null)
{
- UserId = PageState.User.UserId;
+ userId = PageState.User.UserId;
}
- string category = this.GetType().AssemblyQualifiedName;
+ string category = GetType().AssemblyQualifiedName;
string feature = Utilities.GetTypeNameLastSegment(category, 1);
- LogFunction function;
- switch (PageState.Action)
+ LogFunction logFunction;
+ if (string.IsNullOrEmpty(function))
{
- case "Add":
- function = LogFunction.Create;
+ function = PageState.Action;
+ }
+ switch (function.ToLower())
+ {
+ case "add":
+ logFunction = LogFunction.Create;
break;
- case "Edit":
- function = LogFunction.Update;
+ case "edit":
+ logFunction = LogFunction.Update;
break;
- case "Delete":
- function = LogFunction.Delete;
+ case "delete":
+ logFunction = LogFunction.Delete;
break;
default:
- function = LogFunction.Read;
+ logFunction = LogFunction.Read;
break;
}
if (feature == "Login")
{
- function = LogFunction.Security;
+ logFunction = LogFunction.Security;
}
- await LoggingService.Log(PageId, ModuleId, UserId, category, feature, function, level, exception, message, args);
+ await LoggingService.Log(alias, pageId, moduleId, userId, category, feature, logFunction, level, exception, message, args);
}
public class Logger
{
- private ModuleBase modulebase;
+ private readonly ModuleBase _moduleBase;
- public Logger(ModuleBase modulebase)
+ public Logger(ModuleBase moduleBase)
{
- this.modulebase = modulebase;
+ _moduleBase = moduleBase;
}
public async Task LogTrace(string message, params object[] args)
{
- await modulebase.Log(LogLevel.Trace, null, message, args);
+ await _moduleBase.Log(null, LogLevel.Trace, "", null, message, args);
}
public async Task LogTrace(Exception exception, string message, params object[] args)
{
- await modulebase.Log(LogLevel.Trace, exception, message, args);
+ await _moduleBase.Log(null, LogLevel.Trace, "", exception, message, args);
}
public async Task LogDebug(string message, params object[] args)
{
- await modulebase.Log(LogLevel.Debug, null, message, args);
+ await _moduleBase.Log(null, LogLevel.Debug, "", null, message, args);
}
public async Task LogDebug(Exception exception, string message, params object[] args)
{
- await modulebase.Log(LogLevel.Debug, exception, message, args);
+ await _moduleBase.Log(null, LogLevel.Debug, "", exception, message, args);
}
public async Task LogInformation(string message, params object[] args)
{
- await modulebase.Log(LogLevel.Information, null, message, args);
+ await _moduleBase.Log(null, LogLevel.Information, "", null, message, args);
}
public async Task LogInformation(Exception exception, string message, params object[] args)
{
- await modulebase.Log(LogLevel.Information, exception, message, args);
+ await _moduleBase.Log(null, LogLevel.Information, "", exception, message, args);
}
public async Task LogWarning(string message, params object[] args)
{
- await modulebase.Log(LogLevel.Warning, null, message, args);
+ await _moduleBase.Log(null, LogLevel.Warning, "", null, message, args);
}
public async Task LogWarning(Exception exception, string message, params object[] args)
{
- await modulebase.Log(LogLevel.Warning, exception, message, args);
+ await _moduleBase.Log(null, LogLevel.Warning, "", exception, message, args);
}
public async Task LogError(string message, params object[] args)
{
- await modulebase.Log(LogLevel.Error, null, message, args);
+ await _moduleBase.Log(null, LogLevel.Error, "", null, message, args);
}
public async Task LogError(Exception exception, string message, params object[] args)
{
- await modulebase.Log(LogLevel.Error, exception, message, args);
+ await _moduleBase.Log(null, LogLevel.Error, "", exception, message, args);
}
public async Task LogCritical(string message, params object[] args)
{
- await modulebase.Log(LogLevel.Critical, null, message, args);
+ await _moduleBase.Log(null, LogLevel.Critical, "", null, message, args);
}
public async Task LogCritical(Exception exception, string message, params object[] args)
{
- await modulebase.Log(LogLevel.Critical, exception, message, args);
+ await _moduleBase.Log(null, LogLevel.Critical, "", exception, message, args);
}
}
}
diff --git a/Oqtane.Client/Modules/Weather/Index.razor b/Oqtane.Client/Modules/Weather/Index.razor
deleted file mode 100644
index 88e346f8..00000000
--- a/Oqtane.Client/Modules/Weather/Index.razor
+++ /dev/null
@@ -1,42 +0,0 @@
-@using Oqtane.Modules.Weather.Services
-@namespace Oqtane.Modules.Weather
-@inherits ModuleBase
-
-@if (forecasts == null)
-{
- Loading...
-}
-else
-{
-
-
-
- Date
- Temp. (C)
- Temp. (F)
- Summary
-
-
-
- @foreach (var forecast in forecasts)
- {
-
- @forecast.Date.ToShortDateString()
- @forecast.TemperatureC
- @forecast.TemperatureF
- @forecast.Summary
-
- }
-
-
-}
-
-@code {
- WeatherForecast[] forecasts;
-
- protected override async Task OnInitializedAsync()
- {
- WeatherForecastService forecastservice = new WeatherForecastService();
- forecasts = await forecastservice.GetForecastAsync(DateTime.Now);
- }
-}
\ No newline at end of file
diff --git a/Oqtane.Client/Modules/Weather/Models/WeatherForecast.cs b/Oqtane.Client/Modules/Weather/Models/WeatherForecast.cs
deleted file mode 100644
index 7e02ea8a..00000000
--- a/Oqtane.Client/Modules/Weather/Models/WeatherForecast.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using System;
-
-namespace Oqtane.Modules.Weather
-{
- public class WeatherForecast
- {
- public DateTime Date { get; set; }
- public int TemperatureC { get; set; }
- public int TemperatureF { get; set; }
- public string Summary { get; set; }
- }
-}
diff --git a/Oqtane.Client/Modules/Weather/Module.cs b/Oqtane.Client/Modules/Weather/Module.cs
deleted file mode 100644
index 65d719d8..00000000
--- a/Oqtane.Client/Modules/Weather/Module.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using System.Collections.Generic;
-
-namespace Oqtane.Modules.Weather
-{
- public class Module : IModule
- {
- public Dictionary Properties
- {
- get
- {
- Dictionary properties = new Dictionary
- {
- { "Name", "Weather" },
- { "Description", "Displays random weather using a service" },
- { "Version", "1.0.0" }
- };
- return properties;
- }
- }
- }
-}
diff --git a/Oqtane.Client/Modules/Weather/Services/IWeatherForecastService.cs b/Oqtane.Client/Modules/Weather/Services/IWeatherForecastService.cs
deleted file mode 100644
index 743848fb..00000000
--- a/Oqtane.Client/Modules/Weather/Services/IWeatherForecastService.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-using System;
-using System.Threading.Tasks;
-
-namespace Oqtane.Modules.Weather.Services
-{
- public interface IWeatherForecastService
- {
- Task GetForecastAsync(DateTime startDate);
- }
-}
diff --git a/Oqtane.Client/Modules/Weather/Services/WeatherForecastService.cs b/Oqtane.Client/Modules/Weather/Services/WeatherForecastService.cs
deleted file mode 100644
index e6ad13d9..00000000
--- a/Oqtane.Client/Modules/Weather/Services/WeatherForecastService.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-using Oqtane.Modules;
-using System;
-using System.Linq;
-using System.Threading.Tasks;
-
-namespace Oqtane.Modules.Weather.Services
-{
- public class WeatherForecastService : IWeatherForecastService
- {
- private static string[] Summaries = new[]
- {
- "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
- };
-
- public Task