Skip to content

Commit

Permalink
Minor fixes to Views (#431)
Browse files Browse the repository at this point in the history
* Checkpoint

* Checkpoint
  • Loading branch information
lbwexler authored Dec 30, 2024
1 parent e508af0 commit 04fb576
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ class XhViewController extends BaseController {
}

def updateState(String type, String viewInstance) {
viewService.updateState(type, viewInstance, parseRequestJSON())
renderJSON([success: true])
renderJSON(viewService.updateState(type, viewInstance, parseRequestJSON()))
}

//---------------------------
Expand Down
65 changes: 40 additions & 25 deletions grails-app/services/io/xh/hoist/view/ViewService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,10 @@ class ViewService extends BaseService {
def blobs = jsonBlobService.list(type, username).split { it.name == STATE_BLOB_NAME }
def (rawState, views) = [blobs[0], blobs[1]]

// Transform state
rawState = rawState ? parseObject(rawState[0].value) : null
def state = [
userPinned: rawState?.userPinned ?: [:],
autoSave: rawState?.autoSave ?: false
return [
state: getStateFromBlob(rawState ? rawState.first() : null, viewInstance),
views: views*.formatForClient(false)
]
Map currentView = rawState?.currentView as Map
if (currentView?.containsKey(viewInstance)) {
state.currentView = currentView[viewInstance]
}

// Transform views
views = views*.formatForClient(false)

return [state: state, views: views]
}

/**
Expand All @@ -83,10 +72,11 @@ class ViewService extends BaseService {
]

if (update.containsKey('currentView')) newValue.currentView[viewInstance] = update.currentView
if (update.containsKey('userPinned')) newValue.userPinned = update.userPinned
if (update.containsKey('userPinned')) (newValue.userPinned as Map).putAll(update.userPinned as Map)
if (update.containsKey('autoSave')) newValue.autoSave = update.autoSave

jsonBlobService.createOrUpdate(type, STATE_BLOB_NAME, [value: newValue], username)
def blob = jsonBlobService.createOrUpdate(type, STATE_BLOB_NAME, [value: newValue], username)
return getStateFromBlob(blob, viewInstance)
}

//---------------------------
Expand All @@ -100,13 +90,23 @@ class ViewService extends BaseService {
/** Create a new view. */
Map create(Map data, String username = username) {
def ret = jsonBlobService.create([
type: data.type,
name: data.name,
type : data.type,
name : data.name,
description: data.description,
acl: data.isShared ? '*' : null,
meta: [group: data.group, isShared: data.isShared],
value: data.value
acl : data.isShared ? '*' : null,
meta : [group: data.group, isShared: data.isShared],
value : data.value
], username)

if (data.isPinned) {
updateState(
data.type as String,
'default',
[userPinned: [(ret.token): data.isPinned]],
username
)
}

trackChange('Created View', ret)
ret.formatForClient(true)
}
Expand All @@ -115,16 +115,16 @@ class ViewService extends BaseService {
Map updateInfo(String token, Map data, String username = username) {
def existing = jsonBlobService.get(token, username),
existingMeta = parseObject(existing.meta),
isGlobal = existingMeta.isGlobal,
isGlobal = !existing.owner,
isShared = data.containsKey('isShared') ? data.isShared : existingMeta.isShared;

def ret = jsonBlobService.update(
token,
[
*: data,
acl: isGlobal || isShared ? '*' : null,
* : data,
acl : isGlobal || isShared ? '*' : null,
meta: isGlobal ?
[group: data.group, isDefaultPinned: !!data.isDefaultPinned]:
[group: data.group, isDefaultPinned: !!data.isDefaultPinned] :
[group: data.group, isShared: !!data.isShared],
],
username
Expand Down Expand Up @@ -186,4 +186,19 @@ class ViewService extends BaseService {
data
)
}

private Map getStateFromBlob(JsonBlob blob, String viewInstance) {
def rawState = parseObject(blob?.value),
ret = [
userPinned: rawState?.userPinned ?: [:],
autoSave : rawState?.autoSave ?: false
]
Map currentView = rawState?.currentView as Map
if (currentView?.containsKey(viewInstance)) {
ret.currentView = currentView[viewInstance]
}
return ret
}


}

0 comments on commit 04fb576

Please sign in to comment.