-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathmain.js
More file actions
108 lines (87 loc) · 4.44 KB
/
main.js
File metadata and controls
108 lines (87 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
define(['base/js/namespace','base/js/dialog','jquery'],function(IPython, dialog, $, mc){
// we will define an action here that should happen when we ask to clear and restart the kernel.
var git_commit_push = {
help: 'Commit current notebook and push to GitHub',
icon : 'fa-github',
help_index : '',
handler : function (env) {
var on_success = undefined;
var on_error = undefined;
var p = $('<p/>').text("Please enter your commit message. Only this notebook will be committed.")
var input = $('<textarea rows="4" cols="72"></textarea>')
var div = $('<div/>')
var checkbox = '<input type="checkbox" id="commit_only_source" name="feature" value="scales" checked /><label>commit only source code</label>'
div.append(checkbox)
div.append(p)
.append(input)
// get the canvas for user feedback
var container = $('#notebook-container');
function on_ok(){
var re = /^\/notebooks(.*?)$/;
var filepath = window.location.pathname.match(re)[1];
var payload = {
'filename': filepath,
'msg': input.val(),
'commit_only_source': $("#commit_only_source").prop('checked')
};
var settings = {
url : '/git/commit',
processData : false,
type : "PUT",
dataType: "json",
data: JSON.stringify(payload),
contentType: 'application/json',
success: function(data) {
// display feedback to user
var container = $('#notebook-container');
var feedback = '<div class="commit-feedback alert alert-success alert-dismissible" role="alert"> \
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button> \
'+data.statusText+' \
\
</div>';
// display feedback
$('.commit-feedback').remove();
container.prepend(feedback);
},
error: function(data) {
// display feedback to user
var feedback = '<div class="commit-feedback alert alert-danger alert-dismissible" role="alert"> \
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button> \
<strong>Warning!</strong> Something went wrong. \
<div>'+data.statusText+'</div> \
</div>';
// display feedback
$('.commit-feedback').remove();
container.prepend(feedback);
}
};
// display preloader during commit and push
var preloader = '<img class="commit-feedback" src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.5.8/ajax-loader.gif">';
container.prepend(preloader);
// commit and push
$.ajax(settings);
}
dialog.modal({
body: div ,
title: 'Commit and Push Notebook',
buttons: {'Commit and Push':
{ class:'btn-primary btn-large',
click:on_ok
},
'Cancel':{}
},
notebook:env.notebook,
keyboard_manager: env.notebook.keyboard_manager,
})
}
}
function _on_load(){
// log to console
console.info('Loaded Jupyter extension: Git Commit and Push')
// register new action
var action_name = IPython.keyboard_manager.actions.register(git_commit_push, 'commit-push', 'jupyter-git')
// add button for new action
IPython.toolbar.add_buttons_group([action_name])
}
return {load_ipython_extension: _on_load };
})