import InjectProperty from "@web-atoms/core/dist/core/InjectProperty.js";
import { ContentPage } from "@web-atoms/web-controls/dist/mobile-app/MobileApp.js";
import DnsZoneService from "../DnsZoneService.js";
import { IDnsZone, IDnsZoneRecord } from "../../../../model/model.js";
import XNode from "@web-atoms/core/dist/core/XNode.js";
import AtomRepeater, { SelectorCheckBox } from "@web-atoms/web-controls/dist/basic/AtomRepeater.js";
import Bind from "@web-atoms/core/dist/core/Bind.js";
import Action from "@web-atoms/core/dist/view-model/Action.js";
import Checkbox from "@web-atoms/web-controls/dist/basic/Checkbox.js";
import PageNavigator from "@web-atoms/web-controls/dist/PageNavigator.js";
import DnsRecordEditorPage from "./DnsRecordEditorPage.js";
export default class DnsZoneEditorPage extends ContentPage<{ zoneID: number }> {
@InjectProperty
private dnsZoneService: DnsZoneService;
private model: IDnsZone;
private selectedRecords: IDnsZoneRecord[] = [];
private search = "";
private showDisabled = false;
async init() {
this.model = await this.dnsZoneService.get(this.parameters.zoneID);
this.sort();
this.title = this.model.zone;
this.renderer =
}
footer={true}
footerRenderer={() => }
itemRenderer={(item) =>
}
/>
;
}
sort() {
this.model.records.sort((a, b) => (a.disabled ? 1 : 0) - (b.disabled ? 1 : 0));
this.model.records.refresh();
}
@Action({
onEvent: "delete-items",
confirm: "Are you sure you want to delete selected records?"
})
async deleteItem() {
for (const iterator of this.selectedRecords) {
iterator.$deleted = true;
}
await this.dnsZoneService.saveRecord(...this.selectedRecords);
await this.init();
}
@Action({
onEvent: "disable-item",
confirm: "Are you sure you want to disable the record?"
})
async disableItem(item: IDnsZoneRecord) {
item.disabled = true;
await this.dnsZoneService.saveRecord(item);
this.sort();
}
@Action({
onEvent: "enable-item",
confirm: "Are you sure you want to enable the record?"
})
async enableItem(item: IDnsZoneRecord) {
item.disabled = false;
await this.dnsZoneService.saveRecord(item);
this.sort();
}
@Action({
onEvent: "edit-item"
})
async editItem(model: IDnsZoneRecord) {
const zone = this.model;
model = await PageNavigator.pushPageForResult(DnsRecordEditorPage, { model, zone })
await this.dnsZoneService.saveRecord(model);
this.sort();
}
@Action({ onEvent: "add-new-record"})
async addNewRecord() {
const zone = this.model;
const record = await PageNavigator.pushPageForResult(DnsRecordEditorPage, { zone });
record.zoneID = this.model.zoneID;
await this.dnsZoneService.saveRecord(record);
this.model.records.add(record);
}
@Action({ onEvent: "remove-hosting", confirm: "Are you sure you want to remove hosting for this zone?"})
async removeHosting() {
for (const iterator of this.selectedRecords) {
(iterator as any).hosted = false;
}
await this.dnsZoneService.saveRecord(... this.selectedRecords);
}
@Action({ onEvent: "add-hosting", confirm: "Are you sure you want to add hosting for this zone?"})
async addHosting() {
let isWildcard = null;
for (const iterator of this.selectedRecords) {
(iterator as any).hosted = true;
if (iterator.name === "*" && (iterator.type === "A" || iterator.type === "CNAME")) {
isWildcard = iterator;
}
}
let records = [ ... this.selectedRecords];
if (isWildcard) {
for (const iterator of this.model.records) {
if ((iterator.name === "@" || iterator.name === "") && iterator.type === "A") {
continue;
}
(iterator as any).hosted = false;
}
isWildcard.hosted = true;
records = this.model.records;
}
await this.dnsZoneService.saveRecord(... records);
}
}