Skip to content

Commit

Permalink
feat(cache): Added button for clearing cache / close #84
Browse files Browse the repository at this point in the history
  • Loading branch information
anibalealvarezs committed Feb 20, 2022
1 parent 4d9a96c commit d859471
Show file tree
Hide file tree
Showing 13 changed files with 233 additions and 55 deletions.
63 changes: 42 additions & 21 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.3.7.1] - 2022-02-14
## [1.3.7.1] - 2022-02-19

### Added

- Implemented cache for controllers
- Added facades por ```PbDebugbar``` class
Expand All @@ -14,56 +16,81 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- BREAKING CHANGES:
- [x] [1.3.6.1]

### Added

- Added Middleware to store config data in session
- Added singleton for utilities
- Added performance flags to CRUD controllers
- Added facades por ```PbUtilities``` class

### Changed

- Helpers moved from classes to functions in ```helpers.php``` file
- ```Helpers``` folder renamed as ```Utilities```
- ```PbHelpers``` class renamed as ```PbUtilities```
- Added singleton for utilities
- CRUD permitions refactored
- Performance significantly improved
- ```crud``` attribute is now optional for models
- Added performance flags to CRUD controllers
- Added facades por ```PbUtilities``` class
- Overrides moved to ```Overrides``` folder

### Fixed

- Performance significantly improved

## [1.3.6.1] - 2022-02-11

### Added

- Added singleton for current user
- Added option for removing previous migration files

### Changed

- PbLogger and PbConfig tables names updated
- spatie/laravel-translatable minimum requirement updated
- Schema dump updated
- Providers installation moved to Project Builder section

### Fixed

- Fixed typo in Installation Command
- Added option for removing previous migration files
- Fixed error on saving profile data

## [1.3.6] - 2022-02-08

### Added

- Laravel 9.x support added.

### Changed

- Unnecessary packages removed from composer.json.
- Installation updated.
- Ask for confirmation for installing Inertia or leave.
- webpack.congig.js insertions format fixed.
- Jetstream and Fortify no longer being asked to be ignored in composer.json.
- Fix: Inertia class no longer being imported on installation trait to prevent exception on fresh installations.
- Schema's default string length moved to Project Builder's app service provider
- Installation updated.
- Ask for confirmation for installing Inertia or leave.
- Jetstream and Fortify no longer being asked to be ignored in composer.json.

### Fixed

- Fix: Inertia class no longer being imported on installation trait to prevent exception on fresh installations.
- webpack.config.js insertions format fixed.

## [1.3.5] - 2022-02-04

### Added

- New release after several months of work and missing changelog entries.

## [1.2.2.2] - 2021-07-18

### Added

### Changed

- Forms reset after creation
- Dragging no longer requires delay on mobile

### Fixed

- Forms fields validations
- Form fields validations

## [1.2.2] - 2021-07-06

Expand All @@ -89,8 +116,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.2.1.1] - 2021-07-06

### Added

### Changed

- Views paths are now dynamic
Expand All @@ -99,8 +124,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.2.1] - 2021-07-06

### Added

### Changed

- Controllers Refactored
Expand Down Expand Up @@ -180,8 +203,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Translatable alias for Roles and Permissions

### Changed

### Fixed

- Seeders debugged
Expand All @@ -206,4 +227,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Menu CSS classes
- Directly routed CRUD forms
- projectbuilder.js helpers optimizated
- projectbuilder.js helpers optimized
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"homepage": "https://anibalalvarez.com",
"license": "MIT",
"version" : "1.3.7",
"version" : "1.3.7.1",
"type" : "package",
"authors": [
{
Expand Down
46 changes: 41 additions & 5 deletions resources/js/AppLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
<div class="flex justify-between h-16">
<div class="flex">
<!-- Logo -->

<div class="flex-shrink-0 flex items-center">
<Link :href="route('dashboard')">
<jet-application-mark class="block h-9 w-auto" />
</Link>
</div>

<!-- Navigation Links -->
<div class="space-x-8 sm:-my-px sm:ml-10 sm:flex">
<ul class="sm:flex">
Expand All @@ -39,6 +37,36 @@
</div>

<div class="hidden sm:flex sm:items-center sm:ml-6">
<!-- Cache Dropdown -->
<div class="ml-3 relative" v-if="cache.hasOwnProperty('app') && helpers.stringToBoolean(cache.app)">
<jet-dropdown align="right" width="auto">
<template #trigger>
<span class="inline-flex rounded-md">
<button type="button" class="inline-flex items-center px-4 py-2 border border-transparent text-sm leading-4 font-medium rounded-md text-gray-500 bg-white hover:bg-gray-50 hover:text-gray-700 focus:outline-none focus:bg-gray-50 active:bg-gray-50 transition ease-in-out duration-150">
<span>Cache</span>
</button>
</span>
</template>

<template #content>
<!-- Cache Management -->
<form v-if="cache.hasOwnProperty('app') && helpers.stringToBoolean(cache.app)" @submit.prevent="cacheProcess('app')">
<jet-dropdown-link as="button">
<div class="flex items-center">
<span>Clear App's</span>
</div>
</jet-dropdown-link>
</form>
<form v-if="cache.hasOwnProperty('laravel') && helpers.stringToBoolean(cache.laravel)" @submit.prevent="cacheProcess('laravel')">
<jet-dropdown-link as="button">
<div class="flex items-center">
<span>Clear Laravel's</span>
</div>
</jet-dropdown-link>
</form>
</template>
</jet-dropdown>
</div>
<!-- Languages Dropdown -->
<div class="ml-3 relative">
<jet-dropdown align="right" width="auto">
Expand Down Expand Up @@ -68,8 +96,8 @@
</div>

<!-- Teams Dropdown -->
<div class="ml-3 relative">
<jet-dropdown align="right" width="60" v-if="$page.props.jetstream.hasTeamFeatures && teamsEnabled">
<div class="ml-3 relative" v-if="$page.props.jetstream.hasTeamFeatures && teamsEnabled">
<jet-dropdown align="right" width="60">
<template #trigger>
<span class="inline-flex rounded-md">
<button type="button" class="inline-flex items-center px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md text-gray-500 bg-white hover:bg-gray-50 hover:text-gray-700 focus:outline-none focus:bg-gray-50 active:bg-gray-50 transition ease-in-out duration-150">
Expand Down Expand Up @@ -320,6 +348,7 @@
data() {
return {
showingNavigationDropdown: false,
helpers: Helpers,
}
},
Expand Down Expand Up @@ -365,6 +394,12 @@
preserveState: false
})
},
cacheProcess(type) {
this.$inertia.post(route(type == 'laravel' ? 'clear-laravel-cache' : 'clear-cache'), {
preserveState: false
})
},
},
computed: {
Expand All @@ -377,9 +412,10 @@
let languages = computed(() => usePage().props.value.shared.languages)
let apiData = computed(() => usePage().props.value.shared.api_data)
const locale = computed(() => usePage().props.value.locale)
const cache = computed(() => usePage().props.value.shared.cache)
const teamsEnabled = computed(() => usePage().props.value.teams)
return { navigations, apiData, locale, teamsEnabled, languages }
return { navigations, apiData, locale, teamsEnabled, languages, cache }
}
}
</script>
Expand Down
85 changes: 85 additions & 0 deletions src/Controllers/Config/PbCacheController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace Anibalealvarezs\Projectbuilder\Controllers\Config;

use Anibalealvarezs\Projectbuilder\Models\PbCurrentUser;
use Anibalealvarezs\Projectbuilder\Traits\PbControllerTrait;
use Anibalealvarezs\Projectbuilder\Utilities\PbCache;
use Exception;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan;

class PbCacheController
{
use PbControllerTrait;

/**
* Sort model elements
*
* @param Request $request
* @return RedirectResponse
*/
public function clear(Request $request): RedirectResponse
{
if (app(PbCurrentUser::class)->hasPermissionTo('clear cache')) {
try {
PbCache::clearAll();
} catch (Exception $e) {
return $this->redirectResponse(
request: $request,
flashMessage: 'Cache could not be cleared: ' . $e->getMessage(),
withInput: false,
);
}
} else {
return $this->redirectResponse(
request: $request,
flashMessage: 'You are not authorized to clear the cache',
withInput: false,
);
}

return $this->redirectResponse(
request: $request,
flashMessage: 'Cache cleared successfully',
flashStyle: 'success',
withInput: false,
);
}

/**
* Sort model elements
*
* @param Request $request
* @return RedirectResponse
*/
public function clearLaravel(Request $request): RedirectResponse
{
if (app(PbCurrentUser::class)->hasPermissionTo('clear laravel cache')) {
try {
Artisan::call('cache:clear');
} catch (Exception $e) {
return $this->redirectResponse(
request: $request,
flashMessage: 'Laravel\'s cache could not be cleared: ' . $e->getMessage(),
withInput: false,
);
}
} else {
return $this->redirectResponse(
request: $request,
flashMessage: 'You are not authorized to clear the Laravel\'s cache',
withInput: false,
);
}

return $this->redirectResponse(
request: $request,
flashMessage: 'Laravel\'s cache cleared successfully',
flashStyle: 'success',
withInput: false,
);
}

}
33 changes: 28 additions & 5 deletions src/Controllers/Config/PbLocaleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,47 @@
namespace Anibalealvarezs\Projectbuilder\Controllers\Config;

use Anibalealvarezs\Projectbuilder\Models\PbLanguage;
use Anibalealvarezs\Projectbuilder\Traits\PbControllerTrait;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Http\Request;

class PbLocaleController extends Controller
{
use PbControllerTrait;

/**
* Remove the specified resource from storage.
*
* @param Request $request
* @return RedirectResponse
*/
public function update(Request $request): RedirectResponse
{
if (!$language = PbLanguage::findByCode($request->input('locale'))) {
return Redirect::back();
return $this->redirectResponse(
request: $request,
flashMessage: 'The selected language does not exist.',
withInput: false,
);
}

if ($request->session()) {
$request->session()->put('locale', $language->code);
if (!$request->session()) {
return $this->redirectResponse(
request: $request,
flashMessage: 'Current session is not available.',
withInput: false,
);
}

$request->session()->put('locale', $language->code);
app()->setLocale($language->code);

return Redirect::back();
return $this->redirectResponse(
request: $request,
flashMessage: 'Language updated successfully.',
flashStyle: 'success',
withInput: false,
);
}
}
1 change: 1 addition & 0 deletions src/Controllers/Permission/PbPermissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ function() use (&$model, $page, $perpage, $orderby, $field, $order) {
class: 'model_controller',
model: $this->vars->level->names,
modelFunction: 'getList',
pagination: ['page' => $page, 'perpage' => $perpage, 'orderby' => $orderby, 'field' => $field, 'order' => $order],
byRoles: true,
);
$model = $cached['data'];
Expand Down
Loading

0 comments on commit d859471

Please sign in to comment.