more choco rework
This commit is contained in:
parent
2a0b605e92
commit
12c7140536
File diff suppressed because one or more lines are too long
|
@ -18,4 +18,4 @@ class Command(BaseCommand):
|
|||
ChocoSoftware.objects.all().delete()
|
||||
|
||||
ChocoSoftware(chocos=chocos).save()
|
||||
self.stdout.write("Chocos saved to db")
|
||||
self.stdout.write(self.style.SUCCESS("Chocos saved to db"))
|
||||
|
|
|
@ -8,11 +8,7 @@ class ChocoSoftware(models.Model):
|
|||
added = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
from .serializers import ChocoSoftwareSerializer
|
||||
|
||||
return (
|
||||
str(len(ChocoSoftwareSerializer(self).data["chocos"])) + f" - {self.added}"
|
||||
)
|
||||
return f"{len(self.chocos)} - {self.added}"
|
||||
|
||||
|
||||
class ChocoLog(models.Model):
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
from rest_framework import serializers
|
||||
|
||||
from .models import ChocoSoftware, InstalledSoftware
|
||||
|
||||
|
||||
class ChocoSoftwareSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = ChocoSoftware
|
||||
fields = "__all__"
|
||||
from .models import InstalledSoftware
|
||||
|
||||
|
||||
class InstalledSoftwareSerializer(serializers.ModelSerializer):
|
||||
|
|
|
@ -11,13 +11,12 @@ from logs.models import PendingAction
|
|||
from tacticalrmm.utils import filter_software, notify_error
|
||||
|
||||
from .models import ChocoSoftware, InstalledSoftware
|
||||
from .serializers import ChocoSoftwareSerializer, InstalledSoftwareSerializer
|
||||
from .serializers import InstalledSoftwareSerializer
|
||||
|
||||
|
||||
@api_view()
|
||||
def chocos(request):
|
||||
chocos = ChocoSoftware.objects.last()
|
||||
return Response(ChocoSoftwareSerializer(chocos).data["chocos"])
|
||||
return Response(ChocoSoftware.objects.last().chocos)
|
||||
|
||||
|
||||
@api_view(["POST"])
|
||||
|
@ -27,18 +26,16 @@ def install(request):
|
|||
return notify_error("Requires agent v1.4.8")
|
||||
|
||||
name = request.data["name"]
|
||||
ver = request.data["version"]
|
||||
|
||||
action = PendingAction.objects.create(
|
||||
agent=agent,
|
||||
action_type="chocoinstall",
|
||||
details={"name": name, "version": ver, "output": None, "installed": False},
|
||||
details={"name": name, "output": None, "installed": False},
|
||||
)
|
||||
|
||||
nats_data = {
|
||||
"func": "installwithchoco",
|
||||
"choco_prog_name": name,
|
||||
"choco_prog_ver": ver,
|
||||
"pending_action_pk": action.pk,
|
||||
}
|
||||
|
||||
|
@ -47,7 +44,9 @@ def install(request):
|
|||
action.delete()
|
||||
return notify_error("Unable to contact the agent")
|
||||
|
||||
return Response(f"{name} will be installed shortly on {agent.hostname}")
|
||||
return Response(
|
||||
f"{name} will be installed shortly on {agent.hostname}. Check the Pending Actions menu to see the status/output"
|
||||
)
|
||||
|
||||
|
||||
@api_view()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<template>
|
||||
<q-card style="width: 50vw; max-width: 80vw">
|
||||
<q-card style="width: 40vw; max-width: 50vw">
|
||||
<q-card-section>
|
||||
<q-table
|
||||
class="remote-bg-tbl-sticky"
|
||||
|
@ -28,18 +28,11 @@
|
|||
<template slot="body" slot-scope="props" :props="props">
|
||||
<q-tr :props="props">
|
||||
<q-td auto-width>
|
||||
<q-btn
|
||||
size="sm"
|
||||
color="grey-5"
|
||||
icon="fas fa-plus"
|
||||
text-color="black"
|
||||
@click="install(props.row.name, props.row.version)"
|
||||
/>
|
||||
<q-btn size="sm" color="grey-5" icon="fas fa-plus" text-color="black" @click="install(props.row.name)" />
|
||||
</q-td>
|
||||
<q-td @click="showDescription(props.row.name)">
|
||||
<span style="cursor: pointer; text-decoration: underline" class="text-primary">{{ props.row.name }}</span>
|
||||
</q-td>
|
||||
<q-td>{{ props.row.version }}</q-td>
|
||||
</q-tr>
|
||||
</template>
|
||||
</q-table>
|
||||
|
@ -48,8 +41,6 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import axios from "axios";
|
||||
import { mapState } from "vuex";
|
||||
import { mapGetters } from "vuex";
|
||||
import mixins from "@/mixins/mixins";
|
||||
export default {
|
||||
|
@ -74,44 +65,39 @@ export default {
|
|||
field: "name",
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: "version",
|
||||
align: "left",
|
||||
label: "Version",
|
||||
field: "version",
|
||||
sortable: false,
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
getChocos() {
|
||||
axios.get("/software/chocos/").then(r => {
|
||||
this.$axios.get("/software/chocos/").then(r => {
|
||||
this.chocos = r.data;
|
||||
});
|
||||
},
|
||||
showDescription(name) {
|
||||
window.open(`https://chocolatey.org/packages/${name}`, "_blank");
|
||||
},
|
||||
install(name, version) {
|
||||
const data = { name: name, version: version, pk: this.agentpk };
|
||||
install(name) {
|
||||
const data = { name: name, pk: this.agentpk };
|
||||
this.$q
|
||||
.dialog({
|
||||
title: "Install Software",
|
||||
message: `Install ${name} on ${this.agentHostname}?`,
|
||||
title: `Install ${name} on ${this.agentHostname}?`,
|
||||
persistent: true,
|
||||
ok: { label: "Install" },
|
||||
cancel: { color: "negative" },
|
||||
cancel: true,
|
||||
})
|
||||
.onOk(() => {
|
||||
axios
|
||||
this.$q.loading.show();
|
||||
this.$axios
|
||||
.post("/software/install/", data)
|
||||
.then(r => {
|
||||
this.$q.loading.hide();
|
||||
this.$emit("close");
|
||||
this.notifySuccess(r.data);
|
||||
this.notifySuccess(r.data, 5000);
|
||||
})
|
||||
.catch(e => {
|
||||
this.notifyError("Something went wrong");
|
||||
this.$q.loading.hide();
|
||||
this.notifyError(e.response.data);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue