2
0
mirror of https://github.com/VinylDNS/vinyldns synced 2025-08-22 18:17:07 +00:00
vinyldns/modules/portal/public/lib/dns-change/dns-changes.controller.js

187 lines
8.2 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.
*/
(function() {
'use strict';
angular.module('dns-change')
2023-11-14 16:20:54 +05:30
.controller('DnsChangesController', function($scope, $timeout, $q, $log, dnsChangeService, pagingService, utilityService){
2018-07-27 10:18:29 -04:00
$scope.batchChanges = [];
$scope.currentBatchChange;
2018-07-27 10:18:29 -04:00
// Set default params: empty start from and 100 max items
var batchChangePaging = pagingService.getNewPagingParams(100);
2023-11-14 16:20:54 +05:30
var yesterday = moment().subtract(1, 'days').startOf('day').format('YYYY-MM-DD HH:mm:ss');
var now = moment().format('YYYY-MM-DD HH:mm:ss');
$scope.filter = {dateTimeRangeStart: "", dateTimeRangeEnd: ""};
2018-07-27 10:18:29 -04:00
$scope.getBatchChanges = function(maxItems, startFrom) {
function success(response) {
return response;
}
return dnsChangeService
2024-02-26 12:26:48 +05:30
.getBatchChanges(maxItems, startFrom, $scope.ignoreAccess, $scope.approvalStatus, $scope.submitterName, $scope.filter.dateTimeRangeStart, $scope.filter.dateTimeRangeEnd)
2018-07-27 10:18:29 -04:00
.then(success)
.catch(function(error) {
handleError(error, 'dnsChangesService::getBatchChanges-failure');
2018-07-27 10:18:29 -04:00
});
};
2023-11-14 16:20:54 +05:30
$scope.getLocalTimeZone = function() {
return new Date().toLocaleString('en-us', {timeZoneName:'short'}).split(' ')[3];
}
2018-07-27 10:18:29 -04:00
function handleError(error, type) {
var alert = utilityService.failure(error, type);
$scope.alerts.push(alert);
}
$scope.refreshBatchChanges = function() {
batchChangePaging = pagingService.resetPaging(batchChangePaging);
function success(response) {
batchChangePaging.next = response.data.nextId;
$scope.batchChanges = response.data.batchChanges;
for(var i = 0; i < $scope.batchChanges.length; i++) {
$scope.batchChanges[i].createdTimestamp = utilityService.formatDateTime($scope.batchChanges[i].createdTimestamp);
}
2018-07-27 10:18:29 -04:00
}
return dnsChangeService
2024-02-26 12:26:48 +05:30
.getBatchChanges(batchChangePaging.maxItems, undefined, $scope.ignoreAccess, $scope.approvalStatus, $scope.submitterName, $scope.filter.dateTimeRangeStart, $scope.filter.dateTimeRangeEnd)
2018-07-27 10:18:29 -04:00
.then(success)
.catch(function (error){
handleError(error, 'dnsChangesService::getBatchChanges-failure');
2018-07-27 10:18:29 -04:00
});
};
2023-11-14 16:20:54 +05:30
$scope.resetDateTimeFilter = function() {
$scope.filter.dateTimeRangeStart = "";
$scope.filter.dateTimeRangeEnd = "";
2024-02-23 17:37:12 +05:30
$('input[name="dateTimeRange"]').data('daterangepicker').setStartDate(yesterday);
$('input[name="dateTimeRange"]').data('daterangepicker').setEndDate(now);
2023-11-14 16:20:54 +05:30
$scope.refreshBatchChanges();
};
2018-07-27 10:18:29 -04:00
// Previous page button enabled?
$scope.prevPageEnabled = function() {
return pagingService.prevPageEnabled(batchChangePaging);
};
// Next page button enabled?
$scope.nextPageEnabled = function() {
return pagingService.nextPageEnabled(batchChangePaging);
};
// Get page number for display
$scope.getPageTitle = function() {
return pagingService.getPanelTitle(batchChangePaging);
};
$scope.prevPage = function() {
var startFrom = pagingService.getPrevStartFrom(batchChangePaging);
return $scope
2024-02-26 12:26:48 +05:30
.getBatchChanges(batchChangePaging.maxItems, startFrom, $scope.ignoreAccess, $scope.approvalStatus, $scope.submitterName, $scope.filter.dateTimeRangeStart, $scope.filter.dateTimeRangeEnd)
2018-07-27 10:18:29 -04:00
.then(function(response) {
batchChangePaging = pagingService.prevPageUpdate(response.data.nextId, batchChangePaging);
$scope.batchChanges = response.data.batchChanges;
})
.catch(function (error){
handleError(error, 'dnsChangesService::getBatchChanges-failure');
2018-07-27 10:18:29 -04:00
});
};
$scope.nextPage = function() {
return $scope
2024-02-26 12:26:48 +05:30
.getBatchChanges(batchChangePaging.maxItems, batchChangePaging.next, $scope.ignoreAccess, $scope.approvalStatus, $scope.submitterName, $scope.filter.dateTimeRangeStart, $scope.filter.dateTimeRangeEnd)
2018-07-27 10:18:29 -04:00
.then(function(response) {
var batchChanges = response.data.batchChanges;
batchChangePaging = pagingService.nextPageUpdate(batchChanges, response.data.nextId, batchChangePaging);
if(batchChanges.length > 0 ){
$scope.batchChanges = batchChanges;
}
})
.catch(function (error){
handleError(error, 'dnsChangesService::getBatchChanges-failure');
2018-07-27 10:18:29 -04:00
});
};
$scope.getAllRequests = function(ignoreAccess){
$scope.ignoreAccess = ignoreAccess;
$scope.refreshBatchChanges();
}
$scope.cancelChange = function(batchChange) {
$scope.currentBatchChange = batchChange;
$("#cancel_batch_change").modal("show");
}
$scope.confirmCancel = function() {
batchChangePaging = pagingService.resetPaging(batchChangePaging);
$("#cancel_batch_change").modal("hide");
function success(response) {
var alert = utilityService.success('Successfully cancelled DNS Change', response, 'cancelBatchChange: cancelBatchChange successful');
$scope.alerts.push(alert);
$scope.refreshBatchChanges();
}
return dnsChangeService
.cancelBatchChange($scope.currentBatchChange.id)
.then(success)
.catch(function (error){
handleError(error, 'dnsChangesService::cancelBatchChange-failure');
});
};
$scope.cancelCancel = function() {
$("#cancel_batch_change").modal("hide");
$scope.currentBatchChange = null;
}
2019-08-21 14:17:59 -04:00
$scope.canCancelBatchChange = function(batchChange, accountName) {
return batchChange.approvalStatus == 'PendingReview' && accountName == batchChange.userName;
}
2023-11-14 16:20:54 +05:30
$("#dt-range-txt-box").on("click", function() {
$(".daterangepicker").addClass("dt-select-box");
});
$('input[name="dateTimeRange"]').daterangepicker({
timePicker: true,
timePickerSeconds: true,
startDate: yesterday,
endDate: now,
locale: {
format: 'YYYY-MM-DD HH:mm:ss'
}
}, function(start, end) {
$scope.filter.dateTimeRangeStart = start.format('YYYY-MM-DD HH:mm:ss');
$scope.filter.dateTimeRangeEnd = end.format('YYYY-MM-DD HH:mm:ss');
$scope.refreshBatchChanges();
});
2024-02-23 17:37:12 +05:30
$("div.daterangepicker").click( function(e) {
e.stopPropagation();
});
2018-07-27 10:18:29 -04:00
$timeout($scope.refreshBatchChanges, 0);
});
})();