Commit 075a4f76 authored by Elias Englmeier's avatar Elias Englmeier
Browse files

improvements for the idea board and map module

parent 166676ad
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %><%@
taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %><%@
taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %><%@
taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib prefix="aui" uri="http://liferay.com/tld/aui" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="theme" %>
<liferay-theme:defineObjects />
......
<%@ include file="/init.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib prefix="aui" uri="http://liferay.com/tld/aui" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="theme" %>
<portlet:defineObjects />
<head>
<script>
define._amd = define.amd;
......@@ -29,138 +24,29 @@
<script type="text/javascript">
$(document).ready(function(){
//init the map
var map = L.map('map').setView([48.174918, 11.596160], 13);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
var map = L.map('map').setView([0.0, 0.0], 12);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',{
maxZoom: 18,
id: 'mapbox.streets',
accessToken: 'your.mapbox.access.token'
}).addTo(map);
//load markers from server
var ideasJsonArray = JSON.parse('${allIdeas}')
var ideasJsonArray = JSON.parse('${allIdeas}');
$.each(ideasJsonArray, function (index, value) {
if(value.isVisibleOnMap){
var latlng = L.latLng(value.latitude,value.longitude);
var loadedMarker = new L.Marker(latlng, {draggable:false});
loadedMarker.dbId = value.id;
loadedMarker.bindTooltip(value.title).openTooltip();
loadedMarker.bindPopup(getMarkerPopUp(value.id,value.title,value.shortdescription));
loadedMarker.bindPopup(getMarkerPopUp(value.id,value.title,value.shortdescription,value.pageUrl));
map.addLayer(loadedMarker);
map.panTo(latlng);
}
});
function getMarkerPopUp(id, title, description){
return "<h4>" + title + "</h4>" + "<p>" + description + "</p><br>";
function getMarkerPopUp(id, title, description,link){
return "<h4>" + title + "</h4>" + "<p>" + description + "</p><br>" + "<a href=" + link + ">Goto</a>";
}
//adding a marker on click and open a modal
map.on('click', onMapClick);
function onMapClick(e) {
vex.dialog.open({
message: 'Enter a new idea:',
input: [
'<style>',
'.vex-custom-field-wrapper {',
'margin: 1em 0;',
'}',
'.vex-custom-field-wrapper > label {',
'display: inline-block;',
'margin-bottom: .1em;',
'}',
'</style>',
'<div class="vex-custom-field-wrapper">',
'<label for="title">Title</label>',
'<div class="vex-custom-input-wrapper">',
'<input name="title" type="string" placeholder="Title" size="35" />',
'</div>',
'<div class="vex-custom-field-wrapper">',
'<label for="shortdescription">Short Desription</label>',
'<div class="vex-custom-input-wrapper">',
'<input name="shortdescription" type="string" placeholder="Short Description" size="35" />',
'</div>',
'<div class="vex-custom-field-wrapper">',
'<label for="description">Desription</label>',
'<div class="vex-custom-input-wrapper">',
'<input name="description" type="string" placeholder="Description" size="35" />',
'</div>',
].join(''),
callback: function (data) {
if (!data) {
return;
}
console.log(themeDisplay);
//post to db
Liferay.Service(
'/idea.ideas/insert-new-idea',
{
title: data.title,
category: "mapIdea",
userId: themeDisplay.getUserId(),
titleImgRef: null,
shortDescription: data.shortdescription,
description: data.description,
latitude: e.latlng.lat ,
longitude: e.latlng.lng ,
published: true,
showOnMap: true,
groupId: themeDisplay.getScopeGroupId(),
rating : 6,
projectIdRef: themeDisplay.getLayoutId(),
titleFileRef: 0
},
function(obj) {
var response = jQuery.parseJSON(obj)
if(response.created){
//add new marker to map
var marker = new L.Marker(e.latlng, {draggable:false});
marker.bindPopup("<h4>" + data.title + "</h4>" + "<p>" + data.shortdescription + "</p>");
marker.bindTooltip(data.title).openTooltip();
marker.dbId = response.createdId;
map.addLayer(marker);
vex.dialog.alert({
message: 'New Idea successfully created',
callback: function (value) {
Liferay.fire('refreshIdeaBoard', {refresh :true});
}
})
}else{
vex.dialog.alert(response.errorMsg);
}
}
);
}
});
};
});
/*
Rest API example
$.getJSON(serverPrefix + "o/mapApi/mapService/markers", function(data){
$.each(data, function (index, value) {
var latlng = L.latLng(value.latitude,value.longitude);
var loadedMarker = new L.Marker(latlng, {draggable:false});
//loadedMarker.bindTooltip(value.title).openTooltip();
loadedMarker.bindPopup("<h4>" + value.title + "</h4>" + "<p>" + value.description + "</p>");
map.addLayer(loadedMarker);
});
}); */
//Liferay get Service example
/* Liferay.Service(
'/idea.ideas/get-all-ideas',
function(data) {
var received = jQuery.parseJSON(data);
$.each(received, function (index, value) {
if(value.showOnMap){
var latlng = L.latLng(value.latitude,value.longitude);
var loadedMarker = new L.Marker(latlng, {draggable:false});
loadedMarker.dbId = value.id;
loadedMarker.bindTooltip(value.title).openTooltip();
loadedMarker.bindPopup(getMarkerPopUp(value.id,value.title,value.description));
map.addLayer(loadedMarker);
}
});
}
); */
</script>
\ No newline at end of file
......@@ -6,4 +6,5 @@ dependencies {
compileOnly group: "jstl", name: "jstl", version: "1.2"
compileOnly group: "org.osgi", name: "osgi.cmpn", version: "6.0.0"
compile project (":modules:ideaService:ideaService-api")
compile project (":modules:projectService:projectService-api")
}
\ No newline at end of file
package MapModule.portlet;
import MapModule.constants.MapModulePortletKeys;
import ideaService.model.Ideas;
import ideaService.service.IdeasLocalServiceUtil;
import projectService.service.ProjectLocalServiceUtil;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.WebKeys;
import java.io.IOException;
import java.util.ArrayList;
import javax.portlet.Portlet;
import javax.portlet.PortletException;
......@@ -36,7 +41,19 @@ public class MapModulePortlet extends MVCPortlet {
@Override
public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException{
renderRequest.setAttribute("allIdeas", JSONFactoryUtil.looseSerializeDeep(IdeasLocalServiceUtil.getAllIdeas()));
ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
if(ProjectLocalServiceUtil.getProjectByLayoutIdRef(themeDisplay.getLayout().getPrimaryKey()) != null){
renderRequest.setAttribute("allIdeas",
JSONFactoryUtil.looseSerializeDeep(IdeasLocalServiceUtil.getAllIdeasForProject
(ProjectLocalServiceUtil.getProjectByLayoutIdRef(themeDisplay.getLayout().getPrimaryKey()).getPrimaryKey())));
}
else{
ArrayList<Ideas> tmp = new ArrayList<Ideas>();
Ideas i = IdeasLocalServiceUtil.getIdeasByLayoutIdRef(themeDisplay.getLayout().getPrimaryKey());
tmp.add(i);
renderRequest.setAttribute("allIdeas",
JSONFactoryUtil.looseSerializeDeep(tmp));
}
super.render(renderRequest, renderResponse);
}
......
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %><%@
taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %><%@
taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %><%@
taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib prefix="aui" uri="http://liferay.com/tld/aui" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="theme" %>
<liferay-theme:defineObjects />
......
<%@ include file="/init.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib prefix="aui" uri="http://liferay.com/tld/aui" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="theme" %>
<portlet:defineObjects />
<head>
<script>
define._amd = define.amd;
......@@ -29,138 +24,29 @@
<script type="text/javascript">
$(document).ready(function(){
//init the map
var map = L.map('map').setView([48.174918, 11.596160], 13);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
var map = L.map('map').setView([0.0, 0.0], 12);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',{
maxZoom: 18,
id: 'mapbox.streets',
accessToken: 'your.mapbox.access.token'
}).addTo(map);
//load markers from server
var ideasJsonArray = JSON.parse('${allIdeas}')
var ideasJsonArray = JSON.parse('${allIdeas}');
$.each(ideasJsonArray, function (index, value) {
if(value.isVisibleOnMap){
var latlng = L.latLng(value.latitude,value.longitude);
var loadedMarker = new L.Marker(latlng, {draggable:false});
loadedMarker.dbId = value.id;
loadedMarker.bindTooltip(value.title).openTooltip();
loadedMarker.bindPopup(getMarkerPopUp(value.id,value.title,value.shortdescription));
loadedMarker.bindPopup(getMarkerPopUp(value.id,value.title,value.shortdescription,value.pageUrl));
map.addLayer(loadedMarker);
map.panTo(latlng);
}
});
function getMarkerPopUp(id, title, description){
return "<h4>" + title + "</h4>" + "<p>" + description + "</p><br>";
function getMarkerPopUp(id, title, description,link){
return "<h4>" + title + "</h4>" + "<p>" + description + "</p><br>" + "<a href=" + link + ">Goto</a>";
}
//adding a marker on click and open a modal
map.on('click', onMapClick);
function onMapClick(e) {
vex.dialog.open({
message: 'Enter a new idea:',
input: [
'<style>',
'.vex-custom-field-wrapper {',
'margin: 1em 0;',
'}',
'.vex-custom-field-wrapper > label {',
'display: inline-block;',
'margin-bottom: .1em;',
'}',
'</style>',
'<div class="vex-custom-field-wrapper">',
'<label for="title">Title</label>',
'<div class="vex-custom-input-wrapper">',
'<input name="title" type="string" placeholder="Title" size="35" />',
'</div>',
'<div class="vex-custom-field-wrapper">',
'<label for="shortdescription">Short Desription</label>',
'<div class="vex-custom-input-wrapper">',
'<input name="shortdescription" type="string" placeholder="Short Description" size="35" />',
'</div>',
'<div class="vex-custom-field-wrapper">',
'<label for="description">Desription</label>',
'<div class="vex-custom-input-wrapper">',
'<input name="description" type="string" placeholder="Description" size="35" />',
'</div>',
].join(''),
callback: function (data) {
if (!data) {
return;
}
console.log(themeDisplay);
//post to db
Liferay.Service(
'/idea.ideas/insert-new-idea',
{
title: data.title,
category: "mapIdea",
userId: themeDisplay.getUserId(),
titleImgRef: null,
shortDescription: data.shortdescription,
description: data.description,
latitude: e.latlng.lat ,
longitude: e.latlng.lng ,
published: true,
showOnMap: true,
groupId: themeDisplay.getScopeGroupId(),
rating : 6,
projectIdRef: themeDisplay.getLayoutId(),
titleFileRef: 0
},
function(obj) {
var response = jQuery.parseJSON(obj)
if(response.created){
//add new marker to map
var marker = new L.Marker(e.latlng, {draggable:false});
marker.bindPopup("<h4>" + data.title + "</h4>" + "<p>" + data.shortdescription + "</p>");
marker.bindTooltip(data.title).openTooltip();
marker.dbId = response.createdId;
map.addLayer(marker);
vex.dialog.alert({
message: 'New Idea successfully created',
callback: function (value) {
Liferay.fire('refreshIdeaBoard', {refresh :true});
}
})
}else{
vex.dialog.alert(response.errorMsg);
}
}
);
}
});
};
});
/*
Rest API example
$.getJSON(serverPrefix + "o/mapApi/mapService/markers", function(data){
$.each(data, function (index, value) {
var latlng = L.latLng(value.latitude,value.longitude);
var loadedMarker = new L.Marker(latlng, {draggable:false});
//loadedMarker.bindTooltip(value.title).openTooltip();
loadedMarker.bindPopup("<h4>" + value.title + "</h4>" + "<p>" + value.description + "</p>");
map.addLayer(loadedMarker);
});
}); */
//Liferay get Service example
/* Liferay.Service(
'/idea.ideas/get-all-ideas',
function(data) {
var received = jQuery.parseJSON(data);
$.each(received, function (index, value) {
if(value.showOnMap){
var latlng = L.latLng(value.latitude,value.longitude);
var loadedMarker = new L.Marker(latlng, {draggable:false});
loadedMarker.dbId = value.id;
loadedMarker.bindTooltip(value.title).openTooltip();
loadedMarker.bindPopup(getMarkerPopUp(value.id,value.title,value.description));
map.addLayer(loadedMarker);
}
});
}
); */
</script>
\ No newline at end of file
.gradle/
build/
target/
\ No newline at end of file
Bundle-Name: guestbook-web
Bundle-SymbolicName: com.liferay.docs.guestbook.portlet
Bundle-Version: 1.0.0
Export-Package: com.liferay.docs.guestbook.portlet.constants
\ No newline at end of file
dependencies {
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.0.0"
compileOnly group: "com.liferay.portal", name: "com.liferay.util.taglib", version: "2.0.0"
compileOnly group: "javax.portlet", name: "portlet-api", version: "2.0"
compileOnly group: "javax.servlet", name: "javax.servlet-api", version: "3.0.1"
compileOnly group: "jstl", name: "jstl", version: "1.2"
compileOnly group: "org.osgi", name: "osgi.cmpn", version: "6.0.0"
compileOnly project(":modules:guestbook:guestbook-api")
compileOnly project(":modules:guestbook:guestbook-service")
compileOnly project (":modules:ideaService:ideaService-api")
compileOnly project (":modules:ideaService:ideaService-service")
compileOnly group: "com.liferay", name: "com.liferay.application.list.api", version: "2.0.0"
}
package com.liferay.docs.guestbook.application.list;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import com.liferay.application.list.BasePanelApp;
import com.liferay.application.list.PanelApp;
import com.liferay.application.list.constants.PanelCategoryKeys;
import com.liferay.docs.guestbook.portlet.constants.GuestbookPortletKeys;
import com.liferay.portal.kernel.model.Portlet;
@Component(
immediate = true,
property = {
"panel.app.order:Integer=300",
"panel.category.key=" + PanelCategoryKeys.SITE_ADMINISTRATION_CONTENT
},
service = PanelApp.class
)
public class GuestbookAdminPanelApp extends BasePanelApp {
@Override
public String getPortletId() {
return GuestbookPortletKeys.GUESTBOOK_ADMIN;
}
@Override
@Reference(
target = "(javax.portlet.name=" + GuestbookPortletKeys.GUESTBOOK_ADMIN + ")",
unbind = "-"
)
public void setPortlet(Portlet portlet) {
super.setPortlet(portlet);
}
}
package com.liferay.docs.guestbook.portlet.constants;
/**
* @author englmeier
*/
public class GuestbookPortletKeys {
public static final String Guestbook = "Guestbook";
public static final String GUESTBOOK =
"com_liferay_docs_guestbook_portlet_GuestbookPortlet";
public static final String GUESTBOOK_ADMIN =
"com_liferay_docs_guestbook_portlet_GuestbookAdminPortlet";
}
\ No newline at end of file
package com.liferay.docs.guestbook.portlet.portlet;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.Portlet;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import com.liferay.docs.guestbook.model.Guestbook;
import com.liferay.docs.guestbook.portlet.constants.GuestbookPortletKeys;
import com.liferay.docs.guestbook.service.GuestbookLocalService;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet;
import com.liferay.portal.kernel.service.ServiceContext;
import com.liferay.portal.kernel.service.ServiceContextFactory;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.servlet.SessionMessages;
import com.liferay.portal.kernel.util.ParamUtil;
@Component(
immediate = true,
property = {
"com.liferay.portlet.display-category=category.hidden",
"com.liferay.portlet.scopeable=true",
"javax.portlet.display-name=Guestbooks",
"javax.portlet.expiration-cache=0",
"javax.portlet.init-param.portlet-title-based-navigation=true",
"javax.portlet.init-param.template-path=/",
"javax.portlet.init-param.view-template=/guestbookadminportlet/view.jsp",
"javax.portlet.name=" + GuestbookPortletKeys.GUESTBOOK_ADMIN,
"javax.portlet.resource-bundle=content.Language",
"javax.portlet.security-role-ref=administrator",
"javax.portlet.supports.mime-type=text/html",
"com.liferay.portlet.add-default-resource=true"
},
service = Portlet.class
)
public class GuestbookAdminPortlet extends MVCPortlet {
public void addGuestbook(ActionRequest request, ActionResponse response)
throws PortalException {
ServiceContext serviceContext = ServiceContextFactory.getInstance(
Guestbook.class.getName(), request);
String name = ParamUtil.getString(request, "name");
try {
_guestbookLocalService.addGuestbook(
serviceContext.getUserId(), name, serviceContext);
SessionMessages.add(request, "guestbookAdded");
}
catch (PortalException pe) {
Logger.getLogger(GuestbookAdminPortlet.class.getName()).log(
Level.SEVERE, null, pe);
SessionErrors.add(request, pe.getClass().getName());
response.setRenderParameter(
"mvcPath", "/guestbookadminportlet/edit_guestbook.jsp");
}
}
public void updateGuestbook(ActionRequest request, ActionResponse response)
throws PortalException {
ServiceContext serviceContext = ServiceContextFactory.getInstance(
Guestbook.class.getName(), request);
String name = ParamUtil.getString(request, "name");
long guestbookId = ParamUtil.getLong(request, "guestbookId");
try {
_guestbookLocalService.updateGuestbook(
serviceContext.getUserId(), guestbookId, name, serviceContext);
SessionMessages.add(request, "guestbookUpdated");
} catch (PortalException pe) {
Logger.getLogger(GuestbookAdminPortlet.class.getName()).log(
Level.SEVERE, null, pe);
SessionErrors.add(request, pe.getClass().getName());
response.setRenderParameter(
"mvcPath", "/guestbookadminportlet/edit_guestbook.jsp");
}
}
public void deleteGuestbook(ActionRequest request, ActionResponse response)
throws PortalException {
ServiceContext serviceContext = ServiceContextFactory.getInstance(