MCPcopy Create free account
hub / github.com/AutoCodeStack/ios-device-farm / getDevices

Function getDevices

public/static/js/index.js:8–66  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6});
7
8function getDevices() {
9 const devicesListUri = "http://localhost:9000/api/device/list";
10
11 $.ajax({
12 url: devicesListUri,
13 type: "GET",
14 success: function (result) {
15 const tbodyDevices = $("#tbody-devices");
16 tbodyDevices.empty(); // Clear existing device rows
17 devices = result.devices;
18 result.devices.forEach((device) => {
19 const { name, udid, version, status } = device;
20 const statusNumber = Number(status);
21
22 let statusText, btnClass, disabled;
23
24 switch (statusNumber) {
25 case 0:
26 statusText = "Use";
27 btnClass = "btn-success"; // Button color for "Use" status
28 disabled = "enabled";
29 break;
30 case 1:
31 statusText = "Busy";
32 btnClass = "btn-danger"; // Button color for "Busy" status
33 disabled = "disabled";
34 break;
35 default:
36 statusText = "Offline";
37 btnClass = "btn-secondary"; // Button color for "Offline" status
38 disabled = "disabled";
39 break;
40 }
41
42 const tr = `
43 <tr>
44 <td>${name}</td>
45 <td class="udid">${udid}</td>
46 <td>${version}</td>
47 <td>
48 <button ${disabled} type="button" class="btn ${btnClass}" aria-disabled="${disabled}" onclick="redirectToControl(this)">
49 ${statusText}
50 </button>
51 </td>
52 </tr>`;
53
54 tbodyDevices.append(tr);
55 });
56 },
57 error: function (error) {
58 console.error("Error fetching devices:", error);
59 if (error.status === 401) {
60 window.location.assign("/login");
61 } else {
62 alert("Failed to fetch devices. Please try again later.");
63 }
64 },
65 });

Callers 1

index.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected