<commit_before>/// <reference path="../../.tmp/typings/tsd.d.ts" />
/// <reference path="../util/sugar.ts" />

module vs.tools.fields {
'use strict';

	export interface IFieldsResource {
		fetch(fields?: string): ng.IPromise<any>;
		fetchHydrationStats(query: string): ng.IPromise<any>;
	}

	export class FieldsResource implements IFieldsResource {
		static refName = 'fieldsResource';

		fetch: (properties?: string) => any;
		fetchHydrationStats: (query: string) => any;
		ensureTagsFieldExist: (fields: Array<any>) => any;

		/* @ngInject */
		constructor(private sugar: any) {

      this.fetch = (fields?: any) => {
        var fl = (fields || 'name,stype,category,docs,disp_en,sortable,filterable,tableable,displayable,editable');
        return sugar.postForm('solr/fields/select', this.getFieldsParams(fl)).then((res: any) => {
          this.ensureTagsFieldExist(res.data.response.docs);
          return res.data.response.docs;
        });
      };

      this.ensureTagsFieldExist = (fields: Array<any>) => {
        var found = false;
        for (var i = fields.length - 1; i >= 0; i--) {
          if (fields[i].name === 'tag_tags') {
            found = true;
            break;
          }
        }

        if (!found) {
          fields.push({
            category: 'TEXT',
            disp_en: 'Tags',
            displayable: true,
            docs: 0,
            filterable: true,
            name: 'tag_tags',
            sortable: false,
            stype: 'string',
            tableable: false
          });
        }
      };<commit_msg>VG-4397 - field selector caching<commit_after>/// <reference path="../../.tmp/typings/tsd.d.ts" />
/// <reference path="../util/sugar.ts" />

module vs.tools.fields {
'use strict';

	export interface IFieldsResource {
		fetch(fields?: string): ng.IPromise<any>;
		fetchHydrationStats(query: string): ng.IPromise<any>;
	}

	export class FieldsResource implements IFieldsResource {
		static refName = 'fieldsResource';

		fetch: (properties?: string) => any;
		fetchHydrationStats: (query: string) => any;
		ensureTagsFieldExist: (fields: Array<any>) => any;

		/* @ngInject */
		constructor(private sugar: any) {

      this.fetch = (fields?: any) => {
        var fl = (fields || 'name,stype,category,docs,disp_en,sortable,filterable,tableable,displayable,editable');
        return sugar.postForm('solr/fields/select?rand=' + Math.random(), this.getFieldsParams(fl)).then((res: any) => {
          this.ensureTagsFieldExist(res.data.response.docs);
          return res.data.response.docs;
        });
      };

      this.ensureTagsFieldExist = (fields: Array<any>) => {
        var found = false;
        for (var i = fields.length - 1; i >= 0; i--) {
          if (fields[i].name === 'tag_tags') {
            found = true;
            break;
          }
        }

        if (!found) {
          fields.push({
            category: 'TEXT',
            disp_en: 'Tags',
            displayable: true,
            docs: 0,
            filterable: true,
            name: 'tag_tags',
            sortable: false,
            stype: 'string',
            tableable: false
          });
        }
      };
{'fraction_non_alphanumeric': 0.1532639545884579, 'fraction_numerical': 0.00315357931251971, 'mean_word_length': 2.1847389558232932, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 29, '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': '4202126', 'n_tokens_mistral': 991, 'n_tokens_neox': 953, 'n_words': 198}