GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — v2.4-alpha (#765)
by Ahmad
04:29
created

search.js ➔ searchPage   D

Complexity

Conditions 12

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 15
rs 4.8
c 0
b 0
f 0
cc 12

How to fix   Complexity   

Complexity

Complex classes like search.js ➔ searchPage often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
// BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
2
//
3
// Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
4
//
5
// This program is free software; you can redistribute it and/or modify it under the
6
// terms of the GNU Lesser General Public License as published by the Free Software
7
// Foundation; either version 3.0 of the License, or (at your option) any later
8
// version.
9
//
10
// BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
11
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
12
// PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
13
//
14
// You should have received a copy of the GNU Lesser General Public License along
15
// with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
16
17
$(document).on('turbolinks:load', function(){
18
  var controller = $("body").data('controller');
19
  var action = $("body").data('action');
20
21
  if ((controller == "admins" && action == "index") || 
22
      (controller == "rooms" && action == "show") || 
23
      (controller == "rooms" && action == "update") ||
24
      (controller == "rooms" && action == "join") || 
25
      (controller == "users" && action == "recordings") ||
26
      (controller == "admins" && action == "server_recordings")) {
27
    // Submit search if the user hits enter
28
    $("#search-input").keypress(function(key) {
29
      if (key.which == 13) {
30
        searchPage()
31
      }
32
    })
33
34
    // Add listeners for sort
35
    $("th[data-order]").click(function(data){
36
      var header_elem = $(data.target)
37
      var controller = $("body").data('controller');
0 ignored issues
show
Unused Code introduced by
The variable controller seems to be never used. Consider removing it.
Loading history...
38
      var action = $("body").data('action');
0 ignored issues
show
Unused Code introduced by
The variable action seems to be never used. Consider removing it.
Loading history...
39
40
      if(header_elem.data('order') === 'asc'){ // asc
41
        header_elem.data('order', 'desc');
42
      }
43
      else if(header_elem.data('order') === 'desc'){ // desc
44
        header_elem.data('order', 'none');
45
      }
46
      else{ // none
47
        header_elem.data('order', 'asc');
48
      }
49
50
      var search = $("#search-input").val();
51
52
      url = window.location.pathname + "?page=1&search=" + search + "&column=" + header_elem.data("header") +
0 ignored issues
show
Bug introduced by
The variable url seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.url.
Loading history...
53
       "&direction=" + header_elem.data('order')
54
55
      window.location.replace(addRecordingTable(url))
56
    })
57
58
    if(controller === "rooms" && action === "show"){
59
      $(".page-item > a").each(function(){
60
        if(!$(this).attr('href').endsWith("#")){
61
          $(this).attr('href', $(this).attr('href') + "#recordings-table")
62
        }
63
      })
64
    }
65
  }
66
})
67
68
// Searches the user table for the given string
69
function searchPage() {
70
  var search = $("#search-input").val();
71
72
  var controller = $("body").data('controller');
0 ignored issues
show
Unused Code introduced by
The variable controller seems to be never used. Consider removing it.
Loading history...
73
  var action = $("body").data('action');
0 ignored issues
show
Unused Code introduced by
The variable action seems to be never used. Consider removing it.
Loading history...
74
75
  // Check if the user filtered by role
76
  var role = new URL(location.href).searchParams.get('role')
77
78
  var url = window.location.pathname + "?page=1&search=" + search
79
80
  if (role) { url += "&role=" + role } 
81
82
  window.location.replace(addRecordingTable(url));
83
}
84
85
// Clears the search bar
86
function clearSearch() {
87
  var controller = $("body").data('controller');
0 ignored issues
show
Unused Code introduced by
The variable controller seems to be never used. Consider removing it.
Loading history...
88
  var action = $("body").data('action');
0 ignored issues
show
Unused Code introduced by
The variable action seems to be never used. Consider removing it.
Loading history...
89
90
  var role = new URL(location.href).searchParams.get('role')
0 ignored issues
show
Bug introduced by
The variable URL seems to be never declared. If this is a global, consider adding a /** global: URL */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
91
92
  var url = window.location.pathname + "?page=1"
93
94
  if (role) { url += "&role=" + role } 
95
  
96
  window.location.replace(addRecordingTable(url));
97
}
98
99
function addRecordingTable(url) {
100
  if(controller === "rooms" && action === "show") { url += "#recordings-table" }
0 ignored issues
show
Bug introduced by
The variable controller seems to be never declared. If this is a global, consider adding a /** global: controller */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable action seems to be never declared. If this is a global, consider adding a /** global: action */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Unused Code introduced by
The assignment to variable url seems to be never used. Consider removing it.
Loading history...
101
}
102