-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmethods.js
More file actions
156 lines (143 loc) · 6.08 KB
/
Copy pathmethods.js
File metadata and controls
156 lines (143 loc) · 6.08 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import $ from 'jquery';
import common from './common';
import api from './api';
import scripts from './scripts';
/*
This function returns the latest version of a package.
*/
function check_new_version(updates, packagename, pkgversion) {
for (var i = 0; i < updates.length; i++) {
var element = updates[i];
if (element.name === packagename) {
return element.version;
}
}
return pkgversion;
}
/*
This function lists down all the updates and requires a user confirmation.
*/
function update_packages(project) {
$('#updatebtn').unbind();
$('#updatebtn').click(function () {
if ($('#updatebtn').hasClass('fa-wrench')) {
var selectedPackages = common.get_selected_packages();
var html = $('<p> The following packages are about to be updated: </p> </br>');
$('#updatebtn').toggleClass('fa-wrench fa-spinner').addClass('fa-spin');
api.check_update(project, function (resp) {
$('#updatebtn').toggleClass('fa-wrench fa-spinner').removeClass('fa-spin');
var updates = resp.updates;
var packages = [];
if (selectedPackages.length > 0) {
html.append($('<ul/>'));
for (var i = 0; i < selectedPackages.length; i++) {
var element = selectedPackages[i];
element = element.split('=');
var pkg = element[0];
var ver = element[1];
var nver = check_new_version(updates, pkg, ver);
if (nver != ver) {
packages.push(pkg);
html.append("<li>" + pkg + " " + ver + " -> " + nver + "</li>");
}
}
}
else {
var list = $('.installed-values');
html.append($('<ul/>'));
for (var i = 0; i < list.length; i++) {
var element = list[i];
var pkg = $(element).find('.value-name')[0].innerText;
var ver = $(element).find('.value-version')[0].innerText;
var nver = check_new_version(updates, pkg, ver);
if (nver != ver) {
packages.push(pkg);
html.append("<li>" + pkg + " " + ver + " -> " + nver + "</li>");
}
}
}
if (packages.length === 0) {
html = $("<p> There are no updates available </p>");
common.display_msg("Update Packages", html);
}
else
common.confirm("Update Packages", html, "Confirm", function () {
$('#loadingtext').text("Updating Packages");
$('#loadingview').show();
api.update_packages(packages, project, function () {
$('#loadingview').hide();
scripts.package_view(project);
}, function () {
$('#loadingview').hide();
common.display_msg("Server Error", "The selected packages could not be updated. Please try again.");
});
});
},
function () {
common.display_msg("Server Error", "Error in checking for new updates. Please try again.");
});
}
});
}
/*
This function lists down all the packages selected for removal and requires a user confirmation.
*/
function delete_packages(project) {
$('#deletebtn').unbind();
$('#deletebtn').click(function () {
var selectedPackages = common.get_selected_packages();
var html = $("<p> The following packages are about to be deleted: </p> </br>");
html.append($('<ul/>'));
var packages = [];
for (var i = 0; i < selectedPackages.length; i++) {
var element = selectedPackages[i];
element = element.split('=')[0];
packages.push(element);
html.append("<li>" + element + "</li>");
}
common.confirm("Delete Packages", html, "Confirm", function () {
$('#loadingtext').text("Removing Packages");
$('#loadingview').show();
api.delete_packages(packages, project, function () {
$('#loadingview').hide();
$('#deletebtn').css("display", "none");
scripts.package_view(project);
}, function () {
$('#loadingview').hide();
common.display_msg("Server Error", "The selected packages could not be removed. Please try again.");
});
});
});
}
/*
This function lists down all the packages selected for installation and requires a user confirmation.
*/
function install_packages(project) {
$('#installbtn').unbind();
$('#installbtn').click(function () {
var toInstall = common.get_to_install();
var html = $("<p> The following packages are about to be added: </p> </br>");
html.append($('<ul/>'));
for (var i = 0; i < toInstall.length; i++) {
var element = toInstall[i];
element = element.split('=')[0];
html.append("<li>" + element + "</li>");
}
common.confirm("Install Packages", html, "Confirm", function () {
$('#loadingtext').text("Adding Packages");
$('#loadingview').show();
api.install_packages(toInstall, project, function () {
$('#loadingview').hide();
scripts.package_view(project);
}, function () {
$('#loadingview').hide();
common.display_msg("Server Error", "The selected packages could not be installed. Please try again.");
});
});
});
}
export default {
update_packages: update_packages,
delete_packages: delete_packages,
install_packages: install_packages
}