Skip to content

Commit

Permalink
#225 fixed checkbox buttons on editing field/layer
Browse files Browse the repository at this point in the history
Added warnings when a user tries to delete a disabled field
Fixed context-path and base links
  • Loading branch information
qifeng-bai committed Nov 22, 2023
1 parent 0f8ce2e commit 0c2264b
Show file tree
Hide file tree
Showing 17 changed files with 321 additions and 155 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ext {
drivers = ["firefox", "chrome", "chromeHeadless"]
}

version "2.0.1-SNAPSHOT"
version "2.1.0-SNAPSHOT"
group "au.org.ala"

apply plugin: "eclipse"
Expand Down
2 changes: 1 addition & 1 deletion docker/.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
COMPOSE_PROJECT_NAME=SPATIAL_Geoserver_Postgis
COMPOSE_PROJECT_NAME=spatial_geoserver_postgis
7 changes: 7 additions & 0 deletions grails-app/assets/css/ala/ala-styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,9 @@ a:hover, .link-list .heading a:hover {
a:hover, a:focus {
color: #DA644E;
}
a.disabled {
color: #999999; /* or any other styles for a disabled link */
}

.breadcrumb {
background-color: transparent;
Expand Down Expand Up @@ -2148,6 +2151,10 @@ li .login-soc-bell:hover {
display: table-cell !important;
}

td.disabled {
color: #999999; /* or any other styles for a disabled link */
}

/* (@media print) Typography
================================= */
.caption {
Expand Down
8 changes: 8 additions & 0 deletions grails-app/assets/css/fluid.css
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
body.fluid { max-width: none; width:auto; }
body.fluid .container.container-navbar, body.fluid #breadcrumb .container, body.fluid footer .container { max-width: none; width:auto; }

a.disabled {
color: #999999; /* or any other styles for a disabled link */
}

td.disabled {
color: #999999; /* or any other styles for a disabled link */
}
12 changes: 6 additions & 6 deletions grails-app/conf/application.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
grails:
serverURL: "http://localhost:8081"
server:
port: 8081
servlet:
contextPath: '/ws'
# serverURL: "http://localhost:8081/ws"
# server:
# port: 8081
# servlet:
# contextPath: '/ws'
cors:
# using ala-cors-plugin instead of grailsCorsFilter
enabled: true
Expand Down Expand Up @@ -392,7 +392,7 @@ environments:
server:
port: 8081
servlet:
contextPath: '/ws'
context-path: '/ws'
gdal:
dir: "/Library/Frameworks/GDAL.framework/Programs"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ class ManageLayersController {
//add field to layerId
if (params.containsKey("name")) {
def f = manageLayersService.createOrUpdateField(params, id)
map.putAll(f.properties)
map.putAll(f)
} else {
map.putAll manageLayersService.createOrUpdateField(request.JSON as Map, id)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class ObjectController {
@Path('objects/{fid}')
@Produces("application/json")
def fieldObjects() {
String fid = params.fid
String fid = params.fid ?: params.id
Integer start = params.containsKey('start') ? params.start as Integer : 0
Integer pageSize = params.containsKey('pageSize') ? params.pageSize as Integer : -1

Expand Down
28 changes: 28 additions & 0 deletions grails-app/services/au/org/ala/spatial/FieldService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,34 @@ class FieldService {
log.debug("Getting a list of all enabled fields with indb")
Fields.findAllByEnabledAndIndb(true, true)
}
/**
* Return the count of fields of a layer, no matter they are enabled or not
* @return
*/
int countBySpid(spid) {
Fields.countBySpid(spid)
}

/**
* Return the largest sequence number + 1.
* Avoid getting the incorrect seq if some of the records in the middle are deleted
* @param spid
* @return
*/
def calculateNextSequenceId(spid) {
def requestIds = Fields.findAllBySpid(spid).collect { it.id }
if (requestIds.size() == 0) {
return ''
} else {
def maxSequenceNumber = requestIds
.findAll { it.endsWith("${spid}") }
.collect { it.replaceFirst(/^.{2}/, '')
.replaceAll("${spid}", "") }
.collect {it == '' ? 0 : it.toInteger()}
.max()
maxSequenceNumber + 1
}
}


// synchronized void addField(Field field) {
Expand Down
79 changes: 70 additions & 9 deletions grails-app/services/au/org/ala/spatial/ManageLayersService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -689,20 +689,19 @@ class ManageLayersService {

fieldMap.put("raw_id", layerId)

int countInDB = 0
for (Fields f : fieldService.getFieldsByDB()) {
if (f.getSpid() == String.valueOf(fieldMap.get("id"))) {
countInDB++
}
}
int countInDB = fieldService.countBySpid(layerId)
boolean isContextual = "Contextual".equalsIgnoreCase(String.valueOf(layerMap.get("type")))

fieldMap.put("indb", countInDB == 0)
fieldMap.put("intersect", false) //countInDB == 0 && isContextual);
fieldMap.put("analysis", countInDB == 0)
fieldMap.put("addtomap", countInDB == 0)
fieldMap.put("enabled", true)

fieldMap.put("requestedId", (isContextual ? "cl" : "el") + layerId)
// convention of field name
def sid = fieldService.calculateNextSequenceId(layerId)
fieldMap.put("requestedId", (isContextual ? "cl" : "el") + sid + layerId)


//type
//Contextual and shapefile = c, Environmental = e, Contextual and grid file = a & b
Expand Down Expand Up @@ -738,7 +737,7 @@ class ManageLayersService {
}

if (isContextual && fieldMap.containsKey("columns") && fieldMap.get("columns") != null &&
((List) fieldMap.get("columns")).size > 0) {
((List) fieldMap.get("columns")).size() > 0) {
fieldMap.put("sname", ((List) fieldMap.get("columns")).get(0))
//"sdesc" is optional
}
Expand Down Expand Up @@ -801,13 +800,33 @@ class ManageLayersService {
return extents
}

/**
* Have to determine if it is creating a new field or editing an existing field
*
* Assumption:
* If it is field id, it is an 'edit an existing field' function
* If it is a layer id, then it should be 'create new field' function
*
* Since function fieldMapDefault creates a new 'requestId' ( assigned to id after ) with incremental sequence number
* So, if it is an edit function, the requestId should be unchanged.
*
*
* @param fieldId It is field id if starts with el/cl, otherwise layer id
* @return
*/
def fieldMap(String fieldId) {
def layer = layerService.getLayerById(Integer.parseInt(fieldService.getFieldById(fieldId, false).spid), false)

def map = fieldMapDefault(String.valueOf(layer.id))
map.put("layerName", layer.name) // layer name for wms requests

def field = fieldService.getFieldById(fieldId, false)

if (fieldId.startsWith('cl') || fieldId.startsWith('el')) {
//It stands for 'editing' not creating a new field
//Restore requestedId
map.put("requestedId", field.getId())
}
map.put("id", field.getId())
map.put("desc", field.getDesc())
map.put("name", field.getName())
Expand All @@ -828,7 +847,23 @@ class ManageLayersService {
map
}

/**
*
* @param map params without kv pair of checkbox
* @param id
* @param createTask
* @return
*/
def createOrUpdateLayer(Map map, String id, boolean createTask = true) {
// Unchecked checkbox won't be post via params
Map checkboxFields = [:]
checkboxFields["enabled"] = false
checkboxFields.each { key, value ->
if (!map.containsKey(key)) {
map.put(key,value)
}
}

Layers layer = Layers.get(id) ?: new Layers()
layer.properties.each {
if (map.containsKey(it.key)) {
Expand Down Expand Up @@ -985,7 +1020,33 @@ class ManageLayersService {
columns
}

/**
*
* @param map params from http post
* @param id
* @param createTask
* @return
*/
def createOrUpdateField(Map map, String id, boolean createTask = true) {
//Fields of checkbox
//If checkboxes in form are unchecked, the kv pairs of those checkboxes won't be in form params
Map checkboxFields = [:]
checkboxFields["enabled"] = false
checkboxFields["indb"] = false
checkboxFields["namesearch"] = false
checkboxFields["defaultlayer"] = false
checkboxFields["intersect"] = false
checkboxFields["layerbranch"] = false
checkboxFields["analysis"] = false
checkboxFields["addtomap"] = false

checkboxFields.each { key, value ->
if (!map.containsKey(key)) {
map.put(key,value)
}
}


Fields field = Fields.get(id) ?: new Fields()
field.properties.each {
if (map.containsKey(it.key)) {
Expand Down Expand Up @@ -1117,7 +1178,7 @@ class ManageLayersService {

//create default layers table entry, this updates field.id
Task.withNewTransaction {
if (!newField.save()) {
if (!newField.save(true)) {
newField.errors.each {
log.error(it)
}
Expand Down
3 changes: 2 additions & 1 deletion grails-app/views/layer/index.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<html>
<head>
<title>Available Spatial Layers</title>
<meta name="breadcrumbs" content="${g.createLink(controller: 'main', action: 'index')}, Spatial Service"/>
<g:set var="baseUrl" value="${request.scheme}://${request.serverName}:${request.serverPort}${request.contextPath}" />
<meta name="breadcrumbs" content="${g.createLink(uri: baseUrl)}, Spatial Service"/>
<meta name="layout" content="ala-main"/>
<script src="${resource(dir: 'js', file: 'jquery.js')}"></script>
<script src="${resource(dir: 'js', file: 'jquery.dataTables.min.js')}"></script>
Expand Down
Loading

0 comments on commit 0c2264b

Please sign in to comment.