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
46d181da
Commit
46d181da
authored
2 years ago
by
Maximilian Giller
Browse files
Options
Downloads
Patches
Plain Diff
Implemented savepoint concept and interface
parent
d4231240
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2
Implemented editor in the react framework
Pipeline
#56581
passed
2 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/editor/js/structures/manageddata.ts
+39
-5
39 additions, 5 deletions
src/editor/js/structures/manageddata.ts
with
39 additions
and
5 deletions
src/editor/js/structures/manageddata.ts
+
39
−
5
View file @
46d181da
import
{
SerializableItem
}
from
"
./helper/serializableitem
"
;
import
{
SerializableItem
}
from
"
./helper/serializableitem
"
;
import
jQuery
from
"
jquery
"
;
import
jQuery
from
"
jquery
"
;
const
SAVE_BUTTON_ID
=
"
div#ks-editor #toolbar-save
"
;
const
SAVE_BUTTON_ID
=
"
div#ks-editor #toolbar-save
"
;
type
SavePoint
=
{
description
:
string
;
data
:
string
;
id
:
number
;
};
/**
/**
* Allows objects to have undo/redo functionality in their data and custom save points.
* Allows objects to have undo/redo functionality in their data and custom save points.
*/
*/
export
default
class
ManagedData
extends
SerializableItem
{
export
default
class
ManagedData
extends
SerializableItem
{
public
data
:
any
;
// The data to be stored in a history.
public
data
:
any
;
// The data to be stored in a history.
public
history
:
any
[];
// All save points of the data.
public
history
:
SavePoint
[];
// All save points of the data.
public
historyPosition
:
number
;
// Currently selected save point in history. Latest always at index 0.
public
historyPosition
:
number
;
// Currently selected save point in history. Latest always at index 0.
private
savedHistoryId
:
number
;
// Id of save point that is considered saved.
private
savedHistoryId
:
number
;
// Id of save point that is considered saved.
private
storingEnabled
:
boolean
;
// To internally disable saving of objects on save call.
private
storingEnabled
:
boolean
;
// To internally disable saving of objects on save call.
/**
/**
...
@@ -126,6 +132,21 @@ export default class ManagedData extends SerializableItem {
...
@@ -126,6 +132,21 @@ export default class ManagedData extends SerializableItem {
}
}
}
}
/**
* Moves current state of data to a given savepoint that is stored in the history.
* @param savePointId Id of desired savepoint.
* @returns True, if successful.
*/
public
goToSavePoint
(
savePointId
:
number
):
boolean
{
// Iterate overhistory and find position with same savepoint id
for
(
let
i
=
0
;
i
<
this
.
history
.
length
;
i
++
)
{
if
(
this
.
history
[
i
].
id
===
savePointId
)
{
return
this
.
setHistoryPosition
(
i
);
}
}
return
false
;
// Not found
}
/**
/**
* Moves the history pointer to the desired position and adjusts the data object.
* Moves the history pointer to the desired position and adjusts the data object.
* @param direction How many steps to take in the history. Positive for going back in time, negative for going forward.
* @param direction How many steps to take in the history. Positive for going back in time, negative for going forward.
...
@@ -142,7 +163,20 @@ export default class ManagedData extends SerializableItem {
...
@@ -142,7 +163,20 @@ export default class ManagedData extends SerializableItem {
return
false
;
return
false
;
}
}
this
.
historyPosition
=
newHistoryPosition
;
return
this
.
setHistoryPosition
(
newHistoryPosition
);
}
/**
* Loads a given history index into the current data object and sets historyPosition accordingly.
* @param position Position (Index) of history point to load.
* @returns True, if successful.
*/
private
setHistoryPosition
(
position
:
number
):
boolean
{
if
(
position
<
0
||
position
>=
this
.
history
.
length
)
{
return
false
;
}
this
.
historyPosition
=
position
;
this
.
data
=
JSON
.
parse
(
this
.
history
[
this
.
historyPosition
].
data
);
this
.
data
=
JSON
.
parse
(
this
.
history
[
this
.
historyPosition
].
data
);
return
true
;
return
true
;
...
...
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