2
0
mirror of https://github.com/VinylDNS/vinyldns synced 2025-08-23 10:37:08 +00:00

488 lines
19 KiB
JavaScript
Raw Normal View History

2018-07-27 10:18:29 -04:00
/*
* Copyright 2018 Comcast Cable Communications Management, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
angular.module('controller.zones', [])
.controller('ZonesController', function ($scope, $http, $location, $log, recordsService, zonesService, profileService,
groupsService, utilityService, $timeout, pagingService) {
$scope.alerts = [];
$scope.zonesLoaded = false;
2019-06-24 17:19:59 -04:00
$scope.allZonesLoaded = false;
2018-07-27 10:18:29 -04:00
$scope.hasZones = false; // Re-assigned each time zones are fetched without a query
$scope.allGroups = [];
2023-07-24 18:24:02 +05:30
$scope.myDeletedZones = [];
$scope.allDeletedZones = [];
2022-09-28 14:23:51 +05:30
$scope.ignoreAccess = false;
2023-04-04 11:33:57 +05:30
$scope.validEmailDomains= [];
2022-09-28 14:23:51 +05:30
$scope.allZonesAccess = function () {
$scope.ignoreAccess = true;
}
$scope.myZonesAccess = function () {
$scope.ignoreAccess = false;
}
2018-07-27 10:18:29 -04:00
$scope.query = "";
$scope.includeReverse = true;
2018-07-27 10:18:29 -04:00
$scope.keyAlgorithms = ['HMAC-MD5', 'HMAC-SHA1', 'HMAC-SHA224', 'HMAC-SHA256', 'HMAC-SHA384', 'HMAC-SHA512'];
2018-07-27 10:18:29 -04:00
// Paging status for zone sets
var zonesPaging = pagingService.getNewPagingParams(100);
2019-06-24 17:19:59 -04:00
var allZonesPaging = pagingService.getNewPagingParams(100);
2024-01-17 12:46:39 +05:30
var myDeletedZonesPaging = pagingService.getNewPagingParams(100);
var allDeletedZonesPaging = pagingService.getNewPagingParams(100);
2018-07-27 10:18:29 -04:00
profileService.getAuthenticatedUserData().then(function (results) {
if (results.data) {
$scope.profile = results.data;
$scope.profile.active = 'zones';
}
}, function () {
$scope.profile = $scope.profile || {};
$scope.profile.active = 'zones';
});
$scope.resetCurrentZone = function () {
$scope.currentZone = {};
2023-04-04 11:33:57 +05:30
$scope.validDomains();
2018-07-27 10:18:29 -04:00
if($scope.myGroups && $scope.myGroups.length) {
$scope.currentZone.adminGroupId = $scope.myGroups[0].id;
}
$scope.currentZone.connection = {};
$scope.currentZone.transferConnection = {};
};
2022-06-01 15:01:01 +05:30
groupsService.getGroups(true, "").then(function (results) {
if (results.data) {
2022-05-20 09:23:37 -04:00
// Get all groups where the group members include the current user
$scope.myGroups = results.data.groups.filter(grp => grp.members.findIndex(mem => mem.id === $scope.profile.id) >= 0);
$scope.myGroupIds = $scope.myGroups.map(grp => grp.id);
$scope.allGroups = results.data.groups;
}
$scope.resetCurrentZone();
});
zonesService.getBackendIds().then(function (results) {
if (results.data) {
$scope.backendIds = results.data;
}
});
$scope.canAccessGroup = function(groupId) {
2022-09-08 13:35:30 +05:30
return $scope.myGroupIds !== undefined && $scope.myGroupIds.indexOf(groupId) > -1;
2018-07-27 10:18:29 -04:00
};
2019-06-24 17:19:59 -04:00
$scope.canAccessZone = function(accessLevel) {
if (accessLevel == 'Read' || accessLevel == 'Delete') {
return true;
} else {
return false;
}
};
2023-02-27 09:36:13 +05:30
$.zoneAutocompleteSearch = function() {
// Autocomplete for zone search
$(".zone-search-text").autocomplete({
source: function( request, response ) {
$.ajax({
url: "/api/zones?maxItems=100",
dataType: "json",
data: {nameFilter: request.term, ignoreAccess: $scope.ignoreAccess},
success: function(data) {
const search = JSON.parse(JSON.stringify(data));
response($.map(search.zones, function(zone) {
return {value: zone.name, label: zone.name}
}))
}
});
},
minLength: 1,
select: function (event, ui) {
$scope.query = ui.item.value;
$(".zone-search-text").val(ui.item.value);
return false;
},
open: function() {
$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
},
close: function() {
$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
2022-09-28 14:23:51 +05:30
}
});
2023-02-27 09:36:13 +05:30
};
// Should be the default autocomplete search result option
$.zoneAutocompleteSearch();
2022-09-28 14:23:51 +05:30
2023-02-15 14:41:40 +05:30
$('.isGroupSearch').change(function() {
if(this.checked) {
// Autocomplete for search by admin group
$(".zone-search-text").autocomplete({
source: function( request, response ) {
$.ajax({
url: "/api/groups?maxItems=100&abridged=true",
dataType: "json",
data: {groupNameFilter: request.term, ignoreAccess: $scope.ignoreAccess},
success: function(data) {
const search = JSON.parse(JSON.stringify(data));
response($.map(search.groups, function(group) {
return {value: group.name, label: group.name}
}))
}
});
},
minLength: 1,
select: function (event, ui) {
$scope.query = ui.item.value;
$(".zone-search-text").val(ui.item.value);
return false;
},
open: function() {
$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
},
close: function() {
$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
}
});
2023-02-24 17:41:14 +05:30
} else {
2023-02-27 09:36:13 +05:30
$.zoneAutocompleteSearch();
2023-02-15 14:41:40 +05:30
}
});
2023-02-24 17:58:40 +05:30
// Autocomplete text-highlight
$.ui.autocomplete.prototype._renderItem = function(ul, item) {
let txt = String(item.label).replace(new RegExp(this.term, "gi"),"<b>$&</b>");
return $("<li></li>")
.data("ui-autocomplete-item", item.value)
.append("<div>" + txt + "</div>")
.appendTo(ul);
};
2018-07-27 10:18:29 -04:00
/* Refreshes zone data set and then re-displays */
$scope.refreshZones = function () {
zonesPaging = pagingService.resetPaging(zonesPaging);
2019-06-24 17:19:59 -04:00
allZonesPaging = pagingService.resetPaging(allZonesPaging);
2024-01-17 12:46:39 +05:30
myDeletedZonesPaging = pagingService.resetPaging(myDeletedZonesPaging);
allDeletedZonesPaging = pagingService.resetPaging(allDeletedZonesPaging);
2018-07-27 10:18:29 -04:00
2019-06-24 17:19:59 -04:00
zonesService
2023-08-22 23:57:44 +05:30
.getZones(zonesPaging.maxItems, undefined, $scope.query, $scope.searchByAdminGroup, false, $scope.includeReverse)
2019-06-24 17:19:59 -04:00
.then(function (response) {
2022-09-08 13:35:30 +05:30
$log.debug('zonesService::getZones-success (' + response.data.zones.length + ' zones)');
2019-06-24 17:19:59 -04:00
zonesPaging.next = response.data.nextId;
updateZoneDisplay(response.data.zones);
if (!$scope.query.length) {
$scope.hasZones = response.data.zones.length > 0;
}
})
.catch(function (error) {
handleError(error, 'zonesService::getZones-failure');
});
zonesService
.getZones(zonesPaging.maxItems, undefined, $scope.query, $scope.searchByAdminGroup, true, $scope.includeReverse)
2019-06-24 17:19:59 -04:00
.then(function (response) {
2022-09-08 13:35:30 +05:30
$log.debug('zonesService::getZones-success (' + response.data.zones.length + ' zones)');
2019-06-24 17:19:59 -04:00
allZonesPaging.next = response.data.nextId;
updateAllZonesDisplay(response.data.zones);
})
2018-07-27 10:18:29 -04:00
.catch(function (error) {
handleError(error, 'zonesService::getZones-failure');
});
2023-07-24 18:24:02 +05:30
zonesService
2024-01-17 12:46:39 +05:30
.getDeletedZones(myDeletedZonesPaging.maxItems, undefined, $scope.query, false)
2023-07-24 18:24:02 +05:30
.then(function (response) {
$log.debug('zonesService::getMyDeletedZones-success (' + response.data.zonesDeletedInfo.length + ' zones)');
2024-01-17 12:46:39 +05:30
myDeletedZonesPaging.next = response.data.nextId;
2023-07-24 18:24:02 +05:30
updateMyDeletedZoneDisplay(response.data.zonesDeletedInfo);
})
.catch(function (error) {
handleError(error, 'zonesService::getDeletedZones-failure');
});
2023-08-22 23:57:44 +05:30
2023-07-24 18:24:02 +05:30
zonesService
2024-01-17 12:46:39 +05:30
.getDeletedZones(allDeletedZonesPaging.maxItems, undefined, $scope.query, true)
2023-07-24 18:24:02 +05:30
.then(function (response) {
$log.debug('zonesService::getAllDeletedZones-success (' + response.data.zonesDeletedInfo.length + ' zones)');
2024-01-17 12:46:39 +05:30
allDeletedZonesPaging.next = response.data.nextId;
2023-07-24 18:24:02 +05:30
updateAllDeletedZoneDisplay(response.data.zonesDeletedInfo);
})
.catch(function (error) {
handleError(error, 'zonesService::getDeletedZones-failure');
});
2018-07-27 10:18:29 -04:00
};
2023-07-24 18:24:02 +05:30
function updateMyDeletedZoneDisplay (myDeletedZones) {
$scope.myDeletedZones = myDeletedZones;
$scope.myDeletedZonesLoaded = true;
$log.debug("Displaying my Deleted zones: ", $scope.myDeletedZones);
if($scope.myDeletedZones.length > 0) {
$("td.dataTables_empty").hide();
} else {
$("td.dataTables_empty").show();
}
}
function updateAllDeletedZoneDisplay (allDeletedZones) {
$scope.allDeletedZones = allDeletedZones;
$scope.allDeletedZonesLoaded = true;
$log.debug("Displaying all Deleted zones: ", $scope.allDeletedZones);
if($scope.allDeletedZones.length > 0) {
$("td.dataTables_empty").hide();
} else {
$("td.dataTables_empty").show();
}
}
2018-07-27 10:18:29 -04:00
function updateZoneDisplay (zones) {
$scope.zones = zones;
2019-06-24 17:19:59 -04:00
$scope.myZoneIds = zones.map(function(zone) {return zone['id']});
2018-07-27 10:18:29 -04:00
$scope.zonesLoaded = true;
2022-09-08 13:35:30 +05:30
$log.debug("Displaying my zones: ", $scope.zones);
2018-07-27 10:18:29 -04:00
if($scope.zones.length > 0) {
$("td.dataTables_empty").hide();
} else {
$("td.dataTables_empty").show();
}
}
2019-06-24 17:19:59 -04:00
function updateAllZonesDisplay (zones) {
$scope.allZones = zones;
$scope.allZonesLoaded = true;
2022-09-08 13:35:30 +05:30
$log.debug("Displaying all zones: ", $scope.allZones);
2019-06-24 17:19:59 -04:00
if($scope.allZones.length > 0) {
$("td.dataTables_empty").hide();
} else {
$("td.dataTables_empty").show();
}
}
2023-04-04 11:33:57 +05:30
$scope.validDomains=function getValidEmailDomains() {
function success(response) {
2023-05-25 11:38:49 +05:30
$log.debug('zonesService::listEmailDomains-success', response);
2023-04-04 11:33:57 +05:30
return $scope.validEmailDomains = response.data;
}
2019-06-24 17:19:59 -04:00
2023-04-10 11:53:00 +05:30
return groupsService
2023-04-04 11:33:57 +05:30
.listEmailDomains($scope.ignoreAccess, $scope.query)
.then(success)
.catch(function (error) {
handleError(error, 'zonesService::listEmailDomains-failure');
});
}
2023-04-11 11:50:49 +05:30
2018-07-27 10:18:29 -04:00
/* Set total number of zones */
$scope.addZoneConnection = function () {
if ($scope.processing) {
2022-09-08 13:35:30 +05:30
$log.debug('zoneConnection::processing is true; exiting');
return;
}
//flag to prevent multiple clicks until previous promise has resolved.
$scope.processing = true;
$scope.currentZone = zonesService.checkBackendId($scope.currentZone);
2018-07-27 10:18:29 -04:00
zonesService.sendZone($scope.currentZone)
.then(function () {
$timeout($scope.refreshZones(), 1000);
$("#zone_connection_modal").modal("hide");
$scope.processing = false;
2018-07-27 10:18:29 -04:00
})
.catch(function (error){
$("#zone_connection_modal").modal("hide");
$scope.zoneError = true;
handleError(error, 'zonesService::sendZone-failure');
$scope.processing = false;
2018-07-27 10:18:29 -04:00
});
};
function handleError(error, type) {
$scope.zoneError = true;
var alert = utilityService.failure(error, type);
$scope.alerts.push(alert);
if(error.data !== undefined && error.data.errors !== undefined) {
var errors = error.data.errors;
for(i in errors) {
$scope.alerts.push({type: "danger", content:errors[i]});
}
}
}
/*
* Zone set paging
*/
2019-06-24 17:19:59 -04:00
$scope.getZonesPageNumber = function(tab) {
switch(tab) {
case 'myZones':
return pagingService.getPanelTitle(zonesPaging);
case 'allZones':
return pagingService.getPanelTitle(allZonesPaging);
2023-07-24 18:24:02 +05:30
case 'myDeletedZones':
2024-01-17 12:46:39 +05:30
return pagingService.getPanelTitle(myDeletedZonesPaging);
2023-07-24 18:24:02 +05:30
case 'allDeletedZones':
2024-01-17 12:46:39 +05:30
return pagingService.getPanelTitle(allDeletedZonesPaging);
2019-06-24 17:19:59 -04:00
}
};
2018-07-27 10:18:29 -04:00
2019-06-24 17:19:59 -04:00
$scope.prevPageEnabled = function(tab) {
switch(tab) {
case 'myZones':
return pagingService.prevPageEnabled(zonesPaging);
case 'allZones':
return pagingService.prevPageEnabled(allZonesPaging);
2023-07-24 18:24:02 +05:30
case 'myDeletedZones':
2024-01-17 12:46:39 +05:30
return pagingService.prevPageEnabled(myDeletedZonesPaging);
2023-07-24 18:24:02 +05:30
case 'allDeletedZones':
2024-01-17 12:46:39 +05:30
return pagingService.prevPageEnabled(allDeletedZonesPaging);
2019-06-24 17:19:59 -04:00
}
2018-07-27 10:18:29 -04:00
};
2019-06-24 17:19:59 -04:00
$scope.nextPageEnabled = function(tab) {
switch(tab) {
case 'myZones':
return pagingService.nextPageEnabled(zonesPaging);
case 'allZones':
return pagingService.nextPageEnabled(allZonesPaging);
2023-07-24 18:24:02 +05:30
case 'myDeletedZones':
2024-01-17 12:46:39 +05:30
return pagingService.nextPageEnabled(myDeletedZonesPaging);
2023-07-24 18:24:02 +05:30
case 'allDeletedZones':
2024-01-17 12:46:39 +05:30
return pagingService.nextPageEnabled(allDeletedZonesPaging);
2019-06-24 17:19:59 -04:00
}
2018-07-27 10:18:29 -04:00
};
2019-06-24 17:19:59 -04:00
$scope.prevPageMyZones = function() {
2018-07-27 10:18:29 -04:00
var startFrom = pagingService.getPrevStartFrom(zonesPaging);
return zonesService
.getZones(zonesPaging.maxItems, startFrom, $scope.query, $scope.searchByAdminGroup, false, true)
2018-07-27 10:18:29 -04:00
.then(function(response) {
zonesPaging = pagingService.prevPageUpdate(response.data.nextId, zonesPaging);
updateZoneDisplay(response.data.zones);
})
.catch(function (error) {
handleError(error,'zonesService::prevPage-failure');
});
2019-06-24 17:19:59 -04:00
}
$scope.prevPageAllZones = function() {
var startFrom = pagingService.getPrevStartFrom(allZonesPaging);
return zonesService
.getZones(allZonesPaging.maxItems, startFrom, $scope.query, $scope.searchByAdminGroup, true, true)
2019-06-24 17:19:59 -04:00
.then(function(response) {
allZonesPaging = pagingService.prevPageUpdate(response.data.nextId, allZonesPaging);
updateAllZonesDisplay(response.data.zones);
})
.catch(function (error) {
handleError(error,'zonesService::prevPage-failure');
});
}
2018-07-27 10:18:29 -04:00
2023-07-24 18:24:02 +05:30
$scope.prevPageMyDeletedZones = function() {
2024-01-17 12:46:39 +05:30
var startFrom = pagingService.getPrevStartFrom(myDeletedZonesPaging);
2023-07-24 18:24:02 +05:30
return zonesService
2024-01-17 12:46:39 +05:30
.getDeletedZones(myDeletedZonesPaging.maxItems, startFrom, $scope.query, false)
2023-07-24 18:24:02 +05:30
.then(function(response) {
2024-01-17 12:46:39 +05:30
myDeletedZonesPaging = pagingService.prevPageUpdate(response.data.nextId, myDeletedZonesPaging);
2023-07-24 18:24:02 +05:30
updateMyDeletedZoneDisplay(response.data.zonesDeletedInfo);
})
.catch(function (error) {
handleError(error,'zonesService::prevPage-failure');
});
}
$scope.prevPageAllDeletedZones = function() {
2024-01-17 12:46:39 +05:30
var startFrom = pagingService.getPrevStartFrom(allDeletedZonesPaging);
2023-07-24 18:24:02 +05:30
return zonesService
2024-01-17 12:46:39 +05:30
.getDeletedZones(allDeletedZonesPaging.maxItems, startFrom, $scope.query, true)
2023-07-24 18:24:02 +05:30
.then(function(response) {
2024-01-17 12:46:39 +05:30
allDeletedZonesPaging = pagingService.prevPageUpdate(response.data.nextId, allDeletedZonesPaging);
2023-07-24 18:24:02 +05:30
updateAllDeletedZoneDisplay(response.data.zonesDeletedInfo);
})
.catch(function (error) {
handleError(error,'zonesService::prevPage-failure');
});
}
2019-06-24 17:19:59 -04:00
$scope.nextPageMyZones = function () {
2018-07-27 10:18:29 -04:00
return zonesService
.getZones(zonesPaging.maxItems, zonesPaging.next, $scope.query, $scope.searchByAdminGroup, false, true)
2018-07-27 10:18:29 -04:00
.then(function(response) {
var zoneSets = response.data.zones;
zonesPaging = pagingService.nextPageUpdate(zoneSets, response.data.nextId, zonesPaging);
if (zoneSets.length > 0) {
updateZoneDisplay(response.data.zones);
}
})
.catch(function (error) {
handleError(error,'zonesService::nextPage-failure')
});
};
2019-06-24 17:19:59 -04:00
$scope.nextPageAllZones = function () {
return zonesService
.getZones(allZonesPaging.maxItems, allZonesPaging.next, $scope.query, $scope.searchByAdminGroup, true, true)
2019-06-24 17:19:59 -04:00
.then(function(response) {
var zoneSets = response.data.zones;
allZonesPaging = pagingService.nextPageUpdate(zoneSets, response.data.nextId, allZonesPaging);
if (zoneSets.length > 0) {
updateAllZonesDisplay(response.data.zones);
}
})
.catch(function (error) {
handleError(error,'zonesService::nextPage-failure')
});
};
2023-07-24 18:24:02 +05:30
$scope.nextPageMyDeletedZones = function () {
return zonesService
2024-01-17 12:46:39 +05:30
.getDeletedZones(myDeletedZonesPaging.maxItems, myDeletedZonesPaging.next, $scope.query, false)
2023-07-24 18:24:02 +05:30
.then(function(response) {
var myDeletedZoneSets = response.data.zonesDeletedInfo;
2024-01-17 12:46:39 +05:30
myDeletedZonesPaging = pagingService.nextPageUpdate(myDeletedZoneSets, response.data.nextId, myDeletedZonesPaging);
2023-07-24 18:24:02 +05:30
if (myDeletedZoneSets.length > 0) {
updateMyDeletedZoneDisplay(response.data.zonesDeletedInfo);
}
})
.catch(function (error) {
handleError(error,'zonesService::nextPage-failure')
});
};
$scope.nextPageAllDeletedZones = function () {
return zonesService
2024-01-17 12:46:39 +05:30
.getDeletedZones(allDeletedZonesPaging.maxItems, allDeletedZonesPaging.next, $scope.query, true)
2023-07-24 18:24:02 +05:30
.then(function(response) {
var allDeletedZoneSets = response.data.zonesDeletedInfo;
2024-01-17 12:46:39 +05:30
allDeletedZonesPaging = pagingService.nextPageUpdate(allDeletedZoneSets, response.data.nextId, allDeletedZonesPaging);
2023-07-24 18:24:02 +05:30
if (allDeletedZoneSets.length > 0) {
updateAllDeletedZoneDisplay(response.data.zonesDeletedInfo);
}
})
.catch(function (error) {
handleError(error,'zonesService::nextPage-failure')
});
};
2018-07-27 10:18:29 -04:00
$timeout($scope.refreshZones, 0);
});