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

Passed
Push — main ( 822158...87e8bb )
by Pedro
37:52 queued 23:13
created

tree_element()   B

Complexity

Conditions 7
Paths 5

Size

Total Lines 33
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 7
eloc 18
c 1
b 0
f 1
nc 5
nop 4
dl 0
loc 33
rs 8.8333
1
@extends(backpack_view('blank'))
2
3
@php
4
    $defaultBreadcrumbs = [
5
      trans('backpack::crud.admin') => url(config('backpack.base.route_prefix'), 'dashboard'),
6
      $crud->entity_name_plural => url($crud->route),
7
      trans('backpack::crud.reorder') => false,
8
    ];
9
10
    // if breadcrumbs aren't defined in the CrudController, use the default breadcrumbs
11
    $breadcrumbs = $breadcrumbs ?? $defaultBreadcrumbs;
12
@endphp
13
14
@section('header')
15
    <section class="header-operation container-fluid animated fadeIn d-flex align-items-baseline d-print-none" bp-section="page-header">
16
        <h1 class="text-capitalize mb-0" bp-section="page-heading">{!! $crud->getHeading() ?? $crud->entity_name_plural !!}</h1>
17
        <p class="ms-2 ml-2 mb-0" bp-section="page-subheading">{!! $crud->getSubheading() ?? trans('backpack::crud.reorder').' '.$crud->entity_name_plural !!}</p>
18
        @if ($crud->hasAccess('list'))
19
            <p class="ms-2 ml-2 mb-0" bp-section="page-subheading-back-button">
20
                <small><a href="{{ url($crud->route) }}" class="d-print-none font-sm"><i class="la la-angle-double-left"></i> {{ trans('backpack::crud.back_to_all') }} <span>{{ $crud->entity_name_plural }}</span></a></small>
21
            </p>
22
        @endif
23
    </section>
24
@endsection
25
26
@section('content')
27
    <?php
28
    function tree_element($entry, $key, $all_entries, $crud)
29
    {
30
        if (! isset($entry->tree_element_shown)) {
31
            // mark the element as shown
32
            $all_entries[$key]->tree_element_shown = true;
33
            $entry->tree_element_shown = true;
34
            $entryLabel = $crud->get('reorder.escaped') ? e(object_get($entry, $crud->get('reorder.label'))) : object_get($entry, $crud->get('reorder.label'));
35
            // show the tree element
36
            echo '<li id="list_'.$entry->getKey().'">';
37
            echo '<div><span class="disclose"><span></span></span>'.$entryLabel.'</div>';
38
39
            // see if this element has any children
40
            $children = [];
41
            foreach ($all_entries as $key => $subentry) {
0 ignored issues
show
introduced by
$key is overwriting one of the parameters of this function.
Loading history...
42
                if ($subentry->parent_id == $entry->getKey()) {
43
                    $children[] = $subentry;
44
                }
45
            }
46
47
            $children = collect($children)->sortBy('lft');
0 ignored issues
show
Bug introduced by
$children of type array is incompatible with the type Illuminate\Contracts\Support\Arrayable expected by parameter $value of collect(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

47
            $children = collect(/** @scrutinizer ignore-type */ $children)->sortBy('lft');
Loading history...
48
49
            // if it does have children, show them
50
            if (count($children)) {
51
                echo '<ol>';
52
                foreach ($children as $key => $child) {
0 ignored issues
show
introduced by
$key is overwriting one of the parameters of this function.
Loading history...
53
                    $children[$key] = tree_element($child, $child->getKey(), $all_entries, $crud);
54
                }
55
                echo '</ol>';
56
            }
57
            echo '</li>';
58
        }
59
60
        return $entry;
61
    }
62
63
    ?>
64
65
    <div class="row mt-4" bp-section="crud-operation-reorder">
66
        <div class="{{ $crud->getReorderContentClass() }}">
67
            <div class="card p-4">
68
                <p>{{ trans('backpack::crud.reorder_text') }}</p>
69
70
                <ol class="sortable mt-0 mb-0">
71
                    <?php
72
                    $all_entries = collect($entries->all())->sortBy('lft')->keyBy($crud->getModel()->getKeyName());
73
    $root_entries = $all_entries->filter(function ($item) {
74
        return $item->parent_id == 0;
75
    });
76
    foreach ($root_entries as $key => $entry) {
77
        $root_entries[$key] = tree_element($entry, $key, $all_entries, $crud);
78
    }
79
    ?>
80
                </ol>
81
82
            </div>{{-- /.card --}}
83
84
            <div class="mt-3">
85
                <button id="toArray" class="btn btn-success text-light" data-style="zoom-in"><i class="la la-save"></i> {{ trans('backpack::crud.save') }}</button>
86
                <a href="{{ $crud->hasAccess('list') ? url($crud->route) : url()->previous() }}" class="btn btn-secondary text-decoration-none"><span class="la la-ban"></span> &nbsp;{{ trans('backpack::crud.cancel') }}</a>
87
            </div>
88
89
        </div>
90
    </div>
91
@endsection
92
93
94
@section('after_styles')
95
    <style>
96
        .ui-sortable .placeholder {
97
            outline: 1px dashed #4183C4;
98
            /*-webkit-border-radius: 3px;
99
            -moz-border-radius: 3px;
100
            border-radius: 3px;
101
            margin: -1px;*/
102
        }
103
104
        .ui-sortable .mjs-nestedSortable-error {
105
            background: #fbe3e4;
106
            border-color: transparent;
107
        }
108
109
        .ui-sortable ol {
110
            margin: 0;
111
            padding: 0;
112
            padding-left: 30px;
113
        }
114
115
        ol.sortable, ol.sortable ol {
116
            margin: 0 0 0 25px;
117
            padding: 0;
118
            list-style-type: none;
119
        }
120
121
        ol.sortable {
122
            margin: 2em 0;
123
        }
124
125
        .sortable li {
126
            margin: 5px 0 0 0;
127
            padding: 0;
128
        }
129
130
        .sortable li div  {
131
            border: 1px solid #ddd;
132
            -webkit-border-radius: 3px;
133
            -moz-border-radius: 3px;
134
            border-radius: 3px;
135
            padding: 6px;
136
            margin: 0;
137
            cursor: move;
138
            background-color: #f4f4f4;
139
            color: #444;
140
            border-color: #00acd6;
141
        }
142
143
        .sortable li.mjs-nestedSortable-branch div {
144
            /*background-color: #00c0ef;*/
145
            /*border-color: #00acd6;*/
146
        }
147
148
        .sortable li.mjs-nestedSortable-leaf div {
149
            /*background-color: #00c0ef;*/
150
            border: 1px solid #ddd;
151
        }
152
153
        li.mjs-nestedSortable-collapsed.mjs-nestedSortable-hovering div {
154
            border-color: #999;
155
            background: #fafafa;
156
        }
157
158
        .ui-sortable .disclose {
159
            cursor: pointer;
160
            width: 10px;
161
            display: none;
162
        }
163
164
        .sortable li.mjs-nestedSortable-collapsed > ol {
165
            display: none;
166
        }
167
168
        .sortable li.mjs-nestedSortable-branch > div > .disclose {
169
            display: inline-block;
170
        }
171
172
        .sortable li.mjs-nestedSortable-collapsed > div > .disclose > span:before {
173
            content: '+ ';
174
        }
175
176
        .sortable li.mjs-nestedSortable-expanded > div > .disclose > span:before {
177
            content: '- ';
178
        }
179
180
        .ui-sortable h1 {
181
            font-size: 2em;
182
            margin-bottom: 0;
183
        }
184
185
        .ui-sortable h2 {
186
            font-size: 1.2em;
187
            font-weight: normal;
188
            font-style: italic;
189
            margin-top: .2em;
190
            margin-bottom: 1.5em;
191
        }
192
193
        .ui-sortable h3 {
194
            font-size: 1em;
195
            margin: 1em 0 .3em;;
196
        }
197
198
        .ui-sortable p, .ui-sortable ol, .ui-sortable ul, .ui-sortable pre, .ui-sortable form {
199
            margin-top: 0;
200
            margin-bottom: 1em;
201
        }
202
203
        .ui-sortable dl {
204
            margin: 0;
205
        }
206
207
        .ui-sortable dd {
208
            margin: 0;
209
            padding: 0 0 0 1.5em;
210
        }
211
212
        .ui-sortable code {
213
            background: #e5e5e5;
214
        }
215
216
        .ui-sortable input {
217
            vertical-align: text-bottom;
218
        }
219
220
        .ui-sortable .notice {
221
            color: #c33;
222
        }
223
    </style>
224
@endsection
225
226
@section('after_scripts')
227
    @basset('https://unpkg.com/[email protected]/dist/jquery-ui.min.js')
228
    @basset(base_path('vendor/backpack/crud/src/resources/assets/libs/jquery.mjs.nestedSortable2.js'))
229
230
    <script type="text/javascript">
231
        jQuery(document).ready(function($) {
232
            var isRtl = Boolean("{{ (config('backpack.base.html_direction') === 'rtl') ? true : false }}");
233
            if(isRtl) {
234
                $( " <style> .ui-sortable ol {margin: 0;padding: 0;padding-right: 30px;}ol.sortable, ol.sortable ol {margin: 0 25px 0 0;padding: 0;list-style-type: none;}.ui-sortable dd {margin: 0;padding: 0 1.5em 0 0;}</style>" ).appendTo( "head" )
235
            }
236
            // initialize the nested sortable plugin
237
            $('.sortable').nestedSortable({
238
                forcePlaceholderSize: true,
239
                handle: 'div',
240
                helper: 'clone',
241
                items: 'li',
242
                opacity: .6,
243
                placeholder: 'placeholder',
244
                revert: 250,
245
                tabSize: 25,
246
                rtl: isRtl,
247
                tolerance: 'pointer',
248
                toleranceElement: '> div',
249
                maxLevels: {{ $crud->get('reorder.max_level') ?? 3 }},
250
                isTree: true,
251
                expandOnHover: 700,
252
                startCollapsed: false
253
            });
254
255
            $('.disclose').on('click', function() {
256
                $(this).closest('li').toggleClass('mjs-nestedSortable-collapsed').toggleClass('mjs-nestedSortable-expanded');
257
            });
258
259
            $('#toArray').click(function(e){
260
                // get the current tree order
261
                arraied = $('ol.sortable').nestedSortable('toArray', {startDepthCount: 0, expression: /(.+)_(.+)/ });
262
263
                // log it
264
                //console.log(arraied);
265
266
                // send it with POST
267
                $.ajax({
268
                    url: '{{ url(Request::path()) }}',
269
                    type: 'POST',
270
                    data: { tree: JSON.stringify(arraied) },
271
                })
272
                    .done(function() {
273
                        new Noty({
274
                            type: "success",
275
                            text: "<strong>{{ trans('backpack::crud.reorder_success_title') }}</strong><br>{{ trans('backpack::crud.reorder_success_message') }}"
276
                        }).show();
277
                    })
278
                    .fail(function() {
279
                        new Noty({
280
                            type: "error",
281
                            text: "<strong>{{ trans('backpack::crud.reorder_error_title') }}</strong><br>{{ trans('backpack::crud.reorder_error_message') }}"
282
                        }).show();
283
                    })
284
                    .always(function() {
285
                        console.log("complete");
286
                    });
287
288
            });
289
290
            $.ajaxPrefilter(function(options, originalOptions, xhr) {
291
                var token = $('meta[name="csrf_token"]').attr('content');
292
293
                if (token) {
294
                    return xhr.setRequestHeader('X-XSRF-TOKEN', token);
295
                }
296
            });
297
298
        });
299
    </script>
300
@endsection
301