<commit_before>import {_module} from "../apimanPlugin";
import angular = require("angular");
import {ContractSummaryBean} from "../model/contract.model";

_module.controller("Apiman.ApiContractsController",
    ['$q', '$scope', '$location', 'PageLifecycle', 'ApiEntityLoader', 'OrgSvcs', 'Logger', '$routeParams', 'Configuration', 'ContractService', '$uibModal',
    function ($q, $scope, $location, PageLifecycle, ApiEntityLoader, OrgSvcs, Logger, $routeParams, Configuration, ContractService, $uibModal) {
        var params = $routeParams;
        $scope.organizationId = params.org;
        $scope.tab = 'contracts';
        $scope.version = params.version;
        $scope.showMetrics = Configuration.ui.metrics;

        var getNextPage = function(successHandler, errorHandler) {
            var maxCount = 10;
            $scope.currentPage = $scope.currentPage + 1;

            OrgSvcs.query({ organizationId: params.org, entityType: 'apis', entityId: params.api, versionsOrActivity: 'versions', version: params.version, policiesOrActivity: 'contracts', page: $scope.currentPage, count: maxCount  }, function(contracts) {
               $scope.hasMore = contracts.length == maxCount;
               successHandler(contracts);
            }, errorHandler);
        };

        var pageData = ApiEntityLoader.getCommonData($scope, $location);

        pageData = angular.extend(pageData, {
            contracts: $q(function(resolve, reject) {
                $scope.currentPage = 0;
                getNextPage(resolve, reject);
            })
        });

        let handleApprovalError = function (err) {
            if (err !== 'cancel') {
                Logger.error('Error while approve/reject: {0}', err)
            } else {
                Logger.debug('Modal dismissed at: {0}', new Date());
            }
        }

        $scope.approveRequest = (contract: ContractSummaryBean) => {
            Logger.debug("Attempting to approve contract: {0}", contract);

            const options = {
                title: 'Confirm API Signup Request',
                message: 'Do you really want to approve this API Signup request?'
            };

            let modalInstance = $uibModal.open({
                animation: true,
                templateUrl: 'confirmModal.html',
                controller: 'ModalConfirmCtrl',
                resolve: {
                    options: function () {
                        return options;
                    }
                }
            });

            modalInstance.result
            .then(() => ContractService.approveContract(contract.contractId))
            .then(() => contract.status = 'Created')
            .catch((err) => handleApprovalError(err));
        };

        $scope.rejectRequest = (contract: ContractSummaryBean) => {
            Logger.debug("Attempting to reject contract: {0}", contract);

            const options = {
                title: 'Reject API Signup Request',
                message: 'Do you really want to reject this API Signup request?' +
                    '\nRejected contracts will be automatically deleted.' +
                    '\n\nYou can optionally pass a message to the user.',
                label: 'Rejection Message',
                initialValue: ''
            };

            let modalInstance = $uibModal.open({
                animation: true,
                templateUrl: 'getValueModal.html',
                controller: 'ModalGetValueCtrl',
                resolve: {
                    options: function () {
                        return options;
                    }
                }
            });

            modalInstance.result
                .then((rejectionReason) => ContractService.rejectContract(contract.contractId, rejectionReason))
                .then(() => contract.status = 'Rejected')
                .catch((err) => handleApprovalError(err));
        };

        $scope.getNextPage = getNextPage;

        PageLifecycle.loadPage('ApiContracts', 'apiView', pageData, $scope, function() {
            Logger.debug("::: is public: {0}", $scope.version.publicAPI);

            if ($scope.version.publicAPI) {
                Logger.debug("::: num plans: {0}", $scope.version.plans.length);
                if ($scope.version.plans.length == 0) {
                    $scope.isPublicOnly = true;
                }
            }

            PageLifecycle.setPageTitle('api-contracts', [ $scope.api.name ]);
        });
    }]);<commit_msg>feat(ui): add approval error page<commit_after>import {_module} from "../apimanPlugin";
import angular = require("angular");
import {ContractSummaryBean} from "../model/contract.model";

_module.controller("Apiman.ApiContractsController",
    ['$q', '$scope', '$location', 'PageLifecycle', 'ApiEntityLoader', 'OrgSvcs', 'Logger', '$routeParams', 'Configuration', 'ContractService', '$uibModal',
    function ($q, $scope, $location, PageLifecycle, ApiEntityLoader, OrgSvcs, Logger, $routeParams, Configuration, ContractService, $uibModal) {
        var params = $routeParams;
        $scope.organizationId = params.org;
        $scope.tab = 'contracts';
        $scope.version = params.version;
        $scope.showMetrics = Configuration.ui.metrics;

        var getNextPage = function(successHandler, errorHandler) {
            var maxCount = 10;
            $scope.currentPage = $scope.currentPage + 1;

            OrgSvcs.query({ organizationId: params.org, entityType: 'apis', entityId: params.api, versionsOrActivity: 'versions', version: params.version, policiesOrActivity: 'contracts', page: $scope.currentPage, count: maxCount  }, function(contracts) {
               $scope.hasMore = contracts.length == maxCount;
               successHandler(contracts);
            }, errorHandler);
        };

        var pageData = ApiEntityLoader.getCommonData($scope, $location);

        pageData = angular.extend(pageData, {
            contracts: $q(function(resolve, reject) {
                $scope.currentPage = 0;
                getNextPage(resolve, reject);
            })
        });

        let handleError = function (err) {
            if (err !== 'cancel') {
                Logger.error('Error while approve/reject: {0}', err)
                PageLifecycle.handleError(err);
            } else {
                Logger.debug('Modal dismissed at: {0}', new Date());
            }
        }

        $scope.approveRequest = (contract: ContractSummaryBean) => {
            Logger.debug("Attempting to approve contract: {0}", contract);

            const options = {
                title: 'Confirm API Signup Request',
                message: 'Do you really want to approve this API Signup request?'
            };

            let modalInstance = $uibModal.open({
                animation: true,
                templateUrl: 'confirmModal.html',
                controller: 'ModalConfirmCtrl',
                resolve: {
                    options: function () {
                        return options;
                    }
                }
            });

            modalInstance.result
            .then(() => ContractService.approveContract(contract.contractId))
            .then(() => contract.status = 'Created')
            .catch((err) => handleError(err));
        };

        $scope.rejectRequest = (contract: ContractSummaryBean) => {
            Logger.debug("Attempting to reject contract: {0}", contract);

            const options = {
                title: 'Reject API Signup Request',
                message: 'Do you really want to reject this API Signup request?' +
                    '\nRejected contracts will be automatically deleted.' +
                    '\n\nYou can optionally pass a message to the user.',
                label: 'Rejection Message',
                initialValue: ''
            };

            let modalInstance = $uibModal.open({
                animation: true,
                templateUrl: 'getValueModal.html',
                controller: 'ModalGetValueCtrl',
                resolve: {
                    options: function () {
                        return options;
                    }
                }
            });

            modalInstance.result
                .then((rejectionReason) => ContractService.rejectContract(contract.contractId, rejectionReason))
                .then(() => contract.status = 'Rejected')
                .catch((err) => handleError(err));
        };

        $scope.getNextPage = getNextPage;

        PageLifecycle.loadPage('ApiContracts', 'apiView', pageData, $scope, function() {
            Logger.debug("::: is public: {0}", $scope.version.publicAPI);

            if ($scope.version.publicAPI) {
                Logger.debug("::: num plans: {0}", $scope.version.plans.length);
                if ($scope.version.plans.length == 0) {
                    $scope.isPublicOnly = true;
                }
            }

            PageLifecycle.setPageTitle('api-contracts', [ $scope.api.name ]);
        });
    }]);
{'fraction_non_alphanumeric': 0.12259136212624584, 'fraction_numerical': 0.0024363233665559247, 'mean_word_length': 1.8552007587733164, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6099845', 'n_tokens_mistral': 2312, 'n_tokens_neox': 2188, 'n_words': 515}