From bfc535a11f88d2511a479df289b0272e9c098019 Mon Sep 17 00:00:00 2001 From: CloverHearts Date: Wed, 26 Oct 2016 22:47:45 +0900 Subject: [PATCH 1/2] implement restful api editor --- zeppelin-web/bower.json | 3 +- zeppelin-web/src/app/app.js | 3 +- .../paragraph/paragraph.controller.js | 9 ++ .../src/app/notebook/paragraph/paragraph.html | 8 ++ .../restfuleditor.directive.css | 0 .../restful-editor/restfuleditor.directive.js | 108 ++++++++++++++++++ zeppelin-web/src/index.html | 3 + zeppelin-web/test/karma.conf.js | 1 + 8 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 zeppelin-web/src/components/restful-editor/restfuleditor.directive.css create mode 100644 zeppelin-web/src/components/restful-editor/restfuleditor.directive.js diff --git a/zeppelin-web/bower.json b/zeppelin-web/bower.json index 6a101b8e1f2..e656a22c538 100644 --- a/zeppelin-web/bower.json +++ b/zeppelin-web/bower.json @@ -33,7 +33,8 @@ "handsontable": "~0.24.2", "moment-duration-format": "^1.3.0", "select2": "^4.0.3", - "github-markdown-css": "^2.4.0" + "github-markdown-css": "^2.4.0", + "jsoneditor": "^5.5.9" }, "devDependencies": { "angular-mocks": "1.5.0" diff --git a/zeppelin-web/src/app/app.js b/zeppelin-web/src/app/app.js index 30d24c2d2eb..3f3b4e37824 100644 --- a/zeppelin-web/src/app/app.js +++ b/zeppelin-web/src/app/app.js @@ -33,7 +33,8 @@ 'xeditable', 'ngToast', 'focus-if', - 'ngResource' + 'ngResource', + 'restful-editor' ]) .filter('breakFilter', function() { return function(text) { diff --git a/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js b/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js index deab258ed65..8bab1c38799 100644 --- a/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js +++ b/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js @@ -115,6 +115,15 @@ initializeDefault(); + // clover test + $scope.paragraph.restfulObject = { hello: 'world'}; + $scope.restfulOptions={ + 'mode': 'form', + 'history': false, + 'theme': 'ace/theme/chrome', + 'search': false + }; + if ($scope.getResultType() === 'TABLE') { $scope.loadTableData($scope.paragraph.result); $scope.setGraphMode($scope.getGraphMode(), false, false); diff --git a/zeppelin-web/src/app/notebook/paragraph/paragraph.html b/zeppelin-web/src/app/notebook/paragraph/paragraph.html index de102e81a7d..052649487b8 100644 --- a/zeppelin-web/src/app/notebook/paragraph/paragraph.html +++ b/zeppelin-web/src/app/notebook/paragraph/paragraph.html @@ -37,6 +37,14 @@
+
+
+
+ @@ -147,6 +148,7 @@ + @@ -184,6 +186,7 @@ + diff --git a/zeppelin-web/test/karma.conf.js b/zeppelin-web/test/karma.conf.js index f9f03a413fa..d7960fd8369 100644 --- a/zeppelin-web/test/karma.conf.js +++ b/zeppelin-web/test/karma.conf.js @@ -65,6 +65,7 @@ module.exports = function(config) { 'bower_components/handsontable/dist/handsontable.js', 'bower_components/moment-duration-format/lib/moment-duration-format.js', 'bower_components/select2/dist/js/select2.js', + 'bower_components/jsoneditor/dist/jsoneditor.min.js', 'bower_components/angular-mocks/angular-mocks.js', // endbower 'src/app/app.js', From 5184d1deced7d2bac85ac1a501b43c03f9c0ca90 Mon Sep 17 00:00:00 2001 From: CloverHearts Date: Thu, 27 Oct 2016 07:11:42 +0900 Subject: [PATCH 2/2] create restful api editor --- zeppelin-web/bower.json | 3 +- zeppelin-web/src/app/app.js | 3 +- .../notebook/paragraph/paragraph-control.html | 3 + .../paragraph/paragraph.controller.js | 238 ++++- .../src/app/notebook/paragraph/paragraph.css | 78 +- .../src/app/notebook/paragraph/paragraph.html | 26 +- .../restfuleditor.directive.css | 933 ++++++++++++++++++ .../restful-editor/restfuleditor.directive.js | 67 +- zeppelin-web/src/fonts/jsoneditor-icons.svg | 893 +++++++++++++++++ zeppelin-web/src/index.html | 1 + 10 files changed, 2196 insertions(+), 49 deletions(-) create mode 100644 zeppelin-web/src/fonts/jsoneditor-icons.svg diff --git a/zeppelin-web/bower.json b/zeppelin-web/bower.json index e656a22c538..9469d04b0bf 100644 --- a/zeppelin-web/bower.json +++ b/zeppelin-web/bower.json @@ -34,7 +34,8 @@ "moment-duration-format": "^1.3.0", "select2": "^4.0.3", "github-markdown-css": "^2.4.0", - "jsoneditor": "^5.5.9" + "jsoneditor": "^5.5.9", + "angucomplete-alt": "^2.5.0" }, "devDependencies": { "angular-mocks": "1.5.0" diff --git a/zeppelin-web/src/app/app.js b/zeppelin-web/src/app/app.js index 3f3b4e37824..6e892b353da 100644 --- a/zeppelin-web/src/app/app.js +++ b/zeppelin-web/src/app/app.js @@ -34,7 +34,8 @@ 'ngToast', 'focus-if', 'ngResource', - 'restful-editor' + 'restful-editor', + 'angucomplete-alt' ]) .filter('breakFilter', function() { return function(text) { diff --git a/zeppelin-web/src/app/notebook/paragraph/paragraph-control.html b/zeppelin-web/src/app/notebook/paragraph/paragraph-control.html index 80a0dc579a0..3c4a8a8a25e 100644 --- a/zeppelin-web/src/app/notebook/paragraph/paragraph-control.html +++ b/zeppelin-web/src/app/notebook/paragraph/paragraph-control.html @@ -33,6 +33,9 @@ ng-click="toggleEditor()"> + = 0 || + regexFullApiUri.test(str.toLowerCase())) { + matches.push(restfulApiInfo); + } + }); + return matches; + }; + + $scope.setRestfulObject = function(userInputApiString) { + console.log('clover keyssss', arguments); + var keys = userInputApiString.split(' '); + var informationArray = $scope.restfulInformation.interpreters[0].restful; + console.log('clover got keys ', keys, informationArray); + var index = _.findIndex(informationArray, {'method': keys[0], 'uri': keys[2]}); + if (index >= 0) { + $scope.paragraph.restfulObject = angular.copy(informationArray[index].context); + } + }; + + $scope.selectedRestfulApiObject = function(selectObject) { + if (selectObject !== undefined) { + $scope.setRestfulObject(selectObject.title); + } + }; + + // clover test end. + if ($scope.getResultType() === 'TABLE') { $scope.loadTableData($scope.paragraph.result); $scope.setGraphMode($scope.getGraphMode(), false, false); @@ -305,6 +510,11 @@ }; $scope.runParagraph = function(data) { + + if ($scope.paragraph.config.isCodeEditorMode === false) { + console.log('clover - generate restful http hb'); + } + websocketMsgSrv.runParagraph($scope.paragraph.id, $scope.paragraph.title, data, $scope.paragraph.config, $scope.paragraph.settings.params); $scope.originalText = angular.copy(data); @@ -643,11 +853,11 @@ // autocomplete on '.' /* - $scope.editor.commands.on("afterExec", function(e, t) { - if (e.command.name == "insertstring" && e.args == "." ) { + $scope.editor.commands.on('afterExec', function(e, t) { + if (e.command.name == 'insertstring' && e.args == '.' ) { var all = e.editor.completers; //e.editor.completers = [remoteCompleter]; - e.editor.execCommand("startAutocomplete"); + e.editor.execCommand('startAutocomplete'); //e.editor.completers = all; } }); @@ -1458,7 +1668,7 @@ } } - //console.log("schema=%o, rows=%o", schema, rows); + //console.log('schema=%o, rows=%o', schema, rows); return { schema: schema, @@ -1490,7 +1700,7 @@ }; 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); @@ -1535,7 +1745,7 @@ 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++; @@ -2265,7 +2475,7 @@ data.paragraph.status === 'ERROR' || (data.paragraph.status === 'FINISHED' && statusChanged) || (!newActiveApp && oldActiveApp !== newActiveApp); - //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); if ($scope.paragraph.text !== data.paragraph.text) { if ($scope.dirtyText) { // check if editor has local update diff --git a/zeppelin-web/src/app/notebook/paragraph/paragraph.css b/zeppelin-web/src/app/notebook/paragraph/paragraph.css index 60b93d0f9a1..307befc862e 100644 --- a/zeppelin-web/src/app/notebook/paragraph/paragraph.css +++ b/zeppelin-web/src/app/notebook/paragraph/paragraph.css @@ -488,7 +488,7 @@ table.table-striped { } .appSuggestion { - width: 200px; + width: 800px; padding: 5px 10px 5px 10px; } @@ -498,3 +498,79 @@ table.table-striped { padding-left: 4px !important; width: 20px; } + +/* auto completion CSS*/ + +.searchMatch { + color: red; +} + +.angucomplete-holder { + position: relative; +} + +.angucomplete-dropdown { + border-color: #ececec; + border-width: 1px; + border-style: solid; + border-radius: 2px; + width: 100%; + padding: 6px; + cursor: pointer; + z-index: 9999; + position: absolute; + /*top: 32px; + left: 0px; + */ + margin-top: -6px; + background-color: #ffffff; +} + +.angucomplete-searching { + color: #acacac; + font-size: 14px; +} + +.angucomplete-description { + font-size: 14px; + color: gray +} + +.angucomplete-row { + padding: 5px; + color: #000000; + margin-bottom: 4px; + clear: both; +} + +.angucomplete-selected-row { + background-color: lightblue; + color: #ffffff; +} + +.angucomplete-image-holder { + padding-top: 2px; + float: left; + margin-right: 10px; + margin-left: 5px; +} + +.angucomplete-image { + height: 34px; + width: 34px; + border-radius: 50%; + border-color: #ececec; + border-style: solid; + border-width: 1px; +} + +.angucomplete-image-default { + /* Add your own default image here + background-image: url('/assets/default.png'); + */ + background-position: center; + background-size: contain; + height: 34px; + width: 34px; +} + diff --git a/zeppelin-web/src/app/notebook/paragraph/paragraph.html b/zeppelin-web/src/app/notebook/paragraph/paragraph.html index 052649487b8..82caa8c73a4 100644 --- a/zeppelin-web/src/app/notebook/paragraph/paragraph.html +++ b/zeppelin-web/src/app/notebook/paragraph/paragraph.html @@ -37,15 +37,33 @@
-
+
+
+ + +
+ options="restfulOptions" > +
-
div.jsoneditor-icon { + background-position: -24px -24px; +} + +div.jsoneditor-contextmenu button.jsoneditor-remove:hover > div.jsoneditor-icon, +div.jsoneditor-contextmenu button.jsoneditor-remove:focus > div.jsoneditor-icon { + background-position: -24px 0; +} + +div.jsoneditor-contextmenu button.jsoneditor-append > div.jsoneditor-icon { + background-position: 0 -24px; +} + +div.jsoneditor-contextmenu button.jsoneditor-append:hover > div.jsoneditor-icon, +div.jsoneditor-contextmenu button.jsoneditor-append:focus > div.jsoneditor-icon { + background-position: 0 0; +} + +div.jsoneditor-contextmenu button.jsoneditor-insert > div.jsoneditor-icon { + background-position: 0 -24px; +} + +div.jsoneditor-contextmenu button.jsoneditor-insert:hover > div.jsoneditor-icon, +div.jsoneditor-contextmenu button.jsoneditor-insert:focus > div.jsoneditor-icon { + background-position: 0 0; +} + +div.jsoneditor-contextmenu button.jsoneditor-duplicate > div.jsoneditor-icon { + background-position: -48px -24px; +} + +div.jsoneditor-contextmenu button.jsoneditor-duplicate:hover > div.jsoneditor-icon, +div.jsoneditor-contextmenu button.jsoneditor-duplicate:focus > div.jsoneditor-icon { + background-position: -48px 0; +} + +div.jsoneditor-contextmenu button.jsoneditor-sort-asc > div.jsoneditor-icon { + background-position: -168px -24px; +} + +div.jsoneditor-contextmenu button.jsoneditor-sort-asc:hover > div.jsoneditor-icon, +div.jsoneditor-contextmenu button.jsoneditor-sort-asc:focus > div.jsoneditor-icon { + background-position: -168px 0; +} + +div.jsoneditor-contextmenu button.jsoneditor-sort-desc > div.jsoneditor-icon { + background-position: -192px -24px; +} + +div.jsoneditor-contextmenu button.jsoneditor-sort-desc:hover > div.jsoneditor-icon, +div.jsoneditor-contextmenu button.jsoneditor-sort-desc:focus > div.jsoneditor-icon { + background-position: -192px 0; +} + +/* ContextMenu - sub menu */ + +div.jsoneditor-contextmenu ul li button.jsoneditor-selected, +div.jsoneditor-contextmenu ul li button.jsoneditor-selected:hover, +div.jsoneditor-contextmenu ul li button.jsoneditor-selected:focus { + color: white; + background-color: #ee422e; +} + +div.jsoneditor-contextmenu ul li { + overflow: hidden; +} + +div.jsoneditor-contextmenu ul li ul { + display: none; + position: relative; + left: -10px; + top: 0; + border: none; + box-shadow: inset 0 0 10px rgba(128, 128, 128, 0.5); + padding: 0 10px; + /* TODO: transition is not supported on IE8-9 */ + -webkit-transition: all 0.3s ease-out; + -moz-transition: all 0.3s ease-out; + -o-transition: all 0.3s ease-out; + transition: all 0.3s ease-out; +} + + + +div.jsoneditor-contextmenu ul li ul li button { + padding-left: 24px; + animation: all ease-in-out 1s; +} + +div.jsoneditor-contextmenu ul li ul li button:hover, +div.jsoneditor-contextmenu ul li ul li button:focus { + background-color: #f5f5f5; +} + +div.jsoneditor-contextmenu button.jsoneditor-type-string > div.jsoneditor-icon { + background-position: -144px -24px; +} + +div.jsoneditor-contextmenu button.jsoneditor-type-string:hover > div.jsoneditor-icon, +div.jsoneditor-contextmenu button.jsoneditor-type-string:focus > div.jsoneditor-icon, +div.jsoneditor-contextmenu button.jsoneditor-type-string.jsoneditor-selected > div.jsoneditor-icon { + background-position: -144px 0; +} + +div.jsoneditor-contextmenu button.jsoneditor-type-auto > div.jsoneditor-icon { + background-position: -120px -24px; +} + +div.jsoneditor-contextmenu button.jsoneditor-type-auto:hover > div.jsoneditor-icon, +div.jsoneditor-contextmenu button.jsoneditor-type-auto:focus > div.jsoneditor-icon, +div.jsoneditor-contextmenu button.jsoneditor-type-auto.jsoneditor-selected > div.jsoneditor-icon { + background-position: -120px 0; +} + +div.jsoneditor-contextmenu button.jsoneditor-type-object > div.jsoneditor-icon { + background-position: -72px -24px; +} + +div.jsoneditor-contextmenu button.jsoneditor-type-object:hover > div.jsoneditor-icon, +div.jsoneditor-contextmenu button.jsoneditor-type-object:focus > div.jsoneditor-icon, +div.jsoneditor-contextmenu button.jsoneditor-type-object.jsoneditor-selected > div.jsoneditor-icon { + background-position: -72px 0; +} + +div.jsoneditor-contextmenu button.jsoneditor-type-array > div.jsoneditor-icon { + background-position: -96px -24px; +} + +div.jsoneditor-contextmenu button.jsoneditor-type-array:hover > div.jsoneditor-icon, +div.jsoneditor-contextmenu button.jsoneditor-type-array:focus > div.jsoneditor-icon, +div.jsoneditor-contextmenu button.jsoneditor-type-array.jsoneditor-selected > div.jsoneditor-icon { + background-position: -96px 0; +} + +div.jsoneditor-contextmenu button.jsoneditor-type-modes > div.jsoneditor-icon { + background-image: none; + width: 6px; +} +div.jsoneditor-menu { + display: none; + width: 100%; + height: 35px; + padding: 2px; + margin: 0; + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; + color: white; +} + +div.jsoneditor-menu > button, +div.jsoneditor-menu > div.jsoneditor-modes > button { + width: 26px; + height: 26px; + margin: 2px; + padding: 0; + border-radius: 2px; + border: 1px solid transparent; + background: transparent url("../../fonts/jsoneditor-icons.svg"); + color: white; + opacity: 0.8; + font-family: inherit; + font-size: 10pt; + float: left; +} + +div.jsoneditor-menu > button:hover, +div.jsoneditor-menu > div.jsoneditor-modes > button:hover { + background-color: rgba(255,255,255,0.2); + border: 1px solid rgba(255,255,255,0.4); +} + +div.jsoneditor-menu > button:focus, +div.jsoneditor-menu > button:active, +div.jsoneditor-menu > div.jsoneditor-modes > button:focus, +div.jsoneditor-menu > div.jsoneditor-modes > button:active { + background-color: rgba(255,255,255,0.3); +} + +div.jsoneditor-menu > button:disabled, +div.jsoneditor-menu > div.jsoneditor-modes > button:disabled { + opacity: 0.5; +} + +div.jsoneditor-menu > button.jsoneditor-collapse-all { + background-position: 0 -96px; + display: none; +} + +div.jsoneditor-menu > button.jsoneditor-expand-all { + background-position: 0 -120px; + display: none; +} + +div.jsoneditor-menu > button.jsoneditor-undo { + background-position: -24px -96px; +} + +div.jsoneditor-menu > button.jsoneditor-undo:disabled { + background-position: -24px -120px; +} + +div.jsoneditor-menu > button.jsoneditor-redo { + background-position: -48px -96px; +} + +div.jsoneditor-menu > button.jsoneditor-redo:disabled { + background-position: -48px -120px; +} + +div.jsoneditor-menu > button.jsoneditor-compact { + background-position: -72px -96px; +} + +div.jsoneditor-menu > button.jsoneditor-format { + background-position: -72px -120px; +} + +div.jsoneditor-menu > div.jsoneditor-modes { + display: inline-block; + float: left; +} + +div.jsoneditor-menu > div.jsoneditor-modes > button { + background-image: none; + width: auto; + padding-left: 6px; + padding-right: 6px; +} + +div.jsoneditor-menu > button.jsoneditor-separator, +div.jsoneditor-menu > div.jsoneditor-modes > button.jsoneditor-separator { + margin-left: 10px; +} + +div.jsoneditor-menu a { + font-family: arial, sans-serif; + font-size: 10pt; + color: white; + opacity: 0.8; + vertical-align: middle; +} + +div.jsoneditor-menu a:hover { + opacity: 1; +} + +div.jsoneditor-menu a.jsoneditor-poweredBy { + font-size: 8pt; + position: absolute; + right: 0; + top: 0; + padding: 10px; +} +table.jsoneditor-search input, +table.jsoneditor-search div.jsoneditor-results { + font-family: arial, sans-serif; + font-size: 10pt; + color: #1A1A1A; + background: transparent; + /* For Firefox */ +} + +table.jsoneditor-search div.jsoneditor-results { + color: white; + padding-right: 5px; + line-height: 24px; +} + +table.jsoneditor-search { + position: absolute; + right: 4px; + top: 4px; + border-collapse: collapse; + border-spacing: 0; +} + +table.jsoneditor-search div.jsoneditor-frame { + border: 1px solid transparent; + background-color: white; + padding: 0 2px; + margin: 0; +} + +table.jsoneditor-search div.jsoneditor-frame table { + border-collapse: collapse; +} + +table.jsoneditor-search input { + width: 120px; + border: none; + outline: none; + margin: 1px; + line-height: 20px; +} + +table.jsoneditor-search button { + width: 16px; + height: 24px; + padding: 0; + margin: 0; + border: none; + background: url("../../fonts/jsoneditor-icons.svg"); + vertical-align: top; +} + +table.jsoneditor-search button:hover { + background-color: transparent; +} + +table.jsoneditor-search button.jsoneditor-refresh { + width: 18px; + background-position: -99px -73px; +} + +table.jsoneditor-search button.jsoneditor-next { + cursor: pointer; + background-position: -124px -73px; +} + +table.jsoneditor-search button.jsoneditor-next:hover { + background-position: -124px -49px; +} + +table.jsoneditor-search button.jsoneditor-previous { + cursor: pointer; + background-position: -148px -73px; + margin-right: 2px; +} + +table.jsoneditor-search button.jsoneditor-previous:hover { + background-position: -148px -49px; +} diff --git a/zeppelin-web/src/components/restful-editor/restfuleditor.directive.js b/zeppelin-web/src/components/restful-editor/restfuleditor.directive.js index 0a6f7d65b26..ea8b30584d1 100644 --- a/zeppelin-web/src/components/restful-editor/restfuleditor.directive.js +++ b/zeppelin-web/src/components/restful-editor/restfuleditor.directive.js @@ -1,37 +1,41 @@ /* - * Licensed under the Apache License, Version 2.0 (the "License"); + * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, + * distributed under the License is distributed on an 'AS IS' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ 'use strict'; + +// jscs:disable requireCamelCaseOrUpperCaseIdentifiers +/*eslint-disable camelcase*/ +/*eslint-disable no-undef*/ (function() { - var jsonEditor = angular.module("restful-editor", []); - jsonEditor.directive("restfulEditor", function () { + var jsonEditor = angular.module('restful-editor', []); + jsonEditor.directive('restfulEditor', function() { return { restrict: 'A', scope: { model: '=', options: '=' }, - link: function (scope, element, attrs) { - var id = "jsoneditor" + Math.floor(Math.random() * 100000000); - //console.log("ID: "+id); - element.attr("id", id); + link: function(scope, element, attrs) { + var id = 'jsoneditor' + Math.floor(Math.random() * 100000000); + //console.log('ID: '+id); + element.attr('id', id); attrs.$set('disabled', 'disabled'); scope.options = scope.options || {}; - scope.options.change = function () { - setTimeout(function () { - scope.$apply(function () { - if (scope.editor != undefined) { + scope.options.change = function() { + setTimeout(function() { + scope.$apply(function() { + if (scope.editor !== undefined) { scope.model = scope.editor.get(); } }); @@ -43,20 +47,21 @@ scope.model = scope.model || {}; scope.container = document.getElementById(id); scope.editor = new JSONEditor(scope.container, scope.setup, scope.model); - scope.globalTimeout = null; - scope.delay_timeout = function (second_time, func) { - if (scope.globalTimeout != null) clearTimeout(scope.globalTimeout); - scope.globalTimeout = setTimeout(function () { + scope.delay_timeout = function(second_time, func) { + if (scope.globalTimeout !== null) { + clearTimeout(scope.globalTimeout); + } + scope.globalTimeout = setTimeout(function() { func(); }, second_time); - } + }; // Update editor when change model - scope.$watch(function () { + scope.$watch(function() { return scope.model; - }, function () { - scope.delay_timeout(1000, function () { - //console.log("Change on "+id); + }, function() { + scope.delay_timeout(1000, function() { + //console.log('Change on '+id); var json1 = angular.toJson(scope.model); var json2 = angular.toJson(scope.editor.get()); if (!angular.equals(json1, json2)) { @@ -64,11 +69,11 @@ } }); }, true); - scope.$watchCollection(function () { + scope.$watchCollection(function() { return scope.model; - }, function () { - scope.delay_timeout(1000, function () { - ////console.log("Change on "+id); + }, function() { + scope.delay_timeout(1000, function() { + ////console.log('Change on '+id); var json1 = angular.toJson(scope.model); var json2 = angular.toJson(scope.editor.get()); if (!angular.equals(json1, json2)) { @@ -78,9 +83,9 @@ }); // Update editor when change options - scope.$watch(function () { + scope.$watch(function() { return scope.options; - }, function (newValue, oldValue) { + }, function(newValue, oldValue) { scope.setup = angular.extend(scope.setup, scope.options); for (var k in newValue) { if (newValue.hasOwnProperty(k)) { @@ -94,6 +99,12 @@ scope.editor.setTheme(v); } else if (k === 'search') { scope.editor.setOption('search', v); + } else if (k === 'expand') { + if (v === true) { + scope.editor.collapseAll(); + } else { + scope.editor.expandAll(); + } } else { //other settings cannot be changed without re-creating the JsonEditor //scope.editor = new JSONEditor(scope.container, scope.setup,scope.model); //return; @@ -103,6 +114,6 @@ } }, true); } - } + }; }); })(); diff --git a/zeppelin-web/src/fonts/jsoneditor-icons.svg b/zeppelin-web/src/fonts/jsoneditor-icons.svg new file mode 100644 index 00000000000..357eeae5ebd --- /dev/null +++ b/zeppelin-web/src/fonts/jsoneditor-icons.svg @@ -0,0 +1,893 @@ + + + JSON Editor Icons + + + + image/svg+xml + + JSON Editor Icons + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/zeppelin-web/src/index.html b/zeppelin-web/src/index.html index d1412d75751..98c50199517 100644 --- a/zeppelin-web/src/index.html +++ b/zeppelin-web/src/index.html @@ -149,6 +149,7 @@ +