Rename a note from the main page

This commit is contained in:
Jun 2016-11-07 11:47:31 +09:00
parent cb175032a2
commit c019b9ea8a
7 changed files with 77 additions and 12 deletions

View file

@ -48,13 +48,7 @@ import org.apache.zeppelin.interpreter.InterpreterSetting;
import org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry;
import org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcessListener;
import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion;
import org.apache.zeppelin.notebook.JobListenerFactory;
import org.apache.zeppelin.notebook.Note;
import org.apache.zeppelin.notebook.Notebook;
import org.apache.zeppelin.notebook.NotebookAuthorization;
import org.apache.zeppelin.notebook.NotebookEventListener;
import org.apache.zeppelin.notebook.Paragraph;
import org.apache.zeppelin.notebook.ParagraphJobListener;
import org.apache.zeppelin.notebook.*;
import org.apache.zeppelin.notebook.repo.NotebookRepo.Revision;
import org.apache.zeppelin.notebook.socket.Message;
import org.apache.zeppelin.notebook.socket.Message.OP;
@ -234,6 +228,9 @@ public class NotebookServer extends WebSocketServlet implements
case NOTE_UPDATE:
updateNote(conn, userAndRoles, notebook, messagereceived);
break;
case NOTE_RENAME:
renameNote(conn, userAndRoles, notebook, messagereceived);
break;
case COMPLETION:
completion(conn, userAndRoles, notebook, messagereceived);
break;
@ -701,6 +698,34 @@ public class NotebookServer extends WebSocketServlet implements
}
}
private void renameNote(NotebookSocket conn, HashSet<String> userAndRoles,
Notebook notebook, Message fromMessage)
throws SchedulerException, IOException {
String noteId = (String) fromMessage.get("id");
String name = (String) fromMessage.get("name");
if (noteId == null) {
return;
}
NotebookAuthorization notebookAuthorization = notebook.getNotebookAuthorization();
if (!notebookAuthorization.isOwner(noteId, userAndRoles)) {
permissionError(conn, "renameNote", fromMessage.principal,
userAndRoles, notebookAuthorization.getOwners(noteId));
return;
}
Note note = notebook.getNote(noteId);
if (note != null) {
note.setName(name);
AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
note.persist(subject);
broadcastNote(note);
broadcastNoteList(subject, userAndRoles);
}
}
private boolean isCronUpdated(Map<String, Object> configA,
Map<String, Object> configB) {
boolean cronUpdated = false;

View file

@ -88,6 +88,10 @@
}
});
$scope.renameNote = function(node) {
noteActionSrv.renameNote(node.id, node.path);
};
$scope.removeNote = function(noteId) {
noteActionSrv.removeNote(noteId, false);
};

View file

@ -14,20 +14,26 @@ limitations under the License.
<script type="text/ng-template" id="notebook_folder_renderer.html">
<div ng-if="node.children == null"
ng-mouseenter="showButton=true"
ng-mouseleave="showButton=false">
ng-mouseenter="showNoteButton=true"
ng-mouseleave="showNoteButton=false">
<a style="text-decoration: none;" href="#/notebook/{{node.id}}">
<i style="font-size: 10px;" class="icon-doc"/> {{noteName(node)}}
</a>
<a style="text-decoration: none;">
<i style="font-size: 13px; margin-left: 10px; cursor: pointer; text-decoration: none;"
class="fa fa-eraser" ng-show="showButton" ng-click="clearAllParagraphOutput(node.id)"
class="fa fa-pencil" ng-show="showNoteButton" ng-click="renameNote(node)"
tooltip-placement="bottom" tooltip="Rename note">
</i>
</a>
<a style="text-decoration: none;">
<i style="font-size: 13px; margin-left: 2px; cursor: pointer; text-decoration: none;"
class="fa fa-eraser" ng-show="showNoteButton" ng-click="clearAllParagraphOutput(node.id)"
tooltip-placement="bottom" tooltip="Clear output">
</i>
</a>
<a style="text-decoration: none;">
<i style="font-size: 13px; margin-left: 2px; cursor: pointer; text-decoration: none;"
class="fa fa-trash-o" ng-show="showButton" ng-click="removeNote(node.id)"
class="fa fa-trash-o" ng-show="showNoteButton" ng-click="removeNote(node.id)"
tooltip-placement="bottom" tooltip="Remove note">
</i>
</a>

View file

@ -47,5 +47,28 @@
}
});
};
this.renameNote = function(noteId, notePath) {
showRenameDialog('Rename note', notePath, function(newName) {
websocketMsgSrv.renameNote(noteId, newName);
});
};
function showRenameDialog(title, currentName, callback) {
BootstrapDialog.show({
closable: true,
title: title,
message: '<input type="text" class="form-control" value="' + currentName + '">',
buttons: [{
label: 'Rename',
hotkey: 13, // the button is clicked when press enter
action: function(dialogRef) {
var newName = dialogRef.getModalBody().find('input').val().trim();
callback(newName);
dialogRef.close();
}
}]
});
}
}
})();

View file

@ -43,7 +43,8 @@
if (nodes.length === 1) { // the leaf
curDir.children.push({
name: nodes[0],
id: noteId
id: noteId,
path: curDir.id ? curDir.id + '/' + nodes[0] : nodes[0]
});
} else { // a folder node
var node = nodes.shift();

View file

@ -59,6 +59,10 @@
websocketEvents.sendNewEvent({op: 'NOTE_UPDATE', data: {id: noteId, name: noteName, config: noteConfig}});
},
renameNote: function(noteId, noteName) {
websocketEvents.sendNewEvent({op: 'NOTE_RENAME', data: {id: noteId, name: noteName}});
},
moveParagraph: function(paragraphId, newIndex) {
websocketEvents.sendNewEvent({op: 'MOVE_PARAGRAPH', data: {id: paragraphId, index: newIndex}});
},

View file

@ -53,6 +53,8 @@ public class Message {
// @param object notebook
NOTE_UPDATE,
NOTE_RENAME,
RUN_PARAGRAPH, // [c-s] run paragraph
// @param id paragraph id
// @param paragraph paragraph content.ie. script