Skip to content

Commit

Permalink
implement basic voting support #62
Browse files Browse the repository at this point in the history
  • Loading branch information
RainerW committed May 3, 2012
1 parent a021011 commit b229f9b
Show file tree
Hide file tree
Showing 15 changed files with 467 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public enum ConferenceState
{
CREATED, PLANNING, VOTING, PLANNED, RUNNING, FINISHED;
CREATED, CALL4PAPERS, VOTING, VOTED, PLANNED, RUNNING, FINISHED;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import de.bitnoise.sonferenz.model.TalkModel;
Expand All @@ -18,4 +19,7 @@ public interface VoteRepository extends JpaRepository<VoteModel, Integer>

@Query("select v from VoteModel v where v.user = ?1 and v.rateing > ?2")
List<VoteModel> findByUserAndRateing(UserModel user, int rateing);

List<VoteModel> findByUser(UserModel user);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import de.bitnoise.sonferenz.model.TalkModel;
import de.bitnoise.sonferenz.model.UserModel;
import de.bitnoise.sonferenz.model.VoteModel;

public interface VoteService
{
Expand All @@ -12,4 +13,8 @@ public interface VoteService

boolean vote(TalkModel talk, UserModel user, int increment);

List<VoteModel> getMyVotes();

void saveMyVotes(List<VoteModel> votes);

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import de.bitnoise.sonferenz.model.ConferenceModel;
import de.bitnoise.sonferenz.model.TalkModel;
import de.bitnoise.sonferenz.model.UserModel;
import de.bitnoise.sonferenz.model.VoteModel;
import de.bitnoise.sonferenz.repo.TalkRepository;
import de.bitnoise.sonferenz.repo.VoteRepository;
import de.bitnoise.sonferenz.service.v2.services.AuthenticationService;
import de.bitnoise.sonferenz.service.v2.services.VoteService;

@Service
Expand All @@ -25,8 +25,11 @@ public class VoteService2Impl implements VoteService
@Autowired
VoteRepository voteRepo;

@Autowired
AuthenticationService auth;

@Override
@Transactional
@Transactional
public void removeAllVotestForTalk(List<TalkModel> talks)
{
if (talks == null)
Expand All @@ -47,7 +50,7 @@ public void removeAllVotestForTalk(List<TalkModel> talks)
}

@Override
@Transactional
@Transactional
public boolean vote(TalkModel talk, UserModel user, int increment)
{
ConferenceModel conference = talk.getConference();
Expand Down Expand Up @@ -114,15 +117,41 @@ private List<VoteModel> getAllAttendingTalks(ConferenceModel conference,
UserModel user, int minState)
{
List<VoteModel> rest = voteRepo.findByUserAndRateing(user, minState);
for(VoteModel v : rest) {
for (VoteModel v : rest)
{
TalkModel t = v.getTalk();
Hibernate.initialize(v);
if(t!=null) {
Hibernate.initialize (t.getVotes() );
if (t != null)
{
Hibernate.initialize(t.getVotes());
}
}
return rest;
}


@Override
@Transactional
public List<VoteModel> getMyVotes()
{
UserModel user = auth.getCurrentUser();
if (user == null)
{
throw new IllegalStateException("No User logged in");
}
List<VoteModel> votes = voteRepo.findByUser(user);
Hibernate.initialize(votes);
return votes;
}

@Override
@Transactional
public void saveMyVotes(List<VoteModel> votes)
{
UserModel user = auth.getCurrentUser();
voteRepo.deleteInBatch( voteRepo.findByUser(user) );
for(VoteModel vote : votes) {
voteRepo.saveAndFlush(vote);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ public static List<NavCallbackInterface> getPages()
new IsActiveConference()
));
*/
ret.add(new PageNavCallback(VotingOverviewPage.class, "Voting",
new VisibleOnRights(Right.Vote.canVote),
new IsActiveConference(),
new OnStateVoting()
));
// ret.add(new PageNavCallback(VotingOverviewPage.class, "Voting",
// new VisibleOnRights(Right.Vote.canVote),
// new IsActiveConference(),
// new OnStateVoting()
// ));
ret.add(new PageNavCallback(CalculateOverviewPage.class, "Calculate",
new VisibleOnRights(Right.Admin.ViewCalculation),
new IsActiveConference(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,57 @@
import org.apache.wicket.markup.repeater.RepeatingView;

import de.bitnoise.sonferenz.KonferenzSession;
import de.bitnoise.sonferenz.web.component.state.OnStateCallForPapers;
import de.bitnoise.sonferenz.web.component.state.OnStateVoting;
import de.bitnoise.sonferenz.web.pages.paper.TalksOverviewPage;
import de.bitnoise.sonferenz.web.pages.statics.ConferencePage;
import de.bitnoise.sonferenz.web.pages.statics.ContactPage;
import de.bitnoise.sonferenz.web.pages.statics.InfoPage;
import de.bitnoise.sonferenz.web.pages.statics.RegisterPage;
import de.bitnoise.sonferenz.web.pages.voting.VotingOverviewPage;
import de.bitnoise.sonferenz.web.pages.whish.WhishOverviewPage;

public class FirstLevelBar extends Panel {

public FirstLevelBar(String id) {
super(id);
}

@Override
protected void onInitialize() {
super.onInitialize();
RepeatingView items = new RepeatingView("repeater");

if (!KonferenzSession.noUserLoggedIn()) {
items.add(new MenuButton("info", items.newChildId(), InfoPage.class));
items.add(new MenuButton("whishes", items.newChildId(), WhishOverviewPage.class));
items.add(new MenuButton("talks", items.newChildId(), TalksOverviewPage.class));
/*
items.add(new MenuButton("archive", items.newChildId(), ReviewPage.class));
items.add(new MenuButton("program", items.newChildId(), ConferencePage.class));
items.add(new MenuButton("agenda", items.newChildId(), AgendaPage.class));
*/
}
else
{
items.add(new MenuButton("conference", items.newChildId(), ConferencePage.class));
items.add(new MenuButton("register", items.newChildId(), RegisterPage.class));
}

items.add(new MenuButton("contact", items.newChildId(), ContactPage.class));
add(items);
}
public class FirstLevelBar extends Panel
{

public FirstLevelBar(String id)
{
super(id);
}

@Override
protected void onInitialize()
{
super.onInitialize();
RepeatingView items = new RepeatingView("repeater");

if (!KonferenzSession.noUserLoggedIn())
{

items.add(new MenuButton("info", items.newChildId(), InfoPage.class));
if (new OnStateVoting().canBeDisplayed())
{
items.add(new MenuButton("voting", items.newChildId(),VotingOverviewPage.class));
}
if (new OnStateCallForPapers().canBeDisplayed())
{
items.add(new MenuButton("whishes", items.newChildId(),WhishOverviewPage.class));
items.add(new MenuButton("talks", items.newChildId(),TalksOverviewPage.class));
}
/*
* items.add(new MenuButton("archive", items.newChildId(),
* ReviewPage.class)); items.add(new MenuButton("program",
* items.newChildId(), ConferencePage.class)); items.add(new
* MenuButton("agenda", items.newChildId(), AgendaPage.class));
*/
}
else
{
items.add(new MenuButton("conference", items.newChildId(),ConferencePage.class));
items.add(new MenuButton("register", items.newChildId(),RegisterPage.class));
}

items.add(new MenuButton("contact", items.newChildId(), ContactPage.class));
add(items);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package de.bitnoise.sonferenz.web.component.state;

import org.apache.wicket.injection.web.InjectorHolder;
import org.apache.wicket.spring.injection.annot.SpringBean;

import de.bitnoise.sonferenz.facade.UiFacade;
import de.bitnoise.sonferenz.model.ConferenceModel;
import de.bitnoise.sonferenz.model.ConferenceState;
import de.bitnoise.sonferenz.web.component.navigation.VisibleChoice;

public class OnStateCallForPapers implements VisibleChoice
{

@SpringBean
transient UiFacade facade;

public boolean canBeDisplayed()
{
InjectorHolder.getInjector().inject(this);
ConferenceModel active = facade.getActiveConference();
if (active == null)
{
return false;
}
return ConferenceState.CALL4PAPERS.equals(active.getState());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@
el.className = el.className.replace(/( repaint)+$/, '');
}, 0);
}
$(function() {
/* webkit bugfix https://bugs.webkit.org/show_bug.cgi?id=53166 */
if ($.browser.webkit) {
window.addEventListener('resize', function() {
webkitRepaint(document.body);
}, false);
}WA
});
</script>
</head>
<body id="MUNIT-9139f28b-d046-41ef-8933-d888e938bbfb-MUNIT" class="MUNIT-05ded946-7685-45a2-a1e0-31b7b7df767d-MUNIT">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
<wicket:panel>
<span class="header voting">
<p>
Bringe die Vortr&auml;ge via drag'n'drop in die Reihenfolge die du bevorzugen w&uuml;rdest.<br/>
Am besten bringst du am besten die obersten 10 Vortr&auml;ge in Reihe. ( 6 besuchbare Vortr&auml;ge plus 4 Ersatz Vortr&auml;ge )
</p>
</span>
<div wicket:id="voting" class="votinglist">
<div wicket:id="items" class="item">
<span class="initiate">&nbsp;x&nbsp;</span> <span wicket:id="name">[name]</span>
<div class="header">
<span class="head">&nbsp;</span>
<span class="head">Meine Vortragsliste :</span>
</div>
<div wicket:id="items" class="item draglist">
<span class="initiate">&nbsp;</span> <span wicket:id="title">[title]</span>
</div>
</div>
<br class="spacer" />
<div class="buttons">
<a href="#" wicket:id="save" class="button">save</a>
<a href="#" wicket:id="save" class="button">save</a>
</div>
</wicket:panel>

Loading

0 comments on commit b229f9b

Please sign in to comment.