From 0efbbf8287517b755be1774f6aa49947bed50a0d Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Thu, 7 Jun 2012 11:24:29 -0700 Subject: Adding unique ID to canvas data folders Also set up for tracking ID created, will be adding support for parsing files without saving later, but flag is now present. --- js/document/mediators/template.js | 49 ++++++++++++++++++++++----------------- js/document/models/base.js | 33 ++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 23 deletions(-) (limited to 'js/document') diff --git a/js/document/mediators/template.js b/js/document/mediators/template.js index 068a1f48..c9d46f79 100755 --- a/js/document/mediators/template.js +++ b/js/document/mediators/template.js @@ -8,7 +8,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot // var Montage = require("montage/core/core").Montage, Component = require("montage/ui/component").Component, - TemplateCreator = require("node_modules/tools/template/template-creator").TemplateCreator; + TemplateCreator = require("node_modules/tools/template/template-creator").TemplateCreator, + ClassUuid = require("js/components/core/class-uuid").ClassUuid; //////////////////////////////////////////////////////////////////////// // exports.TemplateDocumentMediator = Montage.create(Component, { @@ -93,7 +94,7 @@ exports.TemplateDocumentMediator = Montage.create(Component, { //////////////////////////////////////////////////////////////////// //TODO: Expand to allow more templates, clean up variables parseNinjaTemplateToHtml: { - value: function (template, ninjaWrapper, libCopyCallback) { + value: function (saveExternalData, template, ninjaWrapper, libCopyCallback) { //TODO: Improve reference for rootUrl var regexRootUrl, rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])), @@ -328,7 +329,7 @@ exports.TemplateDocumentMediator = Montage.create(Component, { - //TODO: Make proper webGL/Canvas method + // var webgltag, webgllibtag, webglrdgetag, mjstag, mjslibtag, matchingtags = [], @@ -357,19 +358,33 @@ exports.TemplateDocumentMediator = Montage.create(Component, { } } } + + + + + //TODO: Make proper webGL/Canvas method + + //Checking for webGL elements in document if (template.webgl && template.webgl.length > 1) {//TODO: Should be length 0, hack for a temp fix var rdgeDirName, rdgeVersion, cvsDataDir = this.getCanvasDirectory(template.file.root), fileCvsDir, fileCvsDirAppend, cvsDirCounter = 1, fileOrgDataSrc; // if (cvsDataDir && !matchingtags.length && !webgllibtag) { - fileCvsDir = cvsDataDir+template.file.name.split('.'+template.file.extension)[0]; + + if (template.libs.canvasId) { + libsobserver.canvasId = template.libs.canvasId; + } else { + libsobserver.canvasId = ClassUuid.generate(); + } + + //Creating data directory, will include materials at a later time + fileCvsDir = cvsDataDir+template.file.name.split('.'+template.file.extension)[0]+'_'+libsobserver.canvasId; + if (!this._getUserDirectory(fileCvsDir)) { - fileCvsDirAppend = fileCvsDir+cvsDirCounter; - while (!this._getUserDirectory(fileCvsDirAppend)) { - fileCvsDirAppend = fileCvsDir+(cvsDirCounter++); - } + //TODO: create proper logic not to overwrite files + console.log('error'); } - //TODO: Allow user overwrite + fileCvsDir += '/'; } else if (webgllibtag && webgllibtag.getAttribute && webgllibtag.getAttribute('data-ninja-canvas-json') !== null) { fileOrgDataSrc = template.file.root+webgllibtag.getAttribute('data-ninja-canvas-json'); @@ -437,17 +452,9 @@ exports.TemplateDocumentMediator = Montage.create(Component, { //Looping through data to create escaped array for (var j = 0; template.webgl[j]; j++) { if (j === 0) { - //if (fileCvsDir) { - // json += '\n\t\t\t"' + template.webgl[j] + '"'; - //} else { - json += '\n\t\t\t"' + escape(template.webgl[j]) + '"'; - //} + json += '\n\t\t\t"' + escape(template.webgl[j]) + '"'; } else { - //if (fileCvsDir) { - // json += ',\n\t\t\t"' + template.webgl[j] + '"'; - //} else { - json += ',\n\t\t\t"' + escape(template.webgl[j]) + '"'; - //} + json += ',\n\t\t\t"' + escape(template.webgl[j]) + '"'; } } //Closing array (make-shift JSON string to validate data in