<commit_before>/*!
 Copyright (C) 2017 Google Inc.
 Licensed under http://www.apache.org/licenses/LICENSE-2.0 <see LICENSE file>
 */

(function (can, GGRC, CMS) {
  'use strict';

  var defaultOrderBy = 'created_at';

  can.Component.extend({
    tag: 'related-objects',
    viewModel: {
      isLoading: false,
      baseInstance: null,
      relatedObjects: [],
      relatedItemsType: '@',
      orderBy: '@',
      paging: {
        current: 1,
        pageSize: 5,
        pageSizeSelect: [5, 10, 15]
      },
      getParams: function () {
        var id = this.attr('baseInstance.id');
        var type = this.attr('baseInstance.type');
        var relatedType = this.attr('relatedItemsType');
        var page = this.attr('paging');
        var orderBy = this.attr('orderBy') || defaultOrderBy;
        var params = {};
        var first;
        var last;

        if (page.current && page.pageSize) {
          first = (page.current - 1) * page.pageSize;
          last = page.current * page.pageSize;
        }
        params.data = [{
          limit: [first, last],
          object_name: relatedType,
          order_by: [{name: orderBy, desc: true}],
          filters: {
            expression: {
              object_name: type,
              op: {name: 'similar'},
              ids: [id]
            }
          }
        }];
        return params;
      },
      updatePaging: function (total) {
        var count = Math.ceil(total / this.attr('paging.pageSize'));
        this.attr('paging.total', total);
        this.attr('paging.count', count);
      },
      loadRelatedItems: function () {
        var dfd = can.Deferred();
        var params = this.getParams();
        this.attr('isLoading', true);
        GGRC.Utils.QueryAPI
          .makeRequest(params)
          .done(function (responseArr) {
            var relatedType = this.attr('relatedItemsType');
            var data = responseArr[0];
            var values = data[relatedType].values;
            var result = values.map(function (item) {
              item.instance = new CMS.Models[relatedType](item);<commit_msg>Modify Related Objects Component to use 'relevant' operation type in case passed Instance is not Assessment<commit_after>/*!
 Copyright (C) 2017 Google Inc.
 Licensed under http://www.apache.org/licenses/LICENSE-2.0 <see LICENSE file>
 */

(function (can, GGRC, CMS) {
  'use strict';

  var defaultOrderBy = 'created_at';

  can.Component.extend({
    tag: 'related-objects',
    viewModel: {
      isLoading: false,
      baseInstance: null,
      relatedObjects: [],
      relatedItemsType: '@',
      orderBy: '@',
      paging: {
        current: 1,
        pageSize: 5,
        pageSizeSelect: [5, 10, 15]
      },
      getParams: function () {
        var id = this.attr('baseInstance.id');
        var type = this.attr('baseInstance.type');
        var relatedType = this.attr('relatedItemsType');
        var page = this.attr('paging');
        var orderBy = this.attr('orderBy') || defaultOrderBy;
        var isAssessment = this.attr('baseInstance.type') === 'Assessment';
        var op = isAssessment ? {name: 'similar'} : {name: 'relevant'};
        var params = {};
        var first;
        var last;

        if (page.current && page.pageSize) {
          first = (page.current - 1) * page.pageSize;
          last = page.current * page.pageSize;
        }
        params.data = [{
          limit: [first, last],
          object_name: relatedType,
          order_by: [{name: orderBy, desc: true}],
          filters: {
            expression: {
              object_name: type,
              op: op,
              ids: [id]
            }
          }
        }];
        return params;
      },
      updatePaging: function (total) {
        var count = Math.ceil(total / this.attr('paging.pageSize'));
        this.attr('paging.total', total);
        this.attr('paging.count', count);
      },
      loadRelatedItems: function () {
        var dfd = can.Deferred();
        var params = this.getParams();
        this.attr('isLoading', true);
        GGRC.Utils.QueryAPI
          .makeRequest(params)
          .done(function (responseArr) {
            var relatedType = this.attr('relatedItemsType');
            var data = responseArr[0];
            var values = data[relatedType].values;
            var result = values.map(function (item) {
              item.instance = new CMS.Models[relatedType](item);
{'fraction_non_alphanumeric': 0.1341435966689174, 'fraction_numerical': 0.00675219446320054, 'mean_word_length': 1.9410986101919259, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6204663', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1265, 'n_words': 300}