Compare commits
2 Commits
master
...
feature/lo
| Author | SHA1 | Date |
|---|---|---|
|
|
c9ae84c721 | |
|
|
47b8620013 |
|
|
@ -2,6 +2,7 @@ package ru.kirillius.pf.sdn.web.RPC;
|
|||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
import ru.kirillius.json.DefaultPropertySerializer;
|
||||
import ru.kirillius.json.JSONUtility;
|
||||
import ru.kirillius.json.rpc.Annotations.JRPCArgument;
|
||||
|
|
@ -88,7 +89,8 @@ public class SubscriptionManager implements RPC {
|
|||
@JRPCArgument(name = "subnets") JSONArray subnets,
|
||||
@JRPCArgument(name = "addresses") JSONArray addresses,
|
||||
@JRPCArgument(name = "storage") String storage,
|
||||
@JRPCArgument(name = "subscribe") boolean subscribe) throws IOException {
|
||||
@JRPCArgument(name = "subscribe") boolean subscribe,
|
||||
@JRPCArgument(name = "append") boolean append) throws IOException {
|
||||
var repositoryConfig = findLocalRepo(storage);
|
||||
var directory = new File(repositoryConfig.getSource());
|
||||
if (!directory.exists()) {
|
||||
|
|
@ -96,25 +98,43 @@ public class SubscriptionManager implements RPC {
|
|||
}
|
||||
|
||||
var domainList = new ArrayList<String>();
|
||||
var targetFile = new File(directory, name + ".json");
|
||||
var bundle = new NetworkResourceBundle();
|
||||
|
||||
domains.forEach(d->domainList.add(d.toString()));
|
||||
if (append) {
|
||||
if (targetFile.exists()) {
|
||||
try (var stream = new FileInputStream(targetFile)) {
|
||||
var json = new JSONObject(new JSONTokener(stream));
|
||||
bundle.add(
|
||||
JSONUtility.deserializeStructure(json, NetworkResourceBundle.class)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try (var writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(directory, name + ".json"))))) {
|
||||
domains.forEach(d -> domainList.add(d.toString()));
|
||||
|
||||
|
||||
try (var writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(targetFile)))) {
|
||||
var merged = JSONUtility.deserializeCollection(subnets, IPv4Subnet.class, null).collect(Collectors.toList());
|
||||
addresses.forEach(address -> {
|
||||
merged.add(new IPv4Subnet(address.toString(), 32));
|
||||
});
|
||||
|
||||
|
||||
//noinspection rawtypes
|
||||
@SuppressWarnings("unchecked")
|
||||
var asnList = (List<Integer>) JSONUtility.deserializeCollection(ASN, Integer.class, (Class) DefaultPropertySerializer.class).toList();
|
||||
writer.write(JSONUtility.serializeStructure(
|
||||
NetworkResourceBundle.builder()
|
||||
.ASN(asnList)
|
||||
.subnets(merged)
|
||||
.domains(domainList)
|
||||
.description(description)
|
||||
.build()
|
||||
).toString(2));
|
||||
|
||||
bundle.add(NetworkResourceBundle.builder()
|
||||
.ASN(asnList)
|
||||
.subnets(merged)
|
||||
.domains(domainList)
|
||||
.description(description)
|
||||
.build());
|
||||
|
||||
|
||||
writer.write(JSONUtility.serializeStructure(bundle).toString(2));
|
||||
}
|
||||
if (subscribe) {
|
||||
var subscribedResources = context.getConfig().getSubscribedResources();
|
||||
|
|
|
|||
|
|
@ -53,6 +53,12 @@ function renderSubscriptionList() {
|
|||
}).join('');
|
||||
|
||||
const html = `
|
||||
<div class="select-all-container" style="margin-bottom: 10px;">
|
||||
<label>
|
||||
<input type="checkbox" id="select-all-checkbox">
|
||||
Выделить все
|
||||
</label>
|
||||
</div>
|
||||
<ul class="subscription-list">${listHtml}</ul>
|
||||
<button id="save-subscriptions-btn" class="btn-primary" style="width: 250px; margin-top: 30px;">Сохранить</button>
|
||||
<div id="subscription-status-message" class="error-message" style="display: none;"></div>
|
||||
|
|
@ -63,6 +69,11 @@ function renderSubscriptionList() {
|
|||
}
|
||||
|
||||
function attachEventHandlers() {
|
||||
$('#select-all-checkbox').on('change', function() {
|
||||
const isChecked = $(this).is(':checked');
|
||||
$('.subscription-checkbox').prop('checked', isChecked);
|
||||
});
|
||||
|
||||
$('#save-subscriptions-btn').on('click', async function () {
|
||||
const $btn = $(this);
|
||||
const $message = $('#subscription-status-message');
|
||||
|
|
|
|||
|
|
@ -308,7 +308,8 @@ function handleAdd() {
|
|||
selectedSubnets,
|
||||
selectedAddresses,
|
||||
storage,
|
||||
true
|
||||
true,
|
||||
false
|
||||
).then(() => {
|
||||
setStatus('Ресурсы успешно добавлены.', 'success');
|
||||
}).catch(error => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue