Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Knowledge Space WP Plugin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
alg
Knowledge Space WP Plugin
Commits
e1a8bc99
You need to sign in or sign up before continuing.
Commit
e1a8bc99
authored
2 years ago
by
Maximilian Giller
Browse files
Options
Downloads
Patches
Plain Diff
Adds the missing node type interface into the graph
parent
d488c0bc
No related branches found
No related tags found
1 merge request
!2
Implemented editor in the react framework
Pipeline
#56800
passed
2 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/editor/js/structures/graph/graph.ts
+72
-7
72 additions, 7 deletions
src/editor/js/structures/graph/graph.ts
src/editor/js/structures/graph/nodetype.ts
+7
-4
7 additions, 4 deletions
src/editor/js/structures/graph/nodetype.ts
with
79 additions
and
11 deletions
src/editor/js/structures/graph/graph.ts
+
72
−
7
View file @
e1a8bc99
...
@@ -157,6 +157,36 @@ export class Graph extends ManagedData {
...
@@ -157,6 +157,36 @@ export class Graph extends ManagedData {
};
};
}
}
/**
* Adds a pre-created node type to the graph.
* @param nodeType New node type object.
* @returns True, if successful.
*/
public
addNodeType
(
nodeType
:
NodeType
)
{
if
(
this
.
data
.
types
.
includes
(
nodeType
))
{
return
true
;
// Already exists in graph.
}
// Update id
nodeType
.
id
=
this
.
nextTypeId
;
this
.
nextTypeId
+=
1
;
// Is valid node?
if
(
nodeType
.
name
==
undefined
)
{
nodeType
.
name
=
"
Unnamed
"
;
}
if
(
nodeType
.
color
==
undefined
)
{
nodeType
.
color
=
"
#000000
"
;
}
this
.
data
.
types
.
push
(
node
);
this
.
triggerOnChange
();
this
.
storeCurrentData
(
"
Added node [
"
+
nodeType
+
"
]
"
);
return
true
;
}
/**
/**
* Adds a pre-created node to the graph.
* Adds a pre-created node to the graph.
* @param node New node object.
* @param node New node object.
...
@@ -180,21 +210,59 @@ export class Graph extends ManagedData {
...
@@ -180,21 +210,59 @@ export class Graph extends ManagedData {
// Just give first type in list
// Just give first type in list
node
.
type
=
this
.
types
[
0
];
node
.
type
=
this
.
types
[
0
];
}
else
{
}
else
{
// Give empty type
const
newType
=
new
NodeType
(
this
);
// TODO: Properly add
new
t
ype
, with proper ID. Implemented this.addType(..
);
new
T
ype
.
add
(
);
node
.
type
=
new
NodeType
(
this
)
;
node
.
type
=
new
Type
;
}
}
}
}
this
.
data
.
nodes
.
push
(
node
);
this
.
data
.
nodes
.
push
(
node
);
this
.
triggerOnChange
();
this
.
triggerOnChange
();
// TODO: Use toString implementation of node
this
.
storeCurrentData
(
"
Added node [
"
+
node
+
"
]
"
);
this
.
storeCurrentData
(
"
Added node [
"
+
node
+
"
]
"
);
return
true
;
return
true
;
}
}
/**
* Deletes a node type from the graph. Only works if at least one type remains after deletion.
* @param nodeType Node type object to remove.
* @returns True, if successful.
*/
public
deleteNodeType
(
nodeType
:
NodeType
):
boolean
{
// Only allow deletion if at least one other type remains
if
(
this
.
types
.
length
<=
1
)
{
return
false
;
}
if
(
!
this
.
data
.
types
.
includes
(
nodeType
))
{
return
true
;
// Doesn't even exist in graph to begin with.
}
this
.
data
.
types
=
this
.
data
.
types
.
filter
((
n
:
NodeType
)
=>
!
n
.
equals
(
nodeType
));
try
{
// No save points should be created when replacing usages
this
.
disableStoring
();
// Replace all usages of this type with the first one in the list
this
.
nodes
.
forEach
((
n
:
Node
)
=>
{
if
(
n
.
type
.
equals
(
nodeType
))
{
n
.
type
=
this
.
types
[
0
];
}
});
}
finally
{
this
.
enableStoring
();
}
this
.
triggerOnChange
();
this
.
storeCurrentData
(
"
Deleted type [
"
+
nodeType
+
"
] and replaced usages
"
);
return
true
;
}
/**
/**
* Deletes a node from the graph.
* Deletes a node from the graph.
* @param node Node object to remove.
* @param node Node object to remove.
...
@@ -220,7 +288,6 @@ export class Graph extends ManagedData {
...
@@ -220,7 +288,6 @@ export class Graph extends ManagedData {
}
}
this
.
triggerOnChange
();
this
.
triggerOnChange
();
// TODO: Use toString implementation of node
this
.
storeCurrentData
(
this
.
storeCurrentData
(
"
Deleted node [
"
+
node
+
"
] and all connected links
"
"
Deleted node [
"
+
node
+
"
] and all connected links
"
);
);
...
@@ -262,7 +329,6 @@ export class Graph extends ManagedData {
...
@@ -262,7 +329,6 @@ export class Graph extends ManagedData {
this
.
data
.
links
.
push
(
link
);
this
.
data
.
links
.
push
(
link
);
this
.
triggerOnChange
();
this
.
triggerOnChange
();
// TODO: Use toString implementation of link
this
.
storeCurrentData
(
"
Added link [
"
+
link
+
"
]
"
);
this
.
storeCurrentData
(
"
Added link [
"
+
link
+
"
]
"
);
return
true
;
return
true
;
...
@@ -281,7 +347,6 @@ export class Graph extends ManagedData {
...
@@ -281,7 +347,6 @@ export class Graph extends ManagedData {
this
.
data
.
links
=
this
.
data
.
links
.
filter
((
l
:
Link
)
=>
!
l
.
equals
(
link
));
this
.
data
.
links
=
this
.
data
.
links
.
filter
((
l
:
Link
)
=>
!
l
.
equals
(
link
));
this
.
triggerOnChange
();
this
.
triggerOnChange
();
// TODO: Use toString implementation of link
this
.
storeCurrentData
(
"
Deleted link [
"
+
link
+
"
]
"
);
this
.
storeCurrentData
(
"
Deleted link [
"
+
link
+
"
]
"
);
return
true
;
return
true
;
...
...
This diff is collapsed.
Click to expand it.
src/editor/js/structures/graph/nodetype.ts
+
7
−
4
View file @
e1a8bc99
...
@@ -13,13 +13,16 @@ export class NodeType extends GraphElement {
...
@@ -13,13 +13,16 @@ export class NodeType extends GraphElement {
}
}
public
delete
():
boolean
{
public
delete
():
boolean
{
// TODO: Implement
return
this
.
graph
.
deleteNodeType
(
this
);
throw
new
Error
(
'
Function "delete()" has not been implemented.
'
);
}
}
public
add
(
graph
:
Graph
=
this
.
graph
):
boolean
{
public
add
(
graph
:
Graph
=
this
.
graph
):
boolean
{
// TODO: Implement
this
.
graph
=
graph
;
throw
new
Error
(
'
Function "add(graph)" has not been implemented.
'
);
if
(
this
.
graph
==
undefined
)
{
return
false
;
}
return
this
.
graph
.
addNodeType
(
this
);
}
}
public
getCleanInstance
():
any
{
public
getCleanInstance
():
any
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment