Skip to content

Commit

Permalink
Display list of records.
Browse files Browse the repository at this point in the history
  • Loading branch information
kiarn committed Apr 23, 2023
1 parent f9852ac commit 2d1413b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
11 changes: 10 additions & 1 deletion plugins/dns_api/resources/js/controllers/index.controller.es
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
angular.module('ajenti.dns_api').controller('DnsAPIIndexController', function($scope, $http, pageTitle, gettext, notify) {
pageTitle.set(gettext('DNS API'));

$http.get('/api/dns_api');
$http.get('/api/dns_api/domains').then((resp) => {
$scope.domains = resp.data;
$scope.active_domain = resp.data[0]; // Could not exist
$scope.get_records();
});

$scope.get_records = () => {
$http.get(`/api/dns_api/domain/${$scope.active_domain}/records`).then((rsp) => {
$scope.records = rsp.data;
});
};
});

29 changes: 27 additions & 2 deletions plugins/dns_api/resources/partial/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
<br/>

<h1>DNS</h1>
<div>
<div root-access>
<h1>DNS</h1>

<div>
<span translate>Select domain: </span>
<select ng:options="domain for domain in domains" ng:model="active_domain" ng:change="get_records()"></select>
</div>

<table class="table">
<tr>
<th translate>Name</th>
<th translate>TTL</th>
<th translate>Type</th>
<th translate>Values</th>
<th translate></th>
</tr>
<tr ng:repeat="record in records">
<td>{{record.name}}</td>
<td>{{record.ttl}}</td>
<td>{{record.type}}</td>
<td>
<span ng:repeat="value in record.values">{{value}}</span>
</td>
<td></td>
</tr>

</table>

</div>
15 changes: 12 additions & 3 deletions plugins/dns_api/views.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
from jadi import component
from dataclasses import asdict

from aj.api.http import get, HttpPlugin
from aj.auth import authorize
from aj.api.endpoint import endpoint, EndpointError
from aj.plugins.dns_api.manager import DomainManager


@component(HttpPlugin)
class Handler(HttpPlugin):
def __init__(self, context):
self.context = context
self.mgr = DomainManager(self.context)


@get(r'/api/dns_api')
@get(r'/api/dns_api/domains')
@endpoint(api=True)
def handle_api_example_dns_api(self, http_context):
def handle_api_dns_list_domains(self, http_context):
self.mgr.load()
print(self.mgr.domains)
return list(self.mgr.domains.keys())

@get(r'/api/dns_api/domain/(?P<fqdn>[\w\.]+)/records')
@endpoint(api=True)
def handle_api_dns_list_records(self, http_context, fqdn):
self.mgr.domains[fqdn].get_records()
return [asdict(r) for r in self.mgr.domains[fqdn].records]

0 comments on commit 2d1413b

Please sign in to comment.