добавлен мультивыбор в подписках
This commit is contained in:
parent
1bcf317c8f
commit
47b8620013
|
|
@ -2,6 +2,7 @@ package ru.kirillius.pf.sdn.web.RPC;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
import org.json.JSONTokener;
|
||||||
import ru.kirillius.json.DefaultPropertySerializer;
|
import ru.kirillius.json.DefaultPropertySerializer;
|
||||||
import ru.kirillius.json.JSONUtility;
|
import ru.kirillius.json.JSONUtility;
|
||||||
import ru.kirillius.json.rpc.Annotations.JRPCArgument;
|
import ru.kirillius.json.rpc.Annotations.JRPCArgument;
|
||||||
|
|
@ -88,7 +89,8 @@ public class SubscriptionManager implements RPC {
|
||||||
@JRPCArgument(name = "subnets") JSONArray subnets,
|
@JRPCArgument(name = "subnets") JSONArray subnets,
|
||||||
@JRPCArgument(name = "addresses") JSONArray addresses,
|
@JRPCArgument(name = "addresses") JSONArray addresses,
|
||||||
@JRPCArgument(name = "storage") String storage,
|
@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 repositoryConfig = findLocalRepo(storage);
|
||||||
var directory = new File(repositoryConfig.getSource());
|
var directory = new File(repositoryConfig.getSource());
|
||||||
if (!directory.exists()) {
|
if (!directory.exists()) {
|
||||||
|
|
@ -96,25 +98,43 @@ public class SubscriptionManager implements RPC {
|
||||||
}
|
}
|
||||||
|
|
||||||
var domainList = new ArrayList<String>();
|
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());
|
var merged = JSONUtility.deserializeCollection(subnets, IPv4Subnet.class, null).collect(Collectors.toList());
|
||||||
addresses.forEach(address -> {
|
addresses.forEach(address -> {
|
||||||
merged.add(new IPv4Subnet(address.toString(), 32));
|
merged.add(new IPv4Subnet(address.toString(), 32));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
//noinspection rawtypes
|
//noinspection rawtypes
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
var asnList = (List<Integer>) JSONUtility.deserializeCollection(ASN, Integer.class, (Class) DefaultPropertySerializer.class).toList();
|
var asnList = (List<Integer>) JSONUtility.deserializeCollection(ASN, Integer.class, (Class) DefaultPropertySerializer.class).toList();
|
||||||
writer.write(JSONUtility.serializeStructure(
|
|
||||||
NetworkResourceBundle.builder()
|
bundle.add(NetworkResourceBundle.builder()
|
||||||
.ASN(asnList)
|
.ASN(asnList)
|
||||||
.subnets(merged)
|
.subnets(merged)
|
||||||
.domains(domainList)
|
.domains(domainList)
|
||||||
.description(description)
|
.description(description)
|
||||||
.build()
|
.build());
|
||||||
).toString(2));
|
|
||||||
|
|
||||||
|
writer.write(JSONUtility.serializeStructure(bundle).toString(2));
|
||||||
}
|
}
|
||||||
if (subscribe) {
|
if (subscribe) {
|
||||||
var subscribedResources = context.getConfig().getSubscribedResources();
|
var subscribedResources = context.getConfig().getSubscribedResources();
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,12 @@ function renderSubscriptionList() {
|
||||||
}).join('');
|
}).join('');
|
||||||
|
|
||||||
const html = `
|
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>
|
<ul class="subscription-list">${listHtml}</ul>
|
||||||
<button id="save-subscriptions-btn" class="btn-primary" style="width: 250px; margin-top: 30px;">Сохранить</button>
|
<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>
|
<div id="subscription-status-message" class="error-message" style="display: none;"></div>
|
||||||
|
|
@ -63,6 +69,11 @@ function renderSubscriptionList() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function attachEventHandlers() {
|
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 () {
|
$('#save-subscriptions-btn').on('click', async function () {
|
||||||
const $btn = $(this);
|
const $btn = $(this);
|
||||||
const $message = $('#subscription-status-message');
|
const $message = $('#subscription-status-message');
|
||||||
|
|
|
||||||
|
|
@ -308,7 +308,8 @@ function handleAdd() {
|
||||||
selectedSubnets,
|
selectedSubnets,
|
||||||
selectedAddresses,
|
selectedAddresses,
|
||||||
storage,
|
storage,
|
||||||
true
|
true,
|
||||||
|
false
|
||||||
).then(() => {
|
).then(() => {
|
||||||
setStatus('Ресурсы успешно добавлены.', 'success');
|
setStatus('Ресурсы успешно добавлены.', 'success');
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue