From c55f73fc93c01f594902f4224a488d9b9c9ed021 Mon Sep 17 00:00:00 2001
From: Xiao Gui <xgui3783@gmail.com>
Date: Tue, 26 Apr 2022 16:45:33 +0200
Subject: [PATCH] fix lint

---
 src/api/service.ts       | 317 ++++++++++++++++++++-------------------
 src/messaging/service.ts |  29 ++--
 2 files changed, 176 insertions(+), 170 deletions(-)

diff --git a/src/api/service.ts b/src/api/service.ts
index 0e47842b9..2427dcaa9 100644
--- a/src/api/service.ts
+++ b/src/api/service.ts
@@ -236,196 +236,201 @@ export class ApiService implements BoothResponder<ApiBoothEvents>{
 
     const method = event.method.replace(nameSpaceRegex, '').replace(/^\./, '')
     switch (method) {
-      case 'getAllAtlases': {
-        if (!event.id) return
-        const atlases = await this.sapi.atlases$.pipe(
-          take(1)
-        ).toPromise()
-        return {
-          id: event.id,
-          result: atlases,
-          jsonrpc: '2.0'
+    case 'getAllAtlases': {
+      if (!event.id) return
+      const atlases = await this.sapi.atlases$.pipe(
+        take(1)
+      ).toPromise()
+      return {
+        id: event.id,
+        result: atlases,
+        jsonrpc: '2.0'
+      }
+    }
+    case 'getSupportedParcellations': {
+      if (!event.id) return
+      const parcs = await this.store.pipe(
+        atlasSelection.fromRootStore.allAvailParcs(this.sapi),
+        take(1)
+      ).toPromise()
+      return {
+        id: event.id,
+        jsonrpc: '2.0',
+        result: parcs
+      }
+    }
+    case 'getSupportedTemplates': {
+      if (!event.id) return
+      const spaces = await this.store.pipe(
+        atlasSelection.fromRootStore.allAvailSpaces(this.sapi),
+        take(1)
+      ).toPromise()
+      return {
+        id: event.id,
+        jsonrpc: '2.0',
+        result: spaces
+      }
+    }
+    case 'selectAtlas': {
+      const atlases = await this.sapi.atlases$.pipe(
+        take(1)
+      ).toPromise()
+      const id = event.params as ApiBoothEvents['selectAtlas']['request']
+      const atlas = atlases.find(atlas => atlas["@id"] === id?.["@id"])
+      if (!atlas) {
+        if (!!event.id) {
+          return {
+            id: event.id,
+            jsonrpc: '2.0',
+            error: {
+              code: -32602,
+              message:`atlas id ${id?.["@id"]} not found`
+            }
+          }
         }
+        return
       }
-      case 'getSupportedParcellations': {
-        if (!event.id) return
-        const parcs = await this.store.pipe(
-          atlasSelection.fromRootStore.allAvailParcs(this.sapi),
-          take(1)
-        ).toPromise()
+      this.store.dispatch(
+        atlasSelection.actions.selectAtlas({ atlas })
+      )
+      if (!!event.id) {
         return {
-          id: event.id,
           jsonrpc: '2.0',
-          result: parcs
+          id: event.id,
+          result: null
         }
       }
-      case 'getSupportedTemplates': {
-        if (!event.id) return
-        const spaces = await this.store.pipe(
-          atlasSelection.fromRootStore.allAvailSpaces(this.sapi),
-          take(1)
-        ).toPromise()
+      break
+    }
+    case 'selectParcellation': {
+      if (!!event.id) {
         return {
-          id: event.id,
           jsonrpc: '2.0',
-          result: spaces
-        }
-      }
-      case 'selectAtlas': {
-        const atlases = await this.sapi.atlases$.pipe(
-          take(1)
-        ).toPromise()
-        const id = event.params as ApiBoothEvents['selectAtlas']['request']
-        const atlas = atlases.find(atlas => atlas["@id"] === id?.["@id"])
-        if (!atlas) {
-          if (!!event.id) {
-            return {
-              id: event.id,
-              jsonrpc: '2.0',
-              error: {
-                code: -32602,
-                message:`atlas id ${id?.["@id"]} not found`
-              }
-            }
+          id: event.id,
+          error: {
+            code: -32601,
+            message: `NYI`
           }
-          return
         }
-        this.store.dispatch(
-          atlasSelection.actions.selectAtlas({ atlas })
-        )
-        if (!!event.id) {
-          return {
-            jsonrpc: '2.0',
-            id: event.id,
-            result: null
+      }
+      break
+    }
+    case 'selectTemplate': {
+      if (!!event.id) {
+        return {
+          jsonrpc: '2.0',
+          id: event.id,
+          error: {
+            code: -32601,
+            message: `NYI`
           }
         }
       }
-      case 'selectParcellation': {
-        if (!!event.id) {
-          return {
-            jsonrpc: '2.0',
-            id: event.id,
-            error: {
-              code: -32601,
-              message: `NYI`
-            }
-          }
+      break
+    }
+    case 'navigateTo': {
+      const { animate, ...navigation } = event.params as ApiBoothEvents['navigateTo']['request']
+      this.store.dispatch(
+        atlasSelection.actions.navigateTo({
+          navigation,
+          animation: !!animate
+        })
+      )
+      if (!!event.id) {
+        const timeoutDuration = !!animate
+          ? 500
+          : 0
+        await new Promise(rs => setTimeout(rs, timeoutDuration))
+        return {
+          id: event.id,
+          jsonrpc: '2.0',
+          result: null
         }
       }
-      case 'selectTemplate': {
-        if (!!event.id) {
-          return {
-            jsonrpc: '2.0',
-            id: event.id,
-            error: {
-              code: -32601,
-              message: `NYI`
-            }
+      break
+    }
+    case 'getUserToSelectARoi': {
+      const { params, id } = event as JRPCRequest<'getUserToSelectARoi', ApiBoothEvents['getUserToSelectARoi']['request']>
+      const { type, message } = params
+      if (!params || (type !== "region" && type !== "point")) {
+        return {
+          id: event.id,
+          jsonrpc: '2.0',
+          error: {
+            code: -32602,
+            message: `type must be either region or point!`
           }
         }
       }
-      case 'navigateTo': {
-        const { animate, ...navigation } = event.params as ApiBoothEvents['navigateTo']['request']
-        this.store.dispatch(
-          atlasSelection.actions.navigateTo({
-            navigation,
-            animation: !!animate
-          })
-        )
+      let rs, rj
+      const promise = new Promise<RequestUserTypes['region'] | RequestUserTypes['point']>((_rs, _rj) => {
+        rs = _rs
+        rj = _rj
+      })
+      this.requestUserQueue.push({
+        message,
+        promise,
+        id,
+        type: type as 'region' | 'point',
+        rj,
+        rs
+      })
+      this.requestUser$.next(
+        this.requestUserQueue[0]
+      )
+      return promise.then(val => {
+        return {
+          id,
+          jsonrpc: '2.0',
+          result: val
+        }
+      })
+    }
+    case 'cancelRequest': {
+      const { id } = event.params as ApiBoothEvents['cancelRequest']['request']
+      const idx = this.requestUserQueue.findIndex(q => q.id === id)
+      if (idx < 0) {
         if (!!event.id) {
-          const timeoutDuration = !!animate
-            ? 500
-            : 0
-          await new Promise(rs => setTimeout(rs, timeoutDuration))
           return {
-            id: event.id,
             jsonrpc: '2.0',
-            result: null
-          }
-        }
-      }
-      case 'getUserToSelectARoi': {
-        const { params, id } = event as JRPCRequest<'getUserToSelectARoi', ApiBoothEvents['getUserToSelectARoi']['request']>
-        const { type, message } = params
-        if (!params || (type !== "region" && type !== "point")) {
-          return {
             id: event.id,
-            jsonrpc: '2.0',
             error: {
-              code: -32602,
-              message: `type must be either region or point!`
+              code: -1,
+              message: `cancelRequest failed, request with id ${id} does not exist, or has already been resolved.`
             }
           }
         }
-        let rs, rj, promise = new Promise<RequestUserTypes['region'] | RequestUserTypes['point']>((_rs, _rj) => {
-          rs = _rs
-          rj = _rj
-        })
-        this.requestUserQueue.push({
-          message,
-          promise,
-          id,
-          type: type as 'region' | 'point',
-          rj,
-          rs
-        })
-        this.requestUser$.next(
-          this.requestUserQueue[0]
-        )
-        return promise.then(val => {
-          return {
-            id,
-            jsonrpc: '2.0',
-            result: val
-          }
-        })
+        return
       }
-      case 'cancelRequest': {
-        const { id } = event.params as ApiBoothEvents['cancelRequest']['request']
-        const idx = this.requestUserQueue.findIndex(q => q.id === id)
-        if (idx < 0) {
-          if (!!event.id) {
-            return {
-              jsonrpc: '2.0',
-              id: event.id,
-              error: {
-                code: -1,
-                message: `cancelRequest failed, request with id ${id} does not exist, or has already been resolved.`
-              }
-            }
-          }
-          return
-        }
-        const req = this.requestUserQueue.splice(idx, 1)
-        req[0].rj(`client cancelled`)
+      const req = this.requestUserQueue.splice(idx, 1)
+      req[0].rj(`client cancelled`)
 
-        this.requestUser$.next(
-          this.requestUserQueue[0]
-        )
+      this.requestUser$.next(
+        this.requestUserQueue[0]
+      )
 
-        if (!!event.id) {
-          return {
-            jsonrpc: '2.0',
-            id: event.id,
-            result: null
-          }
+      if (!!event.id) {
+        return {
+          jsonrpc: '2.0',
+          id: event.id,
+          result: null
         }
-        break
       }
-      default: {
-        const message = `Method ${event.method} not found.`
-        if (!!event.id) {
-          return {
-            jsonrpc: '2.0',
-            id: event.id,
-            error: {
-              code: -32601,
-              message
-            }
+      break
+    }
+    default: {
+      const message = `Method ${event.method} not found.`
+      if (!!event.id) {
+        return {
+          jsonrpc: '2.0',
+          id: event.id,
+          error: {
+            code: -32601,
+            message
           }
         }
       }
     }
+    }
   }
 }
diff --git a/src/messaging/service.ts b/src/messaging/service.ts
index 7a1c1f7ff..d3649cdf3 100644
--- a/src/messaging/service.ts
+++ b/src/messaging/service.ts
@@ -188,20 +188,21 @@ export class MessagingService {
       })
       isLoadingSnack?.dismiss()
       const meshId = 'bobby'
-      if (false) {
-        /**
-         * TODO re-enable plotly VTK mesh
-         */
-        const { objectUrl, customFragmentColor } = resp.result || {}
-        // this.loadMesh({
-        //   type: 'VTK',
-        //   id: meshId,
-        //   url: objectUrl,
-        //   customFragmentColor
-        // })
-      } else {
-        this.snackbar.open(`Error: loadMesh method not injected.`)
-      }
+      /**
+       * TODO re-enable plotly VTK mesh
+       */
+      
+      // if (false) {
+      //   const { objectUrl, customFragmentColor } = resp.result || {}
+      //   this.loadMesh({
+      //     type: 'VTK',
+      //     id: meshId,
+      //     url: objectUrl,
+      //     customFragmentColor
+      //   })
+      // } else {
+      //   this.snackbar.open(`Error: loadMesh method not injected.`)
+      // }
       return 'OK'
     }
 
-- 
GitLab