Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes to Views #431

Merged
merged 3 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}


}
Loading