<commit_before>'use strict';
var app = angular.module('com.module.dwDomainItems');

app.controller('DomainItemsCtrl', function($scope, $state, $stateParams, DwDomain, DwDomainItem, DwDomainEntityType, DomainItemsService, gettextCatalog, AppAuth) {

    //Put the currentUser in $scope for convenience
    $scope.currentUser = AppAuth.currentUser;
    $scope.domains = [];
    $scope.entityTypes = [];

    $scope.domainItem = {};
    $scope.formFields = [{
        key: 'id',
        type: 'input',
        templateOptions: {
            label: gettextCatalog.getString('id'),
            disabled: true
        }
    }, {
        key: 'dwDomainId',
        type: 'select',
        templateOptions: {
            label: gettextCatalog.getString('Domain'),
            options: $scope.domains,
            valueProp: 'id',
            labelProp: 'name',
            required: true,
            disabled: false
        }
    }, {
        key: 'dwDomainEntityTypeId',
        type: 'select',
        templateOptions: {
            label: gettextCatalog.getString('Domain Entity Type'),
            options: $scope.entityTypes,
            valueProp: 'id',
            labelProp: 'name',
            required: true,
            disabled: false
        }
    },{
        key: 'itemValue',
        type: 'input',
        templateOptions: {
            label: gettextCatalog.getString('Value'),
            required: true
        }
    },{
        key: 'coreItem',
        type: 'checkbox',
        templateOptions: {
            label: gettextCatalog.getString('Core Item?'),
            required: false
        }
    }];

    $scope.delete = function(id) {
        DomainItemsService.deleteDomainItem(id, function() {
            $scope.safeDisplayeddomainItems = DomainItemsService.getDomainItems();
            $state.go('^.list');
        });
    };

    $scope.onSubmit = function() {
        DomainItemsService.upsertDomainItem($scope.domainItem, function() {
            $scope.safeDisplayeddomainItems = DomainItemsService.getDomainItems();
            $state.go('^.list');
        });
    };

    $scope.loading = true;
    DwDomainItem.find({filter: {include: ['domain','domainEntityType']}}).$promise
        .then(function (allDomainItems) {
            $scope.safeDisplayeddomainItems = allDomainItems;
            $scope.displayedDomainItems = [].concat($scope.safeDisplayeddomainItems);
        })
        .catch(function (err) {
            console.log(err);
        })
        .then(function () {
            $scope.loading = false;
        });

    DwDomain.find({filter: {include: []}}).$promise
        .then(function (allDomains) {
            for (var i = 0; i < allDomains.length; ++i) {
                $scope.domains.push({
                    value: allDomains[i].name,
                    name: allDomains[i].name + " - " + allDomains[i].description,
                    id: allDomains[i].id
                });
            }
        })
        .catch(function (err) {
            console.log(err);
        })
        .then(function () {
        }
    );

    DwDomainEntityType.find({filter: {include: []}}).$promise
        .then(function (allEntityTypes) {
            for (var i = 0; i < allEntityTypes.length; ++i) {
                $scope.entityTypes.push({
                    value: allEntityTypes[i].name,
                    name: allEntityTypes[i].name + " - " + allEntityTypes[i].description,
                    id: allEntityTypes[i].id
                });
            }
        })
        .catch(function (err) {
            console.log(err);
        })
        .then(function () {
        }
    );

    if ($stateParams.id) {
        $scope.loading = true;
        DwDomainItem.findOne({
            filter: {
                where: {
                    id: $stateParams.id
                },
                include: ['domain','domainEntityType']
            }
        }).$promise
            .then(function (domain) {
                $scope.domainItem = domain;
            });
        $scope.loading = false;
    } else {
        $scope.domainItem = {};
    }

});
<commit_msg>domain entitytype dropdown on form now driven by domain<commit_after>'use strict';
var app = angular.module('com.module.dwDomainItems');

app.controller('DomainItemsCtrl', function($scope, $state, $stateParams, DwDomain, DwDomainItem, DwDomainEntityType, DomainItemsService, gettextCatalog, AppAuth) {

    //Put the currentUser in $scope for convenience
    $scope.currentUser = AppAuth.currentUser;
    $scope.domains = [];
    $scope.entityTypes = [];

    $scope.domainItem = {};
    $scope.formFields = [{
        key: 'id',
        type: 'input',
        templateOptions: {
            label: gettextCatalog.getString('id'),
            disabled: true
        }
    }, {
        key: 'dwDomainId',
        type: 'select',
        templateOptions: {
            label: gettextCatalog.getString('Domain'),
            options: $scope.domains,
            valueProp: 'id',
            labelProp: 'name',
            required: true,
            disabled: false,
            onChange: function($viewValue){
                $scope.loadEntityTypes($viewValue);
            }
        }
    }, {
        key: 'dwDomainEntityTypeId',
        type: 'select',
        expressionProperties: {
            // This watches for form changes and enables/disables the entity type dropdown as necessary
            'templateOptions.disabled': function () {
                return $scope.entityTypes.length<=0;
            }
        },
        templateOptions: {
            label: gettextCatalog.getString('Domain Entity TYpe'),
            options: $scope.entityTypes,
            valueProp: 'id',
            labelProp: 'name',
            required: true,
            disabled: false
        }
    },{
        key: 'itemValue',
        type: 'input',
        templateOptions: {
            label: gettextCatalog.getString('Value'),
            required: true
        }
    },{
        key: 'coreItem',
        type: 'checkbox',
        templateOptions: {
            label: gettextCatalog.getString('Core Item?'),
            required: false
        }
    }];

    $scope.loadEntityTypes = function(domainId){
        //Populate entityTypes from the domains for the given domain
        $scope.entityTypes.length=0;
        $scope.domains.forEach(function (domain){
            if (domain.id == domainId){
                if( domain.domainEntityTypes) {
                    for (var i = 0; i < domain.domainEntityTypes.length; ++i) {
                        $scope.entityTypes.push({
                            value: domain.domainEntityTypes[i].name,
                            name: domain.domainEntityTypes[i].name,
                            id: domain.domainEntityTypes[i].id
                        });
                    }
                } else {
                    $scope.entityTypes.length =0;
                }
            }
        });
    };

    $scope.delete = function(id) {
        DomainItemsService.deleteDomainItem(id, function() {
            $scope.safeDisplayeddomainItems = DomainItemsService.getDomainItems();
            $state.go('^.list');
        });
    };

    $scope.onSubmit = function() {
        DomainItemsService.upsertDomainItem($scope.domainItem, function() {
            $scope.safeDisplayeddomainItems = DomainItemsService.getDomainItems();
            $state.go('^.list');
        });
    };

    $scope.loading = true;
    DwDomainItem.find({filter: {include: ['domain','domainEntityType']}}).$promise
        .then(function (allDomainItems) {
            $scope.safeDisplayeddomainItems = allDomainItems;
            $scope.displayedDomainItems = [].concat($scope.safeDisplayeddomainItems);
        })
        .catch(function (err) {
            console.log(err);
        })
        .then(function () {
            $scope.loading = false;
        });

    DwDomain.find({filter: {include: ['domainEntityTypes']}}).$promise
        .then(function (allDomains) {
            $scope.domains.length=0;
            for (var i = 0; i < allDomains.length; ++i) {
                $scope.domains.push({
                    value: allDomains[i].name,
                    name: allDomains[i].name + " - " + allDomains[i].description,
                    id: allDomains[i].id,
                    domainEntityTypes: allDomains[i].domainEntityTypes
                });
            }
        })
        .catch(function (err) {
            console.log(err);
        })
        .then(function () {
        }
    );

    if ($stateParams.id) {
        $scope.loading = true;
        DwDomainItem.findOne({
            filter: {
                where: {
                    id: $stateParams.id
                },
                include: ['domain','domainEntityType']
            }
        }).$promise
            .then(function (domain) {
                $scope.domainItem = domain;

                $scope.entityTypes.push({
                    value: domain.domainEntityType.name,
                    name: domain.domainEntityType.name,
                    id: domain.domainEntityType.id
                });
            });
        $scope.loading = false;
    } else {
        $scope.domainItem = {};
    }

});

{'fraction_non_alphanumeric': 0.12840466926070038, 'fraction_numerical': 0.0008646779074794639, 'mean_word_length': 1.6079481397970687, 'pattern_counts': {'":': 0, '<': 8, '<?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': '417266', 'n_tokens_mistral': 2523, 'n_tokens_neox': 2435, 'n_words': 433}