Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event log pagination #45

Merged
13 commits merged into from Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DeployClient/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.9.1.0")]
[assembly: AssemblyFileVersion("0.9.1.0")]
[assembly: AssemblyVersion("0.9.2.0")]
[assembly: AssemblyFileVersion("0.9.2.0")]
2 changes: 1 addition & 1 deletion DeployClient/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "deploy-client",
"version": "0.9.1",
"version": "0.9.2",
"main": "gulpfile.js",
"license": "Apache-2.0",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion DeployClient/project.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
MODULE_VERSION: '00.09.01'
MODULE_VERSION: '00.09.02'
};
46 changes: 15 additions & 31 deletions PolyDeploy/Clients/Manage/src/css/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,25 @@
}

.can-pagination {
position: relative;
height: 20px;
text-align: center;

.prev, .next {
position: absolute;
height: 100%;
width: 20px;
top: 0;
text-align: center;
line-height: 30px;
cursor: pointer;
}

.prev {
left: 0;
}
ul {
li {
user-select: none;

.next {
right: 0;
a {
cursor: pointer;
width: 45px;
}
}
}
}

.pages {
list-style: none;
margin: 0 20px;
text-align: center;

li {
display: inline-block;
line-height: 20px;
padding: 0 5px;
margin: 0 5px;
cursor: pointer;

&.current {
font-weight: bold;
table {
&.table {
tr {
&.critical {
background-color: #f77e7e;
}
}
}
Expand Down
77 changes: 74 additions & 3 deletions PolyDeploy/Clients/Manage/src/js/controllers/EventsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Defaults.
var options = {
pageIndex: 0,
pageSize: 10,
pageSize: 20,
eventType: undefined,
severity: undefined
};
Expand Down Expand Up @@ -96,8 +96,79 @@
}

// Get array for pagination.
function getPages(number) {
return new Array(number);
function getPages(pageCount, currentPage) {

// Check there are pages to paginate.
if (pageCount < 1) {
return [1];
}

// Number of selectable pages to show at any given time. This should
// be an odd number so the current page can be centralised.
var pageOptionCount = 9;

// This is the number of selectable pages that appear on either side
// of the current page. It's derived from the pageOptionCount.
var bufferSize = (pageOptionCount - 1) / 2;

// Initialise array.
var numArray = [];

// Work out what the bounds will be.
var lowPage = 0;
var highPage = 0;

if (pageCount < pageOptionCount) {

lowPage = 1;
highPage = pageCount;

} else {

lowPage = currentPage - bufferSize;
highPage = currentPage + bufferSize;

// Gone too low?
if (lowPage < 1) {

// How far?
highPage = highPage + Math.abs(lowPage) + 1;

lowPage = 1;
}

// Gone too high?
if (highPage > pageCount) {

// How far?
lowPage = lowPage - Math.abs(highPage - pageCount);

highPage = pageCount;
}
}

// Build array.
for (var i = lowPage; i <= highPage; i++) {
numArray.push(i);
}

// Clipping at the bottom?
if (numArray[0] !== 1) {

// Yes.
numArray[0] = 1;
numArray[1] = '...';
}

// Clipping at the top?
if (numArray[numArray.length - 1] !== pageCount) {

// Yes.
numArray[numArray.length - 1] = pageCount;
numArray[numArray.length - 2] = '...';
}

return numArray;
}

}];
41 changes: 28 additions & 13 deletions PolyDeploy/Clients/Manage/src/js/templates/events.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ <h3 class="panel-title">Event Logs</h3>
</tr>
</thead>
<tbody>
<tr ng-repeat="eventLog in eventLogs">
<tr ng-repeat="eventLog in eventLogs"
ng-class="{ warning: eventLog.Severity === 1, danger: eventLog.Severity === 2, critical: eventLog.Severity === 3 }">
<td>{{ eventLog.Date }}</td>
<td>{{ eventLog.EventType }}</td>
<td>{{ eventLog.Message }}</td>
Expand All @@ -28,18 +29,32 @@ <h3 class="panel-title">Event Logs</h3>
</table>

<!-- Pagination -->
<div class="can-pagination">
<span class="prev"
ng-click="prevPage()"
ng-disable="hasPrevPage()"><</span>
<ul class="pages">
<li ng-repeat="i in getPages(pageCount) track by $index"
ng-click="loadPage($index+1)"
ng-class="{ current: $index+1 === currentPage }">{{ $index+1 }}</li>
</ul>
<span class="next"
ng-click="nextPage()"
ng-disable="hasNextPage()">></span>
<div class="row">
<div class="col-xs-12">
<nav class="can-pagination">
<ul class="pagination pagination-sm">
<li>
<a ng-click="prevPage()"
ng-class="{ disabled: hasPrevPage() }">
<span>&laquo;</span>
</a>
</li>
<li ng-repeat="i in getPages(pageCount, currentPage) track by $index"
ng-click="loadPage(i)"
ng-class="{ active: i === currentPage }">
<a ng-click="loadPage(i)">
{{ i }}
</a>
</li>
<li>
<a ng-click="nextPage()"
ng-class="{ disabled: hasNextPage() }">
<span>&raquo;</span>
</a>
</li>
</ul>
</nav>
</div>
</div>
<!-- /Pagination -->
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,54 +39,31 @@ public IEnumerable<EventLog> Get()

public IEnumerable<EventLog> Browse(int pageIndex, int pageSize, string eventType, EventLogSeverity? severity)
{
Dictionary<string, object> conditions = new Dictionary<string, dynamic>();

if (eventType != null)
{
conditions.Add("EventType", eventType.ToUpper());
}

if (severity != null)
using (IDataContext context = DataContext.Instance())
{
conditions.Add("Severity", severity);
return context.ExecuteQuery<EventLog>(
System.Data.CommandType.StoredProcedure,
"{databaseOwner}[{objectQualifier}Cantarus_PolyDeploy_GetEventLogsPage]",
pageIndex,
pageSize,
eventType,
severity
);
}
}

public int BrowseCount(int pageIndex, int pageSize, string eventType, EventLogSeverity? severity)
{
using (IDataContext context = DataContext.Instance())
{
var repo = context.GetRepository<EventLog>();

string sqlQuery = "";
object[] sqlParams = new object[] { conditions.Values };

// Deal with conditions.
if (conditions.Count > 0)
{
int paramNo = 0;

foreach (KeyValuePair<string, object> kvp in conditions)
{
if (string.IsNullOrEmpty(sqlQuery))
{
sqlQuery = string.Format("WHERE {0} = @{1}", kvp.Key, paramNo);
}
else
{
sqlQuery = string.Format("{0} AND {1} = @{2}", sqlQuery, kvp.Key, paramNo);
}

paramNo++;
}
}

// Perform query.
if (!string.IsNullOrEmpty(sqlQuery))
{
return repo.Find(pageIndex, pageSize, sqlQuery, sqlParams);
}
else
{
return repo.GetPage(pageIndex, pageSize);
}
return context.ExecuteQuery<int>(
System.Data.CommandType.StoredProcedure,
"{databaseOwner}[{objectQualifier}Cantarus_PolyDeploy_GetEventLogsPageTotal]",
pageIndex,
pageSize,
eventType,
severity
).FirstOrDefault();
}
}

Expand Down
5 changes: 5 additions & 0 deletions PolyDeploy/Components/Logging/EventLogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public static IEnumerable<EventLog> Browse(int pageIndex, int pageSize, string e
return LogDC.Browse(pageIndex, pageSize, eventType, severity);
}

public static int BrowseCount(int pageIndex, int pageSize, string eventType, EventLogSeverity? severity)
{
return LogDC.BrowseCount(pageIndex, pageSize, eventType, severity);
}

public static IEnumerable<string> GetEventTypes()
{
return LogDC.GetEventTypes();
Expand Down
6 changes: 3 additions & 3 deletions PolyDeploy/Components/WebAPI/EventLogController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public HttpResponseMessage Browse(int pageIndex = 0, int pageSize = 30, string e
}

// Get event logs.
List<EventLog> eventLogs = EventLogManager.Browse(pageIndex, pageSize, eventType, actualSeverity).ToList();
IEnumerable<EventLog> eventLogs = EventLogManager.Browse(pageIndex, pageSize, eventType, actualSeverity);

// Work out pagination details.
int rowCount = EventLogManager.EventCount();
int pageCount = (int)Math.Ceiling((double)(rowCount / pageSize));
int rowCount = EventLogManager.BrowseCount(pageIndex, pageSize, eventType, actualSeverity);
int pageCount = (int)Math.Ceiling(rowCount / (double)pageSize);

// Start building meta.
Dictionary<string, dynamic> pagination = new Dictionary<string, dynamic>();
Expand Down
1 change: 1 addition & 0 deletions PolyDeploy/PolyDeploy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
<Content Include="SqlDataProviders\00.07.00.SqlDataProvider" />
<Content Include="SqlDataProviders\00.09.00.SqlDataProvider" />
<Content Include="SqlDataProviders\00.09.01.SqlDataProvider" />
<Content Include="SqlDataProviders\00.09.02.SqlDataProvider" />
</ItemGroup>
<ItemGroup>
<Content Include="Clients\Deploy\Deploy.ascx" />
Expand Down
9 changes: 8 additions & 1 deletion PolyDeploy/PolyDeploy.dnn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<dotnetnuke type="Package" version="5.0">
<packages>
<package name="Cantarus.PolyDeploy" type="Module" version="00.09.01">
<package name="Cantarus.PolyDeploy" type="Module" version="00.09.02">
<friendlyName>Cantarus PolyDeploy</friendlyName>
<description>Cantarus PolyDeploy module</description>
<iconFile>Images/polydeploy-logo-icon.png</iconFile>
Expand Down Expand Up @@ -140,6 +140,13 @@
<name>00.09.01.SqlDataProvider</name>
<version>00.09.01</version>
</script>

<!-- v0.9.2 -->
<script type="Install">
<path>SqlDataProviders</path>
<name>00.09.02.SqlDataProvider</name>
<version>00.09.02</version>
</script>

<!-- Uninstall -->
<script type="Uninstall">
Expand Down
2 changes: 1 addition & 1 deletion PolyDeploy/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:

[assembly: AssemblyVersion("00.09.01.*")]
[assembly: AssemblyVersion("00.09.02.*")]
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
Expand Down
Loading