Issues (87)

tcms/testplans/static/testplans/js/search.js (4 issues)

1
function preProcessData (data, callback) {
2
  const planIds = []
3
  data.forEach(function (element) {
4
    planIds.push(element.id)
5
  })
6
7
  // get tags for all objects
8
  const tagsPerPlan = {}
9
  jsonRPC('Tag.filter', { plan__in: planIds }, function (tags) {
10
    tags.forEach(function (element) {
11
      if (tagsPerPlan[element.plan] === undefined) {
12
        tagsPerPlan[element.plan] = []
13
      }
14
15
      // push only if unique
16
      if (tagsPerPlan[element.plan].indexOf(element.name) === -1) {
17
        tagsPerPlan[element.plan].push(element.name)
18
      }
19
    })
20
21
    // augment data set with additional info
22
    data.forEach(function (element) {
23
      if (element.id in tagsPerPlan) {
24
        element.tag = tagsPerPlan[element.id]
25
      } else {
26
        element.tag = []
27
      }
28
    })
29
30
    callback({ data: data }) // renders everything
31
  })
32
}
33
34
$(document).ready(function () {
35
  const table = $('#resultsTable').DataTable({
36
    pageLength: $('#navbar').data('defaultpagesize'),
37
    ajax: function (data, callback, settings) {
0 ignored issues
show
The parameter settings is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
38
      const params = {}
39
40
      if ($('#id_name').val()) {
41
        params.name__icontains = $('#id_name').val()
42
      }
43
44
      if ($('#id_before').val()) {
45
        params.create_date__lte = $('#id_before').data('DateTimePicker').date().format('YYYY-MM-DD 23:59:59')
46
      }
47
48
      if ($('#id_after').val()) {
49
        params.create_date__gte = $('#id_after').data('DateTimePicker').date().format('YYYY-MM-DD 00:00:00')
50
      }
51
52
      if ($('#id_product').val()) {
53
        params.product = $('#id_product').val()
54
      };
55
56
      if ($('#id_version').val()) {
57
        params.product_version = $('#id_version').val()
58
      };
59
60
      if ($('#id_type').val()) {
61
        params.type = $('#id_type').val()
62
      };
63
64
      if ($('#id_author').val()) {
65
        params.author__username__startswith = $('#id_author').val()
66
      };
67
68
      if ($('#id_default_tester').val()) {
69
        params.cases__default_tester__username__startswith = $('#id_default_tester').val()
70
      };
71
72
      updateParamsToSearchTags('#id_tag', params)
73
74
      params.is_active = $('#id_active').is(':checked')
75
76
      dataTableJsonRPC('TestPlan.filter', params, callback, preProcessData)
77
    },
78
    columns: [
79
      { data: 'id' },
80
      {
81
        data: null,
82
        render: function (data, type, full, meta) {
0 ignored issues
show
The parameter type is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
The parameter full is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
The parameter meta is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
83
          result = '<a href="/plan/' + data.id + '/">' + escapeHTML(data.name) + '</a>'
84
          if (!data.is_active) {
85
            result = '<strike>' + result + '</strike>'
86
          }
87
          return result
88
        }
89
      },
90
      { data: 'create_date' },
91
      { data: 'product__name' },
92
      { data: 'product_version__value' },
93
      { data: 'type__name' },
94
      { data: 'author__username' },
95
      { data: 'tag' }
96
    ],
97
    dom: 't',
98
    language: {
99
      loadingRecords: '<div class="spinner spinner-lg"></div>',
100
      processing: '<div class="spinner spinner-lg"></div>',
101
      zeroRecords: 'No records found'
102
    },
103
    order: [[0, 'asc']]
104
  })
105
106
  hookIntoPagination('#resultsTable', table)
107
108
  $('#btn_search').click(function () {
109
    table.ajax.reload()
110
    return false // so we don't actually send the form
111
  })
112
113
  $('#id_product').change(updateVersionSelectFromProduct)
114
115
  $('.bootstrap-switch').bootstrapSwitch()
116
117
  $('.selectpicker').selectpicker()
118
})
119