Skip to content

Commit

Permalink
Show connectionString hint for all data providers (OrchardCMS#3484)
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamco authored and sebastienros committed Jul 25, 2019
1 parent fd88d80 commit 6bc6148
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/OrchardCore.Modules/OrchardCore.Setup/Assets/js/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ function toggleConnectionStringAndPrefix() {
$(this).data("connection-string").toLowerCase() === "true"
? $(".pwd").attr('required', 'required')
: $(".pwd").removeAttr('required');

$("#connectionStringHint").text($(this).data("connection-string-sample"));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
<select asp-for="DatabaseProvider" class="form-control" required>
@foreach (var provider in Model.DatabaseProviders)
{
<option value="@provider.Value" data-connection-string="@provider.HasConnectionString" data-table-prefix="@provider.HasTablePrefix">@provider.Name</option>
<option value="@provider.Value" data-connection-string="@provider.HasConnectionString" data-table-prefix="@provider.HasTablePrefix" data-connection-string-sample="@T["The connection string to your database instance. e.g., {0}", provider.SampleConnectionString]">@provider.Name</option>
}
</select>
<span asp-validation-for="DatabaseProvider" class="text-danger"></span>
Expand All @@ -173,7 +173,7 @@
</div>

<span asp-validation-for="ConnectionString" class="text-danger"></span>
<span class="text-muted form-text small">@T["The connection string to your database instance. e.g., Data Source=<em>localhost</em>;Initial Catalog=<em>Orchard</em>;User Id=<em>userid</em>;Password=<em>password</em>"]</span>
<span id="connectionStringHint" class="text-muted form-text small"></span>
</div>
</fieldset>
}
Expand Down Expand Up @@ -217,7 +217,6 @@
</form>
<script src="~/OrchardCore.Setup/Scripts/setup.min.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
$(function(){
$('#Password').strength({
minLength: @(options.Password.RequiredLength),
Expand Down Expand Up @@ -246,5 +245,4 @@
}
});
})
//]]>
</script>

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<option value="" data-connection-string="false">@T["None"]</option>
@foreach (var provider in DatabaseProviders)
{
<option value="@provider.Value" data-connection-string="@provider.HasConnectionString.ToString().ToLower()" data-table-prefix="@provider.HasTablePrefix.ToString().ToLower()">@provider.Name</option>
<option value="@provider.Value" data-connection-string="@provider.HasConnectionString.ToString().ToLower()" data-table-prefix="@provider.HasTablePrefix.ToString().ToLower()" data-connection-string-sample="@T["The connection string to your database instance. e.g., {0}", provider.SampleConnectionString]">@provider.Name</option>
}
</select>
</div>
Expand All @@ -74,7 +74,7 @@
<label asp-for="ConnectionString">@T["Connection string"]</label>
<input asp-for="ConnectionString" class="form-control" />
<span asp-validation-for="ConnectionString" class="text-danger"></span>
<span class="text-muted form-text small">@T["The connection string to your database instance. e.g., Data Source=<em>localhost</em>;Initial Catalog=<em>Orchard</em>;User Id=<em>userid</em>;Password=<em>password</em>"]</span>
<span id="connectionStringHint" class="text-muted form-text small"></span>
</div>
</fieldset>

Expand All @@ -86,4 +86,4 @@
</fieldset>
</form>

<script at="Foot" type="text/javascript" asp-src="~/OrchardCore.Tenants/Scripts/tenant.js" depends-on="jquery"></script>
<script at="Foot" type="text/javascript" asp-src="~/OrchardCore.Tenants/Scripts/tenant.js" depends-on="jquery"></script>
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ function toggleConnectionStringAndPrefix() {
$(this).data("table-prefix") === true
? $(".tablePrefix").show()
: $(".tablePrefix").hide();

$("#connectionStringHint").text($(this).data("connection-string-sample"));
});
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ public class DatabaseProvider
public bool HasConnectionString { get; set; }
public bool HasTablePrefix { get; set; }
public bool IsDefault { get; set; }
public string SampleConnectionString { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace OrchardCore.Data
{
public static class ServiceCollectionExtensions
{
public static IServiceCollection TryAddDataProvider(this IServiceCollection services, string name, string value, bool hasConnectionString, bool hasTablePrefix, bool isDefault)
public static IServiceCollection TryAddDataProvider(this IServiceCollection services, string name, string value, bool hasConnectionString, bool hasTablePrefix, bool isDefault, string sampleConnectionString = "")
{
for (var i = services.Count - 1; i >= 0; i--)
{
Expand All @@ -20,7 +20,7 @@ public static IServiceCollection TryAddDataProvider(this IServiceCollection serv
}
}

services.AddSingleton(new DatabaseProvider { Name = name, Value = value, HasConnectionString = hasConnectionString, HasTablePrefix = hasTablePrefix , IsDefault = isDefault });
services.AddSingleton(new DatabaseProvider { Name = name, Value = value, HasConnectionString = hasConnectionString, HasTablePrefix = hasTablePrefix , IsDefault = isDefault, SampleConnectionString = sampleConnectionString });

return services;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public static OrchardCoreBuilder AddDataAccess(this OrchardCoreBuilder builder)
services.AddScoped<IModularTenantEvents, AutomaticDataMigrations>();

// Adding supported databases
services.TryAddDataProvider(name: "Sql Server", value: "SqlConnection", hasConnectionString: true, hasTablePrefix: true, isDefault: false);
services.TryAddDataProvider(name: "Sql Server", value: "SqlConnection", hasConnectionString: true, sampleConnectionString: "Server=localhost;Database=Orchard;User Id=username;Password=password", hasTablePrefix: true, isDefault: false);
services.TryAddDataProvider(name: "Sqlite", value: "Sqlite", hasConnectionString: false, hasTablePrefix: false, isDefault: true);
services.TryAddDataProvider(name: "MySql", value: "MySql", hasConnectionString: true, hasTablePrefix: true, isDefault: false);
services.TryAddDataProvider(name: "Postgres", value: "Postgres", hasConnectionString: true, hasTablePrefix: true, isDefault: false);
services.TryAddDataProvider(name: "MySql", value: "MySql", hasConnectionString: true, sampleConnectionString: "Server=localhost;Database=Orchard;Uid=username;Pwd=password", hasTablePrefix: true, isDefault: false);
services.TryAddDataProvider(name: "Postgres", value: "Postgres", hasConnectionString: true, sampleConnectionString: "Server=localhost;Port=5432;Database=Orchard;User Id=username;Password=password", hasTablePrefix: true, isDefault: false);

// Configuring data access

Expand Down

0 comments on commit 6bc6148

Please sign in to comment.