|
| 1 | +--- |
| 2 | +title: Extending the user dashboard wrapper |
| 3 | +description: Extend the Pterodactyl user dashboard using the Laravel blade wrapper |
| 4 | +author: Emma |
| 5 | +category: dev |
| 6 | +thumbnail: dashboard.jpeg |
| 7 | +--- |
| 8 | + |
| 9 | +::card |
| 10 | +The dashboard wrapper should not be your first choice for dashboard extensibility. It's quite limited and can cause weird issues with the React DOM. Use [Components.yml](/docs/configs/componentsyml) instead if available for your extension's use case. |
| 11 | +:: |
| 12 | + |
| 13 | +## Introduction |
| 14 | + |
| 15 | +Blueprint's `dashboard.wrapper` [conf.yml](/docs/configs/confyml#dashboardwrapper) bind extends the user-side dashboard a `.blade.php` view. Dashboard wrappers can be used for quite a lot of purposes. For this guide, we'll be adding a (useless) "barrel roll" button to the Pterodactyl user-side dashboard. |
| 16 | + |
| 17 | +## Create a basic dashboard wrapper |
| 18 | + |
| 19 | +Create a file named `wrapper.blade.php` and bind it to `dashboard.wrapper` in your extension's [conf.yml](/docs/configs/confyml). |
| 20 | + |
| 21 | +```yaml [conf.yml] |
| 22 | +dashboard: |
| 23 | + # bind dashboard.wrapper to the wrapper.blade.php |
| 24 | + # file you created: |
| 25 | + wrapper: 'wrapper.blade.php' |
| 26 | +``` |
| 27 | +
|
| 28 | +In your `dashboard.wrapper`, add a simple button and run `blueprint -build` to apply your changes. |
| 29 | + |
| 30 | +<!-- prettier-ignore --> |
| 31 | +```html [wrapper.blade.php] |
| 32 | +<button style="background: black;"> |
| 33 | + Example button |
| 34 | +</button> |
| 35 | +``` |
| 36 | + |
| 37 | +Visit your Pterodactyl instance in your browser, it should look similar to this: |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +## Doing a barrel roll |
| 42 | + |
| 43 | +Alright, now that we've got ourselves a button, let's replace "Example button" with something else and give it an identifier. |
| 44 | + |
| 45 | +::card |
| 46 | +We're prefixing the buttons `id=` with the `{identifier}` [placeholder](/docs/concepts/placeholders#identifier). This prevents conflicts with other extensions when two extensions assign the same identifier for different elements. |
| 47 | + |
| 48 | +Say, for example, both extensions "foo" and "bar" have an element with the identifier `fizz`. Extension "foo" wants to modify it's own `fizz` element, and does so via JavaScript, there's a non-zero chance that extension "bar"s element gets modified. |
| 49 | + |
| 50 | +_tldr; don't give your element IDs generic names_ |
| 51 | +:: |
| 52 | + |
| 53 | +<!-- prettier-ignore --> |
| 54 | +```html [wrapper.blade.php] |
| 55 | +<button id="{identifier}-barrel" style="background: black;"> |
| 56 | + Do a barrel roll! |
| 57 | +</button> |
| 58 | +``` |
| 59 | + |
| 60 | +### Running a function on button press |
| 61 | + |
| 62 | +We can now create ourselves a JavaScript function, then make `{identifier}-barrel` run it whenever it's pressed. |
| 63 | + |
| 64 | +::card |
| 65 | +The same conflict potential as mentioned for the `id=` can happen here too. Adding placeholders for function names, however, may break syntax highlighting. Either bite the bullet on syntax highlighting, or name your function something unique. |
| 66 | +:: |
| 67 | + |
| 68 | +<!-- prettier-ignore --> |
| 69 | +```html [wrapper.blade.php] |
| 70 | +<script> |
| 71 | +function doBarrelRoll() { |
| 72 | + // something happened?! |
| 73 | + console.log("something happened!!") |
| 74 | +} |
| 75 | +</script> |
| 76 | +``` |
| 77 | + |
| 78 | +<!-- prettier-ignore --> |
| 79 | +```diff [wrapper.blade.php] |
| 80 | +- <button id="{identifier}-barrel" style="background: black;"> |
| 81 | ++ <button id="{identifier}-barrel" onclick="doBarrelRoll()" style="background: black;"> |
| 82 | +``` |
| 83 | + |
| 84 | +### Adding an animation |
| 85 | + |
| 86 | +We'll use a CSS animation to animate rotating the page. Just like elements and scripts, you can also add stylesheets to your `dashboard.wrapper`. |
| 87 | + |
| 88 | +::card |
| 89 | +Stylesheets added inside of `<style />` tags in `dashboard.wrapper` are slightly different to the `dashboard.css` stylesheet. The `dashboard.css` stylesheet is bundled with the React application, the `dashboard.wrapper` is not. |
| 90 | + |
| 91 | +For styling elements made in `dashboard.wrapper`, you should use `dashboard.wrapper`. For styling elements from the React application, you should use `dashboard.css`. |
| 92 | +:: |
| 93 | + |
| 94 | +<!-- prettier-ignore --> |
| 95 | +```html [wrapper.blade.php] |
| 96 | +<style> |
| 97 | +@keyframes barrelRoll { |
| 98 | + 0% { transform: rotate(0deg); } |
| 99 | + 50% { transform: rotate(360deg); } |
| 100 | + 100% { transform: rotate(0deg); } |
| 101 | +} |
| 102 | +
|
| 103 | +.barrel-roll { |
| 104 | + animation: barrelRoll 1s ease-in-out; |
| 105 | +} |
| 106 | +</style> |
| 107 | +``` |
| 108 | + |
| 109 | +This CSS animation will rotate any element with the `barrel-roll` class. We'll use JavaScript to apply this class to the `body` element when `{identifier}-barrel` is pressed. |
| 110 | + |
| 111 | +### Applying the animation class |
| 112 | + |
| 113 | +Update the JavaScript function to apply the `barrel-roll` class to the `body` element when the `doBarrelRoll()` function is called. |
| 114 | + |
| 115 | +<!-- prettier-ignore --> |
| 116 | +```html [wrapper.blade.php] |
| 117 | +<script> |
| 118 | +function doBarrelRoll() { |
| 119 | + const body = document.body; |
| 120 | + body.classList.add('barrel-roll'); |
| 121 | +
|
| 122 | + setTimeout(() => { |
| 123 | + body.classList.remove('barrel-roll'); |
| 124 | + }, 1000); |
| 125 | +} |
| 126 | +</script> |
| 127 | +``` |
| 128 | + |
| 129 | +## Final results |
| 130 | + |
| 131 | +Apply your changes using `blueprint -build` and visit your panel in your browser. The final result should look somewhat like this: |
| 132 | + |
| 133 | +:prose-video-player{src='/img/guides/barrelroll.mp4'} |
0 commit comments