This repository was archived by the owner on Nov 26, 2024. It is now read-only.
forked from BadChoice/thrust
-
Notifications
You must be signed in to change notification settings - Fork 4
REV-12050 fetch correct actions while searching #68
Merged
BadChoice
merged 1 commit into
master
from
bugfix/REV-12050-display-correct-actions-while-searching
Oct 9, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,14 @@ | ||
| <?php | ||
| $actions = collect($resource->actions()); | ||
| ?> | ||
|
|
||
| @if (count($actions) > 0) | ||
| @if ($actions->where('main', false)->count() > 0) | ||
| <div x-data = "{isOpen : false}"> | ||
| <button class="secondary relative" x-on:click="isOpen = !isOpen"> <i id='actions-loading' class="fa fa-circle-o-notch fa-spin fa-fw" style="display:none"></i> {{ __("thrust::messages.actions") }} @icon(caret-down) </button> | ||
| <div class="thrust-actions-dropdown absolute" x-show="isOpen" x-transition x-cloak x-on:click.away = "isOpen = false"> | ||
| @foreach($actions->where('main', false) as $action) | ||
| <div class=""> | ||
| @if (count($action->fields()) == 0) | ||
| <a class='pointer' onclick='runAction("{{ $action->getClassForJs() }}", "{{$action->needsConfirmation}}", "{{$action->needsSelection}}", "{{$action->getConfirmationMessage()}}")'> | ||
| {!! $action->getIcon() !!} {!! $action->getTitle() !!} | ||
| </a> | ||
| @else | ||
| <a class='actionPopup' href="{{route('thrust.actions.create',[$resourceName])}}?action={{get_class($action)}}"> | ||
| {!! $action->getIcon() !!} {!! $action->getTitle() !!} | ||
| </a> | ||
| @endif | ||
| </div> | ||
| @endforeach | ||
| <div id="thrust-resource-actions" class="thrust-actions-dropdown absolute" x-show="isOpen" x-transition x-cloak x-on:click.away = "isOpen = false"> | ||
| @include('thrust::components.actionsIndex') | ||
| </div> | ||
| </div> | ||
| @endif | ||
|
|
||
| @foreach( $actions->where('main', true) as $action) | ||
| <button class="secondary" onclick='runAction("{{ $action->getClassForJs() }}", "{{$action->needsConfirmation}}", "{{$action->needsSelection}}", "{{$action->getConfirmationMessage()}}")'> {!! icon($action->icon) !!} </button> | ||
| @endforeach | ||
| @endif | ||
| @endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| @foreach($actions->where('main', false) as $action) | ||
| <div class=""> | ||
| @if (count($action->fields()) == 0) | ||
| <a class='pointer' onclick='runAction("{{ $action->getClassForJs() }}", "{{$action->needsConfirmation}}", "{{$action->needsSelection}}", "{{$action->getConfirmationMessage()}}")'> | ||
| {!! $action->getIcon() !!} {!! $action->getTitle() !!} | ||
| </a> | ||
| @else | ||
| <a class='actionPopup' href="{{route('thrust.actions.create',[$resourceName])}}?action={{get_class($action)}}"> | ||
| {!! $action->getIcon() !!} {!! $action->getTitle() !!} | ||
| </a> | ||
| @endif | ||
| </div> | ||
| @endforeach |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,28 @@ | ||
| <script> | ||
| $(".actionPopup").on('click',function(e) { | ||
| e.preventDefault(); | ||
| var selected = getSelectedRowsIds(); | ||
| const onClickHandler = function(e) { | ||
| e.preventDefault() | ||
| var selected = getSelectedRowsIds() | ||
| if (selected.length == 0){ | ||
| return alert("{!! __("thrust::messages.noRowsSelected") !!}"); | ||
| return alert("{!! __("thrust::messages.noRowsSelected") !!}") | ||
| } | ||
|
|
||
| $(this).attr('href', $(this).attr('href') + "&ids=" + selected); | ||
| showPopup($(this).attr('href')); | ||
| }); | ||
| this.setAttribute('href', this.getAttribute('href') + "&ids=" + selected) | ||
| showPopup(this.getAttribute('href')) | ||
| } | ||
|
|
||
| function registerActionPopupListeners() { | ||
| const elems = [...document.getElementsByClassName('actionPopup')] | ||
| elems.forEach(elem => { | ||
| elem.removeEventListener('click', onClickHandler) | ||
| elem.addEventListener('click', onClickHandler) | ||
| }) | ||
| } | ||
|
|
||
| function runAction(actionClass, needsConfirmation, needsSelection, confirmationMessage){ | ||
| var selected = getSelectedRowsIds(); | ||
| console.log(actionClass, selected, needsConfirmation, needsSelection); | ||
| var selected = getSelectedRowsIds() | ||
|
|
||
| if (needsSelection == 1 && selected.length == 0){ | ||
| return alert("{!! __("thrust::messages.noRowsSelected") !!}"); | ||
| return alert("{!! __("thrust::messages.noRowsSelected") !!}") | ||
| } | ||
|
|
||
| if (! needsConfirmation || confirm(confirmationMessage)){ | ||
|
|
@@ -25,37 +31,58 @@ function runAction(actionClass, needsConfirmation, needsSelection, confirmationM | |
| } | ||
|
|
||
| function doAction(actionClass, selected){ | ||
| $('#actions-loading').show(); | ||
| document.getElementById('actions-loading').style.display = 'block' | ||
| $.post("{{ route('thrust.actions.perform', [$resourceName]) }}", { | ||
| "_token": "{{ csrf_token() }}", | ||
| "action" : actionClass, | ||
| "ids" : selected | ||
| }).done(function(data){ | ||
| $('#actions-loading').hide(); | ||
| console.log("Action finished"); | ||
| //console.log(data); | ||
| document.getElementById('actions-loading').style.display = 'none' | ||
| if (data["responseAsPopup"]){ | ||
| $('#popup').popup('show'); | ||
| $("#popupContent").html(data["message"]); | ||
| $('#popup').popup('show') | ||
| $("#popupContent").html(data["message"]) | ||
| } else { | ||
| showMessage(data["message"]); | ||
| showMessage(data["message"]) | ||
| } | ||
| if (data["shouldReload"]) { | ||
| location.reload(); | ||
| location.reload() | ||
| } | ||
| }).fail(function(){ | ||
| console.log("Action failed"); | ||
| showMessage("Something went wrong"); | ||
| }); | ||
| showMessage("Something went wrong") | ||
| }) | ||
| } | ||
|
|
||
| function getSelectedRowsIds(){ | ||
| return $("input[name^=selected]:checked").map(function() { | ||
| return $(this).attr("meta:id"); | ||
| }).toArray(); | ||
| return [...document.querySelectorAll('input[name^=selected]:checked')] | ||
| .map(elem => elem.getAttribute("meta:id")) | ||
| } | ||
|
|
||
| function toggleSelectAll(checkbox){ | ||
| $("input[name^=selected]").prop('checked', checkbox.checked); | ||
| console.log([...document.querySelectorAll('input[name^=selected]')]); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ! |
||
| [...document.querySelectorAll('input[name^=selected]')] | ||
| .forEach(elem => checkbox.checked | ||
| ? elem.checked = true | ||
| : elem.checked = false | ||
| ) | ||
| } | ||
| </script> | ||
|
|
||
| registerActionPopupListeners() | ||
|
|
||
| window.addEventListener('thrust.searchStarted', () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. te sentit passar-li si te resource child o no per registrar (o no) els events? |
||
| fetch("{{ route('thrust.actions.index', ['resourceName' => $resourceName, 'search' => true]) }}").then(response => { | ||
| response.text().then(html => { | ||
| document.getElementById('thrust-resource-actions').innerHTML = html | ||
| registerActionPopupListeners() | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| window.addEventListener('thrust.searchEnded', () => { | ||
| fetch("{{ route('thrust.actions.index', ['resourceName' => $resourceName]) }}").then(response => { | ||
| response.text().then(html => { | ||
| document.getElementById('thrust-resource-actions').innerHTML = html | ||
| registerActionPopupListeners() | ||
| }) | ||
| }) | ||
| }) | ||
| </script> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fer una funcio $resource->searchActions() i que si te searchResource torni les del fill