From 817a560b1a8534b66ac9da9dcfa7e766a3a00649 Mon Sep 17 00:00:00 2001 From: Damien Corneau Date: Sun, 15 Feb 2015 22:34:04 +0900 Subject: [PATCH 1/4] Fix watch on .ts files, when on grunt serve --- zeppelin-web/Gruntfile.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/zeppelin-web/Gruntfile.js b/zeppelin-web/Gruntfile.js index 0bb2bccd..6432829a 100644 --- a/zeppelin-web/Gruntfile.js +++ b/zeppelin-web/Gruntfile.js @@ -41,10 +41,11 @@ module.exports = function (grunt) { } }, scripts: { - files: ['<%= yeoman.app %>/scripts/ts/**/*.ts'], + files: ['<%= yeoman.app %>/typescripts/**/*.ts'], tasks: ['typescript'], options: { - spawn: false + spawn: false, + livereload: '<%= connect.options.livereload %>' } }, jsTest: { From f8ddf956fb8c673ecfd9dd809c2e931b8b3397c4 Mon Sep 17 00:00:00 2001 From: Damien Corneau Date: Sun, 15 Feb 2015 23:24:54 +0900 Subject: [PATCH 2/4] Add tslint to replace jshint --- zeppelin-web/Gruntfile.js | 26 +++++++----- zeppelin-web/package.json | 14 ++++--- zeppelin-web/tslint.json | 85 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 17 deletions(-) create mode 100644 zeppelin-web/tslint.json diff --git a/zeppelin-web/Gruntfile.js b/zeppelin-web/Gruntfile.js index 6432829a..a106f8e8 100644 --- a/zeppelin-web/Gruntfile.js +++ b/zeppelin-web/Gruntfile.js @@ -27,22 +27,27 @@ module.exports = function (grunt) { // Project settings yeoman: appConfig, + + // lint typescript files + tslint: { + options: { + configuration: grunt.file.readJSON("tslint.json") + }, + files: { + src: ['<%= yeoman.app %>/typescripts/**/*.ts'] + } + }, + + // Watches files for changes and runs tasks based on the changed files watch: { bower: { files: ['bower.json'], tasks: ['wiredep'] }, - js: { - files: ['<%= yeoman.app %>/scripts/{,*/}*.js'], - tasks: ['newer:jshint:all'], - options: { - livereload: '<%= connect.options.livereload %>' - } - }, scripts: { files: ['<%= yeoman.app %>/typescripts/**/*.ts'], - tasks: ['typescript'], + tasks: ['typescript', 'tslint'], options: { spawn: false, livereload: '<%= connect.options.livereload %>' @@ -382,11 +387,11 @@ module.exports = function (grunt) { grunt.task.run([ 'clean:server', 'typescript', + 'tslint', 'wiredep', 'concurrent:dist', 'autoprefixer', 'connect:livereload', - /*'newer:jshint'*/ 'watch' ]); }); @@ -408,6 +413,7 @@ module.exports = function (grunt) { grunt.registerTask('build', [ 'clean:dist', 'typescript', + 'tslint', 'wiredep', 'useminPrepare', 'concurrent:dist', @@ -417,13 +423,11 @@ module.exports = function (grunt) { 'copy:dist', 'cssmin', 'uglify', - /*'filerev',*/ 'usemin', 'htmlmin' ]); grunt.registerTask('default', [ - 'newer:jshint', /* * Since we dont have test (or up to date) there is no reason to keep this task * I am commented this, but can be changed in the future (if someone want to implement front tests). diff --git a/zeppelin-web/package.json b/zeppelin-web/package.json index c498e615..c1426925 100644 --- a/zeppelin-web/package.json +++ b/zeppelin-web/package.json @@ -6,6 +6,7 @@ "bower": "", "grunt": "^0.4.1", "grunt-autoprefixer": "^0.7.3", + "grunt-cli": "^0.1.13", "grunt-concurrent": "^0.5.0", "grunt-contrib-clean": "^0.5.0", "grunt-contrib-concat": "^0.4.0", @@ -17,20 +18,21 @@ "grunt-contrib-uglify": "^0.4.0", "grunt-contrib-watch": "^0.6.1", "grunt-filerev": "^0.2.1", + "grunt-karma": "~0.8.3", "grunt-newer": "^0.7.0", "grunt-ngmin": "^0.0.3", "grunt-svgmin": "^0.4.0", + "grunt-tslint": "^2.0.0", + "grunt-typescript": "", "grunt-usemin": "^2.1.1", "grunt-wiredep": "~2.0.0", - "grunt-cli": "^0.1.13", "jshint-stylish": "^0.2.0", - "load-grunt-tasks": "^0.4.0", - "time-grunt": "^0.3.1", - "grunt-karma": "~0.8.3", - "karma-phantomjs-launcher": "~0.1.4", "karma": "~0.12.23", "karma-jasmine": "~0.1.5", - "grunt-typescript": "" + "karma-phantomjs-launcher": "~0.1.4", + "load-grunt-tasks": "^0.4.0", + "time-grunt": "^0.3.1", + "tslint": "^2.1.1" }, "engines": { "node": ">=0.10.0" diff --git a/zeppelin-web/tslint.json b/zeppelin-web/tslint.json new file mode 100644 index 00000000..496998db --- /dev/null +++ b/zeppelin-web/tslint.json @@ -0,0 +1,85 @@ +{ + "rules": { + "ban": false, + "class-name": true, + "comment-format": [true, + "check-space", + "check-lowercase" + ], + "curly": true, + "eofline": true, + "forin": false, + "indent": [true, 4], + "interface-name": true, + "jsdoc-format": true, + "label-position": true, + "label-undefined": true, + "max-line-length": [true, 140], + "member-ordering": [true, + "public-before-private", + "static-before-instance", + "variables-before-functions" + ], + "no-arg": true, + "no-bitwise": true, + "no-console": [true, + "debug", + "info", + "time", + "timeEnd", + "trace" + ], + "no-construct": true, + "no-constructor-vars": true, + "no-debugger": true, + "no-duplicate-key": true, + "no-duplicate-variable": false, + "no-empty": true, + "no-eval": true, + "no-string-literal": true, + "no-switch-case-fall-through": true, + "no-trailing-comma": true, + "no-trailing-whitespace": true, + "no-unused-expression": true, + "no-unused-variable": false, + "no-unreachable": true, + "no-use-before-declare": false, + "no-var-requires": true, + "one-line": [true, + "check-open-brace", + "check-catch", + "check-else", + "check-whitespace" + ], + "quotemark": [true, "single"], + "radix": true, + "semicolon": true, + "triple-equals": [true, "allow-null-check"], + "typedef": [false, + "call-signature", + "parameter", + "property-declaration", + "variable-declaration", + "member-variable-declaration" + ], + "typedef-whitespace": [true, { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + }], + "use-strict": [true, + "check-module", + "check-function" + ], + "variable-name": false, + "whitespace": [true, + "check-branch", + "check-decl", + "check-operator", + "check-separator", + "check-type" + ] + } +} \ No newline at end of file From e695e212dc20fde91353f75037bbd4a741cc134e Mon Sep 17 00:00:00 2001 From: Damien Corneau Date: Mon, 16 Feb 2015 00:41:49 +0900 Subject: [PATCH 3/4] Fix tslint errors --- zeppelin-web/app/typescripts/app.ts | 40 +++++----- .../typescripts/controllers/interpreter.ts | 59 ++++++++------- .../app/typescripts/controllers/main.ts | 7 +- .../app/typescripts/controllers/nav.ts | 5 +- .../app/typescripts/controllers/notebook.ts | 35 ++++----- .../app/typescripts/controllers/paragraph.ts | 17 +++-- .../controllers/paragraph_editor.ts | 19 +++-- .../controllers/paragraph_result.ts | 74 ++++++++++--------- .../app/typescripts/directives/resizable.ts | 4 +- zeppelin-web/app/typescripts/events.ts | 4 +- zeppelin-web/app/typescripts/types.ts | 2 +- zeppelin-web/app/views/main.html | 2 +- zeppelin-web/tslint.json | 7 +- 13 files changed, 151 insertions(+), 124 deletions(-) diff --git a/zeppelin-web/app/typescripts/app.ts b/zeppelin-web/app/typescripts/app.ts index 4323fb0a..bf8cbdb4 100644 --- a/zeppelin-web/app/typescripts/app.ts +++ b/zeppelin-web/app/typescripts/app.ts @@ -13,33 +13,35 @@ * limitations under the License. */ -'use strict'; -/** get the current port of the websocket - * In the case of running the zeppelin-server normally, - * The body of this function is just filler. It will be dynamically - * overridden with the zeppelin-site.xml config value when the client - * requests the script. If the config value is not defined, it defaults - * to the HTTP port + 1 - * - * At the moment, the key delimiter denoting the end of this function - * during the replacement is the '}' character. Avoid using this - * character inside the function body - * - * In the case of running "grunt serve", this function will appear - * as is. - */ +/* get the current port of the websocket + * In the case of running the zeppelin-server normally, + * The body of this function is just filler. It will be dynamically + * overridden with the zeppelin-site.xml config value when the client + * requests the script. If the config value is not defined, it defaults + * to the HTTP port + 1 + * + * At the moment, the key delimiter denoting the end of this function + * during the replacement is the '}' character. Avoid using this + * character inside the function body + * + * In the case of running "grunt serve", this function will appear + * as is. + */ module zeppelin { + +'use strict'; + function getPort() { var port = Number(location.port); if (location.protocol !== 'https:' && (port === undefined || port === 0)) { port = 80; - } else if (location.protocol == 'https:' && (port === undefined || port === 0)) { + } else if (location.protocol === 'https:' && (port === undefined || port === 0)) { port = 443; - } else if (port == 3333 || port == 9000) { + } else if (port === 3333 || port === 9000) { port = 8080; } - return port+1; + return (port + 1); } function getWebsocketProtocol() { @@ -92,7 +94,7 @@ module zeppelin { ]) .filter('breakFilter', function() { return function (text) { - if (text !== undefined) return text.replace(/\n/g, '
'); + if (text !== undefined) { return text.replace(/\n/g, '
'); } }; }) .config(function ($routeProvider, WebSocketProvider) { diff --git a/zeppelin-web/app/typescripts/controllers/interpreter.ts b/zeppelin-web/app/typescripts/controllers/interpreter.ts index 1ac8d6c2..9fed59cd 100644 --- a/zeppelin-web/app/typescripts/controllers/interpreter.ts +++ b/zeppelin-web/app/typescripts/controllers/interpreter.ts @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -'use strict'; /** * @ngdoc function @@ -25,6 +24,9 @@ */ module zeppelin { + +'use strict'; + angular.module('zeppelinWebApp').controller('InterpreterCtrl', function($scope, $route, $routeParams, $location, $rootScope, $http) { var remoteSettingToLocalSetting = function(settingId, setting) { @@ -45,7 +47,7 @@ module zeppelin { $http.get(restApiBase() + '/interpreter/setting'). success(function(data, status, headers, config) { var interpreterSettings = []; - //console.log('getInterpreterSettings=%o', data); + // console.log('getInterpreterSettings=%o', data); for (var settingId in data.body) { var setting = data.body[settingId]; @@ -77,7 +79,7 @@ module zeppelin { } $scope.availableInterpreters = groupedInfo; - //console.log('getAvailableInterpreters=%o', data); + // console.log('getAvailableInterpreters=%o', data); }). error(function(data, status, headers, config) { console.log('Error %o %o', status, data.message); @@ -86,9 +88,9 @@ module zeppelin { $scope.copyOriginInterpreterSettingProperties = function(settingId) { $scope.interpreterSettingProperties = {}; - for (var i=0; i < $scope.interpreterSettings.length; i++) { + for (var i = 0; i < $scope.interpreterSettings.length; i++) { var setting = $scope.interpreterSettings[i]; - if(setting.id === settingId) { + if (setting.id === settingId) { angular.copy(setting.properties, $scope.interpreterSettingProperties); break; } @@ -105,9 +107,9 @@ module zeppelin { $scope.addNewInterpreterProperty(settingId); var properties = {}; - for (var i=0; i < $scope.interpreterSettings.length; i++) { + for (var i = 0; i < $scope.interpreterSettings.length; i++) { var setting = $scope.interpreterSettings[i]; - if(setting.id === settingId) { + if (setting.id === settingId) { for (var p in setting.properties) { properties[p] = setting.properties[p].value; } @@ -117,7 +119,7 @@ module zeppelin { $http.put(restApiBase() + '/interpreter/setting/' + settingId, properties). success(function(data, status, headers, config) { - for (var i=0; i < $scope.interpreterSettings.length; i++) { + for (var i = 0; i < $scope.interpreterSettings.length; i++) { var setting = $scope.interpreterSettings[i]; if (setting.id === settingId) { $scope.interpreterSettings.splice(i, 1); @@ -131,10 +133,10 @@ module zeppelin { }); }; - $scope.resetInterpreterSetting = function(settingId){ - for (var i=0; i<$scope.interpreterSettings.length; i++) { + $scope.resetInterpreterSetting = function(settingId) { + for (var i = 0; i < $scope.interpreterSettings.length; i++) { var setting = $scope.interpreterSettings[i]; - if (setting.id ===settingId) { + if (setting.id === settingId) { angular.copy($scope.interpreterSettingProperties, setting.properties); break; } @@ -150,7 +152,7 @@ module zeppelin { console.log('Delete setting %o', settingId); $http.delete(restApiBase() + '/interpreter/setting/' + settingId). success(function(data, status, headers, config) { - for (var i=0; i < $scope.interpreterSettings.length; i++) { + for (var i = 0; i < $scope.interpreterSettings.length; i++) { var setting = $scope.interpreterSettings[i]; if (setting.id === settingId) { $scope.interpreterSettings.splice(i, 1); @@ -166,7 +168,7 @@ module zeppelin { $scope.newInterpreterGroupChange = function() { var property = {}; var intpGroupInfo = $scope.availableInterpreters[$scope.newInterpreterSetting.group]; - for (var i=0; i void; } @@ -100,7 +103,7 @@ module zeppelin { $rootScope.sendEventToServer = function(event: ZEvent) { $rootScope.$emit('sendEventToServer', event.toJson()); - } + }; /** get the childs event and sebd to the websocket server */ $rootScope.$on('sendEventToServer', function(event, data) { diff --git a/zeppelin-web/app/typescripts/controllers/nav.ts b/zeppelin-web/app/typescripts/controllers/nav.ts index bcfc41ff..a4304529 100644 --- a/zeppelin-web/app/typescripts/controllers/nav.ts +++ b/zeppelin-web/app/typescripts/controllers/nav.ts @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -'use strict'; /** * @ngdoc function @@ -24,7 +23,11 @@ * * @author anthonycorbacho */ + module zeppelin { + +'use strict'; + interface INavCtrlScope extends ng.IScope { notes: Array; diff --git a/zeppelin-web/app/typescripts/controllers/notebook.ts b/zeppelin-web/app/typescripts/controllers/notebook.ts index 56fe141b..fa0bf7d2 100644 --- a/zeppelin-web/app/typescripts/controllers/notebook.ts +++ b/zeppelin-web/app/typescripts/controllers/notebook.ts @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -'use strict'; /** * @ngdoc function @@ -27,6 +26,8 @@ module zeppelin { +'use strict'; + export class Notebook { id: string; name: string; @@ -115,7 +116,7 @@ module zeppelin { } for (var o in $scope.cronOption) { - if ($scope.cronOption[o].value===value) { + if ($scope.cronOption[o].value === value) { return $scope.cronOption[o].name; } } @@ -174,7 +175,7 @@ module zeppelin { $scope.isNoteRunning = function() { var running = false; - if(!$scope.note){ return false; } + if (!$scope.note) { return false; } for (var i = 0; i < $scope.note.paragraphs.length; i++) { if ( $scope.note.paragraphs[i].status === 'PENDING' || $scope.note.paragraphs[i].status === 'RUNNING') { running = true; @@ -189,15 +190,15 @@ module zeppelin { $scope.setConfig(); }; - /** Set cron expression for this note **/ + // Set cron expression for this note $scope.setCronScheduler = function(cronExpr) { $scope.note.config.cron = cronExpr; $scope.setConfig(); }; - /** Update note config **/ + // Update note config $scope.setConfig = function(config) { - if(config) { + if (config) { $scope.note.config = config; } $rootScope.sendEventToServer(new ZNoteUpdateEvent($scope.note)); @@ -226,7 +227,7 @@ module zeppelin { updateNote(note); } initializeLookAndFeel(); - //open interpreter binding setting when there're none selected + // open interpreter binding setting when there're none selected getInterpreterBindings(getInterpreterBindingsCallBack); }); @@ -240,7 +241,7 @@ module zeppelin { }; var cleanParagraphExcept = function(paragraphId, note) { - var noteCopy : any = {}; + var noteCopy: any = {}; noteCopy.id = note.id; noteCopy.name = note.name; noteCopy.config = note.config; @@ -304,7 +305,7 @@ module zeppelin { } } - if (newIndex<0 || newIndex>=$scope.note.paragraphs.length) { + if (newIndex < 0 || newIndex >= $scope.note.paragraphs.length) { return; } $rootScope.sendEventToServer(new ZMoveParagraphEvent(paragraphId, newIndex)); @@ -330,7 +331,7 @@ module zeppelin { $scope.$on('moveFocusToNextParagraph', function(event, currentParagraphId){ var focus = false; - for (var i=0; i<$scope.note.paragraphs.length; i++) { + for (var i = 0; i < $scope.note.paragraphs.length; i++) { if (focus === false ) { if ($scope.note.paragraphs[i].id === currentParagraphId) { focus = true; @@ -356,8 +357,8 @@ module zeppelin { $scope.note.config = note.config; $scope.note.info = note.info; - var newParagraphIds = note.paragraphs.map(function(x, i, arr) {return x.id;}); - var oldParagraphIds = $scope.note.paragraphs.map(function(x, i, arr) {return x.id;}); + var newParagraphIds = note.paragraphs.map(function(x, i, arr) { return x.id; }); + var oldParagraphIds = $scope.note.paragraphs.map(function(x, i, arr) { return x.id; }); var numNewParagraphs = newParagraphIds.length; var numOldParagraphs = oldParagraphIds.length; @@ -384,7 +385,7 @@ module zeppelin { $scope.note.paragraphs.splice(oldIdx, 1); $scope.note.paragraphs.splice(idx, 0, newEntry); // rebuild id list since paragraph has moved. - oldParagraphIds = $scope.note.paragraphs.map(function(x) {return x.id;}); + oldParagraphIds = $scope.note.paragraphs.map(function(x) { return x.id; }); } } } @@ -392,7 +393,7 @@ module zeppelin { /** remove paragraph */ if (numNewParagraphs < numOldParagraphs) { for (var oldidx in oldParagraphIds) { - if(oldParagraphIds[oldidx] !== newParagraphIds[oldidx]) { + if (oldParagraphIds[oldidx] !== newParagraphIds[oldidx]) { $scope.note.paragraphs.splice(oldidx, 1); break; } @@ -439,9 +440,9 @@ module zeppelin { }; $scope.interpreterSelectionListeners = { - accept : function(sourceItemHandleScope, destSortableScope) {return true;}, - itemMoved: function (event) {}, - orderChanged: function(event) {} + accept : function(sourceItemHandleScope, destSortableScope) { return true; }, + itemMoved: function (event) { console.log('itemMoved'); }, + orderChanged: function(event) { console.log('orderChanged'); } }; $scope.openSetting = function() { diff --git a/zeppelin-web/app/typescripts/controllers/paragraph.ts b/zeppelin-web/app/typescripts/controllers/paragraph.ts index d6edb55f..bb32cd1a 100644 --- a/zeppelin-web/app/typescripts/controllers/paragraph.ts +++ b/zeppelin-web/app/typescripts/controllers/paragraph.ts @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -'use strict'; /** * @ngdoc function @@ -28,6 +27,8 @@ module zeppelin { +'use strict'; + export class Paragraph { id: string; title: string; @@ -65,7 +66,7 @@ module zeppelin { if (isNaN(timeMs)) { return ' '; } - return 'Took ' + (timeMs/1000) + ' seconds'; + return 'Took ' + (timeMs / 1000) + ' seconds'; } base64ImageSrc(): string { @@ -242,7 +243,7 @@ module zeppelin { $scope.$on('updateParagraph', function(event, data) { var updatedParagraph = new Paragraph(data.paragraph); - if (updatedParagraph.id !== $scope.paragraph.id) return; + if (updatedParagraph.id !== $scope.paragraph.id) { return; } if (updatedParagraph.dateCreated !== $scope.paragraph.dateCreated || updatedParagraph.dateFinished !== $scope.paragraph.dateFinished || updatedParagraph.dateStarted !== $scope.paragraph.dateStarted || @@ -257,7 +258,10 @@ module zeppelin { $scope.lastData.settings = angular.copy(updatedParagraph.settings); $scope.lastData.config = angular.copy(updatedParagraph.config); - //console.log('updateParagraph oldData %o, newData %o. type %o -> %o, mode %o -> %o', $scope.paragraph, data, oldType, newType, oldGraphMode, newGraphMode); + /* + ** console.log('updateParagraph oldData %o, newData %o. type %o -> %o, mode %o -> %o', + ** $scope.paragraph, data, oldType, newType, oldGraphMode, newGraphMode); + */ var updatedText = updatedParagraph.text; if ($scope.paragraph.text !== updatedText) { @@ -368,7 +372,7 @@ module zeppelin { $scope.$on('focusParagraph', function(event, paragraphId) { if ($scope.paragraph.id === paragraphId) { - $('body').scrollTo('#' + paragraphId + '_editor', 300, {offset:-60}); + $('body').scrollTo('#' + paragraphId + '_editor', 300, {offset: -60}); } }); @@ -415,7 +419,8 @@ module zeppelin { $scope.goToSingleParagraph = function () { var noteId = $route.current.pathParams.noteId; - var redirectToUrl = location.protocol + '//' + location.host + '/#/notebook/' + noteId + '/paragraph/' + $scope.paragraph.id + '?asIframe'; + var redirectToUrl = location.protocol + '//' + location.host + '/#/notebook/'; + redirectToUrl += noteId + '/paragraph/' + $scope.paragraph.id + '?asIframe'; $window.open(redirectToUrl); }; }); diff --git a/zeppelin-web/app/typescripts/controllers/paragraph_editor.ts b/zeppelin-web/app/typescripts/controllers/paragraph_editor.ts index 2853c6e0..d3da4c94 100644 --- a/zeppelin-web/app/typescripts/controllers/paragraph_editor.ts +++ b/zeppelin-web/app/typescripts/controllers/paragraph_editor.ts @@ -12,7 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -'use strict'; /** * @ngdoc function @@ -24,6 +23,8 @@ module zeppelin { +'use strict'; + interface IParagraphEditorCtrlScope extends ng.IScope { editor: any; @@ -67,7 +68,8 @@ module zeppelin { $scope.editor.renderer.setShowGutter(false); $scope.editor.setHighlightActiveLine(false); $scope.editor.focus(); - var hight = $scope.editor.getSession().getScreenLength() * $scope.editor.renderer.lineHeight + $scope.editor.renderer.scrollBar.getWidth(); + var hight = $scope.editor.getSession().getScreenLength() * $scope.editor.renderer.lineHeight; + hight += $scope.editor.renderer.scrollBar.getWidth(); setEditorHeight(_editor.container.id, hight); $scope.editor.getSession().setUseWrapMode(true); @@ -82,11 +84,12 @@ module zeppelin { $scope.editor.setOptions({ enableBasicAutocompletion: true, enableSnippets: false, - enableLiveAutocompletion:false + enableLiveAutocompletion: false }); + var remoteCompleter = { getCompletions : function(editor, session, pos, prefix, callback) { - if (!$scope.editor.isFocused() ){ return;} + if (!$scope.editor.isFocused()) { return; } var buf = session.getTextRange(new Range(0, 0, pos.row, pos.column)); $rootScope.sendEventToServer(new ZCodeCompletionEvent($scope.$parent.paragraph, buf)); @@ -97,9 +100,9 @@ module zeppelin { for (var c in data.completions) { var v = data.completions[c]; completions.push({ - name:v, - value:v, - score:300 + name: v, + value: v, + score: 300 }); } callback(null, completions); @@ -186,7 +189,7 @@ module zeppelin { } else if (keyCode === 40 || (keyCode === 78 && e.ctrlKey)) { // DOWN numRows = $scope.editor.getSession().getLength(); currentRow = $scope.editor.getCursorPosition().row; - if (currentRow === numRows-1) { + if (currentRow === (numRows - 1)) { // move focus to next paragraph $rootScope.$emit('moveFocusToNextParagraph', $scope.$parent.paragraph.id); } diff --git a/zeppelin-web/app/typescripts/controllers/paragraph_result.ts b/zeppelin-web/app/typescripts/controllers/paragraph_result.ts index 3a3644de..ee9b3bad 100644 --- a/zeppelin-web/app/typescripts/controllers/paragraph_result.ts +++ b/zeppelin-web/app/typescripts/controllers/paragraph_result.ts @@ -12,7 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -'use strict'; /** * @ngdoc function @@ -24,6 +23,8 @@ module zeppelin { +'use strict'; + interface IParagraphResultCtrlScope extends ng.IScope { init: () => void; paragraph: Paragraph; @@ -51,7 +52,7 @@ module zeppelin { $rootScope: IZeppelinRootScope, $timeout: ng.ITimeoutService) { - // Controller init + // controller init $scope.init = function() { $scope.paragraph = $scope.$parent.paragraph; $scope.chart = {}; @@ -69,7 +70,9 @@ module zeppelin { $scope.$on('updateParagraph', function(event, data) { var updatedParagraph = new Paragraph(data.paragraph); - if (updatedParagraph.id !== $scope.paragraph.id) return; + if (updatedParagraph.id !== $scope.paragraph.id) { + return; + } var oldType = $scope.paragraph.result.type; var newType = updatedParagraph.result.type; @@ -100,7 +103,7 @@ module zeppelin { if ($('#p' + $scope.paragraph.id + '_html').length) { try { $('#p' + $scope.paragraph.id + '_html').html($scope.paragraph.result.msg); - } catch(err) { + } catch (err) { console.log('HTML rendering error %o', err); } } else { @@ -144,7 +147,7 @@ module zeppelin { columnNames.push({name: col, index: j, aggr: 'sum'}); } else { cols.push(col); - cols2.push({key: (columnNames[i]) ? columnNames[i].name: undefined, value: col}); + cols2.push({key: (columnNames[i]) ? columnNames[i].name : undefined, value : col}); } } if (i !== 0) { @@ -175,11 +178,10 @@ module zeppelin { if (!type || type === GraphMode.table) { drawTable($scope.paragraph.result); - } - else { + } else { drawD3Chart(type, $scope.paragraph.result, refresh); } - } + }; var drawTable = function(data) { var getTableContentFormat = function(d) { @@ -206,7 +208,7 @@ module zeppelin { var dStr = d.toString(); var splitted = dStr.split('.'); var formatted = splitted[0].replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,'); - if (splitted.length>1) { + if (splitted.length > 1) { formatted += '.' + splitted[1]; } return formatted; @@ -252,11 +254,11 @@ module zeppelin { if ($('#p' + $scope.paragraph.id + '_table').length) { try { renderTable(); - } catch(err) { + } catch (err) { console.log('Chart drawing error %o', err); } } else { - $timeout(retryRenderer,10); + $timeout(retryRenderer, 10); } }; $timeout(retryRenderer); @@ -279,11 +281,11 @@ module zeppelin { if (type === GraphMode.pieChart) { var d = pivotDataToD3ChartFormat(p, true).d3g; - $scope.chart[type].x(function(d) { return d.label;}) - .y(function(d) { return d.value;}); + $scope.chart[type].x(function(d) { return d.label; }) + .y(function(d) { return d.value; }); - if ( d.length > 0 ) { - for ( var i=0; i 0) { + for (var i = 0; i < d[0].values.length ; i++) { var e = d[0].values[i]; d3g.push({ label : e.x, @@ -319,13 +321,15 @@ module zeppelin { var animationDuration = 300; var numberOfDataThreshold = 150; + // turn off animation when dataset is too large. (for performance issue) // still, since dataset is large, the chart content sequentially appears like animated. try { if (d3g[0].values.length > numberOfDataThreshold) { animationDuration = 0; } - } catch(ignoreErr) { + } catch (ignoreErr) { + console.log('D3 animation error %o', ignoreErr); } var chartEl = d3.select('#p' + $scope.paragraph.id + '_' + type + ' svg') @@ -342,11 +346,11 @@ module zeppelin { if ($('#p' + $scope.paragraph.id + '_' + type + ' svg').length !== 0) { try { renderChart(); - } catch(err) { + } catch (err) { console.log('Chart drawing error %o', err); } } else { - $timeout(retryRenderer,10); + $timeout(retryRenderer, 10); } }; $timeout(retryRenderer); @@ -462,27 +466,27 @@ module zeppelin { var values = graph.values; var aggrFunc = { - sum : function(a,b) { + sum : function(a, b) { var varA = (a !== undefined) ? (isNaN(a) ? 1 : parseFloat(a)) : 0; var varB = (b !== undefined) ? (isNaN(b) ? 1 : parseFloat(b)) : 0; return varA + varB; }, - count : function(a,b) { - var varA = (a !== undefined) ? parseInt(a) : 0; + count : function(a, b) { + var varA = (a !== undefined) ? parseInt(a, 10) : 0; var varB = (b !== undefined) ? 1 : 0; return varA + varB; }, - min : function(a,b) { + min : function(a, b) { var varA = (a !== undefined) ? (isNaN(a) ? 1 : parseFloat(a)) : 0; var varB = (b !== undefined) ? (isNaN(b) ? 1 : parseFloat(b)) : 0; - return Math.min(varA,varB); + return Math.min(varA, varB); }, - max : function(a,b) { + max : function(a, b) { var varA = (a !== undefined) ? (isNaN(a) ? 1 : parseFloat(a)) : 0; var varB = (b !== undefined) ? (isNaN(b) ? 1 : parseFloat(b)) : 0; - return Math.max(varA,varB); + return Math.max(varA, varB); }, - avg : function(a,b,c) { + avg : function(a, b, c) { var varA = (a !== undefined) ? (isNaN(a) ? 1 : parseFloat(a)) : 0; var varB = (b !== undefined) ? (isNaN(b) ? 1 : parseFloat(b)) : 0; return varA + varB; @@ -500,13 +504,13 @@ module zeppelin { var schema = {}; var rows = {}; - for (var i=0; i < data.rows.length; i++) { + for (var i = 0; i < data.rows.length; i++) { var row = data.rows[i]; var newRow = {}; var s = schema; var p = rows; - for (var k=0; k < keys.length; k++) { + for (var k = 0; k < keys.length; k++) { var key = keys[k]; // add key to schema @@ -528,7 +532,7 @@ module zeppelin { p = p[keyKey]; } - for (var g=0; g < groups.length; g++) { + for (var g = 0; g < groups.length; g++) { var group = groups[g]; var groupKey = row[group.index]; @@ -550,7 +554,7 @@ module zeppelin { p = p[groupKey]; } - for (var v=0; v < values.length; v++) { + for (var v = 0; v < values.length; v++) { var value = values[v]; var valueKey = value.name + '(' + value.aggr + ')'; @@ -577,7 +581,7 @@ module zeppelin { } } } - //console.log('schema=%o, rows=%o', schema, rows); + // console.log('schema=%o, rows=%o', schema, rows); return { schema : schema, @@ -609,7 +613,9 @@ module zeppelin { }; var traverse = function(sKey, s, rKey, r, func, rowName?, rowValue?, colName?) { - //console.log('TRAVERSE sKey=%o, s=%o, rKey=%o, r=%o, rowName=%o, rowValue=%o, colName=%o', sKey, s, rKey, r, rowName, rowValue, colName); + /* console.log('TRAVERSE sKey=%o, s=%o, rKey=%o, r=%o, rowName=%o, + ** rowValue=%o, colName=%o', sKey, s, rKey, r, rowName, rowValue, colName); + */ if (s.type === 'key') { rowName = concat(rowName, sKey); @@ -655,7 +661,7 @@ module zeppelin { for (var k in rows) { traverse(sKey, schema[sKey], k, rows[k], function(rowName, rowValue, colName, value) { - //console.log('RowName=%o, row=%o, col=%o, value=%o', rowName, rowValue, colName, value); + // console.log('RowName=%o, row=%o, col=%o, value=%o', rowName, rowValue, colName, value); if (rowNameIndex[rowValue] === undefined) { rowIndexValue[rowIdx] = rowValue; rowNameIndex[rowValue] = rowIdx++; @@ -754,7 +760,7 @@ module zeppelin { }); if (!String.prototype.startsWith) { - String.prototype.startsWith = function (str: string) : boolean { + String.prototype.startsWith = function (str: string): boolean { return this.indexOf(str) === 0; }; } diff --git a/zeppelin-web/app/typescripts/directives/resizable.ts b/zeppelin-web/app/typescripts/directives/resizable.ts index aa04777f..c3a8201b 100644 --- a/zeppelin-web/app/typescripts/directives/resizable.ts +++ b/zeppelin-web/app/typescripts/directives/resizable.ts @@ -5,7 +5,7 @@ angular.module('zeppelinWebApp').directive('resizable', function () { autoHide: true, handles: 'se', helper: 'resizable-helper', - minHeight:100, + minHeight: 100, grid: [10000, 10] // allow only vertical }; @@ -14,7 +14,7 @@ angular.module('zeppelinWebApp').directive('resizable', function () { scope: { callback: '&onResize' }, - link: function postLink(scope : any, elem, attrs) { + link: function postLink(scope: any, elem, attrs) { attrs.$observe('allowresize', function(isAllowed) { if (isAllowed === 'true') { elem.resizable(resizableConfig); diff --git a/zeppelin-web/app/typescripts/events.ts b/zeppelin-web/app/typescripts/events.ts index 43241769..635b6a75 100644 --- a/zeppelin-web/app/typescripts/events.ts +++ b/zeppelin-web/app/typescripts/events.ts @@ -23,8 +23,8 @@ module zeppelin { } export class ZEvent { - op:string; - data:any; + op: string; + data: any; toJson() { return {op: this.op, data: this.data}; diff --git a/zeppelin-web/app/typescripts/types.ts b/zeppelin-web/app/typescripts/types.ts index 965da6a0..7b190c83 100644 --- a/zeppelin-web/app/typescripts/types.ts +++ b/zeppelin-web/app/typescripts/types.ts @@ -11,7 +11,7 @@ interface JQuery { } // nvd3 -declare var nv: NVD3 +declare var nv: NVD3; interface NVD3 { models: any; diff --git a/zeppelin-web/app/views/main.html b/zeppelin-web/app/views/main.html index 001a076a..fb0a49e4 100644 --- a/zeppelin-web/app/views/main.html +++ b/zeppelin-web/app/views/main.html @@ -19,7 +19,7 @@

- Welcome to Zeppelin! + Welcome to Zeppelin! ROFL

Zeppelin is web-based notebook that enables interactive data analytics.
You can make beautiful data-driven, interactive, collaborative document with SQL, code and even more!
diff --git a/zeppelin-web/tslint.json b/zeppelin-web/tslint.json index 496998db..525e9d2e 100644 --- a/zeppelin-web/tslint.json +++ b/zeppelin-web/tslint.json @@ -3,14 +3,13 @@ "ban": false, "class-name": true, "comment-format": [true, - "check-space", - "check-lowercase" + "check-space" ], "curly": true, "eofline": true, "forin": false, "indent": [true, 4], - "interface-name": true, + "interface-name": false, "jsdoc-format": true, "label-position": true, "label-undefined": true, @@ -34,7 +33,7 @@ "no-debugger": true, "no-duplicate-key": true, "no-duplicate-variable": false, - "no-empty": true, + "no-empty": false, "no-eval": true, "no-string-literal": true, "no-switch-case-fall-through": true, From 6fb0b6362dc8422f0ff54124d1ad3f7b067e2532 Mon Sep 17 00:00:00 2001 From: Damien Corneau Date: Thu, 19 Mar 2015 12:14:55 +0900 Subject: [PATCH 4/4] Replace ngmin with ngannotate to reduce grunt build on web project by 75% --- zeppelin-web/Gruntfile.js | 33 +++++++++++++++------------------ zeppelin-web/package.json | 2 +- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/zeppelin-web/Gruntfile.js b/zeppelin-web/Gruntfile.js index a106f8e8..915fbffc 100644 --- a/zeppelin-web/Gruntfile.js +++ b/zeppelin-web/Gruntfile.js @@ -28,6 +28,18 @@ module.exports = function (grunt) { yeoman: appConfig, + // use ngAnnotate instead og ngMin + ngAnnotate: { + dist: { + files: [{ + expand: true, + cwd: '.tmp/concat/scripts', + src: '*.js', + dest: '.tmp/concat/scripts' + }] + } + }, + // lint typescript files tslint: { options: { @@ -38,7 +50,6 @@ module.exports = function (grunt) { } }, - // Watches files for changes and runs tasks based on the changed files watch: { bower: { @@ -49,8 +60,8 @@ module.exports = function (grunt) { files: ['<%= yeoman.app %>/typescripts/**/*.ts'], tasks: ['typescript', 'tslint'], options: { - spawn: false, - livereload: '<%= connect.options.livereload %>' + spawn: false, + livereload: '<%= connect.options.livereload %>' } }, jsTest: { @@ -278,20 +289,6 @@ module.exports = function (grunt) { } }, - // ngmin tries to make the code safe for minification automatically by - // using the Angular long form for dependency injection. It doesn't work on - // things like resolve or inject so those have to be done manually. - ngmin: { - dist: { - files: [{ - expand: true, - cwd: '.tmp/concat/scripts', - src: '*.js', - dest: '.tmp/concat/scripts' - }] - } - }, - // Copies remaining files to places other tasks can use copy: { dist: { @@ -419,7 +416,7 @@ module.exports = function (grunt) { 'concurrent:dist', 'autoprefixer', 'concat', - 'ngmin', + 'ngAnnotate', 'copy:dist', 'cssmin', 'uglify', diff --git a/zeppelin-web/package.json b/zeppelin-web/package.json index c1426925..2bcf605b 100644 --- a/zeppelin-web/package.json +++ b/zeppelin-web/package.json @@ -20,7 +20,7 @@ "grunt-filerev": "^0.2.1", "grunt-karma": "~0.8.3", "grunt-newer": "^0.7.0", - "grunt-ngmin": "^0.0.3", + "grunt-ng-annotate": "^0.10.0", "grunt-svgmin": "^0.4.0", "grunt-tslint": "^2.0.0", "grunt-typescript": "",