Skip to content
This repository has been archived by the owner on Sep 27, 2018. It is now read-only.

Commit

Permalink
Issue #93. Channel page: display currently-displayed game background …
Browse files Browse the repository at this point in the history
…image.
  • Loading branch information
Florent Biville committed Feb 19, 2013
1 parent 1da0390 commit f755121
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 7 deletions.
11 changes: 9 additions & 2 deletions src/main/java/tv/esporx/controllers/ChannelController.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
import tv.esporx.conversion.VideoProviderConverter;
import tv.esporx.domain.Channel;
import tv.esporx.domain.CrawledChannel;
import tv.esporx.domain.Occurrence;
import tv.esporx.domain.remote.JsonChannel;
import tv.esporx.repositories.ChannelRepository;
import tv.esporx.repositories.VideoProviderRepository;
import tv.esporx.services.TimelineService;

import javax.annotation.Resource;
import javax.persistence.PersistenceException;
Expand All @@ -45,16 +47,19 @@ public class ChannelController {
private final ChannelRepository repository;
private final VideoProviderRepository videoProviderRepository;
private final DomainClassConverter<?> entityConverter;
@Resource(name = "supportedLanguages")
private final TimelineService timelineService;
@Resource(name = "supportedLanguages")
private final Set<String> allowedLocales = new HashSet<String>();

@Autowired
@Autowired
public ChannelController(ChannelRepository repository,
VideoProviderRepository videoProviderRepository,
TimelineService timelineService,
DomainClassConverter<?> entityConverter) {

this.repository = repository;
this.videoProviderRepository = videoProviderRepository;
this.timelineService = timelineService;
this.entityConverter = entityConverter;
}

Expand All @@ -66,7 +71,9 @@ public ModelAndView index(@PathVariable final long id, final HttpServletResponse
if (channel == null) {
return notFound(response, "channel/notFound");
}
Occurrence broadcast = timelineService.findCurrentBroadcastByChannel(channel);
ModelMap model = new ModelMap("channel", channel);
model.addAttribute("currentGame", broadcast == null ? null : broadcast.getGame());
model.addAttribute("embeddedVideo", videoProviderRepository.getEmbeddedContents(channel.getVideoUrl()));
return new ModelAndView("channel/index", model);
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/tv/esporx/domain/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ public class Game {
@Length(max = 100)
@Column(name = "title", nullable = false, unique = true)
private String title = "";
@NotBlank
@Length(max = 255)
@Column(name = "icon_url", nullable = false)
private String iconUrl = "";
@Length(max = 255)
@Column(name = "background_url", nullable = true)
private String backgroundUrl = "";

public String getDescription() {
return description;
Expand Down Expand Up @@ -57,6 +61,14 @@ public void setIconUrl(String iconUrl) {
this.iconUrl = iconUrl;
}

public String getBackgroundUrl() {
return backgroundUrl;
}

public void setBackgroundUrl(String backgroundUrl) {
this.backgroundUrl = backgroundUrl;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/tv/esporx/services/TimelineService.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package tv.esporx.services;

import com.google.common.base.Predicate;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tv.esporx.domain.Channel;
import tv.esporx.domain.Game;
import tv.esporx.domain.Occurrence;
import tv.esporx.repositories.OccurrenceRepository;
import tv.esporx.services.timeline.Timeline;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.find;
import static tv.esporx.framework.time.DateTimeUtils.toStartHour;

@Service
@Transactional
Expand All @@ -23,6 +29,18 @@ public Timeline getTimeline(DateTime start, DateTime end) {
return new Timeline(start, end).from(occurrenceRepository.findAllInRange(start, end));
}

@Transactional(readOnly = true)
public Occurrence findCurrentBroadcastByChannel(final Channel channel) {
DateTime start = toStartHour(new DateTime());
Timeline timeline = this.getTimeline(start, start.plusHours(1));
return find(timeline.perHourMultimap().values(), new Predicate<Occurrence>() {
@Override
public boolean apply(Occurrence input) {
return input.getChannels().contains(channel);
}
});
}

private void checkSanity(DateTime startDay, DateTime endDay) {
checkNotNull(startDay);
checkNotNull(endDay);
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/i18n/eSporx.properties
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ game.submission.title=Submit your game!
game.submission.title.placeholder=specify a name...
game.submission.description=Game description
game.submission.description.placeholder=specify a description...
game.submission.icon=Game icon
game.submission.icon=Icon
game.submission.icon.placeholder=specify the picture URL
game.submission.background=Background image (optional)
game.submission.background.placeholder=specify the background URL
game.submission.submit=Save this!

## GONDOLA SLIDE FORM
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
<changeSet id="add_background_image_to_game" author="esporx_dev">
<addColumn tableName="games">
<column name="background_url" type="varchar(255)" />
</addColumn>
</changeSet>
</databaseChangeLog>
1 change: 1 addition & 0 deletions src/main/webapp/META-INF/db-migrations/2.0/master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@
<include file="add_dailymotion_api_endpoint.xml" relativeToChangelogFile="true" />
<include file="create_authentication_tables.xml" relativeToChangelogFile="true" />
<include file="add_columns_to_users.xml" relativeToChangelogFile="true" />
<include file="add_background_image_to_game.xml" relativeToChangelogFile="true" />
</databaseChangeLog>
2 changes: 1 addition & 1 deletion src/main/webapp/WEB-INF/pages/channel/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
});
</script>
</head>
<body>
<body<c:if test="${not empty currentGame && not empty currentGame.backgroundUrl}"><c:out value=' style="background-image:url(${currentGame.backgroundUrl})"' escapeXml="false" /></c:if>>
<div id="pageContent">
<c:import url="/WEB-INF/pages/include/header.jsp" />
<div id="catMain">
Expand Down
14 changes: 12 additions & 2 deletions src/main/webapp/WEB-INF/pages/game/form.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,24 @@

<div class="input">
<spring:message code="game.submission.icon.placeholder"
var="descriptionPlaceholder" />
<form:label path="iconUrl" title="${descriptionPlaceholder}">
var="placeholder" />
<form:label path="iconUrl" title="${placeholder}">
<spring:message code="game.submission.icon" />
</form:label>
<form:input path="iconUrl" />
<form:errors path="iconUrl" cssClass="errors" />
</div>

<div class="input">
<spring:message code="game.submission.background.placeholder"
var="placeholder" />
<form:label path="backgroundUrl" title="${placeholder}">
<spring:message code="game.submission.background" />
</form:label>
<form:input path="backgroundUrl" />
<form:errors path="backgroundUrl" cssClass="errors" />
</div>

<div id="submit" class="submit">
<input type="submit" value="<spring:message code="game.submission.submit" />" />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import tv.esporx.domain.Channel;
import tv.esporx.repositories.ChannelRepository;
import tv.esporx.repositories.VideoProviderRepository;
import tv.esporx.services.TimelineService;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
Expand All @@ -30,7 +31,7 @@ public void setup() {
dummyChannel();
mockedChannelRepository();
mockedEventRepository();
channelController = new ChannelController(channelRepository, videoProviderRepository, mock(DomainClassConverter.class));
channelController = new ChannelController(channelRepository, videoProviderRepository, mock(TimelineService.class), mock(DomainClassConverter.class));
}

@Test
Expand Down

0 comments on commit f755121

Please sign in to comment.