mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
Reload notebooks from repository with reload button click event
This commit is contained in:
parent
f78d3096e0
commit
6a803041c9
7 changed files with 42 additions and 12 deletions
|
|
@ -131,7 +131,7 @@ public class NotebookRestApi {
|
|||
@GET
|
||||
@Path("/")
|
||||
public Response getNotebookList() throws IOException {
|
||||
List<Map<String, String>> notesInfo = notebookServer.generateNotebooksInfo();
|
||||
List<Map<String, String>> notesInfo = notebookServer.generateNotebooksInfo(false);
|
||||
return new JsonResponse<>(Status.OK, "", notesInfo ).build();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -92,6 +92,7 @@ public class Message {
|
|||
// @param completions list of string
|
||||
|
||||
LIST_NOTES, // [c-s] ask list of note
|
||||
RELOAD_NOTES_FROM_REPO, // [c-s] reload notes from repo
|
||||
|
||||
NOTES_INFO, // [s-c] list of note infos
|
||||
// @param notes serialized List<NoteInfo> object
|
||||
|
|
|
|||
|
|
@ -101,6 +101,9 @@ public class NotebookServer extends WebSocketServlet implements
|
|||
case LIST_NOTES:
|
||||
broadcastNoteList();
|
||||
break;
|
||||
case RELOAD_NOTES_FROM_REPO:
|
||||
broadcastReloadedNoteList();
|
||||
break;
|
||||
case GET_HOME_NOTE:
|
||||
sendHomeNote(conn, notebook);
|
||||
break;
|
||||
|
|
@ -291,7 +294,7 @@ public class NotebookServer extends WebSocketServlet implements
|
|||
}
|
||||
}
|
||||
|
||||
public List<Map<String, String>> generateNotebooksInfo (){
|
||||
public List<Map<String, String>> generateNotebooksInfo(boolean needsReload) {
|
||||
Notebook notebook = notebook();
|
||||
|
||||
ZeppelinConfiguration conf = notebook.getConf();
|
||||
|
|
@ -299,6 +302,14 @@ public class NotebookServer extends WebSocketServlet implements
|
|||
boolean hideHomeScreenNotebookFromList = conf
|
||||
.getBoolean(ConfVars.ZEPPELIN_NOTEBOOK_HOMESCREEN_HIDE);
|
||||
|
||||
if (needsReload) {
|
||||
try {
|
||||
notebook.reloadAllNotes();
|
||||
} catch (IOException e) {
|
||||
LOG.error("Fail to reload notes from repository");
|
||||
}
|
||||
}
|
||||
|
||||
List<Note> notes = notebook.getAllNotes();
|
||||
List<Map<String, String>> notesInfo = new LinkedList<>();
|
||||
for (Note note : notes) {
|
||||
|
|
@ -321,8 +332,12 @@ public class NotebookServer extends WebSocketServlet implements
|
|||
}
|
||||
|
||||
public void broadcastNoteList() {
|
||||
List<Map<String, String>> notesInfo = generateNotebooksInfo(false);
|
||||
broadcastAll(new Message(OP.NOTES_INFO).put("notes", notesInfo));
|
||||
}
|
||||
|
||||
List<Map<String, String>> notesInfo = generateNotebooksInfo();
|
||||
public void broadcastReloadedNoteList() {
|
||||
List<Map<String, String>> notesInfo = generateNotebooksInfo(true);
|
||||
broadcastAll(new Message(OP.NOTES_INFO).put("notes", notesInfo));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ angular.module('zeppelinWebApp').controller('HomeCtrl', function($scope, noteboo
|
|||
|
||||
vm.notebookHome = false;
|
||||
vm.staticHome = false;
|
||||
|
||||
$scope.isReloading = false;
|
||||
|
||||
var initHome = function() {
|
||||
websocketMsgSrv.getHomeNotebook();
|
||||
|
|
@ -46,4 +48,13 @@ angular.module('zeppelinWebApp').controller('HomeCtrl', function($scope, noteboo
|
|||
vm.notebookHome = false;
|
||||
}
|
||||
});
|
||||
|
||||
$scope.$on('setNoteMenu', function(event, notes) {
|
||||
$scope.isReloadingNotes = false;
|
||||
});
|
||||
|
||||
$scope.reloadNotebookList = function() {
|
||||
websocketMsgSrv.reloadAllNotesFromRepo();
|
||||
$scope.isReloadingNotes = true;
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -26,7 +26,12 @@ limitations under the License.
|
|||
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<h4>Notebook</h4>
|
||||
<h4>Notebook
|
||||
<i ng-class="isReloadingNotes ? 'fa fa-refresh fa-spin' : 'fa fa-refresh'"
|
||||
ng-style="!isReloadingNotes && {'cursor': 'pointer'}" style="font-size: 13px;"
|
||||
ng-click="reloadNotebookList();">
|
||||
</i>
|
||||
</h4>
|
||||
|
||||
<div>
|
||||
<h5><a href="" data-toggle="modal" data-target="#noteImportModal" style="text-decoration: none;">
|
||||
|
|
|
|||
|
|
@ -32,10 +32,15 @@ angular.module('zeppelinWebApp').service('websocketMsgSrv', function($rootScope,
|
|||
cloneNotebook: function(noteIdToClone, newNoteName ) {
|
||||
websocketEvents.sendNewEvent({op: 'CLONE_NOTE', data: {id: noteIdToClone, name: newNoteName}});
|
||||
},
|
||||
|
||||
getNotebookList: function() {
|
||||
websocketEvents.sendNewEvent({op: 'LIST_NOTES'});
|
||||
},
|
||||
|
||||
reloadAllNotesFromRepo: function() {
|
||||
websocketEvents.sendNewEvent({op: 'RELOAD_NOTES_FROM_REPO'});
|
||||
},
|
||||
|
||||
getNotebook: function(noteId) {
|
||||
websocketEvents.sendNewEvent({op: 'GET_NOTE', data: {id: noteId}});
|
||||
},
|
||||
|
|
|
|||
|
|
@ -330,7 +330,7 @@ public class Notebook {
|
|||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
private void reloadAllNotes() throws IOException {
|
||||
public void reloadAllNotes() throws IOException {
|
||||
synchronized (notes) {
|
||||
notes.clear();
|
||||
}
|
||||
|
|
@ -366,13 +366,6 @@ public class Notebook {
|
|||
}
|
||||
|
||||
public List<Note> getAllNotes() {
|
||||
if (conf.getBoolean(ConfVars.ZEPPELIN_NOTEBOOK_RELOAD_FROM_STORAGE)) {
|
||||
try {
|
||||
reloadAllNotes();
|
||||
} catch (IOException e) {
|
||||
logger.error("Cannot reload notes from storage", e);
|
||||
}
|
||||
}
|
||||
synchronized (notes) {
|
||||
List<Note> noteList = new ArrayList<Note>(notes.values());
|
||||
Collections.sort(noteList, new Comparator<Note>() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue