Skip to content

Commit

Permalink
DASH-97
Browse files Browse the repository at this point in the history
Fixed display of item counts associated with paging navigator and resize page after changes.


git-svn-id: https://source.sakaiproject.org/svn/dashboard/trunk@313011 66ffb92e-73f9-0310-93c1-f5514f145a0a
  • Loading branch information
jimeng committed Nov 11, 2011
1 parent 267cd2b commit 8f920e1
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 29 deletions.
9 changes: 9 additions & 0 deletions dashboard/bundles/resources/dash_entity.properties
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ dash.calendar.nopast = You have no past calendar items.
dash.calendar.nostarred = You have not starred any calendar items.
dash.calendar.nohidden = You have not hidden any calendar items.
dash.calendar.linksCount = {0} items
dash.calendar.linksCount0 = No items
dash.calendar.linksCount1 = Showing 1 item
dash.calendar.linksCount2 = Showing item {0} of {1} items
dash.calendar.linksCount3 = Showing {0} to {1} of {2} items

dash.news.current = Current Stuff
dash.news.starred = Starred
Expand All @@ -75,7 +79,12 @@ dash.news.hidden = Hidden
dash.news.nocurrent = You have no recent items.
dash.news.nostarred = You have not starred any recent items.
dash.news.nohidden = You have not hidden any recent items.

dash.news.linksCount = {0} items
dash.news.linksCount0 = No items
dash.news.linksCount1 = Showing 1 item
dash.news.linksCount2 = Showing item {0} of {1} items
dash.news.linksCount3 = Showing {0} to {1} of {2} items

dash.star = Star this
dash.unstar = Unstar this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,22 @@

import java.io.BufferedReader;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.apache.wicket.IRequestTarget;
import org.apache.wicket.RequestCycle;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.behavior.AbstractAjaxBehavior;
import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.ExternalLink;
import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;
import org.apache.wicket.markup.repeater.DefaultItemReuseStrategy;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.IDataProvider;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.protocol.http.WebRequest;
import org.apache.wicket.request.target.basic.StringRequestTarget;
import org.sakaiproject.dash.model.CalendarItem;
import org.sakaiproject.dash.model.NewsItem;
import org.sakaiproject.dash.tool.panels.CalendarLinksPanel;
import org.sakaiproject.dash.tool.panels.NewsLinksPanel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class CalendarLinksPanel extends Panel {

protected String selectedCalendarTab = null;
protected String calendarLinksDivId = null;
protected String noCalendarLinksDivId = null;
protected String calendarLinksCountId = null;
protected int pageSize = 5;

public CalendarLinksPanel(String id) {
Expand Down Expand Up @@ -122,6 +122,7 @@ public void onClick(AjaxRequestTarget target) {
// refresh calendarItemsDiv
initPanel();
target.addComponent(CalendarLinksPanel.this);
target.appendJavascript("resizeFrame('grow');");
}

};
Expand Down Expand Up @@ -152,6 +153,7 @@ public void onClick(AjaxRequestTarget target) {
// refresh calendarItemsDiv
initPanel();
target.addComponent(CalendarLinksPanel.this);
target.appendJavascript("resizeFrame('grow');");
}

};
Expand Down Expand Up @@ -181,6 +183,7 @@ public void onClick(AjaxRequestTarget target) {
// refresh calendarItemsDiv
initPanel();
target.addComponent(CalendarLinksPanel.this);
target.appendJavascript("resizeFrame('grow');");
}

};
Expand Down Expand Up @@ -210,6 +213,7 @@ public void onClick(AjaxRequestTarget target) {
// refresh calendarItemsDiv
initPanel();
target.addComponent(CalendarLinksPanel.this);
target.appendJavascript("resizeFrame('grow');");
}

};
Expand Down Expand Up @@ -283,6 +287,7 @@ public void onClick(AjaxRequestTarget target) {
String jsonStr = jsonHelper.getJsonObjectFromCalendarItem(changedItem).toString();
String javascript = "reportSuccess('item is no longer starred.'," + jsonStr + ",'" + "not-sure-about-url-yet" + "');";
target.appendJavascript(javascript);
target.appendJavascript("resizeFrame('grow');");
}
}
}
Expand Down Expand Up @@ -338,6 +343,7 @@ public void onClick(AjaxRequestTarget target) {
target.addComponent(CalendarLinksPanel.this);
//String javascript = "alert('success. (" + thisRow.getMarkupId() + ")');";
//target.appendJavascript(javascript );
target.appendJavascript("resizeFrame('grow');");
}
}

Expand Down Expand Up @@ -393,6 +399,7 @@ public void onClick(AjaxRequestTarget target) {
String jsonStr = jsonHelper.getJsonObjectFromCalendarItem(changedItem).toString();
String javascript = "reportSuccess('item is no longer hidden.'," + jsonStr + ",'" + "not-sure-about-url-yet" + "');";
target.appendJavascript(javascript );
target.appendJavascript("resizeFrame('grow');");
}
}

Expand Down Expand Up @@ -449,6 +456,7 @@ public void onClick(AjaxRequestTarget target) {
String jsonStr = jsonHelper.getJsonObjectFromCalendarItem(changedItem).toString();
String javascript = "reportSuccess('item is now hidden.'," + jsonStr + ",'" + "not-sure-about-url-yet" + "');";
target.appendJavascript(javascript );
target.appendJavascript("resizeFrame('grow');");
}
}

Expand Down Expand Up @@ -508,6 +516,8 @@ public boolean isVisible() {
public void onBeforeRender() {
super.onBeforeRender();

renderItemCounter(calendarLinksDiv, calendarDataView);

//clear the feedback panel messages
//clearFeedback(feedbackPanel);
}
Expand All @@ -527,13 +537,14 @@ public void onBeforeRender() {
noCalendarLinksLabel = rl.getString("dash.calendar.nohidden");
}
haveNoLinks.add(new Label("message", noCalendarLinksLabel));


renderItemCounter(calendarLinksDiv, calendarDataView);

int itemCount = 0;
if(calendarLinksProvider != null) {
itemCount = calendarLinksProvider.size();
if(calendarDataView != null) {
itemCount = calendarDataView.getItemCount();
}
// add the count to the calendarLinksDiv
calendarLinksDiv.add(new Label("calendarLinksCount", rl.getFormattedMessage("dash.calendar.linksCount", new Object[]{ new Integer(itemCount) })));

if(itemCount > 0) {
// show the haveLinks
haveLinks.setVisible(true);
Expand All @@ -547,6 +558,57 @@ public void onBeforeRender() {
}
}

/**
* @param rl
* @param calendarLinksDiv
* @param calendarDataView
*/
protected void renderItemCounter(final WebMarkupContainer calendarLinksDiv,
final DataView<CalendarLink> calendarDataView) {

ResourceLoader rl = new ResourceLoader("dash_entity");

if(calendarLinksCountId != null) {
Iterator itx = calendarLinksDiv.iterator();
while(itx.hasNext()) {
Component child = (Component) itx.next();
if(calendarLinksCountId.equals(child.getId())) {
calendarLinksDiv.remove(child);
break;
}
}
}

int itemCount = 0;
String pagerStatus = "";
if(calendarDataView != null) {
int first = 0;
int last = 0;
itemCount = calendarDataView.getItemCount();
int pageSize = calendarDataView.getItemsPerPage();
if(itemCount > pageSize) {
int page = calendarDataView.getCurrentPage();
first = page * pageSize + 1;
last = Math.min(itemCount, (page + 1) * pageSize);
if(first == last) {
pagerStatus = rl.getFormattedMessage("dash.calendar.linksCount2", new Object[]{new Integer(first), new Integer(itemCount)});
} else {
pagerStatus = rl.getFormattedMessage("dash.calendar.linksCount3", new Object[]{new Integer(first), new Integer(last), new Integer(itemCount)});
}
} else if(itemCount > 1) {
pagerStatus = rl.getFormattedMessage("dash.calendar.linksCount3", new Object[]{new Integer(1), new Integer(itemCount), new Integer(itemCount)});
} else if(itemCount > 0) {
pagerStatus = rl.getString("dash.calendar.linksCount1");
} else {
pagerStatus = rl.getString("dash.calendar.linksCount0");
}
}
Label calendarLinksCount = new Label("calendarLinksCount", pagerStatus);
// add the count to the calendarLinksDiv
calendarLinksDiv.add(calendarLinksCount);
calendarLinksCountId = calendarLinksCount.getId();
}

private class CalendarLinkListDataProvider implements IDataProvider<List<CalendarLink>> {

public void detach() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class NewsLinksPanel extends Panel {
protected NewsLinksDataProvider newsLinksProvider = null;
protected String selectedNewsTab;
protected String newsLinksDivId = null;
protected String newsLinksCountId = null;
protected int pageSize = 5;

public NewsLinksPanel(String id) {
Expand Down Expand Up @@ -114,6 +115,7 @@ public void onClick(AjaxRequestTarget target) {

// refresh newsLinksDiv
target.addComponent(NewsLinksPanel.this);
target.appendJavascript("resizeFrame('grow');");
}

};
Expand Down Expand Up @@ -142,6 +144,7 @@ public void onClick(AjaxRequestTarget target) {

// refresh newsLinksDiv
target.addComponent(NewsLinksPanel.this);
target.appendJavascript("resizeFrame('grow');");
}

};
Expand Down Expand Up @@ -170,6 +173,7 @@ public void onClick(AjaxRequestTarget target) {

// refresh newsLinksDiv
target.addComponent(NewsLinksPanel.this);
target.appendJavascript("resizeFrame('grow');");
}

};
Expand Down Expand Up @@ -240,6 +244,7 @@ public void onClick(AjaxRequestTarget target) {
String javascript = "reportSuccess('item is no longer starred.'," + jsonStr + ",'" + "not-sure-about-url-yet" + "');";
target.appendJavascript(javascript );
}
target.appendJavascript("resizeFrame('grow');");
}
}

Expand Down Expand Up @@ -295,6 +300,7 @@ public void onClick(AjaxRequestTarget target) {
//String javascript = "alert('success. (" + thisRow.getMarkupId() + ")');";
//target.appendJavascript(javascript );
}
target.appendJavascript("resizeFrame('grow');");
}

};
Expand Down Expand Up @@ -349,6 +355,7 @@ public void onClick(AjaxRequestTarget target) {
String javascript = "reportSuccess('item is no longer hidden.'," + jsonStr + ",'" + "not-sure-about-url-yet" + "');";
target.appendJavascript(javascript );
}
target.appendJavascript("resizeFrame('grow');");
}

};
Expand Down Expand Up @@ -405,6 +412,7 @@ public void onClick(AjaxRequestTarget target) {
String javascript = "reportSuccess('item is now hidden.'," + jsonStr + ",'" + "not-sure-about-url-yet" + "');";
target.appendJavascript(javascript );
}
target.appendJavascript("resizeFrame('grow');");
}

};
Expand Down Expand Up @@ -462,10 +470,13 @@ public boolean isVisible() {
@Override
public void onBeforeRender() {
super.onBeforeRender();


renderItemCounter(newsLinksDiv, newsDataView);

//clear the feedback panel messages
//clearFeedback(feedbackPanel);
}

});

WebMarkupContainer haveNoLinks = new WebMarkupContainer("haveNoLinks");
Expand All @@ -481,12 +492,12 @@ public void onBeforeRender() {
}
haveNoLinks.add(new Label("message", noNewsLinksLabel));

renderItemCounter(newsLinksDiv, newsDataView);
int itemCount = 0;
if(newsLinksProvider != null) {
itemCount = newsLinksProvider.size();
}
// add the count to the newsLinksDiv
newsLinksDiv.add(new Label("newsLinksCount", rl.getFormattedMessage("dash.news.linksCount", new Object[]{ new Integer(itemCount) })));
if(newsDataView != null) {
itemCount = newsDataView.getItemCount();
}

if(itemCount > 0) {
// show the haveLinks
haveLinks.setVisible(true);
Expand All @@ -500,6 +511,60 @@ public void onBeforeRender() {
}
}

/**
* @param rl
* @param newsLinksDiv
* @param newsDataView
*/
protected void renderItemCounter(
final WebMarkupContainer newsLinksDiv,
final DataView<NewsLink> newsDataView) {

ResourceLoader rl = new ResourceLoader("dash_entity");

if(newsLinksCountId != null) {
Iterator itx = newsLinksDiv.iterator();
while(itx.hasNext()) {
Component child = (Component) itx.next();
if(newsLinksCountId.equals(child.getId())) {
newsLinksDiv.remove(child);
break;
}
}
}

int itemCount = 0;
String pagerStatus = "";
if(newsDataView != null) {
int first = 0;
int last = 0;
itemCount = newsDataView.getItemCount();
int pageSize = newsDataView.getItemsPerPage();
if(itemCount > pageSize) {
int page = newsDataView.getCurrentPage();
first = page * pageSize + 1;
last = Math.min(itemCount, (page + 1) * pageSize);
if(first == last) {
pagerStatus = rl.getFormattedMessage("dash.news.linksCount2", new Object[]{new Integer(first), new Integer(itemCount)});
} else {
pagerStatus = rl.getFormattedMessage("dash.news.linksCount3", new Object[]{new Integer(first), new Integer(last), new Integer(itemCount)});
}
} else if(itemCount > 1) {
pagerStatus = rl.getFormattedMessage("dash.news.linksCount3", new Object[]{new Integer(1), new Integer(itemCount), new Integer(itemCount)});
} else if(itemCount > 0) {
pagerStatus = rl.getString("dash.news.linksCount1");
} else {
pagerStatus = rl.getString("dash.news.linksCount0");
}
}
Label newsLinksCount = new Label("newsLinksCount", pagerStatus);
newsLinksCount.setOutputMarkupId(true);
// add the count to the newsLinksDiv
newsLinksDiv.add(newsLinksCount);

newsLinksCountId = newsLinksCount.getId();
}

/**
* DataProvider to manage our list
*
Expand Down

0 comments on commit 8f920e1

Please sign in to comment.