Skip to content

Commit 21088f8

Browse files
committed
fix init cms
1 parent 4dc5b92 commit 21088f8

File tree

16 files changed

+62
-23
lines changed

16 files changed

+62
-23
lines changed

src/Swastika.Cms.Lib/SWCmsConstants.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public class SWCmsConstants
1717

1818
public const string CONST_DEFAULT_CONNECTION = "CmsConnection";
1919

20+
public const string CONST_FILE_CONFIGURATIONS = "configurations-en.json";
21+
public const string CONST_FILE_LANGUAGES = "languages-en.json";
22+
2023
/// The constant path home access denied
2124
/// </summary>
2225
public const string CONST_PATH_HOME_ACCESS_DENIED = "/home/access-denied";

src/Swastika.Cms.Lib/Services/GlobalConfigurationService.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
using Microsoft.EntityFrameworkCore;
77
using Microsoft.EntityFrameworkCore.Storage;
88
using Microsoft.Extensions.Configuration;
9+
using Newtonsoft.Json.Linq;
910
using Swastika.Cms.Lib.Models.Account;
1011
using Swastika.Cms.Lib.Models.Cms;
1112
using Swastika.Cms.Lib.Repositories;
1213
using Swastika.Cms.Lib.ViewModels;
1314
using Swastika.Cms.Lib.ViewModels.Api;
1415
using Swastika.Cms.Lib.ViewModels.BackEnd;
16+
using Swastika.Cms.Lib.ViewModels.Info;
1517
using Swastika.Common.Helper;
1618
using Swastika.Domain.Core.ViewModels;
1719
using Swastika.Identity.Models;
@@ -75,7 +77,8 @@ public async Task<RepositoryResponse<bool>> InitSWCms(InitCulture culture)
7577

7678
isSucceed = isSucceed && InitThemes(context, transaction);
7779

78-
isSucceed = isSucceed && InitConfigurations(culture, context, transaction);
80+
isSucceed = isSucceed && await InitConfigurationsAsync(culture, context, transaction);
81+
isSucceed = isSucceed && await InitLanguagesAsync(culture, context, transaction);
7982
}
8083
else
8184
{
@@ -344,6 +347,27 @@ public int GetLocalInt(string key, string culture, int defaultValue = 0)
344347
{
345348
return this.CmsConfigurations.GetLocalInt(key, culture, defaultValue);
346349
}
350+
private async Task<bool> InitConfigurationsAsync(InitCulture culture, SiocCmsContext context, IDbContextTransaction transaction)
351+
{
352+
/* Init Configs */
353+
var configurations = FileRepository.Instance.GetFile("configurations-en", ".json", "data", true, "{}");
354+
355+
var obj = JObject.Parse(configurations.Content);
356+
var arrConfiguration = obj["data"].ToObject<List<SiocConfiguration>>();
357+
var result = await InfoConfigurationViewModel.ImportConfigurations(arrConfiguration, culture.Specificulture, context, transaction);
358+
return result.IsSucceed;
359+
360+
}
347361

362+
private async Task<bool> InitLanguagesAsync(InitCulture culture, SiocCmsContext context, IDbContextTransaction transaction)
363+
{
364+
/* Init Languages */
365+
var languages = FileRepository.Instance.GetFile("languages-en", ".json", "data", true, "{}");
366+
var obj = JObject.Parse(languages.Content);
367+
var arrLanguage = obj["data"].ToObject<List<SiocLanguage>>();
368+
var result = await InfoLanguageViewModel.ImportLanguages(arrLanguage, culture.Specificulture, context, transaction);
369+
return result.IsSucceed;
370+
371+
}
348372
}
349373
}

src/Swastika.Cms.Lib/ViewModels/Api/ApiTemplateViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public ApiTemplateViewModel(SiocTemplate model, SiocCmsContext _context = null,
127127

128128
public override void ExpandView(SiocCmsContext _context = null, IDbContextTransaction _transaction = null)
129129
{
130-
var file = FileRepository.Instance.GetFile(FileName, Extension, FileFolder);
130+
var file = FileRepository.Instance.GetFile(FileName, Extension, FileFolder, false, string.Empty);
131131
if (!string.IsNullOrWhiteSpace(file?.Content))
132132
{
133133
Content = file.Content;

src/Swastika.Cms.Lib/ViewModels/BackEnd/BETemplateViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public BETemplateViewModel(SiocTemplate model, SiocCmsContext _context = null, I
127127

128128
public override void ExpandView(SiocCmsContext _context = null, IDbContextTransaction _transaction = null)
129129
{
130-
var file = FileRepository.Instance.GetFile(FileName, Extension, FileFolder);
130+
var file = FileRepository.Instance.GetFile(FileName, Extension, FileFolder, false, string.Empty);
131131
if (!string.IsNullOrWhiteSpace(file?.Content))
132132
{
133133
Content = file.Content;

src/Swastika.Cms.Lib/ViewModels/Info/InfoConfigurationViewModel.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,12 @@ public override void ExpandView(SiocCmsContext _context = null, IDbContextTransa
7272

7373
#region Expands
7474

75-
public static async Task<RepositoryResponse<bool>> ImportConfigurations(List<SiocConfiguration> arrConfiguration, string destCulture)
75+
public static async Task<RepositoryResponse<bool>> ImportConfigurations(List<SiocConfiguration> arrConfiguration, string destCulture, SiocCmsContext _context = null, IDbContextTransaction _transaction = null)
7676
{
7777
var result = new RepositoryResponse<bool>() { IsSucceed = true };
78-
var context = new SiocCmsContext();
79-
var transaction = context.Database.BeginTransaction();
78+
bool isRoot = _context == null;
79+
var context = _context ?? new SiocCmsContext();
80+
var transaction = _transaction ?? context.Database.BeginTransaction();
8081

8182
try
8283
{
@@ -93,19 +94,22 @@ public static async Task<RepositoryResponse<bool>> ImportConfigurations(List<Sio
9394
break;
9495
}
9596
}
96-
UnitOfWorkHelper<SiocCmsContext>.HandleTransaction(result.IsSucceed, true, transaction);
97+
UnitOfWorkHelper<SiocCmsContext>.HandleTransaction(result.IsSucceed, isRoot, transaction);
9798
}
9899
catch (Exception ex) // TODO: Add more specific exeption types instead of Exception only
99100
{
100-
var error = UnitOfWorkHelper<SiocCmsContext>.HandleException<InfoConfigurationViewModel>(ex, true, transaction);
101+
var error = UnitOfWorkHelper<SiocCmsContext>.HandleException<InfoConfigurationViewModel>(ex, isRoot, transaction);
101102
result.IsSucceed = false;
102103
result.Errors = error.Errors;
103104
result.Exception = error.Exception;
104105
}
105106
finally
106107
{
107108
//if current Context is Root
108-
context?.Dispose();
109+
if (isRoot)
110+
{
111+
context?.Dispose();
112+
}
109113
}
110114
return result;
111115
}

src/Swastika.Cms.Lib/ViewModels/Info/InfoLanguageViewModel.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,12 @@ public override async Task<RepositoryResponse<bool>> RemoveRelatedModelsAsync(In
100100

101101
#region Expands
102102

103-
public static async Task<RepositoryResponse<bool>> ImportLanguages(List<SiocLanguage> arrLanguage, string destCulture)
103+
public static async Task<RepositoryResponse<bool>> ImportLanguages(List<SiocLanguage> arrLanguage, string destCulture, SiocCmsContext _context = null, IDbContextTransaction _transaction = null)
104104
{
105105
var result = new RepositoryResponse<bool>() { IsSucceed = true };
106-
var context = new SiocCmsContext();
107-
var transaction = context.Database.BeginTransaction();
106+
bool isRoot = _context == null;
107+
var context = _context ?? new SiocCmsContext();
108+
var transaction = _transaction ?? context.Database.BeginTransaction();
108109

109110
try
110111
{
@@ -121,19 +122,21 @@ public static async Task<RepositoryResponse<bool>> ImportLanguages(List<SiocLang
121122
break;
122123
}
123124
}
124-
UnitOfWorkHelper<SiocCmsContext>.HandleTransaction(result.IsSucceed, true, transaction);
125+
UnitOfWorkHelper<SiocCmsContext>.HandleTransaction(result.IsSucceed, isRoot, transaction);
125126
}
126127
catch (Exception ex) // TODO: Add more specific exeption types instead of Exception only
127128
{
128-
var error = UnitOfWorkHelper<SiocCmsContext>.HandleException<InfoLanguageViewModel>(ex, true, transaction);
129+
var error = UnitOfWorkHelper<SiocCmsContext>.HandleException<InfoLanguageViewModel>(ex, isRoot, transaction);
129130
result.IsSucceed = false;
130131
result.Errors = error.Errors;
131132
result.Exception = error.Exception;
132133
}
133134
finally
134135
{
135-
//if current Context is Root
136-
context?.Dispose();
136+
if (isRoot)
137+
{
138+
context?.Dispose();
139+
}
137140
}
138141
return result;
139142
}

src/Swastika.Cms.Web.Mvc/Swastika.Cms.Web.Mvc.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@
230230
<Content Remove="Areas\Portal\Views\Shared\Widgets\_FeatureImage.cshtml" />
231231
<Content Remove="Areas\Portal\Views\Shared\Widgets\_ThumbnailImage.cshtml" />
232232
<Content Remove="Areas\Portal\Views\Shared\_Layout.cshtml" />
233-
<Content Remove="data\configuration-en.json" />
233+
<Content Remove="data\configurations-en.json" />
234234
<Content Remove="data\lang-en.json" />
235235
<Content Remove="Views\Home\About.cshtml" />
236236
<Content Remove="Views\Home\Article.cshtml" />
@@ -328,7 +328,7 @@
328328
<None Include="Areas\Portal\Views\_ViewImports.cshtml" />
329329
<None Include="Areas\Portal\Views\_ViewStart.cshtml" />
330330
<None Include="data\lang-en.json" />
331-
<None Include="data\configuration-en.json" />
331+
<None Include="data\configurations-en.json" />
332332
<None Include="Views\_ViewImports.cshtml" />
333333
<None Include="Views\_ViewStart.cshtml" />
334334
<None Include="wwwroot\app-portal\pages\order\components\main\main.js" />

src/Swastika.Cms.Web.Mvc/app/app-portal/pages/page/list.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<section>
22
<filter-list request="request" callback="loadPages(pageIndex)"></filter-list>
3+
{{request.}}
34
<sw-data-table ng-init="loadPages()" data="data" can-drag="request.orderBy == 'Priority' && request.direction == '0'" edit-url="'/backend/page/details'"
45
columns="columns" child-name="'childs'" on-delete="removePage(id)" on-update-infos="updateInfos(items)"></sw-data-table>
56
<paging class="small" page="data.page" page-size="data.pageSize" total="data.totalItems" ul-class="pagination justify-content-end"

src/Swastika.Cms.Web.Mvc/app/app-shared/components/data-table/data-table.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.header{
1+
.sw-datatable .header{
22
padding: 10px;
33
font-weight: 700;
44
background: lightgray;

src/Swastika.Cms.Web.Mvc/app/app-shared/components/data-table/data-table.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
</div>
44
<div ng-if="$ctrl.data.items" ng-init="$ctrl.init()">
55
<div class="nav">
6-
<div class="col-sm-12 p-2">
6+
<div class="col-sm-12 p-2 sw-datatable">
77
<div class="row header">
88
<div class="col-1">
99
<span class="fas fa-sort"></span>

0 commit comments

Comments
 (0)