Skip to content
Snippets Groups Projects
Commit bdf07d86 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

First version of the "turn the pages" functionality

parent e9a646a6
No related branches found
No related tags found
No related merge requests found
...@@ -60,6 +60,17 @@ public class BarkbeetleBean { ...@@ -60,6 +60,17 @@ public class BarkbeetleBean {
.getResultList(); .getResultList();
} }
/**
* Get the list of trapsites for the given season
* @param season
* @return
*/
public List<SeasonTrapsite> getSeasonTrapsiteCandidates(Integer season){
return em.createNamedQuery("SeasonTrapsite.findUnactivatedBySeason")
.setParameter("season", season)
.getResultList();
}
/** /**
* Get a specific trapsite * Get a specific trapsite
* @param seasonTrapsiteId * @param seasonTrapsiteId
...@@ -247,4 +258,49 @@ public class BarkbeetleBean { ...@@ -247,4 +258,49 @@ public class BarkbeetleBean {
public Integer getFirstAvailableSeason() { public Integer getFirstAvailableSeason() {
return (Integer) em.createNativeQuery("SELECT MIN(season) FROM barkbeetle.season_trapsite;").getSingleResult(); return (Integer) em.createNativeQuery("SELECT MIN(season) FROM barkbeetle.season_trapsite;").getSingleResult();
} }
/**
* This effectively makes a copy of all trap sites of one season to another. Registrations are not kept
* @param fromSeason
* @param toSeason
*/
public void copySeasonTrapsites(Integer fromSeason, Integer toSeason)
{
em.createNativeQuery("INSERT INTO barkbeetle.season_trapsite("
+ "season,"
+ "gis_geom,"
+ "trapsite_type,"
+ "county_no,"
+ "county_name,"
+ "municipality_no,"
+ "municipality_name,"
+ "county2012_no,"
+ "county2012_name,"
+ "municipality2012_no,"
+ "municipality2012_name,"
+ "user_id,"
+ "activated"
+ ")\n"
+ "SELECT "
+ ":toSeason,"
+ "gis_geom,"
+ "trapsite_type,"
+ "county_no,"
+ "county_name,"
+ "municipality_no,"
+ "municipality_name,"
+ "county2012_no,"
+ "county2012_name,"
+ "municipality2012_no,"
+ "municipality2012_name,"
+ "user_id,"
+ "FALSE \n"
+ "FROM barkbeetle.season_trapsite "
+ "WHERE season=:fromSeason"
)
.setParameter("fromSeason", fromSeason)
.setParameter("toSeason", toSeason)
.executeUpdate();
}
} }
...@@ -83,7 +83,7 @@ public class BarkbeetleController extends HttpServlet { ...@@ -83,7 +83,7 @@ public class BarkbeetleController extends HttpServlet {
List<SeasonTrapsite> seasonTrapSites = BarkbeetleBean.getInstance().getSeasonTrapsites(season); List<SeasonTrapsite> seasonTrapSites = BarkbeetleBean.getInstance().getSeasonTrapsites(season);
Collections.sort(seasonTrapSites); Collections.sort(seasonTrapSites);
Integer firstAvailableSeason = BarkbeetleBean.getInstance().getFirstAvailableSeason(); Integer firstAvailableSeason = BarkbeetleBean.getInstance().getFirstAvailableSeason();
Integer lastAvailableSeason = Calendar.getInstance().get(Calendar.YEAR); Integer lastAvailableSeason = Calendar.getInstance().get(Calendar.YEAR) + 1;
request.setAttribute("firstAvailableSeason", firstAvailableSeason); request.setAttribute("firstAvailableSeason", firstAvailableSeason);
request.setAttribute("lastAvailableSeason", lastAvailableSeason); request.setAttribute("lastAvailableSeason", lastAvailableSeason);
request.setAttribute("season", season); request.setAttribute("season", season);
...@@ -106,7 +106,7 @@ public class BarkbeetleController extends HttpServlet { ...@@ -106,7 +106,7 @@ public class BarkbeetleController extends HttpServlet {
request.setAttribute("trapsiteRegistrators", SessionControllerGetter.getUserBean().getUsersByVipsLogicRoles(new Integer[]{VipsLogicRole.BARKBEETLE_ADMIN, VipsLogicRole.BARKBEETLE_REGISTRATOR, VipsLogicRole.BARKBEETLE_COUNTY_ADMIN})); request.setAttribute("trapsiteRegistrators", SessionControllerGetter.getUserBean().getUsersByVipsLogicRoles(new Integer[]{VipsLogicRole.BARKBEETLE_ADMIN, VipsLogicRole.BARKBEETLE_REGISTRATOR, VipsLogicRole.BARKBEETLE_COUNTY_ADMIN}));
List<TrapsiteType> trapsiteTypes = BarkbeetleBean.getInstance().getTrapsiteTypes(); List<TrapsiteType> trapsiteTypes = BarkbeetleBean.getInstance().getTrapsiteTypes();
request.setAttribute("season", season); request.setAttribute("season", request.getParameter("seasonTrapsiteId") != null ? trapsite.getSeason() : season);
request.setAttribute("seasonTrapsite", trapsite); request.setAttribute("seasonTrapsite", trapsite);
request.setAttribute("seasonTrapsiteTypes", trapsiteTypes); request.setAttribute("seasonTrapsiteTypes", trapsiteTypes);
request.setAttribute("messageKey", request.getParameter("messageKey")); request.setAttribute("messageKey", request.getParameter("messageKey"));
...@@ -147,6 +147,7 @@ public class BarkbeetleController extends HttpServlet { ...@@ -147,6 +147,7 @@ public class BarkbeetleController extends HttpServlet {
trapsite.setDateInstalled(formValidation.getFormField("dateInstalled").isEmpty() ? null : formValidation.getFormField("dateInstalled").getValueAsDate()); trapsite.setDateInstalled(formValidation.getFormField("dateInstalled").isEmpty() ? null : formValidation.getFormField("dateInstalled").getValueAsDate());
trapsite.setInstallationRemarks(formValidation.getFormField("installationRemarks").getWebValue()); trapsite.setInstallationRemarks(formValidation.getFormField("installationRemarks").getWebValue());
trapsite.setUserId(SessionControllerGetter.getUserBean().getVipsLogicUser(formValidation.getFormField("userId").getValueAsInteger())); trapsite.setUserId(SessionControllerGetter.getUserBean().getVipsLogicUser(formValidation.getFormField("userId").getValueAsInteger()));
trapsite.setLocationUpdated(formValidation.getFormField("locationUpdated").getWebValue().equals("true"));
// Handling the GIS // Handling the GIS
Point p2d = formValidation.getFormField("gisGeom").getValueAsPointWGS84(); Point p2d = formValidation.getFormField("gisGeom").getValueAsPointWGS84();
...@@ -320,13 +321,22 @@ public class BarkbeetleController extends HttpServlet { ...@@ -320,13 +321,22 @@ public class BarkbeetleController extends HttpServlet {
{ {
if(SessionControllerGetter.getUserBean().authorizeUser(user, VipsLogicRole.BARKBEETLE_ADMIN, VipsLogicRole.SUPERUSER)) if(SessionControllerGetter.getUserBean().authorizeUser(user, VipsLogicRole.BARKBEETLE_ADMIN, VipsLogicRole.SUPERUSER))
{ {
try try
{ {
if(BarkbeetleBean.getInstance().deleteSeasonTrapsite(Integer.valueOf(request.getParameter("seasonTrapsiteId")))) SeasonTrapsite trapsite = request.getParameter("seasonTrapsiteId") != null ?
BarkbeetleBean.getInstance().getSeasonTrapsite(Integer.valueOf(request.getParameter("seasonTrapsiteId")))
: null;
if(trapsite != null && BarkbeetleBean.getInstance().deleteSeasonTrapsite(trapsite.getSeasonTrapsiteId()))
{ {
Integer siteSeason = trapsite.getSeason();
String redirectAction = request.getParameter("redirectAction") != null ? "&action=" + request.getParameter("redirectAction") : "";
response.sendRedirect(Globals.PROTOCOL + "://" response.sendRedirect(Globals.PROTOCOL + "://"
+ ServletUtil.getServerName(request) + ServletUtil.getServerName(request)
+ "/barkbeetle?messageKey=deleteOK" + "/barkbeetle?messageKey=deleteOK"
+ "&season=" + siteSeason
+ redirectAction
); );
} }
else else
...@@ -344,6 +354,65 @@ public class BarkbeetleController extends HttpServlet { ...@@ -344,6 +354,65 @@ public class BarkbeetleController extends HttpServlet {
response.sendError(403,"Access not authorized"); // HTTP Forbidden response.sendError(403,"Access not authorized"); // HTTP Forbidden
} }
} }
else if(action.equals("listSeasonTrapsiteCandidates"))
{
List<SeasonTrapsite> seasonTrapSiteCandidates = BarkbeetleBean.getInstance().getSeasonTrapsiteCandidates(season);
Collections.sort(seasonTrapSiteCandidates);
Integer firstAvailableSeason = BarkbeetleBean.getInstance().getFirstAvailableSeason();
Integer lastAvailableSeason = Calendar.getInstance().get(Calendar.YEAR) + 1;
request.setAttribute("firstAvailableSeason", firstAvailableSeason);
request.setAttribute("lastAvailableSeason", lastAvailableSeason);
request.setAttribute("season", season);
request.setAttribute("seasonTrapsites", seasonTrapSiteCandidates);
request.setAttribute("messageKey", request.getParameter("messageKey"));
request.getRequestDispatcher("/modules/barkbeetle/barkbeetleSeasonTrapsiteCandidateList.ftl").forward(request, response);
}
else if(action.equals("activateSeasonTrapsite"))
{
if(!SessionControllerGetter.getUserBean().authorizeUser(user, VipsLogicRole.BARKBEETLE_ADMIN, VipsLogicRole.BARKBEETLE_COUNTY_ADMIN, VipsLogicRole.ORGANIZATION_ADMINISTRATOR, VipsLogicRole.SUPERUSER))
{
response.sendError(403,"Access not authorized"); // HTTP Forbidden
}
SeasonTrapsite trapsite = request.getParameter("seasonTrapsiteId") != null ?
BarkbeetleBean.getInstance().getSeasonTrapsite(Integer.valueOf(request.getParameter("seasonTrapsiteId")))
: null;
if(trapsite != null)
{
trapsite.setActivated(Boolean.TRUE);
BarkbeetleBean.getInstance().storeSeasonTrapsite(trapsite);
response.sendRedirect(Globals.PROTOCOL + "://"
+ ServletUtil.getServerName(request)
+ "/barkbeetle?action=listSeasonTrapsiteCandidates&messageKey=activateOK&season=" + trapsite.getSeason()
);
}
else
{
response.sendError(404,"Den etterspurte fellelokaliteten finnes ikke i databasen"); // HTTP Forbidden
}
}
else if(action.equals("copySeasonTrapsites"))
{
if(!SessionControllerGetter.getUserBean().authorizeUser(user, VipsLogicRole.BARKBEETLE_ADMIN, VipsLogicRole.ORGANIZATION_ADMINISTRATOR, VipsLogicRole.SUPERUSER))
{
response.sendError(403,"Access not authorized"); // HTTP Forbidden
}
try
{
Integer fromSeason = Integer.valueOf(request.getParameter("fromSeason"));
Integer toSeason = Integer.valueOf(request.getParameter("toSeason"));
BarkbeetleBean.getInstance().copySeasonTrapsites(fromSeason, toSeason);
response.sendRedirect(Globals.PROTOCOL + "://"
+ ServletUtil.getServerName(request)
+ "/barkbeetle?action=listSeasonTrapsiteCandidates&season=" + toSeason
);
}
catch(NullPointerException | NumberFormatException ex)
{
response.sendError(500, ex.getMessage());
}
}
} }
else else
{ {
......
...@@ -67,7 +67,8 @@ import org.locationtech.jts.geom.Point; ...@@ -67,7 +67,8 @@ import org.locationtech.jts.geom.Point;
@NamedQueries({ @NamedQueries({
@NamedQuery(name = "SeasonTrapsite.findAll", query = "SELECT s FROM SeasonTrapsite s"), @NamedQuery(name = "SeasonTrapsite.findAll", query = "SELECT s FROM SeasonTrapsite s"),
@NamedQuery(name = "SeasonTrapsite.findBySeasonTrapsiteId", query = "SELECT s FROM SeasonTrapsite s WHERE s.seasonTrapsiteId = :seasonTrapsiteId"), @NamedQuery(name = "SeasonTrapsite.findBySeasonTrapsiteId", query = "SELECT s FROM SeasonTrapsite s WHERE s.seasonTrapsiteId = :seasonTrapsiteId"),
@NamedQuery(name = "SeasonTrapsite.findBySeason", query = "SELECT s FROM SeasonTrapsite s WHERE s.season = :season"), @NamedQuery(name = "SeasonTrapsite.findBySeason", query = "SELECT s FROM SeasonTrapsite s WHERE s.season = :season AND s.activated IS TRUE"),
@NamedQuery(name = "SeasonTrapsite.findUnactivatedBySeason", query = "SELECT s FROM SeasonTrapsite s WHERE s.season = :season AND s.activated IS FALSE"),
@NamedQuery(name = "SeasonTrapsite.findByUserId", query = "SELECT s FROM SeasonTrapsite s WHERE s.userId = :userId"), @NamedQuery(name = "SeasonTrapsite.findByUserId", query = "SELECT s FROM SeasonTrapsite s WHERE s.userId = :userId"),
@NamedQuery(name = "SeasonTrapsite.findByOwnerName", query = "SELECT s FROM SeasonTrapsite s WHERE s.ownerName = :ownerName"), @NamedQuery(name = "SeasonTrapsite.findByOwnerName", query = "SELECT s FROM SeasonTrapsite s WHERE s.ownerName = :ownerName"),
@NamedQuery(name = "SeasonTrapsite.findByOwnerPhone", query = "SELECT s FROM SeasonTrapsite s WHERE s.ownerPhone = :ownerPhone"), @NamedQuery(name = "SeasonTrapsite.findByOwnerPhone", query = "SELECT s FROM SeasonTrapsite s WHERE s.ownerPhone = :ownerPhone"),
...@@ -133,6 +134,10 @@ public class SeasonTrapsite implements Serializable, Comparable { ...@@ -133,6 +134,10 @@ public class SeasonTrapsite implements Serializable, Comparable {
@JoinColumn(name = "trapsite_type", referencedColumnName = "trapsite_type_id") @JoinColumn(name = "trapsite_type", referencedColumnName = "trapsite_type_id")
@ManyToOne @ManyToOne
private TrapsiteType trapsiteType; private TrapsiteType trapsiteType;
@Column(name = "activated")
private Boolean activated;
@Column(name = "location_updated")
private Boolean locationUpdated;
public SeasonTrapsite() { public SeasonTrapsite() {
} }
...@@ -538,5 +543,21 @@ public class SeasonTrapsite implements Serializable, Comparable { ...@@ -538,5 +543,21 @@ public class SeasonTrapsite implements Serializable, Comparable {
public void setMunicipality2012Name(String municipality2012Name) { public void setMunicipality2012Name(String municipality2012Name) {
this.municipality2012Name = municipality2012Name; this.municipality2012Name = municipality2012Name;
} }
public Boolean getActivated() {
return activated;
}
public void setActivated(Boolean activated) {
this.activated = activated;
}
public Boolean getLocationUpdated() {
return locationUpdated;
}
public void setLocationUpdated(Boolean locationUpdated) {
this.locationUpdated = locationUpdated;
}
} }
...@@ -121,6 +121,11 @@ ...@@ -121,6 +121,11 @@
"name" : "propertySectionNo", "name" : "propertySectionNo",
"dataType" : "INTEGER", "dataType" : "INTEGER",
"required" : false "required" : false
},
{
"name" : "locationUpdated",
"dataType" : "STRING",
"required" : true
} }
......
<#--
Copyright (c) 2020 NIBIO <http://www.nibio.no/>.
This file is part of VIPSLogic.
VIPSLogic is free software: you can redistribute it and/or modify
it under the terms of the NIBIO Open Source License as published by
NIBIO, either version 1 of the License, or (at your option) any
later version.
VIPSLogic is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
NIBIO Open Source License for more details.
You should have received a copy of the NIBIO Open Source License
along with VIPSLogic. If not, see <http://www.nibio.no/licenses/>.
--><#include "../../master.ftl">
<#macro page_head>
<title>Barkbilleregistrering: Fellelokalitet-kandidater for sesongen ${season}</title>
</#macro>
<#macro page_contents>
<#if messageKey?has_content && messageKey=="activateOK">
<div class="alert alert-success">Fellelokaliteten ble aktivert ${.now}</div>
</#if>
<#if messageKey?has_content && messageKey=="deleteOK">
<div class="alert alert-success">Fellelokaliteten ble slettet ${.now}</div>
</#if>
<p>
<a href="/barkbeetle?season=${season}" class="btn btn-default back" role="button">${i18nBundle.back}</a>
</p>
<h1>Fellelokalitet-kandidater for sesongen ${season}</h1>
<div class="form-inline">
<div class="form-group">
Velg sesong <select class="form-control" onchange="window.location.href='/barkbeetle?action=listSeasonTrapsiteCandidates&season=' + this.options[this.selectedIndex].value;">
<#list firstAvailableSeason..lastAvailableSeason as availableSeason>
<option value="${availableSeason}" <#if availableSeason==season>selected</#if>>${availableSeason}</option>
</#list>
</select>
</div>
</div>
<div class="row">
<div class="col-md-12">
FORKLARING HER
</div>
</div>
<div class="singleBlockContainer">
<div class="row">
<#if seasonTrapsites?size == 0>
<div class="alert alert-warning">
Det finnes for øyeblikket ingen fjorårskopier tilgjengelig. Dette kan enten skyldes at administrator
ikke har "snudd bunken", eller at alle kopiene er ferdig revidert.
</div>
<#if userIsAdmin>
<p>
<button type="button" onclick="if(confirm('Ønsker du virkelig å kopiere fellelokaliteter fra ${season-1} til ${season}?')){window.location.href='/barkbeetle?action=copySeasonTrapsites&fromSeason=${season-1}&toSeason=${season}';}" class="btn btn-primary" role="button">Snu bunken</button>
</p>
</#if>
</#if>
<table class="table table-striped">
<thead>
<th>Fylke</th>
<th>Kommune</th>
<th>Eier</th>
<th>Lokalitet oppdatert</th>
<th>Registrant</th>
<th></th>
<th></th>
<th></th>
</thead>
<tbody>
<#list seasonTrapsites as site>
<tr>
<td>${site.countyName!""}</td>
<td>${site.municipalityName!""}</td>
<td><span class="alert-${site.ownerName?has_content?string("success","danger")}">${site.ownerName!"Ikke oppgitt"}</span></td>
<td><span class="alert-${site.locationUpdated?string("success","danger")}">${site.locationUpdated?string("Ja","Nei")}</span></td>
<td>${site.userId.firstName} ${site.userId.lastName}</td>
<#if userIsAdmin || userIsCountyAdmin || user.userId == site.userId.userId>
<td><a href="/barkbeetle?action=editSeasonTrapsite&season=${season}&seasonTrapsiteId=${site.seasonTrapsiteId}" class="btn btn-default" role="button">Endre lokalitetsinfo</a></td>
<td><#if site.ownerName?has_content && site.locationUpdated><a href="/barkbeetle?action=activateSeasonTrapsite&seasonTrapsiteId=${site.seasonTrapsiteId}" class="btn btn-default" role="button">Aktiver fellelokalitet</a></#if></td>
<#else>
<td colspan="2"></td>
</#if>
<td><button type="button" class="btn btn-danger" onclick="if(confirm('Ønsker du virkelig å slette?')){window.location.href='/barkbeetle?action=seasonTrapsiteDelete&redirectAction=listSeasonTrapsiteCandidates&seasonTrapsiteId=${site.seasonTrapsiteId}';}">Slett</button></td>
</tr>
</#list>
</tbody>
</table>
</div>
</div>
</#macro>
<#macro custom_js>
<script type="text/javascript" src="/js/constants.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// Check for Internet Explorer
var ua = window.navigator.userAgent;
//console.info(ua);
if(ua.indexOf("MSIE ") >= 0 || navigator.userAgent.match(/Trident.*rv\:11\./))
{
alert("Hei! Det ser ut som du bruker Internet Explorer. Vi anbefaler Firefox, Edge eller Chrome når du er på denne nettsiden.");
return;
}
});
</script>
</#macro>
<#macro custom_css>
<link rel="stylesheet" type="text/css" href="/css/3rdparty/ol.css"/ >
<style type="text/css">
td.status_1 {
background-color: #ffe066 !important;
}
td.status_2 {
background-color: #1aff88 !important;
}
td.status_3 {
background-color: #ff6e66 !important;
}
#seasonTrapsiteListMap {
height: 500px;
}
div.popover {
min-width: 250px !important;
}
</style>
</#macro>
<@page_html/>
\ No newline at end of file
...@@ -88,6 +88,7 @@ ...@@ -88,6 +88,7 @@
theForm["countyName"].value=municInfo[0]["fylkenavn"]; theForm["countyName"].value=municInfo[0]["fylkenavn"];
theForm["municipalityNo"].value=municInfo[0]["komnr"]; theForm["municipalityNo"].value=municInfo[0]["komnr"];
theForm["municipalityName"].value=municInfo[0]["komnavn"]; theForm["municipalityName"].value=municInfo[0]["komnavn"];
theForm["locationUpdated"].value="true"; // This is for candidate trapsites copied from last year
} }
} }
) )
...@@ -152,7 +153,7 @@ ...@@ -152,7 +153,7 @@
<div class="alert alert-success">Data ble lagret ${.now}</div> <div class="alert alert-success">Data ble lagret ${.now}</div>
</#if> </#if>
<p> <p>
<a href="/barkbeetle?season=${season}" class="btn btn-default back" role="button">${i18nBundle.back}</a> <a href="/barkbeetle?season=${season}<#if seasonTrapsite.seasonTrapsiteId?has_content && !seasonTrapsite.activated>&action=listSeasonTrapsiteCandidates</#if>" class="btn btn-default back" role="button">${i18nBundle.back}</a>
</p> </p>
<h1><#if seasonTrapsite.seasonTrapsiteId?has_content>Rediger<#else>Ny</#if> fellelokalitet</h1> <h1><#if seasonTrapsite.seasonTrapsiteId?has_content>Rediger<#else>Ny</#if> fellelokalitet</h1>
<div class="row"> <div class="row">
...@@ -189,6 +190,7 @@ ...@@ -189,6 +190,7 @@
<p>Felt merket med * må være utfylt</p> <p>Felt merket med * må være utfylt</p>
<form id="${formId}" role="form" action="/barkbeetle?action=seasonTrapsiteFormSubmit" method="POST" onsubmit="return validateForm(this);""> <form id="${formId}" role="form" action="/barkbeetle?action=seasonTrapsiteFormSubmit" method="POST" onsubmit="return validateForm(this);"">
<input type="hidden" name="seasonTrapsiteId" value="${seasonTrapsite.seasonTrapsiteId!"-1"}"/> <input type="hidden" name="seasonTrapsiteId" value="${seasonTrapsite.seasonTrapsiteId!"-1"}"/>
<input type="hidden" name="locationUpdated" value="${seasonTrapsite.locationUpdated?string("true","false")}"/>
<div class="form-group"> <div class="form-group">
<label for="trapsiteType">Type fellelokalitet *</label> <label for="trapsiteType">Type fellelokalitet *</label>
<select class="form-control" name="trapsiteTypeId" onblur="validateField(this);"> <select class="form-control" name="trapsiteTypeId" onblur="validateField(this);">
......
...@@ -92,6 +92,9 @@ ...@@ -92,6 +92,9 @@
<p> <p>
<a href="/barkbeetle?action=editSeasonTrapsite&season=${season}" class="btn btn-default" role="button">${i18nBundle.addNew}</a> <a href="/barkbeetle?action=editSeasonTrapsite&season=${season}" class="btn btn-default" role="button">${i18nBundle.addNew}</a>
</p> </p>
<p>
<a href="/barkbeetle?action=listSeasonTrapsiteCandidates&season=${season}" class="btn btn-default" role="button">Hent en kopi fra fjoråret</a>
</p>
</#if> </#if>
<div class="singleBlockContainer"> <div class="singleBlockContainer">
<div class="row"> <div class="row">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment