forked from laurmurclar/datadog-to-terraform
-
Notifications
You must be signed in to change notification settings - Fork 1
/
popup.js
57 lines (49 loc) · 1.87 KB
/
popup.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
56
57
import { generateTerraformCode } from "./monitor_generator.js";
import {generateDashboardTerraformCode} from "./dashboard_generator.js";
function onClick() {
var resourceName = document.getElementById("resourceName").value;
var datadogJson = document.getElementById("datadogJson").value;
try {
var terraformAlarmCode;
if (document.getElementById('monitorChoice').checked) {
//rate_value = document.getElementById('r1').value;
terraformAlarmCode = generateTerraformCode(
resourceName,
JSON.parse(datadogJson)
);
} else {
terraformAlarmCode = generateDashboardTerraformCode(
resourceName,
JSON.parse(datadogJson)
);
}
addDomElementsForResult(terraformAlarmCode);
copyResultToClipboard();
updateStatusMessage("Copied to clipboard!", false);
} catch (e) {
updateStatusMessage(e, true);
}
}
function addDomElementsForResult(terraformAlarmCode) {
var resultTextArea = document.createElement("textarea");
resultTextArea.id = "result";
resultTextArea.textContent = terraformAlarmCode;
var outputWrapperDiv = document.getElementById("outputWrapper");
outputWrapperDiv.appendChild(resultTextArea);
outputWrapperDiv.classList.add("active");
}
function copyResultToClipboard() {
var copyText = document.getElementById("result");
copyText.select();
document.execCommand("copy");
}
function updateStatusMessage(message, isError) {
var newMessageText = isError ? "❗️" + message : "🎉" + message;
var statusMessageElement = document.getElementById("statusMessage");
statusMessageElement.textContent = newMessageText;
document.getElementById("convertButton").style.marginBottom = "0";
if (isError) {
statusMessageElement.style.color = "red";
}
}
document.getElementById("convertButton").addEventListener("click", onClick);