-
Notifications
You must be signed in to change notification settings - Fork 19
/
gitfiles.js
55 lines (49 loc) · 2.02 KB
/
gitfiles.js
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
/*
* View model for OctoPrint-GitFiles
*
* Author: OutsourcedGuru
* License: MIT
*/
$(function() {
function GitfilesViewModel(parameters) {
var self = this;
gitPull = function() {
$.ajax({
url: "/api/plugin/gitfiles",
type: "POST",
contentType: "application/json",
dataType: "json",
headers: {"X-Api-Key": UI_API_KEY},
data: JSON.stringify({"command": "git", "arg1": "pull"}),
complete: function () {
var a = $("#files_wrapper").find("div").find(".refresh-trigger").find("a");
if (a.length) {
a.click();
}
}
});
};
self.onStartupComplete = function() {
var element = $("div.gcode_files")
.find("div.scroll-wrapper > div.entry")
.find("div.internal > span")
.filter(function(){ return $(this).text() == 'gitfiles'; }) /* TODO: Make this able to note a changed subfolder */
.parent()
.siblings("div.btn-group.action-buttons")
.find("div.btn.btn-mini");
if (element.length) {
element.hide();
}
}
self.onStartup = function() {
var element = $("#files_wrapper").find("div").find(".refresh-trigger");
if (element.length) {
element.before("<div class=\"gitfiles-trigger accordian-heading-button btn-group\" " +
"data-bind=\"visible: $root.filesListVisible\"><a href=\"#\" " +
"data-bind=\"click: gitPull\" " +
"title=\"Get latest from github\"><i class=\"fa fa-github fa-2\"></i></a></div>");
}
};
}
OCTOPRINT_VIEWMODELS.push({construct: GitfilesViewModel, dependencies: ["printerStateViewModel"], elements: []});
});