Skip to content

Commit

Permalink
1.0 (#24)
Browse files Browse the repository at this point in the history
* Update JS dependencies

* Wip

* Set up javascript tests

* Some refactoring and some tests

* Improve controller testing

* Refactor and test Label

* Update Toggle and related test

* Refactor and add test for Text field

* Wip

* Extract shared styles into Nova-like wrapper

* Extract DefaultSetting layout component and apply to TextSetting

* Update partials and tests

* Rename TextSetting and remove File for now

* Rename config file to `nova-settings-tool`

Technically, fixes #8

* Refactor reading of settings and related tests

* Change package namespace and misc. wip

* Begin refactoring components and related tests

* Update TextareaSetting

* Update ToggleSetting

* Fix toggle setting and key SettingsController response by setting keys

* Rename ambiguous `default` to `placeholder`

* Update writing settings

* Update Code setting and tests

* Capitalize fallback setting labels

* Re-implement panels

* Readme and config updates

* Wip

* Remove File setting for now

* Implement Number setting

* Implement Select setting

* Allow loading settings file from any disk

* Set up GitHub actions

* Assets

* Apply fixes from StyleCI

* Wip

* Wip

* Wip

* Fix default config file

* New screenshot

* Wip
  • Loading branch information
bakerkretzmar authored Sep 29, 2019
1 parent 3f4ed76 commit 6043966
Show file tree
Hide file tree
Showing 50 changed files with 1,142 additions and 778 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CI

on: [push]

jobs:
test:
name: Tests
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v1
with:
fetch-depth: 1

- name: Setup
env:
NOVA_USERNAME: ${{ secrets.NOVA_USERNAME }}
NOVA_PASSWORD: ${{ secrets.NOVA_PASSWORD }}
run: |
composer config http-basic.nova.laravel.com $NOVA_USERNAME $NOVA_PASSWORD
composer install -n --prefer-dist --no-ansi --no-progress --no-suggest --no-scripts
- name: PHPUnit
run: vendor/bin/phpunit --testdox --colors=always

- name: Jest
run: |
npm install
npm run test
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/node_modules
/scratch
/vendor
.DS_Store
.phpunit.result.cache
notes.md
composer.lock
package-lock.json
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to `nova-settings-tool` will be documented in this file.

## 0.3.2 – 2019-06-17
## 0.3.3 – 2019-06-17

- Add support for setting Toggle to be on by default
- Tweak styles to more closely match the rest of Nova
Expand Down
25 changes: 8 additions & 17 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
# Contributing

Contributions are **welcome** and will be fully **credited**.

Please read and understand the contribution guide before creating an issue or pull request.
Contributions are **welcome** and will be fully credited. Please read the contribution guide before creating an issue or pull request.

## Etiquette

This project is open source, and as such, the maintainers give their free time to build and maintain the source code
held within. They make the code freely available in the hope that it will be of use to other developers. It would be
extremely unfair for them to suffer abuse or anger for their hard work.
This project is open source, and as such, the maintainers give their free time to build and maintain the source code held within. They make the code freely available in the hope that it will be of use to other developers. It would be extremely unfair for them to suffer abuse or anger for their hard work.

Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
world that developers are civilized and selfless people.
Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the world that developers are civilized and selfless people.

It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.
It's the duty of the maintainer to ensure that all submissions to the project are of sufficient quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.

## Viability

When requesting or submitting new features, first consider whether it might be useful to others. Open
source projects are used by many developers, who may have entirely different needs to your own. Think about
whether or not your feature is likely to be used by other users of the project.
When requesting or submitting new features, first consider whether it might be useful to others. Open source projects are used by many developers, who may have entirely different needs to your own. Think about whether or not your feature is likely to be used by other users of the project.

## Procedure

Expand All @@ -29,7 +21,6 @@ Before filing an issue:
- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
- Check to make sure your feature suggestion isn't already present within the project.
- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
- Check the pull requests tab to ensure that the feature isn't already in progress.

Before submitting a pull request:

Expand All @@ -40,14 +31,14 @@ Before submitting a pull request:

- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).

<!-- - **Add tests!** - Your patch won't be accepted if it doesn't have tests. -->
- **Add tests!**

- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.

- **Consider the release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.

- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
- **One pull request per feature** - If you want to do multiple things, send multiple pull requests.

- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.

**Happy coding**!
**Happy coding!**
95 changes: 40 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,92 +1,77 @@
A Laravel Nova tool to manage app settings
==========================================
Laravel Nova tool to manage app settings
========================================

[![Latest Version on Packagist](https://img.shields.io/packagist/v/bakerkretzmar/nova-settings-tool.svg?style=flat-square)](https://packagist.org/packages/bakerkretzmar/nova-settings-tool)
[![Total Downloads](https://img.shields.io/packagist/dt/bakerkretzmar/nova-settings-tool.svg?style=flat-square)](https://packagist.org/packages/bakerkretzmar/nova-settings-tool)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)
[![StyleCI](https://github.styleci.io/repos/165178010/shield?branch=master)](https://github.styleci.io/repos/165178010)<!-- Coverage?? -->
[![Latest Version on Packagist](https://img.shields.io/packagist/v/bakerkretzmar/nova-settings-tool.svg?style=flat)](https://packagist.org/packages/bakerkretzmar/nova-settings-tool)
[![Total Downloads](https://img.shields.io/packagist/dt/bakerkretzmar/nova-settings-tool.svg?style=flat)](https://packagist.org/packages/bakerkretzmar/nova-settings-tool)
[![Build](https://github.com/bakerkretzmar/nova-settings-tool/workflows/CI/badge.svg)](https://github.com/bakerkretzmar/nova-settings-tool/actions)
[![StyleCI](https://github.styleci.io/repos/165178010/shield?branch=master&style=flat)](https://github.styleci.io/repos/165178010)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=flat)](https://opensource.org/licenses/MIT)

Store and edit simple app-wide settings right in Nova. Settings are stored as JSON using [`spatie/valuestore`](https://github.com/spatie/valuestore), making them really easy to [pull in and use everywhere else in your app](https://laravel-news.com/global-application-settings).

![Settings Tool screenshot](settings-tool.png)

## Installation

Install the package in any Laravel app that uses [Nova](https://nova.laravel.com) via composer:
Install the package via Composer in any Laravel app using [Nova](https://nova.laravel.com):

```bash
```shell
composer require bakerkretzmar/nova-settings-tool
```

Publish the included default configuration file to `config/settings.php` (optional, see below):
Publish the default configuration file to `config/nova-settings-tool.php`:

```bash
php artisan vendor:publish --tag="settings-tool"
```shell
php artisan vendor:publish --tag="nova-settings-tool"
```

Register the tool with Nova in the `tools` method of your `NovaServiceProvider`:

```php
// in app/Providers/NovaServiceProvider.php

use Bakerkretzmar\SettingsTool\SettingsTool;
use Bakerkretzmar\NovaSettingsTool\SettingsTool;

// ...
// ...

public function tools()
{
return [
new SettingsTool,
];
}
public function tools()
{
return [
new SettingsTool,
];
}
```

## Usage

Settings can be declared using a `settings.php` file in your app's `config` folder. This file lets you specify where your settings are stored, what the tool's title is in Nova's sidebar, the layout of the settings page, and information about the settings themselves.
Settings are declared in a `nova-settings-tool.php` config file. This file specifies where settings are stored, what the tools title is in Novas sidebar, the layout of the settings page, and metadata about the settings themselves.

This package includes a default config file that you can publish and use as a starting point:
A [default config file with some helpful examples](config/nova-settings-tool.php) is included as a starting point:

```bash
php artisan vendor:publish --tag="settings-tool"
```

The [default config](config/settings.php) contains examples that should be pretty self-explanatory, and lots of comments in case they aren't.

Each item in the `panels` array is rendered as its own 'group' of settings, like a panel on one of Nova's detail views. Each panel has a name and contains some settings. Each setting can optionally have a description and a link to more information (e.g. docs). Only the setting's key and value are actually stored in your `settings.json` file.

There are four available setting types:

| Type... | ...displays |
| :--------- | :--------------------- |
| `toggle` | Boolean |
| `text` | Single-line text input |
| `textarea` | Multi-line text input |
| `code` | Code snippet editor |
| `file` | Single file input |

All the strings hard-coded in this package (like in the "Save" button), as well as any you pass to it (like the `name` of any of your settings), can easily be translated using [Laravel's built-in localization features](https://laravel.com/docs/localization#using-translation-strings-as-keys).

## Testing

```bash
composer test
```
Each item in the `settings` array is rendered as an input with a label and help text, similar to one of Nova’s fields. Settings can also be grouped into panels, to separate them visually.

I'm new to testing and would welcome testing-related PRs.
The settings’ actual values are stored as JSON at the location specified in the config file—`storage/app/settings.json` by default.

## Changelog
There are currently six available setting types:

Please see the [CHANGELOG](CHANGELOG.md) for information about what has changed recently.
- `text`: Single-line text input
- `textarea`: Multi-line text input
- `toggle`: Boolean switch
- `code`: [CodeMirror](https://codemirror.net/) text editor
- `number`: Number input
- `select`: Single-select dropdown

## Contributing
All strings in this package, and any you pass to it, can easily be translated using [Laravel’s built-in localization features](https://laravel.com/docs/localization#using-translation-strings-as-keys).

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## Roadmap

## Security
The following features are planned or in development:

If you discover any security related issues, please email <[email protected]> instead of using the issue tracker.
- `color` setting type
- `date` setting type
- `file` setting type
- setting validation

## License
---

This package is licensed under the MIT License (MIT). Please see the [LICENSE](LICENSE.md) for details.
[CHANGELOG](CHANGELOG.md)[CONTRIBUTING](CONTRIBUTING.md)[LICENSE](LICENSE.md)
15 changes: 6 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bakerkretzmar/nova-settings-tool",
"description": "A Laravel Nova tool to manage app settings.",
"description": "A Laravel Nova tool to manage application settings.",
"authors": [
{
"name": "Jacob Baker-Kretzmar",
Expand Down Expand Up @@ -28,29 +28,26 @@
"spatie/valuestore": "^1.2"
},
"require-dev": {
"orchestra/testbench": "^3.7",
"phpunit/phpunit": "^7.5"
"orchestra/testbench": "^4.0",
"phpunit/phpunit": "^8.3"
},
"autoload": {
"psr-4": {
"Bakerkretzmar\\SettingsTool\\": "src/"
"Bakerkretzmar\\NovaSettingsTool\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Bakerkretzmar\\SettingsTool\\Tests\\": "tests"
"Bakerkretzmar\\NovaSettingsTool\\Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"providers": [
"Bakerkretzmar\\SettingsTool\\SettingsToolServiceProvider"
"Bakerkretzmar\\NovaSettingsTool\\SettingsToolServiceProvider"
]
}
},
"scripts": {
"test": "phpunit"
},
"config": {
"sort-packages": true
},
Expand Down
86 changes: 86 additions & 0 deletions config/nova-settings-tool.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Settings Path
|--------------------------------------------------------------------------
|
| Path to the JSON file where settings are stored.
|
*/

'path' => storage_path('app/settings.json'),

/*
|--------------------------------------------------------------------------
| Sidebar Label
|--------------------------------------------------------------------------
|
| The text that Nova displays for this tool in the navigation sidebar.
|
*/

'sidebar-label' => 'Settings',

/*
|--------------------------------------------------------------------------
| Settings
|--------------------------------------------------------------------------
|
| The good stuff :). Each setting defined here will render a field in the
| tool. The only required key is `key`, other available keys include `type`,
| `label`, `help`, `placeholder`, `language`, and `panel`.
|
*/

'settings' => [

[
'key' => 'twitter_url',
'label' => 'Twitter Profile',
'panel' => 'Social',
],

[
'key' => 'feature_42',
'label' => 'Feature 42',
'type' => 'toggle',
'help' => 'For the upcoming release. <a href="/docs#feature_42">Read more here.</a>',
],

[
'key' => 'welcome',
'label' => 'Welcome Message',
'type' => 'textarea',
'help' => 'Greeting for new users on their first login.',
],

[
'key' => 'snippet',
'label' => 'Tracking Snippet',
'type' => 'code',
'language' => 'htmlmixed',
'help' => 'Analytics snippet to add to all marketing pages.',
],

[
'key' => 'theme',
'label' => 'Default App Theme',
'type' => 'select',
'options' => [
'dark' => 'Dark theme',
'light' => 'Light theme',
],
],

[
'key' => 'timeout',
'type' => 'Number',
'label' => 'Timeout (min.)',
],

],

];
Empty file removed dist/css/tool.css
Empty file.
2 changes: 1 addition & 1 deletion dist/js/tool.js

Large diffs are not rendered by default.

Loading

0 comments on commit 6043966

Please sign in to comment.