Skip to content

Commit 4fd8125

Browse files
committed
More work making dashboard lighter and faster with fewer API calls
1 parent 513ebcf commit 4fd8125

3 files changed

Lines changed: 37 additions & 69 deletions

File tree

BlogEngine/BlogEngine.Core/Data/ViewModels/DashboardVM.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private void LoadPosts()
125125
{
126126
var posts = Post.ApplicablePosts.Where(p => p.IsVisible);
127127
DraftPosts = new List<PostItem>();
128-
foreach (var p in posts.Where(p => p.IsPublished == false).ToList())
128+
foreach (var p in posts.Where(p => p.IsPublished == false && p.IsDeleted == false).ToList())
129129
{
130130
DraftPosts.Add(Json.GetPost(p));
131131
}
@@ -145,7 +145,7 @@ private void LoadPages()
145145
{
146146
var pages = Page.Pages.Where(p => p.IsVisible);
147147
DraftPages = new List<PageItem>();
148-
foreach (var p in pages.Where(p => p.IsPublished == false).ToList())
148+
foreach (var p in pages.Where(p => p.IsPublished == false && p.IsDeleted == false).ToList())
149149
{
150150
DraftPages.Add(Json.GetPage(p));
151151
}
@@ -155,7 +155,7 @@ private void LoadPages()
155155

156156
private void LoadTrash()
157157
{
158-
var posts = Post.ApplicablePosts.Where(p => p.IsDeleted);
158+
var posts = Post.DeletedPosts;
159159
_trash = new List<TrashItem>();
160160
if (posts.Count() > 0)
161161
{
@@ -172,7 +172,7 @@ private void LoadTrash()
172172
);
173173
}
174174
}
175-
var pages = Page.Pages.Where(p => p.IsDeleted);
175+
var pages = Page.DeletedPages;
176176
if (pages.Count() > 0)
177177
{
178178
foreach (var page in pages)
@@ -205,6 +205,7 @@ private void LoadTrash()
205205
);
206206
}
207207
}
208+
Trash = _trash;
208209
}
209210

210211
IEnumerable<SelectOption> GetLogFile()

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

Lines changed: 22 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
angular.module('blogAdmin').controller('DashboardController', ["$rootScope", "$scope", "$location", "$log", "$filter", "dataService", function ($rootScope, $scope, $location, $log, $filter, dataService) {
22
$scope.vm = {};
3-
$scope.trash = [];
4-
$scope.logItems = [];
53
$scope.itemToPurge = {};
64
$scope.security = $rootScope.security;
75
$scope.pager = {};
@@ -10,21 +8,13 @@
108
$scope.focusInput = false;
119

1210
$scope.openLogFile = function () {
13-
dataService.getItems('/api/logs/getlog/file')
14-
.success(function (data) {
15-
angular.copy(data, $scope.logItems);
16-
$("#modal-log-file").modal();
17-
return false;
18-
})
19-
.error(function (data) {
20-
toastr.error($rootScope.lbl.errorGettingLogFile);
21-
});
11+
$("#modal-log-file").modal();
12+
return false;
2213
}
23-
2414
$scope.purgeLog = function () {
2515
dataService.updateItem('/api/logs/purgelog/file', $scope.itemToPurge)
2616
.success(function (data) {
27-
$scope.logItems = [];
17+
$scope.vm.Logs = [];
2818
$("#modal-log-file").modal('hide');
2919
toastr.success($rootScope.lbl.purged);
3020
return false;
@@ -36,38 +26,44 @@
3626

3727
$scope.purge = function (id) {
3828
if (id) {
39-
$scope.itemToPurge = findInArray($scope.trash.Items, "Id", id);
29+
$scope.itemToPurge = findInArray($scope.vm.Trash, "Id", id);
4030
}
4131
dataService.updateItem('/api/trash/purge/' + id, $scope.itemToPurge)
4232
.success(function (data) {
43-
$scope.loadTrash();
33+
for (var i = 0; i < $scope.vm.Trash.length; i++)
34+
if ($scope.vm.Trash[i].Id === id) {
35+
$scope.vm.Trash.splice(i, 1);
36+
break;
37+
}
4438
toastr.success($rootScope.lbl.purged);
4539
return false;
4640
})
4741
.error(function (data) {
4842
toastr.error($rootScope.lbl.errorPurging);
4943
});
5044
}
51-
5245
$scope.purgeAll = function () {
5346
dataService.updateItem('/api/trash/purgeall/all')
5447
.success(function (data) {
55-
$scope.loadTrash();
48+
$scope.vm.Trash = [];
5649
toastr.success($rootScope.lbl.purged);
5750
return false;
5851
})
5952
.error(function (data) {
6053
toastr.error($rootScope.lbl.errorPurging);
6154
});
6255
}
63-
6456
$scope.restore = function (id) {
6557
if (id) {
66-
$scope.itemToPurge = findInArray($scope.trash.Items, "Id", id);
58+
$scope.itemToPurge = findInArray($scope.vm.Trash, "Id", id);
6759
}
6860
dataService.updateItem('/api/trash/restore/' + id, $scope.itemToPurge)
6961
.success(function (data) {
70-
$scope.loadTrash();
62+
for (var i = 0; i < $scope.vm.Trash.length; i++)
63+
if ($scope.vm.Trash[i].Id === id) {
64+
$scope.vm.Trash.splice(i, 1);
65+
break;
66+
}
7167
toastr.success($rootScope.lbl.restored);
7268
return false;
7369
})
@@ -86,28 +82,12 @@
8682
$scope.loadPackages();
8783

8884
dataService.getItems('/api/dashboard')
89-
.success(function (data) { angular.copy(data, $scope.vm); })
90-
.error(function (data) { toastr.success($rootScope.lbl.errorGettingStats); });
91-
92-
dataService.getItems('/api/logs/getlog/file')
93-
.success(function (data) {
94-
angular.copy(data, $scope.logItems);
95-
if ($scope.logItems.length > 0) { $('#tr-log-spinner').hide(); }
96-
else { $('#div-log-spinner').html($rootScope.lbl.empty); }
97-
})
98-
.error(function (data) { toastr.error($rootScope.lbl.errorGettingLogFile); });
99-
100-
$scope.loadTrash();
101-
$scope.loadNotes();
102-
}
103-
104-
$scope.loadNotes = function () {
105-
dataService.getItems('/api/quicknotes', { type: 0, take: 5, skip: 0 })
106-
.success(function (data) {
107-
angular.copy(data, $scope.pager.items);
108-
listPagerInit($scope.pager);
109-
})
110-
.error(function () { toastr.error($rootScope.lbl.errorLoadingTrash); });
85+
.success(function (data) {
86+
angular.copy(data, $scope.vm);
87+
$scope.pager.items = $scope.vm.Notes;
88+
listPagerInit($scope.pager);
89+
})
90+
.error(function (data) { toastr.success($rootScope.lbl.errorGettingStats); });
11191
}
11292

11393
$scope.loadPackages = function () {
@@ -148,16 +128,6 @@
148128
});
149129
}
150130

151-
$scope.loadTrash = function () {
152-
dataService.getItems('/api/trash', { type: 0, take: 5, skip: 0 })
153-
.success(function (data) { angular.copy(data, $scope.trash); })
154-
.error(function () { toastr.error($rootScope.lbl.errorLoadingTrash); });
155-
}
156-
157-
$(document).ready(function () {
158-
159-
});
160-
161131
$scope.load();
162132

163133
$scope.noteId = '';

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ <h4 class="modal-title">{{lbl.logFile}}</h4>
1313
</div>
1414
<div class="modal-body modal-logfile">
1515
<div class="form-horizontal clearfix">
16-
<div class="col col-md-12" data-ng-repeat="log in logItems">
16+
<div class="col col-md-12" data-ng-repeat="log in vm.Logs">
1717
<div ng-bind-html="log.OptionValue"></div>
1818
<hr />
1919
</div>
2020
</div>
2121
</div>
2222
<div class="modal-footer">
2323
<button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-ban"></i> {{lbl.close}}</button>
24-
<button data-ng-if="logItems.length > 0" data-ng-click="purgeLog()" class="btn btn-danger"><i class="fa fa-times"></i> {{lbl.purge}}</button>
24+
<button type="button" data-ng-if="vm.Logs.length > 0" data-ng-click="purgeLog()" class="btn btn-danger"><i class="fa fa-times"></i> {{lbl.purge}}</button>
2525
</div>
2626
</div>
2727
</div>
@@ -89,7 +89,7 @@ <h4 class="modal-title">{{lbl.logFile}}</h4>
8989
</div>
9090
<ul class="list-group list-group panel-collapse collaps in" id="collapseThree">
9191
<li class="list-group-item clearfix" data-ng-repeat="post in vm.DraftPosts">
92-
<a href="{{SiteVars.RelativeWebRoot}}admin/editor/post.cshtml?id={{post.Id}}&returnUrl={{SiteVars.RelativeWebRoot}}admin/#/" class="text-ellipsis pull-left">{{post.Title}}</a>
92+
<a href="{{SiteVars.RelativeWebRoot}}admin/editpost.cshtml?id={{post.Id}}&returnUrl={{SiteVars.RelativeWebRoot}}admin/#/" class="text-ellipsis pull-left">{{post.Title}}</a>
9393
<a title="{{post.Title}}" class="external-link pull-right" target="_new" href="{{post.RelativeLink}}"><i class="fa fa-external-link"></i></a>
9494
</li>
9595
<li ng-if="vm.DraftPosts.length == 0" class="list-group-item item-empty">{{lbl.empty}}</li>
@@ -101,13 +101,12 @@ <h4 class="modal-title">{{lbl.logFile}}</h4>
101101
</div>
102102
<ul class="list-group list-group panel-collapse collaps in" id="collapseFour">
103103
<li class="list-group-item clearfix" data-ng-repeat="page in vm.DraftPages">
104-
<a href="{{SiteVars.RelativeWebRoot}}admin/editor/page.cshtml?id={{page.Id}}&returnUrl={{SiteVars.RelativeWebRoot}}admin/#/" class="text-ellipsis pull-left">{{page.Title}}</a>
104+
<a href="{{SiteVars.RelativeWebRoot}}admin/editpage.cshtml?id={{page.Id}}&returnUrl={{SiteVars.RelativeWebRoot}}admin/#/" class="text-ellipsis pull-left">{{page.Title}}</a>
105105
<a title="{{page.Title}}" class="external-link pull-right" target="_new" href="{{SiteVars.RelativeWebRoot}}page/{{page.Slug}}"><i class="fa fa-external-link"></i></a>
106106
</li>
107107
<li ng-if="vm.DraftPages.length == 0" class="list-group-item item-empty">{{lbl.empty}}</li>
108108
</ul>
109109
</div>
110-
111110
</div>
112111
<div class="col-md-4">
113112
<div class="panel panel-default" data-ng-if="security.showTabCustom">
@@ -135,33 +134,31 @@ <h4 class="modal-title">{{lbl.logFile}}</h4>
135134
<div class="panel-title">{{lbl.logs}}</div>
136135
</div>
137136
<ul class="list-group list-group panel-collapse collaps in" id="collapseSeven">
138-
<li data-ng-if="logItems.length > 0" class="list-group-item">
137+
<li data-ng-if="vm.Logs.length > 0" class="list-group-item">
139138
<a href="" data-ng-click="openLogFile()">{{lbl.loggedMessages}}</a>
140139
</li>
141-
<li class="list-group-item item-empty clearfix" id="tr-log-spinner">
142-
<div id="div-log-spinner"><i class="fa fa-spinner fa-spin"></i></div>
143-
</li>
140+
<li ng-if="vm.Logs.length == 0" class="list-group-item item-empty">{{lbl.empty}}</li>
144141
</ul>
145142
</div>
146143
<div class="panel panel-default">
147144
<div class="panel-heading">
148145
<div class="panel-title">
149146
{{lbl.trash}}
150-
<small ng-if="trash.TotalCount > 0">({{trash.TotalCount}})</small>
151-
<span ng-if="trash.TotalCount > 0" class="pull-right">
147+
<small ng-if="vm.Trash.length > 0">({{vm.Trash.length}})</small>
148+
<span ng-if="vm.Trash.length > 0" class="pull-right">
152149
<span class="purgeall label label-danger" data-ng-click="purgeAll()"><i class="fa fa-times"></i> {{lbl.purgeAll}}</span>
153150
</span>
154151
</div>
155152
</div>
156153
<ul class="list-group list-group panel-collapse collaps in" id="collapseFive">
157-
<li class="list-group-item clearfix" data-ng-repeat="t in trash.Items">
154+
<li class="list-group-item clearfix" data-ng-repeat="t in vm.Trash">
158155
<a href="{{t.RelativeUrl}}" class="text-ellipsis pull-left">{{t.Title}}</a>
159156
<span class="pull-right">
160157
<a title="{{lbl.restore}}" href="" data-ng-click="restore(t.Id)" class="restorethis"><i class="fa fa-refresh fa-sm"></i></a>
161158
<a title="{{lbl.purge}}" href="" data-ng-click="purge(t.Id)" class="purgethis"><i class="fa fa-times fa-sm"></i></a>
162159
</span>
163160
</li>
164-
<li ng-if="trash.TotalCount == 0" class="list-group-item item-empty">{{lbl.empty}}</li>
161+
<li ng-if="vm.Trash.length == 0" class="list-group-item item-empty">{{lbl.empty}}</li>
165162
</ul>
166163
</div>
167164

0 commit comments

Comments
 (0)