Commit 356d26bf by Tuomas Riihimäki

Merge branch 'helpthingy2' into 'master'

Help for ewery page

There is possibility to create global help on every page. This must be tested with multible events when put in production (or beforehand).

See merge request !323
2 parents 220fddf4 9868f9ab
Showing with 916 additions and 20 deletions
/*
* Copyright Codecrew Ry
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
package fi.codecrew.moya.beans;
import fi.codecrew.moya.model.Help;
import fi.codecrew.moya.model.HelpText;
import javax.ejb.Local;
import java.util.Locale;
@Local
public interface HelpBeanLocal {
HelpText getHelpForPage(String pagepath, Locale locale);
Help findOrCreateHelp(String pagepath);
HelpText saveOrCreate(HelpText help);
}
......@@ -343,6 +343,58 @@ public class BootstrapBean implements BootstrapBeanLocal {
deleteMenu("/useradmin/changePassword");
dbUpdates.add(new String[] {
"CREATE TABLE helps (id SERIAL NOT NULL, path TEXT, meta json, PRIMARY KEY (id))",
"CREATE TABLE help_texts (id SERIAL NOT NULL, " +
"title TEXT, " +
"description TEXT, " +
"locale TEXT, " +
"meta json, " +
"last_edit_time TIMESTAMPTZ NOT NULL, " +
"users_id INTEGER NOT NULL, " +
"helps_id INTEGER NOT NULL, " +
"PRIMARY KEY (id))",
"ALTER TABLE help_texts " +
"ADD CONSTRAINT FK_help_texts_users_id " +
"FOREIGN KEY (users_id) REFERENCES users (id)",
"ALTER TABLE help_texts " +
"ADD CONSTRAINT FK_help_texts_helps_id " +
"FOREIGN KEY (helps_id) REFERENCES helps (id)",
"CREATE TABLE help_text_histories (id SERIAL NOT NULL, " +
"title TEXT, " +
"description TEXT, " +
"meta json, " +
"edit_time TIMESTAMPTZ NOT NULL, " +
"help_texts_id INTEGER NOT NULL, " +
"users_id INTEGER NOT NULL, " +
"PRIMARY KEY (id))",
"ALTER TABLE help_text_histories " +
"ADD CONSTRAINT FK_help_text_histories_help_texts_id " +
"FOREIGN KEY (help_texts_id) REFERENCES help_texts (id)",
});
dbUpdates.add(new String[] {
"ALTER TABLE help_texts DROP COLUMN users_id;",
"ALTER TABLE help_texts ADD COLUMN event_users_id INTEGER NOT NULL;",
"ALTER TABLE help_text_histories DROP COLUMN users_id;",
"ALTER TABLE help_text_histories ADD COLUMN event_users_id INTEGER NOT NULL;",
"ALTER TABLE help_texts " +
"ADD CONSTRAINT FK_help_texts_event_users_id " +
"FOREIGN KEY (event_users_id) REFERENCES event_users (id)",
"ALTER TABLE help_text_histories " +
"ADD CONSTRAINT FK_help_text_histories_event_users_id " +
"FOREIGN KEY (event_users_id) REFERENCES event_users (id)",
});
dbUpdates.add(new String[] {
"ALTER TABLE help_texts DROP COLUMN title;"
});
}
public BootstrapBean() {
......
/*
* Copyright Codecrew Ry
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
package fi.codecrew.moya.beans;
import fi.codecrew.moya.enums.ValidLocale;
import fi.codecrew.moya.enums.apps.SpecialPermission;
import fi.codecrew.moya.enums.apps.UserPermission;
import fi.codecrew.moya.facade.HelpFacade;
import fi.codecrew.moya.facade.HelpTextFacade;
import fi.codecrew.moya.facade.HelpTextHistoryFacade;
import fi.codecrew.moya.model.Help;
import fi.codecrew.moya.model.HelpText;
import fi.codecrew.moya.model.HelpTextHistory;
import javax.annotation.security.RolesAllowed;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import java.util.Calendar;
import java.util.Locale;
/**
* Session Bean implementation class SitePageBean
*/
@Stateless
@LocalBean
public class HelpBean implements HelpBeanLocal {
@EJB
HelpFacade helpFacade;
@EJB
HelpTextFacade helpTextFacade;
@EJB
HelpTextHistoryFacade helpTextHistoryFacade;
@EJB
PermissionBean permissionBean;
/**
* Default constructor.
*/
public HelpBean() {
// TODO Auto-generated constructor stub
}
/**
* Finds help for specific page on wanted locale.
*
* @param pagepath path or "key" of page
* @param locale Wanted locale
* @return Help for wanted locale, if there is no help for that locale return help on default locale (or null if there is no help for default locale)
*/
@Override
public HelpText getHelpForPage(String pagepath, Locale locale) {
ValidLocale validLocale = ValidLocale.findFromLocale(locale);
HelpText help = helpTextFacade.find(pagepath, validLocale);
if(help == null && validLocale != ValidLocale.getDefaultLocale()) {
help = helpTextFacade.find(pagepath, ValidLocale.getDefaultLocale());
}
return help;
}
@Override
public Help findOrCreateHelp(String pagepath) {
Help help = helpFacade.findByPath(pagepath);
if (help == null) {
help = new Help(pagepath);
helpFacade.create(help);
}
return help;
}
@Override
@RolesAllowed(UserPermission.S_EDIT_HELP)
public HelpText saveOrCreate(HelpText help) {
help.setLastEdited(Calendar.getInstance().getTime());
help.setLastEditor(permissionBean.getCurrentUser());
if(help.getId() == null) {
helpTextFacade.create(help);
} else {
helpTextFacade.merge(help);
}
HelpTextHistory history = new HelpTextHistory(help);
helpTextHistoryFacade.create(history);
return help;
}
}
/*
* Copyright Codecrew Ry
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
package fi.codecrew.moya.facade;
import fi.codecrew.moya.model.Help;
import fi.codecrew.moya.model.Help_;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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;
/**
* Created by tuukka on 19/12/15.
*/
@Stateless
@LocalBean
public class HelpFacade extends IntegerPkGenericFacade<Help> {
private static final Logger logger = LoggerFactory.getLogger(HelpFacade.class);
public HelpFacade() {
super(Help.class);
}
public Help findByPath(String pagepath) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Help> cq = cb.createQuery(Help.class);
Root<Help> root = cq.from(Help.class);
cq.where(cb.equal(root.get(Help_.path), pagepath));
TypedQuery<Help> query = getEm().createQuery(cq);
query.setMaxResults(1);
return super.getSingleNullableResult(query);
}
}
/*
* Copyright Codecrew Ry
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
package fi.codecrew.moya.facade;
import fi.codecrew.moya.enums.ValidLocale;
import fi.codecrew.moya.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.Path;
import javax.persistence.criteria.Root;
/**
* Created by tuukka on 19/12/15.
*/
@Stateless
@LocalBean
public class HelpTextFacade extends IntegerPkGenericFacade<HelpText> {
private static final Logger logger = LoggerFactory.getLogger(HelpTextFacade.class);
public HelpTextFacade() {
super(HelpText.class);
}
public HelpText find(String path, ValidLocale locale) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<HelpText> cq = cb.createQuery(HelpText.class);
Root<HelpText> root = cq.from(HelpText.class);
cq.where(
cb.and(cb.equal(root.get(HelpText_.help).get(Help_.path), path),
cb.equal(root.get(HelpText_.locale), locale))
);
TypedQuery<HelpText> query = getEm().createQuery(cq);
query.setMaxResults(1);
return super.getSingleNullableResult(query);
}
}
/*
* Copyright Codecrew Ry
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
package fi.codecrew.moya.facade;
import fi.codecrew.moya.model.HelpText;
import fi.codecrew.moya.model.HelpTextHistory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
/**
* Created by tuukka on 19/12/15.
*/
@Stateless
@LocalBean
public class HelpTextHistoryFacade extends IntegerPkGenericFacade<HelpTextHistory> {
private static final Logger logger = LoggerFactory.getLogger(HelpTextHistoryFacade.class);
public HelpTextHistoryFacade() {
super(HelpTextHistory.class);
}
}
/*
* Copyright Codecrew Ry
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package fi.codecrew.moya.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
* Group for lectures, so you can set limits how many of these the user can
* choose
*/
@Entity
@Table(name = "helps")
public class Help extends GenericEntity {
private static final long serialVersionUID = 1L;
@Column(name = "path")
private String path;
public Help(String path) {
this.path = path;
}
public Help() {
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
}
/*
* Copyright Codecrew Ry
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package fi.codecrew.moya.model;
import fi.codecrew.moya.enums.ValidLocale;
import javax.persistence.*;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
/**
* Group for lectures, so you can set limits how many of these the user can
* choose
*/
@Entity
@Table(name = "help_texts")
public class HelpText extends GenericEntity {
private static final long serialVersionUID = 1L;
@Column(name = "description")
private String text;
@ManyToOne()
@JoinColumn(name = "helps_id", nullable = false)
private Help help;
@Enumerated(EnumType.STRING)
@Column(name = "locale")
private ValidLocale locale;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "last_edit_time")
private Date lastEdited;
@ManyToOne()
@JoinColumn(name = "event_users_id", nullable = false)
private EventUser lastEditor;
public HelpText(Help help, ValidLocale locale) {
this.help = help;
this.locale = locale;
}
public HelpText() {
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public Help getHelp() {
return help;
}
public void setHelp(Help help) {
this.help = help;
}
public ValidLocale getLocale() {
return locale;
}
public void setLocale(ValidLocale locale) {
this.locale = locale;
}
public Date getLastEdited() {
return lastEdited;
}
public void setLastEdited(Date lastEdited) {
this.lastEdited = lastEdited;
}
public EventUser getLastEditor() {
return lastEditor;
}
public void setLastEditor(EventUser lastEditor) {
this.lastEditor = lastEditor;
}
}
/*
* Copyright Codecrew Ry
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package fi.codecrew.moya.model;
import javax.persistence.*;
import java.util.Date;
/**
* Group for lectures, so you can set limits how many of these the user can
* choose
*/
@Entity
@Table(name = "help_text_histories")
public class HelpTextHistory extends GenericEntity {
private static final long serialVersionUID = 1L;
@ManyToOne()
@JoinColumn(name = "help_texts_id", nullable = false)
HelpText helpText;
@Column(name = "title")
private String title;
@Column(name = "description")
private String text;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "edit_time")
private Date edited;
@ManyToOne()
@JoinColumn(name = "event_users_id", nullable = false)
private EventUser editor;
public HelpTextHistory() {
}
/**
* Create new history entity for specific helpText
* @param parent
*/
public HelpTextHistory(HelpText parent) {
this.text = parent.getText();
this.edited = parent.getLastEdited();
this.editor = parent.getLastEditor();
this.helpText = parent;
}
public HelpText getHelpText() {
return helpText;
}
public void setHelpText(HelpText helpText) {
this.helpText = helpText;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public Date getEdited() {
return edited;
}
public void setEdited(Date edited) {
this.edited = edited;
}
public EventUser getEditor() {
return editor;
}
public void setEditor(EventUser editor) {
this.editor = editor;
}
}
......@@ -16,7 +16,7 @@
* future versions of the Software.
*
*/
package fi.codecrew.moya.web;
package fi.codecrew.moya.enums;
import java.util.Locale;
......@@ -26,12 +26,26 @@ public enum ValidLocale {
private final Locale locale;
ValidLocale(Locale l)
{
ValidLocale(Locale l) {
this.locale = l;
}
public Locale getLocale() {
return locale;
}
public static ValidLocale getDefaultLocale() {
return ValidLocale.ENGLISH;
}
public static ValidLocale findFromLocale(Locale locale) {
for (ValidLocale l : values()) {
if (l.getLocale().equals(locale)) {
return l;
}
}
return ValidLocale.getDefaultLocale();
}
}
\ No newline at end of file
......@@ -43,6 +43,7 @@ public enum UserPermission implements IAppPermission {
MODIFY_OWN_GAMEIDS,
VIEW_ALL_GAMEIDS,
HELPPAGE,
EDIT_HELP,
;
public static final String S_VIEW_ALL = "USER/VIEW_ALL";
......@@ -66,6 +67,7 @@ public enum UserPermission implements IAppPermission {
public static final String S_MODIFY_OWN_GAMEIDS = "USER/MODIFY_OWN_GAMEIDS";
public static final String S_VIEW_ALL_GAMEIDS = "USER/VIEW_ALL_GAMEIDS";
public static final String S_HELPPAGE = "USER/HELPPAGE";
public static final String S_EDIT_HELP = "USER/EDIT_HELP";
private final String fullName;
private final String key;
......
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:tools="http://java.sun.com/jsf/composite/tools"
xmlns:p="http://primefaces.org/ui"
xmlns:pe="http://primefaces.org/ui/extensions"
>
<composite:interface>
</composite:interface>
<composite:implementation>
<h:form>
<p:commandButton rendered="#{helpView.helpAvailable or helpView.permissionToEdit}" icon="ui-icon-help" title="#{i18n['help.title']}" onclick="PF('showHelpDialog').show()" />
<!-- Sorry abt. this dialog mess, I was too lazy to find working way to do inline -editing with ckEditor -TK -->
<p:dialog widgetVar="showHelpDialog" header="#{i18n['help.title']}" >
<p:outputPanel id="helpPanel">
<p:outputPanel rendered="#{helpView.helpAvailable}" >
<h:outputText value="#{helpView.helpText}" escape="false" />
<br /><br />
<p:commandButton rendered="#{helpView.permissionToEdit}" value="#{i18n['help.edit']}" onclick="PF('editHelpDialog').show();PF('showHelpDialog').hide();" />
</p:outputPanel>
<p:outputPanel rendered="#{not helpView.helpAvailable and helpView.permissionToEdit}" id="helpPanelPlaceholder" >
<h2><h:outputText value="#{i18n['help.placeholder.title']}" /></h2>
<br />
<p:commandButton value="#{i18n['help.add']}" onclick="PF('editHelpDialog').show();PF('showHelpDialog').hide();" />
</p:outputPanel>
</p:outputPanel>
</p:dialog>
<p:dialog widgetVar="editHelpDialog" header="#{i18n['help.dialog.header']}" >
<p:outputPanel>
<pe:ckEditor id="editors" value="#{helpView.helpText}" toolbar="
[['Bold','Italic','Underline','Strike','TextColor'],
['NumberedList','BulletedList','Outdent', 'Indent'],
['Image','Table','HorizontalRule','Iframe'],
['Format','FontSize'],
['RemoveFormat', 'Save']]">
<p:ajax event="save" listener="#{helpView.saveHelpText}" update="helpPanel" oncomplete="PF('showHelpDialog').show();PF('editHelpDialog').hide();"/>
</pe:ckEditor>
</p:outputPanel>
<span class="error"><h:outputText value="#{i18n['help.globalWarning']}" /></span>
</p:dialog>
</h:form>
</composite:implementation>
</html>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html class="no-js" xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:tools="http://java.sun.com/jsf/composite/cditools" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:p="http://primefaces.org/ui">
xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:p="http://primefaces.org/ui"
xmlns:help="http://java.sun.com/jsf/composite/cditools/help"
xmlns:pe="http://primefaces.org/ui/extensions"
>
<f:view contentType="text/html" locale="#{sessionHandler.locale}">
<h:head>
<pe:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><h:outputText value="#{layoutView.getHeader()}" /></title>
......@@ -36,7 +39,7 @@
}
</h:outputStylesheet>
</h:head>
</pe:head>
<h:body>
......@@ -48,7 +51,9 @@
<p:dialog widgetVar="keepAliveDialog" showEffect="fade" hideEffect="explode" header="#{i18n['template.keepaliveError.title']}" modal="true">
<br />#{i18n['template.keepaliveError']}<br /><br />
<p:commandButton value="OK" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" onclick="location.reload();" />
<h:form>
<p:commandButton value="OK" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" onclick="location.reload();" />
</h:form>
</p:dialog>
<script type="text/javascript">
......@@ -177,18 +182,24 @@
<p:layoutUnit position="center">
<div class="container top">
<h:form id="selectLanguage">
<p:selectOneButton id="langselect" styleClass="languageSelector" value="#{sessionStore.locale}" immediate="true" converter="#{localeConverter}">
<f:selectItems value="#{localeSelectorView.availableLocales}" var="loc" itemValue="#{loc.locale}" itemLabel="#{loc.locale.displayName}" />
<p:ajax update="@all" event="change" />
</p:selectOneButton>
</h:form>
<div style="float: left;">
<h:form id="selectLanguage">
<p:selectOneButton id="langselect" styleClass="languageSelector" value="#{sessionStore.locale}" immediate="true" converter="#{localeConverter}">
<f:selectItems value="#{localeSelectorView.availableLocales}" var="loc" itemValue="#{loc.locale}" itemLabel="#{loc.locale.displayName}" />
<p:ajax update="@all" event="change" />
</p:selectOneButton>
</h:form>
<h:link rendered="#{layoutView.manageContent}" styleClass="editorlink" value="#{i18n['layout.editTop']}" outcome="/pages/manage">
<f:param name="pagename" value="#{layoutView.pagepath}:top" />
</h:link>
<h:link rendered="#{layoutView.manageContent}" styleClass="editorlink" value="#{i18n['layout.editTop']}" outcome="/pages/manage">
<f:param name="pagename" value="#{layoutView.pagepath}:top" />
</h:link>
</div>
<div style="float: right;">
<help:helptool />
</div>
<div style="clear: both;"> </div>
</div>
......@@ -233,8 +244,6 @@
<h:form>
<!-- <p:growl id="growl" showDetail="true" sticky="true" autoUpdate="true" /> -->
<p:confirmDialog global="true" showEffect="fade" hideEffect="explode">
<p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
<p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
......
......@@ -30,6 +30,16 @@
<artifactId>primefaces</artifactId>
<version>${primefaces.version}</version>
</dependency>
<dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>primefaces-extensions</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>resources-ckeditor</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
......
......@@ -22,6 +22,7 @@ import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import fi.codecrew.moya.enums.ValidLocale;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......
/*
* Copyright Codecrew Ry
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
package fi.codecrew.moya.web.cdiview.help;
import fi.codecrew.moya.beans.HelpBeanLocal;
import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.enums.ValidLocale;
import fi.codecrew.moya.enums.apps.UserPermission;
import fi.codecrew.moya.handler.SessionStore;
import fi.codecrew.moya.model.Help;
import fi.codecrew.moya.model.HelpText;
import fi.codecrew.moya.web.helper.LayoutView;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
/**
* Created by tuukka on 19/12/15.
*/
@Named
@RequestScoped
public class HelpView {
// layoutview.getPagepath()
@Inject
LayoutView layoutView;
@EJB
HelpBeanLocal helpBean;
@EJB
PermissionBeanLocal permissionBean;
String helpText = null;
@Inject
private transient SessionStore sessionstore;
public void populateHelpText() {
HelpText help = helpBean.getHelpForPage(layoutView.getPagepath(), sessionstore.getLocale());
if(help == null) {
helpText = "";
} else {
helpText = help.getText();
}
}
public void saveHelpText() {
if(helpText == null || helpText.trim().isEmpty()) {
// todo: errormessage
return;
}
HelpText help = helpBean.getHelpForPage(layoutView.getPagepath(), sessionstore.getLocale());
if(help == null) {
help = new HelpText(helpBean.findOrCreateHelp(layoutView.getPagepath()), ValidLocale.findFromLocale(sessionstore.getLocale()));
}
help.setText(getHelpText());
helpBean.saveOrCreate(help);
}
public boolean isHelpAvailable() {
return !getHelpText().isEmpty();
}
public void setHelpText(String helpText) {
this.helpText = helpText;
}
public String getHelpText() {
if(helpText == null) {
populateHelpText();
}
return helpText;
}
public boolean isPermissionToEdit() {
return permissionBean.hasPermission(UserPermission.EDIT_HELP);
}
}
......@@ -77,8 +77,6 @@ public class MenuView {
public List<PageContent> getPagecontent(String pagekey)
{
String key = new StringBuilder(layoutview.getPagepath()).append(":").append(pagekey).toString();
// Removed by tkfftk, enought is enought
// logger.debug("Getting pagecontent for key {}. Matches: {}", key, contents.containsKey(key));
if (!contents.containsKey(key)) {
contents.put(key, pagebean.findContentsForUser(key, sessionstore.getLocale()));
......
......@@ -335,6 +335,13 @@ global.notAuthorizedExecute = You are not authorized to do that!
global.notauthorized = You don't have enough rights to enter this site.
global.save = Save
help.edit=Edit help
help.placeholder.content=help.add=Create help for page
help.content=Help content
help.dialog.header=Edit page help
You can add help by pressing button under this text.
help.placeholder.title=No help for page
help.title=Help for page
httpsession.creationTime = Created
httpsession.hostname = Hostname
httpsession.id = ID
......@@ -1548,3 +1555,6 @@ voting.create.voteEnd = Voting close
voting.create.voteStart = Voting start
yes = Yes
help.globalWarning=Helptexts are globals, and shared between every events\!
bortalApplication.user.HELPPAGE=Can see help page
bortalApplication.user.EDIT_HELP=Can edit help texts
......@@ -548,6 +548,13 @@ global.notAuthorizedExecute = You are not authorized to do that!
global.notauthorized = You don't have enough rights to enter this site.
global.save = Save
help.add=Create help for page
help.content=Help content
help.dialog.header=Edit page help
help.edit=Edit help
help.placeholder.content=You can add help by pressing button under this text.
help.placeholder.title=No help for page
help.title=Help for page
httpsession.creationTime = Created
httpsession.hostname = Hostname
httpsession.id = ID
......@@ -1821,3 +1828,6 @@ voting.create.voteEnd = Voting close
voting.create.voteStart = Voting start
yes = Yes
help.globalWarning=Helptexts are globals, and shared between every events\!
bortalApplication.user.HELPPAGE=Can see help page
bortalApplication.user.EDIT_HELP=Can edit help texts
......@@ -549,6 +549,13 @@ global.notAuthorizedExecute = Sinulla ei ole riitt\u00E4v\u00E4sti oikeuksia suo
global.notauthorized = Sinulla ei ole riitt\u00E4vi\u00E4 oikeuksia t\u00E4lle sivulle.
global.save = Tallenna
help.add=Luo ohje sivulle
help.content=Ohjeen sis\u00E4lt\u00F6
help.dialog.header=Muokkaa sivun ohjetta
help.edit=Muokkaa ohjetta
help.placeholder.content=Voit lis\u00E4t\u00E4 ohjeen allaolevalla napilla.
help.placeholder.title=Ei ohjetta sivulle
help.title=Ohje sivulle
httpsession.creationTime = Luotu
httpsession.hostname = Hostname
httpsession.id = ID
......@@ -1808,3 +1815,6 @@ voting.create.voteEnd = \u00C4\u00E4nestys kiinni
voting.create.voteStart = \u00C4\u00E4nestys auki
yes = Kyll\u00E4
help.globalWarning=Ohjeet ovat universaaleja ja ne n\u00E4kyv\u00E4t kaikissa moya-lippukaupoissa\!
bortalApplication.user.HELPPAGE=N\u00E4kee ohjesivun
bortalApplication.user.EDIT_HELP=Voi muokata ohjeita
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!