Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Mirador annotations
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
IIIF
Mirador
Mirador annotations
Commits
c403739a
Commit
c403739a
authored
Feb 4, 2024
by
Anthony
Browse files
Options
Downloads
Patches
Plain Diff
WIP saving
parent
a0566011
Branches
Branches containing commit
No related tags found
1 merge request
!10
Draft: MigratingAnnotationCreation to MUI5.
Pipeline
#1905
failed
Feb 4, 2024
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/AnnotationCreation.js
+15
-60
15 additions, 60 deletions
src/AnnotationCreation.js
src/AnnotationCreationUtils.js
+47
-0
47 additions, 0 deletions
src/AnnotationCreationUtils.js
with
62 additions
and
60 deletions
src/AnnotationCreation.js
+
15
−
60
View file @
c403739a
...
@@ -20,7 +20,7 @@ import WebAnnotation from './WebAnnotation';
...
@@ -20,7 +20,7 @@ import WebAnnotation from './WebAnnotation';
import
{
secondsToHMS
}
from
'
./utils
'
;
import
{
secondsToHMS
}
from
'
./utils
'
;
import
AnnotationFormContent
from
'
./annotationForm/AnnotationFormContent
'
;
import
AnnotationFormContent
from
'
./annotationForm/AnnotationFormContent
'
;
import
AnnotationFormTime
from
'
./annotationForm/AnnotationFormTime
'
;
import
AnnotationFormTime
from
'
./annotationForm/AnnotationFormTime
'
;
import
{
geomFromAnnoTarget
,
timeFromAnnoTarget
}
from
'
./AnnotationCreationUtils
'
;
import
{
geomFromAnnoTarget
,
getSvg
,
saveAnnotation
,
timeFromAnnoTarget
}
from
'
./AnnotationCreationUtils
'
;
import
AnnotationFormOverlay
from
'
./annotationForm/AnnotationFormOverlay/AnnotationFormOverlay.js
'
;
import
AnnotationFormOverlay
from
'
./annotationForm/AnnotationFormOverlay/AnnotationFormOverlay.js
'
;
const
TARGET_VIEW
=
'
target
'
;
const
TARGET_VIEW
=
'
target
'
;
...
@@ -262,16 +262,6 @@ function AnnotationCreation(props) {
...
@@ -262,16 +262,6 @@ function AnnotationCreation(props) {
}));
}));
};
};
/**
* Get SVG picture containing all the stuff draw in the stage (Konva Stage).
* This image will be put in overlay of the iiif media
*/
const
getSvg
=
async
()
=>
{
const
stage
=
window
.
Konva
.
stages
.
find
((
s
)
=>
s
.
attrs
.
id
===
props
.
windowId
);
const
svg
=
await
exportStageSVG
(
stage
,
false
);
// TODO clean
return
svg
;
};
/** Set color tool from current shape */
/** Set color tool from current shape */
const
setColorToolFromCurrentShape
=
(
colorState
)
=>
{
const
setColorToolFromCurrentShape
=
(
colorState
)
=>
{
setToolState
((
prevState
)
=>
({
setToolState
((
prevState
)
=>
({
...
@@ -280,14 +270,6 @@ function AnnotationCreation(props) {
...
@@ -280,14 +270,6 @@ function AnnotationCreation(props) {
}));
}));
};
};
/** update shapes with shapes from annotationDrawing */
const
updateShapes
=
(
newDrawingState
)
=>
{
setDrawingState
(
newDrawingState
);
};
/** delete shape */
const
deleteShape
=
(
shapeId
)
=>
{
const
deleteShape
=
(
shapeId
)
=>
{
if
(
!
shapeId
)
{
if
(
!
shapeId
)
{
setDrawingState
((
prevState
)
=>
({
setDrawingState
((
prevState
)
=>
({
...
@@ -313,13 +295,13 @@ function AnnotationCreation(props) {
...
@@ -313,13 +295,13 @@ function AnnotationCreation(props) {
// TODO Possibly problem of syncing
// TODO Possibly problem of syncing
// TODO Improve this code
// TODO Improve this code
// If we are in edit mode, we have the transformer on the stage saved in the annotation
// If we are in edit mode, we have the transformer on the stage saved in the annotation
if
(
viewTool
===
OVERLAY_VIEW
&&
state
.
activeTool
===
'
edit
'
)
{
/*
if (viewTool === OVERLAY_VIEW && state.activeTool === 'edit') {
setState((prevState) => ({
setState((prevState) => ({
...prevState,
...prevState,
activeTool: 'cursor',
activeTool: 'cursor',
}));
}));
return;
return;
}
}
*/
const
{
const
{
annotation
,
annotation
,
...
@@ -328,14 +310,13 @@ function AnnotationCreation(props) {
...
@@ -328,14 +310,13 @@ function AnnotationCreation(props) {
config
,
config
,
}
=
props
;
}
=
props
;
const
dumbIimage
=
{
// const dumbIimage = {
id
:
null
,
// id: null,
svg
,
// svg,
};
// };
//
//state.image = dumbIimage;
// const konvaThing = dummyAnnot.konvaThing;
state
.
image
=
dumbIimage
;
const
drawingStateSerialized
=
JSON
.
stringify
(
drawingState
);
state
.
konvaThing
=
[
'
SOME KONVA THING
'
,
'
AND ANOTHER KONVA THING
'
,
{
thirdKonvaThing
:
'
Third Konva thing here
'
}];
const
{
const
{
textBody
,
textBody
,
...
@@ -347,43 +328,17 @@ function AnnotationCreation(props) {
...
@@ -347,43 +328,17 @@ function AnnotationCreation(props) {
konvaThing
,
konvaThing
,
}
=
state
;
}
=
state
;
// TODO rename variable for better comprenhension
// TODO rename variable for better comprenhension
const
svg
=
await
getSvg
();
const
svg
=
await
getSvg
(
props
.
windowId
);
const
t
=
(
tstart
&&
tend
)
?
`
${
tstart
}
,
${
tend
}
`
:
null
;
const
t
=
(
tstart
&&
tend
)
?
`
${
tstart
}
,
${
tend
}
`
:
null
;
const
body
=
{
value
:
(
!
textBody
.
length
&&
t
)
?
`
${
secondsToHMS
(
tstart
)}
->
${
secondsToHMS
(
tend
)}
`
:
textBody
};
const
body
=
{
value
:
(
!
textBody
.
length
&&
t
)
?
`
${
secondsToHMS
(
tstart
)}
->
${
secondsToHMS
(
tend
)}
`
:
textBody
};
// TODO promises not handled. Use promiseAll ?
canvases
.
forEach
(
async
(
canvas
)
=>
{
const
storageAdapter
=
config
.
annotation
.
adapter
(
canvas
.
id
);
const
anno
=
new
WebAnnotation
({
body
,
canvasId
:
canvas
.
id
,
fragsel
:
{
t
,
xywh
,
},
id
:
(
annotation
&&
annotation
.
id
)
||
`
${
uuid
()}
`
,
image
,
konvaThing
,
manifestId
:
canvas
.
options
.
resource
.
id
,
svg
,
tags
,
}).
toJson
();
if
(
annotation
)
{
saveAnnotation
(
canvases
,
config
,
receiveAnnotation
,
annotation
,
body
,
t
,
xywh
,
image
,
konvaThing
,
svg
,
tags
);
storageAdapter
.
update
(
anno
)
.
then
((
annoPage
)
=>
{
receiveAnnotation
(
canvas
.
id
,
storageAdapter
.
annotationPageId
,
annoPage
);
});
}
else
{
storageAdapter
.
create
(
anno
)
.
then
((
annoPage
)
=>
{
receiveAnnotation
(
canvas
.
id
,
storageAdapter
.
annotationPageId
,
annoPage
);
});
}
});
props
.
closeCompanionWindow
(
'
annotationCreation
'
,
{
props
.
closeCompanionWindow
(
'
annotationCreation
'
,
{
id
,
id
,
position
:
'
right
'
,
position
:
'
right
'
,
});
});
// TODO this create a re-render too soon for react and crash the app
// TODO this create a re-render too soon for react and crash the app
setState
({
setState
({
image
:
{
id
:
null
},
image
:
{
id
:
null
},
...
...
This diff is collapsed.
Click to expand it.
src/AnnotationCreationUtils.js
+
47
−
0
View file @
c403739a
import
{
exportStageSVG
}
from
"
react-konva-to-svg
"
;
import
WebAnnotation
from
"
./WebAnnotation
"
;
import
{
v4
as
uuid
}
from
"
uuid
"
;
/** Extract time information from annotation target */
/** Extract time information from annotation target */
export
function
timeFromAnnoTarget
(
annotarget
)
{
export
function
timeFromAnnoTarget
(
annotarget
)
{
console
.
info
(
'
TODO proper time extraction from:
'
,
annotarget
);
console
.
info
(
'
TODO proper time extraction from:
'
,
annotarget
);
...
@@ -41,3 +45,46 @@ export function isShapesTool(activeTool) {
...
@@ -41,3 +45,46 @@ export function isShapesTool(activeTool) {
// Find if active tool in the list of overlay tools. I want a boolean in return
// Find if active tool in the list of overlay tools. I want a boolean in return
return
Object
.
values
(
SHAPES_TOOL
).
find
((
tool
)
=>
tool
===
activeTool
)
;
return
Object
.
values
(
SHAPES_TOOL
).
find
((
tool
)
=>
tool
===
activeTool
)
;
}
}
/**
* Get SVG picture containing all the stuff draw in the stage (Konva Stage).
* This image will be put in overlay of the iiif media
*/
export
async
function
getSvg
(
windowId
)
{
const
stage
=
window
.
Konva
.
stages
.
find
((
s
)
=>
s
.
attrs
.
id
===
windowId
);
const
svg
=
await
exportStageSVG
(
stage
,
false
);
// TODO clean
return
svg
;
};
export
function
saveAnnotation
(
canvases
,
config
,
receiveAnnotation
,
annotation
,
body
,
t
,
xywh
,
image
,
konvaThing
,
svg
,
tags
){
// TODO promises not handled. Use promiseAll ?
canvases
.
forEach
(
async
(
canvas
)
=>
{
const
storageAdapter
=
config
.
annotation
.
adapter
(
canvas
.
id
);
const
anno
=
new
WebAnnotation
({
body
,
canvasId
:
canvas
.
id
,
fragsel
:
{
t
,
xywh
,
},
id
:
(
annotation
&&
annotation
.
id
)
||
`
${
uuid
()}
`
,
image
,
konvaThing
,
manifestId
:
canvas
.
options
.
resource
.
id
,
svg
,
tags
,
}).
toJson
();
if
(
annotation
)
{
storageAdapter
.
update
(
anno
)
.
then
((
annoPage
)
=>
{
receiveAnnotation
(
canvas
.
id
,
storageAdapter
.
annotationPageId
,
annoPage
);
});
}
else
{
storageAdapter
.
create
(
anno
)
.
then
((
annoPage
)
=>
{
receiveAnnotation
(
canvas
.
id
,
storageAdapter
.
annotationPageId
,
annoPage
);
});
}
});
}
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