Merge pull request #28 from sbwalker/master

add site admin, logo control, port number
This commit is contained in:
Shaun Walker 2019-06-14 17:28:51 -04:00 committed by GitHub
commit 976f76ea59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 105 additions and 18 deletions

View File

@ -170,7 +170,6 @@
p.ViewPermissions = viewpermissions; p.ViewPermissions = viewpermissions;
p.EditPermissions = editpermissions; p.EditPermissions = editpermissions;
await PageService.AddPageAsync(p); await PageService.AddPageAsync(p);
StateHasChanged();
UriHelper.NavigateTo(NavigateUrl(path, true)); UriHelper.NavigateTo(NavigateUrl(path, true));
} }
} }

View File

@ -2,12 +2,34 @@
@using Oqtane.Models @using Oqtane.Models
@using Oqtane.Services @using Oqtane.Services
@using Oqtane.Modules @using Oqtane.Modules
@using Oqtane.Client.Modules.Controls
@inherits ModuleBase @inherits ModuleBase
@inject IUriHelper UriHelper @inject IUriHelper UriHelper
@inject ITenantService TenantService
@inject IAliasService AliasService
@inject ISiteService SiteService @inject ISiteService SiteService
@inject IPageService PageService
@if (tenants == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="form-group"> <table class="form-group">
<tr>
<td>
<label for="Name" class="control-label">Tenant: </label>
</td>
<td>
<select class="form-control" bind="@tenantid">
<option value="">&lt;Select Tenant&gt;</option>
@foreach (Tenant tenant in tenants)
{
<option value="@tenant.TenantId">@tenant.Name</option>
}
</select>
</td>
</tr>
<tr> <tr>
<td> <td>
<label for="Name" class="control-label">Name: </label> <label for="Name" class="control-label">Name: </label>
@ -21,26 +43,69 @@
<label for="Name" class="control-label">Alias: </label> <label for="Name" class="control-label">Alias: </label>
</td> </td>
<td> <td>
<input class="form-control" bind="@alias" /> <input class="form-control" bind="@url" />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Logo: </label>
</td>
<td>
<input class="form-control" bind="@logo" />
</td> </td>
</tr> </tr>
</table> </table>
<button class="btn btn-success" onclick="@SaveSite">Save</button> <button class="btn btn-success" onclick="@SaveSite">Save</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink> <NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
}
@functions { @functions {
public override SecurityAccessLevelEnum SecurityAccessLevel { get { return SecurityAccessLevelEnum.Host; } } public override SecurityAccessLevelEnum SecurityAccessLevel { get { return SecurityAccessLevelEnum.Host; } }
List<Tenant> tenants;
string tenantid;
string name; string name;
string alias; string url;
string logo;
protected override async Task OnInitAsync()
{
tenants = await TenantService.GetTenantsAsync();
}
private async Task SaveSite() private async Task SaveSite()
{ {
Site site = new Site(); Site site = new Site();
site.Name = name; site.Name = name;
site.Logo = ""; site.Logo = (logo == null ? "" : logo);
await SiteService.AddSiteAsync(site); await SiteService.AddSiteAsync(site);
StateHasChanged(); List<Site> sites = await SiteService.GetSitesAsync();
UriHelper.NavigateTo(NavigateUrl()); site = sites.Where(item => item.Name == name).FirstOrDefault();
Alias alias = new Alias();
alias.Name = url;
alias.TenantId = int.Parse(tenantid);
alias.SiteId = site.SiteId;
await AliasService.AddAliasAsync(alias);
// need to add a home page and admin pages
Page p = new Page();
p.SiteId = site.SiteId;
p.ParentId = null;
p.Name = "Home";
p.Path = "";
p.Order = 1;
p.IsNavigation = true;
p.ThemeType = "Oqtane.Client.Themes.Theme1.Theme1, Oqtane.Client";
p.LayoutType = "";
p.Icon = "";
Type type = Type.GetType(p.ThemeType);
System.Reflection.PropertyInfo property = type.GetProperty("Panes");
p.Panes = (string)property.GetValue(Activator.CreateInstance(type), null);
p.ViewPermissions = "All Users";
p.EditPermissions = "Administrators";
await PageService.AddPageAsync(p);
UriHelper.NavigateTo(url, true);
} }
} }

View File

@ -1,10 +1,13 @@
using Oqtane.Models; using Oqtane.Models;
using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Oqtane.Services namespace Oqtane.Services
{ {
public interface ITenantService public interface ITenantService
{ {
Task<List<Tenant>> GetTenantsAsync();
Task<Tenant> GetTenantAsync(); Task<Tenant> GetTenantAsync();
} }
} }

View File

@ -3,6 +3,8 @@ using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Oqtane.Shared; using Oqtane.Shared;
using System.Collections.Generic;
using System.Linq;
namespace Oqtane.Services namespace Oqtane.Services
{ {
@ -22,6 +24,12 @@ namespace Oqtane.Services
get { return CreateApiUrl(sitestate.Alias, "Tenant"); } get { return CreateApiUrl(sitestate.Alias, "Tenant"); }
} }
public async Task<List<Tenant>> GetTenantsAsync()
{
List<Tenant> tenants = await http.GetJsonAsync<List<Tenant>>(apiurl);
return tenants.OrderBy(item => item.Name).ToList();
}
public async Task<Tenant> GetTenantAsync() public async Task<Tenant> GetTenantAsync()
{ {
return await http.GetJsonAsync<Tenant>(apiurl); return await http.GetJsonAsync<Tenant>(apiurl);

View File

@ -10,8 +10,9 @@
protected PageState PageState { get; set; } protected PageState PageState { get; set; }
[Parameter] [Parameter]
private Module ModuleState { get; set; } private Module Module { get; set; }
Module ModuleState;
string container; string container;
RenderFragment DynamicComponent { get; set; } RenderFragment DynamicComponent { get; set; }
@ -35,6 +36,7 @@
protected override Task OnParametersSetAsync() protected override Task OnParametersSetAsync()
{ {
ModuleState = Module; // passed in from Pane component
container = ModuleState.ContainerType; container = ModuleState.ContainerType;
if (PageState.ModuleId != -1 && PageState.Control != "") if (PageState.ModuleId != -1 && PageState.Control != "")
{ {

View File

@ -84,7 +84,7 @@
} }
} }
builder.OpenComponent(0, Type.GetType(Constants.DefaultContainer)); builder.OpenComponent(0, Type.GetType(Constants.DefaultContainer));
builder.AddAttribute(1, "ModuleState", module); builder.AddAttribute(1, "Module", module);
builder.CloseComponent(); builder.CloseComponent();
} }
} }
@ -106,7 +106,7 @@
if (UserService.IsAuthorized(PageState.User, module.ViewPermissions)) if (UserService.IsAuthorized(PageState.User, module.ViewPermissions))
{ {
builder.OpenComponent(0, Type.GetType(Constants.DefaultContainer)); builder.OpenComponent(0, Type.GetType(Constants.DefaultContainer));
builder.AddAttribute(1, "ModuleState", module); builder.AddAttribute(1, "Module", module);
builder.CloseComponent(); builder.CloseComponent();
} }
} }
@ -119,7 +119,7 @@
if (UserService.IsAuthorized(PageState.User, module.ViewPermissions)) if (UserService.IsAuthorized(PageState.User, module.ViewPermissions))
{ {
builder.OpenComponent(0, Type.GetType(Constants.DefaultContainer)); builder.OpenComponent(0, Type.GetType(Constants.DefaultContainer));
builder.AddAttribute(1, "ModuleState", module); builder.AddAttribute(1, "Module", module);
builder.CloseComponent(); builder.CloseComponent();
} }
} }

View File

@ -234,7 +234,6 @@
{ {
// site does not exist // site does not exist
} }
StateHasChanged();
} }
private async void OnLocationChanged(object sender, string AbsoluteUri) private async void OnLocationChanged(object sender, string AbsoluteUri)

View File

@ -1,5 +1,16 @@
@using Oqtane.Themes @using Oqtane.Themes
@inherits ThemeObjectBase @inherits ThemeObjectBase
<a href="@PageState.Alias.Url"><img src="/Sites/@PageState.Site.SiteId/@PageState.Site.Logo" /></a> @((MarkupString)logo)
@functions {
string logo = "";
protected override void OnInit()
{
if (PageState.Site.Logo != "")
{
logo = "<a href=\"" + PageState.Alias.Url + "\"><img src=\"/Sites/" + PageState.Site.SiteId.ToString() + "/" + PageState.Site.Logo + "\" alt=\"" + PageState.Site.Name + "\"/></a>";
}
}
}

View File

@ -31,18 +31,18 @@ namespace Oqtane.Controllers
// POST api/<controller> // POST api/<controller>
[HttpPost] [HttpPost]
public void Post([FromBody] Alias site) public void Post([FromBody] Alias alias)
{ {
if (ModelState.IsValid) if (ModelState.IsValid)
aliases.AddAlias(site); aliases.AddAlias(alias);
} }
// PUT api/<controller>/5 // PUT api/<controller>/5
[HttpPut("{id}")] [HttpPut("{id}")]
public void Put(int id, [FromBody] Alias site) public void Put(int id, [FromBody] Alias alias)
{ {
if (ModelState.IsValid) if (ModelState.IsValid)
aliases.UpdateAlias(site); aliases.UpdateAlias(alias);
} }
// DELETE api/<controller>/5 // DELETE api/<controller>/5

View File

@ -21,7 +21,7 @@
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
}, },
"applicationUrl": "http://localhost:14245/" "applicationUrl": "http://localhost:44357/"
} }
} }
} }