Skip to content

Commit

Permalink
Merge pull request #565 from Gencaster/564-add-meta-editing-to-the-ed…
Browse files Browse the repository at this point in the history
…itor

564 add meta editing to the editor
  • Loading branch information
vin-ni authored Sep 14, 2023
2 parents 87f0ea6 + 1485003 commit 1928881
Show file tree
Hide file tree
Showing 13 changed files with 790 additions and 28 deletions.
18 changes: 18 additions & 0 deletions caster-back/gencaster/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
ScriptCell,
ScriptCellInputCreate,
ScriptCellInputUpdate,
UpdateGraphInput,
create_python_highlight_string,
)
from stream.exceptions import NoStreamAvailableException
Expand Down Expand Up @@ -486,6 +487,23 @@ async def add_graph(self, info, graph_input: AddGraphInput) -> Graph:
# https://docs.djangoproject.com/en/4.2/ref/models/instances/#django.db.models.Model.arefresh_from_db
return await story_graph_models.Graph.objects.aget(uuid=graph.uuid) # type: ignore

@strawberry.mutation
async def update_graph(
self, info, graph_input: UpdateGraphInput, graph_uuid: uuid.UUID
) -> Graph:
await graphql_check_authenticated(info)

graph = await story_graph_models.Graph.objects.aget(uuid=graph_uuid)

for key, value in graph_input.__dict__.items():
if value == strawberry.UNSET:
continue
graph.__setattr__(key, value)

await graph.asave()

return graph # type: ignore

@strawberry.mutation
async def add_audio_file(self, info, new_audio_file: AddAudioFile) -> AudioFileUploadResponse: # type: ignore
if new_audio_file.file is None or len(new_audio_file.file) == 0:
Expand Down
28 changes: 28 additions & 0 deletions caster-back/operations.gql
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,25 @@ subscription node($uuid: UUID!) {
}
}

fragment GraphMetaData on Graph {
uuid
templateName
startText
slugName
name
endText
displayName
aboutText
streamAssignmentPolicy
publicVisible
}

query GetGraph($graphUuid:ID!) {
graph(pk: $graphUuid) {
...GraphMetaData
}
}

mutation CreateGraph($graphInput: AddGraphInput!) {
addGraph(graphInput: $graphInput) {
name
Expand All @@ -220,6 +239,15 @@ mutation CreateGraph($graphInput: AddGraphInput!) {
}
}

mutation UpdateGraph($graphUuid:UUID!, $graphUpdate: UpdateGraphInput!) {
updateGraph(
graphInput: $graphUpdate
graphUuid: $graphUuid
) {
uuid
}
}

subscription stream($graphUuid: UUID!) {
streamInfo(graphUuid: $graphUuid) {
__typename
Expand Down
65 changes: 64 additions & 1 deletion caster-back/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ input AddGraphInput {
publicVisible: Boolean

"""Manages the stream assignment for this graph"""
streamAssignmentPolicy: String
streamAssignmentPolicy: StreamAssignmentPolicy

"""
Allows to switch to a different template in the frontend with different connection flows or UI
Expand Down Expand Up @@ -360,6 +360,14 @@ type Graph {
"""
templateName: GraphDetailTemplate!

"""Manages the stream assignment for this graph"""
streamAssignmentPolicy: StreamAssignmentPolicy!

"""
If the graph is not public it will not be listed in the frontend, yet it is still accessible via URL
"""
publicVisible: Boolean!

"""
Text about the graph which will be displayed at the start of a stream - only if this is set
"""
Expand Down Expand Up @@ -492,6 +500,7 @@ type Mutation {
"""Deletes a given :class:`~story_graph.models.ScriptCell`."""
deleteScriptCell(scriptCellUuid: UUID!): Void
addGraph(graphInput: AddGraphInput!): Graph!
updateGraph(graphInput: UpdateGraphInput!, graphUuid: UUID!): Graph!
addAudioFile(newAudioFile: AddAudioFile!): AudioFileUploadResponse!
createUpdateStreamVariable(streamVariables: [StreamVariableInput!]!): [StreamVariable!]!
createNodeDoor(nodeDoorInput: NodeDoorInputCreate!, nodeUuid: UUID!): NodeDoor!
Expand Down Expand Up @@ -758,6 +767,13 @@ type Stream {
streamPoint: StreamPoint!
}

"""An enumeration."""
enum StreamAssignmentPolicy {
ONE_GRAPH_ONE_STREAM
ONE_USER_ONE_STREAM
DEACTIVATE
}

type StreamInfo {
stream: Stream!
streamInstruction: StreamInstruction
Expand Down Expand Up @@ -930,6 +946,53 @@ input UpdateAudioFile {
name: String
}

"""
A collection of :class:`~Node` and :class:`~Edge`.
This can be considered a score as well as a program as it
has an entry point as a :class:`~Node` and can jump to any
other :class:`~Node`, also allowing for recursive loops/cycles.
Each node can be considered a little program on its own which can consist
of multiple :class:`~ScriptCell` which can be coded in a variety of
languages which can control the frontend and the audio (by e.g. speaking
on the stream) or setting a background music.
The story graph is a core concept and can be edited with a native editor.
"""
input UpdateGraphInput {
"""Name of the graph"""
name: String

"""Will be used as a display name in the frontend"""
displayName: String

"""
Text about the graph which will be displayed at the start of a stream - only if this is set
"""
startText: String

"""
Text about the graph which can be accessed during a stream - only if this is set
"""
aboutText: String

"""Text which will be displayed at the end of a stream"""
endText: String

"""
If the graph is not public it will not be listed in the frontend, yet it is still accessible via URL
"""
publicVisible: Boolean

"""Manages the stream assignment for this graph"""
streamAssignmentPolicy: StreamAssignmentPolicy

"""
Allows to switch to a different template in the frontend with different connection flows or UI
"""
templateName: GraphDetailTemplate
}

scalar Upload

"""
Expand Down
41 changes: 28 additions & 13 deletions caster-back/story_graph/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
PlaybackType = strawberry.enum(models.AudioCell.PlaybackChoices) # type: ignore
TemplateType = strawberry.enum(models.Graph.GraphDetailTemplate) # type: ignore
NodeDoorType = strawberry.enum(models.NodeDoor.DoorType) # type: ignore
StreamAssignmentPolicy = strawberry.enum(models.Graph.StreamAssignmentPolicy) # type: ignore


def create_python_highlight_string(e: SyntaxError) -> str:
Expand Down Expand Up @@ -85,6 +86,8 @@ class Graph:
display_name: auto
slug_name: auto
template_name: TemplateType
stream_assignment_policy: StreamAssignmentPolicy
public_visible: auto
start_text: auto
about_text: auto
end_text: auto
Expand All @@ -95,6 +98,31 @@ def edges(self) -> List["Edge"]:
return models.Edge.objects.filter(out_node_door__node__graph=self) # type: ignore


@strawberry.django.input(models.Graph)
class AddGraphInput:
name: auto
display_name: auto
slug_name: auto
start_text: auto
about_text: auto
end_text: auto
public_visible: auto
stream_assignment_policy: StreamAssignmentPolicy
template_name: TemplateType


@strawberry.django.input(model=models.Graph, partial=True)
class UpdateGraphInput:
name: auto
display_name: auto
start_text: auto
about_text: auto
end_text: auto
public_visible: auto
stream_assignment_policy: StreamAssignmentPolicy
template_name: TemplateType


@strawberry.django.type(models.Node)
class Node:
uuid: auto
Expand Down Expand Up @@ -210,16 +238,3 @@ class ScriptCellInputUpdate:
cell_code: Optional[str]
cell_order: Optional[int]
audio_cell: Optional[AudioCellInput]


@strawberry.django.input(models.Graph)
class AddGraphInput:
name: auto
display_name: auto
slug_name: auto
start_text: auto
about_text: auto
end_text: auto
public_visible: auto
stream_assignment_policy: auto
template_name: TemplateType
13 changes: 13 additions & 0 deletions caster-editor/src/assets/scss/_elementplus.scss
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,19 @@
border: none;
}

.el-loading-mask {
// background-color: $white-transparent;
color: #{$black};
}

.el-loading-spinner .el-loading-text {
color: #{$black};
}

.el-loading-spinner .path {
stroke: #{$black};
}

/* OLD */

.messages-editor {
Expand Down
6 changes: 4 additions & 2 deletions caster-editor/src/components/MenuTabEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ const removeSelection = async () => {
});
if (error) {
ElMessage.error(`Could not delete edge ${edgeUuid}: ${error.message}`);
} else {
ElMessage.info(`Deleted edge ${edgeUuid}`);
}
ElMessage.info(`Deleted edge ${edgeUuid}`);
});
selectedNodeUUIDs.value.forEach(async (nodeUuid) => {
Expand All @@ -64,8 +65,9 @@ const removeSelection = async () => {
});
if (error) {
ElMessage.error(`Could not delete node ${nodeUuid}: ${error.message}`);
} else {
ElMessage.info(`Deleted node ${nodeUuid}`);
}
ElMessage.info(`Deleted node ${nodeUuid}`);
});
};
</script>
17 changes: 10 additions & 7 deletions caster-editor/src/components/MenuTabHeader.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<script setup lang="ts">
import { useInterfaceStore, Tab } from "@/stores/InterfaceStore";
import { storeToRefs } from "pinia";
const { tab } = storeToRefs(useInterfaceStore());
</script>

<template>
<div class="menu-items left">
<ElRadioGroup v-model="tab">
Expand All @@ -7,13 +14,9 @@
<ElRadioButton :label="Tab.Play">
Listen
</ElRadioButton>
<ElRadioButton :label="Tab.Meta">
Meta
</ElRadioButton>
</ElRadioGroup>
</div>
</template>

<script setup lang="ts">
import { useInterfaceStore, Tab } from "@/stores/InterfaceStore";
import { storeToRefs } from "pinia";
const { tab } = storeToRefs(useInterfaceStore());
</script>
Loading

0 comments on commit 1928881

Please sign in to comment.