From 4ca5e2e0a383ef19d763f293998d31c195d80810 Mon Sep 17 00:00:00 2001 From: Matthew Conlen Date: Sat, 5 Dec 2015 16:30:24 -0500 Subject: [PATCH 01/11] remove logic for non-module visualizations --- app/controllers/static.js | 112 +------ app/controllers/visualizationTypes.js | 186 ++--------- app/models/visualizationtype.js | 314 +++++------------- app/views/embed-layout.jade | 1 - app/views/layout.jade | 3 +- app/views/session/feed-public.jade | 4 - app/views/session/feed.jade | 5 - app/views/session/visualization-embed.jade | 4 - app/views/session/visualization-iframe.jade | 4 - app/views/session/visualization-public.jade | 6 - app/views/session/visualization-pym.jade | 4 - app/views/session/visualization.jade | 4 - app/views/viz-types/editor.jade | 4 - app/views/viz-types/preview-editor.jade | 5 - config/routes.js | 15 +- .../visualization-importer/index.js | 38 +-- .../sources/git-repo.js | 134 -------- .../visualization-importer/sources/index.js | 4 +- .../sources/local-folder.js | 134 -------- .../visualization-importer/sources/npm.js | 18 +- ui/js/utils/index.js | 7 +- 21 files changed, 153 insertions(+), 853 deletions(-) delete mode 100644 ui/js/components/visualization-importer/sources/git-repo.js delete mode 100644 ui/js/components/visualization-importer/sources/local-folder.js diff --git a/app/controllers/static.js b/app/controllers/static.js index 4d273b53..d4cf32f4 100644 --- a/app/controllers/static.js +++ b/app/controllers/static.js @@ -41,43 +41,28 @@ exports.getDynamicVizBundle = function (req, res, next) { models.VisualizationType .findAll().then(function(vizTypes) { + debug('Found ' + vizTypes.length + ' visualization types'); - var funcs = []; - _.each(vizTypes, function(vizType) { - if(!vizType.isModule) { - funcs.push(vizType.exportToFS(tmpPath)); - } - }); - Q.all(funcs).spread(function() { - - _.each(_.filter(vizTypes, function(vizType) { return (visualizationTypes.indexOf(vizType.name) > -1); }), function(vizType) { - if(vizType.isModule) { - debug(vizType.moduleName); - b.require(vizType.moduleName, { - expose: vizType.moduleName - }); - } else { - var stream = resumer().queue(vizType.javascript).end(); - b.require(stream, { - basedir: tmpPath, - expose: vizType.name - }); - } + _.each(_.filter(vizTypes, function(vizType) { return (visualizationTypes.indexOf(vizType.name) > -1); }), function(vizType) { + debug(vizType.moduleName); + b.require(vizType.moduleName, { + expose: vizType.moduleName }); + }); - b.bundle(function(err, buf) { - if(err) { - return next(err); - } + b.bundle(function(err, buf) { + if(err) { + return next(err); + } - var out = buf.toString('utf8'); - cache.put('js/' + visualizationTypes.toString(), out, 1000 * 60 * 10); - if(!cacheHit) { - res.send(out); - } - }); + var out = buf.toString('utf8'); + cache.put('js/' + visualizationTypes.toString(), out, 1000 * 60 * 10); + if(!cacheHit) { + res.send(out); + } }); + }).error(function(err) { return res.status(500).send(err.message).end(); }); @@ -86,9 +71,9 @@ exports.getDynamicVizBundle = function (req, res, next) { exports.bundleJSForExecution = function(req, res, next) { - + res.set('Content-Type', 'application/javascript'); - + var b = browserify({ paths: [ config.root + '/node_modules'] }); @@ -110,64 +95,3 @@ exports.bundleJSForExecution = function(req, res, next) { }; - - - -exports.buildSCSS = function(req, res) { - res.set('Content-Type', 'text/css'); - - var scssData = '#lightning-body {\n'; - scssData += req.body.styles + '\n'; - scssData += '\n}'; - - sass.render({ - data: scssData, - success: function(sassResultss) { - res.send(sassResultss.css); - } - }); -}; - - -exports.getDynamicVizStyles = function (req, res, next) { - - res.set('Content-Type', 'text/css'); - - - // Get all vizTypes in array - var visualizationTypes = _.uniq(req.query.visualizations).sort(); - var styles = cache.get('css/' + visualizationTypes.toString()); - - if(styles) { - return res.send(styles); - } - - debug('building viz styles with ' + visualizationTypes); - - models.VisualizationType - .findAll({ - where: { - name: { - in: visualizationTypes - } - } - }).then(function(vizTypes) { - - var scssData = '#lightning-body {\n'; - _.each(vizTypes, function(vizType) { - if(vizType.styles) { - scssData += vizType.styles + '\n'; - } - }); - - scssData += '\n}'; - - sass.render({ - data: scssData, - success: function(sassResults) { - cache.put('css/' + visualizationTypes.toString(), sassResults.css, 1000 * 60 * 60); - res.send(sassResults.css); - } - }); - }).error(next); -}; diff --git a/app/controllers/visualizationTypes.js b/app/controllers/visualizationTypes.js index 2e6e61ef..c461e0e6 100644 --- a/app/controllers/visualizationTypes.js +++ b/app/controllers/visualizationTypes.js @@ -27,7 +27,7 @@ exports.show = function (req, res, next) { order: '"name" ASC' }) .then(function(types) { - + return res.render('viz-types/show', { vizTypes: types }); @@ -52,11 +52,8 @@ exports.refreshNPM = function(req, res, next) { debug('refreshing npm-based visualizations'); models.VisualizationType - .findAll({ - where: { - isModule: true - } - }).then(function(vizTypes) { + .findAll() + .then(function(vizTypes) { Q.all(_.map(vizTypes, function(vizType) { return vizType.refreshFromNPM(); })).spread(function() { @@ -98,7 +95,7 @@ exports.fetchDefaults = function (req, res, next) { }; exports.create = function (req, res, next) { - + models.VisualizationType .create(_.pick(req.body, 'name', 'initialDataFields', 'isStreaming', 'javascript', 'styles', 'markup', 'sampleData', 'sampleOptions')) .then(function(type) { @@ -106,7 +103,7 @@ exports.create = function (req, res, next) { }).catch(function(err) { return res.status(500).send(err); }); - + }; exports.edit = function (req, res, next) { @@ -123,14 +120,14 @@ exports.edit = function (req, res, next) { debug(key); if(key.indexOf(vizType.name) > -1) { debug('deleting ' + key); - cache.del(key); + cache.del(key); } }); }, 0); return res.status(200).send(); }).catch(function() { return res.status(500).send(); - }); + }); }; exports.delete = function (req, res, next) { @@ -141,13 +138,13 @@ exports.delete = function (req, res, next) { .findById(vizTypeId) .then(function(vizType) { vizType.deleteAndUninstall().then(function() { - return res.json(vizType); + return res.json(vizType); }).catch(next); }).catch(next); }; exports.getDelete = function(req, res, next) { - + var vizTypeId = req.params.vid; models.VisualizationType @@ -162,114 +159,25 @@ exports.getDelete = function(req, res, next) { }; - -exports.preview = function(req, res, next) { - - var tmpPath = path.resolve(__dirname + '/../../tmp/js-build/' + uuid.v4() + '/'); - req.session.lastBundlePath = tmpPath; - - var vizTypePromise, name; - - if(req.query.url) { - var url = req.query.url; - name = url; - if(req.query.path) { - name += '/' + req.query.path; - } - - name = req.query.name || /[^/]*$/.exec(name)[0]; - - vizTypePromise = models.VisualizationType - .createFromRepoURL(url, { name: name }, {preview: true, path: req.query.path}); - } else if(req.query.path && process.env.NODE_ENV !== 'production') { - var p = path.resolve(req.query.path); - name = req.query.name || /[^/]*$/.exec(p)[0]; - - vizTypePromise = models.VisualizationType - .createFromFolder(p, { name: name}, {preview: true}); - } - - vizTypePromise - .then(function(vizType) { - - debug('created viz preview'); - - vizType.exportToFS(tmpPath) - .spread(function() { - var b = browserify({ - paths: [ config.root + '/node_modules'] - }); - if(vizType.isModule) { - b.require(vizType.moduleName, { - expose: vizType.moduleName - }); - } else { - var stream = resumer().queue(vizType.javascript).end(); - b.require(stream, { - basedir: tmpPath, - expose: vizType.name - }); - } - - b.bundle(function(err, buf) { - - if(err) { - return next(err); - } - - var javascript = buf.toString('utf8'); - var scssData = '#lightning-body {\n'; - if(vizType.styles) { - scssData += vizType.styles + '\n'; - } - scssData += '\n}'; - sass.render({ - data: scssData, - success: function(sassResults) { - if(req.url.indexOf('/preview/full') > -1) { - return res.render('viz-types/full-preview', { - vizType: vizType, - javascript: javascript, - css: sassResults.css, - path: path.resolve(req.query.path || ''), - url: req.query.url, - source: req.query.url ? 'gitRepo' : 'localFolder' - }); - } - return res.render('viz-types/preview-editor', { - vizType: vizType, - javascript: javascript, - css: sassResults.css, - path: path.resolve(req.query.path || ''), - url: req.query.url, - source: req.query.url ? 'gitRepo' : 'localFolder' - }); - } - }); - }); - }); - - }).fail(function(err) { - next(err); - }); - -}; - exports.previewNPM = function(req, res, next) { var location = req.params.location; - var name = req.query.name; - debug('requested to link module: ' + name); + var installName = req.query.name; + var moduleName = models.VisualizationType.moduleNameFromInstallName(installName); + + debug(installName + ' : ' + moduleName); + + debug('requested to link module: ' + installName); models.VisualizationType .findAll({ where: { - moduleName: name + moduleName: moduleName } }).then(function(visualizations) { if(visualizations && visualizations.length) { - throw new Error('Please delete the installed ' + visualizations[0].name + ' visualization before trying to preview ' + name); + throw new Error('Please delete the installed ' + visualizations[0].name + ' visualization before trying to preview ' + installName); } var linker; @@ -281,12 +189,12 @@ exports.previewNPM = function(req, res, next) { return res.status(500).send('Invalid location.').end(); } - return linker(name); + return linker(installName, moduleName); }).then(function(vizType) { var b = browserify({ paths: [ config.root + '/node_modules'] }); - b.require(name); + b.require(moduleName); b.bundle(function(err, buf) { @@ -300,7 +208,6 @@ exports.previewNPM = function(req, res, next) { return res.render('viz-types/preview-editor', { vizType: vizType, javascript: javascript, - css: '', location: location, source: 'npm' }); @@ -313,18 +220,19 @@ exports.previewNPM = function(req, res, next) { exports.importNPM = function(req, res, next) { var location = req.params.location; - var name = req.query.name; + var installName = req.query.name; + var moduleName = models.VisualizationType.moduleNameFromInstallName(installName); debug('requested to link module: ' + name); models.VisualizationType .findAll({ where: { - moduleName: name + moduleName: moduleName } }).then(function(visualizations) { if(visualizations && visualizations.length) { - throw new Error('Please delete the installed ' + visualizations[0].name + ' visualization before trying to install ' + name); + throw new Error('Please delete the installed ' + visualizations[0].name + ' visualization before trying to install ' + installName); } var creator; if(location === 'registry') { @@ -335,7 +243,7 @@ exports.importNPM = function(req, res, next) { return res.status(500).send('Invalid location.').end(); } - return creator(name); + return creator(installName, moduleName); }).then(function(vizType) { return res.redirect('/visualization-types/edit/' + vizType.id); }).catch(function(err) { @@ -343,34 +251,11 @@ exports.importNPM = function(req, res, next) { }); }; -exports.importViz = function(req, res, next) { - - var name = req.body.name || req.query.name; - var url = req.body.url || req.query.url; - var path = req.body.path || req.query.path; - - var createPromise; - if(url) { - createPromise = models.VisualizationType.createFromRepoURL(url, {name: name}); - } else if(path) { - createPromise = models.VisualizationType.createFromFolder(path, {name: name}, {preview: false}); - } else { - return res.status(500).send('Invalid location.').end(); - } - - createPromise - .then(function(viz) { - return res.redirect('/visualization-types/edit/' + viz.id); - }).fail(function(err) { - next(err); - }); -}; exports.advanced = function (req, res, next) { return res.render('viz-types/advanced', {}); }; - exports.editor = function (req, res, next) { models.VisualizationType.findById(req.params.vid) @@ -390,7 +275,7 @@ exports.thumbnail = function (req, res, next) { if(type.thumbnailLocation) { return res.sendFile(type.thumbnailLocation); } - + return res.status(404).send('no thumbnail found').end(); }).catch(next); @@ -398,23 +283,16 @@ exports.thumbnail = function (req, res, next) { - exports.importPreviewHandler = function(req, res, next) { var method = req.params.method; var importPreview = req.params.importPreview; - if(method === 'npm') { - if(importPreview === 'import') { - return exports.importNPM(req, res, next); - } else { - return exports.previewNPM(req, res, next); - } - } else if(method === 'git' || method === 'local') { - if(importPreview === 'import') { - return exports.importViz(req, res, next); - } else { - return exports.preview(req, res, next); - } + debug('preview'); + if(importPreview === 'import') { + debug('import npm'); + return exports.importNPM(req, res, next); + } else { + debug('preview npm'); + return exports.previewNPM(req, res, next); } - }; diff --git a/app/models/visualizationtype.js b/app/models/visualizationtype.js index f8d85a83..4716e8de 100644 --- a/app/models/visualizationtype.js +++ b/app/models/visualizationtype.js @@ -27,7 +27,6 @@ module.exports = function(sequelize, DataTypes) { enabled: {type: DataTypes.BOOLEAN, defaultValue: true}, imported: {type: DataTypes.BOOLEAN, defaultValue: false}, - isModule: {type: DataTypes.BOOLEAN, defaultValue: false}, isStreaming: {type: DataTypes.BOOLEAN, defaultValue: false}, moduleName: {type: DataTypes.STRING}, @@ -37,76 +36,68 @@ module.exports = function(sequelize, DataTypes) { sampleOptions: DataTypes.JSON, codeExamples: DataTypes.JSON, sampleImages: DataTypes.ARRAY(DataTypes.STRING), - - javascript: DataTypes.TEXT, - markup: DataTypes.TEXT, - styles: DataTypes.TEXT }; } else { schema = { - 'id': { - type: DataTypes.UUID, - primaryKey: true, - defaultValue: DataTypes.UUIDV4, - }, - name: {type: DataTypes.STRING, unique: true}, - enabled: {type: DataTypes.BOOLEAN, defaultValue: true}, - imported: {type: DataTypes.BOOLEAN, defaultValue: false}, - isModule: {type: DataTypes.BOOLEAN, defaultValue: false}, - isStreaming: {type: DataTypes.BOOLEAN, defaultValue: false}, - moduleName: {type: DataTypes.STRING}, - - thumbnailLocation: DataTypes.STRING, - - sampleData: { - type: DataTypes.TEXT, - get: function() { - return JSON.parse(this.getDataValue('sampleData') || '{}'); - }, - set: function(val) { - return this.setDataValue('sampleData', JSON.stringify(val)); - } - }, - sampleOptions: { - type: DataTypes.TEXT, - get: function() { - return JSON.parse(this.getDataValue('sampleOptions') || '{}'); - }, - set: function(val) { - return this.setDataValue('sampleOptions', JSON.stringify(val)); - } - }, - codeExamples: { - type: DataTypes.TEXT, - get: function() { - return JSON.parse(this.getDataValue('codeExamples') || '{}'); - }, - set: function(val) { - return this.setDataValue('codeExamples', JSON.stringify(val)); - } - }, - sampleImages: { - type: DataTypes.TEXT, - get: function() { - return JSON.parse(this.getDataValue('sampleImages') || '[]'); - }, - set: function(val) { - return this.setDataValue('sampleImages', JSON.stringify(val)); - } - }, - initialDataFields: { - type: DataTypes.TEXT, - get: function() { - return JSON.parse(this.getDataValue('initialDataFields') || '[]'); - }, - set: function(val) { - return this.setDataValue('initialDataFields', JSON.stringify(val)); - } - }, - javascript: DataTypes.TEXT, - markup: DataTypes.TEXT, - styles: DataTypes.TEXT - }; + 'id': { + type: DataTypes.UUID, + primaryKey: true, + defaultValue: DataTypes.UUIDV4, + }, + name: {type: DataTypes.STRING, unique: true}, + enabled: {type: DataTypes.BOOLEAN, defaultValue: true}, + imported: {type: DataTypes.BOOLEAN, defaultValue: false}, + isStreaming: {type: DataTypes.BOOLEAN, defaultValue: false}, + moduleName: {type: DataTypes.STRING}, + + thumbnailLocation: DataTypes.STRING, + + sampleData: { + type: DataTypes.TEXT, + get: function() { + return JSON.parse(this.getDataValue('sampleData') || '{}'); + }, + set: function(val) { + return this.setDataValue('sampleData', JSON.stringify(val)); + } + }, + sampleOptions: { + type: DataTypes.TEXT, + get: function() { + return JSON.parse(this.getDataValue('sampleOptions') || '{}'); + }, + set: function(val) { + return this.setDataValue('sampleOptions', JSON.stringify(val)); + } + }, + codeExamples: { + type: DataTypes.TEXT, + get: function() { + return JSON.parse(this.getDataValue('codeExamples') || '{}'); + }, + set: function(val) { + return this.setDataValue('codeExamples', JSON.stringify(val)); + } + }, + sampleImages: { + type: DataTypes.TEXT, + get: function() { + return JSON.parse(this.getDataValue('sampleImages') || '[]'); + }, + set: function(val) { + return this.setDataValue('sampleImages', JSON.stringify(val)); + } + }, + initialDataFields: { + type: DataTypes.TEXT, + get: function() { + return JSON.parse(this.getDataValue('initialDataFields') || '[]'); + }, + set: function(val) { + return this.setDataValue('initialDataFields', JSON.stringify(val)); + } + } + }; } @@ -171,7 +162,6 @@ module.exports = function(sequelize, DataTypes) { var vizTypeObj = { name: lightningConfig.name || name, isStreaming: lightningConfig.isStreaming || false, - isModule: true, moduleName: name, sampleData: samples.data, sampleOptions: samples.options, @@ -205,180 +195,48 @@ module.exports = function(sequelize, DataTypes) { return VisualizationType.create(vizTypeObj); }, - _createLinkNPM: function(command, name, preview) { + _createLinkNPM: function(command, installName, moduleName, preview) { var self = this; var loglevel = npm.config.get('loglevel'); npm.config.set('loglevel', 'silent'); - return Q.nfcall(npm.commands.uninstall, [name]) + return Q.nfcall(npm.commands.uninstall, [moduleName]) .then(function(results) { - return Q.nfcall(command, [name]); + return Q.nfcall(command, [installName]); }).then(function() { npm.config.set('loglevel', loglevel); - debug(('Successfully installed ' + name).green); - return self._buildFromNPM(name, preview); + debug(('Successfully installed ' + installName).green); + return self._buildFromNPM(moduleName, preview); }); }, - createFromNPM: function(name) { - return this._createLinkNPM(npm.commands.install, name, false); + createFromNPM: function(installName, moduleName) { + return this._createLinkNPM(npm.commands.install, installName, moduleName || installName, false); }, - linkFromNPM: function(name) { - return this._createLinkNPM(npm.commands.install, name, true); + linkFromNPM: function(installName, moduleName) { + return this._createLinkNPM(npm.commands.install, installName, moduleName || installName, true); }, - linkFromLocalModule: function(name) { + linkFromLocalModule: function(installName, moduleName) { debug('link from local module'); debug(name); - return this._createLinkNPM(npm.commands.link, name, true); + return this._createLinkNPM(npm.commands.link, installName, moduleName || installName, true); }, - - createFromLocalModule: function(name) { - return this._createLinkNPM(npm.commands.link, name, false); + createFromLocalModule: function(installName, moduleName) { + return this._createLinkNPM(npm.commands.link, installName, moduleName || installName, false); }, - createFromRepoURL: function(url, attributes, opts) { - - attributes = attributes || {}; - opts = opts || {}; - // clone REPO, extract js, css, and html files... - - var self = this; - - var repoPath = path.resolve(__dirname + '/../../tmp/repos/' + uuid.v4()); - - return Q.nfcall(fs.remove, repoPath) - .then(function() { - return Q.ninvoke(git, 'clone', url, repoPath); - }) - .then(function() { - return self.createFromFolder(repoPath + (opts.path ? ('/' + opts.path) : ''), attributes, opts); - }); - }, - - - createManyFromRepoURL: function(url) { - - var ignoreFolders = ['.git']; - - var self = this; - - var infoStat = function(filename, callback) { - - fs.stat(filename, function(err, stat) { - stat.filename = filename; + moduleNameFromInstallName: function(installName) { + var re = new RegExp("^[^/]+/[^/]+$"); - if(err) { - callback(err); - } else { - callback(err, stat); - } - - }); - }; - - var repoPath = path.resolve(__dirname + '/../../tmp/repos/' + uuid.v4()); - - return Q.nfcall(fs.remove, repoPath) - .then(function() { - return Q.ninvoke(git, 'clone', url, repoPath); - }) - .then(function() { - return Q.nfcall(fs.readdir, repoPath); - }).then(function(files) { - var funcs = []; - _.each(files, function(file) { - if(ignoreFolders.indexOf(file) === -1) { - funcs.push(Q.nfcall(infoStat, repoPath + '/' + file)); - } - }); - - return funcs; - }).spread(function() { - var stats = Array.prototype.slice.call(arguments, 0); - - var funcs = []; - _.each(stats, function(stat) { - if(stat.isDirectory()) { - funcs.push(self.createFromFolder(stat.filename, { - name: stat.filename.replace(/^.*[\\\/]/, '') - })); - } - }); - - return funcs; - }); - - }, - - createFromFolder: function(path, attributes, opts) { - - debug('Create from folder: ' + path); - - attributes = attributes || {}; - opts = opts || {}; - // clone REPO, extract js, css, and html files... - - return Q.all([ - Q.nfcall(glob, path + '/*.js'), - Q.nfcall(glob, path + '/*.{css,scss}'), - Q.nfcall(glob, path + '/*.{html,jade}'), - Q.nfcall(glob, path + '/sample-data.json'), - Q.nfcall(glob, path + '/sample-images.json'), - Q.nfcall(glob, path + '/package.json'), - ]) - .spread(function(jsFiles, styleFiles, markupFiles, sampleDataFiles, sampleImageFiles, packageJSONFiles) { - - if(jsFiles.length > 1) { - throw new Error('There can\'t be more than one javascript file'); - } else if(styleFiles.length > 1) { - throw new Error('There can\'t be more than one style file'); - } else if(markupFiles.length > 1) { - throw new Error('There can\'t be more than one markup file'); - } - - return [ - (jsFiles.length) ? Q.nfcall(fs.readFile, jsFiles[0]) : '', - (styleFiles.length) ? Q.nfcall(fs.readFile, styleFiles[0]) : '', - (markupFiles.length) ? Q.nfcall(fs.readFile, markupFiles[0]) : '', - (sampleDataFiles.length) ? Q.nfcall(fs.readFile, sampleDataFiles[0]) : '[]', - (sampleImageFiles.length) ? Q.nfcall(fs.readFile, sampleImageFiles[0]) : '[]', - (packageJSONFiles.length) ? Q.nfcall(fs.readFile, packageJSONFiles[0]) : '[]', - ]; - - - }).spread(function(javascript, styles, markup, sampleData, sampleImages, packageJSON) { - sampleImages = JSON.parse(sampleImages); - if(!sampleImages.length) { - sampleImages = null; - } - - try { - packageJSON = JSON.parse(packageJSON); - } catch(e) { - debug('Invalid package.json: ' + e.toString()); - } - - var vizTypeObj = _.extend(attributes, { - javascript: javascript.toString('utf8'), - styles: styles.toString('utf8'), - markup: markup.toString('utf8'), - sampleData: JSON.parse(sampleData.toString('utf8')), - sampleImages: sampleImages - }); - - vizTypeObj = _.extend(vizTypeObj, packageJSON['lightning-viz'] || {}); - - if(opts.preview) { - return VisualizationType.build(vizTypeObj); - } - - return VisualizationType.create(vizTypeObj); - - }); - }, + if(re.test(installName)) { + var parts = installName.split("/"); + return parts[parts.length - 1]; + } + return installName; + } }, @@ -412,15 +270,13 @@ module.exports = function(sequelize, DataTypes) { } return Q.all(funcs); }, - + deleteAndUninstall: function() { var self = this; - if(this.isModule) { - return Q.nfcall(npm.commands.uninstall, [this.moduleName]) - .then(function() { - return self.destroy(); - }); - } + return Q.nfcall(npm.commands.uninstall, [this.moduleName]) + .then(function() { + return self.destroy(); + }); return self.destroy(); }, diff --git a/app/views/embed-layout.jade b/app/views/embed-layout.jade index f414a2e5..40d9175b 100644 --- a/app/views/embed-layout.jade +++ b/app/views/embed-layout.jade @@ -5,7 +5,6 @@ meta(charset="UTF-8") block meta link(href='//fonts.googleapis.com/css?family=Open+Sans:400,700', rel='stylesheet', type='text/css') link(rel='stylesheet', href='#{STATIC_URL}css/app.css') -block dynamic-css block head-js block header diff --git a/app/views/layout.jade b/app/views/layout.jade index a195358d..8bc07568 100644 --- a/app/views/layout.jade +++ b/app/views/layout.jade @@ -8,7 +8,6 @@ html(lang="en") block meta link(href='//fonts.googleapis.com/css?family=Open+Sans:400,700', rel='stylesheet', type='text/css') link(rel='stylesheet', href='#{STATIC_URL}css/app.css') - block dynamic-css body #lightning-body @@ -54,4 +53,4 @@ body script(src='//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js') script(src='#{STATIC_URL}js/basic.js') - \ No newline at end of file + diff --git a/app/views/session/feed-public.jade b/app/views/session/feed-public.jade index 7e70fb2a..62dabe87 100644 --- a/app/views/session/feed-public.jade +++ b/app/views/session/feed-public.jade @@ -1,9 +1,5 @@ extends ../layout -block dynamic-css - if visualizations.length - link(rel='stylesheet', href="#{STATIC_URL}css/dynamic/viz/?visualizations[]=#{_.pluck(_.pluck(visualizations, 'VisualizationType'), 'name').join('&visualizations[]=')}") - block sidebar diff --git a/app/views/session/feed.jade b/app/views/session/feed.jade index d8e6cf25..97e6a3ec 100644 --- a/app/views/session/feed.jade +++ b/app/views/session/feed.jade @@ -1,9 +1,4 @@ extends ../layout - -block dynamic-css - if visualizations.length - link(rel='stylesheet', href="#{STATIC_URL}css/dynamic/viz/?visualizations[]=#{_.pluck(_.pluck(visualizations, 'VisualizationType'), 'name').join('&visualizations[]=')}") - block content diff --git a/app/views/session/visualization-embed.jade b/app/views/session/visualization-embed.jade index c5e8d3d9..9220d089 100644 --- a/app/views/session/visualization-embed.jade +++ b/app/views/session/visualization-embed.jade @@ -1,9 +1,5 @@ extends ../embed-layout -block dynamic-css - link(rel='stylesheet', href="#{STATIC_URL}css/dynamic/viz/?visualizations[]=#{viz.VisualizationType.name}") - - block sidebar block content diff --git a/app/views/session/visualization-iframe.jade b/app/views/session/visualization-iframe.jade index 4eb7f9bd..f90d59a1 100644 --- a/app/views/session/visualization-iframe.jade +++ b/app/views/session/visualization-iframe.jade @@ -1,9 +1,5 @@ extends ../embed-layout -block dynamic-css - link(rel='stylesheet', href="#{STATIC_URL}css/dynamic/viz/?visualizations[]=#{viz.VisualizationType.name}") - - block sidebar block content diff --git a/app/views/session/visualization-public.jade b/app/views/session/visualization-public.jade index 0e897ba4..a669d9a0 100644 --- a/app/views/session/visualization-public.jade +++ b/app/views/session/visualization-public.jade @@ -1,9 +1,5 @@ extends ../layout - -block dynamic-css - link(rel='stylesheet', href="#{STATIC_URL}css/dynamic/viz/?visualizations[]=#{viz.VisualizationType.name}") - block sidebar block content @@ -18,5 +14,3 @@ block scripts script(src='#{STATIC_URL}js/basic.js') script(src="#{STATIC_URL}js/dynamic/viz/?visualizations[]=#{viz.VisualizationType.name}") script(src='#{STATIC_URL}js/public.js') - - diff --git a/app/views/session/visualization-pym.jade b/app/views/session/visualization-pym.jade index f675c53b..6f0c177f 100644 --- a/app/views/session/visualization-pym.jade +++ b/app/views/session/visualization-pym.jade @@ -1,9 +1,5 @@ extends ../embed-layout -block dynamic-css - link(rel='stylesheet', href="#{STATIC_URL}css/dynamic/viz/?visualizations[]=#{viz.VisualizationType.name}") - - block sidebar block content diff --git a/app/views/session/visualization.jade b/app/views/session/visualization.jade index b577d557..71db0ddc 100644 --- a/app/views/session/visualization.jade +++ b/app/views/session/visualization.jade @@ -1,9 +1,5 @@ extends ../layout - -block dynamic-css - link(rel='stylesheet', href="#{STATIC_URL}css/dynamic/viz/?visualizations[]=#{viz.VisualizationType.name}") - block sidebar block content diff --git a/app/views/viz-types/editor.jade b/app/views/viz-types/editor.jade index ff8cb909..ffd4cb54 100644 --- a/app/views/viz-types/editor.jade +++ b/app/views/viz-types/editor.jade @@ -1,8 +1,5 @@ extends ../layout -block dynamic-css - link(rel='stylesheet', href="#{STATIC_URL}css/dynamic/viz/?visualizations[]=#{vizType.name}")#viz-styles - block container .editor-outer-section.wrap.push @@ -45,4 +42,3 @@ block scripts codeExamples: !{JSON.stringify(vizType.codeExamples)} }; script(src='#{STATIC_URL}js/editor.js') - diff --git a/app/views/viz-types/preview-editor.jade b/app/views/viz-types/preview-editor.jade index b419772d..8e821781 100644 --- a/app/views/viz-types/preview-editor.jade +++ b/app/views/viz-types/preview-editor.jade @@ -1,9 +1,5 @@ extends ../layout -block dynamic-css - style#viz-styles. - #{css} - block container .editor-outer-section.wrap.push @@ -53,4 +49,3 @@ block scripts path: "#{path}" }; script(src='#{STATIC_URL}js/preview.js') - diff --git a/config/routes.js b/config/routes.js index bfd5513b..63c3a836 100644 --- a/config/routes.js +++ b/config/routes.js @@ -31,12 +31,10 @@ module.exports = function (app) { res.set("Access-Control-Allow-Headers", "Content-Type"); res.set("Access-Control-Allow-Methods", "GET, OPTIONS, PUT, POST"); res.status(200).send(); - }) + }); app.get('/js/dynamic/viz', staticController.getDynamicVizBundle); - app.get('/css/dynamic/viz', staticController.getDynamicVizStyles); app.post('/js/dynamic', staticController.bundleJSForExecution); - app.post('/css/dynamic', staticController.buildSCSS); app.get('/visualizations/:vid/public', visualization.publicRead); app.get('/visualizations/:vid/screenshot', visualization.screenshot); app.get('/sessions/:sid/public', session.publicRead); @@ -49,16 +47,13 @@ module.exports = function (app) { app.get('/visualizations/types', authMiddleware, visualizationTypes.index); app.get('/visualization-types', authMiddleware, visualizationTypes.show); - app.post('/visualization-types', authMiddleware, visualizationTypes.importViz); app.get('/visualization-types/advanced/', authMiddleware, visualizationTypes.advanced); app.get('/visualization-types/advanced/fetch-defaults', authMiddleware, visualizationTypes.fetchDefaults); app.get('/visualization-types/advanced/reset-defaults', authMiddleware, visualizationTypes.resetDefaults); app.get('/visualization-types/advanced/refresh-npm', authMiddleware, visualizationTypes.refreshNPM); - app.get('/visualization-types/preview/full', authMiddleware, visualizationTypes.preview); app.get('/visualization-types/edit/:vid', authMiddleware, visualizationTypes.editor); - app.get('/visualization-types/load/:importPreview/:method', authMiddleware, visualizationTypes.importPreviewHandler); - app.get('/visualization-types/load/:importPreview/:method/:location', authMiddleware, visualizationTypes.importPreviewHandler); + app.get('/visualization-types/load/:importPreview/:location', authMiddleware, visualizationTypes.importPreviewHandler); app.get('/visualization-types/:vizName.json', authMiddleware, visualizationTypes.json); app.get('/visualization-types/:vid/thumbnail', authMiddleware, visualizationTypes.thumbnail); @@ -75,7 +70,7 @@ module.exports = function (app) { app.get('/sessions/:sid', authMiddleware, session.feed); app.get('/sessions/:sid/feed', authMiddleware, session.feed); - + app.put('/sessions/:sid', authMiddleware, session.update); app.put('/visualizations/:vid', authMiddleware, visualization.update); @@ -94,7 +89,7 @@ module.exports = function (app) { app.put('/sessions/:sid/visualizations/:vid/data', authMiddleware, session.updateData); app.put('/sessions/:sid/visualizations/:vid/data/:field', authMiddleware, session.updateData); - + // public / userland stuff @@ -132,4 +127,4 @@ module.exports = function (app) { error: 'Not found' }); }); -}; \ No newline at end of file +}; diff --git a/ui/js/components/visualization-importer/index.js b/ui/js/components/visualization-importer/index.js index e67fbc87..20e15d8b 100644 --- a/ui/js/components/visualization-importer/index.js +++ b/ui/js/components/visualization-importer/index.js @@ -8,7 +8,7 @@ var Sources = require('./sources'); var styles = { radioLabel: { - display: 'inline-block', + display: 'inline-block', }, radioInput: { @@ -36,48 +36,12 @@ var Importer = React.createClass({ }); }, - renderRadioGroup: function(Radio) { - var radios = [{ - name: 'npm', - label: 'NPM' - }, { - name: 'gitRepo', - label: 'Git Repo' - }, { - name: 'localFolder', - label: 'Local Folder' - }]; - - var styleRadio = function(radio, i) { - var rLen = Object.keys(radios).length; - return ( - - ); - - }; - - return ( -
- {radios.map(styleRadio.bind(this))} -
- ); - }, - render: function() { var Source = Sources[this.state.source]; return (
- Select Source: - - {this.renderRadioGroup} - - {radio.label} - - ); - - }; - - return ( -
- {radios.map(styleRadio.bind(this))} -
- ); - }, - - render: function() { - - return ( -
-
- Preview or Import? - - {this.renderImportPreviewRadioGroup} - -
-
- Repo URL: - -
-
- Visualization Name: - -
-
- Submit -
- -
- ); - }, -}); - -module.exports = Git; diff --git a/ui/js/components/visualization-importer/sources/index.js b/ui/js/components/visualization-importer/sources/index.js index bc71c3ff..b4a89aa2 100644 --- a/ui/js/components/visualization-importer/sources/index.js +++ b/ui/js/components/visualization-importer/sources/index.js @@ -2,6 +2,4 @@ module.exports = { npm: require('./npm'), - gitRepo: require('./git-repo'), - localFolder: require('./local-folder'), -}; \ No newline at end of file +}; diff --git a/ui/js/components/visualization-importer/sources/local-folder.js b/ui/js/components/visualization-importer/sources/local-folder.js deleted file mode 100644 index a88953cf..00000000 --- a/ui/js/components/visualization-importer/sources/local-folder.js +++ /dev/null @@ -1,134 +0,0 @@ -'use strict'; - -var React = require('react'); -var _ = require('lodash'); -var RadioGroup = require('react-radio-group'); -var request = require('superagent'); - - -var styles = { - radioInput: { - display: 'none' - } -}; - -var isEmpty = function(str) { - return str.replace(/^\s+|\s+$/g, '').length == 0; -} - - -var Local = React.createClass({ - - getDefaultProps: function() { - return { - initialImportPreview: 'import', - initialName: '', - initialPath: '' - } - }, - - getInitialState: function() { - return { - importPreview: this.props.initialImportPreview, - name: this.props.initialName, - path: this.props.initialPath - } - }, - - serialize: function(obj) { - var str = []; - for(var p in obj) - if (obj.hasOwnProperty(p)) { - str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); - } - return str.join("&"); - }, - - handleChangePath: function(event) { - this.setState({ - path: event.target.value - }); - }, - handleChangeName: function(event) { - this.setState({ - name: event.target.value - }); - }, - - handleSelectImportPreview: function(importPreview) { - this.setState({ - importPreview: importPreview - }); - }, - - handleSubmit: function() { - if(isEmpty(this.state.path) || isEmpty(this.state.name)) { - return; - } - - var url = '/visualization-types/load/' + this.state.importPreview + '/local/'; - url += '?' + this.serialize({ - path: this.state.path, - name: this.state.name - }); - - window.location.href = url; - }, - - renderImportPreviewRadioGroup: function(Radio) { - var radios = [{ - name: 'import', - label: 'Import' - }, { - name: 'preview', - label: 'Preview' - }]; - - var styleRadio = function(radio, i) { - var rLen = Object.keys(radios).length; - return ( - - ); - - }; - - return ( -
- {radios.map(styleRadio.bind(this))} -
- ); - }, - - render: function() { - - return ( -
-
- Preview or Import? - - {this.renderImportPreviewRadioGroup} - -
-
- Folder Path: - -
-
- Visualization Name: - -
-
- Submit -
- -
- ); - }, -}); - -module.exports = Local; diff --git a/ui/js/components/visualization-importer/sources/npm.js b/ui/js/components/visualization-importer/sources/npm.js index 7fd7e1c2..336d2e48 100644 --- a/ui/js/components/visualization-importer/sources/npm.js +++ b/ui/js/components/visualization-importer/sources/npm.js @@ -59,7 +59,7 @@ var NPM = React.createClass({ handleNameChange: function(event) { this.setState({ name: event.target.value - }); + }); }, handleSubmit: function() { @@ -67,7 +67,7 @@ var NPM = React.createClass({ return; } - var url = '/visualization-types/load/' + this.state.importPreview + '/npm/' + this.state.location; + var url = '/visualization-types/load/' + this.state.importPreview + '/' + this.state.location; url += '?' + this.serialize({ name: this.state.name }); @@ -87,8 +87,8 @@ var NPM = React.createClass({ var styleRadio = function(radio, i) { var rLen = Object.keys(radios).length; return ( -
); - }, + }, renderImportPreviewRadioGroup: function(Radio) { var radios = [{ @@ -116,8 +116,8 @@ var NPM = React.createClass({ var styleRadio = function(radio, i) { var rLen = Object.keys(radios).length; return ( -