Commit 5ce3bc48 authored by Anastasios Kalogeropoulos's avatar Anastasios Kalogeropoulos
Browse files

Merge branch 'mark-archived-projects-on-map'

parents f87a9902 2945bdf4
......@@ -33,6 +33,8 @@ $(document).ready(function(){
map.on('drag', function() {
map.panInsideBounds(bounds, { animate: false });
});
var redIcon = L.icon({
iconUrl: 'https://www.weckdenherkulesindir.de/documents/20142/32730/marker-icon.png/f9a304c8-716b-9684-b7d4-a31318ba5e50?t=1544108384492',
shadowUrl: 'https://www.weckdenherkulesindir.de/documents/20142/32730/marker-shadow.png/20ac54bb-8339-1fea-659a-e473c5a18bb5?t=1544108384613',
......@@ -46,40 +48,71 @@ $(document).ready(function(){
shadowAnchor: [14, 41] // the same for the shadow
});
var greyIcon = L.icon({
iconUrl: 'https://www.weckdenherkulesindir.de/documents/20142/32730/marker-gray.png/c4732086-fc0d-2c95-d581-e8c8d8635d08?t=1544544826763',
shadowUrl: 'https://www.weckdenherkulesindir.de/documents/20142/32730/marker-shadow.png/20ac54bb-8339-1fea-659a-e473c5a18bb5?t=1544108384613',
iconSize: [25, 41], // size of the icon
iconAnchor: [12, 41], // point of the icon which will correspond to marker's location
popupAnchor: [0, -34], // point from which the popup should open relative to the iconAnchor
tooltipAnchor: [16, -20],
shadowSize: [41, 41], // size of the shadow
shadowAnchor: [14, 41] // the same for the shadow
});
map.options.minZoom = 12;
var wmsUrl = 'https://geoportal.stadt-kassel.de/arcgis/services/Raster/Geoportal_WebMaps_WGS84/MapServer/WMSServer?';
L.tileLayer.wms(wmsUrl,{
layers:'1:4.514,1:9.028,1:18.056,1:36.112,1:72.224,1:144.448,1:288.895'
}).addTo(map);
/* 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}');
if(ideasJsonArray.length > 0){
var markerGroup = new L.featureGroup();
$.each(ideasJsonArray, function (index, value) {
if(value.isVisibleOnMap){
var latlng = L.latLng(value.latitude,value.longitude);
var loadedMarker = new L.Marker(latlng, {icon: redIcon, draggable:false});
markerGroup.addLayer(loadedMarker);
loadedMarker.dbId = value.id;
loadedMarker.bindTooltip(value.title).openTooltip();
loadedMarker.bindPopup(getMarkerPopUp(value.id,value.title,value.userName,value.pageUrl,value.rating));
map.addLayer(loadedMarker);
}
});
map.options.maxZoom = 16;
map.fitBounds(markerGroup.getBounds().pad(0.5));
var ideasJsonArrayOLD = JSON.parse('${oldIdeas}');
var ideasJsonArrayCURRENT = JSON.parse('${currentIdeas}');
console.log("OLD IDEAS =", ideasJsonArrayOLD.length);
console.log("CURRENT IDEAS =", ideasJsonArrayCURRENT.length);
if(ideasJsonArrayCURRENT.length > 0 || ideasJsonArrayOLD.length > 0){
var markerGroup = new L.featureGroup();
$.each(ideasJsonArrayCURRENT, function (index, value) {
if(value.isVisibleOnMap){
var latlng = L.latLng(value.latitude,value.longitude);
var loadedMarker = new L.Marker(latlng, {icon: redIcon, draggable:false});
markerGroup.addLayer(loadedMarker);
loadedMarker.dbId = value.id;
loadedMarker.bindTooltip(value.title).openTooltip();
loadedMarker.bindPopup(getMarkerPopUp(value.id,value.title,value.userName,value.pageUrl,value.rating));
map.addLayer(loadedMarker);
}
});
$.each(ideasJsonArrayOLD, function (index, value) {
if(value.isVisibleOnMap){
var latlng = L.latLng(value.latitude,value.longitude);
var loadedMarker = new L.Marker(latlng, {icon: greyIcon, draggable:false});
markerGroup.addLayer(loadedMarker);
loadedMarker.dbId = value.id;
loadedMarker.bindTooltip(value.title).openTooltip();
loadedMarker.bindPopup(getMarkerPopUp(value.id,value.title,value.userName,value.pageUrl,value.rating));
map.addLayer(loadedMarker);
}
});
map.options.maxZoom = 16;
map.fitBounds(markerGroup.getBounds().pad(0.5));
}else{
map.setView([51.312066, 9.492901],12)
}
function getMarkerPopUp(id, title, username,link,votes){
var votescount = votes.split(",");
var votescount;
if(votes == '') {
votescount = [];
} else {
votescount = votes.split(",");
}
return "<h4>" + title + "</h4>" + "<p> Eingereicht von " + username + "</p>" + "<p> Stimmen: " + votescount.length + "</p><br>" + "<a href=" + link + ">Details</a>";
}
});
......
package MapModule.portlet;
import java.io.IOException;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.portlet.Portlet;
import javax.portlet.PortletException;
......@@ -28,76 +34,151 @@ import projectService.service.ProjectLocalServiceUtil;
/**
* @author englmeier
*/
@Component(
immediate = true,
property = {
"com.liferay.portlet.display-category=category.EEN",
"com.liferay.portlet.instanceable=true",
"javax.portlet.display-name=Ideenkarte",
"javax.portlet.init-param.template-path=/",
"javax.portlet.init-param.view-template=/view.jsp",
"javax.portlet.name=" + MapModulePortletKeys.MapModule,
"javax.portlet.resource-bundle=content.Language",
"javax.portlet.security-role-ref=power-user,user"
},
service = Portlet.class
)
@Component(immediate = true, property = { "com.liferay.portlet.display-category=category.EEN",
"com.liferay.portlet.instanceable=true", "javax.portlet.display-name=Ideenkarte",
"javax.portlet.init-param.template-path=/", "javax.portlet.init-param.view-template=/view.jsp",
"javax.portlet.name=" + MapModulePortletKeys.MapModule, "javax.portlet.resource-bundle=content.Language",
"javax.portlet.security-role-ref=power-user,user" }, service = Portlet.class)
public class MapModulePortlet extends MVCPortlet {
private final static String ALL_IDEAS ="allIdeas";
private final static String OLD_IDEAS = "oldIdeas";
private final static String CURRENT_IDEAS = "currentIdeas";
@Override
public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException{
ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
String result = null;
public void render(RenderRequest renderRequest, RenderResponse renderResponse)
throws IOException, PortletException {
ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
String all_ideas = null;
String old_ideas = null;
String current_ideas = null;
List<Ideas> all_ideasList = new ArrayList<Ideas>();
List<Ideas> current_ideasList = new ArrayList<Ideas>();
List<Ideas> old_ideasList = new ArrayList<Ideas>();
User user;
if(ProjectLocalServiceUtil.getProjectByLayoutIdRef(themeDisplay.getLayout().getPrimaryKey()) != null){
long projectId = ProjectLocalServiceUtil.getProjectByLayoutIdRef(themeDisplay.getLayout().getPrimaryKey()).getPrimaryKey();
try {
user = PortalUtil.getUser(renderRequest);
for(Role role : user.getRoles()){
if(role.getName().equals(RoleConstants.ADMINISTRATOR) || role.getName().equals(RoleConstants.PORTAL_CONTENT_REVIEWER)){
//Admins and ContentRevs have same viewing rights.
result = JSONFactoryUtil.looseSerializeDeep(removeUnimportantData(IdeasLocalServiceUtil.getIdeasByUserRoleProjectId(RoleConstants.ADMINISTRATOR, user.getUserId(), projectId)));
break;
}
else if(role.getName().equals(RoleConstants.USER)){
result = JSONFactoryUtil.looseSerializeDeep(removeUnimportantData(IdeasLocalServiceUtil.getIdeasByUserRoleProjectId(RoleConstants.USER, user.getUserId(), projectId)));
if (ProjectLocalServiceUtil.getProjectByLayoutIdRef(themeDisplay.getLayout().getPrimaryKey()) != null) {
long projectId = ProjectLocalServiceUtil.getProjectByLayoutIdRef(themeDisplay.getLayout().getPrimaryKey())
.getPrimaryKey();
try {
user = PortalUtil.getUser(renderRequest);
for (Role role : user.getRoles()) {
if (role.getName().equals(RoleConstants.ADMINISTRATOR)
|| role.getName().equals(RoleConstants.PORTAL_CONTENT_REVIEWER)) {
// Admins and ContentRevs have same viewing rights.
all_ideasList = removeUnimportantData(IdeasLocalServiceUtil.getIdeasByUserRoleProjectId(
RoleConstants.ADMINISTRATOR, user.getUserId(), projectId));
for(Ideas idea : all_ideasList) {
if(this.isIdeaInValidPeriod(idea)) {
current_ideasList.add(idea);
} else {
old_ideasList.add(idea);
}
}
all_ideas = JSONFactoryUtil.looseSerializeDeep(all_ideasList);
old_ideas = JSONFactoryUtil.looseSerializeDeep(old_ideasList);
current_ideas = JSONFactoryUtil.looseSerializeDeep(current_ideasList);
break;
} else if (role.getName().equals(RoleConstants.USER)) {
all_ideasList = removeUnimportantData(IdeasLocalServiceUtil
.getIdeasByUserRoleProjectId(RoleConstants.USER, user.getUserId(), projectId));
for(Ideas idea : all_ideasList) {
if(this.isIdeaInValidPeriod(idea)) {
current_ideasList.add(idea);
} else {
old_ideasList.add(idea);
}
}
all_ideas = JSONFactoryUtil.looseSerializeDeep(all_ideasList);
old_ideas = JSONFactoryUtil.looseSerializeDeep(old_ideasList);
current_ideas = JSONFactoryUtil.looseSerializeDeep(current_ideasList);
break;
}
}
} catch (Exception e) {
//case guest user
result = JSONFactoryUtil.looseSerializeDeep(removeUnimportantData(IdeasLocalServiceUtil.getIdeasByUserRoleProjectId(RoleConstants.GUEST, -1, projectId)));
}
if(result.equals(null) || result.equals("") || result.equals("[]")){
//at least return all accepted ideas in any case
result = JSONFactoryUtil.looseSerializeDeep(removeUnimportantData(IdeasLocalServiceUtil.getAllAccpetedIdeas()));
}
renderRequest.setAttribute(ALL_IDEAS, result);
} catch (Exception e) {
all_ideasList = removeUnimportantData(
IdeasLocalServiceUtil.getIdeasByUserRoleProjectId(RoleConstants.GUEST, -1, projectId));
// case guest user
for(Ideas idea : all_ideasList) {
if(this.isIdeaInValidPeriod(idea)) {
current_ideasList.add(idea);
} else {
old_ideasList.add(idea);
}
}
all_ideas = JSONFactoryUtil.looseSerializeDeep(all_ideasList);
old_ideas = JSONFactoryUtil.looseSerializeDeep(old_ideasList);
current_ideas = JSONFactoryUtil.looseSerializeDeep(current_ideasList);
}
if (all_ideas.equals(null) || all_ideas.equals("") || all_ideas.equals("[]")) {
// at least return all accepted ideas in any case
all_ideasList = removeUnimportantData(IdeasLocalServiceUtil.getAllAccpetedIdeas());
for(Ideas idea : all_ideasList) {
if(this.isIdeaInValidPeriod(idea)) {
current_ideasList.add(idea);
} else {
old_ideasList.add(idea);
}
}
all_ideas = JSONFactoryUtil.looseSerializeDeep(all_ideasList);
old_ideas = JSONFactoryUtil.looseSerializeDeep(old_ideasList);
current_ideas = JSONFactoryUtil.looseSerializeDeep(current_ideasList);
}
renderRequest.setAttribute(OLD_IDEAS, old_ideas);
renderRequest.setAttribute(CURRENT_IDEAS, current_ideas);
}
else if (IdeasLocalServiceUtil.getIdeasByLayoutIdRef(themeDisplay.getLayout().getPrimaryKey()) != null){
List<Ideas> tmp = new ArrayList<Ideas>();
Ideas i = IdeasLocalServiceUtil.getIdeasByLayoutIdRef(themeDisplay.getLayout().getPrimaryKey());
tmp.add(i);
tmp = removeUnimportantData(tmp);
result = JSONFactoryUtil.looseSerializeDeep(tmp);
renderRequest.setAttribute(ALL_IDEAS,result);
}
else{
renderRequest.setAttribute(ALL_IDEAS,JSONFactoryUtil.looseSerializeDeep(removeUnimportantData(IdeasLocalServiceUtil.getAllAccpetedIdeas())));
} else if (IdeasLocalServiceUtil.getIdeasByLayoutIdRef(themeDisplay.getLayout().getPrimaryKey()) != null) {
List<Ideas> tmp = new ArrayList<Ideas>();
Ideas i = IdeasLocalServiceUtil.getIdeasByLayoutIdRef(themeDisplay.getLayout().getPrimaryKey());
tmp.add(i);
tmp = removeUnimportantData(tmp);
for(Ideas idea : tmp) {
if(this.isIdeaInValidPeriod(idea)) {
current_ideasList.add(idea);
} else {
old_ideasList.add(idea);
}
}
all_ideas = JSONFactoryUtil.looseSerializeDeep(tmp);
old_ideas = JSONFactoryUtil.looseSerializeDeep(old_ideasList);
current_ideas = JSONFactoryUtil.looseSerializeDeep(current_ideasList);
renderRequest.setAttribute(OLD_IDEAS, old_ideas);
renderRequest.setAttribute(CURRENT_IDEAS, current_ideas);
} else {
all_ideasList = removeUnimportantData(IdeasLocalServiceUtil.getAllAccpetedIdeas());
for(Ideas idea : all_ideasList) {
if(this.isIdeaInValidPeriod(idea)) {
current_ideasList.add(idea);
} else {
old_ideasList.add(idea);
}
}
all_ideas = JSONFactoryUtil.looseSerializeDeep(all_ideasList);
old_ideas = JSONFactoryUtil.looseSerializeDeep(old_ideasList);
current_ideas = JSONFactoryUtil.looseSerializeDeep(current_ideasList);
renderRequest.setAttribute(OLD_IDEAS, old_ideas);
renderRequest.setAttribute(CURRENT_IDEAS, current_ideas);
}
renderRequest.setAttribute(ALL_IDEAS, result);
renderRequest.setAttribute(OLD_IDEAS, old_ideas);
renderRequest.setAttribute(CURRENT_IDEAS, current_ideas);
super.render(renderRequest, renderResponse);
}
private List<Ideas> removeUnimportantData(List<Ideas> ideas){
//some special chars are not properly escaped by the serialization so all unimportant information is set to null.
for(Ideas i : ideas){
private List<Ideas> removeUnimportantData(List<Ideas> ideas) {
// some special chars are not properly escaped by the serialization so
// all unimportant information is set to null.
for (Ideas i : ideas) {
i.setVideoUrl(null);
i.setUuid(null);
i.setTags(null);
......@@ -116,5 +197,128 @@ public class MapModulePortlet extends MVCPortlet {
return ideas;
}
private boolean isIdeaInValidPeriod(Ideas i) {
try {
// get current year
int currentYear = Calendar.getInstance().get(Calendar.YEAR);
// get current month
int currentMonth = this.getCurrentMonth();
Date createDateOfIDea = i.getCreateDate();
// get year of the idea
int yearOfIdea = this.getYearOfIdea(createDateOfIDea);
// get month of idea in number and not in string
int monthOfIdea = this.getMonthOfIdea(createDateOfIDea);
int[] ideaPeriod = this.getPeriod(monthOfIdea);
int[] currentPeriod = this.getPeriod(currentMonth);
// if the idea belongs to the current year and in the current
// period, then it's available for voting
if (yearOfIdea == currentYear && this.samePeriods(ideaPeriod, currentPeriod)) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
private int getCurrentMonth() {
Date currentDate = new Date();
LocalDate localCurrentDate = currentDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
int currentMonth = localCurrentDate.getMonthValue();
return currentMonth;
}
private int getYearOfIdea(Date createDateOfIdea) {
Calendar cal = Calendar.getInstance();
cal.setTime(createDateOfIdea);
int yearOfIdea = cal.get(Calendar.YEAR);
return yearOfIdea;
}
private int getMonthOfIdea(Date createDateOfIdea) {
LocalDate localIdeaDate = createDateOfIdea.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
int monthOfIdea = localIdeaDate.getMonthValue();
return monthOfIdea;
}
/**
* Return the period of the given month. The months of the year are split by
* two, defining one period.
*
* @param month
* The month to be tested
* @return The period that the month belongs to
*/
private int[] getPeriod(int month) {
Map<String, int[]> monthPeriods = new HashMap<String, int[]>();
monthPeriods.put("JAN_FEB", new int[] { 1, 2 });
monthPeriods.put("MAR_APR", new int[] { 3, 4 });
monthPeriods.put("MAY_JUN", new int[] { 5, 6 });
monthPeriods.put("JUL_AUG", new int[] { 7, 8 });
monthPeriods.put("SEPT_OCT", new int[] { 9, 10 });
monthPeriods.put("NOV_DEC", new int[] { 11, 12 });
int[] period = new int[] {};
switch (month) {
case 1:
period = monthPeriods.get("JAN_FEB");
break;
case 2:
period = monthPeriods.get("JAN_FEB");
break;
case 3:
period = monthPeriods.get("MAR_APR");
break;
case 4:
period = monthPeriods.get("MAR_APR");
break;
case 5:
period = monthPeriods.get("MAY_JUN");
break;
case 6:
period = monthPeriods.get("MAY_JUN");
break;
case 7:
period = monthPeriods.get("JUL_AUG");
break;
case 8:
period = monthPeriods.get("JUL_AUG");
break;
case 9:
period = monthPeriods.get("SEPT_OCT");
break;
case 10:
period = monthPeriods.get("SEPT_OCT");
break;
case 11:
period = monthPeriods.get("NOV_DEC");
break;
case 12:
period = monthPeriods.get("NOV_DEC");
break;
default:
break;
}
return period;
}
/**
* Compare if the months of the two periods are the same.
*
* @return true if periods are the same, false otherwise
*/
private boolean samePeriods(int[] period1, int[] period2) {
if (period1[0] == period2[0] && period1[1] == period2[1]) {
return true;
}
return false;
}
}
......@@ -33,6 +33,8 @@ $(document).ready(function(){
map.on('drag', function() {
map.panInsideBounds(bounds, { animate: false });
});
var redIcon = L.icon({
iconUrl: 'https://www.weckdenherkulesindir.de/documents/20142/32730/marker-icon.png/f9a304c8-716b-9684-b7d4-a31318ba5e50?t=1544108384492',
shadowUrl: 'https://www.weckdenherkulesindir.de/documents/20142/32730/marker-shadow.png/20ac54bb-8339-1fea-659a-e473c5a18bb5?t=1544108384613',
......@@ -46,40 +48,71 @@ $(document).ready(function(){
shadowAnchor: [14, 41] // the same for the shadow
});
var greyIcon = L.icon({
iconUrl: 'https://www.weckdenherkulesindir.de/documents/20142/32730/marker-gray.png/c4732086-fc0d-2c95-d581-e8c8d8635d08?t=1544544826763',
shadowUrl: 'https://www.weckdenherkulesindir.de/documents/20142/32730/marker-shadow.png/20ac54bb-8339-1fea-659a-e473c5a18bb5?t=1544108384613',
iconSize: [25, 41], // size of the icon
iconAnchor: [12, 41], // point of the icon which will correspond to marker's location
popupAnchor: [0, -34], // point from which the popup should open relative to the iconAnchor
tooltipAnchor: [16, -20],
shadowSize: [41, 41], // size of the shadow
shadowAnchor: [14, 41] // the same for the shadow
});
map.options.minZoom = 12;
var wmsUrl = 'https://geoportal.stadt-kassel.de/arcgis/services/Raster/Geoportal_WebMaps_WGS84/MapServer/WMSServer?';
L.tileLayer.wms(wmsUrl,{
layers:'1:4.514,1:9.028,1:18.056,1:36.112,1:72.224,1:144.448,1:288.895'
}).addTo(map);
/* 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}');
if(ideasJsonArray.length > 0){
var markerGroup = new L.featureGroup();
$.each(ideasJsonArray, function (index, value) {
if(value.isVisibleOnMap){
var latlng = L.latLng(value.latitude,value.longitude);
var loadedMarker = new L.Marker(latlng, {icon: redIcon, draggable:false});
markerGroup.addLayer(loadedMarker);
loadedMarker.dbId = value.id;
loadedMarker.bindTooltip(value.title).openTooltip();
loadedMarker.bindPopup(getMarkerPopUp(value.id,value.title,value.userName,value.pageUrl,value.rating));
map.addLayer(loadedMarker);
}
});
map.options.maxZoom = 16;
map.fitBounds(markerGroup.getBounds().pad(0.5));
var ideasJsonArrayOLD = JSON.parse('${oldIdeas}');
var ideasJsonArrayCURRENT = JSON.parse('${currentIdeas}');
console.log("OLD IDEAS =", ideasJsonArrayOLD.length);
console.log("CURRENT IDEAS =", ideasJsonArrayCURRENT.length);
if(ideasJsonArrayCURRENT.length > 0 || ideasJsonArrayOLD.length > 0){
var markerGroup = new L.featureGroup();
$.each(ideasJsonArrayCURRENT, function (index, value) {
if(value.isVisibleOnMap){
var latlng = L.latLng(value.latitude,value.longitude);
var loadedMarker = new L.Marker(latlng, {icon: redIcon, draggable:false});
markerGroup.addLayer(loadedMarker);
loadedMarker.dbId = value.id;
loadedMarker.bindTooltip(value.title).openTooltip();
loadedMarker.bindPopup(getMarkerPopUp(value.id,value.title,value.userName,value.pageUrl,value.rating));
map.addLayer(loadedMarker);
}
});
$.each(ideasJsonArrayOLD, function (index, value) {
if(value.isVisibleOnMap){
var latlng = L.latLng(value.latitude,value.longitude);
var loadedMarker = new L.Marker(latlng, {icon: greyIcon, draggable:false});
markerGroup.addLayer(loadedMarker);
loadedMarker.dbId = value.id;
loadedMarker.bindTooltip(value.title).openTooltip();
loadedMarker.bindPopup(getMarkerPopUp(value.id,value.title,value.userName,value.pageUrl,value.rating));
map.addLayer(loadedMarker);
}
});
map.options.maxZoom = 16;
map.fitBounds(markerGroup.getBounds().pad(0.5));
}else{
map.setView([51.312066, 9.492901],12)
}
function getMarkerPopUp(id, title, username,link,votes){
var votescount = votes.split(",");
var votescount;
if(votes == '') {
votescount = [];
} else {
votescount = votes.split(",");
}
return "<h4>" + title + "</h4>" + "<p> Eingereicht von " + username + "</p>" + "<p> Stimmen: " + votescount.length + "</p><br>" + "<a href=" + link + ">Details</a>";
}
});
......
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