From 04fb576815f252cc73a32fc4981da5fdc8ed9da8 Mon Sep 17 00:00:00 2001 From: Lee Wexler Date: Mon, 30 Dec 2024 14:33:34 -0500 Subject: [PATCH] Minor fixes to Views (#431) * Checkpoint * Checkpoint --- .../io/xh/hoist/impl/XhViewController.groovy | 3 +- .../io/xh/hoist/view/ViewService.groovy | 65 ++++++++++++------- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/grails-app/controllers/io/xh/hoist/impl/XhViewController.groovy b/grails-app/controllers/io/xh/hoist/impl/XhViewController.groovy index 7a5dc919..bfdb25fe 100644 --- a/grails-app/controllers/io/xh/hoist/impl/XhViewController.groovy +++ b/grails-app/controllers/io/xh/hoist/impl/XhViewController.groovy @@ -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())) } //--------------------------- diff --git a/grails-app/services/io/xh/hoist/view/ViewService.groovy b/grails-app/services/io/xh/hoist/view/ViewService.groovy index b15a471a..c23ac39c 100644 --- a/grails-app/services/io/xh/hoist/view/ViewService.groovy +++ b/grails-app/services/io/xh/hoist/view/ViewService.groovy @@ -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] } /** @@ -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) } //--------------------------- @@ -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) } @@ -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 @@ -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 + } + + }