| Conditions | 20 |
| Total Lines | 194 |
| Code Lines | 118 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like Admin.constructor 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 | /** |
||
| 38 | constructor() { |
||
| 39 | window.$ = window.jQuery = $; |
||
| 40 | const sidebarPartial = new Sidebar; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Run sidebar toggle |
||
| 44 | */ |
||
| 45 | sidebarPartial.toggle(); |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Run toggle on window resize |
||
| 49 | */ |
||
| 50 | $(window).resize(function () { |
||
| 51 | sidebarPartial.toggle(); |
||
| 52 | }); |
||
| 53 | |||
| 54 | $('.datatables-basic, .datatables-fixed').prop('width', '100%'); |
||
| 55 | var printCounter = 0; |
||
| 56 | var datatablesBasic = $('.datatables-basic').DataTable({ |
||
| 57 | "searching": false, |
||
| 58 | "lengthChange": false, |
||
| 59 | "scrollX": true, |
||
| 60 | //dom: 'Bfrtip', |
||
| 61 | buttons: [ |
||
| 62 | { |
||
| 63 | extend: 'copy', |
||
| 64 | className: 'btn btn-default' |
||
| 65 | }, |
||
| 66 | { |
||
| 67 | extend: 'excel', |
||
| 68 | className: 'btn btn-default' , |
||
| 69 | footer: true, |
||
| 70 | messageTop: function () { |
||
| 71 | var headerPeriode = $('.header-periode').text(); |
||
| 72 | return headerPeriode; |
||
| 73 | }, |
||
| 74 | |||
| 75 | messageBottom: function () { |
||
| 76 | |||
| 77 | var footerPrint = $('.footer-print').text(); |
||
| 78 | |||
| 79 | return footerPrint; |
||
| 80 | }, |
||
| 81 | }, |
||
| 82 | { |
||
| 83 | extend: 'csv', |
||
| 84 | className: 'btn btn-default' |
||
| 85 | }, |
||
| 86 | { |
||
| 87 | extend: 'pdf', |
||
| 88 | className: 'btn btn-default', |
||
| 89 | footer: true, |
||
| 90 | messageTop: function () { |
||
| 91 | printCounter++; |
||
| 92 | |||
| 93 | var headerPrint = $('.header-print').html(); |
||
| 94 | var headerPeriode = $('.header-periode').html(); |
||
| 95 | if ( printCounter === 1 ) { |
||
| 96 | return headerPrint+headerPeriode+'This is the first time you have printed this document.'; |
||
| 97 | } |
||
| 98 | else { |
||
|
|
|||
| 99 | return headerPrint+headerPeriode+'You have printed this document '+printCounter+' times'; |
||
| 100 | } |
||
| 101 | }, |
||
| 102 | |||
| 103 | messageBottom: function () { |
||
| 104 | |||
| 105 | var footerPrint = $('.footer-print').html(); |
||
| 106 | |||
| 107 | return footerPrint; |
||
| 108 | }, |
||
| 109 | |||
| 110 | }, |
||
| 111 | { |
||
| 112 | extend: 'print', |
||
| 113 | className: 'btn btn-default', |
||
| 114 | footer: true, |
||
| 115 | messageTop: function () { |
||
| 116 | printCounter++; |
||
| 117 | |||
| 118 | var headerPrint = $('.header-print').html(); |
||
| 119 | var headerPeriode = $('.header-periode').html(); |
||
| 120 | if ( printCounter === 1 ) { |
||
| 121 | return headerPrint+headerPeriode+'This is the first time you have printed this document.'; |
||
| 122 | } |
||
| 123 | else { |
||
| 124 | return headerPrint+headerPeriode+'You have printed this document '+printCounter+' times'; |
||
| 125 | } |
||
| 126 | }, |
||
| 127 | |||
| 128 | messageBottom: function () { |
||
| 129 | |||
| 130 | var footerPrint = $('.footer-print').html(); |
||
| 131 | |||
| 132 | return footerPrint; |
||
| 133 | }, |
||
| 134 | }, |
||
| 135 | ], |
||
| 136 | drawCallback: function (settings) { |
||
| 137 | $('[data-toggle="tooltip"]').tooltip(); |
||
| 138 | } |
||
| 139 | }); |
||
| 140 | |||
| 141 | datatablesBasic.buttons().container().appendTo( $('.col-md-6:eq(0)', datatablesBasic.table().container() ) ); |
||
| 142 | |||
| 143 | var datatablesFixed = $('.datatables-fixed').DataTable({ |
||
| 144 | "searching": false, |
||
| 145 | "lengthChange": false, |
||
| 146 | "scrollX": true, |
||
| 147 | fixedHeader: true, |
||
| 148 | fixedColumns: true, |
||
| 149 | //dom: 'Bfrtip', |
||
| 150 | buttons: [ |
||
| 151 | { |
||
| 152 | extend: 'copy', |
||
| 153 | className: 'btn btn-default' |
||
| 154 | }, |
||
| 155 | { |
||
| 156 | extend: 'excel', |
||
| 157 | className: 'btn btn-default' , |
||
| 158 | footer: true, |
||
| 159 | messageTop: function () { |
||
| 160 | var headerPeriode = $('.header-periode').text(); |
||
| 161 | return headerPeriode; |
||
| 162 | }, |
||
| 163 | |||
| 164 | messageBottom: function () { |
||
| 165 | |||
| 166 | var footerPrint = $('.footer-print').text(); |
||
| 167 | |||
| 168 | return footerPrint; |
||
| 169 | }, |
||
| 170 | }, |
||
| 171 | { |
||
| 172 | extend: 'csv', |
||
| 173 | className: 'btn btn-default' |
||
| 174 | }, |
||
| 175 | { |
||
| 176 | extend: 'pdf', |
||
| 177 | className: 'btn btn-default', |
||
| 178 | footer: true, |
||
| 179 | messageTop: function () { |
||
| 180 | printCounter++; |
||
| 181 | |||
| 182 | var headerPrint = $('.header-print').html(); |
||
| 183 | var headerPeriode = $('.header-periode').html(); |
||
| 184 | if ( printCounter === 1 ) { |
||
| 185 | return headerPrint+headerPeriode+'This is the first time you have printed this document.'; |
||
| 186 | } |
||
| 187 | else { |
||
| 188 | return headerPrint+headerPeriode+'You have printed this document '+printCounter+' times'; |
||
| 189 | } |
||
| 190 | }, |
||
| 191 | |||
| 192 | messageBottom: function () { |
||
| 193 | |||
| 194 | var footerPrint = $('.footer-print').html(); |
||
| 195 | |||
| 196 | return footerPrint; |
||
| 197 | }, |
||
| 198 | |||
| 199 | }, |
||
| 200 | { |
||
| 201 | extend: 'print', |
||
| 202 | className: 'btn btn-default', |
||
| 203 | footer: true, |
||
| 204 | messageTop: function () { |
||
| 205 | printCounter++; |
||
| 206 | |||
| 207 | var headerPrint = $('.header-print').html(); |
||
| 208 | var headerPeriode = $('.header-periode').html(); |
||
| 209 | if ( printCounter === 1 ) { |
||
| 210 | return headerPrint+headerPeriode+'This is the first time you have printed this document.'; |
||
| 211 | } |
||
| 212 | else { |
||
| 213 | return headerPrint+headerPeriode+'You have printed this document '+printCounter+' times'; |
||
| 214 | } |
||
| 215 | }, |
||
| 216 | |||
| 217 | messageBottom: function () { |
||
| 218 | |||
| 219 | var footerPrint = $('.footer-print').html(); |
||
| 220 | |||
| 221 | return footerPrint; |
||
| 222 | }, |
||
| 223 | }, |
||
| 224 | ], |
||
| 225 | drawCallback: function (settings) { |
||
| 226 | $('[data-toggle="tooltip"]').tooltip(); |
||
| 227 | } |
||
| 228 | }); |
||
| 229 | |||
| 230 | datatablesFixed.buttons().container().appendTo( $('.col-md-6:eq(0)', datatablesFixed.table().container() ) ); |
||
| 231 | } |
||
| 232 | } |
||
| 234 | export default new Admin; |