editor-new.js 144 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306
  1. "use strict";
  2. // Copyright 2012 United States Government, as represented by the Secretary of Defense, Under
  3. // Secretary of Defense (Personnel & Readiness).
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  6. // in compliance with the License. You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software distributed under the License
  11. // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  12. // or implied. See the License for the specific language governing permissions and limitations under
  13. // the License.
  14. /// vwf/view/editor creates a view interface for editor functions.
  15. ///
  16. /// @module vwf/view/editor
  17. /// @requires version
  18. /// @requires vwf/view
  19. /// @requires vwf/utility
  20. define([
  21. "module",
  22. "version",
  23. "vwf/view",
  24. "vwf/utility",
  25. "vwf/view/lib/ace/ace",
  26. "vwf/view/lib/colorpicker/colorpicker.min"
  27. ], function (module, version, view, utility, ace, colorpicker) {
  28. var self;
  29. return view.load(module, {
  30. // == Module Definition ====================================================================
  31. initialize: function () {
  32. self = this;
  33. this.ace = window.ace;
  34. this.nodes = {};
  35. this.scenes = {};
  36. this.allScripts = {};
  37. //$(document.head).append('<style type="text/css" media="screen"> #editorlive { height: 500px; width: 800px; } </style>');
  38. document.querySelector('head').innerHTML += '<style type="text/css" media="screen"> #editorlive { height: 500px; width: 800px; } </style>';
  39. document.querySelector('head').innerHTML += '<link rel="stylesheet" href="vwf/view/lib/editorLive.css">';
  40. //document.querySelector('head').innerHTML += '<script type="text/javascript" src="vwf/view/lib/colorpicker/colorpicker.min.js">';
  41. document.querySelector('head').innerHTML += '<link rel="stylesheet" href="vwf/view/lib/colorpicker/themes.css">';
  42. //$(document.head).append('<meta name="viewport" content="width=device-width, initial-scale=1">');
  43. document.querySelector('head').innerHTML += '<meta name="viewport" content="width=device-width, initial-scale=1">';
  44. // $('body').append('<script>mdc.autoInit()</script>');
  45. this.removeProps = (obj) => {
  46. Object.keys(obj).forEach(key =>
  47. (key === 'id' || key === 'patches' || key === 'random' || key === 'sequence') && delete obj[key] ||
  48. (obj[key] && typeof obj[key] === 'object') && this.removeProps(obj[key])
  49. );
  50. return obj;
  51. };
  52. this.getNodeDef = function (nodeID) {
  53. let node = vwf.getNode(nodeID, true);
  54. let nodeDef = self.removeProps(node);
  55. return nodeDef
  56. }
  57. this.GUID = function () {
  58. var S4 = function () {
  59. return Math.floor(
  60. Math.random() * 0x10000 /* 65536 */
  61. ).toString(16);
  62. };
  63. return (
  64. S4() + S4() + "-" +
  65. S4() + "-" +
  66. S4() + "-" +
  67. S4() + "-" +
  68. S4() + S4() + S4()
  69. );
  70. }
  71. this.getRoot = function () {
  72. var app = window.location.pathname;
  73. var pathSplit = app.split('/');
  74. if (pathSplit[0] == "") {
  75. pathSplit.shift();
  76. }
  77. if (pathSplit[pathSplit.length - 1] == "") {
  78. pathSplit.pop();
  79. }
  80. var instIndex = pathSplit.length - 1;
  81. if (pathSplit.length > 2) {
  82. if (pathSplit[pathSplit.length - 2] == "load") {
  83. instIndex = pathSplit.length - 3;
  84. }
  85. }
  86. if (pathSplit.length > 3) {
  87. if (pathSplit[pathSplit.length - 3] == "load") {
  88. instIndex = pathSplit.length - 4;
  89. }
  90. }
  91. var root = "";
  92. for (var i = 0; i < instIndex; i++) {
  93. if (root != "") {
  94. root = root + "/";
  95. }
  96. root = root + pathSplit[i];
  97. }
  98. if (root.indexOf('.vwf') != -1) root = root.substring(0, root.lastIndexOf('/'));
  99. return root
  100. };
  101. this.getRandomInt = function (min, max) {
  102. min = Math.ceil(min);
  103. max = Math.floor(max);
  104. return Math.floor(Math.random() * (max - min)) + min; //The maximum is exclusive and the minimum is inclusive
  105. };
  106. ["drawer", "toolbar", "sideBar", "propWindow", "clientsWindow", "codeEditorWindow", "propEditorWindow", "viewSceneProps"].forEach(item => {
  107. let el = document.createElement("div");
  108. el.setAttribute("id", item);
  109. document.body.appendChild(el);
  110. }
  111. );
  112. this.avatarCardDef = function (src, desc, onclickfunc) {
  113. return {
  114. $cell: true,
  115. $type: "div",
  116. class: "mdc-card avatar-card",
  117. $init: function () {
  118. this.style.backgroundImage = 'linear-gradient(0deg, rgba(0, 0, 0, 0.0), rgba(0, 0, 0, 0.0) ), url(' + src + ')'
  119. },
  120. onclick: onclickfunc,
  121. $components: [
  122. {
  123. $type: "section",
  124. class: "mdc-card__primary",
  125. $components: [
  126. {
  127. $type: "h1",
  128. class: "mdc-card__title mdc-card__title--large",
  129. $text: desc.subtitle
  130. },
  131. {
  132. $type: "h2",
  133. class: "mdc-card__subtitle",
  134. $text: desc.title
  135. }
  136. ]
  137. },
  138. {
  139. $type: "section",
  140. class: "mdc-card__actions",
  141. $components: [
  142. {
  143. $type: "button",
  144. class: "mdc-button mdc-button--compact mdc-card__action",
  145. //$text: "Use it",
  146. onclick: onclickfunc
  147. }
  148. ]
  149. }
  150. ]
  151. }
  152. }
  153. let avatarSettings =
  154. {
  155. $cell: true,
  156. $type: "div",
  157. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  158. $components: [
  159. {
  160. $cell: true,
  161. $type: "div",
  162. class: "mdc-layout-grid__inner",
  163. $components: [
  164. {
  165. $cell: true,
  166. $type: "div",
  167. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  168. $components: [
  169. {
  170. $cell: true,
  171. $type: "button",
  172. class: "mdc-button mdc-button--raised",
  173. $text: "Go forward",
  174. onclick: function (e) {
  175. function getMovementVector(el) {
  176. var directionVector = new THREE.Vector3(0, 0, 0);
  177. var rotationEuler = new THREE.Euler(0, 0, 0, 'YXZ');
  178. var rotation = el.getAttribute('rotation');
  179. var velocity = new THREE.Vector3(0, 0, -0.5);
  180. var xRotation;
  181. directionVector.copy(velocity);
  182. directionVector.multiplyScalar(1.0);
  183. // Absolute.
  184. if (!rotation) { return directionVector; }
  185. xRotation = 0;
  186. // Transform direction relative to heading.
  187. rotationEuler.set(THREE.Math.degToRad(xRotation), THREE.Math.degToRad(rotation.y), 0);
  188. directionVector.applyEuler(rotationEuler);
  189. return directionVector;
  190. }
  191. let el = document.querySelector('#avatarControl');
  192. let currentPosition = el.getAttribute('position');
  193. let movementVector = getMovementVector(el);
  194. let position = {};
  195. position.x = currentPosition.x + movementVector.x;
  196. position.y = currentPosition.y + movementVector.y;
  197. position.z = currentPosition.z + movementVector.z;
  198. el.setAttribute('position', position);
  199. }
  200. },
  201. ]
  202. },
  203. {
  204. $cell: true,
  205. $type: "div",
  206. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  207. $components: [
  208. {
  209. $cell: true,
  210. $type: "button",
  211. class: "mdc-button mdc-button--raised",
  212. $text: "Reset camera view",
  213. onclick: function (e) {
  214. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  215. let controlEl = document.querySelector('#avatarControl');
  216. controlEl.setAttribute('camera', 'active', true);
  217. }
  218. },
  219. {
  220. $cell: true,
  221. $type: "button",
  222. class: "mdc-button mdc-button--raised",
  223. $text: "Hide cursor",
  224. onclick: function (e) {
  225. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  226. let avatarID = 'avatar-' + self.kernel.moniker();
  227. let cursorID = 'myCursor-' + avatarID;
  228. let controlEl = document.querySelector("[id='" + cursorID + "']");
  229. let vis = controlEl.getAttribute('visible');
  230. this.$text = vis ? 'Show cursor' : 'Hide cursor';
  231. vwf_view.kernel.callMethod(avatarID, "showHideCursor", [!vis]);
  232. //controlEl.setAttribute('visible', !vis);
  233. }
  234. }
  235. ]
  236. },
  237. {
  238. $cell: true,
  239. $type: "div",
  240. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  241. $components: [
  242. {
  243. $type: "div",
  244. class: "mdc-layout-grid",
  245. $components: [
  246. {
  247. $type: "div",
  248. class: "mdc-layout-grid__inner",
  249. $components: [
  250. {
  251. $cell: true,
  252. $type: "div",
  253. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  254. $components: [
  255. self.avatarCardDef("/../assets/avatars/ico/simple.jpg", { title: "Simple", subtitle: "Cube" },
  256. function (e) {
  257. let avatarID = 'avatar-' + self.kernel.moniker();
  258. vwf_view.kernel.callMethod(avatarID, "createSimpleAvatar");
  259. }
  260. )
  261. ]
  262. },
  263. {
  264. $cell: true,
  265. $type: "div",
  266. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  267. $components: [
  268. self.avatarCardDef("/../assets/avatars/ico/female.jpg", { title: "Human", subtitle: "Female" },
  269. function (e) {
  270. let avatarID = 'avatar-' + self.kernel.moniker();
  271. vwf_view.kernel.callMethod(avatarID, "createAvatarFromGLTF", ["/../assets/avatars/female/avatar1.gltf"]);
  272. }
  273. )]
  274. },
  275. {
  276. $cell: true,
  277. $type: "div",
  278. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  279. $components: [
  280. self.avatarCardDef("/../assets/avatars/ico/male.jpg", { title: "Human", subtitle: "Male" },
  281. function (e) {
  282. let avatarID = 'avatar-' + self.kernel.moniker();
  283. vwf_view.kernel.callMethod(avatarID, "createAvatarFromGLTF", ["/../assets/avatars/male/avatar1.gltf"]);
  284. }
  285. )]
  286. }
  287. ]
  288. }
  289. ]
  290. }
  291. ]
  292. },
  293. {
  294. $cell: true,
  295. $type: "div",
  296. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  297. $components: [
  298. {
  299. $cell: true,
  300. $type: "button",
  301. class: "mdc-button mdc-button--raised",
  302. $text: "GearVR controller",
  303. onclick: function (e) {
  304. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  305. let sceneEl = document.querySelector('a-scene');
  306. let gearvr = document.createElement('a-entity');
  307. gearvr.setAttribute('id','gearvrcontrols');
  308. gearvr.setAttribute('gearvr-controls','');
  309. gearvr.setAttribute('gearvr-controls', 'hand', 'right');
  310. sceneEl.appendChild(gearvr);
  311. }
  312. }
  313. ]
  314. }
  315. ]
  316. }
  317. ]
  318. }
  319. let viewSettings =
  320. {
  321. $cell: true,
  322. $type: "div",
  323. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  324. $components: [
  325. {
  326. $cell: true,
  327. $type: "div",
  328. class: "mdc-layout-grid__inner",
  329. $components: [
  330. {
  331. $cell: true,
  332. $type: "div",
  333. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  334. $components: [
  335. {
  336. $cell: true,
  337. $type: "button",
  338. class: "mdc-button mdc-button--raised",
  339. $text: "OSC Settings",
  340. onclick: function (e) {
  341. let sideBar = document.querySelector('#sideBar');
  342. sideBar._sideBarComponent = oscSettings;
  343. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  344. }
  345. }
  346. ]
  347. }
  348. ]
  349. }
  350. ]
  351. }
  352. let savedStateEl = function (item) {
  353. return {
  354. $type: "li",
  355. class: "mdc-list-item",
  356. role: "option",
  357. $components: [
  358. {
  359. $text: "Saved world"
  360. }
  361. ]
  362. }
  363. }
  364. let stateListElement = function (item) {
  365. let liEl = {
  366. $type: "li",
  367. class: "mdc-list-item",
  368. role: "option",
  369. id: "",
  370. applicationpath: "",
  371. $components: [
  372. {
  373. $text: "no saves"
  374. }
  375. ]
  376. }
  377. let applicationName = item.applicationpath.split("/");
  378. if (applicationName == "") {
  379. return liEl
  380. }
  381. if (applicationName.length > 0) {
  382. applicationName = applicationName[applicationName.length - 1];
  383. }
  384. if (applicationName.length > 0) {
  385. applicationName = applicationName.charAt(0).toUpperCase() + applicationName.slice(1);
  386. }
  387. if (item.latestsave) {
  388. liEl = {
  389. $type: "li",
  390. class: "mdc-list-item",
  391. role: "option",
  392. id: item.savename,
  393. applicationpath: item.applicationpath,
  394. $components: [
  395. {
  396. $text: applicationName + ": " + item.savename
  397. }
  398. ]
  399. }
  400. }
  401. else {
  402. liEl = {
  403. $type: "li",
  404. class: "mdc-list-item",
  405. role: "option",
  406. id: item.savename,
  407. revision: item.revision,
  408. applicationpath: item.applicationpath,
  409. $components: [
  410. {
  411. $text: applicationName + ": " + item.savename + " Rev(" + item.revision + ")"
  412. }
  413. ]
  414. }
  415. }
  416. return liEl
  417. }
  418. let oscSettings =
  419. {
  420. $cell: true,
  421. $type: "div",
  422. id: "oscSettings",
  423. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  424. _oscHost: '',
  425. _oscPort: '',
  426. _oscStatus: '',
  427. _updateStatus: function () {
  428. this._oscStatus = window._OSCManager.getStatus()
  429. },
  430. $init: function () {
  431. if (window._OSCManager) {
  432. this._oscHost = window._OSCManager.hostValue;
  433. this._oscPort = window._OSCManager.portValue;
  434. this._oscStatus = window._OSCManager.getStatus();
  435. // var t = this;
  436. // setInterval(function () {
  437. // t._updateStatus();
  438. // }, 1000);
  439. }
  440. },
  441. $update: function () {
  442. let that = this
  443. var buttonText = "Connect";
  444. var buttonFunc = function (e) {
  445. }
  446. if (this._oscStatus == 1) {
  447. buttonText = "Disconnect";
  448. buttonFunc = function (e) {
  449. window._OSCManager.disconnect();
  450. }
  451. } else {
  452. var buttonFunc = function (e) {
  453. window._OSCManager.connect();
  454. window._OSCManager.port.on("open", function () {
  455. that._oscStatus = window._OSCManager.getStatus();
  456. console.log("connected");
  457. });
  458. window._OSCManager.port.on("close", function () {
  459. that._oscStatus = window._OSCManager.getStatus();
  460. console.log("disconnected");
  461. });
  462. }
  463. }
  464. this.$components = [
  465. {
  466. $cell: true,
  467. $type: "div",
  468. class: "mdc-layout-grid__inner",
  469. $components: [
  470. {
  471. $cell: true,
  472. $type: "div",
  473. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  474. $components: [
  475. {
  476. $type: "span",
  477. $text: "Host: "
  478. },
  479. {
  480. class: "mdc-textfield",
  481. $cell: true,
  482. $type: "span",
  483. $components: [
  484. {
  485. class: "mdc-textfield__input",
  486. id: "oscHost",
  487. $cell: true,
  488. $type: "input",
  489. type: "text",
  490. value: this._oscHost,
  491. onchange: function (e) {
  492. this._oscHost = this.value;
  493. window._OSCManager.setOSCHostAndPort(this._oscHost, this._oscPort);
  494. }
  495. }
  496. ]
  497. }
  498. ]
  499. },
  500. {
  501. $cell: true,
  502. $type: "div",
  503. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  504. $components: [
  505. {
  506. $type: "span",
  507. $text: "Port: "
  508. },
  509. {
  510. class: "mdc-textfield",
  511. $cell: true,
  512. $type: "span",
  513. $components: [
  514. {
  515. class: "mdc-textfield__input",
  516. id: "oscPort",
  517. $cell: true,
  518. $type: "input",
  519. type: "text",
  520. value: this._oscPort,
  521. onchange: function (e) {
  522. this._oscPort = this.value;
  523. window._OSCManager.setOSCHostAndPort(this._oscHost, this._oscPort);
  524. }
  525. }
  526. ]
  527. }
  528. ]
  529. },
  530. {
  531. $cell: true,
  532. $type: "div",
  533. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  534. $components: [
  535. {
  536. $cell: true,
  537. $type: "button",
  538. class: "mdc-button mdc-button--raised",
  539. $text: buttonText,
  540. onclick: buttonFunc
  541. }
  542. ]
  543. }
  544. ]
  545. }
  546. ]
  547. }
  548. }
  549. let loadSaveSettings =
  550. {
  551. $cell: true,
  552. $type: "div",
  553. id: "loadSaveSettings",
  554. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  555. _saveStates: [],
  556. _getStates: async function () {
  557. let response = await fetch("/" + self.getRoot() + "/listallsaves");
  558. let data = await response.json();
  559. //this._saveStates = data;
  560. //let appName = self.getRoot();
  561. //console.log(data.filter(item => item.applicationpath.split("/")[1] == appName));
  562. let filterData = data.filter(item => item.applicationpath.split("/")[1] == self.getRoot());
  563. if (filterData.length !== 0) {
  564. this._saveStates = filterData
  565. //return filterData
  566. } else {
  567. this._saveStates = [{
  568. savename: "",
  569. latestsave: "",
  570. revision: "",
  571. applicationpath: "",
  572. url: ""
  573. }]
  574. }
  575. // this._saveStates.filter(item => item.applicationpath.split("/")[1] == self.getRoot()).map(stateListElement)
  576. //return data
  577. //console.log(data);
  578. return this._saveStates
  579. },
  580. $init: function () {
  581. this._getStates();
  582. },
  583. $update: function () {
  584. this.$components =
  585. [
  586. {
  587. $cell: true,
  588. $type: "div",
  589. class: "mdc-layout-grid__inner",
  590. $components: [
  591. {
  592. $cell: true,
  593. $type: "div",
  594. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  595. $components: [
  596. {
  597. class: "mdc-textfield",
  598. $cell: true,
  599. $type: "span",
  600. $components: [
  601. {
  602. class: "mdc-textfield__input",
  603. id: "fileName",
  604. $cell: true,
  605. $type: "input",
  606. type: "text",
  607. value: self.getRoot()
  608. }]
  609. }
  610. ]
  611. },
  612. {
  613. $cell: true,
  614. $type: "div",
  615. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  616. $components: [
  617. {
  618. $cell: true,
  619. $type: "button",
  620. class: "mdc-button mdc-button--raised",
  621. $text: "Save",
  622. onclick: function (e) {
  623. let fileName = document.querySelector('#fileName')
  624. saveStateAsFile.call(self, fileName.value);
  625. document.querySelector("#fileName").value = '';
  626. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  627. }
  628. }
  629. ]
  630. },
  631. {
  632. $cell: true,
  633. $type: "div",
  634. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  635. $components: [
  636. {
  637. $cell: true,
  638. $type: "div",
  639. class: "mdc-select",
  640. $init: function () {
  641. var MDCSelect = mdc.select.MDCSelect;
  642. const select = new MDCSelect(document.querySelector('.mdc-select'));
  643. select.listen('MDCSelect:change', () => {
  644. //this._selectedState = select.value;
  645. document.querySelector('#loadStateButton')._selectedState = select.selectedOptions[0];
  646. //console.log(select.value);
  647. //.selectedOptions[0]
  648. });
  649. },
  650. role: "listbox",
  651. $components: [
  652. {
  653. $type: "span",
  654. class: "mdc-select__selected-text",
  655. $text: "Select saved state"
  656. },
  657. {
  658. $type: "div",
  659. class: "mdc-simple-menu mdc-select__menu",
  660. $components: [
  661. {
  662. $type: "ul",
  663. class: "mdc-list mdc-simple-menu__items",
  664. $components: this._saveStates.map(stateListElement)
  665. }
  666. ]
  667. }
  668. ]
  669. }
  670. ]
  671. },
  672. {
  673. $cell: true,
  674. $type: "div",
  675. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  676. $components: [
  677. {
  678. $cell: true,
  679. $type: "button",
  680. _selectedState: {},
  681. id: "loadStateButton",
  682. class: "mdc-button mdc-button--raised",
  683. $text: "Load",
  684. onclick: function (e) {
  685. loadSavedState.call(self, this._selectedState.getAttribute('id'), this._selectedState.getAttribute('applicationpath'), this._selectedState.getAttribute('revision'));
  686. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  687. }
  688. }
  689. ]
  690. }
  691. ]
  692. }
  693. ]
  694. }
  695. }
  696. let protoPropertiesCell = function (m) {
  697. return {
  698. $type: "div",
  699. class: "mdc-layout-grid__inner",
  700. _prop: {},
  701. $init: function () {
  702. let prop = m[1].prop;
  703. if (prop.value == undefined && this._currentNode !== undefined) {
  704. prop.value = JSON.stringify(utility.transform(vwf.getProperty(this._currentNode, prop.name, []), utility.transforms.transit));
  705. }
  706. this._prop = prop
  707. },
  708. $update: function () {
  709. this.$components = [
  710. {
  711. $type: "div",
  712. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  713. $components: [
  714. { $text: this._prop.name }
  715. ]
  716. },
  717. {
  718. $type: "div",
  719. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  720. },
  721. {
  722. $type: "div",
  723. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-7",
  724. $components: [
  725. {
  726. class: "mdc-textfield",
  727. $cell: true,
  728. $type: "div",
  729. $components: [{
  730. class: "mdc-textfield__input",
  731. $cell: true,
  732. $type: "input",
  733. type: "text",
  734. value: this._prop.value,
  735. onchange: function (e) {
  736. let propValue = this.value;
  737. try {
  738. propValue = JSON.parse(propValue);
  739. self.kernel.setProperty(this._currentNode, this._prop.name, propValue);
  740. } catch (e) {
  741. // restore the original value on error
  742. this.value = propValue;
  743. }
  744. }
  745. }]
  746. }
  747. ]
  748. }
  749. ]
  750. }
  751. }
  752. }
  753. let propertiesCell = function (m) {
  754. var editComponents = [{}, {}]
  755. if (m.name.indexOf("semantics") > -1) { }
  756. else if (m.name.indexOf("grammar") > -1) { }
  757. else if (m.name.indexOf("ohm") > -1) {
  758. editComponents = [
  759. {
  760. $type: "div",
  761. $cell: true,
  762. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-6",
  763. $components: [
  764. {
  765. $cell: true,
  766. $type: "button",
  767. class: "mdc-button",
  768. $text: "Edit", //edit grammar
  769. onclick: function (e) {
  770. var currentNode = document.querySelector('#currentNode')._currentNode;
  771. if (currentNode == '') {
  772. currentNode = vwf_view.kernel.find("", "/")[0];
  773. }
  774. let editor = document.querySelector('#livePropEditor');
  775. editor._setNode(currentNode);
  776. editor._propName = m.name;
  777. editor._prop = { body: m.rawValue, type: 'complex' }
  778. document.querySelector('#propEditorWindow').style.visibility = 'visible';
  779. }
  780. }
  781. ]
  782. },
  783. {
  784. $type: "div",
  785. $cell: true,
  786. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  787. $components: []
  788. }
  789. ]
  790. } else {
  791. editComponents = [
  792. {
  793. $type: "div",
  794. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-6",
  795. $components: [
  796. {
  797. class: "mdc-textfield",
  798. $cell: true,
  799. $type: "span",
  800. $components: [
  801. {
  802. class: "mdc-textfield__input",
  803. id: "prop-" + m.name,
  804. $cell: true,
  805. $type: "input",
  806. type: "text",
  807. value: m.getValue(),
  808. onchange: function (e) {
  809. let propValue = this.value;
  810. try {
  811. propValue = JSON.parse(propValue);
  812. self.kernel.setProperty(this._currentNode, m.name, propValue);
  813. } catch (e) {
  814. // restore the original value on error
  815. this.value = propValue;
  816. }
  817. }
  818. }
  819. ]
  820. }
  821. ]
  822. },
  823. {
  824. $type: "div",
  825. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  826. $components: [
  827. {
  828. $cell: true,
  829. $type: "button",
  830. class: "mdc-button",
  831. $text: "^", //edit grammar
  832. onclick: function (e) {
  833. var currentNode = document.querySelector('#currentNode')._currentNode;
  834. if (currentNode == '') {
  835. currentNode = vwf_view.kernel.find("", "/")[0];
  836. }
  837. let editor = document.querySelector('#livePropEditor');
  838. editor._setNode(currentNode);
  839. editor._propName = m.name;
  840. editor._prop = { body: m.getValue(), type: 'simple' }
  841. document.querySelector('#propEditorWindow').style.visibility = 'visible';
  842. }
  843. }
  844. ]
  845. }
  846. ];
  847. }
  848. return {
  849. $type: "div",
  850. class: "mdc-layout-grid__inner",
  851. $components: [
  852. {
  853. $type: "div",
  854. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  855. $components: [
  856. { $text: m.name }
  857. ]
  858. },
  859. {
  860. $type: "div",
  861. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  862. },
  863. editComponents[0],
  864. editComponents[1]
  865. ]
  866. }
  867. }
  868. let nodeLink = function (m) {
  869. var myClass = "nodeItem";
  870. let myAvatarName = 'avatar-' + self.kernel.moniker();
  871. (myAvatarName == m.name) ? (myClass = "avatarName mdc-typography--subheading2") :
  872. myClass = "nodeItem"
  873. return {
  874. $type: "li",
  875. class: "mdc-list-item",
  876. $components: [{
  877. $type: "a",
  878. class: "mdc-list-item",
  879. $href: "#",
  880. $components: [{
  881. $type: 'span',
  882. class: myClass,
  883. $text: m.name
  884. }
  885. ],
  886. onclick: function (e) {
  887. //self.currentNodeID = m.ID;
  888. document.querySelector('#currentNode')._setNode(m.ID);
  889. // document.querySelector('#liveCodeEditor')._editorNode = m.ID;
  890. // createAceEditor(self, m.ID);
  891. }
  892. }]
  893. }
  894. };
  895. let listDivider = {
  896. $cell: true,
  897. $type: "hr",
  898. class: "mdc-list-divider",
  899. }
  900. let gizmoEdit = {
  901. $type: "div",
  902. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  903. $components: [
  904. {
  905. $type: "div",
  906. class: "mdc-layout-grid__inner",
  907. $components: [
  908. {
  909. $type: "div",
  910. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  911. $components: [
  912. {
  913. $cell: true,
  914. $type: "span",
  915. $text: "Edit: ",
  916. }
  917. ]
  918. },
  919. {
  920. $type: "div",
  921. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-7",
  922. $components: [
  923. {
  924. $cell: true,
  925. $type: "div",
  926. class: "mdc-switch",
  927. $components: [
  928. {
  929. $type: "input",
  930. type: "checkbox",
  931. class: "mdc-switch__native-control",
  932. id: 'editnode',
  933. $init: function () {
  934. vwf_view.kernel.getProperty(this._currentNode, 'edit');
  935. },
  936. //id: "basic-switch",
  937. onchange: function (e) {
  938. var nodeID = document.querySelector('#currentNode')._currentNode;
  939. let chkAttr = this.getAttribute('checked');
  940. if (chkAttr == "") {
  941. self.kernel.setProperty(this._currentNode, 'edit', false);
  942. } else {
  943. self.kernel.setProperty(this._currentNode, 'edit', true);
  944. }
  945. vwf_view.kernel.callMethod(nodeID, "showCloseGizmo");
  946. }
  947. },
  948. {
  949. $type: "div",
  950. class: "mdc-switch__background",
  951. $components: [
  952. {
  953. $type: "div",
  954. class: "mdc-switch__knob"
  955. }
  956. ]
  957. }
  958. ]
  959. }
  960. ]
  961. },
  962. {
  963. $type: "div",
  964. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  965. $components: [
  966. {
  967. $cell: true,
  968. $type: "a",
  969. class: "gizmomode",
  970. $text: "T",
  971. onclick: function (e) {
  972. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['translate'])
  973. }
  974. }
  975. ]
  976. },
  977. {
  978. $type: "div",
  979. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  980. $components: [
  981. {
  982. $cell: true,
  983. $type: "a",
  984. class: "gizmomode",
  985. $text: "R",
  986. onclick: function (e) {
  987. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['rotate'])
  988. }
  989. }
  990. ]
  991. },
  992. {
  993. $type: "div",
  994. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  995. $components: [
  996. {
  997. $cell: true,
  998. $type: "a",
  999. class: "gizmomode",
  1000. $text: "S",
  1001. onclick: function (e) {
  1002. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['scale'])
  1003. }
  1004. }
  1005. ]
  1006. }
  1007. ]
  1008. }
  1009. ]
  1010. }
  1011. let nodesCell = {
  1012. $cell: true,
  1013. $type: "div",
  1014. id: "currentNode",
  1015. _childNodes: [],
  1016. _currentNode: '',
  1017. _displayedProperties: {},
  1018. _setNode: function (aNode) {
  1019. this._currentNode = aNode;
  1020. document.querySelector('#sideBar')._sideCurrentNode = this._currentNode
  1021. },
  1022. $init: function () {
  1023. this._currentNode = document.querySelector('#sideBar')._sideCurrentNode
  1024. //this._currentNode = vwf_view.kernel.find("", "/")[0];
  1025. //this._currentNode = '3333';
  1026. },
  1027. _getChildNodes: function () {
  1028. this._childNodes = self.nodes[this._currentNode];
  1029. if (this._childNodes !== undefined) {
  1030. return this._childNodes.children
  1031. } else {
  1032. return []
  1033. }
  1034. //let nodeIDAlpha = he.encode(this._currentNode);
  1035. },
  1036. // _getNodeComplexProperties: function () {
  1037. // let node = self.nodes[this._currentNode];
  1038. // let props = this._getNodeProperties();
  1039. // let filterFunction = function (prop) {
  1040. // return (prop.name == 'ohmLang')
  1041. // };
  1042. // let complexProps = props.filter(filterFunction.bind(this));
  1043. // return complexProps
  1044. // },
  1045. _getNodeProperties: function () {
  1046. let node = self.nodes[this._currentNode];
  1047. this._displayedProperties = {};
  1048. let filterFunction = function (prop) {
  1049. return (!this._displayedProperties[prop.name] && prop.name.indexOf('$') === -1) ? (this._displayedProperties[prop.name] = "instance", true) : (false);
  1050. };
  1051. let props = node.properties.filter(filterFunction.bind(this));
  1052. return props
  1053. },
  1054. _getNodeProtoProperties: function () {
  1055. let node = self.nodes[this._currentNode];
  1056. let filterFunction = function (prop) {
  1057. return (!this._displayedProperties[prop[1].prop.name]) ? (this._displayedProperties[prop[1].prop.name] = prop[1].prototype, true) : (false);
  1058. };
  1059. let props = Object.entries(getProperties.call(self, self.kernel, node.extendsID)).filter(filterFunction.bind(this));
  1060. return props
  1061. },
  1062. $update: function () {
  1063. //this.$text = this._currentNode;
  1064. let node = self.nodes[this._currentNode];
  1065. let nodeProtos = getPrototypes(self.kernel, node.extendsID);
  1066. var viewerProps = {};
  1067. var viewerPropsCell = {};
  1068. var gizmoCell = {};
  1069. if (this._currentNode !== self.kernel.application()) {
  1070. if (nodeProtos.includes('http://vwf.example.com/aframe/componentNode.vwf')) {
  1071. //gizmoCell = {};
  1072. } else {
  1073. gizmoCell = gizmoEdit
  1074. }
  1075. }
  1076. if (node !== undefined) {
  1077. if (node.extendsID == "http://vwf.example.com/aframe/acamera.vwf") {
  1078. viewerProps = {
  1079. $type: "li",
  1080. class: "mdc-list-item",
  1081. $components: [
  1082. {
  1083. $text: "Viewer properties",
  1084. $type: "span",
  1085. class: "mdc-list-item__text mdc-typography--button"
  1086. }
  1087. ]
  1088. }
  1089. viewerPropsCell = {
  1090. $cell: true,
  1091. $type: "div",
  1092. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1093. $components: [
  1094. {
  1095. $cell: true,
  1096. $type: "div",
  1097. class: "mdc-layout-grid__inner",
  1098. $components: [
  1099. {
  1100. $cell: true,
  1101. $type: "div",
  1102. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1103. $components: [
  1104. {
  1105. $cell: true,
  1106. $type: "button",
  1107. class: "mdc-button mdc-button--raised",
  1108. $text: "Active",
  1109. onclick: function (e) {
  1110. let camera = document.querySelector('#' + this._currentNode);
  1111. camera.setAttribute('camera', 'active', true);
  1112. }
  1113. }
  1114. ]
  1115. }
  1116. ]
  1117. }
  1118. ]
  1119. //$components: this._getNodeProtoProperties().map(protoPropertiesCell)
  1120. }
  1121. } else {
  1122. viewerProps = {};
  1123. viewerPropsCell = {};
  1124. }
  1125. }
  1126. this.$components = [
  1127. {
  1128. $cell: true,
  1129. $type: "ul",
  1130. class: "mdc-list",
  1131. $components: [
  1132. {
  1133. $cell: true,
  1134. $type: "button",
  1135. class: "mdc-list-item mdc-button mdc-button--raised",
  1136. $text: "<--",
  1137. onclick: function (e) {
  1138. let node = self.nodes[this._currentNode];
  1139. if (node.parentID !== 0) {
  1140. //self.currentNodeID = node.parentID,
  1141. document.querySelector('#currentNode')._setNode(node.parentID)
  1142. }
  1143. }
  1144. },
  1145. {
  1146. $type: "li",
  1147. class: "mdc-list-item",
  1148. $components: [
  1149. {
  1150. $text: "name",
  1151. $type: "span",
  1152. $init: function () {
  1153. let node = self.nodes[this._currentNode];
  1154. if (node) this.$text = node.name
  1155. },
  1156. class: "mdc-list-item__text mdc-typography--headline"
  1157. //<h1 class="mdc-typography--display4">Big header</h1>
  1158. }]
  1159. }, listDivider,
  1160. {
  1161. // $cell: true,
  1162. // $type: "ul",
  1163. // class: "mdc-list",
  1164. $type: "div",
  1165. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1166. $components: [
  1167. {
  1168. $type: "div",
  1169. class: "mdc-layout-grid__inner",
  1170. $components: [
  1171. {
  1172. $type: "div",
  1173. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1174. $components: [
  1175. {
  1176. $cell: true,
  1177. $type: "button",
  1178. class: "mdc-button mdc-button--raised",
  1179. $text: "Methods browser",
  1180. onclick: function (e) {
  1181. var currentNode = document.querySelector('#currentNode')._currentNode;
  1182. if (currentNode == '') {
  1183. currentNode = vwf_view.kernel.find("", "/")[0];
  1184. }
  1185. document.querySelector('#liveCodeEditor')._setNode(currentNode);
  1186. //createAceEditor(self, currentNode);
  1187. document.querySelector('#codeEditorWindow').style.visibility = 'visible';
  1188. }
  1189. }
  1190. ]
  1191. }
  1192. ]
  1193. }
  1194. ]
  1195. },
  1196. gizmoCell,
  1197. listDivider,
  1198. {
  1199. $type: "li",
  1200. class: "mdc-list-item",
  1201. $components: [
  1202. {
  1203. $text: "Children",
  1204. $type: "span",
  1205. class: "mdc-list-item__text mdc-typography--button"
  1206. }]
  1207. },
  1208. {
  1209. $cell: true,
  1210. $type: "ul",
  1211. class: "mdc-list",
  1212. $components: this._getChildNodes().map(nodeLink)
  1213. }, listDivider, {
  1214. $type: "li",
  1215. class: "mdc-list-item",
  1216. $components: [
  1217. {
  1218. $text: "Properties",
  1219. $type: "span",
  1220. class: "mdc-list-item__text mdc-typography--button"
  1221. //<h1 class="mdc-typography--display4">Big header</h1>
  1222. }]
  1223. },
  1224. {
  1225. // $cell: true,
  1226. // $type: "ul",
  1227. // class: "mdc-list",
  1228. $type: "div",
  1229. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1230. $components: this._getNodeProperties().map(propertiesCell)
  1231. },
  1232. listDivider,
  1233. {
  1234. $type: "li",
  1235. class: "mdc-list-item",
  1236. $components: [
  1237. {
  1238. $text: "Proto properties",
  1239. $type: "span",
  1240. class: "mdc-list-item__text mdc-typography--button"
  1241. }]
  1242. },
  1243. {
  1244. $cell: true,
  1245. $type: "div",
  1246. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1247. $components: this._getNodeProtoProperties().map(protoPropertiesCell)
  1248. }, listDivider,
  1249. viewerProps,
  1250. viewerPropsCell
  1251. ]
  1252. }
  1253. ]
  1254. }
  1255. }
  1256. let colorPickerComponent = {
  1257. $cell: true,
  1258. $type: "div",
  1259. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
  1260. $init: function () {
  1261. let myEl = this;
  1262. let cp = ColorPicker(
  1263. document.getElementById('slide'),
  1264. document.getElementById('picker'),
  1265. function (hex, hsv, rgb, mousePicker, mouseSlide) {
  1266. ColorPicker.positionIndicators(
  1267. document.getElementById('slide-indicator'),
  1268. document.getElementById('picker-indicator'),
  1269. mouseSlide, mousePicker
  1270. );
  1271. if (myEl._propName == 'color') {
  1272. // console.log(hex);
  1273. document.querySelector('#propAceEditor').env.editor.setValue(JSON.stringify(hex));
  1274. self.kernel.setProperty(myEl._editorNode, myEl._propName, hex);
  1275. }
  1276. });
  1277. if (myEl._propName == 'color') {
  1278. cp.setHex(JSON.parse(myEl._prop.body));
  1279. }
  1280. },
  1281. $components: [
  1282. {
  1283. $cell: true,
  1284. $type: "div",
  1285. id: "color-picker",
  1286. class: "cp-default",
  1287. $components: [
  1288. {
  1289. $cell: true,
  1290. $type: "div",
  1291. class: "picker-wrapper",
  1292. $components: [
  1293. {
  1294. $cell: true,
  1295. $type: "div",
  1296. id: "picker",
  1297. class: "picker",
  1298. style: "width: 130px; height: 130px"
  1299. },
  1300. {
  1301. $cell: true,
  1302. $type: "div",
  1303. id: "picker-indicator",
  1304. class: "picker-indicator"
  1305. }
  1306. ]
  1307. },
  1308. {
  1309. $cell: true,
  1310. $type: "div",
  1311. class: "slide-wrapper",
  1312. $components: [
  1313. {
  1314. $cell: true,
  1315. $type: "div",
  1316. id: "slide",
  1317. class: "slide",
  1318. style: "width: 30px; height: 130px"
  1319. },
  1320. {
  1321. $cell: true,
  1322. $type: "div",
  1323. id: "slide-indicator",
  1324. class: "slide-indicator"
  1325. }
  1326. ]
  1327. }
  1328. ]
  1329. }
  1330. // {
  1331. // $cell: true,
  1332. // $type: "div",
  1333. // id: "color-picker",
  1334. // $init: function () {
  1335. // }
  1336. // }
  1337. ]
  1338. }
  1339. let propEditorWindow = {
  1340. $cell: true,
  1341. $type: "div",
  1342. _editorNode: '',
  1343. _prop: { body: '', type: 'simple' },
  1344. _propName: '',
  1345. id: "livePropEditor",
  1346. _setNode: function (node) {
  1347. this._editorNode = node;
  1348. this._prop.body = ''
  1349. },
  1350. class: "propEditorGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1351. $update: function () {
  1352. var editorClass = "mdc-layout-grid__cell mdc-layout-grid__cell--span-8"
  1353. var livePropertyComponent = {}
  1354. if (this._prop.type == 'simple') {
  1355. if (this._propName == 'color') {
  1356. livePropertyComponent = colorPickerComponent
  1357. }
  1358. } else {
  1359. editorClass = "mdc-layout-grid__cell mdc-layout-grid__cell--span-12"
  1360. }
  1361. this.$components = [
  1362. {
  1363. $cell: true,
  1364. $type: "div",
  1365. class: "mdc-layout-grid__inner",
  1366. $components: [
  1367. {
  1368. $cell: true,
  1369. $type: "div",
  1370. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1371. $components: [
  1372. {
  1373. $cell: true,
  1374. $type: "button",
  1375. class: "mdc-button mdc-button--raised",
  1376. $text: "Update",
  1377. onclick: function (e) {
  1378. let editor = document.querySelector("#propAceEditor").env.editor;
  1379. let value = editor.getValue();
  1380. try {
  1381. let propValue = (this._prop.type == 'simple') ? (JSON.parse(value)) : (value)
  1382. //propValue = JSON.parse(value);
  1383. self.kernel.setProperty(this._editorNode, this._propName, propValue);
  1384. } catch (e) {
  1385. // restore the original value on error
  1386. this.value = propValue;
  1387. }
  1388. }
  1389. }]
  1390. },
  1391. {
  1392. $cell: true,
  1393. $type: "div",
  1394. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-5",
  1395. $components: [
  1396. {
  1397. $type: "h3",
  1398. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  1399. $text: this._editorNode
  1400. }
  1401. ]
  1402. },
  1403. {
  1404. $cell: true,
  1405. $type: "div",
  1406. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-5",
  1407. $components: [
  1408. {
  1409. $type: "h3",
  1410. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  1411. $text: this._propName
  1412. }
  1413. ]
  1414. }
  1415. ]
  1416. },
  1417. {
  1418. $cell: true,
  1419. $type: "div",
  1420. class: "mdc-layout-grid__inner",
  1421. $components: [
  1422. {
  1423. $cell: true,
  1424. $type: "div",
  1425. class: editorClass,
  1426. $components: [
  1427. {
  1428. $cell: true,
  1429. class: "aceEditor",
  1430. id: "propAceEditor",
  1431. $type: "div",
  1432. $text: this._prop.body,
  1433. $init: function () {
  1434. createAceEditor(self, this._editorNode, "propAceEditor");
  1435. this.env.editor.$blockScrolling = Infinity
  1436. }
  1437. }
  1438. ]
  1439. }, livePropertyComponent
  1440. // {
  1441. // $cell: true,
  1442. // $type: "div",
  1443. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1444. // $components: []
  1445. // },
  1446. ]
  1447. }
  1448. ]
  1449. //$components:
  1450. }
  1451. }
  1452. let codeEditorWindow = {
  1453. $cell: true,
  1454. $type: "div",
  1455. _editorNode: '',
  1456. _method: { body: '' },
  1457. _methodName: '',
  1458. _getNodeMethods: function () {
  1459. let node = self.nodes[this._editorNode];
  1460. return node.methods
  1461. },
  1462. _getProtoNodeMethods: function () {
  1463. let node = self.nodes[this._editorNode];
  1464. let prototypeMethods = getMethods.call(self, self.kernel, node.extendsID);
  1465. return prototypeMethods
  1466. },
  1467. id: "liveCodeEditor",
  1468. _setNode: function (node) {
  1469. this._editorNode = node;
  1470. this._method.body = ''
  1471. },
  1472. class: "codeEditorGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1473. // _getComplexProps: function(){
  1474. // let node = self.nodes[this._editorNode];
  1475. // let currentNode = document.querySelector('#currentNode');
  1476. // var props = {}
  1477. // if (currentNode !== null) {
  1478. // props = currentNode._getNodeComplexProperties();
  1479. // }
  1480. // return props
  1481. // },
  1482. // _listPropertyElement: function (m) {
  1483. // return {
  1484. // $type: "li",
  1485. // class: "mdc-list-item",
  1486. // $components: [{
  1487. // $type: "a",
  1488. // class: "mdc-list-item",
  1489. // $href: "#",
  1490. // $text: m[1].name,
  1491. // onclick: function (e) {
  1492. // this._method = {};
  1493. // this._methodName = m[1].name;
  1494. // this._method.body = m[1].rawValue
  1495. // this._method.type = "complexProperty"
  1496. // }
  1497. // }]
  1498. // }
  1499. // },
  1500. _listElement: function (m) {
  1501. return {
  1502. $type: "li",
  1503. class: "mdc-list-item",
  1504. $components: [{
  1505. $type: "a",
  1506. class: "mdc-list-item",
  1507. $href: "#",
  1508. $text: m[0],
  1509. onclick: function (e) {
  1510. let method = vwf.getMethod(this._editorNode, m[0]);
  1511. //document.querySelector('#aceEditor').
  1512. this._method = method;
  1513. this._methodName = m[0];
  1514. //self.currentNodeID = m.ID;
  1515. //document.querySelector('#currentNode')._setNode(m.ID);
  1516. }
  1517. }]
  1518. }
  1519. },
  1520. $update: function () {
  1521. this.$components = [
  1522. {
  1523. $cell: true,
  1524. $type: "div",
  1525. class: "mdc-layout-grid__inner",
  1526. $components: [
  1527. {
  1528. $cell: true,
  1529. $type: "div",
  1530. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1531. $components: [
  1532. {
  1533. $type: "h3",
  1534. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  1535. $text: this._editorNode
  1536. }
  1537. ]
  1538. },
  1539. {
  1540. $cell: true,
  1541. $type: "div",
  1542. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1543. $components: [
  1544. {
  1545. $cell: true,
  1546. $type: "button",
  1547. class: "mdc-button mdc-button--raised",
  1548. $text: "Update",
  1549. onclick: function (e) {
  1550. let editor = document.querySelector("#aceEditor").env.editor;
  1551. let evalText = editor.getValue();
  1552. // if (this._method.type == 'complexProperty') {
  1553. // let propValue = evalText;
  1554. // try {
  1555. // //propValue = JSON.parse(propValue);
  1556. // self.kernel.setProperty(this._editorNode, this._methodName, propValue);
  1557. // } catch (e) {
  1558. // // restore the original value on error
  1559. // this.value = propValue;
  1560. // }
  1561. // } else {
  1562. // }
  1563. self.kernel.setMethod(this._editorNode, this._methodName,
  1564. { body: evalText, type: "application/javascript", parameters: this._method.parameters });
  1565. }
  1566. }]
  1567. },
  1568. {
  1569. $cell: true,
  1570. $type: "div",
  1571. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1572. $components: [
  1573. {
  1574. $cell: true,
  1575. $type: "button",
  1576. class: "mdc-button mdc-button--raised",
  1577. $text: "Call",
  1578. onclick: function (e) {
  1579. var params = [];
  1580. if (this._method.parameters) {
  1581. let paramsLength = this._method.parameters.length
  1582. if (paramsLength >= 1) {
  1583. let paramsVal = document.querySelector("#methodParams").value;
  1584. try {
  1585. params = JSON.parse(paramsVal);
  1586. //params.push(prmtr);
  1587. } catch (e) {
  1588. self.logger.error('Invalid Value');
  1589. }
  1590. }
  1591. };
  1592. self.kernel.callMethod(this._editorNode, this._methodName, params);
  1593. }
  1594. }]
  1595. },
  1596. {
  1597. $cell: true,
  1598. $type: "div",
  1599. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1600. $components: [
  1601. {
  1602. $cell: true,
  1603. $type: "button",
  1604. class: "mdc-button mdc-button--raised",
  1605. $text: "Do It",
  1606. onclick: function (e) {
  1607. let editor = document.querySelector("#aceEditor").env.editor;
  1608. codeEditorDoit.call(self, editor, this._editorNode);
  1609. }
  1610. }]
  1611. },
  1612. {
  1613. $cell: true,
  1614. $type: "div",
  1615. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1616. $components: [
  1617. {
  1618. $cell: true,
  1619. $type: "button",
  1620. class: "mdc-button mdc-button--raised",
  1621. $text: "Print It",
  1622. onclick: function (e) {
  1623. let editor = document.querySelector("#aceEditor").env.editor;
  1624. codeEditorPrintit.call(self, editor, this._editorNode);
  1625. }
  1626. }]
  1627. }
  1628. ]
  1629. },
  1630. {
  1631. $cell: true,
  1632. $type: "div",
  1633. class: "mdc-layout-grid__inner",
  1634. $components: [
  1635. {
  1636. $cell: true,
  1637. $type: "div",
  1638. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1639. style: "overflow-y: scroll; max-height: 400px;",
  1640. $components: [
  1641. {
  1642. $cell: true,
  1643. $type: "div",
  1644. class: "mdc-list-group",
  1645. $components: [
  1646. {
  1647. $type: "h3",
  1648. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  1649. $text: "Node methods"
  1650. },
  1651. {
  1652. $cell: true,
  1653. $type: "ul",
  1654. class: "mdc-list",
  1655. $components: Object.entries(this._getNodeMethods()).map(this._listElement)
  1656. }, listDivider,
  1657. {
  1658. $type: "h3",
  1659. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  1660. $text: "Proto methods"
  1661. },
  1662. {
  1663. $cell: true,
  1664. $type: "ul",
  1665. class: "mdc-list",
  1666. $components: Object.entries(this._getProtoNodeMethods()).map(this._listElement)
  1667. }, listDivider,
  1668. {
  1669. $type: "h3",
  1670. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  1671. $text: "Events"
  1672. }
  1673. // {
  1674. // $cell: true,
  1675. // $type: "ul",
  1676. // class: "mdc-list",
  1677. // $components: Object.entries(this._getComplexProps()).map(this._listPropertyElement)
  1678. // }
  1679. ]
  1680. }
  1681. ]
  1682. },
  1683. {
  1684. $cell: true,
  1685. $type: "div",
  1686. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-9",
  1687. $components: [
  1688. {
  1689. $cell: true,
  1690. class: "aceEditor",
  1691. id: "aceEditor",
  1692. $type: "div",
  1693. $text: this._method.body,
  1694. $init: function () {
  1695. createAceEditor(self, this._editorNode, "aceEditor");
  1696. }
  1697. }
  1698. ]
  1699. }
  1700. ]
  1701. },
  1702. {
  1703. $cell: true,
  1704. $type: "div",
  1705. class: "mdc-layout-grid__inner",
  1706. $components: [
  1707. {
  1708. $cell: true,
  1709. $type: "div",
  1710. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1711. $components: [
  1712. {
  1713. $type: "span",
  1714. $text: "*"
  1715. }
  1716. ]
  1717. }
  1718. ]
  1719. },
  1720. { //params input
  1721. $cell: true,
  1722. $type: "div",
  1723. class: "mdc-layout-grid__inner",
  1724. $components: [
  1725. {
  1726. $cell: true,
  1727. $type: "div",
  1728. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1729. $components: [
  1730. {
  1731. class: "mdc-textfield",
  1732. $cell: true,
  1733. $type: "div",
  1734. $components: [{
  1735. class: "mdc-textfield__input",
  1736. id: "methodName",
  1737. $cell: true,
  1738. $type: "input",
  1739. type: "text",
  1740. value: "newMethodName",
  1741. onchange: function (e) {
  1742. let propValue = this.value;
  1743. try {
  1744. } catch (e) {
  1745. // restore the original value on error
  1746. }
  1747. }
  1748. }]
  1749. }
  1750. ]
  1751. },
  1752. {
  1753. $cell: true,
  1754. $type: "div",
  1755. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-7",
  1756. $components: [
  1757. {
  1758. class: "mdc-textfield params-textfield-input",
  1759. $cell: true,
  1760. $type: "div",
  1761. $components: [{
  1762. class: "mdc-textfield__input",
  1763. id: "methodParams",
  1764. $cell: true,
  1765. $type: "input",
  1766. type: "text",
  1767. value: JSON.stringify(this._method.parameters),
  1768. onchange: function (e) {
  1769. let propValue = this.value;
  1770. try {
  1771. } catch (e) {
  1772. // restore the original value on error
  1773. }
  1774. }
  1775. }]
  1776. }
  1777. ]
  1778. },
  1779. {
  1780. $cell: true,
  1781. $type: "div",
  1782. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1783. $components: [
  1784. {
  1785. $cell: true,
  1786. $type: "button",
  1787. class: "mdc-button mdc-button--raised",
  1788. $text: "Create",
  1789. onclick: function (e) {
  1790. let methodName = document.querySelector('#methodName').value;
  1791. //let methodParams = document.querySelector('#methodParams');
  1792. var params = [];
  1793. let body = '';
  1794. let paramsVal = document.querySelector("#methodParams").value;
  1795. if (paramsVal !== '') {
  1796. try {
  1797. params = JSON.parse(paramsVal);
  1798. //params.push(prmtr);
  1799. } catch (e) {
  1800. self.logger.error('Invalid Value');
  1801. }
  1802. }
  1803. self.kernel.createMethod(this._editorNode, methodName, params, body);
  1804. this._setNode(this._editorNode);
  1805. // let editor = document.querySelector("#aceEditor").env.editor;
  1806. // codeEditorDoit.call(self, editor, this._editorNode);
  1807. }
  1808. }
  1809. ]
  1810. }
  1811. ]
  1812. }
  1813. ]
  1814. //$components:
  1815. }
  1816. }
  1817. let propWindow = {
  1818. $cell: true,
  1819. $type: "div",
  1820. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1821. style: "overflow-y: scroll; max-height: 800px;",
  1822. $components: [
  1823. {
  1824. $type: "div",
  1825. class: "mdc-layout-grid__inner",
  1826. $components: [
  1827. {
  1828. $cell: true,
  1829. $type: "div",
  1830. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1831. $components: [
  1832. nodesCell
  1833. ]
  1834. }
  1835. ]
  1836. }
  1837. // <button class="mdc-button">
  1838. // Flat button
  1839. // </button>
  1840. ]
  1841. }
  1842. let clientListCell = {
  1843. $cell: true,
  1844. $type: "div",
  1845. class: "mdc-list",
  1846. id: "clientsList",
  1847. _watchNodes: [],
  1848. _listElement: function (m) {
  1849. return {
  1850. $type: "a",
  1851. class: "mdc-list-item",
  1852. $href: "#",
  1853. $text: m.name,
  1854. onclick: function (e) {
  1855. //self.currentNodeID = m.ID;
  1856. //document.querySelector('#currentNode')._setNode(m.ID);
  1857. }
  1858. }
  1859. },
  1860. $init: function () {
  1861. var t = this;
  1862. setInterval(function () {
  1863. t._updateMe();
  1864. }, 1000);
  1865. },
  1866. _updateMe: function () {
  1867. this._watchNodes = self.nodes["http://vwf.example.com/clients.vwf"].children.slice()
  1868. },
  1869. $update: function () {
  1870. //this._clientNodes
  1871. this.$components = this._watchNodes.map(this._listElement)
  1872. }
  1873. }
  1874. //createCellWindow("clientsWindow", clientListCell, "Clients");
  1875. //createCellWindow("propWindow", propWindow, "Scene");
  1876. createCellWindow("codeEditorWindow", codeEditorWindow, "Code editor");
  1877. createCellWindow("propEditorWindow", propEditorWindow, "Prop editor");
  1878. let viewSceneProps = {
  1879. $cell: true,
  1880. $type: "div",
  1881. class: "propGrid mdc-layout-grid mdc-layout-grid--align-left",
  1882. //style: "overflow-y: scroll; max-height: 500px; overflow-x: hidden;",
  1883. $components: [
  1884. {
  1885. $type: "div",
  1886. class: "mdc-layout-grid__inner",
  1887. $components: [
  1888. {
  1889. $cell: true,
  1890. $type: "div",
  1891. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1892. $components: [
  1893. nodesCell
  1894. ]
  1895. }
  1896. ]
  1897. }
  1898. ]
  1899. }
  1900. let sideBar = {
  1901. $cell: true,
  1902. $type: "div",
  1903. id: 'sideBar',
  1904. class: "sideBar mdc-toolbar-fixed-adjust",
  1905. _sideBarComponent: {},
  1906. _sideCurrentNode: '',
  1907. $init: function () {
  1908. this.style.visibility = 'hidden';
  1909. this._importScript("/" + self.getRoot() + "/appui.js");
  1910. },
  1911. _importScript: function (sSrc, fOnload) {
  1912. var oScript = document.createElement("script");
  1913. oScript.type = "text\/javascript";
  1914. oScript.async = false;
  1915. //oScript.onerror = loadError;
  1916. if (fOnload) { oScript.onload = fOnload; }
  1917. oScript.src = sSrc;
  1918. //let sideBar = document.querySelector('#sideBar');
  1919. this.appendChild(oScript);
  1920. },
  1921. _getAppDef: async function () {
  1922. let response = await fetch("/" + self.getRoot() + "/appui.js");
  1923. let data = await response.text();
  1924. //console.log(data)
  1925. return data
  1926. },
  1927. $update: function () {
  1928. this.$components = [
  1929. {
  1930. $cell: true,
  1931. $type: "button",
  1932. class: "mdc-button mdc-button--compact",
  1933. $text: "X",
  1934. onclick: function (e) {
  1935. document.querySelector('#sideBar').style.visibility = 'hidden';
  1936. }
  1937. },
  1938. this._sideBarComponent
  1939. ]
  1940. }
  1941. //$components: [this._sideComponents]
  1942. }
  1943. document.querySelector('#' + 'sideBar').$cell(sideBar)
  1944. let defaultApp = function () {
  1945. return {
  1946. $cell: true,
  1947. $type: "div",
  1948. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  1949. $components: [
  1950. {
  1951. $cell: true,
  1952. $type: "div",
  1953. class: "mdc-layout-grid__inner",
  1954. $components: [
  1955. {
  1956. $cell: true,
  1957. $type: "div",
  1958. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1959. $components: [
  1960. {
  1961. $cell: true,
  1962. $type: "h3",
  1963. class: "mdc-typography--headline",
  1964. $text: "Application",
  1965. }
  1966. ]
  1967. }
  1968. ]
  1969. }
  1970. ]
  1971. }
  1972. }
  1973. let drawerCell = {
  1974. $cell: true,
  1975. $type: "nav",
  1976. class: "mdc-temporary-drawer__drawer",
  1977. $components: [
  1978. {
  1979. $cell: true,
  1980. $type: "header",
  1981. class: "mdc-temporary-drawer__header",
  1982. $components: [
  1983. {
  1984. $cell: true,
  1985. $type: "div",
  1986. class: "mdc-temporary-drawer__header-content mdc-theme--primary-bg mdc-theme--text-primary-on-primary",
  1987. $text: "Home"
  1988. }
  1989. ]
  1990. },
  1991. {
  1992. $cell: true,
  1993. $type: "nav",
  1994. class: "mdc-temporary-drawer__content mdc-list-group",
  1995. $components: [
  1996. {
  1997. $cell: true,
  1998. $type: "div",
  1999. class: "mdc-list",
  2000. $components: [
  2001. {
  2002. $cell: true,
  2003. $type: "a",
  2004. class: "mdc-list-item",
  2005. $href: "#",
  2006. onclick: function (e) {
  2007. let sideBar = document.querySelector('#sideBar');
  2008. try {
  2009. sideBar._sideBarComponent = createApp.call(self);
  2010. } catch (e) {
  2011. sideBar._sideBarComponent = defaultApp();
  2012. }
  2013. drawer.open = !drawer.open
  2014. document.querySelector('#sideBar').style.visibility = 'visible';
  2015. },
  2016. $components: [{
  2017. $type: "i",
  2018. class: "material-icons mdc-list-item__start-detail",
  2019. 'aria-hidden': "true",
  2020. $text: "play_arrow"
  2021. },
  2022. {
  2023. $text: "App"
  2024. }]
  2025. },
  2026. {
  2027. $cell: true,
  2028. $type: "a",
  2029. class: "mdc-list-item",
  2030. $href: "#",
  2031. onclick: function (e) {
  2032. let sideBar = document.querySelector('#sideBar');
  2033. sideBar._sideBarComponent = viewSceneProps;
  2034. let currentNode = document.querySelector('#sideBar')._sideCurrentNode;
  2035. currentNode == '' ? document.querySelector('#sideBar')._sideCurrentNode = (vwf_view.kernel.find("", "/")[0]) :
  2036. document.querySelector('#sideBar')._sideCurrentNode = currentNode;
  2037. document.querySelector('#sideBar').style.visibility = 'visible';
  2038. drawer.open = !drawer.open
  2039. // let currentNode = document.querySelector('#currentNode')._currentNode;
  2040. // currentNode == '' ? document.querySelector('#currentNode')._setNode(vwf_view.kernel.find("", "/")[0]) :
  2041. // document.querySelector('#currentNode')._setNode(currentNode);
  2042. },
  2043. $components: [{
  2044. $cell: true,
  2045. $type: "i",
  2046. class: "material-icons mdc-list-item__start-detail",
  2047. $text: "description"
  2048. },
  2049. {
  2050. $text: "Scene"
  2051. }
  2052. ]
  2053. },
  2054. {
  2055. $cell: true,
  2056. $type: "a",
  2057. class: "mdc-list-item",
  2058. $href: "#",
  2059. onclick: function (e) {
  2060. // var currentNode = document.querySelector('#currentNode')._currentNode;
  2061. // if (currentNode == '') {
  2062. // currentNode = vwf_view.kernel.find("", "/")[0];
  2063. // }
  2064. document.querySelector('#liveCodeEditor')._setNode(vwf_view.kernel.find("", "/")[0]);
  2065. //createAceEditor(self, currentNode);
  2066. document.querySelector('#codeEditorWindow').style.visibility = 'visible';
  2067. },
  2068. $components: [{
  2069. $type: "i",
  2070. class: "material-icons mdc-list-item__start-detail",
  2071. 'aria-hidden': "true",
  2072. $text: "code"
  2073. },
  2074. {
  2075. $text: "Code editor"
  2076. }]
  2077. },
  2078. {
  2079. $cell: true,
  2080. $type: "a",
  2081. class: "mdc-list-item",
  2082. $href: "#",
  2083. onclick: function (e) {
  2084. //self.currentNodeID = m.ID;
  2085. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  2086. // document.querySelector('#clientsWindow').style.visibility = 'visible';
  2087. let sideBar = document.querySelector('#sideBar');
  2088. sideBar._sideBarComponent = avatarSettings;
  2089. drawer.open = !drawer.open
  2090. document.querySelector('#sideBar').style.visibility = 'visible';
  2091. },
  2092. $components: [{
  2093. $type: "i",
  2094. class: "material-icons mdc-list-item__start-detail",
  2095. 'aria-hidden': "true",
  2096. $text: "account_circle"
  2097. },
  2098. {
  2099. $text: "My Avatar"
  2100. }]
  2101. },
  2102. {
  2103. $cell: true,
  2104. $type: "a",
  2105. class: "mdc-list-item",
  2106. $href: "#",
  2107. onclick: function (e) {
  2108. //self.currentNodeID = m.ID;
  2109. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  2110. let sideBar = document.querySelector('#sideBar');
  2111. sideBar._sideBarComponent = viewSettings;
  2112. drawer.open = !drawer.open
  2113. document.querySelector('#sideBar').style.visibility = 'visible';
  2114. },
  2115. $components: [{
  2116. $type: "i",
  2117. class: "material-icons mdc-list-item__start-detail",
  2118. 'aria-hidden': "true",
  2119. $text: "settings"
  2120. },
  2121. {
  2122. $text: "Settings"
  2123. }]
  2124. },
  2125. {
  2126. $cell: true,
  2127. $type: "a",
  2128. class: "mdc-list-item",
  2129. $href: "#",
  2130. onclick: function (e) {
  2131. //self.currentNodeID = m.ID;
  2132. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  2133. let sideBar = document.querySelector('#sideBar');
  2134. sideBar._sideBarComponent = loadSaveSettings;
  2135. if (document.querySelector('#loadSaveSettings')) {
  2136. document.querySelector('#loadSaveSettings')._getStates();
  2137. }
  2138. //sideBar._sideBarComponent._getStates();
  2139. drawer.open = !drawer.open
  2140. document.querySelector('#sideBar').style.visibility = 'visible';
  2141. },
  2142. $components: [{
  2143. $type: "i",
  2144. class: "material-icons mdc-list-item__start-detail",
  2145. 'aria-hidden': "true",
  2146. $text: "save"
  2147. },
  2148. {
  2149. $text: "Load/Save"
  2150. }]
  2151. }
  2152. ]
  2153. },
  2154. {
  2155. $cell: true,
  2156. $type: "hr",
  2157. class: "mdc-list-divider",
  2158. },
  2159. {
  2160. $cell: true,
  2161. $type: "h3",
  2162. class: "userList mdc-list-group__subheader",
  2163. $text: "Users online"
  2164. },
  2165. clientListCell
  2166. ]
  2167. }
  2168. // {
  2169. // $cell: true,
  2170. // $type: "div",
  2171. // class: "mdc-persistent-drawer__toolbar-spacer",
  2172. // },
  2173. // {
  2174. // $cell: true,
  2175. // $type: "div",
  2176. // class: "mdc-list-group",
  2177. // $components: [{
  2178. // $cell: true,
  2179. // $type: "nav",
  2180. // class: "mdc-list",
  2181. // $components: [
  2182. // ]
  2183. // }]
  2184. // }
  2185. ]
  2186. };
  2187. // <div class="mdc-form-field">
  2188. // <input type="checkbox" id="input">
  2189. // <label for="input">Input Label</label>
  2190. // </div>
  2191. document.querySelector("#drawer").$cell({
  2192. $cell: true,
  2193. $type: "aside",
  2194. class: "mdc-temporary-drawer",
  2195. $components: [drawerCell]
  2196. }
  2197. );
  2198. let toolbar = {
  2199. $cell: true,
  2200. $type: "div",
  2201. class: "mdc-toolbar__row",
  2202. $components: [{
  2203. $type: "section",
  2204. class: "mdc-toolbar__section mdc-toolbar__section--align-start",
  2205. $components: [
  2206. {
  2207. $type: "button",
  2208. class: "demo-menu material-icons mdc-toolbar__icon--menu",
  2209. $text: "menu"
  2210. },
  2211. {
  2212. $type: "span",
  2213. class: "mdc-toolbar__title catalog-title",
  2214. $text: "LiveCoding.space"
  2215. }
  2216. ]
  2217. }]
  2218. };
  2219. document.querySelector("#toolbar").$cell({
  2220. $cell: true,
  2221. $type: "div",
  2222. class: "mdc-toolbar mdc-toolbar--fixed",
  2223. $components: [toolbar]
  2224. }
  2225. );
  2226. // let drawer = new mdc.drawer.MDCTemporaryDrawer(document.querySelector('.mdc-temporary-drawer'));
  2227. // document.querySelector('.menu').addEventListener('click', () => drawer.open = true);
  2228. var drawerEl = document.querySelector('.mdc-temporary-drawer');
  2229. var MDCTemporaryDrawer = mdc.drawer.MDCTemporaryDrawer;
  2230. var drawer = new MDCTemporaryDrawer(drawerEl);
  2231. document.querySelector('.demo-menu').addEventListener('click', function () {
  2232. //self.currentNodeID = (self.currentNodeID == '') ? (vwf_view.kernel.find("", "/")[0]) : self.currentNodeID;
  2233. // let currentNode = document.querySelector('#currentNode')._currentNode;
  2234. // currentNode == '' ? document.querySelector('#currentNode')._setNode(vwf_view.kernel.find("", "/")[0]) :
  2235. // document.querySelector('#currentNode')._setNode(currentNode);
  2236. //document.querySelector('#currentNode')._setNode(self.currentNodeID);
  2237. drawer.open = !drawer.open;
  2238. });
  2239. drawerEl.addEventListener('MDCTemporaryDrawer:open', function () {
  2240. //console.log('Received MDCPersistentDrawer:open');
  2241. });
  2242. drawerEl.addEventListener('MDCTemporaryDrawer:close', function () {
  2243. //console.log('Received MDCPersistentDrawer:close');
  2244. });
  2245. //==============
  2246. },
  2247. createdNode: function (nodeID, childID, childExtendsID, childImplementsIDs,
  2248. childSource, childType, childIndex, childName, callback /* ( ready ) */) {
  2249. var nodeIDAttribute = $.encoder.encodeForHTMLAttribute("id", nodeID, true);
  2250. var childIDAttribute = $.encoder.encodeForHTMLAttribute("id", childID, true);
  2251. var childIDAlpha = $.encoder.encodeForAlphaNumeric(childID);
  2252. var kernel = this.kernel;
  2253. var self = this;
  2254. var parent = this.nodes[nodeID];
  2255. var node = this.nodes[childID] = {
  2256. children: [],
  2257. properties: [],
  2258. events: {},
  2259. methods: {},
  2260. parent: parent,
  2261. parentID: nodeID,
  2262. ID: childID,
  2263. extendsID: childExtendsID,
  2264. implementsIDs: childImplementsIDs,
  2265. source: childSource,
  2266. name: childName,
  2267. };
  2268. if (parent) {
  2269. parent.children.push(node);
  2270. }
  2271. if (childID == vwf_view.kernel.find("", "/")[0] && childExtendsID && this.kernel.test(childExtendsID,
  2272. "self::element(*,'http://vwf.example.com/aframe/ascene.vwf')", childExtendsID)) {
  2273. this.scenes[childID] = node;
  2274. }
  2275. let nodeCell = document.querySelector("#currentNode");
  2276. if (nodeCell !== null) {
  2277. if (nodeCell._currentNode === nodeID) {
  2278. nodeCell._getChildNodes();
  2279. }
  2280. }
  2281. if (nodeID === this.kernel.application()) {
  2282. // document.querySelector('a-scene').classList.add("mdc-toolbar-fixed-adjust");
  2283. document.querySelector('body').classList.add("editor-body");
  2284. }
  2285. },
  2286. createdProperty: function (nodeID, propertyName, propertyValue) {
  2287. return this.initializedProperty(nodeID, propertyName, propertyValue);
  2288. },
  2289. initializedProperty: function (nodeID, propertyName, propertyValue) {
  2290. var node = this.nodes[nodeID];
  2291. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  2292. var property = node.properties[propertyName] = createProperty.call(this, node, propertyName, propertyValue);
  2293. node.properties.push(property);
  2294. },
  2295. deletedNode: function (nodeID) {
  2296. var node = this.nodes[nodeID];
  2297. node.parent.children.splice(node.parent.children.indexOf(node), 1);
  2298. delete this.nodes[nodeID];
  2299. let nodeCell = document.querySelector("#currentNode");
  2300. if (nodeCell) {
  2301. if (nodeCell._currentNode !== "") {
  2302. if (nodeCell._currentNode !== nodeID) {
  2303. //&& (this.nodes[nodeID] !== undefined)
  2304. nodeCell._getChildNodes();
  2305. } else {
  2306. nodeCell._setNode(vwf_view.kernel.find("", "/")[0]);
  2307. nodeCell._getChildNodes();
  2308. }
  2309. }
  2310. }
  2311. },
  2312. //addedChild: [ /* nodeID, childID, childName */ ],
  2313. //removedChild: [ /* nodeID, childID */ ],
  2314. satProperty: function (nodeID, propertyName, propertyValue) {
  2315. var node = this.nodes[nodeID];
  2316. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  2317. // It is possible for a property to have satProperty called for it without ever getting an
  2318. // initializedProperty (if that property delegated to itself or another on replication)
  2319. // Catch that case here and create the property
  2320. if (!node.properties[propertyName]) {
  2321. var property = node.properties[propertyName] = createProperty.call(this, node, propertyName, propertyValue);
  2322. node.properties.push(property);
  2323. }
  2324. try {
  2325. propertyValue = utility.transform(propertyValue, utility.transforms.transit);
  2326. node.properties[propertyName].value = JSON.stringify(propertyValue);
  2327. node.properties[propertyName].rawValue = propertyValue;
  2328. } catch (e) {
  2329. this.logger.warnx("satProperty", nodeID, propertyName, propertyValue,
  2330. "stringify error:", e.message);
  2331. node.properties[propertyName].value = propertyValue;
  2332. }
  2333. let nodeCell = document.querySelector('#currentNode');
  2334. if (nodeCell !== null) {
  2335. if (nodeCell._currentNode == nodeID && propertyName == 'edit') {
  2336. console.log('EDIT !!!')
  2337. }
  2338. }
  2339. let propCell = document.querySelector("#currentNode #prop-" + propertyName);
  2340. if (propCell !== null) {
  2341. if (propCell._currentNode == nodeID) {
  2342. propCell.value = node.properties[propertyName].getValue();
  2343. }
  2344. }
  2345. },
  2346. //gotProperty: [ /* nodeID, propertyName, propertyValue */ ],
  2347. gotProperty: function (nodeID, propertyName, propertyValue) {
  2348. var node = this.nodes[nodeID];
  2349. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  2350. let nodeCell = document.querySelector('#currentNode');
  2351. if (nodeCell !== null) {
  2352. if (nodeCell._currentNode == nodeID && propertyName == 'edit') {
  2353. let editCheckBox = document.querySelector("#currentNode #editnode");
  2354. if (editCheckBox) {
  2355. if (propertyValue) {
  2356. editCheckBox.setAttribute('checked', '');
  2357. } else {
  2358. let checkAttr = editCheckBox.getAttribute('checked');
  2359. if (checkAttr) editCheckBox.removeAttribute('checked');
  2360. }
  2361. }
  2362. console.log('EDIT !!! is ' + propertyValue)
  2363. }
  2364. }
  2365. },
  2366. createdMethod: function (nodeID, methodName, methodParameters, methodBody) {
  2367. var node = this.nodes[nodeID];
  2368. if (node) {
  2369. node.methods[methodName] = methodParameters;
  2370. }
  2371. },
  2372. //calledMethod: function( nodeID, methodName, methodParameters, methodValue ) {
  2373. //},
  2374. createdEvent: function (nodeID, eventName, eventParameters) {
  2375. var node = this.nodes[nodeID];
  2376. if (node) {
  2377. node.events[eventName] = eventParameters;
  2378. }
  2379. },
  2380. firedEvent: function (nodeID, eventName, eventParameters) {
  2381. },
  2382. executed: function (nodeID, scriptText, scriptType) {
  2383. // var nodeScript = {
  2384. // text: scriptText,
  2385. // type: scriptType,
  2386. // };
  2387. // if ( !this.allScripts[ nodeID ] ) {
  2388. // var nodeScripts = new Array();
  2389. // nodeScripts.push(nodeScript);
  2390. // this.allScripts[ nodeID ] = nodeScripts;
  2391. // }
  2392. // else {
  2393. // this.allScripts[ nodeID ].push(nodeScript);
  2394. // }
  2395. },
  2396. //ticked: [ /* time */ ],
  2397. });
  2398. function createCellWindow(elementID, cellNode, title) {
  2399. document.querySelector('#' + elementID).$cell({
  2400. $cell: true,
  2401. $type: "div",
  2402. id: elementID,
  2403. class: 'draggable',
  2404. $init: function () {
  2405. // let draggie = new Draggabilly('.draggable', {
  2406. // handle: '.handle',
  2407. // containment: true
  2408. // });
  2409. // get all draggie elements
  2410. var draggableElems = document.querySelectorAll('.draggable');
  2411. // array of Draggabillies
  2412. var draggies = []
  2413. // init Draggabillies
  2414. for (var i = 0, len = draggableElems.length; i < len; i++) {
  2415. var draggableElem = draggableElems[i];
  2416. var draggie = new Draggabilly(draggableElem, {
  2417. handle: '.handle',
  2418. containment: true
  2419. });
  2420. draggies.push(draggie);
  2421. }
  2422. this.style.visibility = 'hidden';
  2423. },
  2424. $components: [
  2425. {
  2426. $cell: true,
  2427. $type: "div",
  2428. class: "handle",
  2429. $components: [
  2430. {
  2431. $cell: true,
  2432. $type: "button",
  2433. class: "mdc-button mdc-button--compact",
  2434. $text: "X",
  2435. onclick: function (e) {
  2436. //self.currentNodeID = m.ID;
  2437. document.querySelector('#' + elementID).style.visibility = 'hidden';
  2438. }
  2439. },
  2440. {
  2441. $cell: true,
  2442. $type: "span",
  2443. class: "mdc-typography--button",
  2444. $text: title
  2445. }
  2446. ]
  2447. },
  2448. cellNode,
  2449. {
  2450. $cell: true,
  2451. $type: "div",
  2452. class: "handle",
  2453. style: "height: 10px; width: inherit;",
  2454. //$text: "sdfsdf"
  2455. }
  2456. // { $text: "23423"}
  2457. ]
  2458. }
  2459. );
  2460. }
  2461. // -- getChildByName --------------------------------------------------------------------
  2462. function getChildByName(node, childName) {
  2463. var childNode = undefined;
  2464. for (var i = 0; i < node.children.length && childNode === undefined; i++) {
  2465. if (node.children[i].name == childName) {
  2466. childNode = node.children[i];
  2467. }
  2468. }
  2469. return childNode;
  2470. };
  2471. // -- viewScript ------------------------------------------------------------------------
  2472. function createAceEditor(view, nodeID, elID) {
  2473. var editor = view.ace.edit(elID);
  2474. editor.setTheme("ace/theme/monokai");
  2475. editor.setFontSize(16);
  2476. editor.getSession().setMode("ace/mode/javascript");
  2477. editor.commands.addCommand({
  2478. name: "doit",
  2479. bindKey: { win: "Ctrl-e", mac: "Command-e" },
  2480. exec: function () {
  2481. codeEditorDoit(editor, nodeID);
  2482. }
  2483. });
  2484. editor.commands.addCommand({
  2485. name: "printit",
  2486. bindKey: { win: "Ctrl-b", mac: "Command-b" },
  2487. exec: function () {
  2488. codeEditorPrintit(editor, nodeID);
  2489. }
  2490. });
  2491. return editor;
  2492. }
  2493. function getPrototypes(kernel, extendsID) {
  2494. var prototypes = [];
  2495. var id = extendsID;
  2496. while (id !== undefined) {
  2497. prototypes.push(id);
  2498. id = kernel.prototype(id);
  2499. }
  2500. return prototypes;
  2501. }
  2502. function getPrototypes(kernel, extendsID) {
  2503. var prototypes = [];
  2504. var id = extendsID;
  2505. while (id !== undefined) {
  2506. prototypes.push(id);
  2507. id = kernel.prototype(id);
  2508. }
  2509. return prototypes;
  2510. }
  2511. function createProperty(node, propertyName, propertyValue) {
  2512. var property = {
  2513. name: propertyName,
  2514. rawValue: propertyValue,
  2515. value: undefined,
  2516. getValue: function () {
  2517. var propertyValue;
  2518. if (this.value == undefined) {
  2519. try {
  2520. propertyValue = utility.transform(this.rawValue, utility.transforms.transit);
  2521. this.value = JSON.stringify(propertyValue);
  2522. } catch (e) {
  2523. this.logger.warnx("createdProperty", nodeID, this.propertyName, this.rawValue,
  2524. "stringify error:", e.message);
  2525. this.value = this.rawValue;
  2526. }
  2527. }
  2528. return this.value;
  2529. }
  2530. };
  2531. return property;
  2532. }
  2533. function getProperties(kernel, extendsID) {
  2534. var pTypes = getPrototypes(kernel, extendsID);
  2535. var pProperties = {};
  2536. if (pTypes) {
  2537. for (var i = 0; i < pTypes.length; i++) {
  2538. var nd = this.nodes[pTypes[i]];
  2539. if (nd && nd.properties) {
  2540. for (var key in nd.properties) {
  2541. pProperties[key] = { "prop": nd.properties[key], "prototype": pTypes[i] };
  2542. }
  2543. }
  2544. }
  2545. }
  2546. return pProperties;
  2547. }
  2548. function getChildren(kernel, extendsID) {
  2549. var pTypes = getPrototypes(kernel, extendsID);
  2550. var pChildren = {};
  2551. if (pTypes) {
  2552. for (var i = 0; i < pTypes.length; i++) {
  2553. var nd = this.nodes[pTypes[i]];
  2554. if (nd && nd.children) {
  2555. for (var key in nd.children) {
  2556. pChildren[key] = nd.children[key];
  2557. }
  2558. }
  2559. }
  2560. }
  2561. return pChildren;
  2562. }
  2563. function getEvents(kernel, extendsID) {
  2564. var pTypes = getPrototypes(kernel, extendsID);
  2565. var events = {};
  2566. if (pTypes) {
  2567. for (var i = 0; i < pTypes.length; i++) {
  2568. var nd = this.nodes[pTypes[i]];
  2569. if (nd && nd.events) {
  2570. for (var key in nd.events) {
  2571. events[key] = nd.events[key];
  2572. }
  2573. }
  2574. }
  2575. }
  2576. return events;
  2577. }
  2578. function getMethods(kernel, extendsID) {
  2579. var pTypes = getPrototypes(kernel, extendsID);
  2580. var methods = {};
  2581. if (pTypes) {
  2582. for (var i = 0; i < pTypes.length; i++) {
  2583. var nd = this.nodes[pTypes[i]];
  2584. if (nd && nd.methods) {
  2585. for (var key in nd.methods) {
  2586. methods[key] = nd.methods[key];
  2587. }
  2588. }
  2589. }
  2590. }
  2591. return methods;
  2592. }
  2593. // -- Show Code Editor tab
  2594. function codeEditorDoit(editor, nodeID) {
  2595. var selectedText = editor.getSession().doc.getTextRange(editor.selection.getRange());
  2596. if (selectedText == "") {
  2597. var currline = editor.getSelectionRange().start.row;
  2598. var selectedText = editor.session.getLine(currline);
  2599. }
  2600. //console.log(selectedText);
  2601. //var sceneID = self.kernel.application();
  2602. vwf_view.kernel.execute(nodeID, selectedText);
  2603. }
  2604. function codeEditorPrintit(editor, nodeID) {
  2605. var selectedText = editor.getSession().doc.getTextRange(editor.selection.getRange());
  2606. if (selectedText == "") {
  2607. var currline = editor.getSelectionRange().start.row;
  2608. var selectedText = editor.session.getLine(currline);
  2609. }
  2610. //console.log(selectedText);
  2611. //var sceneID = self.kernel.application();
  2612. let scriptText = 'console.log(' + selectedText + ');'
  2613. self.kernel.execute(nodeID, scriptText);
  2614. }
  2615. function saveStateAsFile(filename) // invoke with the view as "this"
  2616. {
  2617. this.logger.info("Saving: " + filename);
  2618. var clients = this.nodes["http://vwf.example.com/clients.vwf"];
  2619. if (supportAjaxUploadWithProgress.call(this)) {
  2620. var xhr = new XMLHttpRequest();
  2621. // Save State Information
  2622. var state = vwf.getState();
  2623. state.nodes[0].children = {};
  2624. var timestamp = state["queue"].time;
  2625. timestamp = Math.round(timestamp * 1000);
  2626. var objectIsTypedArray = function (candidate) {
  2627. var typedArrayTypes = [
  2628. Int8Array,
  2629. Uint8Array,
  2630. // Uint8ClampedArray,
  2631. Int16Array,
  2632. Uint16Array,
  2633. Int32Array,
  2634. Uint32Array,
  2635. Float32Array,
  2636. Float64Array
  2637. ];
  2638. var isTypedArray = false;
  2639. if (typeof candidate == "object" && candidate != null) {
  2640. typedArrayTypes.forEach(function (typedArrayType) {
  2641. isTypedArray = isTypedArray || candidate instanceof typedArrayType;
  2642. });
  2643. }
  2644. return isTypedArray;
  2645. };
  2646. var transitTransformation = function (object) {
  2647. return objectIsTypedArray(object) ?
  2648. Array.prototype.slice.call(object) : object;
  2649. };
  2650. var json = JSON.stringify(
  2651. require("vwf/utility").transform(
  2652. state, transitTransformation
  2653. )
  2654. );
  2655. json = $.encoder.encodeForURL(json);
  2656. var path = window.location.pathname;
  2657. var pathSplit = path.split('/');
  2658. if (pathSplit[0] == "") {
  2659. pathSplit.shift();
  2660. }
  2661. if (pathSplit[pathSplit.length - 1] == "") {
  2662. pathSplit.pop();
  2663. }
  2664. var inst = undefined;
  2665. var instIndex = pathSplit.length - 1;
  2666. if (pathSplit.length > 2) {
  2667. if (pathSplit[pathSplit.length - 2] == "load") {
  2668. instIndex = pathSplit.length - 3;
  2669. }
  2670. }
  2671. if (pathSplit.length > 3) {
  2672. if (pathSplit[pathSplit.length - 3] == "load") {
  2673. instIndex = pathSplit.length - 4;
  2674. }
  2675. }
  2676. inst = pathSplit[instIndex];
  2677. var root = "";
  2678. for (var i = 0; i < instIndex; i++) {
  2679. if (root != "") {
  2680. root = root + "/";
  2681. }
  2682. root = root + pathSplit[i];
  2683. }
  2684. if (filename == '') filename = inst;
  2685. if (root.indexOf('.vwf') != -1) root = root.substring(0, root.lastIndexOf('/'));
  2686. xhr.open("POST", "/" + root + "/save/" + filename, true);
  2687. xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  2688. xhr.send("root=" + root + "/" + filename + "&filename=saveState&inst=" + inst + "&timestamp=" + timestamp + "&extension=.vwf.json" + "&jsonState=" + json);
  2689. // Save Config Information
  2690. var config = { "info": {}, "model": {}, "view": {} };
  2691. // Save browser title
  2692. config["info"]["title"] = document.title//$('title').html();
  2693. // Save model drivers
  2694. Object.keys(vwf_view.kernel.kernel.models).forEach(function (modelDriver) {
  2695. if (modelDriver.indexOf('vwf/model/') != -1) config["model"][modelDriver] = "";
  2696. });
  2697. // If neither glge or threejs model drivers are defined, specify nodriver
  2698. if (config["model"]["vwf/model/glge"] === undefined && config["model"]["vwf/model/threejs"] === undefined) config["model"]["nodriver"] = "";
  2699. // Save view drivers and associated parameters, if any
  2700. Object.keys(vwf_view.kernel.kernel.views).forEach(function (viewDriver) {
  2701. if (viewDriver.indexOf('vwf/view/') != -1) {
  2702. if (vwf_view.kernel.kernel.views[viewDriver].parameters) {
  2703. config["view"][viewDriver] = vwf_view.kernel.kernel.views[viewDriver].parameters;
  2704. }
  2705. else config["view"][viewDriver] = "";
  2706. }
  2707. });
  2708. var jsonConfig = $.encoder.encodeForURL(JSON.stringify(config));
  2709. // Save config file to server
  2710. var xhrConfig = new XMLHttpRequest();
  2711. xhrConfig.open("POST", "/" + root + "/save/" + filename, true);
  2712. xhrConfig.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  2713. xhrConfig.send("root=" + root + "/" + filename + "&filename=saveState&inst=" + inst + "&timestamp=" + timestamp + "&extension=.vwf.config.json" + "&jsonState=" + jsonConfig);
  2714. }
  2715. else {
  2716. console.error("Unable to save state.");
  2717. }
  2718. }
  2719. // -- LoadSavedState --------------------------------------------------------------------------
  2720. function loadSavedState(filename, applicationpath, revision) {
  2721. this.logger.info("Loading: " + filename);
  2722. // Redirect until setState ID conflict is resolved
  2723. var path = window.location.pathname;
  2724. var inst = path.substring(path.length - 17, path.length - 1);
  2725. var pathSplit = path.split('/');
  2726. if (pathSplit[0] == "") {
  2727. pathSplit.shift();
  2728. }
  2729. if (pathSplit[pathSplit.length - 1] == "") {
  2730. pathSplit.pop();
  2731. }
  2732. var inst = undefined;
  2733. var instIndex = pathSplit.length - 1;
  2734. if (pathSplit.length > 2) {
  2735. if (pathSplit[pathSplit.length - 2] == "load") {
  2736. instIndex = pathSplit.length - 3;
  2737. }
  2738. }
  2739. if (pathSplit.length > 3) {
  2740. if (pathSplit[pathSplit.length - 3] == "load") {
  2741. instIndex = pathSplit.length - 4;
  2742. }
  2743. }
  2744. inst = pathSplit[instIndex];
  2745. if (revision) {
  2746. window.location.pathname = applicationpath + "/" + inst + '/load/' + filename + '/' + revision + '/';
  2747. }
  2748. else {
  2749. window.location.pathname = applicationpath + "/" + inst + '/load/' + filename + '/';
  2750. }
  2751. // $.get(filename,function(data,status){
  2752. // vwf.setState(data);
  2753. // });
  2754. }
  2755. // -- SupportAjax -----------------------------------------------------------------------------
  2756. function supportAjaxUploadWithProgress() {
  2757. return supportAjaxUploadProgressEvents();
  2758. function supportAjaxUploadProgressEvents() {
  2759. var xhr = new XMLHttpRequest();
  2760. return !!(xhr && ('upload' in xhr) && ('onprogress' in xhr.upload));
  2761. }
  2762. }
  2763. });