Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Push — master ( c61b79...4016a1 )
by Cristian
09:20
created

reorder.blade.php ➔ tree_element()   B

Complexity

Conditions 6
Paths 3

Size

Total Lines 34
Code Lines 18

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 6
eloc 18
nc 3
nop 4
dl 0
loc 34
rs 8.439
1
@extends('backpack::layout')
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 23 and the first side effect is on line 1.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
@section('after_styles')
4
    <link href="{{ asset('vendor/backpack/nestedSortable/nestedSortable.css') }}" rel="stylesheet" type="text/css" />
5
@endsection
6
7
@section('header')
8
  <section class="content-header">
9
    <h1>
10
      <span class="text-capitalize">{{ $crud->entity_name_plural }}</span>
11
      <small>{{ trans('backpack::crud.all') }} <span class="text-lowercase">{{ $crud->entity_name_plural }}</span> {{ trans('backpack::crud.in_the_database') }}.</small>
12
    </h1>
13
    <ol class="breadcrumb">
14
      <li><a href="{{ url('admin/dashboard') }}">Admin</a></li>
15
      <li><a href="{{ url($crud->route) }}" class="text-capitalize">{{ $crud->entity_name_plural }}</a></li>
16
      <li class="active">{{ trans('backpack::crud.reorder') }}</li>
17
    </ol>
18
  </section>
19
@endsection
20
21
@section('content')
22
<?php
23
  function tree_element($entry, $key, $all_entries, $crud)
24
  {
25
    if (!isset($entry->tree_element_shown)) {
26
      // mark the element as shown
27
      $all_entries[$key]->tree_element_shown = true;
28
      $entry->tree_element_shown = true;
29
30
      // show the tree element
31
      echo '<li id="list_'.$entry->id.'">';
32
      echo '<div><span class="disclose"><span></span></span>'.$entry->{$crud->reorder_label}.'</div>';
33
34
      // see if this element has any children
35
      $children = [];
36
      foreach ($all_entries as $key => $subentry) {
37
        if ($subentry->parent_id == $entry->id) {
38
          $children[] = $subentry;
39
        }
40
      }
41
42
      $children = collect($children)->sortBy('lft');
43
44
      // if it does have children, show them
45
      if (count($children)) {
46
        echo '<ol>';
47
        foreach ($children as $key => $child) {
48
          $children[$key] = tree_element($child, $child->id, $all_entries, $crud);
49
        }
50
        echo '</ol>';
51
      }
52
      echo '</li>';
53
    }
54
55
    return $entry;
56
  }
57
58
 ?>
59
<div class="row">
60
  <div class="col-md-8 col-md-offset-2">
61
    @if ($crud->hasAccess('list'))
62
      <a href="{{ url($crud->route) }}"><i class="fa fa-angle-double-left"></i> {{ trans('backpack::crud.back_to_all') }} <span class="text-lowercase">{{ $crud->entity_name_plural }}</span></a><br><br>
63
    @endif
64
65
      <!-- Default box -->
66
      <div class="box">
67
        <div class="box-header with-border">
68
          <h3 class="box-title">{{ trans('backpack::crud.reorder').' '.$crud->entity_name_plural }}</h3>
69
        </div>
70
        <div class="box-body">
71
72
          <p>{{ trans('backpack::crud.reorder_text') }}</p>
73
74
          @if (isset($languages))
75
            <ul class="nav nav-tabs">
76
              @foreach ($languages as $lang)
77
                <li role="presentation"
78
                  @if ($lang->abbr == $active_language)
79
                    class="active"
80
                  @endif
81
                >
82
                  <a href="{{ url($crud->route.'/reorder/'.$lang->abbr) }}">{{ $lang->name }}</a>
83
                </li>
84
              @endforeach
85
            </ul>
86
          @endif
87
88
          <ol class="sortable">
89
            <?php
90
              $all_entries = collect($entries->all())->sortBy('lft')->keyBy('id');
91
              $root_entries = $all_entries->filter(function($item) {
92
                return $item->parent_id == 0;
93
              });
94
             ?>
95
            @foreach ($root_entries as $key => $entry)
96
              <?php
97
                $root_entries[$key] = tree_element($entry, $key, $all_entries, $crud);
98
              ?>
99
            @endforeach
100
          </ol>
101
102
          <button id="toArray" class="btn btn-success ladda-button" data-style="zoom-in"><span class="ladda-label"><i class="fa fa-save"></i> {{ trans('backpack::crud.save') }}</span></button>
103
104
        </div><!-- /.box-body -->
105
      </div><!-- /.box -->
106
  </div>
107
</div>
108
@endsection
109
110
@section('after_scripts')
111
  <script src="https://code.jquery.com/ui/1.11.3/jquery-ui.min.js" type="text/javascript"></script>
112
  <script src="{{ url('vendor/backpack/nestedSortable/jquery.mjs.nestedSortable2.js') }}" type="text/javascript"></script>
113
114
  <script type="text/javascript">
115
    jQuery(document).ready(function($) {
116
117
      // initialize the nested sortable plugin
118
      $('.sortable').nestedSortable({
119
            forcePlaceholderSize: true,
120
            handle: 'div',
121
            helper: 'clone',
122
            items: 'li',
123
            opacity: .6,
124
            placeholder: 'placeholder',
125
            revert: 250,
126
            tabSize: 25,
127
            tolerance: 'pointer',
128
            toleranceElement: '> div',
129
            maxLevels: {{ $crud->reorder_max_level or 3 }},
130
131
            isTree: true,
132
            expandOnHover: 700,
133
            startCollapsed: false
134
        });
135
136
      $('.disclose').on('click', function() {
137
        $(this).closest('li').toggleClass('mjs-nestedSortable-collapsed').toggleClass('mjs-nestedSortable-expanded');
138
      });
139
140
      $('#toArray').click(function(e){
141
        // get the current tree order
142
        arraied = $('ol.sortable').nestedSortable('toArray', {startDepthCount: 0});
143
144
        // log it
145
        console.log(arraied);
146
147
        // send it with POST
148
          $.ajax({
149
            url: '{{ Request::url() }}',
150
            type: 'POST',
151
            data: { tree: arraied },
152
          })
153
          .done(function() {
154
            console.log("success");
155
            new PNotify({
156
                        title: "{{ trans('backpack::crud.reorder_success_title') }}",
157
                        text: "{{ trans('backpack::crud.reorder_success_message') }}",
158
                        type: "success"
159
                    });
160
          })
161
          .fail(function() {
162
            console.log("error");
163
            new PNotify({
164
                        title: "{{ trans('backpack::crud.reorder_error_title') }}",
165
                        text: "{{ trans('backpack::crud.reorder_error_message') }}",
166
                        type: "danger"
167
                    });
168
          })
169
          .always(function() {
170
            console.log("complete");
171
          });
172
173
      });
174
175
      $.ajaxPrefilter(function(options, originalOptions, xhr) {
176
          var token = $('meta[name="csrf_token"]').attr('content');
177
178
          if (token) {
179
                return xhr.setRequestHeader('X-XSRF-TOKEN', token);
180
          }
181
      });
182
183
    });
184
  </script>
185
@endsection