<commit_before>
<template>
  <span v-if="multiple">
    <MultiSelectDropdown v-model="inputValue" :list-source="ddListSource" :disabled="disabled" />
  </span>
  <span v-else>
    <Dropdown v-model="inputValue" :list-source="ddListSource" :disabled="disabled" />
  </span>
</template>

<script>
import Dropdown from '@/common/components/Dropdown.vue';
import MultiSelectDropdown from '@/common/components/MultiSelectDropdown.vue';

import http from '@/common/services/HttpClient.js';
import util from '@/common/services/Util.js';
import exprUtil from '@/common/services/ExpressionUtil.js';

export default {
  props: ['modelValue', 'selectProp', 'listSource', 'context', 'multiple', 'disabled'],

  components: {
    Dropdown,
    MultiSelectDropdown
  },

  data() {
    return {
      ddListSource: {
        loadFn: async (opts) => {
          let cache = (this.context && this.context._formCache) || {};
          cache = cache['user-dropdown'] = cache['user-dropdown'] || {};

          opts = opts || {maxResults: 100};
          if (opts.value || opts.value == 0) {
            let id = parseInt(opts.value);
            if (!isNaN(id)) {
              if (!cache[id]) {
                cache[id] = await http.get('users/' + id);
              }

              return [cache[id]];
            }
          }

          let params = Object.assign({searchString: opts.query || ''}, opts || {maxResults: 100});
          let ls = this.listSource || {};
          let qp = ls.queryParams || {};
          if (qp.static) {
            Object.keys(qp.static).forEach(name => params[name] = qp.static[name]);
          }

          if (qp.dynamic && this.context) {
            Object.keys(qp.dynamic).forEach(name => params[name] = exprUtil.eval(this.context, qp.dynamic[name]));
          }

          if (this.listAll) {
            params.listAll = true;
          }

          const qs = util.queryString(params);
          if (!cache[qs]) {
            cache[qs] = await http.get('users', params);
          }

          return cache[qs];
        },
        selectProp: this.selectProp || (this.listSource && this.listSource.selectProp),
        displayProp: (user) => user.firstName + ' ' + user.lastName
      }
    }
  },

  computed: {
    inputValue: {
      get() {
        if (this.modelValue != null && !isNaN(this.modelValue)) {
          return +this.modelValue;
        }

        return this.modelValue;
      },

      set(value) {
        this.$emit('update:modelValue', value);
      }
    }
  }
}
</script>
<commit_msg>User dropdown widget fixes for use in the table form using material alike look and feel.<commit_after>
<template>
  <span v-if="multiple">
    <MultiSelectDropdown v-model="inputValue" :list-source="ddListSource" :disabled="disabled"
      :md-type="$attrs['md-type']" />
  </span>
  <span v-else>
    <Dropdown v-model="inputValue" :list-source="ddListSource" :disabled="disabled"
      :md-type="$attrs['md-type']" />
  </span>
</template>

<script>
import Dropdown from '@/common/components/Dropdown.vue';
import MultiSelectDropdown from '@/common/components/MultiSelectDropdown.vue';

import http from '@/common/services/HttpClient.js';
import util from '@/common/services/Util.js';
import exprUtil from '@/common/services/ExpressionUtil.js';

export default {
  props: ['modelValue', 'selectProp', 'listSource', 'context', 'multiple', 'disabled'],

  components: {
    Dropdown,
    MultiSelectDropdown
  },

  data() {
    return {
      ddListSource: {
        loadFn: async (opts) => {
          let cache = (this.context && this.context._formCache) || {};
          cache = cache['user-dropdown'] = cache['user-dropdown'] || {};

          opts = opts || {maxResults: 100};
          if (opts.value || opts.value == 0) {
            let id = parseInt(opts.value);
            if (!isNaN(id)) {
              if (!cache[id]) {
                cache[id] = await http.get('users/' + id);
              }

              return [cache[id]];
            }
          }

          let params = Object.assign({searchString: opts.query || ''}, opts || {maxResults: 100});
          let ls = this.listSource || {};
          let qp = ls.queryParams || {};
          if (qp.static) {
            Object.keys(qp.static).forEach(name => params[name] = qp.static[name]);
          }

          if (qp.dynamic && this.context) {
            Object.keys(qp.dynamic).forEach(name => params[name] = exprUtil.eval(this.context, qp.dynamic[name]));
          }

          if (this.listAll) {
            params.listAll = true;
          }

          const qs = util.queryString(params);
          if (!cache[qs]) {
            cache[qs] = await http.get('users', params);
          }

          return cache[qs];
        },
        selectProp: this.selectProp || (this.listSource && this.listSource.selectProp),
        displayProp: (user) => user.firstName + ' ' + user.lastName
      }
    }
  },

  computed: {
    inputValue: {
      get() {
        if (this.modelValue != null && !isNaN(this.modelValue)) {
          return +this.modelValue;
        }

        return this.modelValue;
      },

      set(value) {
        this.$emit('update:modelValue', value);
      }
    }
  }
}
</script>

{'fraction_non_alphanumeric': 0.16095693779904308, 'fraction_numerical': 0.002679425837320574, 'mean_word_length': 2.1846435100548445, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 31, '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': '4140943', 'n_tokens_mistral': 1600, 'n_tokens_neox': 1553, 'n_words': 311}