From 1d805a7dd4f5ba1f4e48ef7d1b6b4be2ce154e02 Mon Sep 17 00:00:00 2001 From: lbwexler Date: Mon, 30 Dec 2024 13:25:22 -0500 Subject: [PATCH 1/2] 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 f803e283..191d5a08 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 db2fba03..b21699bc 100644 --- a/grails-app/services/io/xh/hoist/view/ViewService.groovy +++ b/grails-app/services/io/xh/hoist/view/ViewService.groovy @@ -36,25 +36,14 @@ 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] } /** Update state for this user */ - void updateState(String type, String viewInstance, Map update, String username = username) { + Map updateState(String type, String viewInstance, Map update, String username = username) { def currBlob = jsonBlobService.find(type, STATE_BLOB_NAME, username, username), currValue = parseObject(currBlob?.value), newValue = [ @@ -64,10 +53,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 = currValue.userPinned + update.userPinned 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) } //--------------------------- @@ -81,13 +71,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) } @@ -102,10 +102,10 @@ class ViewService extends BaseService { 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 @@ -167,4 +167,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 + } + + } From f301548fb089104fb6d863341c9fdd078f6838cd Mon Sep 17 00:00:00 2001 From: lbwexler Date: Mon, 30 Dec 2024 14:20:29 -0500 Subject: [PATCH 2/2] Checkpoint --- grails-app/services/io/xh/hoist/view/ViewService.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grails-app/services/io/xh/hoist/view/ViewService.groovy b/grails-app/services/io/xh/hoist/view/ViewService.groovy index b21699bc..a67d19d4 100644 --- a/grails-app/services/io/xh/hoist/view/ViewService.groovy +++ b/grails-app/services/io/xh/hoist/view/ViewService.groovy @@ -53,7 +53,7 @@ class ViewService extends BaseService { ] if (update.containsKey('currentView')) newValue.currentView[viewInstance] = update.currentView - if (update.containsKey('userPinned')) newValue.userPinned = currValue.userPinned + update.userPinned + if (update.containsKey('userPinned')) (newValue.userPinned as Map).putAll(update.userPinned as Map) if (update.containsKey('autoSave')) newValue.autoSave = update.autoSave def blob = jsonBlobService.createOrUpdate(type, STATE_BLOB_NAME, [value: newValue], username) @@ -96,7 +96,7 @@ 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(