Commit ec408636 by Tuomas Riihimäki

Add holderizing of printed cards to the web app

This is compatible with the old holderizing software by vectorama.
but works with HID usb readers, instead of serial readers.
1 parent 03676fde
Pipeline #160 passed
in 0 seconds
<!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:c="http://java.sun.com/jsp/jstl/core" xmlns:p="http://primefaces.org/ui"
>
<h:body>
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
<f:event type="preRenderView" listener="#{cardHolderizeView.init}"/>
</f:metadata>
<ui:define name="content">
<h2><h:outputText value="#{i18n['holderize.header']}" /></h2>
<h:form id="holderform">
<h2><h:outputText value="#{i18n['holderize.parametersHeader']}"/></h2>
<h:panelGrid columns="2">
<h:outputLabel value="#{i18n['holderize.pageColumns']}"/>
<p:inputText value="#{cardHolderizeView.cols}"/>
<h:outputLabel value="#{i18n['holderize.pageRows']}"/>
<p:inputText value="#{cardHolderizeView.rows}"/>
</h:panelGrid>
<h2><h:outputText value="#{i18n['holderize.nextCodeHeader']}" /></h2>
<p:focus for="code"/>
<h:panelGrid columns="2">
<h:outputLabel value="#{i18n['holderize.folderName']}"/>
<p:inputText value="#{cardHolderizeView.currentFolder}"/>
<h:outputLabel value="#{i18n['holderize.page']}"/>
<p:inputText value="#{cardHolderizeView.currentPage}">
<f:convertNumber maxFractionDigits="0" minFractionDigits="0"/>
</p:inputText>
<h:outputLabel value="#{i18n['holderize.column']}"/>
<p:inputText value="#{cardHolderizeView.currentCol}">
<f:convertNumber maxFractionDigits="0" minFractionDigits="0"/>
</p:inputText>
<h:outputLabel value="#{i18n['holderize.row']}"/>
<p:inputText value="#{cardHolderizeView.currentRow}">
<f:convertNumber maxFractionDigits="0" minFractionDigits="0"/>
</p:inputText>
<h:outputLabel value="#{i18n['holderize.barcode']}"/>
<p:inputText id="code" value="#{cardHolderizeView.code}">
</p:inputText>
</h:panelGrid>
<p:commandButton update="holderform" action="#{cardHolderizeView.holderizeCard()}" value="Holderize"/>
<h3>History</h3>
<p:dataTable value="#{cardHolderizeView.queue}" var="card">
<p:column>
<p:link outcome="/useradmin/edit" value="#{card.user.wholeName}">
<f:param name="userid" value="#{card.user.user.id}"/>
</p:link>
</p:column>
<p:column>
<h:outputText value="#{card.meta.getJsonObject('card-filing').getString('cardplace')}"/>
</p:column>
</p:dataTable>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
/*
* 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.user;
import fi.codecrew.moya.beans.*;
import fi.codecrew.moya.enums.CardState;
import fi.codecrew.moya.enums.apps.UserPermission;
import fi.codecrew.moya.model.*;
import fi.codecrew.moya.rest.meta.v1.PrintedCardRestViewV1;
import fi.codecrew.moya.util.MassPrintResult;
import fi.codecrew.moya.utilities.jsf.MessageHelper;
import fi.codecrew.moya.web.annotations.LoggedIn;
import fi.codecrew.moya.web.annotations.SelectedUser;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
import fi.codecrew.moya.web.cdiview.reader.ReaderView;
import fi.codecrew.moya.web.helper.LayoutView;
import org.primefaces.event.CaptureEvent;
import org.primefaces.event.FileUploadEvent;
import org.primefaces.model.CroppedImage;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;
import org.primefaces.model.UploadedFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ejb.EJB;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.ConversationScoped;
import javax.enterprise.inject.Produces;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent;
import javax.inject.Inject;
import javax.inject.Named;
import javax.json.*;
import javax.json.stream.JsonGenerator;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Named()
@ConversationScoped
public class CardHolderizeView extends GenericCDIView {
@EJB
private CardPrintBeanLocal cardbean;
@EJB
private CardTemplateBeanLocal tplbean;
@EJB
private UserBeanLocal userbean;
@EJB
private ReaderBeanLocal readerbean;
private int cols = 1;
private int rows = 5;
private String code;
private String currentFolder = "A";
private int currentPage = 1;
private int currentCol = 1;
private int currentRow = 1;
private static final Logger logger = LoggerFactory.getLogger(CardHolderizeView.class);
private List<PrintedCard> queue;
private int QUE_HISTORY_SIZE = 10;
public void init() {
if (queue == null) {
queue = new ArrayList<>();
super.beginConversation();
}
}
public void holderizeCard() {
logger.warn("Holderizing card {}", code);
ReaderEvent event = readerbean.checkCode(code);
logger.warn("got event from card code {}, card {}", code, event.getPrintedCard());
if (event == null || event.getPrintedCard() == null) {
super.addFaceMessage("printecard.not-found");
return;
}
StringBuilder sb = new StringBuilder();
sb.append(currentFolder);
sb.append(" / ").append(currentPage);
sb.append(" / ").append(currentCol);
sb.append(" / ").append(currentRow);
PrintedCard card = event.getPrintedCard();
JsonObjectBuilder metaBuilder = Json.createObjectBuilder();
JsonObject meta = card.getMeta();
JsonObjectBuilder filingBuilder = Json.createObjectBuilder();
if (meta != null) {
meta.entrySet().forEach(e -> metaBuilder.add(e.getKey(), e.getValue()));
JsonObject filingObj = meta.getJsonObject("card-filing");
if (filingObj != null) {
filingObj.entrySet().forEach(e -> filingBuilder.add(e.getKey(), e.getValue()));
}
}
filingBuilder.add("cardplace", sb.toString());
metaBuilder.add("card-filing", filingBuilder);
card.setMeta(metaBuilder.build());
PrintedCard saved = tplbean.saveCard(card);
queue.add(0, saved);
while (queue.size() > QUE_HISTORY_SIZE) {
queue.remove(queue.size() - 1);
}
increaseSlot();
code = "";
}
private void increaseSlot() {
if (++currentRow > rows) {
currentRow = 1;
if (++currentCol > cols) {
currentCol = 1;
++currentPage;
}
}
}
public int getCols() {
return cols;
}
public void setCols(int cols) {
this.cols = cols;
}
public int getRows() {
return rows;
}
public void setRows(int rows) {
this.rows = rows;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getCurrentFolder() {
return currentFolder;
}
public void setCurrentFolder(String currentFolder) {
this.currentFolder = currentFolder;
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getCurrentCol() {
return currentCol;
}
public void setCurrentCol(int currentCol) {
this.currentCol = currentCol;
}
public int getCurrentRow() {
return currentRow;
}
public void setCurrentRow(int currentRow) {
this.currentRow = currentRow;
}
public List<PrintedCard> getQueue() {
return queue;
}
public void setQueue(List<PrintedCard> queue) {
this.queue = queue;
}
}
......@@ -1934,3 +1934,13 @@ feature.user_permission = User
feature.info_permission = Organizer
feature.admin_permission = Administrator
role.features = Event feature permissions
holderize.header = Printed card foldering
holderize.pageRows = Rows on page
holderize.pageColumns = Columns on page
holderize.folderName = Folder name
holderize.page = Page
holderize.column = Column
holderize.row = Row
holderize.barcode = Barcode
holderize.nextCodeHeader = Next card position
holderize.parametersHeader = Folder parameters
\ No newline at end of file
......@@ -1925,3 +1925,13 @@ feature.user_permission = Kyttj
feature.info_permission = Jrjestj
feature.admin_permission = Pkyttj
role.features = Tapahtuman ominaisuuksien oikeudet
holderize.header = Tulostettujen korttien kansiotus
holderize.pageRows = Rivej sivulla
holderize.pageColumns = Sarakkeita sivulla
holderize.folderName = Kansion nimi
holderize.page = Sivu
holderize.column = Sarake
holderize.row = Rivi
holderize.barcode = Viivakoodi
holderize.nextCodeHeader = Seuraavan kortin paikka
holderize.parametersHeader = Kansion asetukset
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!