Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.apache.zeppelin.interpreter.InterpreterSetting;
import org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcessListener;
import org.apache.zeppelin.notebook.*;
import org.apache.zeppelin.notebook.repo.NotebookRepo;
import org.apache.zeppelin.notebook.repo.NotebookRepo.Revision;
import org.apache.zeppelin.notebook.socket.Message;
import org.apache.zeppelin.notebook.socket.Message.OP;
Expand Down Expand Up @@ -221,6 +222,9 @@ public void onMessage(NotebookSocket conn, String msg) {
case CHECKPOINT_NOTEBOOK:
checkpointNotebook(conn, notebook, messagereceived);
break;
case LIST_REVISION_HISTORY:
listRevisionHistory(conn, notebook, messagereceived);
break;
case NOTE_REVISION:
getNoteRevision(conn, notebook, messagereceived);
break;
Expand Down Expand Up @@ -1130,7 +1134,22 @@ private void checkpointNotebook(NotebookSocket conn, Notebook notebook,
String noteId = (String) fromMessage.get("noteId");
String commitMessage = (String) fromMessage.get("commitMessage");
AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
notebook.checkpointNote(noteId, commitMessage, subject);
Revision revision = notebook.checkpointNote(noteId, commitMessage, subject);
if (revision != null) {
List<NotebookRepo.Revision> revisions = notebook.listRevisionHistory(noteId, subject);
conn.send(serializeMessage(new Message(OP.LIST_REVISION_HISTORY)
.put("revisionList", revisions)));
}
}

private void listRevisionHistory(NotebookSocket conn, Notebook notebook,
Message fromMessage) throws IOException {
String noteId = (String) fromMessage.get("noteId");
AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
List<NotebookRepo.Revision> revisions = notebook.listRevisionHistory(noteId, subject);

conn.send(serializeMessage(new Message(OP.LIST_REVISION_HISTORY)
.put("revisionList", revisions)));
}

private void getNoteRevision(NotebookSocket conn, Notebook notebook, Message fromMessage)
Expand Down
83 changes: 56 additions & 27 deletions zeppelin-web/src/app/notebook/notebook-actionBar.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,34 +64,63 @@ <h3>
tooltip-placement="bottom" tooltip="Export the notebook">
<i class="fa fa-download"></i>
</button>
<button type="button"
class="btn btn-default btn-xs dropdown-toggle"
ng-hide="viewOnly"
data-toggle="dropdown"
tooltip-placement="bottom" tooltip="Version control">
<i class="fa fa-file-code-o"></i>
</button>
<ul class="dropdown-menu" role="menu" style="width:250px">
<li>
<div class="commit-container">
<div>
<input type="text"
dropdown-input
placeholder="commit message"
id="note.checkpoint.message"
style="width: 145px;"
ng-model="note.checkpoint.message"/>
<button type="button"
class="btn btn-default btn-xs"
ng-hide="viewOnly"
ng-click="checkpointNotebook(note.checkpoint.message)"
style="margin-left: 4px;"
tooltip-placement="bottom" tooltip="Commit the notebook">Commit
</button>
</span>

<span class="labelBtn btn-group" role="group">
<div class="btn-group" role="group">
<button type="button"
class="btn btn-default btn-xs dropdown-toggle"
id="versionControlDropdown"
ng-hide="viewOnly"
data-toggle="dropdown"
tooltip-placement="bottom" tooltip="Version control">
<i class="fa fa-file-code-o"></i>
</button>
<ul class="dropdown-menu" style="width:250px"
aria-labelledby="versionControlDropdown">
<li>
<div class="commit-container">
<div>
<input type="text"
dropdown-input
placeholder="commit message"
id="note.checkpoint.message"
style="width: 145px;"
ng-model="note.checkpoint.message"/>
<button type="button"
class="btn btn-default btn-xs"
ng-hide="viewOnly"
ng-click="checkpointNotebook(note.checkpoint.message)"
style="margin-left: 4px;"
tooltip-placement="bottom" tooltip="Commit the notebook">Commit
</button>
</div>
</div>
</div>
</li>
</ul>
</li>
</ul>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-default btn-xs revisionName">
Head
</button>
<button type="button" ng-if="noteRevisions.length > 0"
class="btn btn-default dropdown-toggle caretSeparator"
data-toggle="dropdown" id="revisionsDropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu pull-right" aria-labelledby="revisionsDropdown">
<li ng-repeat="revision in noteRevisions | orderBy:'time':true" class="revision">
<a style="cursor:pointer">
<span style="display: block;">
<strong>{{revision.message}}</strong>
</span>
<span class="revisionDate">
<em>{{moment.unix(revision.time).format('MMMM Do YYYY, h:mm a')}}</em>
</span>
</a>
</li>
</ul>
</div>
</span>

<!-- put the delete action by itself for your protection -->
Expand Down
15 changes: 15 additions & 0 deletions zeppelin-web/src/app/notebook/notebook.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ angular.module('zeppelinWebApp').controller('NotebookCtrl', function($scope, $ro
$rootScope, $http, websocketMsgSrv,
baseUrlSrv, $timeout, SaveAsService) {
$scope.note = null;
$scope.moment = moment;
$scope.showEditor = false;
$scope.editorToggled = false;
$scope.tableToggled = false;
Expand Down Expand Up @@ -54,6 +55,14 @@ angular.module('zeppelinWebApp').controller('NotebookCtrl', function($scope, $ro
var previousSelectedListWriters = [];
var searchText = [];
$scope.role = '';
$scope.noteRevisions = [];

$scope.$on('setConnectedStatus', function(event, param) {
if (connectedOnce && param) {
initNotebook();
}
connectedOnce = true;
});

$scope.getCronOptionNameFromValue = function(value) {
if (!value) {
Expand All @@ -71,6 +80,7 @@ angular.module('zeppelinWebApp').controller('NotebookCtrl', function($scope, $ro
/** Init the new controller */
var initNotebook = function() {
websocketMsgSrv.getNotebook($routeParams.noteId);
websocketMsgSrv.listRevisionHistory($routeParams.noteId);

var currentRoute = $route.current;
if (currentRoute) {
Expand Down Expand Up @@ -175,6 +185,11 @@ angular.module('zeppelinWebApp').controller('NotebookCtrl', function($scope, $ro
document.getElementById('note.checkpoint.message').value = '';
};

$scope.$on('listRevisionHistory', function(event, data) {
console.log('We got the revisions %o', data);
$scope.noteRevisions = data.revisionList;
});

// receive certain revision of note
$scope.$on('noteRevision', function(event, data) {
console.log('received note revision %o', data);
Expand Down
42 changes: 42 additions & 0 deletions zeppelin-web/src/app/notebook/notebook.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,48 @@
padding-top: 36px;
}

.revision {
max-width: 250px;
margin-bottom: 0 !important;
}

.revision a {
padding: 2px 10px !important;
}

.revision a span {
width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

.revisionName {
cursor: default;
padding: 1px 10px !important;
max-width: 150px;
}

.revisionDate {
font-size: 8px;
color: DarkGrey;
display: block;
}

.revisionName:hover,
.revisionName:focus,
.revisionName:active {
background: transparent;
border-color: #ccc;
}

.caretSeparator {
height: 22px;
line-height: 9px;
width: 16px;
padding-left: 3px !important;
}

.paragraph-col {
margin: 0;
padding: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ angular.module('zeppelinWebApp').factory('websocketEvents',
$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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ angular.module('zeppelinWebApp').service('websocketMsgSrv', function($rootScope,
});
},

listRevisionHistory: function(noteId) {
websocketEvents.sendNewEvent({
op: 'LIST_REVISION_HISTORY',
data: {
noteId: noteId
}
});
},

getNoteRevision: function(noteId, revisionId) {
websocketEvents.sendNewEvent({
op: 'NOTE_REVISION',
Expand Down
3 changes: 2 additions & 1 deletion zeppelin-web/test/spec/controllers/notebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ describe('Controller: NotebookCtrl', function() {
var scope;

var websocketMsgSrvMock = {
getNotebook: function() {}
getNotebook: function() {},
listRevisionHistory: function() {}
};

var baseUrlSrvMock = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,14 @@ public void removeNote(String id, AuthenticationInfo subject) {
}
}

public void checkpointNote(String noteId, String checkpointMessage, AuthenticationInfo subject)
throws IOException {
notebookRepo.checkpoint(noteId, checkpointMessage, subject);
public Revision checkpointNote(String noteId, String checkpointMessage,
AuthenticationInfo subject) throws IOException {
return notebookRepo.checkpoint(noteId, checkpointMessage, subject);
}

public List<NotebookRepo.Revision> listRevisionHistory(String noteId,
AuthenticationInfo subject) {
return notebookRepo.revisionHistory(noteId, subject);
}

public Note getNoteRevision(String noteId, Revision revision, AuthenticationInfo subject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -366,7 +367,12 @@ public Note get(String noteId, Revision rev, AuthenticationInfo subject) {

@Override
public List<Revision> revisionHistory(String noteId, AuthenticationInfo subject) {
// Auto-generated method stub
return null;
List<Revision> revisions = Collections.emptyList();
try {
revisions = getRepo(0).revisionHistory(noteId, subject);
} catch (IOException e) {
LOG.error("Failed to list revision history", e);
}
return revisions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ public static enum OP {
CHECKPOINT_NOTEBOOK, // [c-s] checkpoint notebook to storage repository
// @param noteId
// @param checkpointName

LIST_REVISION_HISTORY, // [c-s] list revision history of the notebook
// @param noteId
NOTE_REVISION, // [c-s] get certain revision of note
// @param noteId
// @param revisionId
Expand Down
Loading