Initial commit. Implemented OAuth, Linodes, volumes, and images

This commit is contained in:
2020-01-10 00:24:59 -05:00
commit 9915ef3413
121 changed files with 14776 additions and 0 deletions

31
volumes/add/add.css Normal file
View File

@ -0,0 +1,31 @@
/*
* This file is part of Linode Manager Classic.
*
* Linode Manager Classic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Linode Manager Classic is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Linode Manager Classic. If not, see <https://www.gnu.org/licenses/>.
*/
@import url('/global.css');
#add {
padding: 0px 15px 15px;
}
tbody tr td:first-of-type {
font-weight: bold;
text-align: right;
}
tbody tr:last-of-type {
border: none;
}

198
volumes/add/add.js Normal file
View File

@ -0,0 +1,198 @@
/*
* This file is part of Linode Manager Classic.
*
* Linode Manager Classic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Linode Manager Classic is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Linode Manager Classic. If not, see <https://www.gnu.org/licenses/>.
*/
import { settings, elements, apiGet, apiPost, parseParams, regionNames, setupHeader } from "/global.js";
(function()
{
// Element names specific to this page
elements.addButton = "add-button";
elements.attachment = "attachment";
elements.label = "label";
elements.location = "location";
elements.size = "size";
// Data recieved from API calls
var data = {};
data.linodes = [];
data.regions = [];
// Static references to UI elements
var ui = {};
ui.addButton = {};
ui.attachment = {};
ui.label = {};
ui.location = {};
ui.size = {};
// Callback for linodes API call
var displayLinodes = function(response)
{
// Add linodes to array
data.linodes = data.linodes.concat(response.data);
// Request the next page if there are more pages
var filter = {
"+or": []
};
for (var i = 0; i < data.regions.length; i++)
filter["+or"].push({"region": data.regions[i].id});
if (response.page != response.pages) {
apiGet("/linode/instances?page=" + (response.page + 1), displayLinodes, filter);
return;
}
// Add linodes to selector
for (var i = 0; i < data.linodes.length; i++) {
var linode = document.createElement("option");
linode.value = data.linodes[i].id;
linode.innerHTML = data.linodes[i].label;
ui.attachment.appendChild(linode);
if (data.params.lid && parseInt(data.params.lid) == data.linodes[i].id) {
ui.attachment.value = data.linodes[i].id;
ui.location.value = data.linodes[i].region;
}
}
ui.addButton.disabled = false;
};
// Callback for regions API call
var displayRegions = function(response)
{
// Add regions that support block storage to array
for (var i = 0; i < response.data.length; i++) {
if (response.data[i].capabilities.includes("Block Storage"))
data.regions.push(response.data[i]);
}
// Request the next page if there are more pages
if (response.page != response.pages) {
apiGet("/regions?page=" + (response.page + 1), displayRegions, null);
return;
}
// Add regions to selector
for (var i = 0; i < data.regions.length; i++) {
var loc = document.createElement("option");
loc.value = data.regions[i].id;
if (regionNames[data.regions[i].id])
loc.innerHTML = regionNames[data.regions[i].id];
else
loc.innerHTML = data.regions[i].id;
ui.location.appendChild(loc);
}
// Request linodes in all the supported regions
var filter = {
"+or": []
};
for (var i = 0; i < data.regions.length; i++)
filter["+or"].push({"region": data.regions[i].id});
apiGet("/linode/instances", displayLinodes, filter);
};
// Click handler for add button
var handleAdd = function(event)
{
if (event.currentTarget.disabled)
return;
if (ui.location.value == "0") {
alert("You must select a location.");
return;
}
var req = {
"label": ui.label.value,
"size": parseInt(ui.size.value),
"region": ui.location.value
};
if (ui.attachment.value != "0")
req.linode_id = parseInt(ui.attachment.value);
apiPost("/volumes", req, function(response)
{
location.href = "/volumes/settings?vid=" + response.id;
});
};
// Linode select handler
var handleLinode = function(event)
{
// Set the location to the selected linode's region
var linode = null;
var lid = parseInt(ui.attachment.value);
for (var i = 0; i < data.linodes.length; i++) {
if (data.linodes[i].id == lid) {
linode = data.linodes[i];
break;
}
}
if (!linode)
return;
ui.location.value = linode.region;
};
// Location select handler
var handleLocation = function(event)
{
// Clear the linode selector
for (var i = ui.attachment.children.length - 1; i >= 1; i--)
ui.attachment.children[i].remove();
// Insert linodes in the same region
for (var i = 0; i < data.linodes.length; i++) {
if (data.linodes[i].region != ui.location.value)
continue;
var linode = document.createElement("option");
linode.value = data.linodes[i].id;
linode.innerHTML = data.linodes[i].label;
ui.attachment.appendChild(linode);
}
};
// Initial setup
var setup = function()
{
// Parse URL parameters
data.params = parseParams();
setupHeader();
// Get element references
ui.addButton = document.getElementById(elements.addButton);
ui.attachment = document.getElementById(elements.attachment);
ui.label = document.getElementById(elements.label);
ui.location = document.getElementById(elements.location);
ui.size = document.getElementById(elements.size);
// Attach event handlers
ui.addButton.addEventListener("click", handleAdd);
ui.attachment.addEventListener("input", handleLinode);
ui.location.addEventListener("input", handleLocation);
// Get data from API
apiGet("/regions", displayRegions, null);
};
// Attach onload handler
window.addEventListener("load", setup);
})();

76
volumes/add/index.shtml Normal file
View File

@ -0,0 +1,76 @@
<!--
This file is part of Linode Manager Classic.
Linode Manager Classic is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Linode Manager Classic is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Linode Manager Classic. If not, see <https://www.gnu.org/licenses/>.
-->
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>LMC - Add a Volume</title>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<link rel="stylesheet" type="text/css" href="add.css" />
<script src="add.js" type="module"></script>
</head>
<body>
<!--#include virtual="/include/header.html"-->
<div id="main-content" class="wrapper">
<div id="top-links"><a href="/volumes">Volumes</a> » <span class="top-links-title">Add a Volume</span></div>
<div id="add">
<table class="lmc-table">
<thead>
<tr>
<td colspan="3">Add a Volume</td>
</tr>
</thead>
<tbody>
<tr class="lmc-tr3">
<td>Label</td>
<td><input id="label" type="text" /></td>
<td></td>
</tr>
<tr class="lmc-tr3">
<td>Size</td>
<td><input id="size" type="number" min="10" value="20" /></td>
<td class="info">The size of the new volume in GiB</td>
</tr>
<tr class="lmc-tr3">
<td>Location</td>
<td>
<select id="location">
<option selected disabled value="0">Choose A Location</option>
</select>
</td>
<td class="info">The datacenter where the new volume should be created</td>
</tr>
<tr class="lmc-tr3">
<td>Attach To</td>
<td>
<select id="attachment">
<option value="0">No Attachment</option>
</select>
</td>
<td class="info">If you want to attach the new volume to a Linode, select it here</td>
</tr>
<tr class="lmc-tr3">
<td></td>
<td><button disabled id="add-button" type="button">Add this Volume!</button></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>