<commit_before>/*global define*/

define(function (require) {
    'use strict';

    var angular = require('angular'),
        utils = require('ng-admin/lib/utils'),
        Configurable = require('ng-admin/Main/component/service/config/Configurable'),
        Field = require('ng-admin/Main/component/service/config/Field'),
        DashboardView = require('ng-admin/Main/component/service/config/view/DashboardView'),
        ListView = require('ng-admin/Main/component/service/config/view/ListView'),
        CreateView = require('ng-admin/Main/component/service/config/view/CreateView'),
        EditView = require('ng-admin/Main/component/service/config/view/EditView'),
        DeleteView = require('ng-admin/Main/component/service/config/view/DeleteView');

    var config = {
        name: 'entity',
        label: 'My entity',
        order: null,
        dashboardView: null,
        listView: null,
        createView: null,
        editView: null,
        deleteView: null
    };

    /**
     * @param {String} entityName
     *
     * @constructor
     */
    function Entity(entityName) {
        this.values = {};
        this.mappedFields = {};
        this.config = angular.copy(config);
        this.config.name = entityName || 'entity';
        this.config.label = utils.camelCase(this.config.name);
        this.identifierField = new Field('id');
        this.initViews();
    }

    Configurable(Entity.prototype, config);

    /**
     * Returns the value of a fieldName
     *
     * @params {String} fieldName
     *
     * @returns {*}
     */
    Entity.prototype.getValue = function (fieldName) {
        return this.values[fieldName] !== undefined ? this.values[fieldName] : null;
    };

    /**
     * Set the value of a fieldName
     *
     * @params {String} fieldName
     * @params {*}      value
     *
     * @returns {Entity}
     */
    Entity.prototype.setValue = function (fieldName, value) {
        this.values[fieldName] = value;

        return this;
    };

    Entity.prototype.initViews = function() {
        this.config.dashboardView = new DashboardView().setEntity(this);
        this.config.listView = new ListView().setEntity(this);
        this.config.createView = new CreateView().setEntity(this);
        this.config.editView = new EditView().setEntity(this);
        this.config.deleteView = new DeleteView().setEntity(this);
    };

    /**
     * Returns one view by type
     *
     * @returns {View}
     */
    Entity.prototype.getViewByType = function getViewByType(type) {
        switch (type) {
            case 'DashboardView':
                return this.dashboardView();
            case 'ListView':
                return this.listView();
            case 'CreateView':
                return this.createView();
            case 'EditView':
                return this.editView();
            case 'DeleteView':
                return this.deleteView();
            default:
                throw new Error('Unkonwn view type ' + type);
        }
    };

    /**
     * Add (set) a view top the entity
     *
     * @deprecated access the view getter instead (e.g. `listView()`)
     */
    Entity.prototype.addView = function addView(view) {
        var supportedViewConstructors = ['DashboardView', 'ListView', 'CreateView', 'EditView', 'DeleteView'];
        if (supportedViewConstructors.indexOf(view.constructor.name) == -1) {
            throw new Error('Unkonwn view type ' + type);
        }
        var viewName = view.charAt(0).toLowercaseCase() + string.slice(1);
        view.setEntity(this);
        this[viewName](view);
        console.log('addView() is deprecated. Views are added by default, use ' + viewName + '() instead to retreive the view and customize it');
        return this;
    };

    /**
     * Set or get the identifier
     *<commit_msg>Fix undefined error<commit_after>/*global define*/

define(function (require) {
    'use strict';

    var angular = require('angular'),
        utils = require('ng-admin/lib/utils'),
        Configurable = require('ng-admin/Main/component/service/config/Configurable'),
        Field = require('ng-admin/Main/component/service/config/Field'),
        DashboardView = require('ng-admin/Main/component/service/config/view/DashboardView'),
        ListView = require('ng-admin/Main/component/service/config/view/ListView'),
        CreateView = require('ng-admin/Main/component/service/config/view/CreateView'),
        EditView = require('ng-admin/Main/component/service/config/view/EditView'),
        DeleteView = require('ng-admin/Main/component/service/config/view/DeleteView');

    var config = {
        name: 'entity',
        label: 'My entity',
        order: null,
        dashboardView: null,
        listView: null,
        createView: null,
        editView: null,
        deleteView: null
    };

    /**
     * @param {String} entityName
     *
     * @constructor
     */
    function Entity(entityName) {
        this.values = {};
        this.mappedFields = {};
        this.config = angular.copy(config);
        this.config.name = entityName || 'entity';
        this.config.label = utils.camelCase(this.config.name);
        this.identifierField = new Field('id');
        this.initViews();
    }

    Configurable(Entity.prototype, config);

    /**
     * Returns the value of a fieldName
     *
     * @params {String} fieldName
     *
     * @returns {*}
     */
    Entity.prototype.getValue = function (fieldName) {
        return this.values[fieldName] !== undefined ? this.values[fieldName] : null;
    };

    /**
     * Set the value of a fieldName
     *
     * @params {String} fieldName
     * @params {*}      value
     *
     * @returns {Entity}
     */
    Entity.prototype.setValue = function (fieldName, value) {
        this.values[fieldName] = value;

        return this;
    };

    Entity.prototype.initViews = function() {
        this.config.dashboardView = new DashboardView().setEntity(this);
        this.config.listView = new ListView().setEntity(this);
        this.config.createView = new CreateView().setEntity(this);
        this.config.editView = new EditView().setEntity(this);
        this.config.deleteView = new DeleteView().setEntity(this);
    };

    /**
     * Returns one view by type
     *
     * @returns {View}
     */
    Entity.prototype.getViewByType = function getViewByType(type) {
        switch (type) {
            case 'DashboardView':
                return this.dashboardView();
            case 'ListView':
                return this.listView();
            case 'CreateView':
                return this.createView();
            case 'EditView':
                return this.editView();
            case 'DeleteView':
                return this.deleteView();
            default:
                throw new Error('Unkonwn view type ' + type);
        }
    };

    /**
     * Add (set) a view top the entity
     *
     * @deprecated access the view getter instead (e.g. `listView()`)
     */
    Entity.prototype.addView = function addView(view) {
        var supportedViewConstructors = ['DashboardView', 'ListView', 'CreateView', 'EditView', 'DeleteView'];
        var viewName = view.constructor.name;
        if (supportedViewConstructors.indexOf(viewName) == -1) {
            throw new Error('Unkonwn view type ' + type);
        }
        var viewName = viewName.charAt(0).toLowerCase() + viewName.slice(1);
        view.setEntity(this);
        this[viewName](view);
        console.log('addView() is deprecated. Views are added by default, use ' + viewName + '() instead to retreive the view and customize it');
        return this;
    };

    /**
     * Set or get the identifier
     *
{'fraction_non_alphanumeric': 0.13055303717135086, 'fraction_numerical': 0.0007771014117342313, 'mean_word_length': 2.2054794520547945, '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': '4229760', 'n_tokens_mistral': 2169, 'n_tokens_neox': 2140, 'n_words': 455}