Skip to content

Commit

Permalink
DASH-319 do not create dashboard news link for MOTD items; Display th…
Browse files Browse the repository at this point in the history
…e first avaible MOTD item when there is multiple in the list

git-svn-id: https://source.sakaiproject.org/svn/dashboard/trunk@313589 66ffb92e-73f9-0310-93c1-f5514f145a0a
  • Loading branch information
zqian committed Sep 8, 2014
1 parent 72aca51 commit f44d929
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,25 +179,31 @@ private void createUpdateDashboardItemLinks(Event event, AnnouncementMessage ann
updatingExistingLinks = false;
}

if (!anncReference.contains(dashboardLogic.MOTD_CONTEXT))
{
// no need to add links to MOTD items
// where channel reference like '/announcement/channel/!site/motd'
if(dashboardLogic.isAvailable(newsItem.getEntityReference(), IDENTIFIER)) {
// available now -- check whether it has a retract date
Date retractDate = getRetractDate(annc);
if(retractDate != null && retractDate.after(new Date())) {
dashboardLogic.scheduleAvailabilityCheck(newsItem.getEntityReference(), IDENTIFIER, retractDate);
}

// add links
if(updatingExistingLinks) {
dashboardLogic.updateNewsLinks(newsItem.getEntityReference());
} else {
dashboardLogic.createNewsLinks(newsItem);
}
} else {
// not available now -- check whether it has a release date
Date releaseDate = getReleaseDate(annc);
if(releaseDate != null && releaseDate.after(new Date())) {
dashboardLogic.scheduleAvailabilityCheck(newsItem.getEntityReference(), IDENTIFIER, releaseDate);
}
}

// add links
if(updatingExistingLinks) {
dashboardLogic.updateNewsLinks(newsItem.getEntityReference());
} else {
dashboardLogic.createNewsLinks(newsItem);
}
}

Expand Down Expand Up @@ -344,8 +350,9 @@ public boolean isAvailable(String entityReference) {
String channelId = getChannelIdFromReference(entityReference);
AnnouncementChannel channel = (AnnouncementChannel) announcementService.getChannel(channelId);
String siteId = channel.getContext();
if (!sakaiProxy.isSitePublished(siteId))
if (!dashboardLogic.MOTD_CONTEXT.equals(siteId) && !sakaiProxy.isSitePublished(siteId))
{
// exclude "!site" MOTD site id
// return false if site is unpublished
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.sakaiproject.dash.app.SakaiProxy;
import org.sakaiproject.dash.model.NewsItem;
import org.sakaiproject.dash.model.NewsLink;
import org.sakaiproject.dash.model.SourceType;
import org.sakaiproject.dash.tool.util.JsonHelper;
import org.sakaiproject.dash.util.DateUtil;
import org.sakaiproject.util.FormattedText;
Expand Down Expand Up @@ -87,6 +88,9 @@ public class MOTDPanel extends Panel {
@SpringBean(name="org.sakaiproject.dash.app.DashboardConfig")
protected DashboardConfig dashboardConfig;

@SpringBean(name="org.sakaiproject.dash.logic.DashboardLogic")
protected DashboardLogic dashboardLogic;

protected NewsLinksDataProvider motdProvider = null;
protected String motdDivId = null;
protected String motdCountId = null;
Expand All @@ -111,17 +115,22 @@ protected void initText() {
motdDiv.add(new Label("motdPanelTitle", rl.getString("dash.motd.title")));

List<NewsItem> motdList = dashboardCommonLogic.getMOTD();
if(motdList == null || motdList.isEmpty()) {
motdDiv.add(new Label("motdId", "0@0"));
motdDiv.add(new Label("motdText", "No new messages"));
RepeatingView attachments = new RepeatingView("attachments");
motdDiv.add(attachments);
WebMarkupContainer attItem = new WebMarkupContainer(attachments.newChildId());
attachments.add(attItem);
attItem.add(new ExternalLink("attachment-link", "#", "---"));
attachments.setVisible(false);
} else {
NewsItem motd = motdList.get(0);
boolean showMOTD = false;
if(motdList != null && !motdList.isEmpty()) {
for(NewsItem motd : motdList)
{
// exist when we've showed a MOTD item;
// otherwise, loop till showing the first MOTD item
if (showMOTD)
break;

SourceType sType = motd.getSourceType();
if(dashboardLogic.isAvailable(motd.getEntityReference(), sType!=null ? sType.getIdentifier():null))
{
// show MOTD
showMOTD = true;

// only show MOTD when it is available
motdDiv.add(new Label("motdId", motd.getId() + "@" + motd.getNewsTime().getTime()));
Map<String, Object> info = dashboardCommonLogic.getEntityMapping(motd.getSourceType().getIdentifier(), motd.getEntityReference(), getLocale());
motdDiv.add(new Label("motdTitle", (String) info.get(DashboardEntityInfo.VALUE_TITLE)));
Expand All @@ -146,7 +155,9 @@ protected void initText() {
attachments.setVisible(false);
}
}
if(motdMode != MOTD_MODE_TEXT || motdList == null || motdList.isEmpty()) {
}
}
if (!showMOTD || motdMode != MOTD_MODE_TEXT || motdList == null || motdList.isEmpty()) {
motdDiv.setVisibilityAllowed(false);
motdDiv.setVisible(false);
}
Expand Down

0 comments on commit f44d929

Please sign in to comment.