Commit 3b7655ce by Juho Salli

Merge branch 'issue-4' into 'master'

Issue 4

Tagging support for actionlog. This drops the crew field from the database which essentially is just the role that the old messages were targeting. Crew is no longer needed because the crew can just follow tags. UI still could use some work but this should be more or less complete version of the functionality.

Merging this closes #4
2 parents a925af00 939b39af
package fi.codecrew.moya.beans; package fi.codecrew.moya.beans;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import javax.annotation.security.DeclareRoles; import javax.annotation.security.DeclareRoles;
...@@ -9,6 +11,7 @@ import javax.ejb.EJB; ...@@ -9,6 +11,7 @@ import javax.ejb.EJB;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import fi.codecrew.moya.facade.ActionLogFacade; import fi.codecrew.moya.facade.ActionLogFacade;
import fi.codecrew.moya.facade.ActionLogMessageTagFacade;
import fi.codecrew.moya.beans.ActionLogBeanLocal; import fi.codecrew.moya.beans.ActionLogBeanLocal;
import fi.codecrew.moya.beans.PermissionBeanLocal; import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.beans.RoleBeanLocal; import fi.codecrew.moya.beans.RoleBeanLocal;
...@@ -16,6 +19,7 @@ import fi.codecrew.moya.enums.ActionLogMessageState; ...@@ -16,6 +19,7 @@ import fi.codecrew.moya.enums.ActionLogMessageState;
import fi.codecrew.moya.enums.apps.ContentPermission; import fi.codecrew.moya.enums.apps.ContentPermission;
import fi.codecrew.moya.model.ActionLogMessage; import fi.codecrew.moya.model.ActionLogMessage;
import fi.codecrew.moya.model.ActionLogMessageResponse; import fi.codecrew.moya.model.ActionLogMessageResponse;
import fi.codecrew.moya.model.ActionLogMessageTag;
import fi.codecrew.moya.model.Role; import fi.codecrew.moya.model.Role;
/** /**
...@@ -35,15 +39,23 @@ public class ActionLogBean implements ActionLogBeanLocal { ...@@ -35,15 +39,23 @@ public class ActionLogBean implements ActionLogBeanLocal {
@EJB @EJB
private PermissionBeanLocal permissionBean; private PermissionBeanLocal permissionBean;
@EJB
private ActionLogMessageTagFacade actionLogMessageTagFacade;
@EJB
private EventBean eventBean;
public ActionLogBean() { public ActionLogBean() {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
@Override
@RolesAllowed(ContentPermission.S_MANAGE_ACTIONLOG) @RolesAllowed(ContentPermission.S_MANAGE_ACTIONLOG)
public void createActionLogEvent(String message, Role crew, boolean isTask) { public void createActionLogEvent(String message, boolean isTask) {
ArrayList<ActionLogMessageTag> almts = resolveTags(message);
ActionLogMessage alm = new ActionLogMessage(); ActionLogMessage alm = new ActionLogMessage();
alm.setCrew(crew);
if (isTask) { if (isTask) {
alm.setState(ActionLogMessageState.NEW); alm.setState(ActionLogMessageState.NEW);
} else { } else {
...@@ -53,14 +65,25 @@ public class ActionLogBean implements ActionLogBeanLocal { ...@@ -53,14 +65,25 @@ public class ActionLogBean implements ActionLogBeanLocal {
alm.setMessage(message); alm.setMessage(message);
alm.setUser(permissionBean.getCurrentUser()); alm.setUser(permissionBean.getCurrentUser());
alm.setLanEvent(permissionBean.getCurrentUser().getEvent()); alm.setLanEvent(permissionBean.getCurrentUser().getEvent());
alm.setTags(almts);
actionLogFacade.saveToActionLog(alm); actionLogFacade.saveToActionLog(alm);
} }
@RolesAllowed(ContentPermission.S_MANAGE_ACTIONLOG) @RolesAllowed(ContentPermission.S_MANAGE_ACTIONLOG)
@Deprecated
public List<ActionLogMessage> getAllActionLogEvents() { public List<ActionLogMessage> getAllActionLogEvents() {
return actionLogFacade.getAllSortedByTimestamp(permissionBean.getCurrentUser().getEvent()); return actionLogFacade.getAllSortedByTimestamp(permissionBean.getCurrentUser().getEvent());
} }
@Override
@RolesAllowed(ContentPermission.S_MANAGE_ACTIONLOG)
public List<ActionLogMessage> getAllActionLogEventsByFilter(List<ActionLogMessageTag> filterTags) {
if(filterTags.size() == 0)
return actionLogFacade.getAllSortedByTimestamp(permissionBean.getCurrentUser().getEvent());
else
return actionLogFacade.getAllSortedByTimestampFiltered(permissionBean.getCurrentUser().getEvent(), filterTags);
}
@RolesAllowed(ContentPermission.S_MANAGE_ACTIONLOG) @RolesAllowed(ContentPermission.S_MANAGE_ACTIONLOG)
public List<Role> getAssignableRoles() { public List<Role> getAssignableRoles() {
...@@ -72,6 +95,12 @@ public class ActionLogBean implements ActionLogBeanLocal { ...@@ -72,6 +95,12 @@ public class ActionLogBean implements ActionLogBeanLocal {
if(!alm.getLanEvent().equals(permissionBean.getCurrentUser().getEvent())) return null; if(!alm.getLanEvent().equals(permissionBean.getCurrentUser().getEvent())) return null;
return actionLogFacade.getActionLogMessageResponses(alm); return actionLogFacade.getActionLogMessageResponses(alm);
} }
@Override
@RolesAllowed(ContentPermission.S_MANAGE_ACTIONLOG)
public List<ActionLogMessageTag> getAllTags() {
return actionLogMessageTagFacade.getAllTags(eventBean.getCurrentEvent());
}
@RolesAllowed(ContentPermission.S_MANAGE_ACTIONLOG) @RolesAllowed(ContentPermission.S_MANAGE_ACTIONLOG)
public void addActionLogMessageResponse(ActionLogMessage alm, String message, ActionLogMessageState state) { public void addActionLogMessageResponse(ActionLogMessage alm, String message, ActionLogMessageState state) {
...@@ -98,4 +127,64 @@ public class ActionLogBean implements ActionLogBeanLocal { ...@@ -98,4 +127,64 @@ public class ActionLogBean implements ActionLogBeanLocal {
if(!alm.getLanEvent().equals(permissionBean.getCurrentUser().getEvent())) return null; if(!alm.getLanEvent().equals(permissionBean.getCurrentUser().getEvent())) return null;
else return alm; else return alm;
} }
private ArrayList<ActionLogMessageTag> resolveTags(String message) {
ArrayList<ActionLogMessageTag> almts = new ArrayList<>();
StringBuilder sb = null;
boolean rflag = false;
char ch;
for(int i=0; i < message.length(); i++) {
if(rflag) {
if((ch = message.charAt(i)) != ' ') {
sb.append(ch);
} else {
if(sb.length() > 0) {
ActionLogMessageTag almt = getActionLogMessageTagByString(sb.toString());
if(!almts.contains(almt)) {
almts.add(almt);
}
}
rflag = false;
sb = null;
}
} else if(!rflag) {
if(message.charAt(i) == '#') {
rflag=true;
sb=new StringBuilder();
}
}
}
if(sb != null && sb.length() > 0) {
ActionLogMessageTag almt = getActionLogMessageTagByString(sb.toString());
if(!almts.contains(almt)) {
almts.add(almt);
}
}
return almts;
}
@Override
@RolesAllowed(ContentPermission.S_MANAGE_ACTIONLOG)
public ActionLogMessageTag getActionLogMessageTagByString(String s) {
s = s.toLowerCase();
ActionLogMessageTag almt = null;
if((almt = actionLogMessageTagFacade.findByTagStringInEvent(s, eventBean.getCurrentEvent())) == null) {
almt = new ActionLogMessageTag();
almt.setEvent(eventBean.getCurrentEvent());
almt.setTag(s);
almt = actionLogMessageTagFacade.create(almt);
System.out.println("creating tag: "+s);
return almt;
} else {
System.out.println("re-using tag: "+s);
return almt;
}
}
} }
\ No newline at end of file
...@@ -34,6 +34,7 @@ public class BootstrapBean implements BootstrapBeanLocal { ...@@ -34,6 +34,7 @@ public class BootstrapBean implements BootstrapBeanLocal {
dbUpdates.add(new String[] { "DELETE FROM application_permissions WHERE application = 'MAP' and permission = 'RELEASE_PLACE'" }); dbUpdates.add(new String[] { "DELETE FROM application_permissions WHERE application = 'MAP' and permission = 'RELEASE_PLACE'" });
dbUpdates.add(new String[] { "ALTER TABLE site_page_content ADD COLUMN locale varchar(10)" }); dbUpdates.add(new String[] { "ALTER TABLE site_page_content ADD COLUMN locale varchar(10)" });
dbUpdates.add(new String[] { "ALTER TABLE products ALTER COLUMN vat TYPE NUMERIC(4,3)" }); dbUpdates.add(new String[] { "ALTER TABLE products ALTER COLUMN vat TYPE NUMERIC(4,3)" });
dbUpdates.add(new String[] { "ALTER TABLE actionlog_messages DROP COLUMN crew" });
} }
@EJB @EJB
......
...@@ -239,8 +239,8 @@ public class MenuBean implements MenuBeanLocal { ...@@ -239,8 +239,8 @@ public class MenuBean implements MenuBeanLocal {
MenuNavigation lognavi = adminevent.addPage(null, null); MenuNavigation lognavi = adminevent.addPage(null, null);
lognavi.setKey("topnavi.log"); lognavi.setKey("topnavi.log");
lognavi.addPage(menuitemfacade.findOrCreate("/actionlog/messagelist"), UserPermission.VIEW_ALL); lognavi.addPage(menuitemfacade.findOrCreate("/actionlog/index"), ContentPermission.MANAGE_ACTIONLOG);
lognavi.addPage(menuitemfacade.findOrCreate("/actionlog/taskview"), UserPermission.VIEW_ALL).setVisible(false); lognavi.addPage(menuitemfacade.findOrCreate("/actionlog/taskview"), ContentPermission.MANAGE_ACTIONLOG).setVisible(false);
MenuNavigation compoMenu = adminevent.addPage(null, null); MenuNavigation compoMenu = adminevent.addPage(null, null);
compoMenu.setKey("topnavi.compos"); compoMenu.setKey("topnavi.compos");
...@@ -473,8 +473,8 @@ public class MenuBean implements MenuBeanLocal { ...@@ -473,8 +473,8 @@ public class MenuBean implements MenuBeanLocal {
MenuNavigation lognavi = adminnavi.addPage(null, null); MenuNavigation lognavi = adminnavi.addPage(null, null);
lognavi.setKey("topnavi.log"); lognavi.setKey("topnavi.log");
lognavi.addPage(menuitemfacade.findOrCreate("/actionlog/messagelist"), UserPermission.VIEW_ALL); lognavi.addPage(menuitemfacade.findOrCreate("/actionlog/index"), ContentPermission.MANAGE_ACTIONLOG);
lognavi.addPage(menuitemfacade.findOrCreate("/actionlog/taskview"), UserPermission.VIEW_ALL).setVisible(false); lognavi.addPage(menuitemfacade.findOrCreate("/actionlog/taskview"), ContentPermission.MANAGE_ACTIONLOG).setVisible(false);
MenuNavigation foodnavi = adminnavi.addPage(null, null); MenuNavigation foodnavi = adminnavi.addPage(null, null);
foodnavi.setKey("topnavi.foodwave"); foodnavi.setKey("topnavi.foodwave");
......
package fi.codecrew.moya.facade; package fi.codecrew.moya.facade;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
...@@ -12,6 +13,7 @@ import javax.persistence.criteria.Root; ...@@ -12,6 +13,7 @@ import javax.persistence.criteria.Root;
import fi.codecrew.moya.model.ActionLogMessageResponse_; import fi.codecrew.moya.model.ActionLogMessageResponse_;
import fi.codecrew.moya.model.ActionLogMessage; import fi.codecrew.moya.model.ActionLogMessage;
import fi.codecrew.moya.model.ActionLogMessageResponse; import fi.codecrew.moya.model.ActionLogMessageResponse;
import fi.codecrew.moya.model.ActionLogMessageTag;
import fi.codecrew.moya.model.ActionLogMessage_; import fi.codecrew.moya.model.ActionLogMessage_;
import fi.codecrew.moya.model.LanEvent; import fi.codecrew.moya.model.LanEvent;
...@@ -24,6 +26,7 @@ public class ActionLogFacade extends IntegerPkGenericFacade<ActionLogMessage> { ...@@ -24,6 +26,7 @@ public class ActionLogFacade extends IntegerPkGenericFacade<ActionLogMessage> {
super(ActionLogMessage.class); super(ActionLogMessage.class);
} }
public List<ActionLogMessage> getAllSortedByTimestamp(LanEvent event) { public List<ActionLogMessage> getAllSortedByTimestamp(LanEvent event) {
CriteriaBuilder cb = getEm().getCriteriaBuilder(); CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<ActionLogMessage> cq = cb.createQuery(ActionLogMessage.class); CriteriaQuery<ActionLogMessage> cq = cb.createQuery(ActionLogMessage.class);
...@@ -56,4 +59,35 @@ public class ActionLogFacade extends IntegerPkGenericFacade<ActionLogMessage> { ...@@ -56,4 +59,35 @@ public class ActionLogFacade extends IntegerPkGenericFacade<ActionLogMessage> {
getEm().persist(almr); getEm().persist(almr);
getEm().flush(); getEm().flush();
} }
public List<ActionLogMessage> getAllSortedByTimestampFiltered(LanEvent event, List<ActionLogMessageTag> filterTags) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<ActionLogMessage> cq = cb.createQuery(ActionLogMessage.class);
Root<ActionLogMessage> root = cq.from(ActionLogMessage.class);
cq.where(
cb.equal(root.get(ActionLogMessage_.lanEvent), event)
);
cq.orderBy(cb.desc(root.get("time")));
// todo: filter using jpa..
TypedQuery<ActionLogMessage> tq = getEm().createQuery(cq);
List<ActionLogMessage> allResults = tq.getResultList();
List<ActionLogMessage> filteredResults = new ArrayList<>();
boolean containsTag = false;
for(ActionLogMessage alm : allResults) {
for(ActionLogMessageTag almt : alm.getTags()) {
if(filterTags.contains(almt)) {
containsTag = true;
break;
}
}
if(containsTag) {
filteredResults.add(alm);
containsTag = false;
}
}
return filteredResults;
}
} }
package fi.codecrew.moya.facade;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import fi.codecrew.moya.model.ActionLogMessageTag;
import fi.codecrew.moya.model.ActionLogMessageTag_;
import fi.codecrew.moya.model.LanEvent;
@Stateless
@LocalBean
public class ActionLogMessageTagFacade extends IntegerPkGenericFacade<ActionLogMessageTag> {
public ActionLogMessageTagFacade() {
super(ActionLogMessageTag.class);
}
public ActionLogMessageTag findByTagStringInEvent(String tagString, LanEvent event) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<ActionLogMessageTag> cq = cb.createQuery(ActionLogMessageTag.class);
Root<ActionLogMessageTag> root = cq.from(ActionLogMessageTag.class);
cq.where(
cb.and(
cb.equal(root.get(ActionLogMessageTag_.event), event),
cb.equal(root.get(ActionLogMessageTag_.tag), tagString)
)
);
TypedQuery<ActionLogMessageTag> tq = getEm().createQuery(cq);
ActionLogMessageTag almt;
try {
almt = tq.getSingleResult();
} catch(Exception e) {
return null;
}
return almt;
}
public List<ActionLogMessageTag> getAllTags(LanEvent event) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<ActionLogMessageTag> cq = cb.createQuery(ActionLogMessageTag.class);
Root<ActionLogMessageTag> root = cq.from(ActionLogMessageTag.class);
cq.where(
cb.equal(root.get(ActionLogMessageTag_.event), event)
);
TypedQuery<ActionLogMessageTag> tq = getEm().createQuery(cq);
try {
return tq.getResultList();
} catch(Exception e) {
return new ArrayList<ActionLogMessageTag>();
}
}
}
package fi.codecrew.moya.beans; package fi.codecrew.moya.beans;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.ejb.Local; import javax.ejb.Local;
...@@ -6,14 +7,19 @@ import javax.ejb.Local; ...@@ -6,14 +7,19 @@ import javax.ejb.Local;
import fi.codecrew.moya.enums.ActionLogMessageState; import fi.codecrew.moya.enums.ActionLogMessageState;
import fi.codecrew.moya.model.ActionLogMessage; import fi.codecrew.moya.model.ActionLogMessage;
import fi.codecrew.moya.model.ActionLogMessageResponse; import fi.codecrew.moya.model.ActionLogMessageResponse;
import fi.codecrew.moya.model.ActionLogMessageTag;
import fi.codecrew.moya.model.Role; import fi.codecrew.moya.model.Role;
@Local @Local
public interface ActionLogBeanLocal { public interface ActionLogBeanLocal {
public List<ActionLogMessage> getAllActionLogEvents(); public List<ActionLogMessage> getAllActionLogEvents();
public List<Role> getAssignableRoles(); public List<Role> getAssignableRoles();
public void createActionLogEvent(String message, Role crew, boolean isTask);
public ActionLogMessage find(Integer id); public ActionLogMessage find(Integer id);
public List<ActionLogMessageResponse> getActionLogMessageResponses(ActionLogMessage id); public List<ActionLogMessageResponse> getActionLogMessageResponses(ActionLogMessage id);
public void addActionLogMessageResponse(ActionLogMessage alm, String message, ActionLogMessageState state); public void addActionLogMessageResponse(ActionLogMessage alm, String message, ActionLogMessageState state);
public void createActionLogEvent(String message, boolean isTask);
List<ActionLogMessageTag> getAllTags();
ActionLogMessageTag getActionLogMessageTagByString(String s);
List<ActionLogMessage> getAllActionLogEventsByFilter(
List<ActionLogMessageTag> filterTags);
} }
...@@ -10,6 +10,8 @@ import javax.persistence.Entity; ...@@ -10,6 +10,8 @@ import javax.persistence.Entity;
import javax.persistence.EnumType; import javax.persistence.EnumType;
import javax.persistence.Enumerated; import javax.persistence.Enumerated;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.OrderBy; import javax.persistence.OrderBy;
import javax.persistence.Table; import javax.persistence.Table;
...@@ -37,9 +39,6 @@ public class ActionLogMessage extends GenericEntity { ...@@ -37,9 +39,6 @@ public class ActionLogMessage extends GenericEntity {
@JoinColumn(name = "lan_event_id") @JoinColumn(name = "lan_event_id")
private LanEvent lanEvent; private LanEvent lanEvent;
@JoinColumn(name = "crew", nullable = false)
private Role crew;
@Column(name = "message", nullable = false) @Column(name = "message", nullable = false)
private String message; private String message;
...@@ -49,6 +48,18 @@ public class ActionLogMessage extends GenericEntity { ...@@ -49,6 +48,18 @@ public class ActionLogMessage extends GenericEntity {
@OrderBy("id") @OrderBy("id")
private List<ActionLogMessageResponse> actionLogMessageResponses = new ArrayList<ActionLogMessageResponse>(); private List<ActionLogMessageResponse> actionLogMessageResponses = new ArrayList<ActionLogMessageResponse>();
@ManyToMany()
@JoinTable(
name = "actionlog_message_tag_sets",
joinColumns = {
@JoinColumn(name = "actionlog_message_id", referencedColumnName = ActionLogMessage.ID_COLUMN)
},
inverseJoinColumns = {
@JoinColumn(name = "actionlog_message_tag_id", referencedColumnName = ActionLogMessageTag.ID_COLUMN)
}
)
private List<ActionLogMessageTag> tags = new ArrayList<ActionLogMessageTag>();
@Column(name = "state", nullable = true) @Column(name = "state", nullable = true)
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
private ActionLogMessageState state; private ActionLogMessageState state;
...@@ -77,14 +88,6 @@ public class ActionLogMessage extends GenericEntity { ...@@ -77,14 +88,6 @@ public class ActionLogMessage extends GenericEntity {
this.user = user; this.user = user;
} }
public Role getCrew() {
return crew;
}
public void setCrew(Role crew) {
this.crew = crew;
}
public String getMessage() { public String getMessage() {
return message; return message;
} }
...@@ -109,4 +112,11 @@ public class ActionLogMessage extends GenericEntity { ...@@ -109,4 +112,11 @@ public class ActionLogMessage extends GenericEntity {
this.actionLogMessageResponses = actionLogMessageResponses; this.actionLogMessageResponses = actionLogMessageResponses;
} }
public List<ActionLogMessageTag> getTags() {
return tags;
}
public void setTags(List<ActionLogMessageTag> tags) {
this.tags = tags;
}
} }
package fi.codecrew.moya.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Table;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
import org.eclipse.persistence.annotations.PrivateOwned;
@Entity
@Table(name = "actionlog_message_tags")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class ActionLogMessageTag extends GenericEntity {
private static final long serialVersionUID = -2902547412412000488L;
@Column(name = "tag", nullable = false)
private String tag;
@JoinColumn(name="event")
private LanEvent event;
public LanEvent getEvent() {
return event;
}
public void setEvent(LanEvent lanEvent) {
this.event = lanEvent;
}
public void setTag(String tag) {
this.tag = tag;
}
public String getTag() {
return tag;
}
}
...@@ -97,11 +97,11 @@ ...@@ -97,11 +97,11 @@
</navigation-case> </navigation-case>
</navigation-rule> </navigation-rule>
<navigation-rule> <navigation-rule>
<display-name>actionlog/messagelist</display-name> <display-name>actionlog/index</display-name>
<from-view-id>/actionlog/messagelist.xhtml</from-view-id> <from-view-id>/actionlog/index.xhtml</from-view-id>
<navigation-case> <navigation-case>
<from-outcome>success</from-outcome> <from-outcome>success</from-outcome>
<to-view-id>/actionlog/messagelist.xhtml</to-view-id> <to-view-id>/actionlog/index.xhtml</to-view-id>
<redirect /> <redirect />
</navigation-case> </navigation-case>
</navigation-rule> </navigation-rule>
......
<!DOCTYPE html <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> "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:users="http://java.sun.com/jsf/composite/cditools/user" <html xmlns="http://www.w3.org/1999/xhtml"
xmlns:tools="http://java.sun.com/jsf/composite/cditools" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui"> xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:users="http://java.sun.com/jsf/composite/cditools/user"
xmlns:tools="http://java.sun.com/jsf/composite/cditools"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:body> <h:body>
<ui:composition template="#{sessionHandler.template}"> <ui:composition template="#{sessionHandler.template}">
<f:metadata> <f:metadata>
<!-- f:event type="preRenderView" listener="#{newsListView.initView}" /--> <f:event type="preRenderView"
listener="#{actionLogMessageView.initView}" />
</f:metadata> </f:metadata>
<ui:define name="content"> <ui:define name="content">
<h:outputStylesheet library="style" name="templates/insomnia2/css/actionlog.css" /> <h:outputStylesheet library="style"
name="templates/insomnia2/css/actionlog.css" />
<h1>#{i18n['actionlog.messagelist.header']}</h1> <h1>#{i18n['actionlog.messagelist.header']}</h1>
<p>#{i18n['actionlog.messagelist.description']}</p> <p>#{i18n['actionlog.messagelist.description']}</p>
<h:form id="actionlog_create"> <h:form id="actionlog">
<h2>#{i18n['actionlog.create.header']}</h2> <h2>#{i18n['actionlog.create.header']}</h2>
<h:messages /> <p:messages />
<div class="row"> <h:panelGrid columns="2">
<h3 class="actionlog_create_role">#{i18n['actionlog.create.role']}</h3> <h:panelGrid columns="3">
<h3 class="actionlog_create_message">#{i18n['actionlog.create.message']}</h3> <h:outputText value="#{i18n['actionlog.create.message']}" />
<h3 class="actionlog_create_istask">#{i18n['actionlog.create.taskradio']}</h3> <h:outputText value="#{i18n['actionlog.create.taskradio']}" />
</div> <h:outputText />
<div class="row">
<div class="actionlog_create_role">
<h:selectOneMenu value="#{actionLogCreateView.role}" converter="#{roleConverter}">
<f:selectItems var="role" itemLabel="#{role.name}" value="#{actionLogCreateView.roles}" />
</h:selectOneMenu>
</div>
<div class="actionlog_create_message"> <p:inputText value="#{actionLogCreateView.message}" style="width: 400px;" />
<h:inputText value="#{actionLogCreateView.message}" /> <p:selectBooleanCheckbox value="#{actionLogCreateView.task}" />
</div> <h:commandButton class="sendbutton"
action="#{actionLogCreateView.send}"
value="#{i18n['actionlog.create.submitbutton']}" update="@form" />
</h:panelGrid>
<div class="actionlog_create_istask"> <h:panelGrid columns="1">
<h:selectBooleanCheckbox value="#{actionLogCreateView.task}" /> <p:tagCloud model="#{actionLogMessageView.tagCloud}">
</div> <p:ajax event="select"
listener="#{actionLogMessageView.onTagSelect}"
update="@form,actionlogtable" />
</p:tagCloud>
<h:commandButton class="sendbutton" action="#{actionLogCreateView.send}" value="#{i18n['actionlog.create.submitbutton']}"> <h:panelGroup layout="block">
</h:commandButton> <ui:repeat id="selectedtags" var="tag" value="#{actionLogMessageView.activeTags}">
</div> <!-- <span style="border: 1px solid #0af; display: inline-block; padding: 2px">#{tag.tag}</span> -->
</h:form> <p:commandButton actionListener="#{actionLogMessageView.selectFilterTag(tag.tag)}" value="#{tag.tag}" immediate="true" update="@form" />
<div class="clearfix"></div> </ui:repeat>
<h2>#{i18n['actionlog.tasklist.header']}</h2> </h:panelGroup>
<div id="actionlog"> </h:panelGrid>
<h:form id="refresh"> </h:panelGrid>
<p:poll interval="10" update="actionlogtable" onerror="location.reload();" /> <!-- </h:form>-->
<p:dataTable styleClass="bordertable" rowStyleClass="#{message.state.name}" <div class="clearfix"></div>
id="actionlogtable" value="#{actionLogMessageView.messages}" var="message" paginator="true" rows="30" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="30,50,100" > <h2>#{i18n['actionlog.tasklist.header']}</h2>
<div id="actionlog">
<!-- <h:form id="refresh"> -->
<p:poll interval="10" update="actionlogtable"
onerror="location.reload();" />
<p:dataTable styleClass="bordertable"
rowStyleClass="#{message.state.name}" id="actionlogtable"
value="#{actionLogMessageView.messages}" var="message"
paginator="true" rows="30"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="30,50,100">
<p:column> <p:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="#{i18n['actionlog.time']}" /> <h:outputText value="#{i18n['actionlog.time']}" />
</f:facet> </f:facet>
<h:outputText value="#{message.time}"> <h:outputText value="#{message.time}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" /> <f:convertDateTime pattern="#{sessionHandler.datetimeFormat}"
timeZone="#{sessionHandler.timezone}" />
</h:outputText> </h:outputText>
</p:column> </p:column>
<p:column> <p:column>
...@@ -63,12 +80,6 @@ ...@@ -63,12 +80,6 @@
<h:outputText value="#{message.user.nick}" /> <h:outputText value="#{message.user.nick}" />
</p:column> </p:column>
<p:column> <p:column>
<f:facet name="header">
<h:outputText value="#{i18n['actionlog.crew']}" />
</f:facet>
<h:outputText value="#{message.crew.name}" />
</p:column>
<p:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="#{i18n['actionlog.message']}" /> <h:outputText value="#{i18n['actionlog.message']}" />
...@@ -89,8 +100,8 @@ ...@@ -89,8 +100,8 @@
</h:link> </h:link>
</p:column> </p:column>
</p:dataTable> </p:dataTable>
</h:form> </div>
</div> </h:form>
</ui:define> </ui:define>
</ui:composition> </ui:composition>
</h:body> </h:body>
......
...@@ -30,10 +30,6 @@ ...@@ -30,10 +30,6 @@
<td><h:outputText value="#{taskModificationView.message.user.nick}" /></td> <td><h:outputText value="#{taskModificationView.message.user.nick}" /></td>
</tr> </tr>
<tr> <tr>
<td><h:outputText class="taskHeader" value="#{i18n['actionlog.crew']}: " /></td>
<td><h:outputText value="#{taskModificationView.message.crew.name}" /></td>
</tr>
<tr>
<td><h:outputText class="taskHeader" value="#{i18n['actionlog.state']}: " /></td> <td><h:outputText class="taskHeader" value="#{i18n['actionlog.state']}: " /></td>
<td><h:outputText value="#{i18n[taskModificationView.message.state.key]}" /></td> <td><h:outputText value="#{i18n[taskModificationView.message.state.key]}" /></td>
</tr> </tr>
...@@ -45,7 +41,7 @@ ...@@ -45,7 +41,7 @@
</div> </div>
<div class="clearfix"></div> <div class="clearfix"></div>
<hr style="width: 90%;" /> <hr style="width: 90%;" />
<div> <div>
<h:form> <h:form>
<p:poll interval="1" update="messageresponsetable" onerror="location.reload();" /> <p:poll interval="1" update="messageresponsetable" onerror="location.reload();" />
......
@CHARSET "utf-8"; @CHARSET "utf-8";
/*
#actionlog_create .row { #actionlog_create .row {
display: block; display: block;
clear: both; clear: both;
...@@ -81,11 +81,11 @@ ...@@ -81,11 +81,11 @@
.taskHeader { .taskHeader {
color: #7DAC0C; color: #7DAC0C;
font-size: 120%; font-size: 120%;
font-weight: bold; font-weight: bold;
} }
.sendbutton2 { .sendbutton2 {
border: 1px solid #aaa; border: 1px solid #aaa;
margin-left: 10px; margin-left: 10px;
} }*/
\ No newline at end of file \ No newline at end of file
...@@ -22,23 +22,10 @@ public class ActionLogCreateView extends GenericCDIView { ...@@ -22,23 +22,10 @@ public class ActionLogCreateView extends GenericCDIView {
@Size(min=4,message="{actionlog.message.tooshort}") @Size(min=4,message="{actionlog.message.tooshort}")
private String message; private String message;
private Role role;
private boolean task; private boolean task;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public List<Role> getRoles() {
return actionLogBean.getAssignableRoles();
}
public Role getRole() {
return this.role;
}
public void setRole(Role role) {
this.role = role;
}
public String getMessage() { public String getMessage() {
return message; return message;
} }
...@@ -56,7 +43,7 @@ public class ActionLogCreateView extends GenericCDIView { ...@@ -56,7 +43,7 @@ public class ActionLogCreateView extends GenericCDIView {
} }
public String send() { public String send() {
actionLogBean.createActionLogEvent(message, role, task); actionLogBean.createActionLogEvent(message, task);
return "success"; return "success";
} }
} }
package fi.codecrew.moya.web.cdiview.actionlog; package fi.codecrew.moya.web.cdiview.actionlog;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.inject.Named; import javax.inject.Named;
import org.primefaces.event.SelectEvent;
import org.primefaces.model.tagcloud.DefaultTagCloudItem;
import org.primefaces.model.tagcloud.DefaultTagCloudModel;
import org.primefaces.model.tagcloud.TagCloudItem;
import org.primefaces.model.tagcloud.TagCloudModel;
import fi.codecrew.moya.beans.ActionLogBeanLocal; import fi.codecrew.moya.beans.ActionLogBeanLocal;
import fi.codecrew.moya.enums.apps.ContentPermission; import fi.codecrew.moya.enums.apps.ContentPermission;
import fi.codecrew.moya.model.ActionLogMessage; import fi.codecrew.moya.model.ActionLogMessage;
import fi.codecrew.moya.model.ActionLogMessageTag;
import fi.codecrew.moya.web.cdiview.GenericCDIView; import fi.codecrew.moya.web.cdiview.GenericCDIView;
@Named @Named
@RequestScoped @ConversationScoped
public class ActionLogMessageView extends GenericCDIView { public class ActionLogMessageView extends GenericCDIView {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private boolean updateEnabled = true; private boolean updateEnabled = true;
private TagCloudModel tagCloud = null;
private List<ActionLogMessageTag> activeTags = null;
@EJB @EJB
private transient ActionLogBeanLocal actionLogBean; private transient ActionLogBeanLocal actionLogBean;
public void initView() {
if(super.requirePermissions(ContentPermission.MANAGE_ACTIONLOG)) {
this.beginConversation();
refreshTagCloud();
if(activeTags == null) {
activeTags = new ArrayList<>();
}
}
}
public void refreshTagCloud() {
tagCloud = new DefaultTagCloudModel();
for(ActionLogMessageTag almt : actionLogBean.getAllTags()) {
tagCloud.addTag(new DefaultTagCloudItem(almt.getTag(), 1));
}
}
public boolean getUpdateEnabled() { public boolean getUpdateEnabled() {
return updateEnabled; return updateEnabled;
} }
...@@ -30,9 +63,32 @@ public class ActionLogMessageView extends GenericCDIView { ...@@ -30,9 +63,32 @@ public class ActionLogMessageView extends GenericCDIView {
} }
public List<ActionLogMessage> getMessages() { public List<ActionLogMessage> getMessages() {
if (super.hasPermission(ContentPermission.MANAGE_ACTIONLOG)) { return actionLogBean.getAllActionLogEventsByFilter(activeTags);
return actionLogBean.getAllActionLogEvents(); }
public TagCloudModel getTagCloud() {
return tagCloud;
}
public void onTagSelect(SelectEvent event) {
TagCloudItem item = (TagCloudItem)event.getObject();
ActionLogMessageTag almt = actionLogBean.getActionLogMessageTagByString(item.getLabel());
if(!activeTags.contains(almt))
activeTags.add(almt);
}
public void selectFilterTag(String tag) {
for(ActionLogMessageTag almt : this.activeTags) {
if(tag.equals(almt.getTag())) {
this.activeTags.remove(almt);
break;
}
} }
return null; }
public List<ActionLogMessageTag> getActiveTags() {
return this.activeTags;
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!