Merge pull request #1339 from sbwalker/dev
added DatabaseService to get list of database types from server
This commit is contained in:
commit
0bd6fea476
@ -1,11 +1,10 @@
|
||||
@namespace Oqtane.Installer
|
||||
@using Oqtane.Interfaces
|
||||
@using Oqtane.Installer.Controls
|
||||
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IInstallationService InstallationService
|
||||
@inject ISiteService SiteService
|
||||
@inject IUserService UserService
|
||||
@inject IDatabaseService DatabaseService
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject IStringLocalizer<Installer> Localizer
|
||||
|
||||
@ -28,10 +27,13 @@
|
||||
</td>
|
||||
<td>
|
||||
<select class="custom-select" value="@_databaseName" @onchange="(e => DatabaseChanged(e))">
|
||||
@foreach (var database in _databases)
|
||||
@if (_databases != null)
|
||||
{
|
||||
foreach (var database in _databases)
|
||||
{
|
||||
<option value="@database.Name">@Localizer[@database.FriendlyName]</option>
|
||||
}
|
||||
}
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
@ -95,7 +97,7 @@
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private IList<Database> _databases;
|
||||
private List<Database> _databases;
|
||||
private string _databaseName = "LocalDB";
|
||||
private Type _databaseConfigType;
|
||||
private object _databaseConfig;
|
||||
@ -108,44 +110,9 @@
|
||||
private string _message = string.Empty;
|
||||
private string _loadingDisplay = "display: none;";
|
||||
|
||||
protected override void OnInitialized()
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
base.OnInitialized();
|
||||
|
||||
_databases = new List<Database>
|
||||
{
|
||||
new()
|
||||
{
|
||||
Name = "LocalDB",
|
||||
FriendlyName = "Local Database",
|
||||
Type = "Oqtane.Installer.Controls.LocalDBConfig, Oqtane.Client"
|
||||
},
|
||||
new()
|
||||
{
|
||||
Name = "SqlServer",
|
||||
FriendlyName = "SQL Server",
|
||||
Type = "Oqtane.Installer.Controls.SqlServerConfig, Oqtane.Client"
|
||||
},
|
||||
new()
|
||||
{
|
||||
Name = "Sqlite",
|
||||
FriendlyName = "Sqlite",
|
||||
Type = "Oqtane.Installer.Controls.SqliteConfig, Oqtane.Client"
|
||||
},
|
||||
new()
|
||||
{
|
||||
Name = "MySQL",
|
||||
FriendlyName = "MySQL",
|
||||
Type = "Oqtane.Installer.Controls.MySQLConfig, Oqtane.Client"
|
||||
},
|
||||
new()
|
||||
{
|
||||
Name = "PostgreSQL",
|
||||
FriendlyName = "PostgreSQL",
|
||||
Type = "Oqtane.Installer.Controls.PostgreSQLConfig, Oqtane.Client"
|
||||
}
|
||||
};
|
||||
|
||||
_databases = await DatabaseService.GetDatabasesAsync();
|
||||
LoadDatabaseConfigComponent();
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
@inject ISiteTemplateService SiteTemplateService
|
||||
@inject IUserService UserService
|
||||
@inject IInstallationService InstallationService
|
||||
@inject IDatabaseService DatabaseService
|
||||
@inject IStringLocalizer<Add> Localizer
|
||||
@inject IEnumerable<IOqtaneDatabase> Databases
|
||||
|
||||
@ -162,7 +163,7 @@ else
|
||||
}
|
||||
|
||||
@code {
|
||||
private IList<Database> _databases;
|
||||
private List<Database> _databases;
|
||||
private string _databaseName = "LocalDB";
|
||||
private Type _databaseConfigType;
|
||||
private object _databaseConfig;
|
||||
@ -197,41 +198,7 @@ else
|
||||
_themeList = await ThemeService.GetThemesAsync();
|
||||
_themes = ThemeService.GetThemeControls(_themeList);
|
||||
_siteTemplates = await SiteTemplateService.GetSiteTemplatesAsync();
|
||||
|
||||
_databases = new List<Database>
|
||||
{
|
||||
new()
|
||||
{
|
||||
Name = "LocalDB",
|
||||
FriendlyName = "Local Database",
|
||||
Type = "Oqtane.Installer.Controls.LocalDBConfig, Oqtane.Client"
|
||||
},
|
||||
new()
|
||||
{
|
||||
Name = "SqlServer",
|
||||
FriendlyName = "SQL Server",
|
||||
Type = "Oqtane.Installer.Controls.SqlServerConfig, Oqtane.Client"
|
||||
},
|
||||
new()
|
||||
{
|
||||
Name = "Sqlite",
|
||||
FriendlyName = "Sqlite",
|
||||
Type = "Oqtane.Installer.Controls.SqliteConfig, Oqtane.Client"
|
||||
},
|
||||
new()
|
||||
{
|
||||
Name = "MySQL",
|
||||
FriendlyName = "MySQL",
|
||||
Type = "Oqtane.Installer.Controls.MySQLConfig, Oqtane.Client"
|
||||
},
|
||||
new()
|
||||
{
|
||||
Name = "PostgreSQL",
|
||||
FriendlyName = "PostgreSQL",
|
||||
Type = "Oqtane.Installer.Controls.PostGreSQLConfig, Oqtane.Client"
|
||||
}
|
||||
};
|
||||
|
||||
_databases = await DatabaseService.GetDatabasesAsync();
|
||||
LoadDatabaseConfigComponent();
|
||||
}
|
||||
|
||||
|
28
Oqtane.Client/Services/DatabaseService.cs
Normal file
28
Oqtane.Client/Services/DatabaseService.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using Oqtane.Models;
|
||||
using System.Threading.Tasks;
|
||||
using System.Net.Http;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Services
|
||||
{
|
||||
public class DatabaseService : ServiceBase, IDatabaseService
|
||||
{
|
||||
|
||||
private readonly SiteState _siteState;
|
||||
|
||||
public DatabaseService(HttpClient http, SiteState siteState) : base(http)
|
||||
{
|
||||
_siteState = siteState;
|
||||
}
|
||||
|
||||
private string Apiurl => CreateApiUrl("Database", _siteState.Alias);
|
||||
|
||||
public async Task<List<Database>> GetDatabasesAsync()
|
||||
{
|
||||
List<Database> databases = await GetJsonAsync<List<Database>>(Apiurl);
|
||||
return databases.OrderBy(item => item.FriendlyName).ToList();
|
||||
}
|
||||
}
|
||||
}
|
11
Oqtane.Client/Services/Interfaces/IDatabaseService.cs
Normal file
11
Oqtane.Client/Services/Interfaces/IDatabaseService.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using Oqtane.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Oqtane.Services
|
||||
{
|
||||
public interface IDatabaseService
|
||||
{
|
||||
Task<List<Database>> GetDatabasesAsync();
|
||||
}
|
||||
}
|
52
Oqtane.Server/Controllers/DatabaseController.cs
Normal file
52
Oqtane.Server/Controllers/DatabaseController.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class DatabaseController : Controller
|
||||
{
|
||||
public DatabaseController() { }
|
||||
|
||||
// GET: api/<controller>
|
||||
[HttpGet]
|
||||
public IEnumerable<Models.Database> Get()
|
||||
{
|
||||
var databases = new List<Models.Database>
|
||||
{
|
||||
new()
|
||||
{
|
||||
Name = "LocalDB",
|
||||
FriendlyName = "Local Database",
|
||||
Type = "Oqtane.Installer.Controls.LocalDBConfig, Oqtane.Client"
|
||||
},
|
||||
new()
|
||||
{
|
||||
Name = "SqlServer",
|
||||
FriendlyName = "SQL Server",
|
||||
Type = "Oqtane.Installer.Controls.SqlServerConfig, Oqtane.Client"
|
||||
},
|
||||
new()
|
||||
{
|
||||
Name = "Sqlite",
|
||||
FriendlyName = "Sqlite",
|
||||
Type = "Oqtane.Installer.Controls.SqliteConfig, Oqtane.Client"
|
||||
},
|
||||
new()
|
||||
{
|
||||
Name = "MySQL",
|
||||
FriendlyName = "MySQL",
|
||||
Type = "Oqtane.Installer.Controls.MySQLConfig, Oqtane.Client"
|
||||
},
|
||||
new()
|
||||
{
|
||||
Name = "PostgreSQL",
|
||||
FriendlyName = "PostgreSQL",
|
||||
Type = "Oqtane.Installer.Controls.PostGreSQLConfig, Oqtane.Client"
|
||||
}
|
||||
};
|
||||
return databases;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
@ -10,7 +9,6 @@ using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
@ -126,6 +124,7 @@ namespace Oqtane
|
||||
services.AddScoped<ISystemService, SystemService>();
|
||||
services.AddScoped<ILocalizationService, LocalizationService>();
|
||||
services.AddScoped<ILanguageService, LanguageService>();
|
||||
services.AddScoped<IDatabaseService, DatabaseService>();
|
||||
|
||||
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user