Skip to content

Commit

Permalink
Merge pull request #158 from SaaShup/ui_force_pull
Browse files Browse the repository at this point in the history
✨ add force pull in ui
  • Loading branch information
fanshan authored Nov 18, 2024
2 parents df7964e + 8beb702 commit 05d01a6
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 20 deletions.
62 changes: 56 additions & 6 deletions flows.json
Original file line number Diff line number Diff line change
Expand Up @@ -3766,7 +3766,7 @@
"y": 500,
"wires": [
[
"5c79a22a8f9ad79f"
"0b12e4e0c5591d31"
],
[],
[]
Expand Down Expand Up @@ -3912,6 +3912,13 @@
"pt": "msg",
"to": "'\\\"http://localhost/images/' & msg.input.data.name & ':' & msg.input.data.version & '/json\\\"'",
"tot": "jsonata"
},
{
"t": "set",
"p": "journal",
"pt": "msg",
"to": "{\t \"assigned_object_type\": \"netbox_docker_plugin.image\",\t \"assigned_object_id\": msg.input.data.id,\t \"kind\": \"success\",\t \"comments\": \"pulled image\"\t}",
"tot": "jsonata"
}
],
"action": "",
Expand Down Expand Up @@ -4578,7 +4585,7 @@
"repair": false,
"outputs": 2,
"x": 1630,
"y": 500,
"y": 520,
"wires": [
[
"dce108611cd0c5ba"
Expand All @@ -4600,6 +4607,13 @@
"pt": "msg",
"to": "{\t \"assigned_object_type\": \"netbox_docker_plugin.image\",\t \"assigned_object_id\": msg.input.data.id,\t \"kind\": \"danger\",\t \"comments\": \"not pulled image\"\t}",
"tot": "jsonata"
},
{
"t": "set",
"p": "journal.comments",
"pt": "msg",
"to": "$string($map(\t $split(resultPull, \"\\n\"),\t function($v) {\t $v != \"\" ? $eval($v)\t }\t ))",
"tot": "jsonata"
}
],
"action": "",
Expand Down Expand Up @@ -4630,6 +4644,13 @@
"z": "3ea1a4b04d852f38",
"name": "find image digest in output",
"rules": [
{
"t": "set",
"p": "resultPull",
"pt": "msg",
"to": "payload",
"tot": "msg"
},
{
"t": "set",
"p": "payload",
Expand All @@ -4643,8 +4664,8 @@
"from": "",
"to": "",
"reg": false,
"x": 1410,
"y": 500,
"x": 1570,
"y": 460,
"wires": [
[
"84d8b152e92556ef"
Expand Down Expand Up @@ -5114,8 +5135,8 @@
"from": "",
"to": "",
"reg": false,
"x": 3380,
"y": 580,
"x": 3330,
"y": 620,
"wires": [
[]
]
Expand Down Expand Up @@ -5363,6 +5384,35 @@
]
]
},
{
"id": "0b12e4e0c5591d31",
"type": "switch",
"z": "3ea1a4b04d852f38",
"name": "was netbox webhook?",
"property": "req.url",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "/api/containers",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 1380,
"y": 520,
"wires": [
[
"5c79a22a8f9ad79f"
],
[]
]
},
{
"id": "dcf35b57666a30f9",
"type": "http in",
Expand Down
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "netbox-docker-agent",
"version": "1.4.0",
"version": "1.5.0",
"description": "Saashup agent for netbox manager",
"main": "index.js",
"scripts": {
Expand Down
30 changes: 29 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,10 @@ <h5 class="modal-title" id="modalNotificationTitle"></h5>
new Date(c.Created * 1000).toISOString().substring(0, 19).replace('T', ' ') +
'</div><div class="col-sm-12 col-md-6 p-2"> <b>Size</b>: ' + (c.Size / 1024 / 1024).toFixed(2) +
'MB</div><div class="col-sm-12 col-md-12 p-2"> <b>Id</b>: ' + c.Id + '</div>' +
'<div class="col-sm-12 col-md-12 p-2"> <b>Digest</b>: ' + (c.RepoDigests[0] ? c.RepoDigests[0].split("@")[0] : "none") + '</div>' +
'<div class="col-sm-12 col-md-12 p-2"> <b>Used By</b>: <span class="badge rounded-pill bg-primary">' + (used_by.split(' ').length - 1) + '</span> ' + used_by + '</div>' +
'<div class="col-sm-12 col-md-12 p-2"><button class="btn btn-sm btn-danger m-2 ' + (used_by.length > 0 ? "disabled" : "") + '" onclick="deleteImage(\'' + c.Id +
'<div class="col-sm-12 col-md-12 p-2"><button class="btn btn-sm btn-warning m-2 ' + (c.RepoTags[0] ? "":"disabled") + '" onclick="pullImage(\'' + c.Id +
'\', \'' + (c.RepoTags[0] ? c.RepoTags[0].split(':')[0]:"") + '\', \'' + (c.RepoTags[0] ? c.RepoTags[0].split(':')[1]:"") + '\', \'' + Math.ceil(c.Size / 1024 / 1024) + '\');"><i class="fas fa-arrow-down"></i> Pull</button><button class="btn btn-sm btn-danger m-2 ' + (used_by.length > 0 ? "disabled" : "") + '" onclick="deleteImage(\'' + c.Id +
'\');"><i class="fas fa-trash-alt"></i> Remove</button></div></div>'+
'</div></div></div>'
}
Expand Down Expand Up @@ -636,6 +638,32 @@ <h5 class="modal-title" id="modalNotificationTitle"></h5>
})
}

function pullImage(id, name, version, size) {
$("#modalNotificationTitle").html("Pulling image");
$("#modalNotificationContent").html('Pls wait ! Image is being pulled.... ');
$("#modalNotification").modal("show");
$.ajax({
url: "/api/engine/images",
method: "POST",
data: JSON.stringify({
"data": {
"name": name,
"version": version,
"size": parseInt(size),
"ImageID": id,
"force": true
}
}),
contentType: "application/json; charset=utf-8",
dataType: "json"
}).done(function (result) {
setTimeout(function () {
$("#modalNotification").modal("hide");
$("#nav-images-btn").click();
}, 5000)
})
}

function deleteImage(id) {
$("#modalNotificationTitle").html("Delete image");
$("#modalNotificationContent").html('Pls wait ! Deletion is ongoing.... ');
Expand Down

0 comments on commit 05d01a6

Please sign in to comment.