+ more validation
+ working dark theme - some bugs Signed-off-by: Johannes Theiner <j.theiner@live.de>
This commit is contained in:
parent
5bc0162cf2
commit
48724a5853
|
@ -77,7 +77,7 @@ public class Database {
|
|||
private Database() {
|
||||
Configuration config = Configuration.get();
|
||||
dataSource = new MariaDbPoolDataSource("jdbc:mysql://" + config.getDatabase().getHostname()
|
||||
+ ":" + config.getDatabase().getPort() + "/" + config.getDatabase().getDatabase() + "?useUnicode=true&characterEncoding=UTF-8");
|
||||
+ ":" + config.getDatabase().getPort() + "/" + config.getDatabase().getDatabase() + "?useUnicode=true&characterEncoding=UTF-8&maxPoolSize=10&pool");
|
||||
try {
|
||||
dataSource.setUser(config.getDatabase().getUsername());
|
||||
dataSource.setPassword(config.getDatabase().getPassword());
|
||||
|
|
|
@ -6,6 +6,7 @@ import lombok.Setter;
|
|||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.faces.annotation.ManagedProperty;
|
||||
import javax.faces.application.FacesMessage;
|
||||
import javax.faces.bean.ManagedBean;
|
||||
import javax.faces.bean.SessionScoped;
|
||||
import javax.faces.context.FacesContext;
|
||||
|
@ -45,31 +46,44 @@ public class CartBean {
|
|||
if (getUser() != null && getUser().getId() != 0) {
|
||||
for (ShoppingCartItem item : getItems()) {
|
||||
if (item.getArticle().getId() == book.getId()) {
|
||||
if(item.getCount() >= 127) {
|
||||
items = getFreshItems();
|
||||
FacesContext.getCurrentInstance().addMessage("count:count", new FacesMessage("Es können maximal 127 eines Artikels auf einmal gekauft werden."));
|
||||
return "cart.jsf";
|
||||
}
|
||||
Database.getInstance().shoppingCart().delete(item);
|
||||
item.setCount(item.getCount() + 1);
|
||||
Database.getInstance().shoppingCart().insert(item);
|
||||
items = getFreshItems();
|
||||
return "cart.jsf";
|
||||
}
|
||||
}
|
||||
Database.getInstance().shoppingCart().insert(new ShoppingCartItem(getUser(), book, 1));
|
||||
}
|
||||
items = getFreshItems();
|
||||
return "cart.jsf";
|
||||
}
|
||||
|
||||
public String remove(ShoppingCartItem item) {
|
||||
if (getUser() != null) {
|
||||
Database.getInstance().shoppingCart().delete(item);
|
||||
items = getFreshItems();
|
||||
}
|
||||
return "cart.jsf";
|
||||
}
|
||||
|
||||
public List<ShoppingCartItem> getItems() {
|
||||
if(items != null) return items;
|
||||
if(items == null)
|
||||
items = getFreshItems();
|
||||
return items;
|
||||
}
|
||||
|
||||
private List<ShoppingCartItem> getFreshItems() {
|
||||
Database db = Database.getInstance();
|
||||
if (getUser() != null) {
|
||||
items = db.shoppingCart().get(getUser());
|
||||
} else {
|
||||
items = new ArrayList<ShoppingCartItem>();
|
||||
items = new ArrayList<>();
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
@ -88,18 +102,23 @@ public class CartBean {
|
|||
|
||||
public String buy() {
|
||||
ArrayList<OrderItem> orderList = new ArrayList<>();
|
||||
for (ShoppingCartItem item : getItems()) {
|
||||
for (ShoppingCartItem item : getFreshItems()) {
|
||||
orderList.add(new OrderItem(item.getArticle(), item.getCount()));
|
||||
}
|
||||
Database.getInstance().order().insert(new Order(getUser(), orderList, new Date(System.currentTimeMillis()), sum(), getPayment(), getAddress()));
|
||||
for (ShoppingCartItem item : getItems()) {
|
||||
for (ShoppingCartItem item : getFreshItems()) {
|
||||
Database.getInstance().shoppingCart().delete(item);
|
||||
}
|
||||
items = getFreshItems();
|
||||
return "thanks.jsf";
|
||||
}
|
||||
|
||||
public int getItemCount() {
|
||||
return getItems().size();
|
||||
int count = 0;
|
||||
for(ShoppingCartItem item : getItems()) {
|
||||
count += item.getCount();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public long sum() {
|
||||
|
|
|
@ -10,6 +10,7 @@ import lombok.Setter;
|
|||
import javax.faces.bean.ManagedBean;
|
||||
import javax.faces.bean.RequestScoped;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.validation.constraints.Future;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
@ -38,6 +39,7 @@ public class CreditCardBean implements Serializable {
|
|||
|
||||
@Getter
|
||||
@Setter
|
||||
@Future
|
||||
private Date expiration;
|
||||
|
||||
@Getter
|
||||
|
|
|
@ -9,6 +9,7 @@ import lombok.Setter;
|
|||
import javax.faces.bean.ManagedBean;
|
||||
import javax.faces.bean.RequestScoped;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
|
@ -27,6 +28,7 @@ public class PayPalBean implements Serializable {
|
|||
|
||||
@Getter
|
||||
@Setter
|
||||
@Pattern(regexp = "(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])")
|
||||
private String mail;
|
||||
|
||||
@Getter
|
||||
|
|
|
@ -19,6 +19,6 @@ public class SettingsBean {
|
|||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean darkTheme = true;
|
||||
private boolean darkTheme = false;
|
||||
|
||||
}
|
|
@ -64,7 +64,8 @@ public class UserBean implements Serializable {
|
|||
public String logout() {
|
||||
user = null;
|
||||
loggedIn = false;
|
||||
return "index.html";
|
||||
FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
|
||||
return "/index.xhtml?faces-redirect=true";
|
||||
}
|
||||
|
||||
public String register() {
|
||||
|
|
|
@ -38,9 +38,10 @@
|
|||
</div>
|
||||
<div class="m-row">
|
||||
<div class="m-col-t-4 m-push-t-6">
|
||||
<h:form>
|
||||
<h:inputText value="#{item.count}" valueChangeListener="#{cartBean.change}">
|
||||
<h:form id="count">
|
||||
<h:inputText id="count" value="#{item.count}" valueChangeListener="#{cartBean.change}">
|
||||
<f:validateLength minimum="1" maximum="3"/>
|
||||
<f:validateLongRange minimum="1" maximum="127"/>
|
||||
<f:ajax />
|
||||
</h:inputText>
|
||||
</h:form>
|
||||
|
@ -68,10 +69,14 @@
|
|||
</div>
|
||||
</h:panelGroup>
|
||||
|
||||
<h:panelGroup layout="block" styleClass="m-row" rendered="#{cartBean.itemCount == 0}">
|
||||
<h:panelGroup layout="block" styleClass="m-row" rendered="#{not userBean.loggedIn}">
|
||||
<h1 class="m-text-center">Bitte melden Sie sich an um Bücher in ihrem Warenkorb hinzuzufügen.</h1>
|
||||
</h:panelGroup>
|
||||
|
||||
<h:panelGroup layout="block" styleClass="m-row" rendered="#{cartBean.itemCount == 0}">
|
||||
<h1 class="m-text-center">Ihr Warenkorb ist leer.</h1>
|
||||
</h:panelGroup>
|
||||
|
||||
|
||||
<h:panelGroup layout="block" styleClass="m-row" rendered="#{cartBean.itemCount != 0}">
|
||||
<div class="m-col-t-4 m-push-t-4 m-button m-success">
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
<ul>
|
||||
<ui:repeat value="#{order.items}" var="item">
|
||||
<li>
|
||||
#{item.book.title} - #{item.book.authorsString}
|
||||
#{item.count} x #{item.book.title} - #{item.book.authorsString}
|
||||
</li>
|
||||
</ui:repeat>
|
||||
</ul>
|
||||
|
|
|
@ -73,15 +73,9 @@
|
|||
<li>Dark Theme
|
||||
<h:form>
|
||||
<div class="onoffswitch">
|
||||
|
||||
<h:selectBooleanCheckbox styleClass="onoffswitch-checkbox"
|
||||
id="myonoffswitch"
|
||||
title="onoffswitch" onchange="changeTheme()"
|
||||
value="#{settingsBean.darkTheme}"/>
|
||||
<h:outputLabel styleClass="onoffswitch-label" for="myonoffswitch">
|
||||
<span class="onoffswitch-inner"/>
|
||||
<span class="onoffswitch-switch"/>
|
||||
</h:outputLabel>
|
||||
<h:selectBooleanCheckbox title="onoffswitch" onchange="changeTheme()" value="#{settingsBean.darkTheme}">
|
||||
<f:ajax/>
|
||||
</h:selectBooleanCheckbox>
|
||||
</div>
|
||||
</h:form>
|
||||
</li>
|
||||
|
|
Loading…
Reference in New Issue