<commit_before>'use strict';

/**
 * ContainerController controller for the view of a single container
 */
containerModule.controller('ContainerController',
    ['$scope', '$rootScope', '$state', '$stateParams', '$timeout', '$filter', 'containerService', 'fileSystemService', 'objectClassService', '$mdDialog', '$mdMedia',
        function ($scope, $rootScope, $state, $stateParams, $timeout, $filter, containerService, fileSystemService, objectClassService, $mdDialog, $mdMedia) {

            console.log("hello, ContainerController");

            /**
             * ****************************************************************
             * State
             *
             * ****************************************************************
             */



            $scope.isGetObjectsRequestPending = false;
            $scope.isAllDataLoaded = false;


            /**
             * ****************************************************************
             * Model
             *
             * ****************************************************************
             */


            /**
             *
             * contains all available metadata field names for use in the table
             * column selection. fields can come from: * filters * the document
             * class of the container
             *
             */


            $scope.availableMetadataFields = {"mgmt": ["retentiondate"]};
            $scope.availableInternalMetadataFields = ["bytes", "content_type", "last_modified", "hash"];

            $scope.selectedMetadataFields = [];
            $scope.selectedInternalMetadataFields = [];


            /**
             * contains the relevant information about the current container
             *
             * @type {{name: string, metadata: {objectClass: string,
			 *       objectCount: number}, metadataFields: Array, objects:
			 *       Array}}
             */
            $scope.container = {
                name: $stateParams.containerName,
                metadata: {
                    objectCount: 0
                },
                metadataFields: [],
                objects: [],
                isSdos: false,
                isMeta: $filter('isMetaContainer')($stateParams.containerName)
            };

            /**
             * the form model for the file upload
             *
             * @type {{file: null, retentionDate: null, metadata: {}}}
             */
            $scope.fileModel = {
                files: null,
                retentionDate: null,
                metadata: {}
            };


            /**
             * list of special metadata fields that are not part of the object
             * class, but shall possibly be shown in a column
             *
             * @type {Array}
             */
            $scope.specialMetadataFields = [
                {
                    headerKey: "date",
                    dateFormat: "medium"
                },
                {
                    headerKey: "last-modified",
                    dateFormat: "medium"
                },
                {
                    headerKey: "x-object-meta-mgmt-retentiondate",
                    dateFormat: "mediumDate"
                }
            ];

            /**
             * ****************************************************************
             * Model / Backend interaction
             *
             * ****************************************************************
             */


            /**
             * GET new objects from the container service
             *
             * @param {boolean}
             *            reload if true, the list will be reloaded from the
             *            beginning
             */
            $scope.getObjects = function (reload) {

                if ($scope.isGetObjectsRequestPending) return;
                $scope.isGetObjectsRequestPending = true;

                var limit = 0;
                var marker = "";
                if (reload) {
                    limit = Math.max($scope.container.objects.length, 30);
                    limit = Math.min(limit, 100);
                    marker = "";
                } else {
                    limit = 30;
                    marker = _.last($scope.container.objects) ? _.last($scope.container.objects).name : "";
                }


                containerService
                    .getObjects($scope.container, $scope.prefix, marker, limit)
                    .then(function (response) {

                        $scope.container.objects = reload ? response.objects : $scope.container.objects.concat(response.objects);
                        $scope.container.metadata = response.metadata;
                        parseMetadataIntoModel();

                        $scope.isGetObjectsRequestPending = false;

                        $scope.isAllDataLoaded = ($scope.container.objects.length == response.metadata.objectCount);

                        if ($scope.selectedMetadataFields.length > 0) {
                            getAllMissingDetails();
                        }
                    })
                    .catch(function (response) {
                        if (401 == response.status) {
                            $state.go('loginState', {noAuth: true});
                            return;
                        }
                        if (response.status === 404) {
                            $state.go('fileSystemState');
                            $rootScope.$broadcast('FlashMessage', {
                                "type": "danger",
                                "text": "Container \"" + $scope.container.name + "\" not found."
                            });
                        } else {
                            $rootScope.$broadcast('FlashMessage', {
                                "type": "danger",
                                "text": response.data
                            });
                        }
                        $scope.isGetObjectsRequestPending = false;
                    });
            };

            var parseObjectClassFieldsIntoColumnList = function () {
                var fields = [];
                for (var thisField of $scope.objectClassModel.metadataFields) {
                    fields.push(thisField.name);
                }
                $scope.availableMetadataFields['class-' + $scope.objectClassModel.name] = fields;
                //console.log($scope.availableMetadataFields);
            };

            var getObjectClassData = function () {
                fileSystemService.getContainerMetadata($scope.container)
                    .then(function (response) {
                        var objectClass = response['x-container-meta-objectclass'];
                        objectClassService.getObjectClass(objectClass)
                            .then(function (response) {
                                $scope.objectClassModel = $filter('jsonSchema')(response.schema, true);
                                parseObjectClassFieldsIntoColumnList();
                                //console.log($scope.objectClassModel);
                            });
                    });
            };

            var parseMetadataIntoModel = function () {
                //console.log($scope.container.metadata);
                var mdf = [];
                var mdfi = [];


                try {
                    mdfi = JSON.parse($scope.container.metadata['x-container-meta-mdfi']);
                } catch (err) {
                    //console.log(err);
                }

                try {
                    mdf = JSON.parse($scope.container.metadata['x-container-meta-mdf']);
                } catch (err) {
                    //console.log(err);<commit_msg>undefined objectclass fix<commit_after>'use strict';

/**
 * ContainerController controller for the view of a single container
 */
containerModule.controller('ContainerController',
    ['$scope', '$rootScope', '$state', '$stateParams', '$timeout', '$filter', 'containerService', 'fileSystemService', 'objectClassService', '$mdDialog', '$mdMedia',
        function ($scope, $rootScope, $state, $stateParams, $timeout, $filter, containerService, fileSystemService, objectClassService, $mdDialog, $mdMedia) {

            console.log("hello, ContainerController");

            /**
             * ****************************************************************
             * State
             *
             * ****************************************************************
             */



            $scope.isGetObjectsRequestPending = false;
            $scope.isAllDataLoaded = false;


            /**
             * ****************************************************************
             * Model
             *
             * ****************************************************************
             */


            /**
             *
             * contains all available metadata field names for use in the table
             * column selection. fields can come from: * filters * the document
             * class of the container
             *
             */


            $scope.availableMetadataFields = {"mgmt": ["retentiondate"]};
            $scope.availableInternalMetadataFields = ["bytes", "content_type", "last_modified", "hash"];

            $scope.selectedMetadataFields = [];
            $scope.selectedInternalMetadataFields = [];


            /**
             * contains the relevant information about the current container
             *
             * @type {{name: string, metadata: {objectClass: string,
			 *       objectCount: number}, metadataFields: Array, objects:
			 *       Array}}
             */
            $scope.container = {
                name: $stateParams.containerName,
                metadata: {
                    objectCount: 0
                },
                metadataFields: [],
                objects: [],
                isSdos: false,
                isMeta: $filter('isMetaContainer')($stateParams.containerName)
            };

            /**
             * the form model for the file upload
             *
             * @type {{file: null, retentionDate: null, metadata: {}}}
             */
            $scope.fileModel = {
                files: null,
                retentionDate: null,
                metadata: {}
            };


            /**
             * list of special metadata fields that are not part of the object
             * class, but shall possibly be shown in a column
             *
             * @type {Array}
             */
            $scope.specialMetadataFields = [
                {
                    headerKey: "date",
                    dateFormat: "medium"
                },
                {
                    headerKey: "last-modified",
                    dateFormat: "medium"
                },
                {
                    headerKey: "x-object-meta-mgmt-retentiondate",
                    dateFormat: "mediumDate"
                }
            ];

            /**
             * ****************************************************************
             * Model / Backend interaction
             *
             * ****************************************************************
             */


            /**
             * GET new objects from the container service
             *
             * @param {boolean}
             *            reload if true, the list will be reloaded from the
             *            beginning
             */
            $scope.getObjects = function (reload) {

                if ($scope.isGetObjectsRequestPending) return;
                $scope.isGetObjectsRequestPending = true;

                var limit = 0;
                var marker = "";
                if (reload) {
                    limit = Math.max($scope.container.objects.length, 30);
                    limit = Math.min(limit, 100);
                    marker = "";
                } else {
                    limit = 30;
                    marker = _.last($scope.container.objects) ? _.last($scope.container.objects).name : "";
                }


                containerService
                    .getObjects($scope.container, $scope.prefix, marker, limit)
                    .then(function (response) {

                        $scope.container.objects = reload ? response.objects : $scope.container.objects.concat(response.objects);
                        $scope.container.metadata = response.metadata;
                        parseMetadataIntoModel();

                        $scope.isGetObjectsRequestPending = false;

                        $scope.isAllDataLoaded = ($scope.container.objects.length == response.metadata.objectCount);

                        if ($scope.selectedMetadataFields.length > 0) {
                            getAllMissingDetails();
                        }
                    })
                    .catch(function (response) {
                        if (401 == response.status) {
                            $state.go('loginState', {noAuth: true});
                            return;
                        }
                        if (response.status === 404) {
                            $state.go('fileSystemState');
                            $rootScope.$broadcast('FlashMessage', {
                                "type": "danger",
                                "text": "Container \"" + $scope.container.name + "\" not found."
                            });
                        } else {
                            $rootScope.$broadcast('FlashMessage', {
                                "type": "danger",
                                "text": response.data
                            });
                        }
                        $scope.isGetObjectsRequestPending = false;
                    });
            };

            var parseObjectClassFieldsIntoColumnList = function () {
                var fields = [];
                for (var thisField of $scope.objectClassModel.metadataFields) {
                    fields.push(thisField.name);
                }
                $scope.availableMetadataFields['class-' + $scope.objectClassModel.name] = fields;
                //console.log($scope.availableMetadataFields);
            };

            var getObjectClassData = function () {
                fileSystemService.getContainerMetadata($scope.container)
                    .then(function (response) {
                        var objectClass = response['x-container-meta-objectclass'];
                        if (objectClass) {
                            objectClassService.getObjectClass(objectClass)
                                .then(function (response) {
                                    $scope.objectClassModel = $filter('jsonSchema')(response.schema, true);
                                    parseObjectClassFieldsIntoColumnList();
                                    //console.log($scope.objectClassModel);
                                });
                        }

                    });
            };

            var parseMetadataIntoModel = function () {
                //console.log($scope.container.metadata);
                var mdf = [];
                var mdfi = [];


                try {
                    mdfi = JSON.parse($scope.container.metadata['x-container-meta-mdfi']);
                } catch (err) {
                    //console.log(err);
                }

                try {
                    mdf = JSON.parse($scope.container.metadata['x-container-meta-mdf']);
                } catch (err) {
                    //console.log(err);
{'fraction_non_alphanumeric': 0.1460688428807316, 'fraction_numerical': 0.0020322621618188747, 'mean_word_length': 1.2023776223776224, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7485736', 'n_tokens_mistral': 3476, 'n_tokens_neox': 3155, 'n_words': 641}