server categories
This commit is contained in:
parent
5b2da20947
commit
8c595601a6
@ -51,7 +51,7 @@ class Subscription_ListView(generics.ListCreateAPIView):
|
||||
filter_backends = [filters.SearchFilter, rest_filters.DjangoFilterBackend, filters.OrderingFilter]
|
||||
filterset_fields = ["uuid", "name", "rss_url", "server", "targets", "creation_datetime", "extra_notes", "active"]
|
||||
search_fields = ["name", "extra_notes"]
|
||||
ordering_fields = ["creation_datetime"]
|
||||
ordering_fields = ["creation_datetime", "server"]
|
||||
|
||||
def post(self, request):
|
||||
serializer = self.get_serializer(data=request.data)
|
||||
|
@ -35,6 +35,24 @@ function getSubscription(uuid) {
|
||||
});
|
||||
}
|
||||
|
||||
function getServer(serverId) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
$.ajax({
|
||||
url: `/api/serverlink/?server_id=${serverId}`,
|
||||
type: "GET",
|
||||
beforeSend: function(xhr) {
|
||||
xhr.setRequestHeader("X-CSRFToken", CSRF_MiddlewareToken);
|
||||
},
|
||||
success: function(response) {
|
||||
resolve(response.results[0]);
|
||||
},
|
||||
error: function(response) {
|
||||
reject(response.results[0]);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function newSubscription(formData) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
$.ajax({
|
||||
|
@ -198,6 +198,28 @@
|
||||
|
||||
<!-- Specific Page JS goes HERE -->
|
||||
{% block javascripts %}
|
||||
<script id="subCategoryTemplate" type="text/template">
|
||||
<div class="col-12">
|
||||
<hr>
|
||||
<div class="peers mB-20">
|
||||
<div class="peer">
|
||||
<img class="cat-icon rounded-3" width="50" height="50">
|
||||
</div>
|
||||
<div class="peer px-2">
|
||||
<div class="layers align-items-start">
|
||||
<h5 class="layer cat-name mb-1"></h4>
|
||||
<h6 class="layer cat-id"></h6>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container-fluid">
|
||||
<div class="row sub-container">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script id="subItemTemplate" type="text/template">
|
||||
<div class="col-md-6 col-lg-4 col-xxl-3">
|
||||
<div class="sub-item layers bd bg-body h-100 rounded-3" data-uuid="">
|
||||
@ -253,6 +275,11 @@
|
||||
<i class="bi bi-pencil"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="peer ms-3">
|
||||
<button type="button" class="sub-copy btn bg-body-tertiary waves-effect bd rounded-3 border-0">
|
||||
<i class="bi bi-copy"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="peer ms-3">
|
||||
<button type="button" class="sub-delete btn bg-body-tertiary waves-effect bd rounded-3 border-0">
|
||||
<i class="bi bi-trash3"></i>
|
||||
@ -265,6 +292,20 @@
|
||||
</script>
|
||||
<script src="{% static 'js/api.js' %}"></script>
|
||||
<script type="text/javascript">
|
||||
function createSubCategory(serverId) {
|
||||
var template = $($("#subCategoryTemplate").html());
|
||||
|
||||
template.find(".cat-id").text(serverId);
|
||||
|
||||
var server = getServer(serverId).then(resp => {
|
||||
template.find(".cat-icon").attr("src", resp.icon_url);
|
||||
template.find(".cat-name").text(resp.name);
|
||||
});
|
||||
|
||||
|
||||
return template
|
||||
}
|
||||
|
||||
function createSubscriptionItem(data) {
|
||||
var template = $($("#subItemTemplate").html());
|
||||
|
||||
@ -441,14 +482,33 @@
|
||||
|
||||
function loadSubscriptions() {
|
||||
$("#subscriptionContainer").empty();
|
||||
getSubscriptions().then(resp => {
|
||||
getSubscriptions(ordering="server").then(resp => {
|
||||
updateSubscriptionCount(resp.results.length, true);
|
||||
for (i = 0; i < resp.results.length; i++) {
|
||||
var sub = resp.results[i];
|
||||
console.log(JSON.stringify(sub));
|
||||
var subElem = createSubscriptionItem(sub);
|
||||
$("#subscriptionContainer").append(subElem);
|
||||
}
|
||||
|
||||
var categorisedSubs = {};
|
||||
|
||||
$.each(resp.results, function(index, sub) {
|
||||
categorisedSubs[sub.server] = categorisedSubs[sub.server] || [];
|
||||
categorisedSubs[sub.server].push(sub);
|
||||
});
|
||||
|
||||
console.log(JSON.stringify(categorisedSubs, null, 4))
|
||||
|
||||
$.each(categorisedSubs, function(server, subs) {
|
||||
var categoryElem = createSubCategory(server);
|
||||
$("#subscriptionContainer").append(categoryElem);
|
||||
|
||||
$.each(subs, function(index, sub) {
|
||||
var subElem = createSubscriptionItem(sub);
|
||||
categoryElem.find(".sub-container").append(subElem);
|
||||
});
|
||||
})
|
||||
|
||||
// for (i = 0; i < resp.results.length; i++) {
|
||||
// var sub = resp.results[i];
|
||||
// console.log(JSON.stringify(sub));
|
||||
// var subElem = createSubscriptionItem(sub);
|
||||
// }
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user