Skip to content

Commit

Permalink
Use SC-generated paging links to page the audit message data
Browse files Browse the repository at this point in the history
Also solves #736
  • Loading branch information
SzymonPobiega committed Jul 11, 2017
1 parent 3a604e3 commit b4ede46
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 85 deletions.
2 changes: 1 addition & 1 deletion src/ServiceInsight.Tests/MessageListViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void TestInitialize()
public void Should_load_the_messages_from_the_endpoint()
{
var endpoint = new Endpoint { Host = "localhost", Name = "Service" };
serviceControl.GetAuditMessages(Arg.Is(endpoint), Arg.Any<string>(), Arg.Any<int>(), Arg.Any<string>(), Arg.Any<bool>())
serviceControl.GetAuditMessages(Arg.Is(endpoint), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<bool>())
.Returns(x => new PagedResult<StoredMessage>
{
CurrentPage = 1,
Expand Down
78 changes: 41 additions & 37 deletions src/ServiceInsight/MessageList/MessageListViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,28 +97,49 @@ public void CopyHeaders()
clipboard.CopyTo(generalHeaderDisplay.HeaderContent);
}

public void RefreshMessages(string orderBy = null, bool ascending = false)
public void RefreshMessages(string link, int pageIndex)
{
var serviceControlExplorerItem = selectedExplorerItem as ServiceControlExplorerItem;
if (serviceControlExplorerItem != null)
using (workNotifier.NotifyOfWork("Loading messages..."))
{
RefreshMessages(searchQuery: SearchBar.SearchQuery,
endpoint: null,
orderBy: orderBy,
ascending: ascending);
var pagedResult = serviceControl.GetAuditMessages(link);
if (pagedResult == null)
{
return;
}

pagedResult.CurrentPage = pageIndex;
TryRebindMessageList(pagedResult);

SearchBar.IsVisible = true;
SearchBar.SetupPaging(pagedResult.TotalCount > 0 ? pagedResult.CurrentPage : 0, pagedResult.TotalCount, pagedResult.PageSize, pagedResult.Result,
pagedResult.NextLink,
pagedResult.PrevLink,
pagedResult.FirstLink,
pagedResult.LastLink,
link);
}
}

public void RefreshMessages(string orderBy = null, bool ascending = false)
{
var endpointNode = selectedExplorerItem as AuditEndpointExplorerItem;
if (endpointNode != null)
{
RefreshMessages(searchQuery: SearchBar.SearchQuery,
InitSearch(searchQuery: SearchBar.SearchQuery,
endpoint: endpointNode.Endpoint,
orderBy: orderBy,
ascending: ascending);
}
else
{
InitSearch(searchQuery: SearchBar.SearchQuery,
endpoint: null,
orderBy: orderBy,
ascending: ascending);
}
}

public void RefreshMessages(Endpoint endpoint, int pageIndex = 1, string searchQuery = null, string orderBy = null, bool ascending = false)
public void InitSearch(Endpoint endpoint, string searchQuery = null, string orderBy = null, bool ascending = false)
{
using (workNotifier.NotifyOfWork($"Loading {(endpoint == null ? "all" : endpoint.Address)} messages..."))
{
Expand All @@ -130,28 +151,11 @@ public void RefreshMessages(Endpoint endpoint, int pageIndex = 1, string searchQ

PagedResult<StoredMessage> pagedResult;

if (endpoint != null)
{
pagedResult = serviceControl.GetAuditMessages(endpoint,
pageIndex: pageIndex,
searchQuery: searchQuery,
orderBy: lastSortColumn,
ascending: lastSortOrderAscending);
}
else if (!searchQuery.IsEmpty())
{
pagedResult = serviceControl.Search(pageIndex: pageIndex,
searchQuery: searchQuery,
orderBy: lastSortColumn,
ascending: lastSortOrderAscending);
}
else
{
pagedResult = serviceControl.Search(pageIndex: pageIndex,
searchQuery: null,
orderBy: lastSortColumn,
ascending: lastSortOrderAscending);
}
pagedResult = serviceControl.GetAuditMessages(
endpoint,
searchQuery,
lastSortColumn,
lastSortOrderAscending);

if (pagedResult == null)
{
Expand All @@ -161,12 +165,12 @@ public void RefreshMessages(Endpoint endpoint, int pageIndex = 1, string searchQ
TryRebindMessageList(pagedResult);

SearchBar.IsVisible = true;
SearchBar.SetupPaging(new PagedResult<StoredMessage>
{
CurrentPage = pagedResult.CurrentPage,
TotalCount = pagedResult.TotalCount,
Result = pagedResult.Result,
});
SearchBar.SetupPaging(pagedResult.TotalCount > 0 ? pagedResult.CurrentPage : 0, pagedResult.TotalCount, pagedResult.PageSize, pagedResult.Result,
pagedResult.NextLink,
pagedResult.PrevLink,
pagedResult.FirstLink,
pagedResult.LastLink,
null);
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/ServiceInsight/Models/PagedResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ public PagedResult()

public int TotalCount { get; set; }

public int PageSize { get; set; }

public int CurrentPage { get; set; }

public string FirstLink { get; set; }

public string LastLink { get; set; }

public string NextLink { get; set; }

public string PrevLink { get; set; }
}
}
61 changes: 41 additions & 20 deletions src/ServiceInsight/Search/SearchBarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public SearchBarViewModel(CommandLineArgParser commandLineArgParser, ISettingsPr
{
this.commandLineArgParser = commandLineArgParser;
this.settingProvider = settingProvider;
PageSize = 50; //NOTE: Do we need to change this?

SearchCommand = Command.Create(this, Search, vm => vm.CanSearch);
CancelSearchCommand = Command.Create(this, CancelSearch, vm => vm.CanCancelSearch);
Expand All @@ -52,22 +51,22 @@ protected override void OnActivate()

public void GoToFirstPage()
{
Parent.RefreshMessages(SelectedEndpoint, 1, SearchQuery);
Parent.RefreshMessages(FirstLink, 1);
}

public void GoToPreviousPage()
{
Parent.RefreshMessages(SelectedEndpoint, CurrentPage - 1, SearchQuery);
Parent.RefreshMessages(PrevLink, CurrentPage - 1);
}

public void GoToNextPage()
{
Parent.RefreshMessages(SelectedEndpoint, CurrentPage + 1, SearchQuery);
Parent.RefreshMessages(NextLink, CurrentPage + 1);
}

public void GoToLastPage()
{
Parent.RefreshMessages(SelectedEndpoint, PageCount, SearchQuery);
Parent.RefreshMessages(LastLink, PageCount);
}

public ICommand SearchCommand { get; }
Expand All @@ -91,22 +90,27 @@ public void Search()
{
SearchInProgress = true;
AddRecentSearchEntry(SearchQuery);
Parent.RefreshMessages(SelectedEndpoint, 1, SearchQuery);
Parent.InitSearch(SelectedEndpoint, SearchQuery);
}

public void CancelSearch()
{
SearchQuery = null;
SearchInProgress = false;
Parent.RefreshMessages(SelectedEndpoint, 1, SearchQuery);
Parent.InitSearch(SelectedEndpoint, SearchQuery);
}

public void SetupPaging(PagedResult<StoredMessage> pagedResult)
public void SetupPaging(int currentPage, int totalCount, int pageSize, IList<StoredMessage> messages, string nextLink, string prevLink, string firstLink, string lastLink, string selfLink)
{
Result = pagedResult.Result;
CurrentPage = pagedResult.TotalCount > 0 ? pagedResult.CurrentPage : 0;
TotalItemCount = pagedResult.TotalCount;

CurrentPage = currentPage;
TotalItemCount = totalCount;
Result = messages;
NextLink = nextLink;
PrevLink = prevLink;
FirstLink = firstLink;
LastLink = lastLink;
SelfLink = selfLink;
PageSize = pageSize;
NotifyPropertiesChanged();
}

Expand All @@ -122,11 +126,16 @@ public void ClearPaging()

public void RefreshResult()
{
Parent.RefreshMessages(SelectedEndpoint, CurrentPage, SearchQuery);
if (SelfLink != null)
{
Parent.RefreshMessages(SelfLink, CurrentPage);
}
else
{
Parent.InitSearch(SelectedEndpoint, SearchQuery);
}
}

public bool CanGoToLastPage => CurrentPage < PageCount && !WorkInProgress;

public bool CanCancelSearch => SearchInProgress;

public new MessageListViewModel Parent => base.Parent as MessageListViewModel;
Expand All @@ -135,7 +144,7 @@ public int PageCount
{
get
{
if (TotalItemCount == 0)
if (TotalItemCount == 0 || PageSize == 0)
{
return 0;
}
Expand All @@ -158,19 +167,31 @@ public int PageCount

public bool IsVisible { get; set; }

public bool CanGoToFirstPage => CurrentPage > 1 && !WorkInProgress;
public bool CanGoToFirstPage => FirstLink != null && !WorkInProgress;

public bool CanGoToPreviousPage => CurrentPage - 1 >= 1 && !WorkInProgress;
public bool CanGoToLastPage => LastLink != null && !WorkInProgress;

public bool CanGoToNextPage => CurrentPage + 1 <= PageCount && !WorkInProgress;
public bool CanGoToPreviousPage => PrevLink != null && !WorkInProgress;

public bool CanGoToNextPage => NextLink != null && !WorkInProgress;

public IList<StoredMessage> Result { get; private set; }

public IObservableCollection<string> RecentSearchQueries { get; private set; }

public int CurrentPage { get; private set; }

public int PageSize { get; }
public string NextLink { get; private set; }

public string PrevLink { get; private set; }

public string FirstLink { get; private set; }

public string LastLink { get; private set; }

public string SelfLink { get; private set; }

public int PageSize { get; private set; }

public int TotalItemCount { get; private set; }

Expand Down
Loading

0 comments on commit b4ede46

Please sign in to comment.