From 72cc28a1f912d258265ca3f69cf766ccf73b5fc7 Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Wed, 27 Mar 2019 16:06:07 +0000 Subject: [PATCH 01/28] erp5_notebook: Add highlight.js for Python code syntax highlight --- .../erp5_notebook/default.css.css | 99 +++++++++++++++++++ .../erp5_notebook/default.css.xml | 28 ++++++ .../erp5_notebook/highlight.js.js | 1 + .../erp5_notebook/highlight.js.xml | 28 ++++++ 4 files changed, 156 insertions(+) create mode 100644 bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/default.css.css create mode 100644 bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/default.css.xml create mode 100644 bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/highlight.js.js create mode 100644 bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/highlight.js.xml diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/default.css.css b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/default.css.css new file mode 100644 index 00000000000..f1bfade31e5 --- /dev/null +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/default.css.css @@ -0,0 +1,99 @@ +/* + +Original highlight.js style (c) Ivan Sagalaev + +*/ + +.hljs { + display: block; + overflow-x: auto; + padding: 0.5em; + background: #F0F0F0; +} + + +/* Base color: saturation 0; */ + +.hljs, +.hljs-subst { + color: #444; +} + +.hljs-comment { + color: #888888; +} + +.hljs-keyword, +.hljs-attribute, +.hljs-selector-tag, +.hljs-meta-keyword, +.hljs-doctag, +.hljs-name { + font-weight: bold; +} + + +/* User color: hue: 0 */ + +.hljs-type, +.hljs-string, +.hljs-number, +.hljs-selector-id, +.hljs-selector-class, +.hljs-quote, +.hljs-template-tag, +.hljs-deletion { + color: #880000; +} + +.hljs-title, +.hljs-section { + color: #880000; + font-weight: bold; +} + +.hljs-regexp, +.hljs-symbol, +.hljs-variable, +.hljs-template-variable, +.hljs-link, +.hljs-selector-attr, +.hljs-selector-pseudo { + color: #BC6060; +} + + +/* Language color: hue: 90; */ + +.hljs-literal { + color: #78A960; +} + +.hljs-built_in, +.hljs-bullet, +.hljs-code, +.hljs-addition { + color: #397300; +} + + +/* Meta color: hue: 200 */ + +.hljs-meta { + color: #1f7199; +} + +.hljs-meta-string { + color: #4d99bf; +} + + +/* Misc effects */ + +.hljs-emphasis { + font-style: italic; +} + +.hljs-strong { + font-weight: bold; +} diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/default.css.xml b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/default.css.xml new file mode 100644 index 00000000000..50e0653b52b --- /dev/null +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/default.css.xml @@ -0,0 +1,28 @@ + + + + + + + + + + __name__ + default.css + + + content_type + text/css + + + precondition + + + + title + + + + + + diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/highlight.js.js b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/highlight.js.js new file mode 100644 index 00000000000..5dcb79cfe44 --- /dev/null +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/highlight.js.js @@ -0,0 +1 @@ +!function(e){var n="object"==typeof window&&window||"object"==typeof self&&self;"undefined"!=typeof exports?e(exports):n&&(n.hljs=e({}),"function"==typeof define&&define.amd&&define([],function(){return n.hljs}))}(function(a){var E=[],u=Object.keys,N={},g={},n=/^(no-?highlight|plain|text)$/i,R=/\blang(?:uage)?-([\w-]+)\b/i,t=/((^(<[^>]+>|\t|)+|(?:\n)))/gm,r={case_insensitive:"cI",lexemes:"l",contains:"c",keywords:"k",subLanguage:"sL",className:"cN",begin:"b",beginKeywords:"bK",end:"e",endsWithParent:"eW",illegal:"i",excludeBegin:"eB",excludeEnd:"eE",returnBegin:"rB",returnEnd:"rE",relevance:"r",variants:"v",IDENT_RE:"IR",UNDERSCORE_IDENT_RE:"UIR",NUMBER_RE:"NR",C_NUMBER_RE:"CNR",BINARY_NUMBER_RE:"BNR",RE_STARTERS_RE:"RSR",BACKSLASH_ESCAPE:"BE",APOS_STRING_MODE:"ASM",QUOTE_STRING_MODE:"QSM",PHRASAL_WORDS_MODE:"PWM",C_LINE_COMMENT_MODE:"CLCM",C_BLOCK_COMMENT_MODE:"CBCM",HASH_COMMENT_MODE:"HCM",NUMBER_MODE:"NM",C_NUMBER_MODE:"CNM",BINARY_NUMBER_MODE:"BNM",CSS_NUMBER_MODE:"CSSNM",REGEXP_MODE:"RM",TITLE_MODE:"TM",UNDERSCORE_TITLE_MODE:"UTM",COMMENT:"C",beginRe:"bR",endRe:"eR",illegalRe:"iR",lexemesRe:"lR",terminators:"t",terminator_end:"tE"},b="",h={classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:void 0};function _(e){return e.replace(/&/g,"&").replace(//g,">")}function d(e){return e.nodeName.toLowerCase()}function v(e,n){var t=e&&e.exec(n);return t&&0===t.index}function p(e){return n.test(e)}function l(e){var n,t={},r=Array.prototype.slice.call(arguments,1);for(n in e)t[n]=e[n];return r.forEach(function(e){for(n in e)t[n]=e[n]}),t}function M(e){var a=[];return function e(n,t){for(var r=n.firstChild;r;r=r.nextSibling)3===r.nodeType?t+=r.nodeValue.length:1===r.nodeType&&(a.push({event:"start",offset:t,node:r}),t=e(r,t),d(r).match(/br|hr|img|input/)||a.push({event:"stop",offset:t,node:r}));return t}(e,0),a}function i(e){if(r&&!e.langApiRestored){for(var n in e.langApiRestored=!0,r)e[n]&&(e[r[n]]=e[n]);(e.c||[]).concat(e.v||[]).forEach(i)}}function m(c){function s(e){return e&&e.source||e}function o(e,n){return new RegExp(s(e),"m"+(c.cI?"i":"")+(n?"g":""))}!function n(t,e){if(!t.compiled){if(t.compiled=!0,t.k=t.k||t.bK,t.k){var r={},a=function(t,e){c.cI&&(e=e.toLowerCase()),e.split(" ").forEach(function(e){var n=e.split("|");r[n[0]]=[t,n[1]?Number(n[1]):1]})};"string"==typeof t.k?a("keyword",t.k):u(t.k).forEach(function(e){a(e,t.k[e])}),t.k=r}t.lR=o(t.l||/\w+/,!0),e&&(t.bK&&(t.b="\\b("+t.bK.split(" ").join("|")+")\\b"),t.b||(t.b=/\B|\b/),t.bR=o(t.b),t.endSameAsBegin&&(t.e=t.b),t.e||t.eW||(t.e=/\B|\b/),t.e&&(t.eR=o(t.e)),t.tE=s(t.e)||"",t.eW&&e.tE&&(t.tE+=(t.e?"|":"")+e.tE)),t.i&&(t.iR=o(t.i)),null==t.r&&(t.r=1),t.c||(t.c=[]),t.c=Array.prototype.concat.apply([],t.c.map(function(e){return(n="self"===e?t:e).v&&!n.cached_variants&&(n.cached_variants=n.v.map(function(e){return l(n,{v:null},e)})),n.cached_variants||n.eW&&[l(n)]||[n];var n})),t.c.forEach(function(e){n(e,t)}),t.starts&&n(t.starts,e);var i=t.c.map(function(e){return e.bK?"\\.?(?:"+e.b+")\\.?":e.b}).concat([t.tE,t.i]).map(s).filter(Boolean);t.t=i.length?o(function(e,n){for(var t=/\[(?:[^\\\]]|\\.)*\]|\(\??|\\([1-9][0-9]*)|\\./,r=0,a="",i=0;i')+n+(t?"":b)}function s(){g+=null!=E.sL?function(){var e="string"==typeof E.sL;if(e&&!N[E.sL])return _(R);var n=e?C(E.sL,R,!0,i[E.sL]):O(R,E.sL.length?E.sL:void 0);return 0")+'"');return R+=n,n.length||1}var f=S(e);if(!f)throw new Error('Unknown language: "'+e+'"');m(f);var a,E=t||f,i={},g="";for(a=E;a!==f;a=a.parent)a.cN&&(g=u(a.cN,"",!0)+g);var R="",d=0;try{for(var c,p,M=0;E.t.lastIndex=M,c=E.t.exec(n);)p=r(n.substring(M,c.index),c[0]),M=c.index+p;for(r(n.substr(M)),a=E;a.parent;a=a.parent)a.cN&&(g+=b);return{r:d,value:g,language:e,top:E}}catch(e){if(e.message&&-1!==e.message.indexOf("Illegal"))return{r:0,value:_(n)};throw e}}function O(t,e){e=e||h.languages||u(N);var r={r:0,value:_(t)},a=r;return e.filter(S).filter(s).forEach(function(e){var n=C(e,t,!1);n.language=e,n.r>a.r&&(a=n),n.r>r.r&&(a=r,r=n)}),a.language&&(r.second_best=a),r}function B(e){return h.tabReplace||h.useBR?e.replace(t,function(e,n){return h.useBR&&"\n"===e?"
":h.tabReplace?n.replace(/\t/g,h.tabReplace):""}):e}function c(e){var n,t,r,a,i,c,o,u,s,l,f=function(e){var n,t,r,a,i=e.className+" ";if(i+=e.parentNode?e.parentNode.className:"",t=R.exec(i))return S(t[1])?t[1]:"no-highlight";for(n=0,r=(i=i.split(/\s+/)).length;n/g,"\n"):n=e,i=n.textContent,r=f?C(f,i,!0):O(i),(t=M(n)).length&&((a=document.createElementNS("http://www.w3.org/1999/xhtml","div")).innerHTML=r.value,r.value=function(e,n,t){var r=0,a="",i=[];function c(){return e.length&&n.length?e[0].offset!==n[0].offset?e[0].offset"}function u(e){a+=""}function s(e){("start"===e.event?o:u)(e.node)}for(;e.length||n.length;){var l=c();if(a+=_(t.substring(r,l[0].offset)),r=l[0].offset,l===e){for(i.reverse().forEach(u);s(l.splice(0,1)[0]),(l=c())===e&&l.length&&l[0].offset===r;);i.reverse().forEach(o)}else"start"===l[0].event?i.push(l[0].node):i.pop(),s(l.splice(0,1)[0])}return a+_(t.substr(r))}(t,M(a),i)),r.value=B(r.value),e.innerHTML=r.value,e.className=(c=e.className,o=f,u=r.language,s=o?g[o]:u,l=[c.trim()],c.match(/\bhljs\b/)||l.push("hljs"),-1===c.indexOf(s)&&l.push(s),l.join(" ").trim()),e.result={language:r.language,re:r.r},r.second_best&&(e.second_best={language:r.second_best.language,re:r.second_best.r}))}function o(){if(!o.called){o.called=!0;var e=document.querySelectorAll("pre code");E.forEach.call(e,c)}}function S(e){return e=(e||"").toLowerCase(),N[e]||N[g[e]]}function s(e){var n=S(e);return n&&!n.disableAutodetect}return a.highlight=C,a.highlightAuto=O,a.fixMarkup=B,a.highlightBlock=c,a.configure=function(e){h=l(h,e)},a.initHighlighting=o,a.initHighlightingOnLoad=function(){addEventListener("DOMContentLoaded",o,!1),addEventListener("load",o,!1)},a.registerLanguage=function(n,e){var t=N[n]=e(a);i(t),t.aliases&&t.aliases.forEach(function(e){g[e]=n})},a.listLanguages=function(){return u(N)},a.getLanguage=S,a.autoDetection=s,a.inherit=l,a.IR=a.IDENT_RE="[a-zA-Z]\\w*",a.UIR=a.UNDERSCORE_IDENT_RE="[a-zA-Z_]\\w*",a.NR=a.NUMBER_RE="\\b\\d+(\\.\\d+)?",a.CNR=a.C_NUMBER_RE="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",a.BNR=a.BINARY_NUMBER_RE="\\b(0b[01]+)",a.RSR=a.RE_STARTERS_RE="!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",a.BE=a.BACKSLASH_ESCAPE={b:"\\\\[\\s\\S]",r:0},a.ASM=a.APOS_STRING_MODE={cN:"string",b:"'",e:"'",i:"\\n",c:[a.BE]},a.QSM=a.QUOTE_STRING_MODE={cN:"string",b:'"',e:'"',i:"\\n",c:[a.BE]},a.PWM=a.PHRASAL_WORDS_MODE={b:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},a.C=a.COMMENT=function(e,n,t){var r=a.inherit({cN:"comment",b:e,e:n,c:[]},t||{});return r.c.push(a.PWM),r.c.push({cN:"doctag",b:"(?:TODO|FIXME|NOTE|BUG|XXX):",r:0}),r},a.CLCM=a.C_LINE_COMMENT_MODE=a.C("//","$"),a.CBCM=a.C_BLOCK_COMMENT_MODE=a.C("/\\*","\\*/"),a.HCM=a.HASH_COMMENT_MODE=a.C("#","$"),a.NM=a.NUMBER_MODE={cN:"number",b:a.NR,r:0},a.CNM=a.C_NUMBER_MODE={cN:"number",b:a.CNR,r:0},a.BNM=a.BINARY_NUMBER_MODE={cN:"number",b:a.BNR,r:0},a.CSSNM=a.CSS_NUMBER_MODE={cN:"number",b:a.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0},a.RM=a.REGEXP_MODE={cN:"regexp",b:/\//,e:/\/[gimuy]*/,i:/\n/,c:[a.BE,{b:/\[/,e:/\]/,r:0,c:[a.BE]}]},a.TM=a.TITLE_MODE={cN:"title",b:a.IR,r:0},a.UTM=a.UNDERSCORE_TITLE_MODE={cN:"title",b:a.UIR,r:0},a.METHOD_GUARD={b:"\\.\\s*"+a.UIR,r:0},a});hljs.registerLanguage("python",function(e){var r={keyword:"and elif is global as in if from raise for except finally print import pass return exec else break not with class assert yield try while continue del or def lambda async await nonlocal|10",built_in:"Ellipsis NotImplemented",literal:"False None True"},b={cN:"meta",b:/^(>>>|\.\.\.) /},c={cN:"subst",b:/\{/,e:/\}/,k:r,i:/#/},a={cN:"string",c:[e.BE],v:[{b:/(u|b)?r?'''/,e:/'''/,c:[e.BE,b],r:10},{b:/(u|b)?r?"""/,e:/"""/,c:[e.BE,b],r:10},{b:/(fr|rf|f)'''/,e:/'''/,c:[e.BE,b,c]},{b:/(fr|rf|f)"""/,e:/"""/,c:[e.BE,b,c]},{b:/(u|r|ur)'/,e:/'/,r:10},{b:/(u|r|ur)"/,e:/"/,r:10},{b:/(b|br)'/,e:/'/},{b:/(b|br)"/,e:/"/},{b:/(fr|rf|f)'/,e:/'/,c:[e.BE,c]},{b:/(fr|rf|f)"/,e:/"/,c:[e.BE,c]},e.ASM,e.QSM]},i={cN:"number",r:0,v:[{b:e.BNR+"[lLjJ]?"},{b:"\\b(0o[0-7]+)[lLjJ]?"},{b:e.CNR+"[lLjJ]?"}]},l={cN:"params",b:/\(/,e:/\)/,c:["self",b,i,a]};return c.c=[a,i,b],{aliases:["py","gyp","ipython"],k:r,i:/(<\/|->|\?)|=>/,c:[b,i,a,e.HCM,{v:[{cN:"function",bK:"def"},{cN:"class",bK:"class"}],e:/:/,i:/[${=;\n,]/,c:[e.UTM,l,{b:/->/,eW:!0,k:"None"}]},{cN:"meta",b:/^[\t ]*@/,e:/$/},{b:/\b(print|exec)\(/}]}});hljs.registerLanguage("xml",function(s){var e={eW:!0,i:/`]+/}]}]}]};return{aliases:["html","xhtml","rss","atom","xjb","xsd","xsl","plist"],cI:!0,c:[{cN:"meta",b:"",r:10,c:[{b:"\\[",e:"\\]"}]},s.C("\x3c!--","--\x3e",{r:10}),{b:"<\\!\\[CDATA\\[",e:"\\]\\]>",r:10},{cN:"meta",b:/<\?xml/,e:/\?>/,r:10},{b:/<\?(php)?/,e:/\?>/,sL:"php",c:[{b:"/\\*",e:"\\*/",skip:!0},{b:'b"',e:'"',skip:!0},{b:"b'",e:"'",skip:!0},s.inherit(s.ASM,{i:null,cN:null,c:null,skip:!0}),s.inherit(s.QSM,{i:null,cN:null,c:null,skip:!0})]},{cN:"tag",b:"|$)",e:">",k:{name:"style"},c:[e],starts:{e:"",rE:!0,sL:["css","xml"]}},{cN:"tag",b:"|$)",e:">",k:{name:"script"},c:[e],starts:{e:"<\/script>",rE:!0,sL:["actionscript","javascript","handlebars","xml"]}},{cN:"tag",b:"",c:[{cN:"name",b:/[^\/><\s]+/,r:0},e]}]}});hljs.registerLanguage("markdown",function(e){return{aliases:["md","mkdown","mkd"],c:[{cN:"section",v:[{b:"^#{1,6}",e:"$"},{b:"^.+?\\n[=-]{2,}$"}]},{b:"<",e:">",sL:"xml",r:0},{cN:"bullet",b:"^([*+-]|(\\d+\\.))\\s+"},{cN:"strong",b:"[*_]{2}.+?[*_]{2}"},{cN:"emphasis",v:[{b:"\\*.+?\\*"},{b:"_.+?_",r:0}]},{cN:"quote",b:"^>\\s+",e:"$"},{cN:"code",v:[{b:"^```w*s*$",e:"^```s*$"},{b:"`.+?`"},{b:"^( {4}|\t)",e:"$",r:0}]},{b:"^[-\\*]{3,}",e:"$"},{b:"\\[.+?\\][\\(\\[].*?[\\)\\]]",rB:!0,c:[{cN:"string",b:"\\[",e:"\\]",eB:!0,rE:!0,r:0},{cN:"link",b:"\\]\\(",e:"\\)",eB:!0,eE:!0},{cN:"symbol",b:"\\]\\[",e:"\\]",eB:!0,eE:!0}],r:10},{b:/^\[[^\n]+\]:/,rB:!0,c:[{cN:"symbol",b:/\[/,e:/\]/,eB:!0,eE:!0},{cN:"link",b:/:\s*/,e:/$/,eB:!0}]}]}});hljs.registerLanguage("javascript",function(e){var r="[A-Za-z$_][0-9A-Za-z$_]*",t={keyword:"in of if for while finally var new function do return void else break catch instanceof with throw case default try this switch continue typeof delete let yield const export super debugger as async await static import from as",literal:"true false null undefined NaN Infinity",built_in:"eval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Error EvalError InternalError RangeError ReferenceError StopIteration SyntaxError TypeError URIError Number Math Date String RegExp Array Float32Array Float64Array Int16Array Int32Array Int8Array Uint16Array Uint32Array Uint8Array Uint8ClampedArray ArrayBuffer DataView JSON Intl arguments require module console window document Symbol Set Map WeakSet WeakMap Proxy Reflect Promise"},a={cN:"number",v:[{b:"\\b(0[bB][01]+)"},{b:"\\b(0[oO][0-7]+)"},{b:e.CNR}],r:0},n={cN:"subst",b:"\\$\\{",e:"\\}",k:t,c:[]},c={cN:"string",b:"`",e:"`",c:[e.BE,n]};n.c=[e.ASM,e.QSM,c,a,e.RM];var s=n.c.concat([e.CBCM,e.CLCM]);return{aliases:["js","jsx"],k:t,c:[{cN:"meta",r:10,b:/^\s*['"]use (strict|asm)['"]/},{cN:"meta",b:/^#!/,e:/$/},e.ASM,e.QSM,c,e.CLCM,e.CBCM,a,{b:/[{,]\s*/,r:0,c:[{b:r+"\\s*:",rB:!0,r:0,c:[{cN:"attr",b:r,r:0}]}]},{b:"("+e.RSR+"|\\b(case|return|throw)\\b)\\s*",k:"return throw case",c:[e.CLCM,e.CBCM,e.RM,{cN:"function",b:"(\\(.*?\\)|"+r+")\\s*=>",rB:!0,e:"\\s*=>",c:[{cN:"params",v:[{b:r},{b:/\(\s*\)/},{b:/\(/,e:/\)/,eB:!0,eE:!0,k:t,c:s}]}]},{b://,sL:"xml",c:[{b:/<\w+\s*\/>/,skip:!0},{b:/<\w+/,e:/(\/\w+|\w+\/)>/,skip:!0,c:[{b:/<\w+\s*\/>/,skip:!0},"self"]}]}],r:0},{cN:"function",bK:"function",e:/\{/,eE:!0,c:[e.inherit(e.TM,{b:r}),{cN:"params",b:/\(/,e:/\)/,eB:!0,eE:!0,c:s}],i:/\[|%/},{b:/\$[(.]/},e.METHOD_GUARD,{cN:"class",bK:"class",e:/[{;=]/,eE:!0,i:/[:"\[\]]/,c:[{bK:"extends"},e.UTM]},{bK:"constructor get set",e:/\{/,eE:!0}],i:/#(?!!)/}}); \ No newline at end of file diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/highlight.js.xml b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/highlight.js.xml new file mode 100644 index 00000000000..416f79a97b8 --- /dev/null +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/highlight.js.xml @@ -0,0 +1,28 @@ + + + + + + + + + + __name__ + highlight.js + + + content_type + application/javascript + + + precondition + + + + title + + + + + + -- 2.30.9 From 854572f89dd6a23b1f7f4e6ea29fe10768f4165c Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Wed, 27 Mar 2019 16:18:40 +0000 Subject: [PATCH 02/28] erp5_notebook: Temp fix, window.iodide.xxx is undefined the iodide seems not initialized correctly. I checked the new pyodide.js in the upstream, this logic was changed. But I didn't dig whether there has an issue associated with this problem. I plan to update the compiled pyodide module and source code later. --- .../SkinTemplateItem/portal_skins/erp5_notebook/pyodide.js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/pyodide.js.js b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/pyodide.js.js index cee7cb1e3e3..9feac7db959 100644 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/pyodide.js.js +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/pyodide.js.js @@ -108,7 +108,7 @@ var languagePluginLoader = new Promise((resolve, reject) => { }); if (window.iodide !== undefined) { - window.iodide.evalQueue.await([ promise ]); + // window.iodide.evalQueue.await([ promise ]); } return promise; -- 2.30.9 From 9beecd84369478aec67c1604b5fda170e9697afa Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Wed, 27 Mar 2019 16:21:48 +0000 Subject: [PATCH 03/28] erp5_notebook: Load pyodide in jsmd eval file to handle python setction. The output of Python is a mimic of jupyter notebook. --- .../erp5_notebook/gadget_jsmd_eval.html.html | 5 ++ .../erp5_notebook/gadget_jsmd_eval.js.js | 73 ++++++++++++++++++- 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.html.html b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.html.html index 6897c1c58fe..c75b7c16ed7 100644 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.html.html +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.html.html @@ -8,10 +8,15 @@ JSMD Eval Gadget + + + + + diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js index 3e8228b9d17..9091a2b03c0 100644 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js @@ -1,6 +1,6 @@ -/*global window, console, RSVP, document, URL, eval, XMLHttpRequest, marked */ +/*global window, console, RSVP, document, URL, eval, XMLHttpRequest, marked, pyodide hljs */ /*jslint nomen: true, indent: 2, maxerr: 3 */ -(function (window) { +(function (window, languagePluginLoader) { "use strict"; var IODide = function createIODide() { @@ -107,6 +107,8 @@ pre, br, code; + renderCodeblock(line_list.join('\n'), 'undefined', 'js'); + try { return eval.call(window, text); } catch (e) { @@ -253,6 +255,60 @@ }); } + function executePyCell(line_list) { + return new RSVP.Promise(function (resolve, reject) { + var result_text, code_text = line_list.join('\n'); + try { + result_text = pyodide.runPython(line_list.join('\n')); + } catch (e) { + result_text = e.message; + } + console.log("Result test:"); + console.log(result_text); + console.log("================="); + if (typeof(result_text) === 'undefined') { + result_text = 'undefined'; + } + + renderCodeblock(code_text, result_text, 'python'); + resolve(); + }); + } + + function renderCodeblock(code_text, result_text, language) { + var div = document.createElement('div'), + pre0 = document.createElement('pre'), + p = document.createElement('p'), + pre1 = document.createElement('pre'), + pre2 = document.createElement('pre'), + code = document.createElement('code'), + result = document.createElement('code'); + div.style.border = '1px solid #C3CCD0'; + div.style.margin = '40px 10px'; + code.style.border = '1px solid #C3CCD0'; + + code.classList.add(language); + code.classList.add('hljs'); + + result.classList.add('shell'); + result.classList.add('hljs'); + code.innerHTML = code_text; + hljs.highlightBlock(code); + hljs.highlightBlock(result); + + p.innerHTML = language; + p.style.marginLeft = '10px'; + pre0.appendChild(p); + pre1.appendChild(code); + div.appendChild(pre0); + div.appendChild(pre1); + if (result_text !== 'undefined') { + result.innerHTML = result_text; + pre2.appendChild(result); + div.appendChild(pre2); + } + document.body.appendChild(div); + } function executeCell(cell) { if (cell._type === 'raw') { // Do nothing... @@ -273,6 +329,9 @@ if (cell._type === 'css') { return executeCssCell(cell._line_list); } + if (cell._type === 'py') { + return executePyCell(cell._line_list); + } return executeUnknownCellType(cell); } @@ -291,6 +350,9 @@ i, queue = new RSVP.Queue(); + queue.push(function () { + return languagePluginLoader; + }); for (i = 0; i < len; i += 1) { queue.push(deferCellExecution(cell_list[i])); } @@ -299,6 +361,11 @@ console.info('JSMD executed.'); }, function (error) { console.error(error); + // do not print the error page with a non-styled pre tag + // the Python error message will be displayed along with Python source code in above + if (error.message.startsWith('Traceback')) { + return; + } var pre = document.createElement('pre'); pre.textContent = error; document.body.appendChild(pre); @@ -306,4 +373,4 @@ }, false); -}(window)); \ No newline at end of file +}(window, languagePluginLoader)); \ No newline at end of file -- 2.30.9 From b6a606af3ad57d7e38a7b76d071c58a6f2af93b9 Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Wed, 27 Mar 2019 16:29:05 +0000 Subject: [PATCH 04/28] erp5_notebook: Only render the result of Python code Not render original Python and JS source code anymore --- .../erp5_notebook/gadget_jsmd_eval.js.js | 32 ++++--------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js index 9091a2b03c0..9687a775fa7 100644 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js @@ -107,7 +107,6 @@ pre, br, code; - renderCodeblock(line_list.join('\n'), 'undefined', 'js'); try { return eval.call(window, text); @@ -263,52 +262,35 @@ } catch (e) { result_text = e.message; } - console.log("Result test:"); - console.log(result_text); - console.log("================="); + if (typeof(result_text) === 'undefined') { result_text = 'undefined'; } - renderCodeblock(code_text, result_text, 'python'); + renderCodeblock(result_text, 'python'); resolve(); }); } - function renderCodeblock(code_text, result_text, language) { + function renderCodeblock(result_text, language) { var div = document.createElement('div'), - pre0 = document.createElement('pre'), - p = document.createElement('p'), - pre1 = document.createElement('pre'), - pre2 = document.createElement('pre'), - code = document.createElement('code'), + pre = document.createElement('pre'), result = document.createElement('code'); div.style.border = '1px solid #C3CCD0'; div.style.margin = '40px 10px'; - code.style.border = '1px solid #C3CCD0'; - - code.classList.add(language); - code.classList.add('hljs'); result.classList.add('shell'); result.classList.add('hljs'); - code.innerHTML = code_text; - hljs.highlightBlock(code); hljs.highlightBlock(result); - p.innerHTML = language; - p.style.marginLeft = '10px'; - pre0.appendChild(p); - pre1.appendChild(code); - div.appendChild(pre0); - div.appendChild(pre1); if (result_text !== 'undefined') { result.innerHTML = result_text; - pre2.appendChild(result); - div.appendChild(pre2); + pre.appendChild(result); + div.appendChild(pre); } document.body.appendChild(div); } + function executeCell(cell) { if (cell._type === 'raw') { // Do nothing... -- 2.30.9 From e84f99f1b7dc48f9d861f1004badb2ce3bba5239 Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Wed, 27 Mar 2019 17:00:30 +0000 Subject: [PATCH 05/28] erp5_notebook: Remove highligh.js We don't need syntax highlight anymore --- .../erp5_notebook/default.css.css | 99 ------------------- .../erp5_notebook/default.css.xml | 28 ------ .../erp5_notebook/gadget_jsmd_eval.html.html | 3 - .../erp5_notebook/gadget_jsmd_eval.js.js | 7 +- .../erp5_notebook/highlight.js.js | 1 - .../erp5_notebook/highlight.js.xml | 28 ------ 6 files changed, 2 insertions(+), 164 deletions(-) delete mode 100644 bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/default.css.css delete mode 100644 bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/default.css.xml delete mode 100644 bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/highlight.js.js delete mode 100644 bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/highlight.js.xml diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/default.css.css b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/default.css.css deleted file mode 100644 index f1bfade31e5..00000000000 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/default.css.css +++ /dev/null @@ -1,99 +0,0 @@ -/* - -Original highlight.js style (c) Ivan Sagalaev - -*/ - -.hljs { - display: block; - overflow-x: auto; - padding: 0.5em; - background: #F0F0F0; -} - - -/* Base color: saturation 0; */ - -.hljs, -.hljs-subst { - color: #444; -} - -.hljs-comment { - color: #888888; -} - -.hljs-keyword, -.hljs-attribute, -.hljs-selector-tag, -.hljs-meta-keyword, -.hljs-doctag, -.hljs-name { - font-weight: bold; -} - - -/* User color: hue: 0 */ - -.hljs-type, -.hljs-string, -.hljs-number, -.hljs-selector-id, -.hljs-selector-class, -.hljs-quote, -.hljs-template-tag, -.hljs-deletion { - color: #880000; -} - -.hljs-title, -.hljs-section { - color: #880000; - font-weight: bold; -} - -.hljs-regexp, -.hljs-symbol, -.hljs-variable, -.hljs-template-variable, -.hljs-link, -.hljs-selector-attr, -.hljs-selector-pseudo { - color: #BC6060; -} - - -/* Language color: hue: 90; */ - -.hljs-literal { - color: #78A960; -} - -.hljs-built_in, -.hljs-bullet, -.hljs-code, -.hljs-addition { - color: #397300; -} - - -/* Meta color: hue: 200 */ - -.hljs-meta { - color: #1f7199; -} - -.hljs-meta-string { - color: #4d99bf; -} - - -/* Misc effects */ - -.hljs-emphasis { - font-style: italic; -} - -.hljs-strong { - font-weight: bold; -} diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/default.css.xml b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/default.css.xml deleted file mode 100644 index 50e0653b52b..00000000000 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/default.css.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - __name__ - default.css - - - content_type - text/css - - - precondition - - - - title - - - - - - diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.html.html b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.html.html index c75b7c16ed7..437944bedb3 100644 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.html.html +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.html.html @@ -8,14 +8,11 @@ JSMD Eval Gadget - - - diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js index 9687a775fa7..658c0d10fa7 100644 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js @@ -278,17 +278,14 @@ result = document.createElement('code'); div.style.border = '1px solid #C3CCD0'; div.style.margin = '40px 10px'; - - result.classList.add('shell'); - result.classList.add('hljs'); - hljs.highlightBlock(result); + div.style.paddingLeft = '10px'; if (result_text !== 'undefined') { result.innerHTML = result_text; pre.appendChild(result); div.appendChild(pre); + document.body.appendChild(div); } - document.body.appendChild(div); } function executeCell(cell) { diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/highlight.js.js b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/highlight.js.js deleted file mode 100644 index 5dcb79cfe44..00000000000 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/highlight.js.js +++ /dev/null @@ -1 +0,0 @@ -!function(e){var n="object"==typeof window&&window||"object"==typeof self&&self;"undefined"!=typeof exports?e(exports):n&&(n.hljs=e({}),"function"==typeof define&&define.amd&&define([],function(){return n.hljs}))}(function(a){var E=[],u=Object.keys,N={},g={},n=/^(no-?highlight|plain|text)$/i,R=/\blang(?:uage)?-([\w-]+)\b/i,t=/((^(<[^>]+>|\t|)+|(?:\n)))/gm,r={case_insensitive:"cI",lexemes:"l",contains:"c",keywords:"k",subLanguage:"sL",className:"cN",begin:"b",beginKeywords:"bK",end:"e",endsWithParent:"eW",illegal:"i",excludeBegin:"eB",excludeEnd:"eE",returnBegin:"rB",returnEnd:"rE",relevance:"r",variants:"v",IDENT_RE:"IR",UNDERSCORE_IDENT_RE:"UIR",NUMBER_RE:"NR",C_NUMBER_RE:"CNR",BINARY_NUMBER_RE:"BNR",RE_STARTERS_RE:"RSR",BACKSLASH_ESCAPE:"BE",APOS_STRING_MODE:"ASM",QUOTE_STRING_MODE:"QSM",PHRASAL_WORDS_MODE:"PWM",C_LINE_COMMENT_MODE:"CLCM",C_BLOCK_COMMENT_MODE:"CBCM",HASH_COMMENT_MODE:"HCM",NUMBER_MODE:"NM",C_NUMBER_MODE:"CNM",BINARY_NUMBER_MODE:"BNM",CSS_NUMBER_MODE:"CSSNM",REGEXP_MODE:"RM",TITLE_MODE:"TM",UNDERSCORE_TITLE_MODE:"UTM",COMMENT:"C",beginRe:"bR",endRe:"eR",illegalRe:"iR",lexemesRe:"lR",terminators:"t",terminator_end:"tE"},b="",h={classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:void 0};function _(e){return e.replace(/&/g,"&").replace(//g,">")}function d(e){return e.nodeName.toLowerCase()}function v(e,n){var t=e&&e.exec(n);return t&&0===t.index}function p(e){return n.test(e)}function l(e){var n,t={},r=Array.prototype.slice.call(arguments,1);for(n in e)t[n]=e[n];return r.forEach(function(e){for(n in e)t[n]=e[n]}),t}function M(e){var a=[];return function e(n,t){for(var r=n.firstChild;r;r=r.nextSibling)3===r.nodeType?t+=r.nodeValue.length:1===r.nodeType&&(a.push({event:"start",offset:t,node:r}),t=e(r,t),d(r).match(/br|hr|img|input/)||a.push({event:"stop",offset:t,node:r}));return t}(e,0),a}function i(e){if(r&&!e.langApiRestored){for(var n in e.langApiRestored=!0,r)e[n]&&(e[r[n]]=e[n]);(e.c||[]).concat(e.v||[]).forEach(i)}}function m(c){function s(e){return e&&e.source||e}function o(e,n){return new RegExp(s(e),"m"+(c.cI?"i":"")+(n?"g":""))}!function n(t,e){if(!t.compiled){if(t.compiled=!0,t.k=t.k||t.bK,t.k){var r={},a=function(t,e){c.cI&&(e=e.toLowerCase()),e.split(" ").forEach(function(e){var n=e.split("|");r[n[0]]=[t,n[1]?Number(n[1]):1]})};"string"==typeof t.k?a("keyword",t.k):u(t.k).forEach(function(e){a(e,t.k[e])}),t.k=r}t.lR=o(t.l||/\w+/,!0),e&&(t.bK&&(t.b="\\b("+t.bK.split(" ").join("|")+")\\b"),t.b||(t.b=/\B|\b/),t.bR=o(t.b),t.endSameAsBegin&&(t.e=t.b),t.e||t.eW||(t.e=/\B|\b/),t.e&&(t.eR=o(t.e)),t.tE=s(t.e)||"",t.eW&&e.tE&&(t.tE+=(t.e?"|":"")+e.tE)),t.i&&(t.iR=o(t.i)),null==t.r&&(t.r=1),t.c||(t.c=[]),t.c=Array.prototype.concat.apply([],t.c.map(function(e){return(n="self"===e?t:e).v&&!n.cached_variants&&(n.cached_variants=n.v.map(function(e){return l(n,{v:null},e)})),n.cached_variants||n.eW&&[l(n)]||[n];var n})),t.c.forEach(function(e){n(e,t)}),t.starts&&n(t.starts,e);var i=t.c.map(function(e){return e.bK?"\\.?(?:"+e.b+")\\.?":e.b}).concat([t.tE,t.i]).map(s).filter(Boolean);t.t=i.length?o(function(e,n){for(var t=/\[(?:[^\\\]]|\\.)*\]|\(\??|\\([1-9][0-9]*)|\\./,r=0,a="",i=0;i')+n+(t?"":b)}function s(){g+=null!=E.sL?function(){var e="string"==typeof E.sL;if(e&&!N[E.sL])return _(R);var n=e?C(E.sL,R,!0,i[E.sL]):O(R,E.sL.length?E.sL:void 0);return 0")+'"');return R+=n,n.length||1}var f=S(e);if(!f)throw new Error('Unknown language: "'+e+'"');m(f);var a,E=t||f,i={},g="";for(a=E;a!==f;a=a.parent)a.cN&&(g=u(a.cN,"",!0)+g);var R="",d=0;try{for(var c,p,M=0;E.t.lastIndex=M,c=E.t.exec(n);)p=r(n.substring(M,c.index),c[0]),M=c.index+p;for(r(n.substr(M)),a=E;a.parent;a=a.parent)a.cN&&(g+=b);return{r:d,value:g,language:e,top:E}}catch(e){if(e.message&&-1!==e.message.indexOf("Illegal"))return{r:0,value:_(n)};throw e}}function O(t,e){e=e||h.languages||u(N);var r={r:0,value:_(t)},a=r;return e.filter(S).filter(s).forEach(function(e){var n=C(e,t,!1);n.language=e,n.r>a.r&&(a=n),n.r>r.r&&(a=r,r=n)}),a.language&&(r.second_best=a),r}function B(e){return h.tabReplace||h.useBR?e.replace(t,function(e,n){return h.useBR&&"\n"===e?"
":h.tabReplace?n.replace(/\t/g,h.tabReplace):""}):e}function c(e){var n,t,r,a,i,c,o,u,s,l,f=function(e){var n,t,r,a,i=e.className+" ";if(i+=e.parentNode?e.parentNode.className:"",t=R.exec(i))return S(t[1])?t[1]:"no-highlight";for(n=0,r=(i=i.split(/\s+/)).length;n/g,"\n"):n=e,i=n.textContent,r=f?C(f,i,!0):O(i),(t=M(n)).length&&((a=document.createElementNS("http://www.w3.org/1999/xhtml","div")).innerHTML=r.value,r.value=function(e,n,t){var r=0,a="",i=[];function c(){return e.length&&n.length?e[0].offset!==n[0].offset?e[0].offset"}function u(e){a+=""}function s(e){("start"===e.event?o:u)(e.node)}for(;e.length||n.length;){var l=c();if(a+=_(t.substring(r,l[0].offset)),r=l[0].offset,l===e){for(i.reverse().forEach(u);s(l.splice(0,1)[0]),(l=c())===e&&l.length&&l[0].offset===r;);i.reverse().forEach(o)}else"start"===l[0].event?i.push(l[0].node):i.pop(),s(l.splice(0,1)[0])}return a+_(t.substr(r))}(t,M(a),i)),r.value=B(r.value),e.innerHTML=r.value,e.className=(c=e.className,o=f,u=r.language,s=o?g[o]:u,l=[c.trim()],c.match(/\bhljs\b/)||l.push("hljs"),-1===c.indexOf(s)&&l.push(s),l.join(" ").trim()),e.result={language:r.language,re:r.r},r.second_best&&(e.second_best={language:r.second_best.language,re:r.second_best.r}))}function o(){if(!o.called){o.called=!0;var e=document.querySelectorAll("pre code");E.forEach.call(e,c)}}function S(e){return e=(e||"").toLowerCase(),N[e]||N[g[e]]}function s(e){var n=S(e);return n&&!n.disableAutodetect}return a.highlight=C,a.highlightAuto=O,a.fixMarkup=B,a.highlightBlock=c,a.configure=function(e){h=l(h,e)},a.initHighlighting=o,a.initHighlightingOnLoad=function(){addEventListener("DOMContentLoaded",o,!1),addEventListener("load",o,!1)},a.registerLanguage=function(n,e){var t=N[n]=e(a);i(t),t.aliases&&t.aliases.forEach(function(e){g[e]=n})},a.listLanguages=function(){return u(N)},a.getLanguage=S,a.autoDetection=s,a.inherit=l,a.IR=a.IDENT_RE="[a-zA-Z]\\w*",a.UIR=a.UNDERSCORE_IDENT_RE="[a-zA-Z_]\\w*",a.NR=a.NUMBER_RE="\\b\\d+(\\.\\d+)?",a.CNR=a.C_NUMBER_RE="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",a.BNR=a.BINARY_NUMBER_RE="\\b(0b[01]+)",a.RSR=a.RE_STARTERS_RE="!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",a.BE=a.BACKSLASH_ESCAPE={b:"\\\\[\\s\\S]",r:0},a.ASM=a.APOS_STRING_MODE={cN:"string",b:"'",e:"'",i:"\\n",c:[a.BE]},a.QSM=a.QUOTE_STRING_MODE={cN:"string",b:'"',e:'"',i:"\\n",c:[a.BE]},a.PWM=a.PHRASAL_WORDS_MODE={b:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},a.C=a.COMMENT=function(e,n,t){var r=a.inherit({cN:"comment",b:e,e:n,c:[]},t||{});return r.c.push(a.PWM),r.c.push({cN:"doctag",b:"(?:TODO|FIXME|NOTE|BUG|XXX):",r:0}),r},a.CLCM=a.C_LINE_COMMENT_MODE=a.C("//","$"),a.CBCM=a.C_BLOCK_COMMENT_MODE=a.C("/\\*","\\*/"),a.HCM=a.HASH_COMMENT_MODE=a.C("#","$"),a.NM=a.NUMBER_MODE={cN:"number",b:a.NR,r:0},a.CNM=a.C_NUMBER_MODE={cN:"number",b:a.CNR,r:0},a.BNM=a.BINARY_NUMBER_MODE={cN:"number",b:a.BNR,r:0},a.CSSNM=a.CSS_NUMBER_MODE={cN:"number",b:a.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0},a.RM=a.REGEXP_MODE={cN:"regexp",b:/\//,e:/\/[gimuy]*/,i:/\n/,c:[a.BE,{b:/\[/,e:/\]/,r:0,c:[a.BE]}]},a.TM=a.TITLE_MODE={cN:"title",b:a.IR,r:0},a.UTM=a.UNDERSCORE_TITLE_MODE={cN:"title",b:a.UIR,r:0},a.METHOD_GUARD={b:"\\.\\s*"+a.UIR,r:0},a});hljs.registerLanguage("python",function(e){var r={keyword:"and elif is global as in if from raise for except finally print import pass return exec else break not with class assert yield try while continue del or def lambda async await nonlocal|10",built_in:"Ellipsis NotImplemented",literal:"False None True"},b={cN:"meta",b:/^(>>>|\.\.\.) /},c={cN:"subst",b:/\{/,e:/\}/,k:r,i:/#/},a={cN:"string",c:[e.BE],v:[{b:/(u|b)?r?'''/,e:/'''/,c:[e.BE,b],r:10},{b:/(u|b)?r?"""/,e:/"""/,c:[e.BE,b],r:10},{b:/(fr|rf|f)'''/,e:/'''/,c:[e.BE,b,c]},{b:/(fr|rf|f)"""/,e:/"""/,c:[e.BE,b,c]},{b:/(u|r|ur)'/,e:/'/,r:10},{b:/(u|r|ur)"/,e:/"/,r:10},{b:/(b|br)'/,e:/'/},{b:/(b|br)"/,e:/"/},{b:/(fr|rf|f)'/,e:/'/,c:[e.BE,c]},{b:/(fr|rf|f)"/,e:/"/,c:[e.BE,c]},e.ASM,e.QSM]},i={cN:"number",r:0,v:[{b:e.BNR+"[lLjJ]?"},{b:"\\b(0o[0-7]+)[lLjJ]?"},{b:e.CNR+"[lLjJ]?"}]},l={cN:"params",b:/\(/,e:/\)/,c:["self",b,i,a]};return c.c=[a,i,b],{aliases:["py","gyp","ipython"],k:r,i:/(<\/|->|\?)|=>/,c:[b,i,a,e.HCM,{v:[{cN:"function",bK:"def"},{cN:"class",bK:"class"}],e:/:/,i:/[${=;\n,]/,c:[e.UTM,l,{b:/->/,eW:!0,k:"None"}]},{cN:"meta",b:/^[\t ]*@/,e:/$/},{b:/\b(print|exec)\(/}]}});hljs.registerLanguage("xml",function(s){var e={eW:!0,i:/`]+/}]}]}]};return{aliases:["html","xhtml","rss","atom","xjb","xsd","xsl","plist"],cI:!0,c:[{cN:"meta",b:"",r:10,c:[{b:"\\[",e:"\\]"}]},s.C("\x3c!--","--\x3e",{r:10}),{b:"<\\!\\[CDATA\\[",e:"\\]\\]>",r:10},{cN:"meta",b:/<\?xml/,e:/\?>/,r:10},{b:/<\?(php)?/,e:/\?>/,sL:"php",c:[{b:"/\\*",e:"\\*/",skip:!0},{b:'b"',e:'"',skip:!0},{b:"b'",e:"'",skip:!0},s.inherit(s.ASM,{i:null,cN:null,c:null,skip:!0}),s.inherit(s.QSM,{i:null,cN:null,c:null,skip:!0})]},{cN:"tag",b:"|$)",e:">",k:{name:"style"},c:[e],starts:{e:"",rE:!0,sL:["css","xml"]}},{cN:"tag",b:"|$)",e:">",k:{name:"script"},c:[e],starts:{e:"<\/script>",rE:!0,sL:["actionscript","javascript","handlebars","xml"]}},{cN:"tag",b:"",c:[{cN:"name",b:/[^\/><\s]+/,r:0},e]}]}});hljs.registerLanguage("markdown",function(e){return{aliases:["md","mkdown","mkd"],c:[{cN:"section",v:[{b:"^#{1,6}",e:"$"},{b:"^.+?\\n[=-]{2,}$"}]},{b:"<",e:">",sL:"xml",r:0},{cN:"bullet",b:"^([*+-]|(\\d+\\.))\\s+"},{cN:"strong",b:"[*_]{2}.+?[*_]{2}"},{cN:"emphasis",v:[{b:"\\*.+?\\*"},{b:"_.+?_",r:0}]},{cN:"quote",b:"^>\\s+",e:"$"},{cN:"code",v:[{b:"^```w*s*$",e:"^```s*$"},{b:"`.+?`"},{b:"^( {4}|\t)",e:"$",r:0}]},{b:"^[-\\*]{3,}",e:"$"},{b:"\\[.+?\\][\\(\\[].*?[\\)\\]]",rB:!0,c:[{cN:"string",b:"\\[",e:"\\]",eB:!0,rE:!0,r:0},{cN:"link",b:"\\]\\(",e:"\\)",eB:!0,eE:!0},{cN:"symbol",b:"\\]\\[",e:"\\]",eB:!0,eE:!0}],r:10},{b:/^\[[^\n]+\]:/,rB:!0,c:[{cN:"symbol",b:/\[/,e:/\]/,eB:!0,eE:!0},{cN:"link",b:/:\s*/,e:/$/,eB:!0}]}]}});hljs.registerLanguage("javascript",function(e){var r="[A-Za-z$_][0-9A-Za-z$_]*",t={keyword:"in of if for while finally var new function do return void else break catch instanceof with throw case default try this switch continue typeof delete let yield const export super debugger as async await static import from as",literal:"true false null undefined NaN Infinity",built_in:"eval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Error EvalError InternalError RangeError ReferenceError StopIteration SyntaxError TypeError URIError Number Math Date String RegExp Array Float32Array Float64Array Int16Array Int32Array Int8Array Uint16Array Uint32Array Uint8Array Uint8ClampedArray ArrayBuffer DataView JSON Intl arguments require module console window document Symbol Set Map WeakSet WeakMap Proxy Reflect Promise"},a={cN:"number",v:[{b:"\\b(0[bB][01]+)"},{b:"\\b(0[oO][0-7]+)"},{b:e.CNR}],r:0},n={cN:"subst",b:"\\$\\{",e:"\\}",k:t,c:[]},c={cN:"string",b:"`",e:"`",c:[e.BE,n]};n.c=[e.ASM,e.QSM,c,a,e.RM];var s=n.c.concat([e.CBCM,e.CLCM]);return{aliases:["js","jsx"],k:t,c:[{cN:"meta",r:10,b:/^\s*['"]use (strict|asm)['"]/},{cN:"meta",b:/^#!/,e:/$/},e.ASM,e.QSM,c,e.CLCM,e.CBCM,a,{b:/[{,]\s*/,r:0,c:[{b:r+"\\s*:",rB:!0,r:0,c:[{cN:"attr",b:r,r:0}]}]},{b:"("+e.RSR+"|\\b(case|return|throw)\\b)\\s*",k:"return throw case",c:[e.CLCM,e.CBCM,e.RM,{cN:"function",b:"(\\(.*?\\)|"+r+")\\s*=>",rB:!0,e:"\\s*=>",c:[{cN:"params",v:[{b:r},{b:/\(\s*\)/},{b:/\(/,e:/\)/,eB:!0,eE:!0,k:t,c:s}]}]},{b://,sL:"xml",c:[{b:/<\w+\s*\/>/,skip:!0},{b:/<\w+/,e:/(\/\w+|\w+\/)>/,skip:!0,c:[{b:/<\w+\s*\/>/,skip:!0},"self"]}]}],r:0},{cN:"function",bK:"function",e:/\{/,eE:!0,c:[e.inherit(e.TM,{b:r}),{cN:"params",b:/\(/,e:/\)/,eB:!0,eE:!0,c:s}],i:/\[|%/},{b:/\$[(.]/},e.METHOD_GUARD,{cN:"class",bK:"class",e:/[{;=]/,eE:!0,i:/[:"\[\]]/,c:[{bK:"extends"},e.UTM]},{bK:"constructor get set",e:/\{/,eE:!0}],i:/#(?!!)/}}); \ No newline at end of file diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/highlight.js.xml b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/highlight.js.xml deleted file mode 100644 index 416f79a97b8..00000000000 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/highlight.js.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - __name__ - highlight.js - - - content_type - application/javascript - - - precondition - - - - title - - - - - - -- 2.30.9 From 0f16aaa581e60a6e2891218cc16222a89c01bce8 Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Thu, 28 Mar 2019 16:19:31 +0000 Subject: [PATCH 06/28] erp5_notebook: Add a js file to init the pyodide webassembly module loading Replace the original pyodide.js --- .../erp5_notebook/custom_pyodide.js.js | 36 +++++++++++++++++++ .../erp5_notebook/custom_pyodide.js.xml | 28 +++++++++++++++ .../erp5_notebook/gadget_jsmd_eval.html.html | 2 +- .../erp5_notebook/gadget_jsmd_eval.js.js | 8 ++--- 4 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/custom_pyodide.js.js create mode 100644 bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/custom_pyodide.js.xml diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/custom_pyodide.js.js b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/custom_pyodide.js.js new file mode 100644 index 00000000000..051504fcb4f --- /dev/null +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/custom_pyodide.js.js @@ -0,0 +1,36 @@ +var initPyodide = new Promise((resolve, reject) => { + + // Loading Pyodide + let wasmURL = `pyodide.asm.wasm`; + let Module = {}; + window.Module = Module; + + let wasm_promise = WebAssembly.compileStreaming(fetch(wasmURL)); + Module.instantiateWasm = (info, receiveInstance) => { + wasm_promise.then(module => WebAssembly.instantiate(module, info)) + .then(instance => receiveInstance(instance)); + return {}; + }; + + var postRunPromise = new Promise((resolve, reject) => { + Module.postRun = () => { + resolve(); + }; + }); + + Promise.all([ postRunPromise, ]).then(() => resolve()); + + let data_script = document.createElement('script'); + data_script.src = `pyodide.asm.data.js`; + data_script.onload = (event) => { + let script = document.createElement('script'); + script.src = `pyodide.asm.js`; + script.onload = () => { + window.pyodide = pyodide(Module); + }; + document.head.appendChild(script); + }; + + document.head.appendChild(data_script); +}); +initPyodide diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/custom_pyodide.js.xml b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/custom_pyodide.js.xml new file mode 100644 index 00000000000..550360aaf2e --- /dev/null +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/custom_pyodide.js.xml @@ -0,0 +1,28 @@ + + + + + + + + + + __name__ + custom_pyodide.js + + + content_type + application/javascript + + + precondition + + + + title + + + + + + diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.html.html b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.html.html index 437944bedb3..89c7f249163 100644 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.html.html +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.html.html @@ -11,7 +11,7 @@ - + diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js index 658c0d10fa7..331a9ca2c8f 100644 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js @@ -1,6 +1,6 @@ -/*global window, console, RSVP, document, URL, eval, XMLHttpRequest, marked, pyodide hljs */ +/*global window, console, RSVP, document, URL, eval, XMLHttpRequest, marked, pyodide */ /*jslint nomen: true, indent: 2, maxerr: 3 */ -(function (window, languagePluginLoader) { +(function (window, initPyodide) { "use strict"; var IODide = function createIODide() { @@ -330,7 +330,7 @@ queue = new RSVP.Queue(); queue.push(function () { - return languagePluginLoader; + return initPyodide; }); for (i = 0; i < len; i += 1) { queue.push(deferCellExecution(cell_list[i])); @@ -352,4 +352,4 @@ }, false); -}(window, languagePluginLoader)); \ No newline at end of file +}(window, initPyodide)); \ No newline at end of file -- 2.30.9 From 2ddf2d6af946ccd293e2cb78dc29e9709f8f2636 Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Mon, 1 Apr 2019 08:09:39 +0000 Subject: [PATCH 07/28] erp5_notebook: Remove independent custom_pyodide.js file Merge the code to gadget_jsmd_eval.js --- .../erp5_notebook/gadget_jsmd_eval.html.html | 1 - .../erp5_notebook/gadget_jsmd_eval.js.js | 113 ++++++++++++++---- 2 files changed, 92 insertions(+), 22 deletions(-) diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.html.html b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.html.html index 89c7f249163..0a5aa4de163 100644 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.html.html +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.html.html @@ -11,7 +11,6 @@ - diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js index 331a9ca2c8f..c35f3d38862 100644 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js @@ -1,6 +1,6 @@ /*global window, console, RSVP, document, URL, eval, XMLHttpRequest, marked, pyodide */ /*jslint nomen: true, indent: 2, maxerr: 3 */ -(function (window, initPyodide) { +(function (window) { "use strict"; var IODide = function createIODide() { @@ -11,13 +11,38 @@ this._line_list = line_list; }, split_line_regex = /[\r\n|\n|\r]/, - cell_type_regexp = /^\%\% (\w+)$/; + cell_type_regexp = /^\%\% (\w+)$/, + is_pyodide_loaded = false; - window.iodide = new IODide(); + window.xiodide = new IODide(); IODide.prototype.addOutputHandler = function () { return; }; + var Module = {}; + var initPyodide = new Promise((resolve, reject) => { + var postRunPromise = new Promise((resolve, reject) => { + Module.postRun = () => { + resolve(); + }; + }); + + Promise.all([ postRunPromise, ]).then(() => resolve()); + + let data_script = document.createElement('script'); + data_script.src = `pyodide.asm.data.js`; + + data_script.onload = (event) => { + let script = document.createElement('script'); + script.src = `pyodide.asm.js`; + script.onload = () => { + window.pyodide = pyodide(Module); + }; + document.head.appendChild(script); + }; + + document.head.appendChild(data_script); + }); // Copied from jio function ajax(param) { @@ -254,22 +279,30 @@ }); } + function loadPyodide() { + let wasm_promise = WebAssembly.compileStreaming(fetch(`pyodide.asm.wasm`)); + Module.instantiateWasm = function (info, receiveInstance) { + wasm_promise + .then(module => WebAssembly.instantiate(module, info)) + .then(instance => receiveInstance(instance)); + return {}; + }; + } + function executePyCell(line_list) { - return new RSVP.Promise(function (resolve, reject) { - var result_text, code_text = line_list.join('\n'); - try { - result_text = pyodide.runPython(line_list.join('\n')); - } catch (e) { - result_text = e.message; - } + var result_text, code_text = line_list.join('\n'); - if (typeof(result_text) === 'undefined') { - result_text = 'undefined'; - } + try { + result_text = pyodide.runPython(line_list.join('\n')); + } catch (e) { + result_text = e.message; + } - renderCodeblock(result_text, 'python'); - resolve(); - }); + if (typeof(result_text) === 'undefined') { + result_text = 'undefined'; + } + + renderCodeblock(result_text, 'python'); } function renderCodeblock(result_text, language) { @@ -309,7 +342,48 @@ return executeCssCell(cell._line_list); } if (cell._type === 'py') { - return executePyCell(cell._line_list); + console.log("Py cell"); + + console.log(is_pyodide_loaded); + var queue = new RSVP.Queue(); + + if (!is_pyodide_loaded) { + console.log("Loading pyodide"); + queue.push(function() { + console.log("Loading webassembly module"); + return loadPyodide(); + }) + .push(function () { + window.Module = Module; + console.log("WIndow Module"); + console.log(window.Module); + console.log("Module"); + console.log(Module); + }) + .push(function () { + console.log("Prepare enter initPyodide"); + return initPyodide; + }); + is_pyodide_loaded = true; + /* + queue.push(function () { + console.log("Loading pyodide.asm.data.js"); + return loadJSResource(`pyodide.asm.data.js`); + });*/ + /* + queue.push(function () { + console.log("Loading pyodide.asm.js"); + return loadJSResource('pyodide.asm.js'); + }); + */ + } + console.log("Fuck!"); + queue.push(function () { + console.log("Executing Python cell"); + console.log(window.pyodide); + return executePyCell(cell._line_list); + }); + return queue; } return executeUnknownCellType(cell); } @@ -329,9 +403,6 @@ i, queue = new RSVP.Queue(); - queue.push(function () { - return initPyodide; - }); for (i = 0; i < len; i += 1) { queue.push(deferCellExecution(cell_list[i])); } @@ -352,4 +423,4 @@ }, false); -}(window, initPyodide)); \ No newline at end of file +}(window)); \ No newline at end of file -- 2.30.9 From 23e13f5cc49179fa7d3cc72be66681cea5093ed8 Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Mon, 1 Apr 2019 08:18:20 +0000 Subject: [PATCH 08/28] erp5_notebook: Remove custom_pyodide.js --- .../erp5_notebook/custom_pyodide.js.js | 36 ------------------- .../erp5_notebook/custom_pyodide.js.xml | 28 --------------- 2 files changed, 64 deletions(-) delete mode 100644 bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/custom_pyodide.js.js delete mode 100644 bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/custom_pyodide.js.xml diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/custom_pyodide.js.js b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/custom_pyodide.js.js deleted file mode 100644 index 051504fcb4f..00000000000 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/custom_pyodide.js.js +++ /dev/null @@ -1,36 +0,0 @@ -var initPyodide = new Promise((resolve, reject) => { - - // Loading Pyodide - let wasmURL = `pyodide.asm.wasm`; - let Module = {}; - window.Module = Module; - - let wasm_promise = WebAssembly.compileStreaming(fetch(wasmURL)); - Module.instantiateWasm = (info, receiveInstance) => { - wasm_promise.then(module => WebAssembly.instantiate(module, info)) - .then(instance => receiveInstance(instance)); - return {}; - }; - - var postRunPromise = new Promise((resolve, reject) => { - Module.postRun = () => { - resolve(); - }; - }); - - Promise.all([ postRunPromise, ]).then(() => resolve()); - - let data_script = document.createElement('script'); - data_script.src = `pyodide.asm.data.js`; - data_script.onload = (event) => { - let script = document.createElement('script'); - script.src = `pyodide.asm.js`; - script.onload = () => { - window.pyodide = pyodide(Module); - }; - document.head.appendChild(script); - }; - - document.head.appendChild(data_script); -}); -initPyodide diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/custom_pyodide.js.xml b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/custom_pyodide.js.xml deleted file mode 100644 index 550360aaf2e..00000000000 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/custom_pyodide.js.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - __name__ - custom_pyodide.js - - - content_type - application/javascript - - - precondition - - - - title - - - - - - -- 2.30.9 From 5f0fdf3fda26cc8787a31d008eb20353d59ea70d Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Mon, 1 Apr 2019 14:59:10 +0000 Subject: [PATCH 09/28] erp5_notebook: Refine the pyodide initialization --- .../erp5_notebook/gadget_jsmd_eval.js.js | 84 +++++++------------ 1 file changed, 32 insertions(+), 52 deletions(-) diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js index c35f3d38862..fcd9ef4018a 100644 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js @@ -20,29 +20,6 @@ return; }; var Module = {}; - var initPyodide = new Promise((resolve, reject) => { - var postRunPromise = new Promise((resolve, reject) => { - Module.postRun = () => { - resolve(); - }; - }); - - Promise.all([ postRunPromise, ]).then(() => resolve()); - - let data_script = document.createElement('script'); - data_script.src = `pyodide.asm.data.js`; - - data_script.onload = (event) => { - let script = document.createElement('script'); - script.src = `pyodide.asm.js`; - script.onload = () => { - window.pyodide = pyodide(Module); - }; - document.head.appendChild(script); - }; - - document.head.appendChild(data_script); - }); // Copied from jio function ajax(param) { @@ -280,13 +257,14 @@ } function loadPyodide() { - let wasm_promise = WebAssembly.compileStreaming(fetch(`pyodide.asm.wasm`)); - Module.instantiateWasm = function (info, receiveInstance) { - wasm_promise - .then(module => WebAssembly.instantiate(module, info)) - .then(instance => receiveInstance(instance)); - return {}; - }; + let wasm_promise = WebAssembly.compileStreaming(fetch(`pyodide.asm.wasm`)); + Module.instantiateWasm = function (info, receiveInstance) { + wasm_promise + .then(module => WebAssembly.instantiate(module, info)) + .then(instance => receiveInstance(instance)); + return {}; + }; + window.Module = Module; } function executePyCell(line_list) { @@ -321,6 +299,19 @@ } } + function pyodideSetting() { + return new RSVP.Promise(function (resolve, reject) { + window.pyodide = pyodide(Module); + var postRunPromise = new Promise((resolve, reject) => { + Module.postRun = () => { + resolve(); + }; + }); + console.log("Setting postRun"); + Promise.all([ postRunPromise, ]).then(() => resolve()); + }); + } + function executeCell(cell) { if (cell._type === 'raw') { // Do nothing... @@ -352,38 +343,27 @@ queue.push(function() { console.log("Loading webassembly module"); return loadPyodide(); - }) - .push(function () { - window.Module = Module; - console.log("WIndow Module"); - console.log(window.Module); - console.log("Module"); - console.log(Module); - }) - .push(function () { - console.log("Prepare enter initPyodide"); - return initPyodide; - }); - is_pyodide_loaded = true; - /* - queue.push(function () { + }) + .push(function () { console.log("Loading pyodide.asm.data.js"); return loadJSResource(`pyodide.asm.data.js`); - });*/ - /* - queue.push(function () { + }) + .push(function () { console.log("Loading pyodide.asm.js"); return loadJSResource('pyodide.asm.js'); + }) + .push(function () { + console.log("Prepare to set postRun and pyodide"); + return pyodideSetting(); }); - */ + is_pyodide_loaded = true; } console.log("Fuck!"); queue.push(function () { console.log("Executing Python cell"); - console.log(window.pyodide); return executePyCell(cell._line_list); - }); - return queue; + }); + return queue; } return executeUnknownCellType(cell); } -- 2.30.9 From 515c3a845f2b00e2611d7c3b096203cad5dec76a Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Wed, 3 Apr 2019 11:46:17 +0200 Subject: [PATCH 10/28] erp5_notebook: Use RSVP.defer instead use Promise directly --- .../erp5_notebook/gadget_jsmd_eval.js.js | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js index fcd9ef4018a..6142ebdaeeb 100644 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js @@ -300,16 +300,18 @@ } function pyodideSetting() { - return new RSVP.Promise(function (resolve, reject) { - window.pyodide = pyodide(Module); - var postRunPromise = new Promise((resolve, reject) => { - Module.postRun = () => { - resolve(); - }; - }); - console.log("Setting postRun"); - Promise.all([ postRunPromise, ]).then(() => resolve()); + window.pyodide = pyodide(Module); + var defer = RSVP.defer(), promise=defer.promise; + console.log("Setting postRun"); + window.pyodide.loadPackage = pyodideLoadPackage; + + Module.postRun = defer.resolve; + promise.then(function() { + console.log("postRun get called"); }); + + console.log("Setting postRun finished"); + return defer.promise; } function executeCell(cell) { -- 2.30.9 From 9c428be4d894811d8e70607f39c51bb229236dd0 Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Wed, 3 Apr 2019 16:21:59 +0000 Subject: [PATCH 11/28] erp5_notebook: Support standard pyodide notebook grammar Simply ignore the section "meta" and "plugin", support "%%code {"language" : "py"}" instead "%% py" --- .../erp5_notebook/gadget_jsmd_eval.js.js | 126 ++++++++++-------- 1 file changed, 70 insertions(+), 56 deletions(-) diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js index 6142ebdaeeb..277125c6e92 100644 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js @@ -1,4 +1,4 @@ -/*global window, console, RSVP, document, URL, eval, XMLHttpRequest, marked, pyodide */ +/*global window, console, RSVP, document, URL, eval, XMLHttpRequest, marked, pyodide, WebAssembly, fetch*/ /*jslint nomen: true, indent: 2, maxerr: 3 */ (function (window) { "use strict"; @@ -11,15 +11,16 @@ this._line_list = line_list; }, split_line_regex = /[\r\n|\n|\r]/, - cell_type_regexp = /^\%\% (\w+)$/, - is_pyodide_loaded = false; + cell_type_regexp = /^\%\% (\w+)\b/, + language_type_regexp = /\{[\S\s]+\}/, + is_pyodide_loaded = false, + Module = {}; - window.xiodide = new IODide(); + window.iodide = new IODide(); IODide.prototype.addOutputHandler = function () { return; }; - var Module = {}; // Copied from jio function ajax(param) { @@ -71,6 +72,7 @@ len = line_list.length, current_line, current_type, + language_type, current_text_list, next_type, cell_list = []; @@ -87,6 +89,15 @@ next_type = current_line.match(cell_type_regexp); if (next_type) { // New type detexted + if (next_type[1] === 'code') { + // language detected + try { + language_type = JSON.parse(current_line.match(language_type_regexp)).language; + } catch (e) { + throw e; + } + next_type[1] = next_type[1] + '_' + language_type; + } pushNewCell(); current_type = next_type; current_text_list = []; @@ -256,37 +267,24 @@ }); } - function loadPyodide() { - let wasm_promise = WebAssembly.compileStreaming(fetch(`pyodide.asm.wasm`)); - Module.instantiateWasm = function (info, receiveInstance) { - wasm_promise - .then(module => WebAssembly.instantiate(module, info)) - .then(instance => receiveInstance(instance)); - return {}; - }; - window.Module = Module; - } - - function executePyCell(line_list) { - var result_text, code_text = line_list.join('\n'); - - try { - result_text = pyodide.runPython(line_list.join('\n')); - } catch (e) { - result_text = e.message; - } - - if (typeof(result_text) === 'undefined') { - result_text = 'undefined'; - } - - renderCodeblock(result_text, 'python'); + function loadPyodide(info, receiveInstance) { + var queue = new RSVP.Queue(); + queue.push(function () { + return WebAssembly.compileStreaming(fetch("pyodide.asm.wasm")); + }) + .push(function (module) { + return WebAssembly.instantiate(module, info); + }) + .push(function (instance) { + return receiveInstance(instance); + }); + return queue; } - function renderCodeblock(result_text, language) { + function renderCodeblock(result_text) { var div = document.createElement('div'), - pre = document.createElement('pre'), - result = document.createElement('code'); + pre = document.createElement('pre'), + result = document.createElement('code'); div.style.border = '1px solid #C3CCD0'; div.style.margin = '40px 10px'; div.style.paddingLeft = '10px'; @@ -299,23 +297,32 @@ } } + function executePyCell(line_list) { + var result_text, code_text = line_list.join('\n'); + + try { + result_text = pyodide.runPython(code_text); + } catch (e) { + result_text = e.message; + } + + renderCodeblock(result_text, 'python'); + } + function pyodideSetting() { window.pyodide = pyodide(Module); - var defer = RSVP.defer(), promise=defer.promise; - console.log("Setting postRun"); - window.pyodide.loadPackage = pyodideLoadPackage; + var defer = RSVP.defer(), promise = defer.promise; Module.postRun = defer.resolve; - promise.then(function() { + promise.then(function () { console.log("postRun get called"); }); - console.log("Setting postRun finished"); return defer.promise; } function executeCell(cell) { - if (cell._type === 'raw') { + if (['raw', 'meta', 'plugin'].indexOf(cell._type) !== -1) { // Do nothing... return; } @@ -334,30 +341,37 @@ if (cell._type === 'css') { return executeCssCell(cell._line_list); } - if (cell._type === 'py') { - console.log("Py cell"); + if (cell._type === 'code_py') { + if (cell._line_list.length === 0) { + // empty block, do nothing. + return; + } - console.log(is_pyodide_loaded); var queue = new RSVP.Queue(); if (!is_pyodide_loaded) { console.log("Loading pyodide"); - queue.push(function() { + queue.push(function () { console.log("Loading webassembly module"); - return loadPyodide(); - }) - .push(function () { - console.log("Loading pyodide.asm.data.js"); - return loadJSResource(`pyodide.asm.data.js`); + Module.instantiateWasm = loadPyodide; + window.Module = Module; }) - .push(function () { - console.log("Loading pyodide.asm.js"); - return loadJSResource('pyodide.asm.js'); - }) - .push(function () { - console.log("Prepare to set postRun and pyodide"); - return pyodideSetting(); - }); + .push(function () { + console.log("Loading pyodide.asm.data.js"); + return loadJSResource('pyodide.asm.data.js'); + }) + .push(function () { + console.log("Loading pyodide.asm.js"); + return loadJSResource('pyodide.asm.js'); + }) + .push(function () { + console.log("Delay the execution"); + return RSVP.delay(); + }) + .push(function () { + console.log("Prepare to set postRun and pyodide"); + return pyodideSetting(); + }); is_pyodide_loaded = true; } console.log("Fuck!"); -- 2.30.9 From b9f825f3945e020991e8eccf268870c76de4c16b Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Thu, 4 Apr 2019 09:29:15 +0000 Subject: [PATCH 12/28] erp5_notebook: If the Python statements have no output, then don't display anything --- .../portal_skins/erp5_notebook/gadget_jsmd_eval.js.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js index 277125c6e92..45723cf29aa 100644 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js @@ -289,7 +289,7 @@ div.style.margin = '40px 10px'; div.style.paddingLeft = '10px'; - if (result_text !== 'undefined') { + if (result_text !== undefined) { result.innerHTML = result_text; pre.appendChild(result); div.appendChild(pre); @@ -299,13 +299,11 @@ function executePyCell(line_list) { var result_text, code_text = line_list.join('\n'); - try { result_text = pyodide.runPython(code_text); } catch (e) { result_text = e.message; } - renderCodeblock(result_text, 'python'); } @@ -364,10 +362,6 @@ console.log("Loading pyodide.asm.js"); return loadJSResource('pyodide.asm.js'); }) - .push(function () { - console.log("Delay the execution"); - return RSVP.delay(); - }) .push(function () { console.log("Prepare to set postRun and pyodide"); return pyodideSetting(); -- 2.30.9 From a8ca17dd0421ff46be477494b9e4630233f17c62 Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Thu, 4 Apr 2019 10:18:25 +0000 Subject: [PATCH 13/28] erp5_notebook: Remove error handling, let the notebook failed asap --- .../erp5_notebook/gadget_jsmd_eval.js.js | 25 +++---------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js index 45723cf29aa..09cdc6f7322 100644 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js @@ -91,11 +91,7 @@ // New type detexted if (next_type[1] === 'code') { // language detected - try { - language_type = JSON.parse(current_line.match(language_type_regexp)).language; - } catch (e) { - throw e; - } + language_type = JSON.parse(current_line.match(language_type_regexp)).language; next_type[1] = next_type[1] + '_' + language_type; } pushNewCell(); @@ -299,12 +295,8 @@ function executePyCell(line_list) { var result_text, code_text = line_list.join('\n'); - try { - result_text = pyodide.runPython(code_text); - } catch (e) { - result_text = e.message; - } - renderCodeblock(result_text, 'python'); + result_text = pyodide.runPython(code_text); + renderCodeblock(result_text); } function pyodideSetting() { @@ -350,27 +342,21 @@ if (!is_pyodide_loaded) { console.log("Loading pyodide"); queue.push(function () { - console.log("Loading webassembly module"); Module.instantiateWasm = loadPyodide; window.Module = Module; }) .push(function () { - console.log("Loading pyodide.asm.data.js"); return loadJSResource('pyodide.asm.data.js'); }) .push(function () { - console.log("Loading pyodide.asm.js"); return loadJSResource('pyodide.asm.js'); }) .push(function () { - console.log("Prepare to set postRun and pyodide"); return pyodideSetting(); }); is_pyodide_loaded = true; } - console.log("Fuck!"); queue.push(function () { - console.log("Executing Python cell"); return executePyCell(cell._line_list); }); return queue; @@ -401,11 +387,6 @@ console.info('JSMD executed.'); }, function (error) { console.error(error); - // do not print the error page with a non-styled pre tag - // the Python error message will be displayed along with Python source code in above - if (error.message.startsWith('Traceback')) { - return; - } var pre = document.createElement('pre'); pre.textContent = error; document.body.appendChild(pre); -- 2.30.9 From 26929ed6e6bcaa48b73d36683a0336df6639879c Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Thu, 4 Apr 2019 16:10:08 +0000 Subject: [PATCH 14/28] erp5_notebook: Revert the changes in pyodide.js We don't use pyodide.js anymore --- .../SkinTemplateItem/portal_skins/erp5_notebook/pyodide.js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/pyodide.js.js b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/pyodide.js.js index 9feac7db959..cee7cb1e3e3 100644 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/pyodide.js.js +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/pyodide.js.js @@ -108,7 +108,7 @@ var languagePluginLoader = new Promise((resolve, reject) => { }); if (window.iodide !== undefined) { - // window.iodide.evalQueue.await([ promise ]); + window.iodide.evalQueue.await([ promise ]); } return promise; -- 2.30.9 From bf37ed8e2f3259b8bf55179bf4a6fccd474ea85b Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Fri, 5 Apr 2019 10:45:58 +0200 Subject: [PATCH 15/28] erp5_notebook: Add iodide.output --- .../erp5_notebook/gadget_jsmd_eval.js.js | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js index 09cdc6f7322..6799ecbaf39 100644 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js @@ -2,9 +2,41 @@ /*jslint nomen: true, indent: 2, maxerr: 3 */ (function (window) { "use strict"; - + function sideEffectDiv(sideEffectClass, reportSideEffect) { + // appends a side effect div to the side effect area + var div = document.createElement("div"); + div.setAttribute("class", sideEffectClass); + if (reportSideEffect === false) { + div.setAttribute("style", "display:"); + } + document.body.appendChild(div); + return div; + } var IODide = function createIODide() { - return; + var iodide = { + addOutputHandler: function (renderer) { + // TODO: seems this function was deprecated... + }, + output: { + text: (s, reportSideEffect = false) => { + console.log("Inside output.text"); + console.log(s); + for (const line of s.toString().split("\n")) { + const div = sideEffectDiv("side-effect-print", reportSideEffect); + div.innerText = line; + } + }, + element: (nodeType, reportSideEffect = true) => { + console.log("Inside output.element"); + const div = sideEffectDiv("side-effect-element", reportSideEffect); + const node = document.createElement(nodeType); + div.append(node); + console.log(node); + return node; + } + } + }; + return iodide; }, JSMDCell = function createJSMDCell(type, line_list) { this._type = type; -- 2.30.9 From e8cfcaf016549fc403566159804adbd843bc8339 Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Fri, 5 Apr 2019 10:50:21 +0200 Subject: [PATCH 16/28] [WIP]erp5_notebook: Add code for load Python extension --- .../erp5_notebook/gadget_jsmd_eval.js.js | 117 ++++++++++++++++-- 1 file changed, 107 insertions(+), 10 deletions(-) diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js index 6799ecbaf39..7ef1697c3b1 100644 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js @@ -38,18 +38,25 @@ }; return iodide; }, - JSMDCell = function createJSMDCell(type, line_list) { - this._type = type; - this._line_list = line_list; - }, - split_line_regex = /[\r\n|\n|\r]/, - cell_type_regexp = /^\%\% (\w+)\b/, - language_type_regexp = /\{[\S\s]+\}/, - is_pyodide_loaded = false, - Module = {}; - + JSMDCell = function createJSMDCell(type, line_list) { + this._type = type; + this._line_list = line_list; + }, + split_line_regex = /[\r\n|\n|\r]/, + cell_type_regexp = /^\%\% (\w+)\b/, + language_type_regexp = /\{[\S\s]+\}/, + is_pyodide_loaded = false, + Module = {}, + packages, + loadedPackages = new Array(), + // Regexp for validating package name and URI + package_name_regexp = '[a-z0-9_][a-z0-9_\-]*', + package_uri_regexp = new RegExp('^https?://.*?(' + package_name_regexp + ').js$', 'i'); + + package_name_regexp = new RegExp('^' + package_name_regexp + '$', 'i'); window.iodide = new IODide(); + IODide.prototype.addOutputHandler = function () { return; }; @@ -97,6 +104,96 @@ }); } + // Pyodide package loading + function _uri_to_package_name(package_uri) { + // Generate a unique package name from URI + if (package_name_regexp.test(package_uri)) { + return package_uri; + } else if (package_uri_regexp.test(package_uri)) { + let match = package_uri_regexp.exec(package_uri); + // Get the regexp group corresponding to the package name + return match[1]; + } else { + return null; + } + } + + function pyodideLoadPackage(names) { + // DFS to find all dependencies of the requested packages + let packages = window.pyodide.packages.dependencies; + let queue = new Array(names); + let toLoad = new Array(); + while (queue.length) { + let package_uri = queue.pop(); + + const package_name = _uri_to_package_name(package_uri); + + if (package_name == null) { + throw new Error(`Invalid package name or URI '${package_uri}'`); + } else if (package_name == package_uri) { + package_uri = 'default channel'; + } + + console.log(`Loading ${package_name} from ${package_uri}`); + + if (package_name in loadedPackages) { + if (package_uri != loadedPackages[package_name]) { + throw new Error( + `URI mismatch, attempting to load package ` + + `${package_name} from ${package_uri} while it is already ` + + `loaded from ${loadedPackages[package_name]}!`); + } + } else { + toLoad[package_name] = package_uri; + if (packages.hasOwnProperty(package_name)) { + packages[package_name].forEach((subpackage) => { + if (!(subpackage in loadedPackages) && !(subpackage in toLoad)) { + queue.push(subpackage); + } + }); + } else { + console.log(`Unknown package '${package_name}'`); + } + } + } + + let promise = new Promise((resolve, reject) => { + if (Object.keys(toLoad).length === 0) { + resolve('No new packages to load'); + } + + pyodide.monitorRunDependencies = (n) => { + if (n === 0) { + for (let package_name in toLoad) { + loadedPackages[package_name] = toLoad[package_name]; + } + delete pyodide.monitorRunDependencies; + const packageList = Array.from(Object.keys(toLoad)).join(', '); + resolve(`Loaded ${packageList}`); + } + }; + + for (let package_name in toLoad) { + let script = document.createElement('script'); + let package_uri = toLoad[package_name]; + if (package_uri == 'default channel') { + script.src = `${package_name}.js`; + } else { + script.src = `${package_uri}`; + } + script.onerror = (e) => { reject(e); }; + document.body.appendChild(script); + } + + // We have to invalidate Python's import caches, or it won't + // see the new files. This is done here so it happens in parallel + // with the fetching over the network. + window.pyodide.runPython('import importlib as _importlib\n' + + '_importlib.invalidate_caches()\n'); + }); + return promise; + } + function parseJSMDCellList(jsmd) { // Split the text into a list of Iodide cells var line_list = jsmd.split(split_line_regex), -- 2.30.9 From 299ff77fe4da2691f29158b0420896f5c7c2973a Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Fri, 5 Apr 2019 10:51:24 +0200 Subject: [PATCH 17/28] erp5_notebook: Extract pyodide initialization code to a independent function --- .../erp5_notebook/gadget_jsmd_eval.js.js | 54 ++++++++++++++----- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js index 7ef1697c3b1..b2e6d2dc778 100644 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js @@ -423,23 +423,56 @@ } function executePyCell(line_list) { - var result_text, code_text = line_list.join('\n'); - result_text = pyodide.runPython(code_text); - renderCodeblock(result_text); + var result, code_text = line_list.join('\n'); + result = pyodide.runPython(code_text); + console.log("Result is"); + console.log(result); + renderCodeblock(result); } function pyodideSetting() { window.pyodide = pyodide(Module); + window.pyodide.loadPackage = pyodideLoadPackage; + var defer = RSVP.defer(), promise = defer.promise; Module.postRun = defer.resolve; promise.then(function () { console.log("postRun get called"); + delete window.Module; }); return defer.promise; } + function initPyodide() { + var queue = new RSVP.Queue(); + queue.push(function () { + Module.instantiateWasm = loadPyodide; + window.Module = Module; + }) + .push(function () { + return loadJSResource('pyodide.asm.data.js'); + }) + .push(function () { + return loadJSResource('pyodide.asm.js'); + }) + .push(function () { + return pyodideSetting(); + }) + .push(function () { + return fetch(`packages.json`) + }) + .push(function (response) { + return response.json(); + }) + .push(function (json) { + window.pyodide.packages = json; + return; + }); + return queue; + } + function executeCell(cell) { if (['raw', 'meta', 'plugin'].indexOf(cell._type) !== -1) { // Do nothing... @@ -471,18 +504,11 @@ if (!is_pyodide_loaded) { console.log("Loading pyodide"); queue.push(function () { - Module.instantiateWasm = loadPyodide; - window.Module = Module; + return initPyodide(); }) - .push(function () { - return loadJSResource('pyodide.asm.data.js'); - }) - .push(function () { - return loadJSResource('pyodide.asm.js'); - }) - .push(function () { - return pyodideSetting(); - }); + .push(function () { + return pyodideLoadPackage('matplotlib'); + }); is_pyodide_loaded = true; } queue.push(function () { -- 2.30.9 From 1a47bd9e934381b4e9d8bf01bd32944d08a88af6 Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Fri, 5 Apr 2019 09:01:51 +0000 Subject: [PATCH 18/28] erp5_notebook: Revert the change made by import pyodide.js --- .../portal_skins/erp5_notebook/gadget_jsmd_eval.html.html | 1 - 1 file changed, 1 deletion(-) diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.html.html b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.html.html index 0a5aa4de163..6897c1c58fe 100644 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.html.html +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.html.html @@ -12,7 +12,6 @@ - -- 2.30.9 From 88f427e14e8a2327dc8499e0b16e4c8ab869199a Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Tue, 9 Apr 2019 15:09:01 +0200 Subject: [PATCH 19/28] Amend the code to meet the JSLint requirement --- .../erp5_notebook/gadget_jsmd_eval.js.js | 179 +++++++++--------- 1 file changed, 94 insertions(+), 85 deletions(-) diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js index b2e6d2dc778..655b283c766 100644 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js @@ -2,61 +2,60 @@ /*jslint nomen: true, indent: 2, maxerr: 3 */ (function (window) { "use strict"; + function sideEffectDiv(sideEffectClass, reportSideEffect) { // appends a side effect div to the side effect area var div = document.createElement("div"); div.setAttribute("class", sideEffectClass); - if (reportSideEffect === false) { + if (reportSideEffect === undefined) { div.setAttribute("style", "display:"); } document.body.appendChild(div); return div; } + var IODide = function createIODide() { var iodide = { - addOutputHandler: function (renderer) { - // TODO: seems this function was deprecated... - }, output: { - text: (s, reportSideEffect = false) => { + text: function (s, reportSideEffect) { + var i, div, line_list; console.log("Inside output.text"); console.log(s); - for (const line of s.toString().split("\n")) { - const div = sideEffectDiv("side-effect-print", reportSideEffect); - div.innerText = line; + line_list = s.toString().split("\n"); + for (i = 0; i < line_list.length; i += 1) { + div = sideEffectDiv("side-effect-print", reportSideEffect); + div.innerText = line_list[i]; } }, - element: (nodeType, reportSideEffect = true) => { - console.log("Inside output.element"); - const div = sideEffectDiv("side-effect-element", reportSideEffect); - const node = document.createElement(nodeType); + element: function (nodeType, reportSideEffect) { + var div, node; + div = sideEffectDiv("side-effect-element", reportSideEffect); + node = document.createElement(nodeType); div.append(node); - console.log(node); return node; } } }; return iodide; }, - JSMDCell = function createJSMDCell(type, line_list) { - this._type = type; - this._line_list = line_list; - }, - split_line_regex = /[\r\n|\n|\r]/, - cell_type_regexp = /^\%\% (\w+)\b/, - language_type_regexp = /\{[\S\s]+\}/, - is_pyodide_loaded = false, - Module = {}, - packages, - loadedPackages = new Array(), - // Regexp for validating package name and URI - package_name_regexp = '[a-z0-9_][a-z0-9_\-]*', - package_uri_regexp = new RegExp('^https?://.*?(' + package_name_regexp + ').js$', 'i'); + JSMDCell = function createJSMDCell(type, line_list) { + this._type = type; + this._line_list = line_list; + }, + split_line_regex = /[\r\n|\n|\r]/, + cell_type_regexp = /^\%\% (\w+)\b/, + language_type_regexp = /\{[\S\s]+\}/, + is_pyodide_loaded = false, + Module = {}, + packages, + loadedPackages = [], + // Regexp for validating package name and URI + package_name_regexp = '[a-z0-9_][a-z0-9_\-]*', + package_uri_regexp = new RegExp('^https?://.*?(' + package_name_regexp + ').js$', 'i'); package_name_regexp = new RegExp('^' + package_name_regexp + '$', 'i'); window.iodide = new IODide(); - IODide.prototype.addOutputHandler = function () { return; }; @@ -109,79 +108,91 @@ // Generate a unique package name from URI if (package_name_regexp.test(package_uri)) { return package_uri; - } else if (package_uri_regexp.test(package_uri)) { - let match = package_uri_regexp.exec(package_uri); + } + + if (package_uri_regexp.test(package_uri)) { + var match = package_uri_regexp.exec(package_uri); // Get the regexp group corresponding to the package name return match[1]; - } else { - return null; } + + return null; } function pyodideLoadPackage(names) { // DFS to find all dependencies of the requested packages - let packages = window.pyodide.packages.dependencies; - let queue = new Array(names); - let toLoad = new Array(); + var queue, toLoad, package_uri, package_name, k, + subpackage, promise, packageList, script; + packages = window.pyodide.packages.dependencies; + queue = new Array(names); + toLoad = []; while (queue.length) { - let package_uri = queue.pop(); + package_uri = queue.pop(); + package_name = _uri_to_package_name(package_uri); - const package_name = _uri_to_package_name(package_uri); + if (package_name === null) { + throw new Error("Invalid package name or URI " + package_uri); + } - if (package_name == null) { - throw new Error(`Invalid package name or URI '${package_uri}'`); - } else if (package_name == package_uri) { + if (package_name === package_uri) { package_uri = 'default channel'; } - console.log(`Loading ${package_name} from ${package_uri}`); - + console.log("Loading " + package_name + " from " + package_uri); + console.log("Loaded packages"); + console.log(loadedPackages); if (package_name in loadedPackages) { - if (package_uri != loadedPackages[package_name]) { + if (package_uri !== loadedPackages[package_name]) { throw new Error( - `URI mismatch, attempting to load package ` + - `${package_name} from ${package_uri} while it is already ` + - `loaded from ${loadedPackages[package_name]}!`); + "URI mismatch, attempting to load package " + + package_name + " from " + package_uri + " while it is already " + + "loaded from " + loadedPackages[package_name] + " ! " + ); } } else { toLoad[package_name] = package_uri; if (packages.hasOwnProperty(package_name)) { - packages[package_name].forEach((subpackage) => { + for (k in packages[package_name]) { + subpackage = packages[package_name][k]; if (!(subpackage in loadedPackages) && !(subpackage in toLoad)) { queue.push(subpackage); } - }); + } } else { - console.log(`Unknown package '${package_name}'`); + console.log("Unknown package " + package_name); } } } - let promise = new Promise((resolve, reject) => { + promise = new RSVP.Promise(function (resolve, reject) { if (Object.keys(toLoad).length === 0) { resolve('No new packages to load'); } - pyodide.monitorRunDependencies = (n) => { + pyodide.monitorRunDependencies = function (n) { if (n === 0) { - for (let package_name in toLoad) { + for (package_name in toLoad) { loadedPackages[package_name] = toLoad[package_name]; } delete pyodide.monitorRunDependencies; - const packageList = Array.from(Object.keys(toLoad)).join(', '); - resolve(`Loaded ${packageList}`); + packageList = Array.from(Object.keys(toLoad)).join(', '); + resolve("Loaded " + packageList); } }; - for (let package_name in toLoad) { - let script = document.createElement('script'); - let package_uri = toLoad[package_name]; - if (package_uri == 'default channel') { - script.src = `${package_name}.js`; + function script_reject(e) { + reject(e); + } + + for (package_name in toLoad) { + script = document.createElement('script'); + package_uri = toLoad[package_name]; + if (package_uri === 'default channel') { + script.src = package_name + ".js"; } else { - script.src = `${package_uri}`; + script.src = package_uri; } - script.onerror = (e) => { reject(e); }; + script.onerror = script_reject; document.body.appendChild(script); } @@ -425,8 +436,6 @@ function executePyCell(line_list) { var result, code_text = line_list.join('\n'); result = pyodide.runPython(code_text); - console.log("Result is"); - console.log(result); renderCodeblock(result); } @@ -451,25 +460,25 @@ Module.instantiateWasm = loadPyodide; window.Module = Module; }) - .push(function () { - return loadJSResource('pyodide.asm.data.js'); - }) - .push(function () { - return loadJSResource('pyodide.asm.js'); - }) - .push(function () { - return pyodideSetting(); - }) - .push(function () { - return fetch(`packages.json`) - }) - .push(function (response) { - return response.json(); - }) - .push(function (json) { - window.pyodide.packages = json; - return; - }); + .push(function () { + return loadJSResource('pyodide.asm.data.js'); + }) + .push(function () { + return loadJSResource('pyodide.asm.js'); + }) + .push(function () { + return pyodideSetting(); + }) + .push(function () { + return fetch('packages.json'); + }) + .push(function (response) { + return response.json(); + }) + .push(function (json) { + window.pyodide.packages = json; + return; + }); return queue; } @@ -506,9 +515,9 @@ queue.push(function () { return initPyodide(); }) - .push(function () { - return pyodideLoadPackage('matplotlib'); - }); + .push(function () { + return pyodideLoadPackage('matplotlib'); + }); is_pyodide_loaded = true; } queue.push(function () { -- 2.30.9 From a5317aaddd6fa76e95d94ed3defc2e1a248dd70e Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Tue, 9 Apr 2019 15:09:47 +0200 Subject: [PATCH 20/28] Display the JS code reuslt if there have --- .../portal_skins/erp5_notebook/gadget_jsmd_eval.js.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js index 655b283c766..8fe814bbca8 100644 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js @@ -255,10 +255,13 @@ var text = line_list.join('\n'), pre, br, - code; + code, + result; try { - return eval.call(window, text); + result = eval.call(window, text); + renderCodeblock(result); + return result; } catch (e) { console.error(e); pre = document.createElement('pre'); @@ -487,7 +490,7 @@ // Do nothing... return; } - if (cell._type === 'js') { + if (cell._type === 'js' || cell._type === 'code_js') { return executeJSCell(cell._line_list); } if (cell._type === 'resource') { -- 2.30.9 From 8ece690c5b3df6470875c1900c24d813810f40ad Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Tue, 9 Apr 2019 16:32:02 +0000 Subject: [PATCH 21/28] erp5_notebook_test: Create ui test for testing erp5_notebook --- .../ModuleTemplateItem/notebook_module.xml | 96 + .../notebook_module/notebook_test_purejs.xml | 4169 +++++++++++++++++ .../testNotebookJSMDViewerJS.xml | 58 + .../testNotebookJSMDViewerJS.zpt | 42 + .../portal_skins/erp5_notebook_test.xml | 26 + .../Zuite_Notebook_JSMD_Viewer_JS.xml | 58 + .../Zuite_Notebook_JSMD_Viewer_JS.zpt | 16 + bt5/erp5_notebook_test/bt/dependency_list | 1 + .../bt/template_format_version | 1 + .../bt/template_keep_workflow_path_list | 1 + .../bt/template_module_id_list | 1 + bt5/erp5_notebook_test/bt/template_path_list | 2 + .../bt/template_skin_id_list | 1 + bt5/erp5_notebook_test/bt/title | 1 + 14 files changed, 4473 insertions(+) create mode 100644 bt5/erp5_notebook_test/ModuleTemplateItem/notebook_module.xml create mode 100644 bt5/erp5_notebook_test/PathTemplateItem/notebook_module/notebook_test_purejs.xml create mode 100644 bt5/erp5_notebook_test/PathTemplateItem/portal_tests/renderjs_ui_notebook_zuite/testNotebookJSMDViewerJS.xml create mode 100644 bt5/erp5_notebook_test/PathTemplateItem/portal_tests/renderjs_ui_notebook_zuite/testNotebookJSMDViewerJS.zpt create mode 100644 bt5/erp5_notebook_test/SkinTemplateItem/portal_skins/erp5_notebook_test.xml create mode 100644 bt5/erp5_notebook_test/SkinTemplateItem/portal_skins/erp5_notebook_test/Zuite_Notebook_JSMD_Viewer_JS.xml create mode 100644 bt5/erp5_notebook_test/SkinTemplateItem/portal_skins/erp5_notebook_test/Zuite_Notebook_JSMD_Viewer_JS.zpt create mode 100644 bt5/erp5_notebook_test/bt/dependency_list create mode 100644 bt5/erp5_notebook_test/bt/template_format_version create mode 100644 bt5/erp5_notebook_test/bt/template_keep_workflow_path_list create mode 100644 bt5/erp5_notebook_test/bt/template_module_id_list create mode 100644 bt5/erp5_notebook_test/bt/template_path_list create mode 100644 bt5/erp5_notebook_test/bt/template_skin_id_list create mode 100644 bt5/erp5_notebook_test/bt/title diff --git a/bt5/erp5_notebook_test/ModuleTemplateItem/notebook_module.xml b/bt5/erp5_notebook_test/ModuleTemplateItem/notebook_module.xml new file mode 100644 index 00000000000..25fda14b587 --- /dev/null +++ b/bt5/erp5_notebook_test/ModuleTemplateItem/notebook_module.xml @@ -0,0 +1,96 @@ + + notebook_module + + + Access Transient Objects + Assignee + Assignor + Associate + Auditor + Author + Manager + + + Access contents information + Assignee + Assignor + Associate + Auditor + Author + Manager + + + Access session data + Assignee + Assignor + Associate + Auditor + Author + Manager + + + Add portal content + Assignor + Author + Manager + + + Add portal folders + Assignor + Author + Manager + + + Change local roles + Assignor + Manager + + + Copy or Move + Assignee + Assignor + Associate + Auditor + Author + Manager + + + Delete objects + Assignor + Manager + + + List folder contents + Assignee + Assignor + Associate + Auditor + Author + Manager + + + Modify portal content + Assignor + Manager + + + View + Assignee + Assignor + Associate + Auditor + Manager + + + View History + Assignee + Assignor + Associate + Auditor + Author + Manager + + + Notebook Module + Notebooks + \ No newline at end of file diff --git a/bt5/erp5_notebook_test/PathTemplateItem/notebook_module/notebook_test_purejs.xml b/bt5/erp5_notebook_test/PathTemplateItem/notebook_module/notebook_test_purejs.xml new file mode 100644 index 00000000000..97172bf297f --- /dev/null +++ b/bt5/erp5_notebook_test/PathTemplateItem/notebook_module/notebook_test_purejs.xml @@ -0,0 +1,4169 @@ + + + + + + + + + + _Access_contents_information_Permission + + + Assignee + Assignor + Manager + Owner + + + + + _Add_portal_content_Permission + + + Assignee + Assignor + Manager + Owner + + + + + _Change_local_roles_Permission + + + Assignor + Manager + + + + + _Modify_portal_content_Permission + + + Assignee + Assignor + Manager + Owner + + + + + _View_Permission + + + Assignee + Assignor + Manager + Owner + + + + + content_md5 + + + + + + description + + + + + + id + notebook_test_purejs + + + language + + + + + + portal_type + Notebook + + + short_title + + + + + + text_content + %% meta\n +{\n + "title": "Lecture-3-Matplotlib",\n + "lastSaved": "2018-10-16T13:50:00.550Z",\n + "languages": {\n + "js": {\n + "pluginType": "language",\n + "languageId": "js",\n + "displayName": "Javascript",\n + "codeMirrorMode": "javascript",\n + "module": "window",\n + "evaluator": "eval",\n + "keybinding": "j",\n + "url": ""\n + },\n + "py": {\n + "languageId": "py",\n + "displayName": "python",\n + "codeMirrorMode": "python",\n + "keybinding": "p",\n + "url": "https://iodide.io/pyodide-demo/pyodide.js",\n + "module": "pyodide",\n + "evaluator": "runPython",\n + "pluginType": "language"\n + }\n + },\n + "lastExport": "2018-10-16T13:50:03.563Z"\n +}\n +\n +%% plugin\n +{\n + "languageId": "py",\n + "displayName": "python",\n + "codeMirrorMode": "python",\n + "keybinding": "p",\n + "url": "https://iodide.io/pyodide-demo/pyodide.js",\n + "module": "pyodide",\n + "evaluator": "runPython",\n + "pluginType": "language"\n +}\n +\n +%% md\n +# Notebook JSDM Viewer Test\n +\n +%% md\n +This is a sample content for check the JS section can be executed in JSMD viewer.\n +\n +%% code {"language":"js"}\n +2 + 40 + + + title + Notebook test pure js + + + workflow_history + + AAAAAAAAAAI= + + + + + + + + + + + + + data + + + + document_publication_workflow + + AAAAAAAAAAM= + + + + edit_workflow + + AAAAAAAAAAQ= + + + + processing_status_workflow + + AAAAAAAAAAU= + + + + + + + + + + + + + + + + + + + action + + + + + + actor + zope + + + comment + + + + error_message + + + + time + + + + + + + + + + + 1553080507.54 + UTC + + + + + + + validation_state + draft + + + + + + + + + + + + + AAAAAAAAAAY= + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.60196.14387.38229 + + + state + current + + + time + + + + + + + + + + + 1554822032.22 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.60196.35205.3072 + + + state + current + + + time + + + + + + + + + 1554824357.4 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.60235.19016.55125 + + + state + current + + + time + + + + + + + + + 1554826187.44 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.60265.51822.50397 + + + state + current + + + time + + + + + + + + + 1554826250.94 + UTC + + + + + + + + + + + + + + + + + + + + + action + + + + + + actor + zope + + + comment + + + + error_message + + + + external_processing_state + empty + + + serial + 0.0.0.0 + + + time + + + + + + + + + + + 1553080507.54 + UTC + + + + + + + + + + + + + + + + + AAAAAAAAAAc= + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.52956.4237.9130 + + + state + current + + + time + + + + + + + + + + + 1554387762.17 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.52958.46070.16913 + + + state + current + + + time + + + + + + + + + 1554388391.17 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.52969.12207.42649 + + + state + current + + + time + + + + + + + + + 1554388559.48 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.52971.64975.5358 + + + state + current + + + time + + + + + + + + + 1554388781.87 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.52975.45746.18261 + + + state + current + + + time + + + + + + + + + 1554389037.3 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.52979.62593.45516 + + + state + current + + + time + + + + + + + + + 1554389249.62 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.52983.32366.23552 + + + state + current + + + time + + + + + + + + + 1554390497.1 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.53004.18684.580 + + + state + current + + + time + + + + + + + + + 1554391112.35 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.53014.35345.938 + + + state + current + + + time + + + + + + + + + 1554393353.95 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.53051.58933.38161 + + + state + current + + + time + + + + + + + + + 1554466990.66 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.54279.11663.6621 + + + state + current + + + time + + + + + + + + + 1554467179.88 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.54282.21727.17561 + + + state + current + + + time + + + + + + + + + 1554468740.69 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.54308.22605.14353 + + + state + current + + + time + + + + + + + + + 1554813987.53 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.60062.30080.54647 + + + state + current + + + time + + + + + + + + + 1554814697.78 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.60074.19432.44219 + + + state + current + + + time + + + + + + + + + 1554814986.26 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.60079.6845.57497 + + + state + current + + + time + + + + + + + + + 1554822013.16 + UTC + + + + + + + + + + + + + + + + + AAAAAAAAAAg= + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.51517.25137.34372 + + + state + current + + + time + + + + + + + + + + + 1554303060.66 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.51547.734.55756 + + + state + current + + + time + + + + + + + + + 1554303110.45 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.51547.55108.45465 + + + state + current + + + time + + + + + + + + + 1554303223.38 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.51549.47393.12134 + + + state + current + + + time + + + + + + + + + 1554305708.5 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.51591.9296.60910 + + + state + current + + + time + + + + + + + + + 1554367890.94 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.52627.33813.60262 + + + state + current + + + time + + + + + + + + + 1554368098.37 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.52630.63766.31675 + + + state + current + + + time + + + + + + + + + 1554368213.08 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.52632.57987.13960 + + + state + current + + + time + + + + + + + + + 1554369119.21 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.52647.64685.5137 + + + state + current + + + time + + + + + + + + + 1554369611.8 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.52656.12893.22971 + + + state + current + + + time + + + + + + + + + 1554382924.31 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.52878.4726.35635 + + + state + current + + + time + + + + + + + + + 1554384925.54 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.52911.27901.64819 + + + state + current + + + time + + + + + + + + + 1554387126.14 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.52948.6712.2901 + + + state + current + + + time + + + + + + + + + 1554387150.54 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.52948.33364.58385 + + + state + current + + + time + + + + + + + + + 1554387338.4 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.52951.41956.59750 + + + state + current + + + time + + + + + + + + + 1554387469.27 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.52953.53827.5205 + + + state + current + + + time + + + + + + + + + 1554387603.87 + UTC + + + + + + + + + + + + + + + + + AAAAAAAAAAk= + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.41487.26138.25070 + + + state + current + + + time + + + + + + + + + + + 1553703300.43 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.41551.475.256 + + + state + current + + + time + + + + + + + + + 1553783326.31 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.42884.50596.30890 + + + state + current + + + time + + + + + + + + + 1554196262.44 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.49767.2688.38041 + + + state + current + + + time + + + + + + + + + 1554196382.25 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.49769.2463.30941 + + + state + current + + + time + + + + + + + + + 1554197839.84 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.49793.21680.62003 + + + state + current + + + time + + + + + + + + + 1554198037.96 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.49796.41475.65177 + + + state + current + + + time + + + + + + + + + 1554198045.67 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.49796.49892.18244 + + + state + current + + + time + + + + + + + + + 1554198119.94 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.49797.65478.33262 + + + state + current + + + time + + + + + + + + + 1554198235.28 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.49799.60394.53299 + + + state + current + + + time + + + + + + + + + 1554299426.39 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.51486.28840.41472 + + + state + current + + + time + + + + + + + + + 1554299473.06 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.51487.14272.57463 + + + state + current + + + time + + + + + + + + + 1554299809.37 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.51492.53928.64529 + + + state + current + + + time + + + + + + + + + 1554300000.16 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.51496.181.31470 + + + state + current + + + time + + + + + + + + + 1554300193.04 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.51499.14256.44185 + + + state + current + + + time + + + + + + + + + 1554300276.8 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.51500.40207.9233 + + + state + current + + + time + + + + + + + + + 1554301283.01 + UTC + + + + + + + + + + + + + + + + + AAAAAAAAAAo= + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.34395.33880.1553 + + + state + current + + + time + + + + + + + + + + + 1553273991.55 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.34395.56311.22818 + + + state + current + + + time + + + + + + + + + 1553274262.45 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.34400.24532.40021 + + + state + current + + + time + + + + + + + + + 1553534203.82 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.38732.47879.58999 + + + state + current + + + time + + + + + + + + + 1553608905.52 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.39977.49740.55825 + + + state + current + + + time + + + + + + + + + 1553611437.78 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.40019.63118.34662 + + + state + current + + + time + + + + + + + + + 1553611990.16 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.40029.11103.51746 + + + state + current + + + time + + + + + + + + + 1553612109.23 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.40031.10090.51404 + + + state + current + + + time + + + + + + + + + 1553612183.18 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.40032.25333.18739 + + + state + current + + + time + + + + + + + + + 1553620627.86 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.40173.8602.30771 + + + state + current + + + time + + + + + + + + + 1553621219.72 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.40182.65235.53674 + + + state + current + + + time + + + + + + + + + 1553677726.38 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.41124.50677.26692 + + + state + current + + + time + + + + + + + + + 1553678215.85 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.41132.61014.47581 + + + state + current + + + time + + + + + + + + + 1553695443.02 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.41420.3317.27255 + + + state + current + + + time + + + + + + + + + 1553695448.59 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.41420.9391.64256 + + + state + current + + + time + + + + + + + + + 1553699234.6 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.41483.15961.12817 + + + state + current + + + time + + + + + + + + + 1553699483.92 + UTC + + + + + + + + + + + + + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + error_message + + + + serial + 0.0.0.0 + + + state + current + + + time + + + + + + + + + + + 1553080507.53 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.31171.8249.43946 + + + state + current + + + time + + + + + + + + + 1553081203.89 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.31182.47955.6673 + + + state + current + + + time + + + + + + + + + 1553096428.56 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.31436.31199.49783 + + + state + current + + + time + + + + + + + + + 1553096538.85 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.31438.20595.38963 + + + state + current + + + time + + + + + + + + + 1553270409.83 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.34336.10750.64000 + + + state + current + + + time + + + + + + + + + 1553270453.21 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.34336.58123.38451 + + + state + current + + + time + + + + + + + + + 1553270551.83 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.34338.34771.55534 + + + state + current + + + time + + + + + + + + + 1553270606.2 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.34339.28631.2184 + + + state + current + + + time + + + + + + + + + 1553271689.77 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.34357.32524.64614 + + + state + current + + + time + + + + + + + + + 1553271813.27 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.34359.36343.49510 + + + state + current + + + time + + + + + + + + + 1553271972.57 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.34362.13743.11212 + + + state + current + + + time + + + + + + + + + 1553272280.78 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.34367.22703.60330 + + + state + current + + + time + + + + + + + + + 1553272455.28 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.34370.16700.29883 + + + state + current + + + time + + + + + + + + + 1553272532.75 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.34371.35785.48742 + + + state + current + + + time + + + + + + + + + 1553273645.47 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.34390.5982.58794 + + + state + current + + + time + + + + + + + + + 1553273971.01 + UTC + + + + + + + + + + + diff --git a/bt5/erp5_notebook_test/PathTemplateItem/portal_tests/renderjs_ui_notebook_zuite/testNotebookJSMDViewerJS.xml b/bt5/erp5_notebook_test/PathTemplateItem/portal_tests/renderjs_ui_notebook_zuite/testNotebookJSMDViewerJS.xml new file mode 100644 index 00000000000..e01386ddb28 --- /dev/null +++ b/bt5/erp5_notebook_test/PathTemplateItem/portal_tests/renderjs_ui_notebook_zuite/testNotebookJSMDViewerJS.xml @@ -0,0 +1,58 @@ + + + + + + + + + + _bind_names + + + + + + + + + + _asgns + + + + name_subpath + traverse_subpath + + + + + + + + + + + content_type + text/html + + + expand + 0 + + + id + testNotebookJSMDViewerJS + + + output_encoding + utf-8 + + + title + + + + + + diff --git a/bt5/erp5_notebook_test/PathTemplateItem/portal_tests/renderjs_ui_notebook_zuite/testNotebookJSMDViewerJS.zpt b/bt5/erp5_notebook_test/PathTemplateItem/portal_tests/renderjs_ui_notebook_zuite/testNotebookJSMDViewerJS.zpt new file mode 100644 index 00000000000..8cc6c1f0a2f --- /dev/null +++ b/bt5/erp5_notebook_test/PathTemplateItem/portal_tests/renderjs_ui_notebook_zuite/testNotebookJSMDViewerJS.zpt @@ -0,0 +1,42 @@ + + + +Test Notebook JSMD RenderJS UI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Test Notebook JSMD RenderJS UI
open${base_url}/web_site_module/renderjs_runner/#/notebook_module/notebook_test_purejs
waitForElementPresent//iframe
waitForElementPresent//iframe[contains(@src, 'gadget_jsmd_viewer.html')]
waitForElementPresent//iframe[contains(@src, 'gadget_jsmd_viewer.html')]//body
waitForElementPresent//iframe[contains(@src, 'gadget_jsmd_viewer.html')]//iframe/h1[contains(@text, 'Notebook')]
+ + \ No newline at end of file diff --git a/bt5/erp5_notebook_test/SkinTemplateItem/portal_skins/erp5_notebook_test.xml b/bt5/erp5_notebook_test/SkinTemplateItem/portal_skins/erp5_notebook_test.xml new file mode 100644 index 00000000000..420f49b4994 --- /dev/null +++ b/bt5/erp5_notebook_test/SkinTemplateItem/portal_skins/erp5_notebook_test.xml @@ -0,0 +1,26 @@ + + + + + + + + + + _objects + + + + + + id + erp5_notebook_test + + + title + ERP5 Notebook test + + + + + diff --git a/bt5/erp5_notebook_test/SkinTemplateItem/portal_skins/erp5_notebook_test/Zuite_Notebook_JSMD_Viewer_JS.xml b/bt5/erp5_notebook_test/SkinTemplateItem/portal_skins/erp5_notebook_test/Zuite_Notebook_JSMD_Viewer_JS.xml new file mode 100644 index 00000000000..3bd6ec7b630 --- /dev/null +++ b/bt5/erp5_notebook_test/SkinTemplateItem/portal_skins/erp5_notebook_test/Zuite_Notebook_JSMD_Viewer_JS.xml @@ -0,0 +1,58 @@ + + + + + + + + + + _bind_names + + + + + + + + + + _asgns + + + + name_subpath + traverse_subpath + + + + + + + + + + + content_type + text/html + + + expand + 0 + + + id + Zuite_Notebook_JSMD_Viewer_JS + + + output_encoding + utf-8 + + + title + + + + + + diff --git a/bt5/erp5_notebook_test/SkinTemplateItem/portal_skins/erp5_notebook_test/Zuite_Notebook_JSMD_Viewer_JS.zpt b/bt5/erp5_notebook_test/SkinTemplateItem/portal_skins/erp5_notebook_test/Zuite_Notebook_JSMD_Viewer_JS.zpt new file mode 100644 index 00000000000..5c791255dee --- /dev/null +++ b/bt5/erp5_notebook_test/SkinTemplateItem/portal_skins/erp5_notebook_test/Zuite_Notebook_JSMD_Viewer_JS.zpt @@ -0,0 +1,16 @@ + + + + + open + ${base_url}/web_site_module/renderjs_runner/#/notebook_module/notebook_test_purejs + + + + waitForTextPresent + Notebook JSDM Viewer Test + + + + \ No newline at end of file diff --git a/bt5/erp5_notebook_test/bt/dependency_list b/bt5/erp5_notebook_test/bt/dependency_list new file mode 100644 index 00000000000..34ddbac43b6 --- /dev/null +++ b/bt5/erp5_notebook_test/bt/dependency_list @@ -0,0 +1 @@ +erp5_notebook \ No newline at end of file diff --git a/bt5/erp5_notebook_test/bt/template_format_version b/bt5/erp5_notebook_test/bt/template_format_version new file mode 100644 index 00000000000..56a6051ca2b --- /dev/null +++ b/bt5/erp5_notebook_test/bt/template_format_version @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/bt5/erp5_notebook_test/bt/template_keep_workflow_path_list b/bt5/erp5_notebook_test/bt/template_keep_workflow_path_list new file mode 100644 index 00000000000..90fba4cf6a0 --- /dev/null +++ b/bt5/erp5_notebook_test/bt/template_keep_workflow_path_list @@ -0,0 +1 @@ +notebook_module/notebook_test_purejs \ No newline at end of file diff --git a/bt5/erp5_notebook_test/bt/template_module_id_list b/bt5/erp5_notebook_test/bt/template_module_id_list new file mode 100644 index 00000000000..3cc2430b48d --- /dev/null +++ b/bt5/erp5_notebook_test/bt/template_module_id_list @@ -0,0 +1 @@ +notebook_module \ No newline at end of file diff --git a/bt5/erp5_notebook_test/bt/template_path_list b/bt5/erp5_notebook_test/bt/template_path_list new file mode 100644 index 00000000000..aba4110764b --- /dev/null +++ b/bt5/erp5_notebook_test/bt/template_path_list @@ -0,0 +1,2 @@ +notebook_module/notebook_test_purejs +portal_tests/renderjs_ui_notebook_zuite/testNotebookJSMDViewerJS \ No newline at end of file diff --git a/bt5/erp5_notebook_test/bt/template_skin_id_list b/bt5/erp5_notebook_test/bt/template_skin_id_list new file mode 100644 index 00000000000..dfb2157da14 --- /dev/null +++ b/bt5/erp5_notebook_test/bt/template_skin_id_list @@ -0,0 +1 @@ +erp5_notebook_test \ No newline at end of file diff --git a/bt5/erp5_notebook_test/bt/title b/bt5/erp5_notebook_test/bt/title new file mode 100644 index 00000000000..dfb2157da14 --- /dev/null +++ b/bt5/erp5_notebook_test/bt/title @@ -0,0 +1 @@ +erp5_notebook_test \ No newline at end of file -- 2.30.9 From d787c06cb096e62e2fb84131dc47df8bc53fb4c6 Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Wed, 10 Apr 2019 10:18:39 +0000 Subject: [PATCH 22/28] erp5_notebook_test: Add test driver for notebook test --- .../notebook_module/notebook_test_purejs.xml | 92 ++++++++++++- .../testNotebookJSMDViewerJS.zpt | 19 ++- .../test.erp5.testNotebookRJS.py | 48 +++++++ .../test.erp5.testNotebookRJS.xml | 123 ++++++++++++++++++ bt5/erp5_notebook_test/bt/dependency_list | 8 +- bt5/erp5_notebook_test/bt/description | 1 + .../bt/template_test_id_list | 1 + .../bt/test_dependency_list | 1 + 8 files changed, 289 insertions(+), 4 deletions(-) create mode 100644 bt5/erp5_notebook_test/TestTemplateItem/portal_components/test.erp5.testNotebookRJS.py create mode 100644 bt5/erp5_notebook_test/TestTemplateItem/portal_components/test.erp5.testNotebookRJS.xml create mode 100644 bt5/erp5_notebook_test/bt/description create mode 100644 bt5/erp5_notebook_test/bt/template_test_id_list create mode 100644 bt5/erp5_notebook_test/bt/test_dependency_list diff --git a/bt5/erp5_notebook_test/PathTemplateItem/notebook_module/notebook_test_purejs.xml b/bt5/erp5_notebook_test/PathTemplateItem/notebook_module/notebook_test_purejs.xml index 97172bf297f..24f78a87552 100644 --- a/bt5/erp5_notebook_test/PathTemplateItem/notebook_module/notebook_test_purejs.xml +++ b/bt5/erp5_notebook_test/PathTemplateItem/notebook_module/notebook_test_purejs.xml @@ -135,7 +135,7 @@ }\n \n %% md\n -# Notebook JSDM Viewer Test\n +# Notebook JSMD Viewer Test\n \n %% md\n This is a sample content for check the JS section can be executed in JSMD viewer.\n @@ -435,6 +435,96 @@ This is a sample content for check the JS section can be executed in JSMD viewer + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.60266.55641.60484 + + + state + current + + + time + + + + + + + + + 1554889170.96 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 974.61315.33837.443 + + + state + current + + + time + + + + + + + + + 1554890435.53 + UTC + + + + + + diff --git a/bt5/erp5_notebook_test/PathTemplateItem/portal_tests/renderjs_ui_notebook_zuite/testNotebookJSMDViewerJS.zpt b/bt5/erp5_notebook_test/PathTemplateItem/portal_tests/renderjs_ui_notebook_zuite/testNotebookJSMDViewerJS.zpt index 8cc6c1f0a2f..cd8700cbc51 100644 --- a/bt5/erp5_notebook_test/PathTemplateItem/portal_tests/renderjs_ui_notebook_zuite/testNotebookJSMDViewerJS.zpt +++ b/bt5/erp5_notebook_test/PathTemplateItem/portal_tests/renderjs_ui_notebook_zuite/testNotebookJSMDViewerJS.zpt @@ -27,14 +27,29 @@ //iframe[contains(@src, 'gadget_jsmd_viewer.html')] + + selectFrame + index=0 + + + + waitForElementPresent + //body//iframe + + + + selectFrame + index=0 + + waitForElementPresent - //iframe[contains(@src, 'gadget_jsmd_viewer.html')]//body + //h1[contains(text(),'Notebook JSMD Viewer Test')] waitForElementPresent - //iframe[contains(@src, 'gadget_jsmd_viewer.html')]//iframe/h1[contains(@text, 'Notebook')] + //code[contains(text(),'42')] diff --git a/bt5/erp5_notebook_test/TestTemplateItem/portal_components/test.erp5.testNotebookRJS.py b/bt5/erp5_notebook_test/TestTemplateItem/portal_components/test.erp5.testNotebookRJS.py new file mode 100644 index 00000000000..485eb4975d4 --- /dev/null +++ b/bt5/erp5_notebook_test/TestTemplateItem/portal_components/test.erp5.testNotebookRJS.py @@ -0,0 +1,48 @@ +############################################################################## +# +# Copyright (c) 2019 Nexedi SARL and Contributors. All Rights Reserved. +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## +import unittest + +from Products.ERP5Type.tests.ERP5TypeFunctionalTestCase import ERP5TypeFunctionalTestCase + +class TestRenderJSUICore(ERP5TypeFunctionalTestCase): + foreground = 0 + run_only = "renderjs_ui_notebook_zuite" + + def getBusinessTemplateList(self): + return ( + 'erp5_web_renderjs_ui', + 'erp5_notebook', + 'erp5_notebook_test', + 'erp5_ui_test_core', + 'erp5_accounting', + 'erp5_test_result', + ) + +def test_suite(): + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestRenderJSUICore)) + return suite \ No newline at end of file diff --git a/bt5/erp5_notebook_test/TestTemplateItem/portal_components/test.erp5.testNotebookRJS.xml b/bt5/erp5_notebook_test/TestTemplateItem/portal_components/test.erp5.testNotebookRJS.xml new file mode 100644 index 00000000000..f9a255e27fc --- /dev/null +++ b/bt5/erp5_notebook_test/TestTemplateItem/portal_components/test.erp5.testNotebookRJS.xml @@ -0,0 +1,123 @@ + + + + + + + + + + _recorded_property_dict + + AAAAAAAAAAI= + + + + default_reference + testNotebookRJS + + + description + + + + + + id + test.erp5.testNotebookRJS + + + portal_type + Test Component + + + sid + + + + + + text_content_error_message + + + + + + text_content_warning_message + + + + + + version + erp5 + + + workflow_history + + AAAAAAAAAAM= + + + + + + + + + + + + + data + + + + + + + + + + + + + + + data + + + + component_validation_workflow + + AAAAAAAAAAQ= + + + + + + + + + + + + + + + + + + + action + validate + + + validation_state + validated + + + + + + + diff --git a/bt5/erp5_notebook_test/bt/dependency_list b/bt5/erp5_notebook_test/bt/dependency_list index 34ddbac43b6..1c3aa5509a5 100644 --- a/bt5/erp5_notebook_test/bt/dependency_list +++ b/bt5/erp5_notebook_test/bt/dependency_list @@ -1 +1,7 @@ -erp5_notebook \ No newline at end of file +erp5_notebook +erp5_ui_test_core +erp5_ui_test +erp5_web_renderjs_ui +erp5_gadget_interface_validator +erp5_accounting +erp5_test_result \ No newline at end of file diff --git a/bt5/erp5_notebook_test/bt/description b/bt5/erp5_notebook_test/bt/description new file mode 100644 index 00000000000..85fbc2c7d5e --- /dev/null +++ b/bt5/erp5_notebook_test/bt/description @@ -0,0 +1 @@ +Notebook renderjs test suite \ No newline at end of file diff --git a/bt5/erp5_notebook_test/bt/template_test_id_list b/bt5/erp5_notebook_test/bt/template_test_id_list new file mode 100644 index 00000000000..fa12ef60df9 --- /dev/null +++ b/bt5/erp5_notebook_test/bt/template_test_id_list @@ -0,0 +1 @@ +test.erp5.testNotebookRJS \ No newline at end of file diff --git a/bt5/erp5_notebook_test/bt/test_dependency_list b/bt5/erp5_notebook_test/bt/test_dependency_list new file mode 100644 index 00000000000..bff77e32d84 --- /dev/null +++ b/bt5/erp5_notebook_test/bt/test_dependency_list @@ -0,0 +1 @@ +erp5_full_text_mroonga_catalog \ No newline at end of file -- 2.30.9 From 505ea6dec55fa3d899d2a699f6d9615a0c9bb731 Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Wed, 10 Apr 2019 12:40:23 +0000 Subject: [PATCH 23/28] erp5_notebook_test: Test amending --- .../portal_components/test.erp5.testNotebookRJS.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bt5/erp5_notebook_test/TestTemplateItem/portal_components/test.erp5.testNotebookRJS.py b/bt5/erp5_notebook_test/TestTemplateItem/portal_components/test.erp5.testNotebookRJS.py index 485eb4975d4..291963fb134 100644 --- a/bt5/erp5_notebook_test/TestTemplateItem/portal_components/test.erp5.testNotebookRJS.py +++ b/bt5/erp5_notebook_test/TestTemplateItem/portal_components/test.erp5.testNotebookRJS.py @@ -28,7 +28,7 @@ import unittest from Products.ERP5Type.tests.ERP5TypeFunctionalTestCase import ERP5TypeFunctionalTestCase -class TestRenderJSUICore(ERP5TypeFunctionalTestCase): +class TestNotebookRJSUI(ERP5TypeFunctionalTestCase): foreground = 0 run_only = "renderjs_ui_notebook_zuite" @@ -44,5 +44,5 @@ class TestRenderJSUICore(ERP5TypeFunctionalTestCase): def test_suite(): suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(TestRenderJSUICore)) + suite.addTest(unittest.makeSuite(TestNotebookRJSUI)) return suite \ No newline at end of file -- 2.30.9 From 0a0419e9d5289527d4df9a99e32e7eadf4375844 Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Wed, 10 Apr 2019 13:09:47 +0000 Subject: [PATCH 24/28] erp5_notebook_test: Seems we don't need to add a portal_skins folder for erp5_notebook_test --- .../portal_skins/erp5_notebook_test.xml | 26 --------- .../Zuite_Notebook_JSMD_Viewer_JS.xml | 58 ------------------- .../Zuite_Notebook_JSMD_Viewer_JS.zpt | 16 ----- .../bt/template_skin_id_list | 1 - 4 files changed, 101 deletions(-) delete mode 100644 bt5/erp5_notebook_test/SkinTemplateItem/portal_skins/erp5_notebook_test.xml delete mode 100644 bt5/erp5_notebook_test/SkinTemplateItem/portal_skins/erp5_notebook_test/Zuite_Notebook_JSMD_Viewer_JS.xml delete mode 100644 bt5/erp5_notebook_test/SkinTemplateItem/portal_skins/erp5_notebook_test/Zuite_Notebook_JSMD_Viewer_JS.zpt delete mode 100644 bt5/erp5_notebook_test/bt/template_skin_id_list diff --git a/bt5/erp5_notebook_test/SkinTemplateItem/portal_skins/erp5_notebook_test.xml b/bt5/erp5_notebook_test/SkinTemplateItem/portal_skins/erp5_notebook_test.xml deleted file mode 100644 index 420f49b4994..00000000000 --- a/bt5/erp5_notebook_test/SkinTemplateItem/portal_skins/erp5_notebook_test.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - _objects - - - - - - id - erp5_notebook_test - - - title - ERP5 Notebook test - - - - - diff --git a/bt5/erp5_notebook_test/SkinTemplateItem/portal_skins/erp5_notebook_test/Zuite_Notebook_JSMD_Viewer_JS.xml b/bt5/erp5_notebook_test/SkinTemplateItem/portal_skins/erp5_notebook_test/Zuite_Notebook_JSMD_Viewer_JS.xml deleted file mode 100644 index 3bd6ec7b630..00000000000 --- a/bt5/erp5_notebook_test/SkinTemplateItem/portal_skins/erp5_notebook_test/Zuite_Notebook_JSMD_Viewer_JS.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - - - _bind_names - - - - - - - - - - _asgns - - - - name_subpath - traverse_subpath - - - - - - - - - - - content_type - text/html - - - expand - 0 - - - id - Zuite_Notebook_JSMD_Viewer_JS - - - output_encoding - utf-8 - - - title - - - - - - diff --git a/bt5/erp5_notebook_test/SkinTemplateItem/portal_skins/erp5_notebook_test/Zuite_Notebook_JSMD_Viewer_JS.zpt b/bt5/erp5_notebook_test/SkinTemplateItem/portal_skins/erp5_notebook_test/Zuite_Notebook_JSMD_Viewer_JS.zpt deleted file mode 100644 index 5c791255dee..00000000000 --- a/bt5/erp5_notebook_test/SkinTemplateItem/portal_skins/erp5_notebook_test/Zuite_Notebook_JSMD_Viewer_JS.zpt +++ /dev/null @@ -1,16 +0,0 @@ - - - - - open - ${base_url}/web_site_module/renderjs_runner/#/notebook_module/notebook_test_purejs - - - - waitForTextPresent - Notebook JSDM Viewer Test - - - - \ No newline at end of file diff --git a/bt5/erp5_notebook_test/bt/template_skin_id_list b/bt5/erp5_notebook_test/bt/template_skin_id_list deleted file mode 100644 index dfb2157da14..00000000000 --- a/bt5/erp5_notebook_test/bt/template_skin_id_list +++ /dev/null @@ -1 +0,0 @@ -erp5_notebook_test \ No newline at end of file -- 2.30.9 From f0568d35ac9561fc5bbf97942dee67a065c16444 Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Thu, 11 Apr 2019 18:01:22 +0200 Subject: [PATCH 25/28] erp5_notebook_test: Minify the test --- tests/__init__.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index 580935d622e..5c5da1aaf8c 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -35,9 +35,7 @@ class _ERP5(ERP5TypeTestSuite): component_re = re.compile(".*/([^/]+)/TestTemplateItem/portal_components" "/test\.[^.]+\.([^.]+).py$") for test_path in ( - glob('%s/product/*/tests/test*.py' % path) + - glob('%s/bt5/*/TestTemplateItem/test*.py' % path) + - glob('%s/bt5/*/TestTemplateItem/portal_components/test.*.test*.py' % path)): + glob('%s/bt5/erp5_notebook_test/TestTemplateItem/portal_components/test.*.test*.py' % path)): component_re_match = component_re.match(test_path) if component_re_match is not None: test_case = "%s:%s" % (component_re_match.group(1), -- 2.30.9 From 645cfb976f49f925fe90feb2905981ce39061d40 Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Mon, 15 Apr 2019 16:28:48 +0000 Subject: [PATCH 26/28] erp5_notebook_test: Fix: Add renderjs_ui_notebook_zuite --- .../renderjs_ui_notebook_zuite.xml | 26 +++++++++++++++++++ bt5/erp5_notebook_test/bt/template_path_list | 3 ++- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 bt5/erp5_notebook_test/PathTemplateItem/portal_tests/renderjs_ui_notebook_zuite.xml diff --git a/bt5/erp5_notebook_test/PathTemplateItem/portal_tests/renderjs_ui_notebook_zuite.xml b/bt5/erp5_notebook_test/PathTemplateItem/portal_tests/renderjs_ui_notebook_zuite.xml new file mode 100644 index 00000000000..ca0045e0cf6 --- /dev/null +++ b/bt5/erp5_notebook_test/PathTemplateItem/portal_tests/renderjs_ui_notebook_zuite.xml @@ -0,0 +1,26 @@ + + + + + + + + + + _objects + + + + + + id + renderjs_ui_notebook_zuite + + + title + + + + + + diff --git a/bt5/erp5_notebook_test/bt/template_path_list b/bt5/erp5_notebook_test/bt/template_path_list index aba4110764b..a963d0e95ea 100644 --- a/bt5/erp5_notebook_test/bt/template_path_list +++ b/bt5/erp5_notebook_test/bt/template_path_list @@ -1,2 +1,3 @@ notebook_module/notebook_test_purejs -portal_tests/renderjs_ui_notebook_zuite/testNotebookJSMDViewerJS \ No newline at end of file +portal_tests/renderjs_ui_notebook_zuite +portal_tests/renderjs_ui_notebook_zuite/** \ No newline at end of file -- 2.30.9 From b67078a7d6a80fa4986140872ba3a64ab4f3570e Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Tue, 16 Apr 2019 08:29:00 +0000 Subject: [PATCH 27/28] erp5_notebook: Use jsmd_viewer replace the notebook_viewer by default. --- .../erp5_notebook/Notebook_view/my_text_content.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/Notebook_view/my_text_content.xml b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/Notebook_view/my_text_content.xml index 9e9ebbe75b3..3da5e6df0c0 100644 --- a/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/Notebook_view/my_text_content.xml +++ b/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/Notebook_view/my_text_content.xml @@ -139,7 +139,7 @@ _text - python: [(\'editor\', \'notebook_editor\'), (\'portal_type\', context.getPortalType()), (\'maximize\', \'listbox\' not in field.id)] + python: [(\'editor\', \'jsmd_editor\'), (\'portal_type\', context.getPortalType()), (\'maximize\', \'listbox\' not in field.id)] -- 2.30.9 From c89d635636ec015859a8b1efbcb0bc7dd8ef1d45 Mon Sep 17 00:00:00 2001 From: Boxiang Sun Date: Wed, 17 Apr 2019 13:00:40 +0000 Subject: [PATCH 28/28] erp5_notebook_test: Add test for check the Python in browser --- .../notebook_test_python_basic.xml | 707 ++++++++++++++++++ .../testNotebookJSMDViewerPyBasic.xml | 58 ++ .../testNotebookJSMDViewerPyBasic.zpt | 57 ++ .../bt/template_keep_workflow_path_list | 3 +- bt5/erp5_notebook_test/bt/template_path_list | 1 + 5 files changed, 825 insertions(+), 1 deletion(-) create mode 100644 bt5/erp5_notebook_test/PathTemplateItem/notebook_module/notebook_test_python_basic.xml create mode 100644 bt5/erp5_notebook_test/PathTemplateItem/portal_tests/renderjs_ui_notebook_zuite/testNotebookJSMDViewerPyBasic.xml create mode 100644 bt5/erp5_notebook_test/PathTemplateItem/portal_tests/renderjs_ui_notebook_zuite/testNotebookJSMDViewerPyBasic.zpt diff --git a/bt5/erp5_notebook_test/PathTemplateItem/notebook_module/notebook_test_python_basic.xml b/bt5/erp5_notebook_test/PathTemplateItem/notebook_module/notebook_test_python_basic.xml new file mode 100644 index 00000000000..51f39fed6b7 --- /dev/null +++ b/bt5/erp5_notebook_test/PathTemplateItem/notebook_module/notebook_test_python_basic.xml @@ -0,0 +1,707 @@ + + + + + + + + + + _Access_contents_information_Permission + + + Assignee + Assignor + Manager + Owner + + + + + _Add_portal_content_Permission + + + Assignee + Assignor + Manager + Owner + + + + + _Change_local_roles_Permission + + + Assignor + Manager + + + + + _Modify_portal_content_Permission + + + Assignee + Assignor + Manager + Owner + + + + + _View_Permission + + + Assignee + Assignor + Manager + Owner + + + + + content_md5 + + + + + + description + + + + + + id + notebook_test_python_basic + + + language + + + + + + portal_type + Notebook + + + short_title + + + + + + text_content + %% meta\n +{\n + "title": "Lecture-3-Matplotlib",\n + "lastSaved": "2018-10-16T13:50:00.550Z",\n + "languages": {\n + "js": {\n + "pluginType": "language",\n + "languageId": "js",\n + "displayName": "Javascript",\n + "codeMirrorMode": "javascript",\n + "module": "window",\n + "evaluator": "eval",\n + "keybinding": "j",\n + "url": ""\n + },\n + "py": {\n + "languageId": "py",\n + "displayName": "python",\n + "codeMirrorMode": "python",\n + "keybinding": "p",\n + "url": "https://iodide.io/pyodide-demo/pyodide.js",\n + "module": "pyodide",\n + "evaluator": "runPython",\n + "pluginType": "language"\n + }\n + },\n + "lastExport": "2018-10-16T13:50:03.563Z"\n +}\n +\n +%% plugin\n +{\n + "languageId": "py",\n + "displayName": "python",\n + "codeMirrorMode": "python",\n + "keybinding": "p",\n + "url": "https://iodide.io/pyodide-demo/pyodide.js",\n + "module": "pyodide",\n + "evaluator": "runPython",\n + "pluginType": "language"\n +}\n +\n +%% md\n +# Notebook JSMD Viewer Basic Python Test\n +\n +%% md\n +This is a sample content for check the Python section can be executed in JSMD viewer.\n +\n +%% code {"language":"py"}\n +2 + 40 + + + title + Notebook test python basic + + + workflow_history + + AAAAAAAAAAI= + + + + + + + + + + + + + data + + + + document_publication_workflow + + AAAAAAAAAAM= + + + + edit_workflow + + AAAAAAAAAAQ= + + + + processing_status_workflow + + AAAAAAAAAAU= + + + + + + + + + + + + + + + + + + + action + + + + + + actor + zope + + + comment + + + + error_message + + + + time + + + + + + + + + + + 1555491600.85 + UTC + + + + + + + validation_state + draft + + + + + + + + + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + error_message + + + + serial + 0.0.0.0 + + + state + current + + + time + + + + + + + + + + + 1555491600.83 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + AAAAAAAAAAY= + + + + error_message + + + + serial + 0.0.0.0 + + + state + current + + + time + + + + + + + + + 1555491600.86 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 975.5820.943.6348 + + + state + current + + + time + + + + + + + + + 1555491625.73 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 975.5820.28117.55671 + + + state + current + + + time + + + + + + + + + 1555491680.35 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 975.5821.22240.44305 + + + state + current + + + time + + + + + + + + + 1555505646.03 + UTC + + + + + + + + + action + edit + + + actor + zope + + + comment + + + + + + error_message + + + + serial + 975.6054.6589.45414 + + + state + current + + + time + + + + + + + + + 1555505830.04 + UTC + + + + + + + + + + + + + + + + + + + + + action + + + + + + actor + zope + + + comment + + + + error_message + + + + external_processing_state + empty + + + serial + 0.0.0.0 + + + time + + + + + + + + + + + 1555491600.84 + UTC + + + + + + + + + action + detect_uploaded_file + + + actor + zope + + + comment + + + + error_message + + + + external_processing_state + uploaded + + + serial + 0.0.0.0 + + + time + + + + + + + + + 1555491600.84 + UTC + + + + + + + + + action + detect_converted_file + + + actor + zope + + + comment + + + + error_message + + + + external_processing_state + converted + + + serial + 0.0.0.0 + + + time + + + + + + + + + 1555491600.85 + UTC + + + + + + + + + + + + + + + + + + default + Object copied from ${source_item} + + + domain + erp5_ui + + + mapping + + + + source_item + /erp5/notebook_module/notebook_test_purejs + + + + + + message + Object copied from ${source_item} + + + + + diff --git a/bt5/erp5_notebook_test/PathTemplateItem/portal_tests/renderjs_ui_notebook_zuite/testNotebookJSMDViewerPyBasic.xml b/bt5/erp5_notebook_test/PathTemplateItem/portal_tests/renderjs_ui_notebook_zuite/testNotebookJSMDViewerPyBasic.xml new file mode 100644 index 00000000000..dbaf41ee727 --- /dev/null +++ b/bt5/erp5_notebook_test/PathTemplateItem/portal_tests/renderjs_ui_notebook_zuite/testNotebookJSMDViewerPyBasic.xml @@ -0,0 +1,58 @@ + + + + + + + + + + _bind_names + + + + + + + + + + _asgns + + + + name_subpath + traverse_subpath + + + + + + + + + + + content_type + text/html + + + expand + 0 + + + id + testNotebookJSMDViewerPyBasic + + + output_encoding + utf-8 + + + title + + + + + + diff --git a/bt5/erp5_notebook_test/PathTemplateItem/portal_tests/renderjs_ui_notebook_zuite/testNotebookJSMDViewerPyBasic.zpt b/bt5/erp5_notebook_test/PathTemplateItem/portal_tests/renderjs_ui_notebook_zuite/testNotebookJSMDViewerPyBasic.zpt new file mode 100644 index 00000000000..58475d6d272 --- /dev/null +++ b/bt5/erp5_notebook_test/PathTemplateItem/portal_tests/renderjs_ui_notebook_zuite/testNotebookJSMDViewerPyBasic.zpt @@ -0,0 +1,57 @@ + + + +Test Notebook JSMD RenderJS UI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Test Notebook JSMD RenderJS UI
open${base_url}/web_site_module/renderjs_runner/#/notebook_module/notebook_test_python_basic
waitForElementPresent//iframe
waitForElementPresent//iframe[contains(@src, 'gadget_jsmd_viewer.html')]
selectFrameindex=0
waitForElementPresent//body//iframe
selectFrameindex=0
waitForElementPresent//h1[contains(text(),'Notebook JSMD Viewer Basic Python Test')]
waitForElementPresent//code[contains(text(),'42')]
+ + \ No newline at end of file diff --git a/bt5/erp5_notebook_test/bt/template_keep_workflow_path_list b/bt5/erp5_notebook_test/bt/template_keep_workflow_path_list index 90fba4cf6a0..ec7c14c07a4 100644 --- a/bt5/erp5_notebook_test/bt/template_keep_workflow_path_list +++ b/bt5/erp5_notebook_test/bt/template_keep_workflow_path_list @@ -1 +1,2 @@ -notebook_module/notebook_test_purejs \ No newline at end of file +notebook_module/notebook_test_purejs +notebook_module/notebook_test_python_basic \ No newline at end of file diff --git a/bt5/erp5_notebook_test/bt/template_path_list b/bt5/erp5_notebook_test/bt/template_path_list index a963d0e95ea..7f2e7660c8c 100644 --- a/bt5/erp5_notebook_test/bt/template_path_list +++ b/bt5/erp5_notebook_test/bt/template_path_list @@ -1,3 +1,4 @@ notebook_module/notebook_test_purejs +notebook_module/notebook_test_python_basic portal_tests/renderjs_ui_notebook_zuite portal_tests/renderjs_ui_notebook_zuite/** \ No newline at end of file -- 2.30.9