Skip to content

Commit 1090299

Browse files
committed
Ability to save editor options in the post and page editors
1 parent dca4e3b commit 1090299

14 files changed

Lines changed: 157 additions & 16 deletions

File tree

BlogEngine/BlogEngine.Core/BlogEngine.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
<ItemGroup>
122122
<Compile Include="Data\Contracts\IDashboardRepository.cs" />
123123
<Compile Include="Data\DashboardRepository.cs" />
124+
<Compile Include="Data\Models\EditorOptions.cs" />
124125
<Compile Include="Data\Services\Json.cs" />
125126
<Compile Include="Data\ViewModels\CommentsVM.cs" />
126127
<Compile Include="Data\ViewModels\DashboardVM.cs" />

BlogEngine/BlogEngine.Core/BlogSettings.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,5 +1415,17 @@ public void Save()
14151415

14161416
#endregion
14171417

1418+
#region EditorOptions
1419+
1420+
public bool PostOptionsSlug { get; set; }
1421+
public bool PostOptionsDescription { get; set; }
1422+
public bool PostOptionsCustomFields { get; set; }
1423+
1424+
public bool PageOptionsSlug { get; set; }
1425+
public bool PageOptionsDescription { get; set; }
1426+
public bool PageOptionsCustomFields { get; set; }
1427+
1428+
#endregion
1429+
14181430
}
14191431
}

BlogEngine/BlogEngine.Core/Data/Contracts/ILookupsRepository.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using BlogEngine.Core.Data.Models;
2-
using System.Collections.Generic;
32

43
namespace BlogEngine.Core.Data.Contracts
54
{
@@ -13,5 +12,11 @@ public interface ILookupsRepository
1312
/// </summary>
1413
/// <returns>Lookups</returns>
1514
Lookups GetLookups();
15+
16+
/// <summary>
17+
/// Editor options
18+
/// </summary>
19+
/// <param name="options">Options</param>
20+
void SaveEditorOptions(EditorOptions options);
1621
}
1722
}

BlogEngine/BlogEngine.Core/Data/LookupsRepository.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public Lookups GetLookups()
3939

4040
LoadThemes();
4141

42+
LoadEditorOptions();
43+
4244
return lookups;
4345
}
4446

@@ -151,5 +153,45 @@ void LoadThemes()
151153
lookups.InstalledThemes = items;
152154
}
153155

156+
void LoadEditorOptions()
157+
{
158+
var bs = BlogSettings.Instance;
159+
160+
lookups.PostOptions = new EditorOptions {
161+
OptionType ="Post",
162+
ShowSlug = bs.PostOptionsSlug,
163+
ShowDescription = bs.PostOptionsDescription,
164+
ShowCustomFields = bs.PostOptionsCustomFields
165+
};
166+
167+
lookups.PageOptions = new EditorOptions {
168+
OptionType = "Page",
169+
ShowSlug = bs.PageOptionsSlug,
170+
ShowDescription = bs.PageOptionsDescription,
171+
ShowCustomFields = bs.PageOptionsCustomFields
172+
};
173+
}
174+
175+
/// <summary>
176+
/// Editor options
177+
/// </summary>
178+
/// <param name="options">Options</param>
179+
public void SaveEditorOptions(EditorOptions options)
180+
{
181+
var bs = BlogSettings.Instance;
182+
if (options.OptionType == "Post")
183+
{
184+
bs.PostOptionsSlug = options.ShowSlug;
185+
bs.PostOptionsDescription = options.ShowDescription;
186+
bs.PostOptionsCustomFields = options.ShowCustomFields;
187+
}
188+
if (options.OptionType == "Page")
189+
{
190+
bs.PageOptionsSlug = options.ShowSlug;
191+
bs.PageOptionsDescription = options.ShowDescription;
192+
bs.PageOptionsCustomFields = options.ShowCustomFields;
193+
}
194+
bs.Save();
195+
}
154196
}
155197
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
namespace BlogEngine.Core.Data.Models
2+
{
3+
/// <summary>
4+
/// Editor options
5+
/// </summary>
6+
public class EditorOptions
7+
{
8+
/// <summary>
9+
/// Option type
10+
/// </summary>
11+
public string OptionType { get; set; }
12+
/// <summary>
13+
/// Show slug
14+
/// </summary>
15+
public bool ShowSlug { get; set; }
16+
/// <summary>
17+
/// Show description
18+
/// </summary>
19+
public bool ShowDescription { get; set; }
20+
/// <summary>
21+
/// Show custom fields
22+
/// </summary>
23+
public bool ShowCustomFields { get; set; }
24+
}
25+
}

BlogEngine/BlogEngine.Core/Data/Models/Lookups.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,8 @@ public class Lookups
3131
/// List of installed themes
3232
/// </summary>
3333
public IEnumerable<SelectOption> InstalledThemes { get; set; }
34+
35+
public EditorOptions PostOptions { get; set; }
36+
public EditorOptions PageOptions { get; set; }
3437
}
3538
}

BlogEngine/BlogEngine.Core/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
[assembly: CLSCompliant(false)]
2020
[assembly: ComVisible(false)]
2121
[assembly: AllowPartiallyTrustedCallers]
22-
[assembly: AssemblyVersion("3.1.3.5")]
22+
[assembly: AssemblyVersion("3.1.3.6")]
2323
[assembly: SecurityRules(SecurityRuleSet.Level1)]

BlogEngine/BlogEngine.NET/AppCode/Api/LookupsController.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,23 @@ public Lookups Get()
1717
{
1818
return repository.GetLookups();
1919
}
20+
21+
[HttpPut]
22+
public bool Update([FromBody]EditorOptions item)
23+
{
24+
try
25+
{
26+
repository.SaveEditorOptions(item);
27+
return true;
28+
}
29+
catch (UnauthorizedAccessException)
30+
{
31+
throw new HttpResponseException(HttpStatusCode.Unauthorized);
32+
}
33+
catch (Exception ex)
34+
{
35+
BlogEngine.Core.Utils.Log("Error updating", ex);
36+
throw new HttpResponseException(HttpStatusCode.InternalServerError);
37+
}
38+
}
2039
}

BlogEngine/BlogEngine.NET/Custom/Widgets/TextBox/edit.ascx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
"insertdatetime media table contextmenu paste sh4tinymce"
1212
],
1313
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | sh4tinymce",
14+
menubar: false,
15+
relative_urls: false,
16+
browser_spellcheck: true,
1417
autosave_ask_before_unload: false,
1518
max_height: 300,
1619
min_height: 160,

BlogEngine/BlogEngine.NET/admin/app/controllers/pageEditor.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,16 @@
166166
}
167167
}
168168

169+
$scope.saveEditOptions = function () {
170+
dataService.updateItem('api/lookups/update/foo', $scope.lookups.PageOptions)
171+
.success(function (data) {
172+
toastr.success($rootScope.lbl.pageUpdated);
173+
$("#myModal").modal('hide');
174+
spinOff();
175+
})
176+
.error(function () { toastr.error($rootScope.lbl.updateFailed); });
177+
}
178+
169179
/* custom fields */
170180

171181
$scope.showCustom = function () {

0 commit comments

Comments
 (0)