Skip to content

Commit cffd854

Browse files
committed
Quick notes replaced with quick draft.
1 parent 4fd8125 commit cffd854

4 files changed

Lines changed: 67 additions & 105 deletions

File tree

BlogEngine/BlogEngine.Core/Data/PostRepository.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public bool Remove(Guid id)
144144
static void Save(Post post, PostDetail detail)
145145
{
146146
post.Title = detail.Title;
147-
post.Author = detail.Author;
147+
post.Author = string.IsNullOrEmpty(detail.Author) ? Security.CurrentUser.Identity.Name : detail.Author;
148148
post.Description = GetDescription(detail.Description, detail.Content);
149149
post.Content = detail.Content;
150150
post.IsPublished = detail.IsPublished;
@@ -165,6 +165,10 @@ static void Save(Post post, PostDetail detail)
165165
static void UpdatePostCategories(Post post, List<CategoryItem> categories)
166166
{
167167
post.Categories.Clear();
168+
169+
if (categories == null)
170+
return;
171+
168172
foreach (var cat in categories)
169173
{
170174
// add if category does not exist
@@ -185,6 +189,10 @@ static void UpdatePostCategories(Post post, List<CategoryItem> categories)
185189
static void UpdatePostTags(Post post, List<TagItem> tags)
186190
{
187191
post.Tags.Clear();
192+
193+
if (tags == null)
194+
return;
195+
188196
foreach (var t in tags)
189197
{
190198
post.Tags.Add(t.TagName);
@@ -194,6 +202,10 @@ static void UpdatePostTags(Post post, List<TagItem> tags)
194202
static List<TagItem> FilterTags(List<TagItem> tags)
195203
{
196204
var uniqueTags = new List<TagItem>();
205+
206+
if (tags == null)
207+
return uniqueTags;
208+
197209
foreach (var t in tags)
198210
{
199211
if (!uniqueTags.Any(u => u.TagName == t.TagName))

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.2.9")]
22+
[assembly: AssemblyVersion("3.1.3.0")]
2323
[assembly: SecurityRules(SecurityRuleSet.Level1)]

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

Lines changed: 43 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,44 @@
22
$scope.vm = {};
33
$scope.itemToPurge = {};
44
$scope.security = $rootScope.security;
5-
$scope.pager = {};
6-
$scope.pager.items = [];
7-
$scope.pagerCurrentPage = 0;
85
$scope.focusInput = false;
6+
$scope.qd = angular.copy(newDraft);
7+
8+
$scope.postDraft = function () {
9+
var draft = {
10+
"Id": "",
11+
"Title": $scope.qd.title,
12+
"Author": "",
13+
"Content": $scope.qd.text,
14+
"DateCreated": moment().format("YYYY-MM-DD HH:mm"),
15+
"Slug": "",
16+
"Categories": "",
17+
"Tags": "",
18+
"Comments": "",
19+
"HasCommentsEnabled": true,
20+
"IsPublished": false
21+
}
22+
dataService.addItem('api/posts', draft)
23+
.success(function (data) {
24+
$scope.qd = angular.copy(newDraft);
25+
var dft = {
26+
"IsChecked": false,
27+
"Id": data.Id,
28+
"Title": data.Title,
29+
"Author": data.Author,
30+
"DateCreated": data.DateCreated,
31+
"Slug": data.Slug,
32+
"RelativeLink": data.RelativeLink,
33+
"Categories": null,
34+
"Tags": null,
35+
"Comments": null,
36+
"IsPublished": false
37+
};
38+
$scope.vm.DraftPosts.push(dft);
39+
toastr.success($rootScope.lbl.postAdded);
40+
})
41+
.error(function () { toastr.error($rootScope.lbl.failedAddingNewPost); });
42+
}
943

1044
$scope.openLogFile = function () {
1145
$("#modal-log-file").modal();
@@ -84,12 +118,9 @@
84118
dataService.getItems('/api/dashboard')
85119
.success(function (data) {
86120
angular.copy(data, $scope.vm);
87-
$scope.pager.items = $scope.vm.Notes;
88-
listPagerInit($scope.pager);
89121
})
90122
.error(function (data) { toastr.success($rootScope.lbl.errorGettingStats); });
91123
}
92-
93124
$scope.loadPackages = function () {
94125
if (!$scope.security.showTabCustom) {
95126
return;
@@ -108,7 +139,6 @@
108139
toastr.error($rootScope.lbl.errorLoadingPackages);
109140
});
110141
}
111-
112142
$scope.checkNewVersion = function () {
113143
if (!$scope.security.showTabCustom) {
114144
return;
@@ -129,87 +159,10 @@
129159
}
130160

131161
$scope.load();
162+
}]);
132163

133-
$scope.noteId = '';
134-
$scope.notePage = 1;
135-
$scope.addNote = function () {
136-
$scope.noteId = '';
137-
$("#txtAddNote").val('');
138-
$("#modal-add-note").modal();
139-
$scope.focusInput = true;
140-
}
141-
$scope.editNote = function (id) {
142-
$scope.noteId = id;
143-
var note = findInArray($scope.pager.items, 'Id', id);
144-
$("#txtEditNote").val(note.Note);
145-
$("#modal-edit-note").modal();
146-
$scope.focusInput = true;
147-
}
148-
$scope.deleteNote = function (id) {
149-
var note = { 'Id': id };
150-
dataService.deleteItem("/api/quicknotes/", note)
151-
.success(function (data) {
152-
toastr.success($rootScope.lbl.completed);
153-
$scope.load();
154-
$("#modal-edit-note").modal('hide');
155-
})
156-
.error(function () {
157-
toastr.error($rootScope.lbl.failed);
158-
$("#modal-edit-note").modal('hide');
159-
});
160-
}
161-
saveNote = function () {
162-
if ($scope.noteId === '') {
163-
$scope.addNewNote();
164-
}
165-
else {
166-
$scope.updateNote();
167-
}
168-
$scope.focusInput = false;
169-
}
170-
$scope.addNewNote = function () {
171-
if ($("#txtAddNote").val().length < 1) {
172-
toastr.error($rootScope.lbl.isRequiredField);
173-
return false;
174-
}
175-
var note = { 'Id': '', 'Note': $("#txtAddNote").val() };
176-
dataService.addItem("/api/quicknotes/add", note)
177-
.success(function (data) {
178-
toastr.success($rootScope.lbl.completed);
179-
$scope.load();
180-
$("#modal-add-note").modal('hide');
181-
})
182-
.error(function () {
183-
toastr.error($rootScope.lbl.failed);
184-
$("#modal-add-note").modal('hide');
185-
});
186-
}
187-
$scope.updateNote = function () {
188-
if ($("#txtEditNote").val().length < 1) {
189-
toastr.error($rootScope.lbl.isRequiredField);
190-
return false;
191-
}
192-
var note = { 'Id': $scope.noteId, 'Note': $("#txtEditNote").val() };
193-
dataService.updateItem("/api/quicknotes/" + $scope.noteId, note)
194-
.success(function (data) {
195-
toastr.success($rootScope.lbl.completed);
196-
$scope.load();
197-
$("#modal-edit-note").modal('hide');
198-
})
199-
.error(function () {
200-
toastr.error($rootScope.lbl.failed);
201-
$("#modal-edit-note").modal('hide');
202-
});
203-
}
204-
$scope.notePrevPage = function () {
205-
if ($scope.notePage > 1) {
206-
$scope.notePage--;
207-
}
208-
alert($scope.notePage);
209-
}
210-
$scope.noteNextPage = function () {
211-
$scope.notePage++;
212-
alert($scope.notePage);
213-
}
214-
215-
}]);
164+
var newDraft = {
165+
show: UserVars.Rights.indexOf("CreateNewPosts") > 0,
166+
title: "",
167+
text: ""
168+
}

BlogEngine/BlogEngine.NET/admin/views/dashboard.html

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,22 @@ <h4 class="modal-title">{{lbl.logFile}}</h4>
6262
</div>
6363
</div>
6464
<div class="col-md-4">
65-
<div class="panel panel-default">
65+
<div ng-if="qd.show" class="panel panel-default">
6666
<div class="panel-heading">
6767
<div class="panel-title">
68-
Quick Notes
69-
<span class="pull-right">
70-
<a href="" ng-if="pager.currentPage != 0" data-ng-click="pager.prevPage()"><i class="fa fa-angle-left fa-sm"></i></a>
71-
<a href="" ng-if="pager.currentPage + 1 < pager.pagedItems.length" data-ng-click="pager.nextPage()"><i class="fa fa-angle-right"></i></a>&nbsp;
72-
<a title="{{lbl.add}}" href="" ng-click="addNote()"><i class="fa fa-plus fa-sm"></i></a>
73-
</span>
68+
Quick Draft
7469
</div>
7570
</div>
7671
<ul class="list-group list-group panel-collapse collaps in" id="collapseFour">
77-
<li class="list-group-item clearfix" data-ng-repeat="note in pager.pagedItems[pager.currentPage]">
78-
<a title="{{note.Title}}" href="" ng-click="editNote(note.Id)">{{note.Title}}</a>
79-
<span class="pull-right">
80-
<a title="{{lbl.doDelete}}" href="" ng-click="deleteNote(note.Id)" class="purgethis"><i class="fa fa-times fa-sm"></i></a>
81-
</span>
72+
<li class="list-group-item clearfix">
73+
<input ng-model="qd.title" type="text" placeholder="Title" class="form-control" id="txtDraftTitle" name="txtDraftTitle" />
74+
<textarea ng-model="qd.text" placeholder="Type here..." style="margin-top: 5px" class="form-control ltr-dir" rows="2" id="txtDraftText" name="txtDraftText"></textarea>
75+
</li>
76+
<li class="list-group-item clearfix">
77+
<button type="button" ng-click="postDraft()" ng-disabled="qd.title.length == 0 || qd.text.length == 0" class="btn btn-success btn-sm" title="{{lbl.publish}}">
78+
{{lbl.save}}
79+
</button>
8280
</li>
83-
<li ng-if="pager.pagedItems.length == 0" class="list-group-item item-empty">{{lbl.empty}}</li>
8481
</ul>
8582
</div>
8683
<div class="panel panel-default">

0 commit comments

Comments
 (0)