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';
|
|
|
|
|
2019-11-04 11:00:14 -05:00
|
|
|
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 = [];
|
2019-08-13 12:10:11 -04:00
|
|
|
$scope.currentBatchChange;
|
2019-08-02 17:02:18 -04:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-11-04 11:00:14 -05:00
|
|
|
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) {
|
2019-11-04 11:00:14 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2024-10-09 12:20:41 +05:30
|
|
|
// Initialize tooltips after the view has rendered
|
|
|
|
$timeout(function() {
|
|
|
|
$('[data-toggle="tooltip"]').tooltip();
|
|
|
|
}, 0);
|
|
|
|
|
|
|
|
// Function to copy the ID to clipboard
|
|
|
|
$scope.copyToClipboard = function(copyText) {
|
|
|
|
utilityService.copyToClipboard(copyText);
|
|
|
|
// Trigger success alert using utilityService
|
2024-10-15 12:33:39 +05:30
|
|
|
var alert = utilityService.success('Successfully copied Batch ID to clipboard');
|
2024-10-09 12:20:41 +05:30
|
|
|
$scope.alerts.push(alert);
|
|
|
|
};
|
|
|
|
|
2018-07-27 10:18:29 -04:00
|
|
|
$scope.refreshBatchChanges = function() {
|
|
|
|
batchChangePaging = pagingService.resetPaging(batchChangePaging);
|
|
|
|
|
|
|
|
function success(response) {
|
|
|
|
batchChangePaging.next = response.data.nextId;
|
|
|
|
$scope.batchChanges = response.data.batchChanges;
|
2019-08-02 17:02:18 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-11-04 11:00:14 -05: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){
|
2019-11-04 11:00:14 -05:00
|
|
|
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){
|
2019-11-04 11:00:14 -05:00
|
|
|
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){
|
2019-11-04 11:00:14 -05:00
|
|
|
handleError(error, 'dnsChangesService::getBatchChanges-failure');
|
2018-07-27 10:18:29 -04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2019-08-02 17:02:18 -04:00
|
|
|
$scope.getAllRequests = function(ignoreAccess){
|
|
|
|
$scope.ignoreAccess = ignoreAccess;
|
|
|
|
$scope.refreshBatchChanges();
|
|
|
|
}
|
|
|
|
|
2019-08-13 12:10:11 -04:00
|
|
|
$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();
|
|
|
|
}
|
|
|
|
|
2019-11-04 11:00:14 -05:00
|
|
|
return dnsChangeService
|
2019-08-13 12:10:11 -04:00
|
|
|
.cancelBatchChange($scope.currentBatchChange.id)
|
|
|
|
.then(success)
|
|
|
|
.catch(function (error){
|
2019-11-04 11:00:14 -05:00
|
|
|
handleError(error, 'dnsChangesService::cancelBatchChange-failure');
|
2019-08-13 12:10:11 -04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$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);
|
|
|
|
});
|
|
|
|
})();
|