Files
librenms-librenms/app/Plugins/ExamplePlugin/resources/views/settings.blade.php
Kevin Zink 98ed6bb9dc New plugin system based on Laravel Package Development (#12998)
* use Blade view and Eloquent models for plugins

* move views

* fix style

* fix style

* revert mistake

* Update Plugin.php

delete test property "name"

* rename plugin function to settings

* last but not least - rename in Test.php

* Rename Test to Example

* fix typo

* fix style

* fix style

* fix style

* fix style - I hate tabs...

* Extract view calls

* fix method calls and style

* Move Models the the abstract class

* fix style

* Convert to traits

* Change the Example description

* Fix style

* Fix style

* Fix style

* Convert plugin function to Model static methods and delete .inc.php

* fix style

* fix style

* Use scope

* final methods blows up legacy code

* Config > \LibreNMS\Config

* convert the static string to a static method

* Correct placement in the page

* fix tabs

* fix style

* Rename from tait to hook

to make it easier to understand and be complient

* rename file

* Typo

* Started to change the docu

* change to a more usefully Device_Overview example

* and activate of course

* PluginManager

* fix .gitignore

* only php files in the root folder

* corrected .gitignore with all files :)

* Rename the Hooks and ExampleClass for better readability

* Fix style

* Fix style

* Exception handling (especially if DB is not present)

* Fix style and update schema

* fix indentation

* actually correct indent

* fix migration collation check include utf8mb4_bin

* stop phpstan whining

* A view lines documentation

* add typeHints

* Allow return null on handle

* lint

* fix return types

* fix logic of column collation check

* Fix MenuEntryHook

* switch to longtext instead of json type for now :D

* try phpstan on PHP 7.3

* set phpstan target version to 7.3

* all the typehints

* optional

* more

* Use namespace to prevent view collisions
disambiguate plugin and hook
no magic guessing of names in PluginManager, bad assumptions
remove unused plugins from the DB

* cleanup plugin menu

* cleanup on shutdown and ignore but log query error on cleanup

* instanceof must be called against an instance

* Allow multiple hooks per plugin

* Port plugin ui code to Laravel

* page instead of settings for v1 plugins

* actually working settings pages
a little url cleanup plugin/admin -> plugin/settings

* fix style

* Add page hook

* PHPstan

* Try to fix Illuminate\Http\RedirectResponse

* typehint

* Rewrite the doc

* Fix style

Co-authored-by: PipoCanaja <38363551+PipoCanaja@users.noreply.github.com>
Co-authored-by: Tony Murray <murraytony@gmail.com>
2021-10-19 06:53:28 -05:00

95 lines
3.1 KiB
PHP

<div style="margin: 15px;">
<h4>{{ $plugin_name }} Settings:</h4>
<!-- Example of free-form settings, real plugins should use specific fields -->
<!-- All input fields should be in the settings array (settings[]) -->
<form method="post" style="margin: 15px">
@csrf
<table id="settings-table">
<tr>
<th>Name</th>
<th>Value</th>
</tr>
@forelse($settings as $name => $value)
<tr id="settings-row-{{ $name }}">
<td>
{{ $name }}
</td>
<td>
<input id="value-{{ $value }}" type="text" name="settings[{{ $name }}]" value="{{ $value }}">
<button type="button" onclick="deleteSetting('{{ $name }}')" class="delete-button"><i class="fa fa-trash"></i></button>
</td>
</tr>
@empty
<tr>
<td>No settings yet</td>
</tr>
@endforelse
</table>
<div style="margin: 15px 0;">
<input id="new-setting-name" style="display: inline-block;" type="text" placeholder="Name">
<input id="new-setting-value" style="display: inline-block;" type="text" placeholder="Value">
<button type="button" onclick="newSetting()">Add Setting</button>
</div>
<div>
<button type="submit">Save</button>
</div>
</form>
</div>
<script>
function newSetting() {
var name = document.getElementById('new-setting-name').value;
var value = document.getElementById('new-setting-value').value;
var existing = document.getElementById('value-' + name);
if (existing) {
existing.value = value;
} else {
// insert setting
var newValue = document.createElement('input');
newValue.id = 'value-' + name;
newValue.type = 'text';
newValue.name = 'settings[' + name + ']';
newValue.value = value;
var deleteButton = document.createElement('button');
deleteButton.type = 'button';
deleteButton.className = 'delete-button';
deleteButton.onclick = () => deleteSetting(name);
var deleteIcon = document.createElement('i');
deleteIcon.className = 'fa fa-trash';
deleteButton.appendChild(deleteIcon);
var row = document.createElement('tr');
row.id = 'settings-row-' + name;
var col1 = document.createElement('td');
var col2 = document.createElement('td');
col1.innerText = name;
col2.appendChild(newValue);
col2.appendChild(document.createTextNode(' '));
col2.appendChild(deleteButton);
row.appendChild(col1);
row.appendChild(col2);
document.getElementById('settings-table').appendChild(row);
}
document.getElementById('new-setting-name').value = '';
document.getElementById('new-setting-value').value = '';
}
function deleteSetting(name) {
document.getElementById('settings-row-' + name).remove();
}
</script>
<style>
#settings-table td, #settings-table th {
padding: .2em;
}
.delete-button {
padding: 3px 5px;
}
</style>