mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
Refactor components service and factory
This commit is contained in:
parent
f86adb4c94
commit
0055191a88
8 changed files with 492 additions and 455 deletions
|
|
@ -12,21 +12,24 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
(function() {
|
||||
|
||||
angular.module('zeppelinWebApp').service('arrayOrderingSrv', function() {
|
||||
angular.module('zeppelinWebApp').service('arrayOrderingSrv', arrayOrderingSrv);
|
||||
|
||||
var arrayOrderingSrv = this;
|
||||
function arrayOrderingSrv() {
|
||||
var arrayOrderingSrv = this;
|
||||
|
||||
this.notebookListOrdering = function(note) {
|
||||
return arrayOrderingSrv.getNoteName(note);
|
||||
};
|
||||
this.notebookListOrdering = function(note) {
|
||||
return arrayOrderingSrv.getNoteName(note);
|
||||
};
|
||||
|
||||
this.getNoteName = function(note) {
|
||||
if (note.name === undefined || note.name.trim() === '') {
|
||||
return 'Note ' + note.id;
|
||||
} else {
|
||||
return note.name;
|
||||
}
|
||||
};
|
||||
this.getNoteName = function(note) {
|
||||
if (note.name === undefined || note.name.trim() === '') {
|
||||
return 'Note ' + note.id;
|
||||
} else {
|
||||
return note.name;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -12,36 +12,41 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
(function() {
|
||||
|
||||
angular.module('zeppelinWebApp').service('baseUrlSrv', function() {
|
||||
angular.module('zeppelinWebApp').service('baseUrlSrv', baseUrlSrv);
|
||||
|
||||
this.getPort = function() {
|
||||
var port = Number(location.port);
|
||||
if (!port) {
|
||||
port = 80;
|
||||
if (location.protocol === 'https:') {
|
||||
port = 443;
|
||||
function baseUrlSrv() {
|
||||
this.getPort = function() {
|
||||
var port = Number(location.port);
|
||||
if (!port) {
|
||||
port = 80;
|
||||
if (location.protocol === 'https:') {
|
||||
port = 443;
|
||||
}
|
||||
}
|
||||
}
|
||||
//Exception for when running locally via grunt
|
||||
if (port === 3333 || port === 9000) {
|
||||
port = 8080;
|
||||
}
|
||||
return port;
|
||||
};
|
||||
//Exception for when running locally via grunt
|
||||
if (port === 3333 || port === 9000) {
|
||||
port = 8080;
|
||||
}
|
||||
return port;
|
||||
};
|
||||
|
||||
this.getWebsocketUrl = function() {
|
||||
var wsProtocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
return wsProtocol + '//' + location.hostname + ':' + this.getPort() + skipTrailingSlash(location.pathname) + '/ws';
|
||||
};
|
||||
this.getWebsocketUrl = function() {
|
||||
var wsProtocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
return wsProtocol + '//' + location.hostname + ':' + this.getPort() +
|
||||
skipTrailingSlash(location.pathname) + '/ws';
|
||||
};
|
||||
|
||||
this.getRestApiBase = function() {
|
||||
return location.protocol + '//' + location.hostname + ':' + this.getPort() + skipTrailingSlash(location.pathname) +
|
||||
'/api';
|
||||
};
|
||||
this.getRestApiBase = function() {
|
||||
return location.protocol + '//' + location.hostname + ':' +
|
||||
this.getPort() + skipTrailingSlash(location.pathname) +
|
||||
'/api';
|
||||
};
|
||||
|
||||
var skipTrailingSlash = function(path) {
|
||||
return path.replace(/\/$/, '');
|
||||
};
|
||||
var skipTrailingSlash = function(path) {
|
||||
return path.replace(/\/$/, '');
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -12,29 +12,32 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
(function() {
|
||||
|
||||
angular.module('zeppelinWebApp').service('browserDetectService', function() {
|
||||
angular.module('zeppelinWebApp').service('browserDetectService', browserDetectService);
|
||||
|
||||
this.detectIE = function() {
|
||||
var ua = window.navigator.userAgent;
|
||||
var msie = ua.indexOf('MSIE ');
|
||||
if (msie > 0) {
|
||||
// IE 10 or older => return version number
|
||||
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
|
||||
}
|
||||
var trident = ua.indexOf('Trident/');
|
||||
if (trident > 0) {
|
||||
// IE 11 => return version number
|
||||
var rv = ua.indexOf('rv:');
|
||||
return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
|
||||
}
|
||||
var edge = ua.indexOf('Edge/');
|
||||
if (edge > 0) {
|
||||
// IE 12 (aka Edge) => return version number
|
||||
return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
|
||||
}
|
||||
// other browser
|
||||
return false;
|
||||
};
|
||||
function browserDetectService() {
|
||||
this.detectIE = function() {
|
||||
var ua = window.navigator.userAgent;
|
||||
var msie = ua.indexOf('MSIE ');
|
||||
if (msie > 0) {
|
||||
// IE 10 or older => return version number
|
||||
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
|
||||
}
|
||||
var trident = ua.indexOf('Trident/');
|
||||
if (trident > 0) {
|
||||
// IE 11 => return version number
|
||||
var rv = ua.indexOf('rv:');
|
||||
return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
|
||||
}
|
||||
var edge = ua.indexOf('Edge/');
|
||||
if (edge > 0) {
|
||||
// IE 12 (aka Edge) => return version number
|
||||
return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
|
||||
}
|
||||
// other browser
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -12,54 +12,58 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
(function() {
|
||||
|
||||
angular.module('zeppelinWebApp').factory('notebookListDataFactory', function() {
|
||||
angular.module('zeppelinWebApp').factory('notebookListDataFactory', notebookListDataFactory);
|
||||
|
||||
var notes = {
|
||||
root: {children: []},
|
||||
flatList: [],
|
||||
function notebookListDataFactory() {
|
||||
var notes = {
|
||||
root: {children: []},
|
||||
flatList: [],
|
||||
|
||||
setNotes: function(notesList) {
|
||||
// a flat list to boost searching
|
||||
notes.flatList = angular.copy(notesList);
|
||||
setNotes: function(notesList) {
|
||||
// a flat list to boost searching
|
||||
notes.flatList = angular.copy(notesList);
|
||||
|
||||
// construct the folder-based tree
|
||||
notes.root = {children: []};
|
||||
_.reduce(notesList, function(root, note) {
|
||||
var noteName = note.name || note.id;
|
||||
var nodes = noteName.match(/([^\/][^\/]*)/g);
|
||||
// construct the folder-based tree
|
||||
notes.root = {children: []};
|
||||
_.reduce(notesList, function(root, note) {
|
||||
var noteName = note.name || note.id;
|
||||
var nodes = noteName.match(/([^\/][^\/]*)/g);
|
||||
|
||||
// recursively add nodes
|
||||
addNode(root, nodes, note.id);
|
||||
// recursively add nodes
|
||||
addNode(root, nodes, note.id);
|
||||
|
||||
return root;
|
||||
}, notes.root);
|
||||
}
|
||||
};
|
||||
|
||||
var addNode = function(curDir, nodes, noteId) {
|
||||
if (nodes.length === 1) { // the leaf
|
||||
curDir.children.push({
|
||||
name: nodes[0],
|
||||
id: noteId
|
||||
});
|
||||
} else { // a folder node
|
||||
var node = nodes.shift();
|
||||
var dir = _.find(curDir.children,
|
||||
function(c) {return c.name === node && c.children !== undefined;});
|
||||
if (dir !== undefined) { // found an existing dir
|
||||
addNode(dir, nodes, noteId);
|
||||
} else {
|
||||
var newDir = {
|
||||
name: node,
|
||||
hidden: true,
|
||||
children: []
|
||||
};
|
||||
curDir.children.push(newDir);
|
||||
addNode(newDir, nodes, noteId);
|
||||
return root;
|
||||
}, notes.root);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
return notes;
|
||||
});
|
||||
var addNode = function(curDir, nodes, noteId) {
|
||||
if (nodes.length === 1) { // the leaf
|
||||
curDir.children.push({
|
||||
name: nodes[0],
|
||||
id: noteId
|
||||
});
|
||||
} else { // a folder node
|
||||
var node = nodes.shift();
|
||||
var dir = _.find(curDir.children,
|
||||
function(c) {return c.name === node && c.children !== undefined;});
|
||||
if (dir !== undefined) { // found an existing dir
|
||||
addNode(dir, nodes, noteId);
|
||||
} else {
|
||||
var newDir = {
|
||||
name: node,
|
||||
hidden: true,
|
||||
children: []
|
||||
};
|
||||
curDir.children.push(newDir);
|
||||
addNode(newDir, nodes, noteId);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return notes;
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -12,38 +12,44 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
(function() {
|
||||
|
||||
angular.module('zeppelinWebApp').service('saveAsService', function(browserDetectService) {
|
||||
angular.module('zeppelinWebApp').service('saveAsService', saveAsService);
|
||||
|
||||
this.saveAs = function(content, filename, extension) {
|
||||
var BOM = '\uFEFF';
|
||||
if (browserDetectService.detectIE()) {
|
||||
angular.element('body').append('<iframe id="SaveAsId" style="display: none"></iframe>');
|
||||
var frameSaveAs = angular.element('body > iframe#SaveAsId')[0].contentWindow;
|
||||
content = BOM + content;
|
||||
frameSaveAs.document.open('text/json', 'replace');
|
||||
frameSaveAs.document.write(content);
|
||||
frameSaveAs.document.close();
|
||||
frameSaveAs.focus();
|
||||
var t1 = Date.now();
|
||||
frameSaveAs.document.execCommand('SaveAs', false, filename + '.' + extension);
|
||||
var t2 = Date.now();
|
||||
saveAsService.$inject = ['browserDetectService'];
|
||||
|
||||
//This means, this version of IE dosen't support auto download of a file with extension provided in param
|
||||
//falling back to ".txt"
|
||||
if (t1 === t2) {
|
||||
frameSaveAs.document.execCommand('SaveAs', true, filename + '.txt');
|
||||
function saveAsService(browserDetectService) {
|
||||
this.saveAs = function(content, filename, extension) {
|
||||
var BOM = '\uFEFF';
|
||||
if (browserDetectService.detectIE()) {
|
||||
angular.element('body').append('<iframe id="SaveAsId" style="display: none"></iframe>');
|
||||
var frameSaveAs = angular.element('body > iframe#SaveAsId')[0].contentWindow;
|
||||
content = BOM + content;
|
||||
frameSaveAs.document.open('text/json', 'replace');
|
||||
frameSaveAs.document.write(content);
|
||||
frameSaveAs.document.close();
|
||||
frameSaveAs.focus();
|
||||
var t1 = Date.now();
|
||||
frameSaveAs.document.execCommand('SaveAs', false, filename + '.' + extension);
|
||||
var t2 = Date.now();
|
||||
|
||||
//This means, this version of IE dosen't support auto download of a file with extension provided in param
|
||||
//falling back to ".txt"
|
||||
if (t1 === t2) {
|
||||
frameSaveAs.document.execCommand('SaveAs', true, filename + '.txt');
|
||||
}
|
||||
angular.element('body > iframe#SaveAsId').remove();
|
||||
} else {
|
||||
content = 'data:image/svg;charset=utf-8,' + BOM + encodeURIComponent(content);
|
||||
angular.element('body').append('<a id="SaveAsId"></a>');
|
||||
var saveAsElement = angular.element('body > a#SaveAsId');
|
||||
saveAsElement.attr('href', content);
|
||||
saveAsElement.attr('download', filename + '.' + extension);
|
||||
saveAsElement.attr('target', '_blank');
|
||||
saveAsElement[0].click();
|
||||
saveAsElement.remove();
|
||||
}
|
||||
angular.element('body > iframe#SaveAsId').remove();
|
||||
} else {
|
||||
content = 'data:image/svg;charset=utf-8,' + BOM + encodeURIComponent(content);
|
||||
angular.element('body').append('<a id="SaveAsId"></a>');
|
||||
var saveAsElement = angular.element('body > a#SaveAsId');
|
||||
saveAsElement.attr('href', content);
|
||||
saveAsElement.attr('download', filename + '.' + extension);
|
||||
saveAsElement.attr('target', '_blank');
|
||||
saveAsElement[0].click();
|
||||
saveAsElement.remove();
|
||||
}
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -12,21 +12,26 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
(function() {
|
||||
|
||||
angular.module('zeppelinWebApp').service('searchService', function($resource, baseUrlSrv) {
|
||||
angular.module('zeppelinWebApp').service('searchService', searchService);
|
||||
|
||||
this.search = function(term) {
|
||||
this.searchTerm = term.q;
|
||||
console.log('Searching for: %o', term.q);
|
||||
if (!term.q) { //TODO(bzz): empty string check
|
||||
return;
|
||||
}
|
||||
var encQuery = window.encodeURIComponent(term.q);
|
||||
return $resource(baseUrlSrv.getRestApiBase() + '/notebook/search?q=' + encQuery, {}, {
|
||||
query: {method: 'GET'}
|
||||
});
|
||||
};
|
||||
searchService.$inject = ['$resource', 'baseUrlSrv'];
|
||||
|
||||
this.searchTerm = '';
|
||||
function searchService($resource, baseUrlSrv) {
|
||||
this.search = function(term) {
|
||||
this.searchTerm = term.q;
|
||||
console.log('Searching for: %o', term.q);
|
||||
if (!term.q) { //TODO(bzz): empty string check
|
||||
return;
|
||||
}
|
||||
var encQuery = window.encodeURIComponent(term.q);
|
||||
return $resource(baseUrlSrv.getRestApiBase() + '/notebook/search?q=' + encQuery, {}, {
|
||||
query: {method: 'GET'}
|
||||
});
|
||||
};
|
||||
|
||||
});
|
||||
this.searchTerm = '';
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -12,140 +12,146 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
(function() {
|
||||
|
||||
angular.module('zeppelinWebApp').factory('websocketEvents',
|
||||
function($rootScope, $websocket, $location, baseUrlSrv) {
|
||||
var websocketCalls = {};
|
||||
angular.module('zeppelinWebApp').factory('websocketEvents', websocketEvents);
|
||||
|
||||
websocketCalls.ws = $websocket(baseUrlSrv.getWebsocketUrl());
|
||||
websocketCalls.ws.reconnectIfNotNormalClose = true;
|
||||
websocketEvents.$inject = ['$rootScope', '$websocket', '$location', 'baseUrlSrv'];
|
||||
|
||||
websocketCalls.ws.onOpen(function() {
|
||||
console.log('Websocket created');
|
||||
$rootScope.$broadcast('setConnectedStatus', true);
|
||||
setInterval(function() {
|
||||
websocketCalls.sendNewEvent({op: 'PING'});
|
||||
}, 10000);
|
||||
});
|
||||
function websocketEvents($rootScope, $websocket, $location, baseUrlSrv) {
|
||||
var websocketCalls = {};
|
||||
|
||||
websocketCalls.sendNewEvent = function(data) {
|
||||
if ($rootScope.ticket !== undefined) {
|
||||
data.principal = $rootScope.ticket.principal;
|
||||
data.ticket = $rootScope.ticket.ticket;
|
||||
data.roles = $rootScope.ticket.roles;
|
||||
} else {
|
||||
data.principal = '';
|
||||
data.ticket = '';
|
||||
data.roles = '';
|
||||
}
|
||||
console.log('Send >> %o, %o, %o, %o, %o', data.op, data.principal, data.ticket, data.roles, data);
|
||||
websocketCalls.ws.send(JSON.stringify(data));
|
||||
};
|
||||
websocketCalls.ws = $websocket(baseUrlSrv.getWebsocketUrl());
|
||||
websocketCalls.ws.reconnectIfNotNormalClose = true;
|
||||
|
||||
websocketCalls.isConnected = function() {
|
||||
return (websocketCalls.ws.socket.readyState === 1);
|
||||
};
|
||||
websocketCalls.ws.onOpen(function() {
|
||||
console.log('Websocket created');
|
||||
$rootScope.$broadcast('setConnectedStatus', true);
|
||||
setInterval(function() {
|
||||
websocketCalls.sendNewEvent({op: 'PING'});
|
||||
}, 10000);
|
||||
});
|
||||
|
||||
websocketCalls.ws.onMessage(function(event) {
|
||||
var payload;
|
||||
if (event.data) {
|
||||
payload = angular.fromJson(event.data);
|
||||
}
|
||||
console.log('Receive << %o, %o', payload.op, payload);
|
||||
var op = payload.op;
|
||||
var data = payload.data;
|
||||
if (op === 'NOTE') {
|
||||
$rootScope.$broadcast('setNoteContent', data.note);
|
||||
} else if (op === 'NEW_NOTE') {
|
||||
$location.path('/notebook/' + data.note.id);
|
||||
} else if (op === 'NOTES_INFO') {
|
||||
$rootScope.$broadcast('setNoteMenu', data.notes);
|
||||
} else if (op === 'LIST_NOTEBOOK_JOBS') {
|
||||
$rootScope.$broadcast('setNotebookJobs', data.notebookJobs);
|
||||
} else if (op === 'LIST_UPDATE_NOTEBOOK_JOBS') {
|
||||
$rootScope.$broadcast('setUpdateNotebookJobs', data.notebookRunningJobs);
|
||||
} else if (op === 'AUTH_INFO') {
|
||||
BootstrapDialog.show({
|
||||
closable: false,
|
||||
closeByBackdrop: false,
|
||||
closeByKeyboard: false,
|
||||
title: 'Insufficient privileges',
|
||||
message: data.info.toString(),
|
||||
buttons: [{
|
||||
label: 'Login',
|
||||
action: function(dialog) {
|
||||
dialog.close();
|
||||
angular.element('#loginModal').modal({
|
||||
show: 'true'
|
||||
});
|
||||
}
|
||||
}, {
|
||||
label: 'Cancel',
|
||||
action: function(dialog) {
|
||||
dialog.close();
|
||||
$location.path('/');
|
||||
}
|
||||
}]
|
||||
});
|
||||
} else if (op === 'PARAGRAPH') {
|
||||
$rootScope.$broadcast('updateParagraph', data);
|
||||
} else if (op === 'PARAGRAPH_APPEND_OUTPUT') {
|
||||
$rootScope.$broadcast('appendParagraphOutput', data);
|
||||
} else if (op === 'PARAGRAPH_UPDATE_OUTPUT') {
|
||||
$rootScope.$broadcast('updateParagraphOutput', data);
|
||||
} else if (op === 'PROGRESS') {
|
||||
$rootScope.$broadcast('updateProgress', data);
|
||||
} else if (op === 'COMPLETION_LIST') {
|
||||
$rootScope.$broadcast('completionList', data);
|
||||
} else if (op === 'EDITOR_SETTING') {
|
||||
$rootScope.$broadcast('editorSetting', data);
|
||||
} else if (op === 'ANGULAR_OBJECT_UPDATE') {
|
||||
$rootScope.$broadcast('angularObjectUpdate', data);
|
||||
} else if (op === 'ANGULAR_OBJECT_REMOVE') {
|
||||
$rootScope.$broadcast('angularObjectRemove', data);
|
||||
} else if (op === 'APP_APPEND_OUTPUT') {
|
||||
$rootScope.$broadcast('appendAppOutput', data);
|
||||
} else if (op === 'APP_UPDATE_OUTPUT') {
|
||||
$rootScope.$broadcast('updateAppOutput', data);
|
||||
} else if (op === 'APP_LOAD') {
|
||||
$rootScope.$broadcast('appLoad', data);
|
||||
} else if (op === 'APP_STATUS_CHANGE') {
|
||||
$rootScope.$broadcast('appStatusChange', data);
|
||||
} else if (op === 'LIST_REVISION_HISTORY') {
|
||||
$rootScope.$broadcast('listRevisionHistory', data);
|
||||
} else if (op === 'NOTE_REVISION') {
|
||||
$rootScope.$broadcast('noteRevision', data);
|
||||
} else if (op === 'INTERPRETER_BINDINGS') {
|
||||
$rootScope.$broadcast('interpreterBindings', data);
|
||||
} else if (op === 'ERROR_INFO') {
|
||||
BootstrapDialog.show({
|
||||
closable: false,
|
||||
closeByBackdrop: false,
|
||||
closeByKeyboard: false,
|
||||
title: 'Details',
|
||||
message: data.info.toString(),
|
||||
buttons: [{
|
||||
// close all the dialogs when there are error on running all paragraphs
|
||||
label: 'Close',
|
||||
action: function() {
|
||||
BootstrapDialog.closeAll();
|
||||
}
|
||||
}]
|
||||
});
|
||||
} else if (op === 'CONFIGURATIONS_INFO') {
|
||||
$rootScope.$broadcast('configurationsInfo', data);
|
||||
}
|
||||
});
|
||||
websocketCalls.sendNewEvent = function(data) {
|
||||
if ($rootScope.ticket !== undefined) {
|
||||
data.principal = $rootScope.ticket.principal;
|
||||
data.ticket = $rootScope.ticket.ticket;
|
||||
data.roles = $rootScope.ticket.roles;
|
||||
} else {
|
||||
data.principal = '';
|
||||
data.ticket = '';
|
||||
data.roles = '';
|
||||
}
|
||||
console.log('Send >> %o, %o, %o, %o, %o', data.op, data.principal, data.ticket, data.roles, data);
|
||||
websocketCalls.ws.send(JSON.stringify(data));
|
||||
};
|
||||
|
||||
websocketCalls.ws.onError(function(event) {
|
||||
console.log('error message: ', event);
|
||||
$rootScope.$broadcast('setConnectedStatus', false);
|
||||
});
|
||||
websocketCalls.isConnected = function() {
|
||||
return (websocketCalls.ws.socket.readyState === 1);
|
||||
};
|
||||
|
||||
websocketCalls.ws.onClose(function(event) {
|
||||
console.log('close message: ', event);
|
||||
$rootScope.$broadcast('setConnectedStatus', false);
|
||||
});
|
||||
websocketCalls.ws.onMessage(function(event) {
|
||||
var payload;
|
||||
if (event.data) {
|
||||
payload = angular.fromJson(event.data);
|
||||
}
|
||||
console.log('Receive << %o, %o', payload.op, payload);
|
||||
var op = payload.op;
|
||||
var data = payload.data;
|
||||
if (op === 'NOTE') {
|
||||
$rootScope.$broadcast('setNoteContent', data.note);
|
||||
} else if (op === 'NEW_NOTE') {
|
||||
$location.path('/notebook/' + data.note.id);
|
||||
} else if (op === 'NOTES_INFO') {
|
||||
$rootScope.$broadcast('setNoteMenu', data.notes);
|
||||
} else if (op === 'LIST_NOTEBOOK_JOBS') {
|
||||
$rootScope.$broadcast('setNotebookJobs', data.notebookJobs);
|
||||
} else if (op === 'LIST_UPDATE_NOTEBOOK_JOBS') {
|
||||
$rootScope.$broadcast('setUpdateNotebookJobs', data.notebookRunningJobs);
|
||||
} else if (op === 'AUTH_INFO') {
|
||||
BootstrapDialog.show({
|
||||
closable: false,
|
||||
closeByBackdrop: false,
|
||||
closeByKeyboard: false,
|
||||
title: 'Insufficient privileges',
|
||||
message: data.info.toString(),
|
||||
buttons: [{
|
||||
label: 'Login',
|
||||
action: function(dialog) {
|
||||
dialog.close();
|
||||
angular.element('#loginModal').modal({
|
||||
show: 'true'
|
||||
});
|
||||
}
|
||||
}, {
|
||||
label: 'Cancel',
|
||||
action: function(dialog) {
|
||||
dialog.close();
|
||||
$location.path('/');
|
||||
}
|
||||
}]
|
||||
});
|
||||
} else if (op === 'PARAGRAPH') {
|
||||
$rootScope.$broadcast('updateParagraph', data);
|
||||
} else if (op === 'PARAGRAPH_APPEND_OUTPUT') {
|
||||
$rootScope.$broadcast('appendParagraphOutput', data);
|
||||
} else if (op === 'PARAGRAPH_UPDATE_OUTPUT') {
|
||||
$rootScope.$broadcast('updateParagraphOutput', data);
|
||||
} else if (op === 'PROGRESS') {
|
||||
$rootScope.$broadcast('updateProgress', data);
|
||||
} else if (op === 'COMPLETION_LIST') {
|
||||
$rootScope.$broadcast('completionList', data);
|
||||
} else if (op === 'EDITOR_SETTING') {
|
||||
$rootScope.$broadcast('editorSetting', data);
|
||||
} else if (op === 'ANGULAR_OBJECT_UPDATE') {
|
||||
$rootScope.$broadcast('angularObjectUpdate', data);
|
||||
} else if (op === 'ANGULAR_OBJECT_REMOVE') {
|
||||
$rootScope.$broadcast('angularObjectRemove', data);
|
||||
} else if (op === 'APP_APPEND_OUTPUT') {
|
||||
$rootScope.$broadcast('appendAppOutput', data);
|
||||
} else if (op === 'APP_UPDATE_OUTPUT') {
|
||||
$rootScope.$broadcast('updateAppOutput', data);
|
||||
} else if (op === 'APP_LOAD') {
|
||||
$rootScope.$broadcast('appLoad', data);
|
||||
} else if (op === 'APP_STATUS_CHANGE') {
|
||||
$rootScope.$broadcast('appStatusChange', data);
|
||||
} else if (op === 'LIST_REVISION_HISTORY') {
|
||||
$rootScope.$broadcast('listRevisionHistory', data);
|
||||
} else if (op === 'NOTE_REVISION') {
|
||||
$rootScope.$broadcast('noteRevision', data);
|
||||
} else if (op === 'INTERPRETER_BINDINGS') {
|
||||
$rootScope.$broadcast('interpreterBindings', data);
|
||||
} else if (op === 'ERROR_INFO') {
|
||||
BootstrapDialog.show({
|
||||
closable: false,
|
||||
closeByBackdrop: false,
|
||||
closeByKeyboard: false,
|
||||
title: 'Details',
|
||||
message: data.info.toString(),
|
||||
buttons: [{
|
||||
// close all the dialogs when there are error on running all paragraphs
|
||||
label: 'Close',
|
||||
action: function() {
|
||||
BootstrapDialog.closeAll();
|
||||
}
|
||||
}]
|
||||
});
|
||||
} else if (op === 'CONFIGURATIONS_INFO') {
|
||||
$rootScope.$broadcast('configurationsInfo', data);
|
||||
}
|
||||
});
|
||||
|
||||
return websocketCalls;
|
||||
});
|
||||
websocketCalls.ws.onError(function(event) {
|
||||
console.log('error message: ', event);
|
||||
$rootScope.$broadcast('setConnectedStatus', false);
|
||||
});
|
||||
|
||||
websocketCalls.ws.onClose(function(event) {
|
||||
console.log('close message: ', event);
|
||||
$rootScope.$broadcast('setConnectedStatus', false);
|
||||
});
|
||||
|
||||
return websocketCalls;
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -12,215 +12,220 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
(function() {
|
||||
|
||||
angular.module('zeppelinWebApp').service('websocketMsgSrv', function($rootScope, websocketEvents) {
|
||||
angular.module('zeppelinWebApp').service('websocketMsgSrv', websocketMsgSrv);
|
||||
|
||||
return {
|
||||
websocketMsgSrv.$inject = ['$rootScope', 'websocketEvents'];
|
||||
|
||||
getHomeNotebook: function() {
|
||||
websocketEvents.sendNewEvent({op: 'GET_HOME_NOTE'});
|
||||
},
|
||||
function websocketMsgSrv($rootScope, websocketEvents) {
|
||||
return {
|
||||
|
||||
createNotebook: function(noteName) {
|
||||
websocketEvents.sendNewEvent({op: 'NEW_NOTE',data: {name: noteName}});
|
||||
},
|
||||
getHomeNotebook: function() {
|
||||
websocketEvents.sendNewEvent({op: 'GET_HOME_NOTE'});
|
||||
},
|
||||
|
||||
deleteNotebook: function(noteId) {
|
||||
websocketEvents.sendNewEvent({op: 'DEL_NOTE', data: {id: noteId}});
|
||||
},
|
||||
createNotebook: function(noteName) {
|
||||
websocketEvents.sendNewEvent({op: 'NEW_NOTE',data: {name: noteName}});
|
||||
},
|
||||
|
||||
cloneNotebook: function(noteIdToClone, newNoteName) {
|
||||
websocketEvents.sendNewEvent({op: 'CLONE_NOTE', data: {id: noteIdToClone, name: newNoteName}});
|
||||
},
|
||||
deleteNotebook: function(noteId) {
|
||||
websocketEvents.sendNewEvent({op: 'DEL_NOTE', data: {id: noteId}});
|
||||
},
|
||||
|
||||
getNotebookList: function() {
|
||||
websocketEvents.sendNewEvent({op: 'LIST_NOTES'});
|
||||
},
|
||||
cloneNotebook: function(noteIdToClone, newNoteName) {
|
||||
websocketEvents.sendNewEvent({op: 'CLONE_NOTE', data: {id: noteIdToClone, name: newNoteName}});
|
||||
},
|
||||
|
||||
reloadAllNotesFromRepo: function() {
|
||||
websocketEvents.sendNewEvent({op: 'RELOAD_NOTES_FROM_REPO'});
|
||||
},
|
||||
getNotebookList: function() {
|
||||
websocketEvents.sendNewEvent({op: 'LIST_NOTES'});
|
||||
},
|
||||
|
||||
getNotebook: function(noteId) {
|
||||
websocketEvents.sendNewEvent({op: 'GET_NOTE', data: {id: noteId}});
|
||||
},
|
||||
reloadAllNotesFromRepo: function() {
|
||||
websocketEvents.sendNewEvent({op: 'RELOAD_NOTES_FROM_REPO'});
|
||||
},
|
||||
|
||||
updateNotebook: function(noteId, noteName, noteConfig) {
|
||||
websocketEvents.sendNewEvent({op: 'NOTE_UPDATE', data: {id: noteId, name: noteName, config: noteConfig}});
|
||||
},
|
||||
getNotebook: function(noteId) {
|
||||
websocketEvents.sendNewEvent({op: 'GET_NOTE', data: {id: noteId}});
|
||||
},
|
||||
|
||||
moveParagraph: function(paragraphId, newIndex) {
|
||||
websocketEvents.sendNewEvent({op: 'MOVE_PARAGRAPH', data: {id: paragraphId, index: newIndex}});
|
||||
},
|
||||
updateNotebook: function(noteId, noteName, noteConfig) {
|
||||
websocketEvents.sendNewEvent({op: 'NOTE_UPDATE', data: {id: noteId, name: noteName, config: noteConfig}});
|
||||
},
|
||||
|
||||
insertParagraph: function(newIndex) {
|
||||
websocketEvents.sendNewEvent({op: 'INSERT_PARAGRAPH', data: {index: newIndex}});
|
||||
},
|
||||
moveParagraph: function(paragraphId, newIndex) {
|
||||
websocketEvents.sendNewEvent({op: 'MOVE_PARAGRAPH', data: {id: paragraphId, index: newIndex}});
|
||||
},
|
||||
|
||||
updateAngularObject: function(noteId, paragraphId, name, value, interpreterGroupId) {
|
||||
websocketEvents.sendNewEvent({
|
||||
op: 'ANGULAR_OBJECT_UPDATED',
|
||||
data: {
|
||||
noteId: noteId,
|
||||
paragraphId: paragraphId,
|
||||
name: name,
|
||||
value: value,
|
||||
interpreterGroupId: interpreterGroupId
|
||||
}
|
||||
});
|
||||
},
|
||||
insertParagraph: function(newIndex) {
|
||||
websocketEvents.sendNewEvent({op: 'INSERT_PARAGRAPH', data: {index: newIndex}});
|
||||
},
|
||||
|
||||
clientBindAngularObject: function(noteId, name, value, paragraphId) {
|
||||
websocketEvents.sendNewEvent({
|
||||
op: 'ANGULAR_OBJECT_CLIENT_BIND',
|
||||
data: {
|
||||
noteId: noteId,
|
||||
name: name,
|
||||
value: value,
|
||||
paragraphId: paragraphId
|
||||
}
|
||||
});
|
||||
},
|
||||
updateAngularObject: function(noteId, paragraphId, name, value, interpreterGroupId) {
|
||||
websocketEvents.sendNewEvent({
|
||||
op: 'ANGULAR_OBJECT_UPDATED',
|
||||
data: {
|
||||
noteId: noteId,
|
||||
paragraphId: paragraphId,
|
||||
name: name,
|
||||
value: value,
|
||||
interpreterGroupId: interpreterGroupId
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
clientUnbindAngularObject: function(noteId, name, paragraphId) {
|
||||
websocketEvents.sendNewEvent({
|
||||
op: 'ANGULAR_OBJECT_CLIENT_UNBIND',
|
||||
data: {
|
||||
noteId: noteId,
|
||||
name: name,
|
||||
paragraphId: paragraphId
|
||||
}
|
||||
});
|
||||
},
|
||||
clientBindAngularObject: function(noteId, name, value, paragraphId) {
|
||||
websocketEvents.sendNewEvent({
|
||||
op: 'ANGULAR_OBJECT_CLIENT_BIND',
|
||||
data: {
|
||||
noteId: noteId,
|
||||
name: name,
|
||||
value: value,
|
||||
paragraphId: paragraphId
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
cancelParagraphRun: function(paragraphId) {
|
||||
websocketEvents.sendNewEvent({op: 'CANCEL_PARAGRAPH', data: {id: paragraphId}});
|
||||
},
|
||||
clientUnbindAngularObject: function(noteId, name, paragraphId) {
|
||||
websocketEvents.sendNewEvent({
|
||||
op: 'ANGULAR_OBJECT_CLIENT_UNBIND',
|
||||
data: {
|
||||
noteId: noteId,
|
||||
name: name,
|
||||
paragraphId: paragraphId
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
runParagraph: function(paragraphId, paragraphTitle, paragraphData, paragraphConfig, paragraphParams) {
|
||||
websocketEvents.sendNewEvent({
|
||||
op: 'RUN_PARAGRAPH',
|
||||
data: {
|
||||
id: paragraphId,
|
||||
title: paragraphTitle,
|
||||
paragraph: paragraphData,
|
||||
config: paragraphConfig,
|
||||
params: paragraphParams
|
||||
}
|
||||
});
|
||||
},
|
||||
cancelParagraphRun: function(paragraphId) {
|
||||
websocketEvents.sendNewEvent({op: 'CANCEL_PARAGRAPH', data: {id: paragraphId}});
|
||||
},
|
||||
|
||||
removeParagraph: function(paragraphId) {
|
||||
websocketEvents.sendNewEvent({op: 'PARAGRAPH_REMOVE', data: {id: paragraphId}});
|
||||
},
|
||||
runParagraph: function(paragraphId, paragraphTitle, paragraphData, paragraphConfig, paragraphParams) {
|
||||
websocketEvents.sendNewEvent({
|
||||
op: 'RUN_PARAGRAPH',
|
||||
data: {
|
||||
id: paragraphId,
|
||||
title: paragraphTitle,
|
||||
paragraph: paragraphData,
|
||||
config: paragraphConfig,
|
||||
params: paragraphParams
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
clearParagraphOutput: function(paragraphId) {
|
||||
websocketEvents.sendNewEvent({op: 'PARAGRAPH_CLEAR_OUTPUT', data: {id: paragraphId}});
|
||||
},
|
||||
removeParagraph: function(paragraphId) {
|
||||
websocketEvents.sendNewEvent({op: 'PARAGRAPH_REMOVE', data: {id: paragraphId}});
|
||||
},
|
||||
|
||||
completion: function(paragraphId, buf, cursor) {
|
||||
websocketEvents.sendNewEvent({
|
||||
op: 'COMPLETION',
|
||||
data: {
|
||||
id: paragraphId,
|
||||
buf: buf,
|
||||
cursor: cursor
|
||||
}
|
||||
});
|
||||
},
|
||||
clearParagraphOutput: function(paragraphId) {
|
||||
websocketEvents.sendNewEvent({op: 'PARAGRAPH_CLEAR_OUTPUT', data: {id: paragraphId}});
|
||||
},
|
||||
|
||||
commitParagraph: function(paragraphId, paragraphTitle, paragraphData, paragraphConfig, paragraphParams) {
|
||||
websocketEvents.sendNewEvent({
|
||||
op: 'COMMIT_PARAGRAPH',
|
||||
data: {
|
||||
id: paragraphId,
|
||||
title: paragraphTitle,
|
||||
paragraph: paragraphData,
|
||||
config: paragraphConfig,
|
||||
params: paragraphParams
|
||||
}
|
||||
});
|
||||
},
|
||||
completion: function(paragraphId, buf, cursor) {
|
||||
websocketEvents.sendNewEvent({
|
||||
op: 'COMPLETION',
|
||||
data: {
|
||||
id: paragraphId,
|
||||
buf: buf,
|
||||
cursor: cursor
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
importNotebook: function(notebook) {
|
||||
websocketEvents.sendNewEvent({
|
||||
op: 'IMPORT_NOTE',
|
||||
data: {
|
||||
notebook: notebook
|
||||
}
|
||||
});
|
||||
},
|
||||
commitParagraph: function(paragraphId, paragraphTitle, paragraphData, paragraphConfig, paragraphParams) {
|
||||
websocketEvents.sendNewEvent({
|
||||
op: 'COMMIT_PARAGRAPH',
|
||||
data: {
|
||||
id: paragraphId,
|
||||
title: paragraphTitle,
|
||||
paragraph: paragraphData,
|
||||
config: paragraphConfig,
|
||||
params: paragraphParams
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
checkpointNotebook: function(noteId, commitMessage) {
|
||||
websocketEvents.sendNewEvent({
|
||||
op: 'CHECKPOINT_NOTEBOOK',
|
||||
data: {
|
||||
noteId: noteId,
|
||||
commitMessage: commitMessage
|
||||
}
|
||||
});
|
||||
},
|
||||
importNotebook: function(notebook) {
|
||||
websocketEvents.sendNewEvent({
|
||||
op: 'IMPORT_NOTE',
|
||||
data: {
|
||||
notebook: notebook
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
listRevisionHistory: function(noteId) {
|
||||
websocketEvents.sendNewEvent({
|
||||
op: 'LIST_REVISION_HISTORY',
|
||||
data: {
|
||||
noteId: noteId
|
||||
}
|
||||
});
|
||||
},
|
||||
checkpointNotebook: function(noteId, commitMessage) {
|
||||
websocketEvents.sendNewEvent({
|
||||
op: 'CHECKPOINT_NOTEBOOK',
|
||||
data: {
|
||||
noteId: noteId,
|
||||
commitMessage: commitMessage
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
getNoteByRevision: function(noteId, revisionId) {
|
||||
websocketEvents.sendNewEvent({
|
||||
op: 'NOTE_REVISION',
|
||||
data: {
|
||||
noteId: noteId,
|
||||
revisionId: revisionId
|
||||
}
|
||||
});
|
||||
},
|
||||
listRevisionHistory: function(noteId) {
|
||||
websocketEvents.sendNewEvent({
|
||||
op: 'LIST_REVISION_HISTORY',
|
||||
data: {
|
||||
noteId: noteId
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
getEditorSetting: function(paragraphId, replName) {
|
||||
websocketEvents.sendNewEvent({
|
||||
op: 'EDITOR_SETTING',
|
||||
data: {
|
||||
paragraphId: paragraphId,
|
||||
magic: replName
|
||||
}
|
||||
});
|
||||
},
|
||||
getNoteByRevision: function(noteId, revisionId) {
|
||||
websocketEvents.sendNewEvent({
|
||||
op: 'NOTE_REVISION',
|
||||
data: {
|
||||
noteId: noteId,
|
||||
revisionId: revisionId
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
isConnected: function() {
|
||||
return websocketEvents.isConnected();
|
||||
},
|
||||
getEditorSetting: function(paragraphId, replName) {
|
||||
websocketEvents.sendNewEvent({
|
||||
op: 'EDITOR_SETTING',
|
||||
data: {
|
||||
paragraphId: paragraphId,
|
||||
magic: replName
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
getNotebookJobsList: function() {
|
||||
websocketEvents.sendNewEvent({op: 'LIST_NOTEBOOK_JOBS'});
|
||||
},
|
||||
isConnected: function() {
|
||||
return websocketEvents.isConnected();
|
||||
},
|
||||
|
||||
getUpdateNotebookJobsList: function(lastUpdateServerUnixTime) {
|
||||
websocketEvents.sendNewEvent(
|
||||
{op: 'LIST_UPDATE_NOTEBOOK_JOBS', data: {lastUpdateUnixTime: lastUpdateServerUnixTime * 1}}
|
||||
);
|
||||
},
|
||||
getNotebookJobsList: function() {
|
||||
websocketEvents.sendNewEvent({op: 'LIST_NOTEBOOK_JOBS'});
|
||||
},
|
||||
|
||||
unsubscribeJobManager: function() {
|
||||
websocketEvents.sendNewEvent({op: 'UNSUBSCRIBE_UPDATE_NOTEBOOK_JOBS'});
|
||||
},
|
||||
getUpdateNotebookJobsList: function(lastUpdateServerUnixTime) {
|
||||
websocketEvents.sendNewEvent(
|
||||
{op: 'LIST_UPDATE_NOTEBOOK_JOBS', data: {lastUpdateUnixTime: lastUpdateServerUnixTime * 1}}
|
||||
);
|
||||
},
|
||||
|
||||
getInterpreterBindings: function(noteID) {
|
||||
websocketEvents.sendNewEvent({op: 'GET_INTERPRETER_BINDINGS', data: {noteID: noteID}});
|
||||
},
|
||||
unsubscribeJobManager: function() {
|
||||
websocketEvents.sendNewEvent({op: 'UNSUBSCRIBE_UPDATE_NOTEBOOK_JOBS'});
|
||||
},
|
||||
|
||||
saveInterpreterBindings: function(noteID, selectedSettingIds) {
|
||||
websocketEvents.sendNewEvent({op: 'SAVE_INTERPRETER_BINDINGS',
|
||||
data: {noteID: noteID, selectedSettingIds: selectedSettingIds}});
|
||||
},
|
||||
getInterpreterBindings: function(noteID) {
|
||||
websocketEvents.sendNewEvent({op: 'GET_INTERPRETER_BINDINGS', data: {noteID: noteID}});
|
||||
},
|
||||
|
||||
listConfigurations: function() {
|
||||
websocketEvents.sendNewEvent({op: 'LIST_CONFIGURATIONS'});
|
||||
}
|
||||
saveInterpreterBindings: function(noteID, selectedSettingIds) {
|
||||
websocketEvents.sendNewEvent({op: 'SAVE_INTERPRETER_BINDINGS',
|
||||
data: {noteID: noteID, selectedSettingIds: selectedSettingIds}});
|
||||
},
|
||||
|
||||
};
|
||||
listConfigurations: function() {
|
||||
websocketEvents.sendNewEvent({op: 'LIST_CONFIGURATIONS'});
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
|
|||
Loading…
Reference in a new issue