Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Memri
iOS client for Memri
Commits
9f7eeb00
Commit
9f7eeb00
authored
3 years ago
by
Chaitanya Pandit
Browse files
Options
Download
Email Patches
Plain Diff
Rendering from plugin CVU
parent
78613ec8
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
MemriApp/CVU/CVUController.swift
+4
-4
MemriApp/CVU/CVUController.swift
MemriApp/CVU/actions/CVUAction.swift
+11
-6
MemriApp/CVU/actions/CVUAction.swift
MemriApp/Controllers/Plugins/PluginHandler.swift
+13
-17
MemriApp/Controllers/Plugins/PluginHandler.swift
MemriApp/Controllers/PubSub/PubSubController.swift
+10
-2
MemriApp/Controllers/PubSub/PubSubController.swift
MemriApp/Controllers/SceneController.swift
+5
-5
MemriApp/Controllers/SceneController.swift
MemriApp/Controllers/Syncing/SyncController.swift
+11
-5
MemriApp/Controllers/Syncing/SyncController.swift
MemriApp/UI/Renderers/GeneralEditorRenderer.swift
+24
-3
MemriApp/UI/Renderers/GeneralEditorRenderer.swift
with
78 additions
and
42 deletions
+78
-42
MemriApp/CVU/CVUController.swift
+
4
-
4
View file @
9f7eeb00
...
...
@@ -10,17 +10,17 @@ import Foundation
class
CVUController
{
var
definitions
:
[
CVUParsedDefinition
]
init
()
{
init
(
_
content
:
String
?
=
nil
)
{
do
{
definitions
=
Constants
.
isRunningTests
?
[]
:
try
CVUController
.
parseCVU
()
definitions
=
Constants
.
isRunningTests
?
[]
:
try
CVUController
.
parseCVU
(
content
)
}
catch
{
print
(
error
)
definitions
=
[]
}
}
static
func
parseCVU
()
throws
->
[
CVUParsedDefinition
]
{
let
string
=
CVUController
.
readCVUString
()
static
func
parseCVU
(
_
content
:
String
?
=
nil
)
throws
->
[
CVUParsedDefinition
]
{
let
string
=
content
??
CVUController
.
readCVUString
()
return
try
parseCVU
(
string
:
string
)
}
...
...
This diff is collapsed.
Click to expand it.
MemriApp/CVU/actions/CVUAction.swift
+
11
-
6
View file @
9f7eeb00
...
...
@@ -422,13 +422,18 @@ struct CVUAction_PluginRun: CVUAction {
try
pluginRunItem
.
setPropertyValue
(
name
:
"status"
,
value
:
.
string
(
"idle"
))
try
pluginRunItem
.
setPropertyValue
(
name
:
"pluginModule"
,
value
:
.
string
(
pluginModule
))
try
pluginRunItem
.
setPropertyValue
(
name
:
"pluginName"
,
value
:
.
string
(
pluginName
))
// This is test code to render cvu for a plugin locally without connecting to pod
// Ideally plugins will contain more detailed container name
// We can remove this once plugins are able to send CVUs in stored definition
/*
// This is test code to render cvu for a plugin locally without connecting to pod
// Ideally plugins will contain more detailed container name
// We can remove this once plugins are able to send CVUs in stored definition
if (container == "cvu") {
PluginHandler
.
presentCVUforPlugin
(
plugin
:
plugin
,
runner
:
pluginRunItem
,
sceneController
:
sceneController
,
context
:
context
)
}
else
{
PluginHandler.presentDemoCVUforPlugin(plugin: plugin, runner: pluginRunItem, sceneController: sceneController, context: context)
return
}
*/
try
?
AppController
.
shared
.
syncController
.
sync
{
_
in
PluginHandler
.
start
(
plugin
:
plugin
,
runner
:
pluginRunItem
,
sceneController
:
sceneController
,
context
:
context
)
}
}
catch
let
error
{
...
...
This diff is collapsed.
Click to expand it.
MemriApp/Controllers/Plugins/PluginHandler.swift
+
13
-
17
View file @
9f7eeb00
...
...
@@ -6,19 +6,12 @@ import Foundation
class
PluginHandler
{
public
static
func
start
(
plugin
:
ItemRecord
,
runner
:
ItemRecord
,
sceneController
:
SceneController
,
context
:
CVUContext
)
{
AppController
.
shared
.
pubsubController
.
startObservingItemProperty
(
runner
,
property
:
"status"
,
desiredValue
:
nil
)
{
(
newValue
,
error
)
in
guard
case
let
.
string
(
state
)
=
n
ewValue
else
{
AppController
.
shared
.
pubsubController
.
startObservingItemProperty
(
runner
,
property
:
"status"
,
desiredValue
:
.
string
(
"userActionNeeded"
))
{
(
_
,
error
)
in
guard
error
=
=
n
il
else
{
return
}
switch
state
{
case
"userActionNeeded"
:
presentCVUforPlugin
(
plugin
:
plugin
,
runner
:
runner
,
sceneController
:
sceneController
,
context
:
context
)
case
"cvuPresented"
:
try
?
runner
.
setPropertyValue
(
name
:
"status"
,
value
:
.
string
(
"userActionNeeded"
))
default
:
break
}
presentCVUforPlugin
(
plugin
:
plugin
,
runner
:
runner
,
sceneController
:
sceneController
,
context
:
context
)
}
try
?
AppController
.
shared
.
syncController
.
sync
()
...
...
@@ -26,9 +19,9 @@ class PluginHandler {
static
func
presentCVUforPlugin
(
plugin
:
ItemRecord
,
runner
:
ItemRecord
,
sceneController
:
SceneController
,
context
:
CVUContext
)
{
guard
let
runnerRowId
=
runner
.
rowId
,
let
view
=
plugin
.
edgeItem
(
"view"
),
case
let
.
string
(
viewName
)
=
view
.
propertyValue
(
"definition"
)
else
{
AppController
.
shared
.
pubsubController
.
stopObservingItemProperty
(
runner
,
property
:
"state"
)
let
view
=
runner
.
edgeItem
(
"view"
),
case
let
.
string
(
cvuContent
)
=
view
.
propertyValue
(
"definition"
)
else
{
start
(
plugin
:
plugin
,
runner
:
runner
,
sceneController
:
sceneController
,
context
:
context
)
return
}
...
...
@@ -43,10 +36,13 @@ class PluginHandler {
edge
.
syncState
=
.
skip
// Don't sync it yet
try
?
edge
.
save
()
var
newVars
:
[
String
:
CVUValue
]
=
[:]
newVars
[
"viewArguments"
]
=
.
subdefinition
(
CVUDefinitionContent
(
properties
:
[
"readOnly"
:
.
constant
(
.
bool
(
false
))]))
CVUAction_OpenView
(
viewName
:
viewName
,
renderer
:
"generalEditor"
)
.
execute
(
sceneController
:
sceneController
,
context
:
context
.
replacingItem
(
item
),
completion
:
nil
)
let
cvuController
=
CVUController
(
cvuContent
)
var
renderer
=
"custom"
if
case
let
.
constant
(
.
argument
(
rendererName
))
=
cvuController
.
definitions
.
first
?
.
parsed
.
properties
[
"defaultRenderer"
]
{
renderer
=
rendererName
}
sceneController
.
navigateToNewContext
(
cvuController
:
cvuController
,
viewName
:
cvuController
.
definitions
.
first
?
.
name
,
defaultRenderer
:
renderer
,
targetItem
:
item
)
sceneController
.
isInEditMode
=
true
}
}
This diff is collapsed.
Click to expand it.
MemriApp/Controllers/PubSub/PubSubController.swift
+
10
-
2
View file @
9f7eeb00
...
...
@@ -41,7 +41,7 @@ class PubSubController {
stopObservingItemProperty
(
item
,
property
:
property
)
let
subscription
=
ItemSubscription
(
item
:
item
,
property
:
property
,
desiredValue
:
desiredValue
,
completion
:
completion
)
subscribers
.
insert
(
subscription
)
startObserver
(
subscription
)
s
yncAndS
tartObserver
(
subscription
)
}
public
func
stopObservingItemProperty
(
_
item
:
ItemRecord
,
property
:
String
)
{
...
...
@@ -123,7 +123,15 @@ class PubSubController {
}
DispatchQueue
.
main
.
asyncAfter
(
deadline
:
.
now
()
+
PubSubController
.
pollInterval
)
{[
weak
self
]
in
self
?
.
startObserver
(
subscription
)
self
?
.
syncAndStartObserver
(
subscription
)
}
}
private
func
syncAndStartObserver
(
_
subscription
:
ItemSubscription
)
{
DispatchQueue
.
main
.
async
{
try
?
AppController
.
shared
.
syncController
.
sync
{[
weak
self
]
_
in
self
?
.
startObserver
(
subscription
)
}
}
}
...
...
This diff is collapsed.
Click to expand it.
MemriApp/Controllers/SceneController.swift
+
5
-
5
View file @
9f7eeb00
...
...
@@ -180,8 +180,8 @@ class SceneController: ObservableObject {
}
}
func
makeContext
(
forConfig
config
:
ViewContextHolder
)
->
ViewContextController
{
ViewContextController
(
config
:
config
,
databaseController
:
appController
.
databaseController
,
cvuController
:
appController
.
cvuController
)
func
makeContext
(
forConfig
config
:
ViewContextHolder
,
cvuController
:
CVUController
?
=
nil
)
->
ViewContextController
{
ViewContextController
(
config
:
config
,
databaseController
:
appController
.
databaseController
,
cvuController
:
cvuController
??
appController
.
cvuController
)
}
var
canNavigateBack
:
Bool
{
...
...
@@ -201,7 +201,7 @@ class SceneController: ObservableObject {
navigationController
.
popToViewController
(
vc
,
animated
:
true
)
}
func
navigateToNewContext
(
defaultDefinition
:
CVUDefinitionContent
?
=
nil
,
func
navigateToNewContext
(
cvuController
:
CVUController
?
=
nil
,
defaultContext
:
CVUContext
?
=
nil
,
clearStack
:
Bool
=
false
,
animated
:
Bool
=
true
,
...
...
@@ -215,7 +215,7 @@ class SceneController: ObservableObject {
customDefinition
:
CVUDefinitionContent
?
=
nil
,
viewArguments
:
CVUViewArguments
?
=
nil
)
{
let
viewDefinition
=
defaultDefinition
??
appController
.
cvuController
.
viewDefinitionFor
(
viewName
:
viewName
??
""
,
customDefinition
:
customDefinition
)
??
CVUDefinitionContent
()
let
viewDefinition
=
(
cvuController
??
appController
.
cvuController
)
.
viewDefinitionFor
(
viewName
:
viewName
??
""
,
customDefinition
:
customDefinition
)
??
CVUDefinitionContent
()
let
cvuContext
=
CVUContext
(
currentItem
:
targetItem
,
selector
:
nil
,
viewName
:
viewName
,
viewDefinition
:
viewDefinition
,
viewArguments
:
viewArguments
)
let
rendererName
=
overrideRenderer
??
{
()
->
String
in
...
...
@@ -233,7 +233,7 @@ class SceneController: ObservableObject {
let
config
=
ViewContext
(
viewName
:
viewName
,
rendererName
:
rendererName
,
viewDefinition
:
viewDefinition
,
query
:
queryConfig
,
viewArguments
:
viewArguments
,
focusedItem
:
targetItem
)
let
holder
=
ViewContextHolder
(
config
)
let
newViewContextController
=
makeContext
(
forConfig
:
holder
)
let
newViewContextController
=
makeContext
(
forConfig
:
holder
,
cvuController
:
cvuController
)
topMostContext
=
newViewContextController
if
clearStack
{
...
...
This diff is collapsed.
Click to expand it.
MemriApp/Controllers/Syncing/SyncController.swift
+
11
-
5
View file @
9f7eeb00
...
...
@@ -27,7 +27,7 @@ class SyncController {
var
syncing
=
false
var
lastError
:
Error
?
=
nil
var
completion
:
((
Error
?)
->
Void
)
?
=
nil
var
completion
s
=
[
((
Error
?)
->
Void
)
]()
let
databaseController
:
DatabaseController
public
private(set)
var
subscriptions
:
Set
<
AnyCancellable
>
=
[]
var
state
:
SyncControllerState
{
...
...
@@ -69,11 +69,14 @@ class SyncController {
throw
StringError
(
description
:
"Not Setup"
)
}
if
let
completion
=
completion
{
self
.
completions
.
append
(
completion
)
}
guard
!
syncing
else
{
throw
StringError
(
description
:
"Already syncing"
)
return
}
self
.
completion
=
completion
self
.
state
=
.
started
}
...
...
@@ -250,10 +253,13 @@ class SyncController {
private
func
finishSync
()
{
self
.
state
=
.
done
self
.
syncing
=
false
self
.
completion
?(
self
.
lastError
)
let
completionsToCall
=
self
.
completions
self
.
completions
=
[]
for
completion
in
completionsToCall
{
completion
(
self
.
lastError
)
}
self
.
state
=
.
idle
self
.
completion
=
nil
print
(
"Sync Complete!"
)
}
...
...
This diff is collapsed.
Click to expand it.
MemriApp/UI/Renderers/GeneralEditorRenderer.swift
+
24
-
3
View file @
9f7eeb00
...
...
@@ -93,7 +93,7 @@ struct GeneralEditorRendererView: View {
}
}
guard
let
viewDefs
=
viewDefs_
,
let
generalDefs
=
generalDefs_
else
{
guard
let
viewDefs
=
viewDefs_
else
{
return
[]
}
...
...
@@ -103,7 +103,7 @@ struct GeneralEditorRendererView: View {
}
var
mergedDefinitions
=
viewDefs
if
(
showDefaultLayout
)
{
if
let
generalDefs
=
generalDefs_
,
showDefaultLayout
{
// Merge layout from default generalEditor cvu
mergedDefinitions
.
append
(
contentsOf
:
generalDefs
)
}
...
...
@@ -260,6 +260,25 @@ struct GeneralEditorSection: View {
return
items
}
func
findNodeDefinitionForIdentifier
(
_
identifier
:
String
,
definitions
:
[
CVUParsedDefinition
]
=
[])
->
CVUDefinitionContent
?
{
guard
definitions
.
count
>
0
else
{
return
nil
}
for
definition
in
definitions
{
if
case
let
.
subdefinition
(
nodeDefinition
)
=
definition
.
parsed
.
properties
[
identifier
]
{
return
nodeDefinition
}
if
definition
.
parsed
.
definitions
.
count
>
0
{
return
findNodeDefinitionForIdentifier
(
identifier
,
definitions
:
definition
.
parsed
.
definitions
)
}
}
return
nil
}
var
nodeDefinition
:
CVUDefinitionContent
?
{
if
let
nodeDefinition
=
viewContext
.
cvuController
.
viewDefinitionFor
(
itemRecord
:
item
)?
.
definitions
.
first
?[
layout
.
id
]?
.
getSubdefinition
()
{
return
nodeDefinition
...
...
@@ -267,9 +286,11 @@ struct GeneralEditorSection: View {
return
nodeDefinition
}
else
if
let
viewName
=
viewContext
.
config
.
viewName
,
let
nodeDefinition
=
viewContext
.
cvuController
.
viewDefinitionFor
(
viewName
:
viewName
)?
.
properties
[
layout
.
id
]?
.
getSubdefinition
()
{
return
nodeDefinition
}
else
if
case
let
.
subdefinition
(
nodeDefinition
)
=
viewContext
.
cvuController
.
definitions
.
first
?
.
parsed
.
properties
[
layout
.
id
]
{
return
nodeDefinition
}
return
nil
return
findNodeDefinitionForIdentifier
(
layout
.
id
,
definitions
:
viewContext
.
cvuController
.
definitions
)
}
var
viewArguments
:
CVUViewArguments
?
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment