Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
144
Merge Requests
144
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
erp5
Commits
b3dd2872
Commit
b3dd2872
authored
Sep 04, 2018
by
Richard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[erp5_notebook]: different localStorages for different notebooks
parent
e9aedce2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
96 additions
and
3 deletions
+96
-3
bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_notebook.html.html
...Item/portal_skins/erp5_notebook/gadget_notebook.html.html
+1
-1
bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_officejs_jio_notebook.js.js
...al_skins/erp5_notebook/gadget_officejs_jio_notebook.js.js
+95
-2
No files found.
bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_notebook.html.html
View file @
b3dd2872
...
...
@@ -14,7 +14,7 @@
</head>
<body>
<div
id=
'page'
></div>
<script
id=
"jsmd"
type=
"text/jsmd"
></script>
<div
id=
'page'
></div>
</body>
</html>
\ No newline at end of file
bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_officejs_jio_notebook.js.js
View file @
b3dd2872
...
...
@@ -22,11 +22,22 @@
return
this
.
changeState
({
key
:
options
.
key
,
value
:
options
.
value
,
first_render
:
true
first_render
:
true
,
timestamp
:
options
.
render_timestamp
});
})
.
onStateChange
(
function
(
modified_dict
)
{
var
notebookTitle
=
getiodideSettingsFromJsmd
(
this
.
state
.
value
).
title
;
if
(
!
notebookTitle
)
{
var
jsmdTitleTemplate
=
'
%% meta
\n
{
\n
"title": ""
\n
}
'
;
notebookTitle
=
'
notebook-
'
+
modified_dict
.
timestamp
;
var
positionToInsertTitle
=
20
;
var
jsmdNotebookTitle
=
[
jsmdTitleTemplate
.
slice
(
0
,
positionToInsertTitle
),
notebookTitle
,
jsmdTitleTemplate
.
slice
(
positionToInsertTitle
)].
join
(
''
);
this
.
state
.
value
=
jsmdNotebookTitle
+
this
.
state
.
value
;
}
this
.
element
.
querySelector
(
'
script
'
).
textContent
=
this
.
state
.
value
;
if
(
!
modified_dict
.
hasOwnProperty
(
'
first_render
'
))
{
throw
new
Error
(
'
Sorry, it is not possible to dynamically change the iodide content
'
);
}
...
...
@@ -36,8 +47,90 @@
})
.
declareMethod
(
"
getContent
"
,
function
()
{
//prefer content since last save, fallback on autosave if it does not exist
var
dict
=
{};
dict
[
this
.
state
.
key
]
=
localStorage
.
getItem
(
'
AUTOSAVE: untitled
'
);
var
notebookTitle
=
getiodideSettingsFromJsmd
(
this
.
state
.
value
).
title
;
var
localStorageJsmd
=
localStorage
.
getItem
(
notebookTitle
);
if
(
!
localStorageJsmd
)
{
var
autosaveString
=
'
AUTOSAVE:
'
+
notebookTitle
;
localStorageJsmd
=
localStorage
.
getItem
(
autosaveString
);
}
dict
[
this
.
state
.
key
]
=
localStorageJsmd
;
return
dict
;
});
function
parseMetaChunk
(
content
)
{
var
metaSettings
;
try
{
metaSettings
=
JSON
.
parse
(
content
);
}
catch
(
e
)
{
console
.
error
(
'
Failed to parse notebook settings from meta cell. Using default settings.
'
,
content
);
metaSettings
=
{};
// set content back to empty object
}
return
{
chunkType
:
'
meta
'
,
iodideSettings
:
metaSettings
};
}
function
parseJsmdChunk
(
str
)
{
var
chunkType
;
var
settings
=
{};
var
content
;
var
firstLine
;
var
firstLineBreak
=
str
.
indexOf
(
'
\n
'
);
if
(
firstLineBreak
===
-
1
)
{
// a cell with only 1 line, and hence no content
firstLine
=
str
;
content
=
''
;
}
else
{
firstLine
=
str
.
substring
(
0
,
firstLineBreak
).
trim
();
content
=
str
.
substring
(
firstLineBreak
+
1
).
trim
();
}
// let firstLine = str.substring(0,firstLineBreak).trim()
var
firstLineFirstSpace
=
firstLine
.
indexOf
(
'
'
);
if
(
firstLineFirstSpace
===
-
1
)
{
// if there is NO space on the first line (after trimming), there are no cell settings
chunkType
=
firstLine
.
toLowerCase
();
}
else
{
// if there is a space on the first line (after trimming), there must be cell settings
chunkType
=
firstLine
.
substring
(
0
,
firstLineFirstSpace
).
toLowerCase
();
// make sure the cell settings parse as JSON
}
var
chunkObject
;
if
(
chunkType
===
'
meta
'
)
{
chunkObject
=
parseMetaChunk
(
content
);
}
else
{
console
.
log
(
'
not meta chunk
'
);
}
return
chunkObject
;
}
function
getiodideSettingsFromJsmd
(
jsmdString
)
{
// returns iodideSettings of last found chunk and exits
var
notebookTitle
=
jsmdString
;
var
chunkObjects
=
notebookTitle
.
split
(
'
\n
%%
'
)
.
map
((
str
,
chunkNum
)
=>
{
// if this is the first chunk, and it starts with "%%", drop those chars
let
sstr
if
(
chunkNum
===
0
&&
str
.
substring
(
0
,
2
)
===
'
%%
'
)
{
sstr
=
str
.
substring
(
2
)
}
else
{
sstr
=
str
}
return
sstr
})
.
map
(
str
=>
str
.
trim
())
.
filter
(
str
=>
str
!==
''
);
//for (var i = chunkObjects.length; i > 0; i--){
for
(
var
i
=
(
chunkObjects
.
length
-
1
);
i
>=
0
;
i
--
){
var
chunk
=
parseJsmdChunk
(
chunkObjects
[
i
]);
if
(
chunk
&&
chunk
.
iodideSettings
)
{
return
chunk
.
iodideSettings
}
}
return
''
;
}
}(
window
,
rJS
,
RSVP
));
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment