suggestions.adoc 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. [#arg-suggestions]
  2. = Suggestions
  3. Argument inputs can also have "suggested" values, which can make it quicker to type commonly used options. The way that these are displayed will vary depending on your browser, as they are implemented as a modern HTML5 browser feature called "datalist".
  4. Suggestions are configured like this;
  5. [source,yaml]
  6. .Configuration example of input suggestions
  7. ----
  8. actions:
  9. - title: Restart Docker Container
  10. icon: restart
  11. shell: docker restart {{ container }}
  12. arguments:
  13. - name: container
  14. title: Container name
  15. suggestions:
  16. - plex:
  17. - graefik:
  18. - grafana:
  19. - wifi-controller: WiFi Controller
  20. - firewall-controller: Firewall Controller
  21. ----
  22. In the examples above, there are 5 suggestions. The first 3 suggestions contain a suggestion with a blank title. The last 2 suggestions contain a human readable title (eg: `wifi-controller` is the suggestion, and `WiFi Controller` is the title).
  23. NOTE: `suggestions:` is a yaml **map**, not a **list**. If you leave the title empty you must still end the suggestion with a ":".
  24. == Examples
  25. .Screenshot of input suggestions with Firefox on Linux.
  26. image::arg-suggestions-firefox.png[]
  27. .Screenshot of input suggestions with Chrome on Linux.
  28. image::arg-suggestions-chrome.png[]
  29. [#suggestions-browser-key]
  30. == Browser-Stored Suggestions
  31. In addition to static suggestions defined in your configuration, OliveTin can remember values that users have previously entered and offer them as suggestions for future use. This is enabled using the `suggestionsBrowserKey` property.
  32. When a user submits an action with a `suggestionsBrowserKey` configured, the entered value is saved in the browser's local storage. The next time the user opens the same form (or any form with the same key), those previously-used values appear as suggestions alongside any static suggestions.
  33. === Basic Usage
  34. [source,yaml]
  35. ----
  36. actions:
  37. - title: SSH to Server
  38. shell: ssh {{ hostname }}
  39. arguments:
  40. - name: hostname
  41. title: Hostname
  42. description: Server to connect to
  43. suggestionsBrowserKey: ssh-hosts
  44. ----
  45. With this configuration:
  46. 1. The first time a user runs this action and enters `server1.example.com`, that value is saved
  47. 2. The next time they open the action, `server1.example.com` appears as a suggestion
  48. 3. Each new unique value they enter is added to the suggestions list
  49. === Sharing Suggestions Across Arguments
  50. Multiple arguments can share the same `suggestionsBrowserKey`, allowing suggestions to be reused across different actions or arguments. This is useful when the same type of value is used in multiple places.
  51. [source,yaml]
  52. ----
  53. actions:
  54. - title: Ping Host
  55. shell: ping -c 4 {{ host }}
  56. arguments:
  57. - name: host
  58. title: Hostname
  59. suggestionsBrowserKey: network-hosts
  60. - title: SSH to Host
  61. shell: ssh {{ server }}
  62. arguments:
  63. - name: server
  64. title: Server
  65. suggestionsBrowserKey: network-hosts
  66. - title: Traceroute
  67. shell: traceroute {{ destination }}
  68. arguments:
  69. - name: destination
  70. title: Destination
  71. suggestionsBrowserKey: network-hosts
  72. ----
  73. In this example, all three actions share the `network-hosts` key. If a user enters `192.168.1.100` in the Ping action, that value will also appear as a suggestion in the SSH and Traceroute actions.
  74. === Combining Static and Browser Suggestions
  75. You can use both static `suggestions` and `suggestionsBrowserKey` together. Both sets of suggestions will be displayed to the user:
  76. [source,yaml]
  77. ----
  78. actions:
  79. - title: Deploy to Environment
  80. shell: /opt/scripts/deploy.sh {{ environment }}
  81. arguments:
  82. - name: environment
  83. title: Environment
  84. suggestions:
  85. production: Production Server
  86. staging: Staging Server
  87. development: Development Server
  88. suggestionsBrowserKey: deploy-environments
  89. ----
  90. This gives users quick access to the predefined environments while also remembering any custom environments they've deployed to.
  91. === Behavior Notes
  92. * **Password and sensitive fields**: Values from `password`, `checkbox`, and `confirmation` type arguments are never saved to browser storage
  93. * **Empty values**: Empty or blank values are not saved as suggestions
  94. * **Local storage**: Suggestions are stored in the browser's `localStorage` under keys prefixed with `olivetin-suggestions-`
  95. * **Per-browser**: Since suggestions use browser local storage, they are specific to each browser and device - they don't sync across devices or browsers
  96. * **Clearing suggestions**: Users can clear their saved suggestions by clearing their browser's local storage for the OliveTin site
  97. == Browser Support
  98. `datalist` is widely supported now-a-days, but Firefox on Android notably lacks support; https://caniuse.com/datalist . See the upstream bug here; https://bugzilla.mozilla.org/show_bug.cgi?id=1535985 .