Skip to content

Commit

Permalink
ERM-2971: Back end changes to support storing location/dimensions of …
Browse files Browse the repository at this point in the history
…widgets (#93)

* feat: Dashboard display data

Added a String field to house generic display data about the dashboard. Have not explicitly modelled as this is display only data and we should not particularly care

refs ERM-2971, ERM-1795

* refactor: DashboardDisplayData

Changed dashboard display data to its own domain class, so we can fetch it completely independently of dashboard. This _does_ mean that editing display data does not count as an update to the dashboard as far as GORM is concerned. However we should NOT be reflecting frontend ordering changes in any backend logic anyway, so this is fine--I think

ERM-2971

* chore: Removed old displayData linked to dashboard object itself
  • Loading branch information
EthanFreestone authored Aug 17, 2023
1 parent 67feccf commit 5916e47
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 13 deletions.
25 changes: 25 additions & 0 deletions service/grails-app/controllers/org/olf/DashboardController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import grails.rest.*
import grails.converters.*

import grails.gorm.multitenancy.CurrentTenant
import grails.gorm.transactions.Transactional
import groovy.util.logging.Slf4j

import com.k_int.okapi.OkapiTenantAwareController
Expand Down Expand Up @@ -126,6 +127,29 @@ class DashboardController extends OkapiTenantAwareController<DashboardController
getUserSpecificDashboards()
}

public def getDisplayData() {
if (!canView()) {
response.sendError(403)
} else {
DashboardDisplayData displayData = DashboardDisplayData.findByDashId(getDashboardId())

respond displayData
}
}

@Transactional
public def editDisplayData() {
if (!canEdit()) {
response.sendError(403)
} else {
DashboardDisplayData displayData = DashboardDisplayData.findByDashId(getDashboardId())
bindData(displayData, getObjectToBind())
updateResource displayData

respond displayData
}
}

public def widgets() {
if (!canView()) {
response.sendError(403)
Expand Down Expand Up @@ -167,6 +191,7 @@ class DashboardController extends OkapiTenantAwareController<DashboardController
} else {
// Ensure you delete all dashboard access objects before the dash itself
dashboardService.deleteAccessObjects(getDashboardId())
dashboardService.deleteDisplayDataObject(getDashboardId())
super.delete()
}
}
Expand Down
4 changes: 4 additions & 0 deletions service/grails-app/controllers/org/olf/UrlMappings.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class UrlMappings {
action = [GET: 'getDashboardUsers', POST: 'editDashboardUsers']
}

"/displayData" ( controller: 'dashboard') {
action = [GET: 'getDisplayData', PUT: 'editDisplayData']
}

"/widgets" (action: 'widgets', method: 'GET')

"/my-access" (action: 'myAccess', method: 'GET')
Expand Down
9 changes: 0 additions & 9 deletions service/grails-app/domain/org/olf/Dashboard.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,22 @@ import com.k_int.web.toolkit.refdata.RefdataValue
import org.olf.ExternalUser

class Dashboard implements MultiTenant<Dashboard> {

String id
String name
String description

/* Due to the nature of dashboard, we need some display only data
* To avoid having to model this and locking ourselves to a particular
* frontend structure, store as RAW json we can send/parse in the frontend
*/
String displayData

static hasMany = [ widgets: WidgetInstance ]

static mapping = {
id column:'dshb_id', generator: 'uuid2', length:36
version column: 'dshb_version'
name column:'dshb_name'
description column: 'dshb_description'
displayData column: 'dshb_display_data'
widgets cascade: 'all-delete-orphan'
}

static constraints = {
name (nullable:true, blank:false)
description (nullable:true, blank:false)
displayData (nullable: true, blank: false)
}
}
24 changes: 24 additions & 0 deletions service/grails-app/domain/org/olf/DashboardDisplayData.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.olf

import grails.gorm.MultiTenant

/* A domain class to hold all of the information about */

class DashboardDisplayData implements MultiTenant<DashboardDisplayData> {

String id
String dashId
String layoutData

static mapping = {
id column:'ddd_id', generator: 'uuid2', length:36
version column: 'ddd_version'
dashId column: 'ddd_dash_id'
layoutData column: 'ddd_layout_data'
}

static constraints = {
dashId (nullable:false, blank:false)
layoutData (nullable: true, blank: false)
}
}
21 changes: 18 additions & 3 deletions service/grails-app/migrations/service-interaction-3-0.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
databaseChangeLog = {
changeSet(author: "efreestone (manual)", id: "2023-08-16-0940-001") {
addColumn (tableName: "dashboard" ) {
column(name: "dshb_display_data", type: "text")
changeSet(author: "efreestone (manual)", id: "2023-08-17-1207-001") {
createTable (tableName: "dashboard_display_data" ) {
column(name: "ddd_id", type: "VARCHAR(36)") {
constraints(nullable: "false")
}
column(name: "ddd_version", type: "BIGINT") {
constraints(nullable: "false")
}
column(name: "ddd_dash_id", type: "VARCHAR(36)")
column(name: "ddd_layout_data", type: "text")
}
}

changeSet(author: "efreestone (manual)", id: "2023-08-17-1207-002") {
addUniqueConstraint(
columnNames: "ddd_dash_id",
constraintName: "dashboard_display_data_dash_id_unique",
tableName: "dashboard_display_data"
)
}
}
10 changes: 10 additions & 0 deletions service/grails-app/services/org/olf/DashboardService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class DashboardService {
defaultUserDashboard: defaultUserDashboard
]).save(flush:true, failOnError: true);

DashboardDisplayData dashboardDisplayData = new DashboardDisplayData([
dashId: dashboard.id,
]).save(flush:true, failOnError: true);

return dashboard;
}

Expand Down Expand Up @@ -79,6 +83,12 @@ class DashboardService {
""".toString(), [dashId: dashboardId])
}

public void deleteDisplayDataObject(String dashboardId) {
DashboardDisplayData.executeUpdate("""
DELETE FROM DashboardDisplayData WHERE dashId = :dashId
""".toString(), [dashId: dashboardId])
}

/*
* A method to update a list of users on a dashboard, or more accurately to
* bulk update a list of DashboardAccess objects which all point at a given dashboard,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import org.olf.DashboardDisplayData

import groovy.transform.*

@Field
DashboardDisplayData dashboardDisplayData

json g.render (dashboardDisplayData)
26 changes: 25 additions & 1 deletion service/src/main/okapi/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@
"permissionsRequired": ["servint.dashboards.item.get"],
"permissionsDesired":["servint.dashboards.admin"]
},
{
"methods": [ "GET" ],
"pathPattern": "/servint/dashboard/{id}/displayData",
"permissionsRequired": ["servint.dashboards.displayData.get"],
"permissionsDesired":["servint.dashboards.admin"]
},
{
"methods": [ "PUT" ],
"pathPattern": "/servint/dashboard/{id}/displayData",
"permissionsRequired": ["servint.dashboards.displayData.put"],
"permissionsDesired":["servint.dashboards.admin"]
},
{
"methods": [ "POST" ],
"pathPattern": "/servint/dashboard",
Expand Down Expand Up @@ -327,11 +339,22 @@
"displayName": "Dashboard user item get",
"description": "Get a dashboard item for a user"
},
{
"permissionName": "servint.dashboards.displayData.get",
"displayName": "Dashboard display data get",
"description": "Get display data for a dashboard"
},
{
"permissionName": "servint.dashboards.displayData.put",
"displayName": "Dashboard display data put",
"description": "Edit display data for a dashboard"
},
{
"permissionName": "servint.dashboards.view",
"subPermissions": [
"servint.dashboards.user.get",
"servint.dashboards.item.get"
"servint.dashboards.item.get",
"servint.dashboards.displayData.get"
]
},
{
Expand Down Expand Up @@ -433,6 +456,7 @@
"servint.dashboards.user.put",
"servint.dashboards.item.post",
"servint.dashboards.item.put",
"servint.dashboards.displayData.put",
"servint.widget.create",
"servint.widget.edit"
]
Expand Down

0 comments on commit 5916e47

Please sign in to comment.