Commit 00bc5734 authored by Elias Englmeier's avatar Elias Englmeier
Browse files

admins may now create their own categories when creating a project

parent 99fcc500
......@@ -45,8 +45,12 @@ import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.MimeTypesUtil;
import com.liferay.portal.kernel.util.WebKeys;
import ideaService.model.Category;
import ideaService.service.CategoryLocalService;
import model.CategoryPojo;
import projectService.model.Project;
import projectService.service.ProjectLocalService;
import servicetrackers.CategoryLocalServiceTracker;
import servicetrackers.DLAppLocalServiceTracker;
import servicetrackers.LayoutLocalServiceTracker;
import servicetrackers.ProjectLocalServiceTracker;
......@@ -63,6 +67,7 @@ public class ProjectOverviewBean implements Serializable {
private DLAppLocalServiceTracker dlAppLocalServiceTracker;
private ProjectLocalServiceTracker projectLocalServiceTracker;
private LayoutLocalServiceTracker layoutLocalServiceTracker;
private CategoryLocalServiceTracker categoryLocalSerivceTracker;
//private Map<Long,Project> allProjects;
private List<Project> allProjects;
private String newProjectTitle;
......@@ -70,8 +75,52 @@ public class ProjectOverviewBean implements Serializable {
private boolean newProjectPublish;
private UploadedFile titlePic;
private File currentPicture;
private List<CategoryPojo> categories;
public void onPageLoad(){
updateProjects();
}
private void updateProjects() {
ProjectLocalService projectLocalServiceUtil = projectLocalServiceTracker.getService();
this.allProjects = projectLocalServiceUtil.getAllProjects();
if(this.allProjects.equals(null)){
this.allProjects = new ArrayList<Project>();
}
}
public List<Project> getAllProjects(){
return this.allProjects;
}
@PostConstruct
public void postConstruct() {
Bundle bundle = FrameworkUtil.getBundle(this.getClass());
BundleContext bundleContext = bundle.getBundleContext();
userLocalServiceTracker = new UserLocalServiceTracker(bundleContext);
dlAppLocalServiceTracker = new DLAppLocalServiceTracker(bundleContext);
projectLocalServiceTracker = new ProjectLocalServiceTracker(bundleContext);
layoutLocalServiceTracker = new LayoutLocalServiceTracker(bundleContext);
categoryLocalSerivceTracker = new CategoryLocalServiceTracker(bundleContext);
dlAppLocalServiceTracker.open();
userLocalServiceTracker.open();
projectLocalServiceTracker.open();
layoutLocalServiceTracker.open();
categoryLocalSerivceTracker.open();
categories = new ArrayList<CategoryPojo>();
}
@PreDestroy
public void preDestroy() {
userLocalServiceTracker.close();
dlAppLocalServiceTracker.close();
projectLocalServiceTracker.close();
layoutLocalServiceTracker.close();
categoryLocalSerivceTracker.close();
}
public void deleteOnClick(long id){
ProjectLocalService projectLocalServiceUtil = projectLocalServiceTracker.getService();
......@@ -118,10 +167,23 @@ public class ProjectOverviewBean implements Serializable {
if(this.currentPicture.exists()){
this.currentPicture.delete();
}
//Save all Categories
if(!categories.isEmpty())
for(CategoryPojo c : categories){
saveCategory(newProject.getPrimaryKey(),user,themeDisplay,c);
}
RequestContext.getCurrentInstance().update("projectoverviewform");
return newProject.getPrimaryKey();
}
private void saveCategory(long projectId, User u, ThemeDisplay t, CategoryPojo cat){
CategoryLocalService categoryService = categoryLocalSerivceTracker.getService();
Category newCat = categoryService.createNewCategoryWithAutomatedDBId(u.getUserId(),t.getScopeGroupId() , cat.getCategoryDescription() , cat.getCategoryName(),projectId);
newCat.persist();
}
private User getCurrentUser(String id) throws NumberFormatException, PortalException{
UserLocalService userLocalService = userLocalServiceTracker.getService();
return userLocalService.getUserById(Long.parseLong(id));
......@@ -131,46 +193,33 @@ public class ProjectOverviewBean implements Serializable {
this.setTitlePic(event.getFile());
}
public void addCategory() {
System.out.println("add category");
categories.add(new CategoryPojo());
RequestContext.getCurrentInstance().update("projectInputModalForm");
public void onPageLoad(){
updateProjects();
}
}
private void updateProjects() {
ProjectLocalService projectLocalServiceUtil = projectLocalServiceTracker.getService();
this.allProjects = projectLocalServiceUtil.getAllProjects();
if(this.allProjects.equals(null)){
this.allProjects = new ArrayList<Project>();
}
}
public void removeCategory(CategoryPojo cat) {
categories.remove(cat);
}
public List<Project> getAllProjects(){
return this.allProjects;
}
@PostConstruct
public void postConstruct() {
Bundle bundle = FrameworkUtil.getBundle(this.getClass());
BundleContext bundleContext = bundle.getBundleContext();
userLocalServiceTracker = new UserLocalServiceTracker(bundleContext);
dlAppLocalServiceTracker = new DLAppLocalServiceTracker(bundleContext);
projectLocalServiceTracker = new ProjectLocalServiceTracker(bundleContext);
layoutLocalServiceTracker = new LayoutLocalServiceTracker(bundleContext);
dlAppLocalServiceTracker.open();
userLocalServiceTracker.open();
projectLocalServiceTracker.open();
layoutLocalServiceTracker.open();
}
/**
* @return the categories
*/
public List<CategoryPojo> getCategories() {
return categories;
}
@PreDestroy
public void preDestroy() {
userLocalServiceTracker.close();
dlAppLocalServiceTracker.close();
projectLocalServiceTracker.close();
layoutLocalServiceTracker.close();
}
/**
* @param categories the categories to set
*/
public void setCategories(List<CategoryPojo> categories) {
this.categories = categories;
}
/**
* @return the newProjectTitle
......@@ -251,6 +300,7 @@ public class ProjectOverviewBean implements Serializable {
}
}
//////////////////////////////////////////////////////////////////////////////////////////
///////////////////// DUPLICATE CODE FROM IDEAINPUTBEAN //////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
......
package model;
public class CategoryPojo {
private String categoryName;
private String categoryDescription;
/**
* @return the categoryDescription
*/
public String getCategoryDescription() {
return categoryDescription;
}
/**
* @param categoryDescription the categoryDescription to set
*/
public void setCategoryDescription(String categoryDescription) {
this.categoryDescription = categoryDescription;
}
/**
* @return the categoryName
*/
public String getCategoryName() {
return categoryName;
}
/**
* @param categoryName the categoryName to set
*/
public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}
@Override
public String toString(){
return "categoryName: " +categoryName + " - categorydescription: " + categoryDescription;
}
}
package servicetrackers;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
import ideaService.service.CategoryLocalService;
public class CategoryLocalServiceTracker extends ServiceTracker<CategoryLocalService, CategoryLocalService> {
public CategoryLocalServiceTracker(BundleContext bundleContext){
super(bundleContext, CategoryLocalService.class, null);
}
}
......@@ -60,7 +60,7 @@
<!-- Input Modal -->
<div id="projectInputModal" class="w3-modal">
<h:form enctype="multipart/form-data">
<h:form id="projectInputModalForm" enctype="multipart/form-data">
<div class="w3-modal-content w3-animate-opacity">
<header class="w3-container w3-blue">
<h2>New Project</h2>
......@@ -69,13 +69,23 @@
<div class="w3-container w3-padding-small">
<p style="padding-bottom:20px" >
<p:inputText class="w3-input w3-animate-input " type="text" style="width:40%"
value="#{projectOverviewBean.newProjectTitle}" placeholder="Enter the title of your project here." />
value="#{projectOverviewBean.newProjectTitle}" placeholder="Titel des neuen Projekts hier angeben." />
</p>
<p style="padding-bottom:15px">
<p:inputText class="w3-input w3-animate-input" type="text" style="width:40%"
value="#{projectOverviewBean.newProjectDescription}" placeholder="Enter a description here." />
value="#{projectOverviewBean.newProjectDescription}" placeholder="Beschreibung des neuen Projekts hier angeben." />
</p>
<!-- Categories -->
<p:dataTable value="#{projectOverviewBean.categories}" var="category">
<p:column headerText="Name der Kategorie"><h:inputText value="#{category.categoryName}" /></p:column>
<p:column headerText="Beschreibung der Kategorie"><h:inputText value="#{category.categoryDescription}" /></p:column>
<p:column headerText="Aktionen"><h:commandButton value="entfernen" action="#{projectOverviewBean.removeCategory(category)}" /></p:column>
</p:dataTable>
<p:commandButton value="Kategorie hinzufügen" action="#{projectOverviewBean.addCategory}" />
<!-- publish and upload -->
<h:panelGrid columns="3" style="margin-bottom:10px" cellpadding="5">
<h:outputText value="Publish immediately" style="font: 15px Verdana" />
<p:spacer width="5"/>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment