Skip to content

Commit

Permalink
fixed paging buttons in federation search
Browse files Browse the repository at this point in the history
  • Loading branch information
rchadwic committed Feb 24, 2012
1 parent 996bb15 commit cb94913
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 24 deletions.
Binary file modified LearningRegistry/obj/Debug/LearningRegistry.dll
Binary file not shown.
Binary file modified LearningRegistry/obj/Debug/LearningRegistry.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion VwarWeb/App_Code/Security.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static bool IsAdministrator()
/// </summary>
public static void CreateRolesAndAdministrativeUser()
{
if (Website.Config.GenerateDefaultAdministratorOnApplicationStartup)
if (Website.Config.GenerateDefaultAdministratorOnApplicationStartup)
{
try
{
Expand Down
Binary file modified VwarWeb/Bin/LearningRegistry.dll
Binary file not shown.
4 changes: 2 additions & 2 deletions VwarWeb/Public/FederationResults.aspx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ limitations under the License.
</asp:DataList>
<asp:Label ID="NoneFoundLabel" runat="server" Visible="false" />
<div id="PagingControls">
<asp:LinkButton CssClass="previous-page-button" ID="PreviousPageButton" OnClick="PageNumberChanged" runat="server">Previous</asp:LinkButton>
<asp:LinkButton CssClass="previous-page-button" ID="PreviousPageButton" CommandArgument="Prev" OnClick="PageNumberChanged" runat="server">Previous</asp:LinkButton>
<div style="width: 300px; margin: 0 auto;">
<asp:Repeater ID="PageNumbersRepeater" runat="server">
<ItemTemplate>
Expand All @@ -139,7 +139,7 @@ limitations under the License.
</ItemTemplate>
</asp:Repeater>
</div>
<asp:LinkButton CssClass="next-page-button" ID="NextPageButton" OnClick="PageNumberChanged" runat="server">Next</asp:LinkButton>
<asp:LinkButton CssClass="next-page-button" ID="NextPageButton" CommandArgument="Next" OnClick="PageNumberChanged" runat="server">Next</asp:LinkButton>
</div>
</ContentTemplate>
</asp:UpdatePanel>
Expand Down
74 changes: 53 additions & 21 deletions VwarWeb/Public/FederationResults.aspx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ public partial class Public_Results : Website.Pages.PageBase
{
const int DEFAULT_RESULTS_PER_PAGE = 5;

private int _ResultsPerPage;
private int _ResultsPerPage = 6;
private int _PageNumber = 1;

private FederateRecordSet federates;
private List<SearchResult> SearchResults;
[Serializable]
class SearchResult
{
public string PID { get; set; }
Expand All @@ -33,33 +35,50 @@ class SearchResult
protected void Page_Load(object sender, EventArgs e)
{
SearchPanel.Visible = false;
_ResultsPerPage = 6;
if(!IsPostBack)
if (Request.QueryString["SearchTerms"] != "" && Request.QueryString["SearchTerms"] != null)


if (!IsPostBack)
{
if (Request.QueryString["SearchTerms"] != "" && Request.QueryString["SearchTerms"] != null)
{
ViewState["Federates"] = null;
ViewState["SearchResults"] = null;
SearchResults = null;
ApplySearchResults(GetSearchResults(Request.QueryString["SearchTerms"]));
SearchFederationTextBox.Text = Request.QueryString["SearchTerms"];
SearchResultsUpdatePanel.Visible = true;

}


}
else
{
ApplySearchResults(GetSearchResults(Request.QueryString["SearchTerms"]));
SearchFederationTextBox.Text = Request.QueryString["SearchTerms"];
SearchResultsUpdatePanel.Visible = true;
_ResultsPerPage = System.Convert.ToInt16(ResultsPerPageDropdown.SelectedValue);
}


}


private IEnumerable<SearchResult> GetSearchResults(string terms)
{
List<SearchResult> SearchResults = new List<SearchResult>();

if (ViewState["SearchResults"] == null)
{
SearchResults = new List<SearchResult>();

System.Net.WebClient wc = new System.Net.WebClient();
wc.Credentials = new System.Net.NetworkCredential("AnonymousUser", "");
string data = wc.DownloadString("http://3dr.adlnet.gov/Federation/3DR_Federation.svc/Search/"+terms+"/json?ID=00-00-00");
string data = wc.DownloadString("http://3dr.adlnet.gov/Federation/3DR_Federation.svc/Search/" + terms + "/json?ID=00-00-00");
SearchResults.Clear();
SearchResult[] results = (new JavaScriptSerializer()).Deserialize<SearchResult[]>(data);
foreach (SearchResult s in results)
{
SearchResults.Add(s);
}
return SearchResults;
ViewState["SearchResults"] = SearchResults;
}
return ViewState["SearchResults"] as List<SearchResult>;
}
protected void RefreshSearch(object sender, EventArgs args)
{
Expand All @@ -82,10 +101,18 @@ protected void SearchFederatonButton_Click(object sender, EventArgs args)
private void ApplySearchResults(IEnumerable<SearchResult> co)
{
List<SearchResult> results = new List<SearchResult>();
for (int i = (_PageNumber - 1) * System.Convert.ToInt16(ResultsPerPageDropdown.Text); i<co.Count() && i < (_PageNumber - 1) * System.Convert.ToInt16(ResultsPerPageDropdown.Text) + System.Convert.ToInt16(ResultsPerPageDropdown.Text); i++)
for (int i = (_PageNumber - 1) * _ResultsPerPage; i < co.Count() && i < (_PageNumber - 1) * _ResultsPerPage + _ResultsPerPage; i++)
{
co.ElementAt(i).OrganizationName = GetFederateInfo(PidToNamespace(co.ElementAt(i).PID)).OrginizationName;
co.ElementAt(i).OrganizationURL = GetFederateInfo(PidToNamespace(co.ElementAt(i).PID)).OrganizationURL;
try
{
co.ElementAt(i).OrganizationName = GetFederateInfo(PidToNamespace(co.ElementAt(i).PID)).OrginizationName;
co.ElementAt(i).OrganizationURL = GetFederateInfo(PidToNamespace(co.ElementAt(i).PID)).OrganizationURL;
}
catch (Exception e)
{
//it's possible that the federate info for a result is null. Should not happen, but totally possible if fedreates
//have PID's in their search results that are unregistered namespaces
}
results.Add(co.ElementAt(i));
}

Expand Down Expand Up @@ -132,14 +159,14 @@ public class FederateRecordSet
}
public FederateRecordSet GetFederateInfo()
{
if (ViewState["FederateRecordSet"] == null)
if (ViewState["Federates"] == null)
{
System.Net.WebClient wc = new System.Net.WebClient();
string federatedata = wc.UploadString("http://3dr.adlnet.gov/federation/3DR_Federation_Mgmt.svc/GetAllFederates", "POST", "");
FederateRecordSet federates = (new JavaScriptSerializer()).Deserialize<FederateRecordSet>(federatedata);
ViewState["FederateRecordSet"] = federates;
federates = (new JavaScriptSerializer()).Deserialize<FederateRecordSet>(federatedata);
ViewState["Federates"] = federates;
}
return ViewState["FederateRecordSet"] as FederateRecordSet;
return ViewState["Federates"] as FederateRecordSet;
}
public FederateRecord GetFederateInfo(string pid)
{
Expand Down Expand Up @@ -190,7 +217,12 @@ protected void PageNumberChanged(object sender, EventArgs e)
LinkButton btn = (LinkButton)sender;
if (btn.CommandArgument == "Next")
_PageNumber += 1;
_PageNumber = System.Convert.ToInt32(btn.CommandArgument);
else if (btn.CommandArgument == "Prev")
_PageNumber -= 1;
else
_PageNumber = System.Convert.ToInt32(btn.CommandArgument);

if (_PageNumber < 1) _PageNumber = 1;

IEnumerable<SearchResult> co = null;
if (Request.QueryString["SearchTerms"] != "")
Expand Down

0 comments on commit cb94913

Please sign in to comment.