Skip to content

Commit 6fd4d06

Browse files
committed
A little formatting of JS files
1 parent 0ee8363 commit 6fd4d06

File tree

2 files changed

+42
-42
lines changed

2 files changed

+42
-42
lines changed

apps/dashboard/app/javascript/dag.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ export class DAG {
1515
}
1616

1717
addEdge(fromId, toId) {
18-
if(!this.#launcher_list.has(fromId)) {
18+
if (!this.#launcher_list.has(fromId)) {
1919
this.#launcher_list.add(fromId);
2020
}
2121

22-
if(!this.#launcher_list.has(toId)) {
22+
if (!this.#launcher_list.has(toId)) {
2323
this.#launcher_list.add(toId);
2424
}
2525

@@ -31,20 +31,18 @@ export class DAG {
3131
this.#has_cycle = false;
3232
this.#visited = new Set();
3333
this.#stack = new Set();
34-
this.#launcher_list.forEach( l => this.#detectCycle(l) );
34+
this.#launcher_list.forEach(l => this.#detectCycle(l));
3535

36-
// Remove the added edges form the adjacency list
37-
if(this.#has_cycle === true) {
36+
// Remove the added edge from the adjacency list if cycle detected
37+
if (this.#has_cycle === true) {
3838
this.#adjacency_list[fromId].pop();
3939
}
4040
}
4141

4242
removeEdge(fromId, toId) {
43-
if (!this.#adjacency_list[fromId]) {
44-
return;
45-
}
43+
if (!this.#adjacency_list[fromId]) return;
4644

47-
if(this.#adjacency_list[fromId].includes(toId)) {
45+
if (this.#adjacency_list[fromId].includes(toId)) {
4846
this.#adjacency_list[fromId] = this.#adjacency_list[fromId].filter(x => x !== toId);
4947
}
5048
}
@@ -64,20 +62,17 @@ export class DAG {
6462

6563
// Basic dfs on graph to find a cycle
6664
#detectCycle(id) {
67-
if(this.#stack.has(id)) {
65+
if (this.#stack.has(id)) {
6866
this.#has_cycle = true;
6967
return;
7068
}
71-
if(this.#visited.has(id)) {
72-
return;
73-
}
69+
if (this.#visited.has(id)) return;
7470

7571
this.#stack.add(id);
7672
this.#visited.add(id);
7773
for (const l of this.#adjacency_list[id] || []) {
7874
this.#detectCycle(l);
7975
}
80-
8176
this.#stack.delete(id);
8277
}
8378
}

apps/dashboard/app/javascript/workflows.js

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { DAG } from './dag.js';
99
const delete_edge_button = document.getElementById('btn-delete-edge');
1010
const selected_launcher = document.getElementById('select_launcher');
1111
const base_launcher_url = document.getElementById('base-launcher-url').value;
12-
const dag = new DAG;
12+
const dag = new DAG();
1313
const styles = getComputedStyle(document.documentElement);
1414
const grid_cols = parseInt(styles.getPropertyValue('--grid_cols'));
1515
const grid_rows = parseInt(styles.getPropertyValue('--grid_rows'));
@@ -23,19 +23,21 @@ import { DAG } from './dag.js';
2323
let connect_mode = false;
2424
let connect_queue = null;
2525

26-
function stageRect() { return stage.getBoundingClientRect(); }
26+
function stageRect() {
27+
return stage.getBoundingClientRect();
28+
}
2729

2830
function gridSpawn() {
2931
const cols = 12;
3032
const rows = 6;
3133
for (let r = 1; r <= rows; r++) {
3234
for (let c = 1; c <= cols; c++) {
33-
if (!document.querySelector(`.launcher-item[data-row="${r}"][data-col="${c}"]`)) {
35+
if (!document.querySelector(`.launcher-item[data-row='${r}'][data-col='${c}']`)) {
3436
return { row: r, col: c };
3537
}
3638
}
3739
}
38-
alert("No empty grid cells available!");
40+
alert('No empty grid cells available!');
3941
return null;
4042
}
4143

@@ -47,7 +49,7 @@ import { DAG } from './dag.js';
4749

4850
function cellToXY(row, col) {
4951
return {
50-
x: (col - 1) * cell_w + 10, // +padding
52+
x: (col - 1) * cell_w + 10, //padding
5153
y: (row - 1) * cell_h + 10
5254
};
5355
}
@@ -71,16 +73,19 @@ import { DAG } from './dag.js';
7173
function updateBoxPosition(id, x, y) {
7274
const b = boxes.get(id);
7375
if (!b) return;
74-
b.x = x; b.y = y;
76+
b.x = x;
77+
b.y = y;
7578
b.el.style.left = x + 'px';
76-
b.el.style.top = y + 'px';
77-
edges.forEach(edge => { if (edge.fromId===id || edge.toId===id) updateEdgeLine(edge); });
79+
b.el.style.top = y + 'px';
80+
edges.forEach(edge => {
81+
if (edge.fromId === id || edge.toId === id) updateEdgeLine(edge);
82+
});
7883
}
7984

8085
function intersectRect(cx, cy, w, h, dx, dy) {
8186
const absDx = Math.abs(dx);
8287
const absDy = Math.abs(dy);
83-
let scale = 0.5 / Math.max(absDx/w, absDy/h);
88+
let scale = 0.5 / Math.max(absDx / w, absDy / h);
8489
scale = Math.min(scale, 1);
8590
return { x: cx + dx * scale, y: cy + dy * scale };
8691
}
@@ -93,13 +98,13 @@ import { DAG } from './dag.js';
9398
const x1 = from.x, y1 = from.y, w1 = from.w, h1 = from.h;
9499
const x2 = to.x, y2 = to.y, w2 = to.w, h2 = to.h;
95100

96-
const cx1 = x1 + w1/2, cy1 = y1 + h1/2;
97-
const cx2 = x2 + w2/2, cy2 = y2 + h2/2;
101+
const cx1 = x1 + w1 / 2, cy1 = y1 + h1 / 2;
102+
const cx2 = x2 + w2 / 2, cy2 = y2 + h2 / 2;
98103
const dx = cx2 - cx1;
99104
const dy = cy2 - cy1;
100105

101106
const start = intersectRect(cx1, cy1, w1, h1, dx, dy);
102-
const end = intersectRect(cx2, cy2, w2, h2, -dx, -dy);
107+
const end = intersectRect(cx2, cy2, w2, h2, -dx, -dy);
103108
edge.el.setAttribute('x1', start.x);
104109
edge.el.setAttribute('y1', start.y);
105110
edge.el.setAttribute('x2', end.x);
@@ -109,22 +114,22 @@ import { DAG } from './dag.js';
109114
function createEdge(fromId, toId) {
110115
if (fromId === toId) return;
111116
if (!boxes.has(fromId) || !boxes.has(toId)) return;
112-
117+
113118
const existingEdge = edges.find(e => e.fromId === fromId && e.toId === toId);
114-
if (existingEdge) { return; }
115-
119+
if (existingEdge) return;
120+
116121
const reverseEdge = edges.find(e => e.fromId === toId && e.toId === fromId);
117-
if (reverseEdge) {
122+
if (reverseEdge) {
118123
alert('Bidirectional edges are not allowed.');
119124
return;
120125
}
121126

122-
dag.addEdge(fromId, toId)
123-
if (dag.hasCycle()) {
127+
dag.addEdge(fromId, toId);
128+
if (dag.hasCycle()) {
124129
alert('Adding this edge will create a cyclic dependency among the launchers.');
125-
return;
130+
return;
126131
}
127-
132+
128133
const line = document.createElementNS('http://www.w3.org/2000/svg', 'line');
129134
line.classList.add('edge');
130135
edges_svg.appendChild(line);
@@ -148,15 +153,15 @@ import { DAG } from './dag.js';
148153

149154
$.get(url, function(html) {
150155
const $launcher = $(`
151-
<div class="launcher-item" id="launcher_${id}" data-row="${row}" data-col="${col}">
152-
<div class="launcher-title">${title}</div>
156+
<div class='launcher-item' id='launcher_${id}' data-row='${row}' data-col='${col}'>
157+
<div class='launcher-title'>${title}</div>
153158
${html}
154159
</div>
155160
`);
156161

157162
$('#stage').append($launcher);
158163
const pos = cellToXY(row, col);
159-
$launcher.css({ left: pos.x + "px", top: pos.y + "px" });
164+
$launcher.css({ left: pos.x + 'px', top: pos.y + 'px' });
160165
const model = { el: $launcher[0], row, col, w: $launcher.outerWidth(), h: $launcher.outerHeight() };
161166
boxes.set(id, model);
162167
updateBoxPosition(id, pos.x, pos.y);
@@ -188,7 +193,7 @@ import { DAG } from './dag.js';
188193
model.col = snapped.col;
189194
const finalPos = cellToXY(snapped.row, snapped.col);
190195
updateBoxPosition(id, finalPos.x, finalPos.y);
191-
$launcher.attr("data-row", snapped.row).attr("data-col", snapped.col);
196+
$launcher.attr('data-row', snapped.row).attr('data-col', snapped.col);
192197
}
193198
});
194199
});
@@ -215,11 +220,11 @@ import { DAG } from './dag.js';
215220
if (!selected_launcher_id) return;
216221
dag.removeLauncher(selected_launcher_id);
217222
const id = selected_launcher_id;
218-
for (let i = edges.length-1; i>=0; i--) {
223+
for (let i = edges.length - 1; i >= 0; i--) {
219224
const e = edges[i];
220-
if (e.fromId===id || e.toId===id) {
225+
if (e.fromId === id || e.toId === id) {
221226
e.el.remove();
222-
edges.splice(i,1);
227+
edges.splice(i, 1);
223228
}
224229
}
225230
boxes.get(id)?.el.remove();
@@ -239,7 +244,7 @@ import { DAG } from './dag.js';
239244
const launcher_id = selected_launcher.value;
240245
if (!launcher_id) return alert('Please select a launcher');
241246
const launcher_exists = document.getElementById(`launcher_${launcher_id}`);
242-
if(launcher_exists) return alert('Launcher already exists, please select a different launcher');
247+
if (launcher_exists) return alert('Launcher already exists, please select a different launcher');
243248

244249
const title = selected_launcher.options[selected_launcher.selectedIndex].text;
245250
const spawn = gridSpawn();

0 commit comments

Comments
 (0)