Commit a50873a7 by Tuukka Kivilahti

lectures, now user can participate lectures etc.

1 parent 5c776ce2
...@@ -6,12 +6,16 @@ import java.util.List; ...@@ -6,12 +6,16 @@ import java.util.List;
import javax.annotation.security.DeclareRoles; import javax.annotation.security.DeclareRoles;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import javax.faces.model.ListDataModel;
import fi.codecrew.moya.enums.apps.LecturePermission; import fi.codecrew.moya.enums.apps.LecturePermission;
import fi.codecrew.moya.facade.EventUserFacade;
import fi.codecrew.moya.facade.LectureFacade; import fi.codecrew.moya.facade.LectureFacade;
import fi.codecrew.moya.facade.LectureGroupFacade; import fi.codecrew.moya.facade.LectureGroupFacade;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Lecture; import fi.codecrew.moya.model.Lecture;
import fi.codecrew.moya.model.LectureGroup; import fi.codecrew.moya.model.LectureGroup;
import fi.codecrew.moya.model.Role;
/** /**
* Session Bean implementation class FoodWaveBean * Session Bean implementation class FoodWaveBean
...@@ -25,8 +29,13 @@ public class LectureBean implements LectureBeanLocal { ...@@ -25,8 +29,13 @@ public class LectureBean implements LectureBeanLocal {
@EJB @EJB
LectureGroupFacade lectureGroupFacade; LectureGroupFacade lectureGroupFacade;
@EJB @EJB
EventUserFacade eventUserFacade;
@EJB
EventBean eventBean; EventBean eventBean;
@EJB
UserBeanLocal userBean;
@Override @Override
public List<Lecture> getLecturesByLectureGroup(LectureGroup group) { public List<Lecture> getLecturesByLectureGroup(LectureGroup group) {
return new ArrayList<Lecture>(); return new ArrayList<Lecture>();
...@@ -50,7 +59,7 @@ public class LectureBean implements LectureBeanLocal { ...@@ -50,7 +59,7 @@ public class LectureBean implements LectureBeanLocal {
} else { } else {
group = lectureGroupFacade.merge(group); group = lectureGroupFacade.merge(group);
} }
return group; return group;
} }
...@@ -61,23 +70,115 @@ public class LectureBean implements LectureBeanLocal { ...@@ -61,23 +70,115 @@ public class LectureBean implements LectureBeanLocal {
@Override @Override
public Lecture saveLecture(Lecture lecture) { public Lecture saveLecture(Lecture lecture) {
if(lecture == null || lecture.getLectureGroup() == null) { if (lecture == null || lecture.getLectureGroup() == null) {
throw new NullPointerException("Lecture must be in some lecturegroup!"); throw new NullPointerException("Lecture must be in some lecturegroup!");
} }
if(lecture.getId() == null) { // let's try this, some weird cache problem
LectureGroup group = lectureGroupFacade.reload(lecture.getLectureGroup());
lecture.setLectureGroup(group);
if (lecture.getId() == null) {
lecture = lectureFacade.create(lecture); lecture = lectureFacade.create(lecture);
if(!lecture.getLectureGroup().getLectures().contains(lecture)) if (!lecture.getLectureGroup().getLectures().contains(lecture))
lecture.getLectureGroup().getLectures().add(lecture); lecture.getLectureGroup().getLectures().add(lecture);
} else { } else {
lecture = lectureFacade.merge(lecture); lecture = lectureFacade.merge(lecture);
} }
return lecture;
}
@Override
public List<Lecture> findAvailableLectures(LectureGroup group, EventUser user) {
LectureGroup lectureGroup = lectureGroupFacade.reload(group);
List<Role> userRoles = userBean.findUsersRoles(user);
List<Lecture> lectures = new ArrayList<Lecture>();
lectureloop: for (Lecture l : lectureGroup.getLectures()) {
for (Role r : l.getOpenForRoles()) {
if (userRoles.contains(r)) {
lectures.add(l);
continue lectureloop;
}
}
}
return lectures;
}
@Override
public List<Lecture> getParticipatedLectures(EventUser user) {
return eventUserFacade.reload(user).getLectures();
}
@Override
public Lecture participate(EventUser user, Lecture lecture) {
if(userLectureSelectsLeft(lecture.getLectureGroup(), user) <= 0)
return lecture;
EventUser targetUser = eventUserFacade.reload(user);
lecture.getParticipants().add(targetUser);
lectureFacade.merge(lecture);
targetUser.getLectures().add(lecture);
return lecture; return lecture;
} }
@Override
public Lecture unparticipate(EventUser user, Lecture lecture) {
EventUser targetUser = eventUserFacade.reload(user);
lecture.getParticipants().remove(targetUser);
targetUser.getLectures().remove(lecture);
lectureFacade.merge(lecture);
return lecture;
}
@Override
public int userLectureSelects(LectureGroup group, EventUser user) {
EventUser updatedUser = eventUserFacade.reload(user);
int count = 0;
for(Lecture l : updatedUser.getLectures()) {
if(l.getLectureGroup().equals(group)) {
count++;
}
}
return count;
}
@Override
public int userLectureSelectsLeft(LectureGroup group, EventUser user) {
LectureGroup updatedGroup = lectureGroupFacade.reload(group);
int maxCount = updatedGroup.getSelectCount();
if(maxCount <= 0)
return 99;
return maxCount - userLectureSelects(group, user);
}
} }
...@@ -3,6 +3,7 @@ package fi.codecrew.moya.facade; ...@@ -3,6 +3,7 @@ package fi.codecrew.moya.facade;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Lecture; import fi.codecrew.moya.model.Lecture;
@Stateless @Stateless
......
...@@ -3,21 +3,33 @@ package fi.codecrew.moya.beans; ...@@ -3,21 +3,33 @@ package fi.codecrew.moya.beans;
import java.util.List; import java.util.List;
import javax.ejb.Local; import javax.ejb.Local;
import javax.faces.model.ListDataModel;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Lecture; import fi.codecrew.moya.model.Lecture;
import fi.codecrew.moya.model.LectureGroup; import fi.codecrew.moya.model.LectureGroup;
@Local @Local
public interface LectureBeanLocal { public interface LectureBeanLocal {
public List<Lecture> getLecturesByLectureGroup(LectureGroup group); public List<Lecture> getLecturesByLectureGroup(LectureGroup group);
public List<LectureGroup> getLectureGroups(); public List<LectureGroup> getLectureGroups();
public LectureGroup saveLectureGroup(LectureGroup group); public LectureGroup saveLectureGroup(LectureGroup group);
public LectureGroup findLectureGroup(Integer id); public LectureGroup findLectureGroup(Integer id);
public Lecture saveLecture(Lecture lecture); public Lecture saveLecture(Lecture lecture);
public List<Lecture> findAvailableLectures(LectureGroup group, EventUser user);
public List<Lecture> getParticipatedLectures(EventUser user);
public Lecture participate(EventUser user, Lecture lecture);
public Lecture unparticipate(EventUser user, Lecture lecture);
public int userLectureSelectsLeft(LectureGroup group, EventUser user);
public int userLectureSelects(LectureGroup group, EventUser user);
} }
...@@ -473,6 +473,9 @@ public class EventUser extends GenericEntity { ...@@ -473,6 +473,9 @@ public class EventUser extends GenericEntity {
} }
public List<Lecture> getLectures() { public List<Lecture> getLectures() {
if(lectures == null)
lectures = new ArrayList<Lecture>();
return lectures; return lectures;
} }
......
...@@ -19,6 +19,7 @@ import javax.persistence.ManyToOne; ...@@ -19,6 +19,7 @@ import javax.persistence.ManyToOne;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import javax.persistence.Transient;
import org.eclipse.persistence.annotations.OptimisticLocking; import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType; import org.eclipse.persistence.annotations.OptimisticLockingType;
...@@ -111,6 +112,9 @@ public class Lecture extends GenericEntity { ...@@ -111,6 +112,9 @@ public class Lecture extends GenericEntity {
} }
public List<EventUser> getParticipants() { public List<EventUser> getParticipants() {
if(participants == null)
participants = new ArrayList<EventUser>();
return participants; return participants;
} }
...@@ -173,9 +177,7 @@ public class Lecture extends GenericEntity { ...@@ -173,9 +177,7 @@ public class Lecture extends GenericEntity {
setHours(new BigDecimal((int) endTime.compareTo(getStartTime()) / 1000 / 60 / 60)); setHours(new BigDecimal((int) endTime.compareTo(getStartTime()) / 1000 / 60 / 60));
} }
public boolean isFull() {
return (getParticipants().size() >= maxParticipantsCount);
}
public BigDecimal getHours() { public BigDecimal getHours() {
return hours; return hours;
...@@ -203,6 +205,23 @@ public class Lecture extends GenericEntity { ...@@ -203,6 +205,23 @@ public class Lecture extends GenericEntity {
return newLecture; return newLecture;
} }
@Transient
public boolean isFull() {
if(getMaxParticipantsCount() <= 0) {
return false;
}
return (getParticipants().size() >= getMaxParticipantsCount());
}
@Transient
public int getParticipantsCount() {
return getParticipants().size();
}
} }
......
...@@ -6,8 +6,10 @@ package fi.codecrew.moya.model; ...@@ -6,8 +6,10 @@ package fi.codecrew.moya.model;
import java.util.List; import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.Lob; import javax.persistence.Lob;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
...@@ -47,7 +49,7 @@ public class LectureGroup extends GenericEntity { ...@@ -47,7 +49,7 @@ public class LectureGroup extends GenericEntity {
private String description; private String description;
@OneToMany(mappedBy = "lectureGroup") @OneToMany(mappedBy = "lectureGroup", cascade = CascadeType.ALL)
private List<Lecture> lectures; private List<Lecture> lectures;
......
...@@ -41,8 +41,10 @@ ...@@ -41,8 +41,10 @@
</p:column> </p:column>
</p:dataTable> </p:dataTable>
</p:fieldset> </p:fieldset>
<p:commandButton value="#{i18n['lecture.createNew']}" actionListener="#{lectureView.createNew}" update=":managelectures:editcreate" /> <p:commandButton value="#{i18n['lecture.createNew']}" actionListener="#{lectureView.createNew}" update=":managelectures:editcreate" />
<p:outputLabel value="#{i18n['lecture.multicreate']}" /> <p:selectBooleanButton value="#{lectureView.multicreate}" offLabel="#{i18n['off']}" onLabel="#{i18n['on']}" onIcon="ui-icon-check" offIcon="ui-icon-close" />
<br /> <br />
<br /> <br />
<br /> <br />
...@@ -69,8 +71,8 @@ ...@@ -69,8 +71,8 @@
<f:selectItems var="roleitem" itemLabel="#{roleitem.name}" value="#{roleDataView.roles}" /> <f:selectItems var="roleitem" itemLabel="#{roleitem.name}" value="#{roleDataView.roles}" />
</h:selectManyCheckbox> </h:selectManyCheckbox>
<p:commandButton rendered="#{!lectureView.creatingLecture}" actionListener="#{lectureView.saveLecture}" value="#{i18n['save']}" update=":managelectures:lectures" /> <p:commandButton rendered="#{!lectureView.creatingLecture}" actionListener="#{lectureView.saveLecture}" value="#{i18n['save']}" update="editcreate :managelectures:lectures" />
<p:commandButton rendered="#{lectureView.creatingLecture}" actionListener="#{lectureView.saveLecture}" value="#{i18n['create']}" update=":managelectures:lectures" /> <p:commandButton rendered="#{lectureView.creatingLecture}" actionListener="#{lectureView.saveLecture}" value="#{i18n['create']}" update="editcreate :managelectures:lectures" />
</p:panelGrid> </p:panelGrid>
</p:fieldset> </p:fieldset>
......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:products="http://java.sun.com/jsf/composite/cditools/products" xmlns:users="http://java.sun.com/jsf/composite/cditools/user" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:p="http://primefaces.org/ui">
<h:body>
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
<f:viewParam name="lecturegroupid" value="#{lectureView.lectureGroupId}" />
<f:event type="preRenderView" listener="#{lectureGroupView.initView()}" />
</f:metadata>
<ui:define name="title">
<h1>#{i18n['viewlectures.title']}</h1>
</ui:define>
<ui:define name="content">
<h:form id="viewlecturesform">
<p:fieldset id="lectureGroups" legend="#{i18n['lecture.selectgroup']}">
<p:dataTable value="#{lectureUserView.lectureGroups}" var="lectureGroup">
<p:column headerText="#{i18n['lectureGroup.name']}">
<h:outputText value="#{lectureGroup.name}" />
</p:column>
<p:column headerText="#{i18n['lectureGroup.description']}">
<h:outputText value="#{lectureGroup.description}" />
</p:column>
<p:column headerText="#{i18n['lectureGroup.selectCountUserInfo']}">
<h:outputText value="#{lectureGroup.selectCount}" />
</p:column>
<p:column>
<p:commandButton value="#{i18n['lectureGroup.view']}" actionListener="#{lectureUserView.selectCurrentLectureGroup}" update=":viewlecturesform:participatedLectures :viewlecturesform:availableLectures :viewlecturesform:title" onerror="location.reload(true)" />
</p:column>
</p:dataTable>
</p:fieldset>
<h1>
<h:outputText id="title" value="#{lectureUserView.currentLectureGroup.name}" />
</h1>
<p:fieldset id="participatedLectures" legend="#{i18n['lecture.participatedLectures']} #{lectureUserView.currentGroupParticipateCount} / #{lectureUserView.currentLectureGroup.selectCount}">
<p:dataTable value="#{lectureUserView.participatedLectures}" var="lecture">
<p:column headerText="#{i18n['lecture.name']}">
<h:outputText value="#{lecture.name}" />
</p:column>
<p:column headerText="#{i18n['lecture.description']}">
<h:outputText value="#{lecture.description}" />
</p:column>
<p:column headerText="#{i18n['lecture.hours']}">
<h:outputText value="#{lecture.hours}" />
</p:column>
<p:column headerText="#{i18n['lecture.startTime']}">
<h:outputText value="#{lecture.startTime.time}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" />
</h:outputText>
</p:column>
<p:column headerText="#{i18n['lecture.participants']}">
<h:outputText value="#{lecture.participantsCount}" /> / <h:outputText value="#{lecture.maxParticipantsCount}" />
</p:column>
<p:column>
<p:commandButton value="#{i18n['lecture.unparticipate']}" actionListener="#{lectureUserView.unParticipateCurrent}" update=":viewlecturesform:availableLectures :viewlecturesform:participatedLectures" onerror="location.reload(true)" />
</p:column>
</p:dataTable>
</p:fieldset>
<br /><br />
<p:fieldset id="availableLectures" legend="#{i18n['lecture.availableLectures']}">
<p:dataTable value="#{lectureUserView.lectures}" var="lecture">
<p:column headerText="#{i18n['lecture.name']}">
<h:outputText value="#{lecture.name}" />
</p:column>
<p:column headerText="#{i18n['lecture.description']}">
<h:outputText value="#{lecture.description}" />
</p:column>
<p:column headerText="#{i18n['lecture.hours']}">
<h:outputText value="#{lecture.hours}" />
</p:column>
<p:column headerText="#{i18n['lecture.startTime']}">
<h:outputText value="#{lecture.startTime.time}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" />
</h:outputText>
</p:column>
<p:column headerText="#{i18n['lecture.participants']}">
<h:outputText value="#{lecture.participantsCount}" /> / <h:outputText value="#{lecture.maxParticipantsCount}" />
</p:column>
<p:column>
<p:commandButton value="#{i18n['lecture.participate']}" rendered="#{!lectureUserView.currentGroupFull and !lecture.full}" actionListener="#{lectureUserView.participateCurrent}" update=":viewlecturesform:availableLectures :viewlecturesform:participatedLectures" onerror="location.reload(true)" />
<h:outputText value="#{i18n['lecture.full']}" rendered="#{lecture.full}" />
<h:outputText value="#{i18n['lecture.groupFull']}" rendered="#{lectureUserView.currentGroupFull}" />
</p:column>
</p:dataTable>
</p:fieldset>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
...@@ -204,22 +204,32 @@ lanEventProperty.defaultValue = Default value ...@@ -204,22 +204,32 @@ lanEventProperty.defaultValue = Default value
lanEventProperty.save = Save lanEventProperty.save = Save
lanEventProperty.textValue = Text value lanEventProperty.textValue = Text value
lecture.createLecture = Uuden tiedot lecture.availableLectures = Aihealueen kurssit ja luennot
lecture.createNew = Luo uusi lecture.createLecture = Uuden tiedot
lecture.description = Kuvaus lecture.createNew = Luo uusi
lecture.hours = Kesto, tunteja lecture.description = Kuvaus
lecture.maxParticipantsCount = Max. osallistujia lecture.groupFull = Kiinti\u00F6 t\u00E4ynn\u00E4
lecture.name = Nimi lecture.hours = Kesto, tunteja
lecture.roles = Roolit lecture.maxParticipantsCount = Max. osallistujia
lecture.saveLecture = Muokkaa lecture.multicreate = Luo monta putkeen
lecture.startTime = Aloitusaika lecture.name = Nimi
lecture.participants = Osallistujia
lectureGroup.createLectureGroup = Luo luetokokonaisuus lecture.participate = Ilmoittaudu
lectureGroup.createNew = Luo uusi lecture.participatedLectures = Kurssi-ilmoittautumisesi
lectureGroup.description = Kuvaus lecture.roles = Roolit
lectureGroup.manageLectures = Hallitse luentoja lecture.saveLecture = Muokkaa
lectureGroup.name = Nimi lecture.selectgroup = Valitse aihealue
lectureGroup.selectCount = Montako kurssia saa valita lecture.startTime = Aloitusaika
lecture.unparticipate = Poista ilmoittautuminen
lectureGroup.createLectureGroup = Luo kurssikokonaisuus
lectureGroup.createNew = Luo uusi
lectureGroup.description = Kuvaus
lectureGroup.manageLectures = Hallitse luentoja
lectureGroup.name = Nimi
lectureGroup.selectCount = Montako kurssia saa valita
lectureGroup.selectCountUserInfo = Yhden osallistujan kiinti\u00F6
lectureGroup.view = Tarkastele
lecturegroup.create.success = Kurssiryhm\u00E4 luotu onnistuneesti. lecturegroup.create.success = Kurssiryhm\u00E4 luotu onnistuneesti.
lecturegroup.list.title = Luennot lecturegroup.list.title = Luennot
...@@ -242,7 +252,8 @@ navi.auth.login = frontpage ...@@ -242,7 +252,8 @@ navi.auth.login = frontpage
navi.auth.loginerror = frontpage navi.auth.loginerror = frontpage
navi.auth.logout = frontpage navi.auth.logout = frontpage
off = Pois
off = Poissa
on = P\u00E4\u00E4ll\u00E4 on = P\u00E4\u00E4ll\u00E4
...@@ -319,3 +330,5 @@ user.unauthenticated = Kirjautumaton ...@@ -319,3 +330,5 @@ user.unauthenticated = Kirjautumaton
usercart.downloadCsv = CSV usercart.downloadCsv = CSV
usercart.showoverview = Vie tarkastusn\u00E4kym\u00E4\u00E4n usercart.showoverview = Vie tarkastusn\u00E4kym\u00E4\u00E4n
viewlectures.title = Kurssit ja luennot
...@@ -555,22 +555,32 @@ layout.editBottom = Edit bottom content ...@@ -555,22 +555,32 @@ layout.editBottom = Edit bottom content
layout.editContent = Edit center layout.editContent = Edit center
layout.editTop = Edit topcontent layout.editTop = Edit topcontent
lecture.createLecture = New lecture lecture.availableLectures = available lectures
lecture.createNew = Create new lecture.createLecture = New lecture
lecture.description = Description lecture.createNew = Create new
lecture.hours = Duration hours lecture.description = Description
lecture.maxParticipantsCount = Max participants lecture.groupFull = Limit reached
lecture.name = Name lecture.hours = Duration hours
lecture.roles = Roles lecture.maxParticipantsCount = Max participants
lecture.saveLecture = Edit lecture.multicreate = Create multible in row
lecture.startTime = Start time lecture.name = Name
lecture.participants = Participants
lectureGroup.createLectureGroup = Create lecturegroup lecture.participate = Participate
lectureGroup.createNew = Create new lecture.participatedLectures = Your lectures
lectureGroup.description = Description lecture.roles = Roles
lectureGroup.manageLectures = Manage lectures lecture.saveLecture = Edit
lectureGroup.name = Name lecture.selectgroup = Select lecturegroup
lectureGroup.selectCount = Max lecture select count lecture.startTime = Start time
lecture.unparticipate = Remove participation
lectureGroup.createLectureGroup = Create lecturegroup
lectureGroup.createNew = Create new
lectureGroup.description = Description
lectureGroup.manageLectures = Manage lectures
lectureGroup.name = Name
lectureGroup.selectCount = Max lecture select count
lectureGroup.selectCountUserInfo = Quota for one participant
lectureGroup.view = View
lecturegroup.create.success = Lecturegroup created successfully. lecturegroup.create.success = Lecturegroup created successfully.
lecturegroup.list.title = Lectures lecturegroup.list.title = Lectures
...@@ -1434,6 +1444,8 @@ userview.userExists = Username already exists! You may already have an a ...@@ -1434,6 +1444,8 @@ userview.userExists = Username already exists! You may already have an a
viewexpired.body = Please login again. viewexpired.body = Please login again.
viewexpired.title = Login expired. Please login again. viewexpired.title = Login expired. Please login again.
viewlectures.title = Courses and lectures
voting.allcompos.curEntries = # of entries voting.allcompos.curEntries = # of entries
voting.allcompos.descri = Description voting.allcompos.descri = Description
voting.allcompos.description = List of all compos and theirs information. voting.allcompos.description = List of all compos and theirs information.
......
...@@ -566,22 +566,32 @@ layout.editBottom = Muokkaa alasis\u00E4lt\u00F6\u00E4 ...@@ -566,22 +566,32 @@ layout.editBottom = Muokkaa alasis\u00E4lt\u00F6\u00E4
layout.editContent = Muokkaa sis\u00E4lt\u00F6\u00E4 layout.editContent = Muokkaa sis\u00E4lt\u00F6\u00E4
layout.editTop = Muokkaa yl\u00E4sis\u00E4lt\u00F6\u00E4 layout.editTop = Muokkaa yl\u00E4sis\u00E4lt\u00F6\u00E4
lecture.createLecture = Uuden tiedot lecture.availableLectures = Aihealueen kurssit ja luennot
lecture.createNew = Luo uusi lecture.createLecture = Uuden tiedot
lecture.description = Kuvaus lecture.createNew = Luo uusi
lecture.hours = Kesto tunteina lecture.description = Kuvaus
lecture.maxParticipantsCount = Osallistujia enint. lecture.groupFull = Kiinti\u00F6 t\u00E4ynn\u00E4
lecture.name = Nimi lecture.hours = Kesto tunteina
lecture.roles = Roolit lecture.maxParticipantsCount = Osallistujia enint.
lecture.saveLecture = Muokkaa lecture.multicreate = Luo monta putkeen
lecture.startTime = Aloitusaika lecture.name = Nimi
lecture.participants = Osallistujia
lectureGroup.createLectureGroup = Luo Luentokokonaisuus lecture.participate = Ilmoittaudu
lectureGroup.createNew = Luo uusi lecture.participatedLectures = Ilmoittautumisesi
lectureGroup.description = Kuvaus lecture.roles = Roolit
lectureGroup.manageLectures = Hallitse luentoja lecture.saveLecture = Muokkaa
lectureGroup.name = Nimi lecture.selectgroup = Valitse aihealue
lectureGroup.selectCount = Monellekko saa osallistua lecture.startTime = Aloitusaika
lecture.unparticipate = Poista ilmoittautuminen
lectureGroup.createLectureGroup = Luo kurssikokonaisuus
lectureGroup.createNew = Luo uusi
lectureGroup.description = Kuvaus
lectureGroup.manageLectures = Hallitse luentoja
lectureGroup.name = Nimi
lectureGroup.selectCount = Monellekko saa osallistua
lectureGroup.selectCountUserInfo = Yhden henkil\u00F6n kiinti\u00F6
lectureGroup.view = Tarkastele kursseja
lecturegroup.create.success = Kurssiryhm\u00E4 luotu onnistuneesti. lecturegroup.create.success = Kurssiryhm\u00E4 luotu onnistuneesti.
lecturegroup.list.title = Luennot lecturegroup.list.title = Luennot
...@@ -685,7 +695,9 @@ newsgroup.writerRole = Kirjoittajaryhm\u00E4 ...@@ -685,7 +695,9 @@ newsgroup.writerRole = Kirjoittajaryhm\u00E4
newslist.header = Uutisryhm\u00E4t newslist.header = Uutisryhm\u00E4t
off = Pois
off = Poissa
on = P\u00E4\u00E4ll\u00E4 on = P\u00E4\u00E4ll\u00E4
...@@ -1415,6 +1427,8 @@ userview.userExists = K\u00E4ytt\u00E4j\u00E4tunnus on jo olemassa. Sinu ...@@ -1415,6 +1427,8 @@ userview.userExists = K\u00E4ytt\u00E4j\u00E4tunnus on jo olemassa. Sinu
viewexpired.body = Ole hyv\u00E4 ja kirjaudu sis\u00E4\u00E4n uudelleen. viewexpired.body = Ole hyv\u00E4 ja kirjaudu sis\u00E4\u00E4n uudelleen.
viewexpired.title = N\u00E4kym\u00E4 on vanhentunut viewexpired.title = N\u00E4kym\u00E4 on vanhentunut
viewlectures.title = Kurssit ja luennot
voting.allcompos.curEntries = Entryja voting.allcompos.curEntries = Entryja
voting.allcompos.descri = Kuvaus voting.allcompos.descri = Kuvaus
voting.allcompos.description = Compojen informaatiot. voting.allcompos.description = Compojen informaatiot.
......
package fi.codecrew.moya.web.cdiview.lecture; package fi.codecrew.moya.web.lecture;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped; import javax.enterprise.context.ConversationScoped;
......
package fi.codecrew.moya.web.lecture;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.faces.model.ListDataModel;
import javax.inject.Inject;
import javax.inject.Named;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.LectureBeanLocal;
import fi.codecrew.moya.model.Lecture;
import fi.codecrew.moya.model.LectureGroup;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
import fi.codecrew.moya.web.cdiview.user.UserView;
@Named
@ConversationScoped
public class LectureUserView extends GenericCDIView {
private static final long serialVersionUID = 1L;
@Inject
UserView userView;
@EJB
LectureBeanLocal lectureBean;
@EJB
EventBeanLocal eventBean;
ListDataModel<LectureGroup> lectureGroups = null;
ListDataModel<Lecture> lectures = null;
ListDataModel<Lecture> participatedLectures = null;
LectureGroup currentLectureGroup;
public ListDataModel<LectureGroup> getLectureGroups() {
lectureGroups = new ListDataModel<LectureGroup>(lectureBean.getLectureGroups());
return lectureGroups;
}
public void selectCurrentLectureGroup() {
if (lectureGroups != null && lectureGroups.isRowAvailable()) {
currentLectureGroup = lectureGroups.getRowData();
lectures = null;
}
}
public LectureGroup getCurrentLectureGroup() {
List<LectureGroup> groups = lectureBean.getLectureGroups();
if (currentLectureGroup == null && groups.size() > 0) {
currentLectureGroup = groups.get(0);
}
return currentLectureGroup;
}
public ListDataModel<Lecture> getLectures() {
if (currentLectureGroup == null)
return new ListDataModel<Lecture>();
lectures = new ListDataModel<Lecture>(lectureBean.findAvailableLectures(getCurrentLectureGroup(), userView.getCurrentUser()));
return lectures;
}
public ListDataModel<Lecture> getParticipatedLectures() {
participatedLectures = new ListDataModel<Lecture>(lectureBean.getParticipatedLectures(userView.getCurrentUser()));
return participatedLectures;
}
public void participateCurrent() {
if (lectures != null && lectures.isRowAvailable()) {
Lecture lecture = lectures.getRowData();
lectureBean.participate(userView.getCurrentUser(), lecture);
super.addFaceMessage("lecture.participated");
this.lectures = null;
}
}
public void unParticipateCurrent() {
if (participatedLectures != null && participatedLectures.isRowAvailable()) {
Lecture lecture = participatedLectures.getRowData();
lectureBean.unparticipate(userView.getCurrentUser(), lecture);
super.addFaceMessage("lecture.unparticipated");
this.lectures = null;
}
}
public boolean isCurrentGroupFull() {
return (lectureBean.userLectureSelectsLeft(getCurrentLectureGroup(), userView.getCurrentUser()) <= 0);
}
public int getCurrentGroupParticipateCount() {
return lectureBean.userLectureSelects(getCurrentLectureGroup(), userView.getCurrentUser());
}
}
package fi.codecrew.moya.web.cdiview.lecture; package fi.codecrew.moya.web.lecture;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped; import javax.enterprise.context.ConversationScoped;
...@@ -36,6 +36,7 @@ public class LectureView extends GenericCDIView { ...@@ -36,6 +36,7 @@ public class LectureView extends GenericCDIView {
private ListDataModel<Lecture> lectures; private ListDataModel<Lecture> lectures;
private Integer lecturegroupId = null;
...@@ -53,7 +54,8 @@ public class LectureView extends GenericCDIView { ...@@ -53,7 +54,8 @@ public class LectureView extends GenericCDIView {
return ; return ;
} }
currentLecture= lectureBean.saveLecture(currentLecture); currentLecture = lectureBean.saveLecture(currentLecture);
currentLectureGroup = currentLecture.getLectureGroup();
if(creatingLecture) if(creatingLecture)
context.addMessage(null, new FacesMessage(I18n.get("success"), I18n.get("lecturegroup.create.success")) ); context.addMessage(null, new FacesMessage(I18n.get("success"), I18n.get("lecturegroup.create.success")) );
...@@ -70,6 +72,8 @@ public class LectureView extends GenericCDIView { ...@@ -70,6 +72,8 @@ public class LectureView extends GenericCDIView {
currentLecture.setName(""); currentLecture.setName("");
currentLecture.setDescription(""); currentLecture.setDescription("");
} else {
currentLecture = null;
} }
} }
...@@ -91,26 +95,20 @@ public class LectureView extends GenericCDIView { ...@@ -91,26 +95,20 @@ public class LectureView extends GenericCDIView {
public Integer getLectureGroupId() { public Integer getLectureGroupId() {
if(currentLectureGroup != null && currentLectureGroup.getId() != null) return lecturegroupId;
return currentLectureGroup.getId();
return null;
} }
public void setLectureGroupId(Integer lectureGroupId) { public void setLectureGroupId(Integer lectureGroupId) {
if(lectureGroupId == null) this.lecturegroupId = lectureGroupId;
currentLectureGroup = null;
else
currentLectureGroup = lectureBean.findLectureGroup(lectureGroupId);
} }
public ListDataModel<Lecture> getLectures() { public ListDataModel<Lecture> getLectures() {
if(lectures == null && currentLectureGroup != null) { if(lectures == null && getCurrentLectureGroup() != null) {
lectures = new ListDataModel<Lecture>(currentLectureGroup.getLectures()); lectures = new ListDataModel<Lecture>(getCurrentLectureGroup().getLectures());
} }
return lectures; return lectures;
...@@ -138,7 +136,7 @@ public class LectureView extends GenericCDIView { ...@@ -138,7 +136,7 @@ public class LectureView extends GenericCDIView {
public Lecture getCurrentLecture() { public Lecture getCurrentLecture() {
if(currentLecture == null) { if(currentLecture == null) {
currentLecture = new Lecture(currentLectureGroup); currentLecture = new Lecture(getCurrentLectureGroup());
} }
return currentLecture; return currentLecture;
...@@ -151,6 +149,11 @@ public class LectureView extends GenericCDIView { ...@@ -151,6 +149,11 @@ public class LectureView extends GenericCDIView {
public LectureGroup getCurrentLectureGroup() { public LectureGroup getCurrentLectureGroup() {
if(currentLectureGroup == null) {
currentLectureGroup = lectureBean.findLectureGroup(lecturegroupId);
}
return currentLectureGroup; return currentLectureGroup;
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!