diff --git a/app/Http/Controllers/Campaign/RecoveryController.php b/app/Http/Controllers/Campaign/RecoveryController.php index bd19f40da..ba6e71bec 100644 --- a/app/Http/Controllers/Campaign/RecoveryController.php +++ b/app/Http/Controllers/Campaign/RecoveryController.php @@ -9,7 +9,6 @@ use App\Services\Entity\RecoverySetupService; use Exception; use Illuminate\Http\Request; -use Illuminate\Support\Facades\DB; class RecoveryController extends Controller { @@ -17,7 +16,6 @@ class RecoveryController extends Controller protected EntityRecoveryService $entityService; protected RecoverySetupService $service; - public function __construct(RecoveryService $postService, EntityRecoveryService $entityService, RecoverySetupService $recoverySetupService) { $this->middleware('auth'); @@ -34,22 +32,9 @@ public function index(Campaign $campaign) { $this->authorize('recover', $campaign); - $elements = DB::select( - 'select id, name, deleted_at, deleted_by, "entity" as type - from entities - where deleted_at is not null and campaign_id = ' . $campaign->id . ' - union all - select p.id, p.name, p.deleted_at, p.deleted_by, "post" as type - from posts as p - left join entities as e on e.id = p.entity_id - where p.deleted_at is not null and e.deleted_at is null and e.campaign_id = ' . $campaign->id . - ' order by deleted_at DESC' - ); - - return view('campaigns.recovery.index', compact('elements', 'campaign')); + return view('campaigns.recovery.index', compact('campaign')); } - public function setup(Campaign $campaign) { $this->authorize('recover', $campaign); diff --git a/app/Services/Entity/RecoveryService.php b/app/Services/Entity/RecoveryService.php index a545cb123..23602dfd5 100644 --- a/app/Services/Entity/RecoveryService.php +++ b/app/Services/Entity/RecoveryService.php @@ -25,7 +25,6 @@ public function recover(array $ids): array return $entities; } - /** */ public function count(): int @@ -41,13 +40,13 @@ protected function entity(int $id): string { $entity = Entity::onlyTrashed()->find($id); if (!$entity) { - return false; + return null; } // @phpstan-ignore-next-line $child = $entity->child()->onlyTrashed()->first(); if (!$child) { - return ''; + return null; } $entity->restore(); diff --git a/app/Services/Entity/RecoverySetupService.php b/app/Services/Entity/RecoverySetupService.php index 4e2b366bf..762877de0 100644 --- a/app/Services/Entity/RecoverySetupService.php +++ b/app/Services/Entity/RecoverySetupService.php @@ -79,13 +79,14 @@ protected function elements(): array $element->date = \Carbon\Carbon::createFromTimeStamp(strtotime($element->deleted_at))->diffForHumans(); $element->position = $key; } + //This will cast each object in the array to an array, and the toArray gets you from the collection back to an array. return collect($elements)->map(function ($x) { return (array) $x; })->toArray(); } protected function i18n(): array { $translations = [ - '0' => __('entities.post'), + 'model_0' => __('entities.post'), 'order_by_newest' => __('campaigns/recovery.order.newest'), 'order_by_oldest' => __('campaigns/recovery.order.oldest'), 'order_by_type' => __('campaigns/recovery.order.type'), @@ -111,7 +112,7 @@ protected function i18n(): array if ($this->campaign->superboosted() && $this->campaign->hasModuleName($id)) { $moduleName = $this->campaign->moduleName($id); } - $translations[$id] = $moduleName; + $translations['model_' . $id] = $moduleName; } return $translations; } diff --git a/app/Services/Posts/RecoveryService.php b/app/Services/Posts/RecoveryService.php index e9587112b..2c12c5190 100644 --- a/app/Services/Posts/RecoveryService.php +++ b/app/Services/Posts/RecoveryService.php @@ -42,10 +42,10 @@ protected function post(int $id): string /** @var ?Post $post */ $post = Post::onlyTrashed()->find($id); if (!$post) { - return ''; + return null; } if ($post->entity->deleted_at) { - return ''; + return null; } $post->restore(); $this->count++; diff --git a/resources/js/recovery/Element.vue b/resources/js/recovery/Element.vue index fb3ae7ff3..699e50dcf 100644 --- a/resources/js/recovery/Element.vue +++ b/resources/js/recovery/Element.vue @@ -1,29 +1,29 @@ @@ -35,25 +35,24 @@ import {matches} from "lodash"; const emit = defineEmits(['recover']) const props = defineProps<{ - file: Object, - isBulking: Boolean, + model: Object, i18n: Object }>() const click = () => { - if (!props.file.url) { - props.file.is_selected = !props.file.is_selected + if (!props.model.url) { + props.model.is_selected = !props.model.is_selected } } -const fileClass = () => { +const modelClass = () => { let css = 'rounded shadow bg-base-100 flex flex-col gap-2 p-2 hover:shadow-lg' - if (!props.file.url) { + if (!props.model.url) { css = css + ' cursor-pointer' } - if (!props.file.is_selected) { + if (!props.model.is_selected) { return css + ' ' } @@ -76,14 +75,14 @@ const trans = (key, replace = []) => { const buttonClass = () => { let css = 'btn2 btn-default btn-sm' - if (props.file.is_recovering) { - css += ' loading btn-disabled btn-sm' + if (props.model.is_recovering) { + css += ' loading btn-disabled' } return css } const restoreElement = () => { - emit('recover', props.file) + emit('recover', props.model) } diff --git a/resources/js/recovery/Recovery.vue b/resources/js/recovery/Recovery.vue index 1350c83ea..bef925e00 100644 --- a/resources/js/recovery/Recovery.vue +++ b/resources/js/recovery/Recovery.vue @@ -44,13 +44,12 @@
-
+
@@ -58,10 +57,10 @@
- +

- @@ -90,18 +89,16 @@ const props = defineProps<{ const initiated = ref(false) const loading = ref(false) -const isBulking = ref(false) const premium = ref(false) -const currentFile = ref() const searchTerm = ref() const lastTerm = ref() const typingTimeout = ref(null) -const files = ref([]) +const models = ref([]) const filter = ref('newest') const i18n = ref() -const newDialog = ref() -const updateApi = ref() -const moving = ref(false) +const premiumDialog = ref() +const recoveryApi = ref() +const recovering = ref(false) const showFilters = ref(false) const upgradeLink = ref() @@ -109,9 +106,9 @@ onMounted(() => { axios.get(props.api) .then((res) => { initiated.value = true - files.value = res.data.elements + models.value = res.data.elements i18n.value = res.data.i18n - updateApi.value = res.data.api.recovery + recoveryApi.value = res.data.api.recovery premium.value = res.data.acl.premium upgradeLink.value = res.data.upgrade }) @@ -126,43 +123,35 @@ const trans = (key) => { return i18n.value[key] } -const gridClass = () => { - let css = "grid grid-cols-3 gap-2" - if (currentFile.value) { - css += ' basis-2/4 md:basis-3/4' - } - return css -} - -const selectElements = (file) => { - let f = files.value.find(f => f.id === file.id) +const selectElements = (model) => { + let f = models.value.find(f => f.id === model.id) if (!f.url && !f.is_hidden) { f.is_selected = true } return; } -const deselectElements = (file) => { - let f = files.value.find(f => f.id === file.id) +const deselectElements = (model) => { + let f = models.value.find(f => f.id === model.id) f.is_selected = false return; } -const recoverElement = (file) => { +const recoverElement = (model) => { if (!premium.value) { - openDialog(newDialog.value) + openDialog(premiumDialog.value) return } - let f = files.value.find(f => f.id === file.id) + let f = models.value.find(f => f.id === model.id) f.is_recovering = true - if (moving.value) { + if (recovering.value) { return } - moving.value = true + recovering.value = true let data = {} if (f.type === 'post') { @@ -173,15 +162,15 @@ const recoverElement = (file) => { data.posts = [] } - axios.post(updateApi.value, data).then(res => { - moving.value = false + axios.post(recoveryApi.value, data).then(res => { + recovering.value = false const entities = Object.keys(res.data.entities).map( key => res.data.entities[key] ); - let ids = files.value.filter(f => f.is_recovering && f.type == 'entity') - let postIds = files.value.filter(f => f.is_recovering && f.type == 'post') + let ids = models.value.filter(f => f.is_recovering && f.type == 'entity') + let postIds = models.value.filter(f => f.is_recovering && f.type == 'post') ids.forEach(f => { f.is_selected = false @@ -205,12 +194,12 @@ const recoverElement = (file) => { } const selectAll = () => { - files.value.forEach(selectElements) + models.value.forEach(selectElements) return } const deselectAll = () => { - files.value.forEach(deselectElements) + models.value.forEach(deselectElements) return } @@ -231,9 +220,8 @@ const search = () => { } lastTerm.value = searchTerm.value - // Nothing? Go back home if (!searchTerm.value) { - files.value.forEach(f => { + models.value.forEach(f => { f.is_hidden = false }) return; @@ -245,7 +233,7 @@ const search = () => { } const hasSelection = () => { - let count = files.value.filter(f => f.is_selected).length + let count = models.value.filter(f => f.is_selected).length if (count === 0) { return false } @@ -255,35 +243,34 @@ const hasSelection = () => { const bulkRecover = () => { if (!premium.value) { - openDialog(newDialog.value) + openDialog(premiumDialog.value) return } - if (moving.value) { + if (recovering.value) { return } - let ids = files.value.filter(f => f.is_selected && f.type == 'entity').map(f => f.id) - let postIds = files.value.filter(f => f.is_selected && f.type == 'post').map(f => f.id) + let ids = models.value.filter(f => f.is_selected && f.type == 'entity').map(f => f.id) + let postIds = models.value.filter(f => f.is_selected && f.type == 'post').map(f => f.id) if (ids.length === 0 && postIds.length === 0) { return } - moving.value = true + recovering.value = true let data = {} data.entities = ids data.posts = postIds - axios.post(updateApi.value, data).then(res => { - moving.value = false + axios.post(recoveryApi.value, data).then(res => { + recovering.value = false const entities = Object.keys(res.data.entities).map( key => res.data.entities[key] ); - //console.log(res.data.entities, entities) - let ids = files.value.filter(f => f.is_selected && f.type == 'entity') - let postIds = files.value.filter(f => f.is_selected && f.type == 'post') + let ids = models.value.filter(f => f.is_selected && f.type == 'entity') + let postIds = models.value.filter(f => f.is_selected && f.type == 'post') ids.forEach(f => { f.is_selected = false @@ -304,7 +291,7 @@ const bulkRecover = () => { } const countSelected = () => { - let count = files.value.filter(f => f.is_selected).length + let count = models.value.filter(f => f.is_selected).length if (count === 0) { return } @@ -320,7 +307,7 @@ const onClickOutside = () => { } const showSearchResults = () => { - files.value.forEach(f => { + models.value.forEach(f => { const slug = f.name.toLowerCase() if (slug.includes(searchTerm.value)) { f.is_hidden = false @@ -333,7 +320,7 @@ const showSearchResults = () => { const orderByNew = () => { loading.value = true - files.value.sort(function(a, b){return a.position - b.position}); + models.value.sort(function(a, b){return a.position - b.position}); loading.value = false showFilters.value = false filter.value = 'newest' @@ -341,7 +328,7 @@ const orderByNew = () => { const orderByOld = () => { loading.value = true - files.value.sort(function(a, b){return b.position - a.position}); + models.value.sort(function(a, b){return b.position - a.position}); loading.value = false showFilters.value = false filter.value = 'oldest' @@ -349,7 +336,7 @@ const orderByOld = () => { const orderByType = () => { loading.value = true - files.value.sort(function(a, b){return trans(a.type_id).localeCompare(trans(b.type_id))}); + models.value.sort(function(a, b){return trans(a.type_id).localeCompare(trans(b.type_id))}); loading.value = false showFilters.value = false filter.value = 'type' diff --git a/resources/views/campaigns/recovery/_table.blade.php b/resources/views/campaigns/recovery/_table.blade.php deleted file mode 100644 index 98fe82cf4..000000000 --- a/resources/views/campaigns/recovery/_table.blade.php +++ /dev/null @@ -1,23 +0,0 @@ -
- @foreach ($elements as $element) -
-
-
- -
-
{{ $element->name }}
- -
- @if ($element->type == 'entity') - {{ __('crud.fields.entity') }} - @else - {{ __('entities.post') }} - @endif -
-
-
- {{ __('campaigns/recovery.fields.deleted_at', ['date' => \Carbon\Carbon::createFromTimeStamp(strtotime($element->deleted_at))->diffForHumans()]) }} -
-
- @endforeach -
diff --git a/resources/views/campaigns/recovery/index.blade.php b/resources/views/campaigns/recovery/index.blade.php index fbe7969c6..53c1d2992 100644 --- a/resources/views/campaigns/recovery/index.blade.php +++ b/resources/views/campaigns/recovery/index.blade.php @@ -21,10 +21,6 @@ {{ __('crud.actions.help') }}
- @if (session()->get('boosted-pitch')) - - - @endif