<commit_before>(function(angular){
    "use strict";
    angular.module("mfl.facilities.controllers.view", [
        "mfl.facilities.services"
    ])
    .controller("mfl.facilities.controllers.view.base", ["$scope",
        "$stateParams", "mfl.facilities.wrappers",
        "mfl.facilities.wrappers", function($scope, $stateParams, facilityApi){
            $scope.title = [
                {
                    icon: "fa-building",
                    name: "Facility Details"
                }
            ];
            $scope.action = [
                {
                    func : "ui-sref='facilities_view' " +
                            "has-permission='users.add_mfluser' ",
                    class: "action-btn action-btn-info action-btn-md",
                    color: "blue",
                    tipmsg: "Go Back",
                    icon: "fa-arrow-left"
                }
            ];
            facilityApi.facilities.get($stateParams.facilityId)
            .success(function(data){
                $scope.facility = data;
            }).error(function(error){
                $scope.alert = facilityApi.utils.getError(error);
            });
        }]
        )
    .controller("mfl.facilities.controllers.view.approve", ["$scope",
        "$stateParams", "mfl.facilities.wrappers",
        "mfl.facilities.wrappers", function($scope, $stateParams, facilityApi){
            $scope.title = [
                {
                    icon: "fa-check",
                    name: "Approve Facility"
                }
            ];
            $scope.action = [
                {
                    func : "ui-sref='facilities' " +
                            "has-permission='users.add_mfluser' ",
                    class: "action-btn action-btn-info action-btn-md",
                    color: "blue",
                    tipmsg: "Go Back",
                    icon: "fa-arrow-left"
                }
            ];
            $scope.facility = {facilityId: $stateParams.facilityId};
            var promise = facilityApi.facilities.get($stateParams.facilityId);
            facilityApi.utils.resolvePromise($scope, $scope, "facility_data", promise);
            $scope.facility_approvals = [];
            facilityApi.utils.resolvePromise(
                $scope, $scope, "facility_approvals",
                facilityApi.facility_approval.filter({facility: $stateParams.facilityId})
            );
            $scope.approveFacility = function(approval){
                approval.facility = $stateParams.facilityId;
                facilityApi.facility_approval.create(facilityApi.utils.cleanFormData(approval))
                .success(function(data){
                    $scope.approval = {
                        comment: ""
                    };
                    $scope.facility_approvals.push(data);
                }).error(function(error){
                    $scope.alert = facilityApi.utils.getError(error);
                });
            };
        }]
        )

    .controller("mfl.facilities.controllers.view.add_unit", ["$scope",
        "$stateParams", "mfl.facilities.wrappers",
        "mfl.facilities.wrappers", function($scope, $stateParams, facilityApi){
            $scope.title = [
                {
                    icon: "fa-plus",
                    name: "Add Facility Unit"
                }
            ];
            $scope.facility = $stateParams.facilityId;
            $scope.action = [
                {
                    func : "ui-sref='facilities' " +
                            "has-permission='users.add_mfluser' ",
                    class: "action-btn action-btn-info action-btn-md",
                    color: "blue",
                    tipmsg: "Go Back",
                    icon: "fa-arrow-left"
                }
            ];
            $scope.facility = {facilityId: $stateParams.facilityId};
            var promise = facilityApi.facilities.get($stateParams.facilityId);
            facilityApi.utils.resolvePromise($scope, $scope, "facility_data", promise);
            $scope.getOptionsData = {
                getData: function(api, callback, what){
                    api.list()
                    .success(function(data){
                        callback(data[what]);
                    }).error(function(error){
                        callback([]);
                        $scope.alert = error.error;
                    });
                },
                regulatingBody: function(callback){
                    $scope.getOptionsData.getData(
                        facilityApi.regulating_body, callback, "results");
                },
                regulationStatus: function(callback){
                    $scope.getOptionsData.getData(
                        facilityApi.regulation_status, callback, "results");
                }

            };
            $scope.facility_units = [];
            facilityApi.utils.resolvePromise(
                $scope, $scope, "facility_units",
                facilityApi.facility_unit.filter({facility: $stateParams.facilityId})
            );
            $scope.saveFacilityUnit = function(unit){
                unit.facility = $stateParams.facilityId;
                facilityApi.facility_unit.create(facilityApi.utils.cleanFormData(unit))
                .success(function(data){
                    $scope.facility_units.push(data);
                }).error(function(error){
                    $scope.alert = facilityApi.utils.getError(error);
                });
            };
        }]
        )
    .controller("mfl.facilities.controllers.view.upgrade", ["$scope",
        "$stateParams", "mfl.facilities.wrappers",
        "mfl.facilities.wrappers", function($scope, $stateParams, facilityApi){
            $scope.title = [
                {
                    icon: "fa-up",
                    name: "Upgrade Facility"
                }
            ];
            $scope.action = [
                {
                    func : "ui-sref='facilities' " +
                            "has-permission='users.add_mfluser' ",
                    class: "action-btn action-btn-info action-btn-md",
                    color: "blue",
                    tipmsg: "Go Back",
                    icon: "fa-arrow-left"
                }
            ];
            $scope.facility = {facilityId: $stateParams.facilityId};
            var promise = facilityApi.facilities.get($stateParams.facilityId);
            facilityApi.utils.resolvePromise($scope, $scope, "facility_data", promise);
            $scope.getOptionsData = {
                getData: function(callback, what){
                    facilityApi.filterOptions.filter({fields: what})
                    .success(function(data){
                        callback(data[what]);
                    }).error(function(error){
                        callback([]);
                        $scope.alert = facilityApi.utils.getError(error);
                    });
                },
                facilityType: function(callback){
                    $scope.getOptionsData.getData(callback, "facility_type");
                }
            };

            $scope.facility_upgrades = [];
            facilityApi.facility_upgrade.filter({facility: $stateParams.facilityId})
            .success(function(data){
                $scope.facility_upgrades = data.results;
            }).error(function(error){
                $scope.alert = facilityApi.utils.getError(error);
            });
            $scope.upgradeFacility = function(upgrade){
                upgrade.facility = $stateParams.facilityId;
                var patch_data = {
                    facility_type: facilityApi.utils.cleanFormData(upgrade.facility_type).id
                };
                facilityApi.facilities.update($stateParams.facilityId, patch_data)
                .success(function(){
                    facilityApi.facility_upgrade.create(facilityApi.utils.cleanFormData(upgrade))
                    .success(function(data){
                        $scope.facility_upgrades.push(data);
                        $scope.upgrade = {
                            reason: "",
                            is_confirmed: false,
                            is_cancelled: false
                        };
                    }).error(function(error){
                        $scope.alert = facilityApi.utils.getError(error);
                    });<commit_msg>facility upgrade: minor fixes<commit_after>(function(angular){
    "use strict";
    angular.module("mfl.facilities.controllers.view", [
        "mfl.facilities.services"
    ])
    .controller("mfl.facilities.controllers.view.base", ["$scope",
        "$stateParams", "mfl.facilities.wrappers",
        "mfl.facilities.wrappers", function($scope, $stateParams, facilityApi){
            $scope.title = [
                {
                    icon: "fa-building",
                    name: "Facility Details"
                }
            ];
            $scope.action = [
                {
                    func : "ui-sref='facilities_view' " +
                            "has-permission='users.add_mfluser' ",
                    class: "action-btn action-btn-info action-btn-md",
                    color: "blue",
                    tipmsg: "Go Back",
                    icon: "fa-arrow-left"
                }
            ];
            facilityApi.facilities.get($stateParams.facilityId)
            .success(function(data){
                $scope.facility = data;
            }).error(function(error){
                $scope.alert = facilityApi.utils.getError(error);
            });
        }]
        )
    .controller("mfl.facilities.controllers.view.approve", ["$scope",
        "$stateParams", "mfl.facilities.wrappers",
        "mfl.facilities.wrappers", function($scope, $stateParams, facilityApi){
            $scope.title = [
                {
                    icon: "fa-check",
                    name: "Approve Facility"
                }
            ];
            $scope.action = [
                {
                    func : "ui-sref='facilities' " +
                            "has-permission='users.add_mfluser' ",
                    class: "action-btn action-btn-info action-btn-md",
                    color: "blue",
                    tipmsg: "Go Back",
                    icon: "fa-arrow-left"
                }
            ];
            $scope.facility = {facilityId: $stateParams.facilityId};
            var promise = facilityApi.facilities.get($stateParams.facilityId);
            facilityApi.utils.resolvePromise($scope, $scope, "facility_data", promise);
            $scope.facility_approvals = [];
            facilityApi.utils.resolvePromise(
                $scope, $scope, "facility_approvals",
                facilityApi.facility_approval.filter({facility: $stateParams.facilityId})
            );
            $scope.approveFacility = function(approval){
                approval.facility = $stateParams.facilityId;
                facilityApi.facility_approval.create(facilityApi.utils.cleanFormData(approval))
                .success(function(data){
                    $scope.approval = {
                        comment: ""
                    };
                    $scope.facility_approvals.push(data);
                }).error(function(error){
                    $scope.alert = facilityApi.utils.getError(error);
                });
            };
        }]
        )

    .controller("mfl.facilities.controllers.view.add_unit", ["$scope",
        "$stateParams", "mfl.facilities.wrappers",
        "mfl.facilities.wrappers", function($scope, $stateParams, facilityApi){
            $scope.title = [
                {
                    icon: "fa-plus",
                    name: "Add Facility Unit"
                }
            ];
            $scope.facility = $stateParams.facilityId;
            $scope.action = [
                {
                    func : "ui-sref='facilities' " +
                            "has-permission='users.add_mfluser' ",
                    class: "action-btn action-btn-info action-btn-md",
                    color: "blue",
                    tipmsg: "Go Back",
                    icon: "fa-arrow-left"
                }
            ];
            $scope.facility = {facilityId: $stateParams.facilityId};
            var promise = facilityApi.facilities.get($stateParams.facilityId);
            facilityApi.utils.resolvePromise($scope, $scope, "facility_data", promise);
            $scope.getOptionsData = {
                getData: function(api, callback, what){
                    api.list()
                    .success(function(data){
                        callback(data[what]);
                    }).error(function(error){
                        callback([]);
                        $scope.alert = error.error;
                    });
                },
                regulatingBody: function(callback){
                    $scope.getOptionsData.getData(
                        facilityApi.regulating_body, callback, "results");
                },
                regulationStatus: function(callback){
                    $scope.getOptionsData.getData(
                        facilityApi.regulation_status, callback, "results");
                }

            };
            $scope.facility_units = [];
            facilityApi.utils.resolvePromise(
                $scope, $scope, "facility_units",
                facilityApi.facility_unit.filter({facility: $stateParams.facilityId})
            );
            $scope.saveFacilityUnit = function(unit){
                unit.facility = $stateParams.facilityId;
                facilityApi.facility_unit.create(facilityApi.utils.cleanFormData(unit))
                .success(function(data){
                    $scope.facility_units.push(data);
                }).error(function(error){
                    $scope.alert = facilityApi.utils.getError(error);
                });
            };
        }]
        )
    .controller("mfl.facilities.controllers.view.upgrade", ["$scope",
        "$stateParams", "mfl.facilities.wrappers",
        "mfl.facilities.wrappers", function($scope, $stateParams, facilityApi){
            $scope.title = [
                {
                    icon: "fa-up",
                    name: "Upgrade Facility"
                }
            ];
            $scope.action = [
                {
                    func : "ui-sref='facilities' " +
                            "has-permission='users.add_mfluser' ",
                    class: "action-btn action-btn-info action-btn-md",
                    color: "blue",
                    tipmsg: "Go Back",
                    icon: "fa-arrow-left"
                }
            ];
            $scope.facility = {facilityId: $stateParams.facilityId};
            var promise = facilityApi.facilities.get($stateParams.facilityId);
            facilityApi.utils.resolvePromise($scope, $scope, "facility_data", promise);
            $scope.getOptionsData = {
                getData: function(callback, what){
                    facilityApi.filterOptions.filter({fields: what})
                    .success(function(data){
                        callback(data[what]);
                    }).error(function(error){
                        callback([]);
                        $scope.alert = facilityApi.utils.getError(error);
                    });
                },
                facilityType: function(callback){
                    $scope.getOptionsData.getData(callback, "facility_type");
                }
            };

            $scope.facility_upgrades = [];
            facilityApi.utils.resolvePromise(
                $scope, $scope, "facility_upgrades",
                facilityApi.facility_upgrade.filter({facility: $stateParams.facilityId})
            );
            $scope.upgradeFacility = function(upgrade){
                upgrade.facility = $stateParams.facilityId;
                var patch_data = {
                    facility_type: facilityApi.utils.cleanFormData(upgrade.facility_type).id
                };
                facilityApi.facilities.update($stateParams.facilityId, patch_data)
                .success(function(){
                    facilityApi.facility_upgrade.create(facilityApi.utils.cleanFormData(upgrade))
                    .success(function(data){
                        $scope.facility_upgrades.push(data);
                        $scope.upgrade = {
                            reason: "",
                            is_confirmed: false,
                            is_cancelled: false
                        };
                    }).error(function(error){
                        $scope.alert = facilityApi.utils.getError(error);
                    });
{'fraction_non_alphanumeric': 0.11628598620033309, 'fraction_numerical': 0.0, 'mean_word_length': 1.3066264233776923, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6073548', 'n_tokens_mistral': 4328, 'n_tokens_neox': 4133, 'n_words': 539}