Skip to content

Commit 60664f4

Browse files
author
Jens Kürten
committed
add custom operation event for docs
1 parent c0bd6a2 commit 60664f4

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

csfunctions/events/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from pydantic import Field
44

5+
from .custom_operations import CustomOperationDocumentData, CustomOperationDocumentEvent
56
from .dialog_data import DocumentReleasedDialogData, PartReleasedDialogData
67
from .document_create_check import DocumentCreateCheckData, DocumentCreateCheckEvent
78
from .document_field_calculation import DocumentFieldCalculationData, DocumentFieldCalculationEvent
@@ -36,6 +37,7 @@
3637
DocumentModifyCheckEvent,
3738
PartCreateCheckEvent,
3839
PartModifyCheckEvent,
40+
CustomOperationDocumentEvent,
3941
],
4042
Field(discriminator="name"),
4143
]
@@ -55,6 +57,7 @@
5557
DocumentModifyCheckData,
5658
PartCreateCheckData,
5759
PartModifyCheckData,
60+
CustomOperationDocumentData,
5861
]
5962

6063
__all__ = [
@@ -90,4 +93,6 @@
9093
"PartCreateCheckEvent",
9194
"PartModifyCheckData",
9295
"PartModifyCheckEvent",
96+
"CustomOperationDocumentData",
97+
"CustomOperationDocumentEvent",
9398
]

csfunctions/events/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class EventNames(str, Enum):
1919
DOCUMENT_MODIFY_CHECK = "document_modify_check"
2020
PART_CREATE_CHECK = "part_create_check"
2121
PART_MODIFY_CHECK = "part_modify_check"
22+
CUSTOM_OPERATION_DOCUMENT = "custom_operation_document"
2223

2324

2425
class BaseEvent(BaseModel):
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from typing import Literal
2+
3+
from pydantic import BaseModel, Field
4+
5+
from csfunctions.objects import Document, Part
6+
7+
from .base import BaseEvent, EventNames
8+
9+
10+
class CustomOperationDocumentData(BaseModel):
11+
documents: list[Document] = Field(..., description="List of documents that the custom operation was called on")
12+
parts: list[Part] = Field(..., description="List of parts that belong to the documents")
13+
14+
15+
class CustomOperationDocumentEvent(BaseEvent):
16+
"""
17+
Event triggered when a custom operation is called on a document.
18+
"""
19+
20+
name: Literal[EventNames.CUSTOM_OPERATION_DOCUMENT] = EventNames.CUSTOM_OPERATION_DOCUMENT
21+
data: CustomOperationDocumentData

json_schemas/request.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,57 @@
8585
"title": "Briefcase",
8686
"type": "object"
8787
},
88+
"CustomOperationDocumentData": {
89+
"properties": {
90+
"documents": {
91+
"description": "List of documents that the custom operation was called on",
92+
"items": {
93+
"$ref": "#/$defs/Document"
94+
},
95+
"title": "Documents",
96+
"type": "array"
97+
},
98+
"parts": {
99+
"description": "List of parts that belong to the documents",
100+
"items": {
101+
"$ref": "#/$defs/Part"
102+
},
103+
"title": "Parts",
104+
"type": "array"
105+
}
106+
},
107+
"required": [
108+
"documents",
109+
"parts"
110+
],
111+
"title": "CustomOperationDocumentData",
112+
"type": "object"
113+
},
114+
"CustomOperationDocumentEvent": {
115+
"description": "Event triggered when a custom operation is called on a document.",
116+
"properties": {
117+
"name": {
118+
"const": "custom_operation_document",
119+
"default": "custom_operation_document",
120+
"title": "Name",
121+
"type": "string"
122+
},
123+
"event_id": {
124+
"description": "unique identifier",
125+
"title": "Event Id",
126+
"type": "string"
127+
},
128+
"data": {
129+
"$ref": "#/$defs/CustomOperationDocumentData"
130+
}
131+
},
132+
"required": [
133+
"event_id",
134+
"data"
135+
],
136+
"title": "CustomOperationDocumentEvent",
137+
"type": "object"
138+
},
88139
"Document": {
89140
"description": "Normal Document that doesn't contain a CAD-Model.",
90141
"properties": {
@@ -3068,6 +3119,7 @@
30683119
"event": {
30693120
"discriminator": {
30703121
"mapping": {
3122+
"custom_operation_document": "#/$defs/CustomOperationDocumentEvent",
30713123
"document_create_check": "#/$defs/DocumentCreateCheckEvent",
30723124
"document_field_calculation": "#/$defs/DocumentFieldCalculationEvent",
30733125
"document_modify_check": "#/$defs/DocumentModifyCheckEvent",
@@ -3131,6 +3183,9 @@
31313183
},
31323184
{
31333185
"$ref": "#/$defs/PartModifyCheckEvent"
3186+
},
3187+
{
3188+
"$ref": "#/$defs/CustomOperationDocumentEvent"
31343189
}
31353190
],
31363191
"title": "Event"

0 commit comments

Comments
 (0)