<commit_before>/**
 * Developer: <NAME>
 * Date: 23.07.2015
 * Copyright: 2009-2015 Comindware®
 *       All Rights Reserved
 *
 * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF Comindware
 *       The copyright notice above does not evidence any
 *       actual or intended publication of such source code.
 */

/* global define, require, Handlebars, Backbone, Marionette, $, _, Localizer */

define([
        'core/Meta',
        'core/utils/utilsApi',
        'core/collections/VirtualCollection',
        './views/ListView', './views/ScrollbarView', './views/EmptyListView', './views/EmptyGridView', './EventAggregator', './views/GridView', './views/GridColumnHeaderView'
    ],
    function (
        meta,
        utils,
        VirtualCollection,
        ListView, ScrollbarView, EmptyListView, EmptyGridView, EventAggregator, GridView, GridColumnHeaderView
    ) {
        'use strict';

        var factory = {
            getCellViewByDataType: function(type) {
                var result;

                switch (type) {
                case meta.objectPropertyTypes.STRING:
                    result = factory.getTextCellView();
                    break;
                case meta.objectPropertyTypes.INSTANCE:
                    result = factory.getReferenceCellView();
                    break;
                case meta.objectPropertyTypes.ACCOUNT:
                    result = factory.getUserCellView();
                    break;
                case meta.objectPropertyTypes.ENUM:
                    result = factory.getEnumCellView();
                    break;
                case meta.objectPropertyTypes.INTEGER:
                case meta.objectPropertyTypes.DOUBLE:
                case meta.objectPropertyTypes.DECIMAL:
                    result = factory.getNumberCellView();
                    break;
                case meta.objectPropertyTypes.DURATION:
                    result = factory.getDurationCellView();
                    break;
                case meta.objectPropertyTypes.BOOLEAN:
                    result = factory.getBooleanCellView();
                    break;
                case meta.objectPropertyTypes.DATETIME:
                    result = factory.getDateTimeCellView();
                    break;
                case meta.objectPropertyTypes.DOCUMENT:
                    result = factory.getDocumentCellView();
                    break;
                default:
                    utils.helpers.throwNotSupportedError('Data type' + type + 'is not supported');
                    break;
                }

                return result;
            },

            getTextCellView: function () {
                return factory.__getSimpleView('{{{highlightFragment value highlightedFragment}}}');
            },

            getReferenceCellView: function () {
                return factory.__getSimpleView('{{#if value}}{{#if value.name}}{{{highlightFragment value.name highlightedFragment}}}{{/if}}{{/if}}');
            },

            getUserCellView: function () {
                return factory.__getAccountView();
            },

            getEnumCellView: function () {
                return factory.__getEnumView();
            },

            getNumberCellView: function () {
                return factory.__getSimpleView('{{value}}');
            },

            getDurationCellView: function () {
                return factory.__getSimpleView('{{renderShortDuration value}}');
            },

            getBooleanCellView: function () {
                return factory.__getSimpleView(
                    "{{#if value}}{{localize 'CORE.GRID.CELLVIEWFACTORY.BOOLEANCELLVIEW.YES'}}{{/if}}" +
                    "{{#unless value}}{{localize 'CORE.GRID.CELLVIEWFACTORY.BOOLEANCELLVIEW.NO'}}{{/unless}}");
            },

            getDateTimeCellView: function () {
                return factory.__getSimpleView('{{#if value}}{{renderFullDate value}}{{/if}}');
            },

            getDocumentCellView: function () {
                return factory.__getDocumentView();
            },

            __getSimpleView: function (template, templateHelpers) {
                return Marionette.ItemView.extend({
                    template: Handlebars.compile(template),
                    modelEvents: {
                        'change:highlightedFragment': '__handleHighlightedFragmentChange'
                    },
                    __handleHighlightedFragmentChange: function () {
                        this.render();
                    },
                    className: 'grid-cell',
                    templateHelpers: templateHelpers
                });
            },

            __getAccountView: function () {
                return Marionette.ItemView.extend({
                    template: Handlebars.compile('{{text}}'),
                    templateHelpers: function () {
                        var value = this.model.get('value');
                        var text = '';
                        if (value && value.length > 0) {
                            text = _.chain(value).
                                map(function (item) {
                                    return {
                                        id: item.id,
                                        text: item.columns[0]
                                    };
                                }).
                                sortBy(function (member) {
                                    return member.text;
                                }).
                                reduce(function (memo, member) {
                                    if (memo) {
                                        return memo + ', ' + member.text;
                                    } else {
                                        return member.text;
                                    }
                                }, null).
                                value();
                        }

                        return {
                            text: text
                        };
                    },
                    modelEvents: {
                        'change:highlightedFragment': '__handleHighlightedFragmentChange'
                    },
                    __handleHighlightedFragmentChange: function () {
                        this.render();
                    },
                    className: 'grid-cell'
                });
            },

            __getDocumentView: function () {
                return Marionette.ItemView.extend({
                    template: Handlebars.compile('{{#each documents}}<a href="{{url}}">{{text}}</a>{{#unless @last}}, {{/unless}}{{/each}}'),

                    templateHelpers: function () {
                        var value = this.model.get('value');
                        var documents = [];
                        if (value && value.length > 0) {
                            documents = _.chain(value).
                                map(function (item) {<commit_msg>fixed bug where cell view of the list did not handled single-value user field fixed bug with wrong evaluation of process id<commit_after>/**
 * Developer: <NAME>
 * Date: 23.07.2015
 * Copyright: 2009-2015 Comindware®
 *       All Rights Reserved
 *
 * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF Comindware
 *       The copyright notice above does not evidence any
 *       actual or intended publication of such source code.
 */

/* global define, require, Handlebars, Backbone, Marionette, $, _, Localizer */

define([
        'core/Meta',
        'core/utils/utilsApi',
        'core/collections/VirtualCollection',
        './views/ListView', './views/ScrollbarView', './views/EmptyListView', './views/EmptyGridView', './EventAggregator', './views/GridView', './views/GridColumnHeaderView'
    ],
    function (
        meta,
        utils,
        VirtualCollection,
        ListView, ScrollbarView, EmptyListView, EmptyGridView, EventAggregator, GridView, GridColumnHeaderView
    ) {
        'use strict';

        var factory = {
            getCellViewByDataType: function(type) {
                var result;

                switch (type) {
                case meta.objectPropertyTypes.STRING:
                    result = factory.getTextCellView();
                    break;
                case meta.objectPropertyTypes.INSTANCE:
                    result = factory.getReferenceCellView();
                    break;
                case meta.objectPropertyTypes.ACCOUNT:
                    result = factory.getUserCellView();
                    break;
                case meta.objectPropertyTypes.ENUM:
                    result = factory.getEnumCellView();
                    break;
                case meta.objectPropertyTypes.INTEGER:
                case meta.objectPropertyTypes.DOUBLE:
                case meta.objectPropertyTypes.DECIMAL:
                    result = factory.getNumberCellView();
                    break;
                case meta.objectPropertyTypes.DURATION:
                    result = factory.getDurationCellView();
                    break;
                case meta.objectPropertyTypes.BOOLEAN:
                    result = factory.getBooleanCellView();
                    break;
                case meta.objectPropertyTypes.DATETIME:
                    result = factory.getDateTimeCellView();
                    break;
                case meta.objectPropertyTypes.DOCUMENT:
                    result = factory.getDocumentCellView();
                    break;
                default:
                    utils.helpers.throwNotSupportedError('Data type' + type + 'is not supported');
                    break;
                }

                return result;
            },

            getTextCellView: function () {
                return factory.__getSimpleView('{{{highlightFragment value highlightedFragment}}}');
            },

            getReferenceCellView: function () {
                return factory.__getSimpleView('{{#if value}}{{#if value.name}}{{{highlightFragment value.name highlightedFragment}}}{{/if}}{{/if}}');
            },

            getUserCellView: function () {
                return factory.__getAccountView();
            },

            getEnumCellView: function () {
                return factory.__getEnumView();
            },

            getNumberCellView: function () {
                return factory.__getSimpleView('{{value}}');
            },

            getDurationCellView: function () {
                return factory.__getSimpleView('{{renderShortDuration value}}');
            },

            getBooleanCellView: function () {
                return factory.__getSimpleView(
                    "{{#if value}}{{localize 'CORE.GRID.CELLVIEWFACTORY.BOOLEANCELLVIEW.YES'}}{{/if}}" +
                    "{{#unless value}}{{localize 'CORE.GRID.CELLVIEWFACTORY.BOOLEANCELLVIEW.NO'}}{{/unless}}");
            },

            getDateTimeCellView: function () {
                return factory.__getSimpleView('{{#if value}}{{renderFullDate value}}{{/if}}');
            },

            getDocumentCellView: function () {
                return factory.__getDocumentView();
            },

            __getSimpleView: function (template, templateHelpers) {
                return Marionette.ItemView.extend({
                    template: Handlebars.compile(template),
                    modelEvents: {
                        'change:highlightedFragment': '__handleHighlightedFragmentChange'
                    },
                    __handleHighlightedFragmentChange: function () {
                        this.render();
                    },
                    className: 'grid-cell',
                    templateHelpers: templateHelpers
                });
            },

            __getAccountView: function () {
                return Marionette.ItemView.extend({
                    template: Handlebars.compile('{{text}}'),
                    templateHelpers: function () {
                        var value = this.model.get('value');
                        var text = '';
                        if (value && value.length > 0) {
                            text = _.chain(value).
                                map(function (item) {
                                    return {
                                        id: item.id,
                                        text: item.columns[0]
                                    };
                                }).
                                sortBy(function (member) {
                                    return member.text;
                                }).
                                reduce(function (memo, member) {
                                    if (memo) {
                                        return memo + ', ' + member.text;
                                    } else {
                                        return member.text;
                                    }
                                }, null).
                                value();
                        }
                        else if (value.name) {
                            text = value.name
                        }

                        return {
                            text: text
                        };
                    },
                    modelEvents: {
                        'change:highlightedFragment': '__handleHighlightedFragmentChange'
                    },
                    __handleHighlightedFragmentChange: function () {
                        this.render();
                    },
                    className: 'grid-cell'
                });
            },

            __getDocumentView: function () {
                return Marionette.ItemView.extend({
                    template: Handlebars.compile('{{#each documents}}<a href="{{url}}">{{text}}</a>{{#unless @last}}, {{/unless}}{{/each}}'),

                    templateHelpers: function () {
                        var value = this.model.get('value');
                        var documents = [];
                        if (value && value.length > 0) {
                            documents = _.chain(value).
                                map(function (item) {
{'fraction_non_alphanumeric': 0.09748581833461727, 'fraction_numerical': 0.002661250787870299, 'mean_word_length': 1.1606899682251475, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2063696', 'n_tokens_mistral': 3247, 'n_tokens_neox': 2940, 'n_words': 588}