super_settings 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83d20aa4f55a73597f12a1fed76db8d01bd81ec128b5208ed60ff8acc82a273b
4
- data.tar.gz: c2bf00fe10c179d9ddc6849fbc6b2be2eb511b8132463a143e202ea42996581b
3
+ metadata.gz: a7e5362ee5262805e4178be0485c0a3fba4d3f5468a793b8819abd1bb0322399
4
+ data.tar.gz: 1051e29b721ffb12a431b14ad660b13b25673abd766f7f987838030f665807cc
5
5
  SHA512:
6
- metadata.gz: 6fec2ccebbc1f84a7bb1878c4b6ea5f9fb5b36eacb0fddc3fcc2520ce3e738d895bf540be762a225aab970cc102287f5598b99588f4ad82494b726306b3f4601
7
- data.tar.gz: 4d9d0641b7b47a845c26f6e72fccdd996c81b5e5f25c88d93b9148ca1c1767fe4c4d97681b558af0490028cbac3ac9e1ac447271b971829f2e8f3ea2a11311fd
6
+ metadata.gz: f29c06dc13802640cb1b7edd51b2fc8d8f2ed01f1e354fc6fe1eb50f58c32baa331ebb21fed9c42858c86a4d0a8a1b5a220aa1ca6bd1fe1c7a17fe2217cbcdf5
7
+ data.tar.gz: e5f5d481458271761744533629e504c93b8c4a3b4b70da048881ac1b272de1f8266e1da10444a55d5af7c60415c2de11eba9ba33fdf8f9d637ff3e33adc7b616
data/CHANGELOG.md CHANGED
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## 2.0.1
8
+
9
+ ### Added
10
+
11
+ - Added support for targeting a editing a specific setting in the web UI by passing `#edit=key` in the URL hash.
12
+
7
13
  ## 2.0.0
8
14
 
9
15
  ### Added
data/README.md CHANGED
@@ -24,19 +24,25 @@ Key features include:
24
24
 
25
25
  For projects that require a combination of runtime settings, environment variables, and YAML files, SuperSettings integrates seamlessly with [ultra_settings](https://github.com/bdurand/ultra_settings), creating a flexible and powerful configuration system.
26
26
 
27
- ## Usage
27
+ ## Table Of Contents
28
+
29
+ - [Usage](#usage)
30
+ - [Getting Value](#getting-values)
31
+ - [Hashes](#hashes)
32
+ - [Defaults](#defaults)
33
+ - [Caching](#caching)
34
+ - [Data Model](#data-model)
35
+ - [Storage Engines](#storage-engines)
36
+ - [Web UI](#web-ui)
37
+ - [REST API](#rest-api)
38
+ - [Authentication](#authentication)
39
+ - [Rails Engine](#rails-engine)
40
+ - [Configuration](#configuration)
41
+ - [Installation](#installation)
42
+ - [Contributing](#contributing)
43
+ - [License](#license)
28
44
 
29
- - [Getting Value](#getting-values)
30
- - [Hashes](#hashes)
31
- - [Defaults](#defaults)
32
- - [Caching](#caching)
33
- - [Data Model](#data-model)
34
- - [Storage Engines](#storage-engines)
35
- - [Web UI](#web-ui)
36
- - [REST API](#rest-api)
37
- - [Authentication](#authentication)
38
- - [Rails Engine](#rails-engine)
39
- - [Configuration](#configuration)
45
+ ## Usage
40
46
 
41
47
  ### Getting Values
42
48
 
@@ -175,6 +181,8 @@ You can change the layout used by the Web UI. However, if you do this, you will
175
181
 
176
182
  It is not required to use the bundled Web UI. You can implement your own UI using the `SuperSettings::Setting` model.
177
183
 
184
+ You can link directly to editing a setting by passing `#edit=key` in the URL hash. This will open the Web UI with the setting with the key `key` selected for editing.
185
+
178
186
  #### REST API
179
187
 
180
188
  You can mount a REST API for exposing and managing the settings. This API is required for the Web UI and is mounted along with the Web UI. The REST interface is documented in the `SuperSettings::RestAPI` class.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0
1
+ 2.0.1
@@ -232,9 +232,12 @@
232
232
  }
233
233
 
234
234
  // Create a table row with form elements for creating a new setting.
235
- function newSettingRow() {
235
+ function newSettingRow(key) {
236
+ if (!key) {
237
+ key = "";
238
+ }
236
239
  const randomId = "new" + Math.floor((Math.random() * 0xFFFFFFFFFFFFFF)).toString(16);
237
- const setting = {id: randomId, key: "", value: "", value_type: "string", new_record: true}
240
+ const setting = {id: randomId, key: key, value: "", value_type: "string", new_record: true}
238
241
  row = editSettingRow(setting);
239
242
  return row;
240
243
  }
@@ -456,6 +459,33 @@
456
459
  return found;
457
460
  }
458
461
 
462
+ // Find a setting by key.
463
+ function findSettingByKey(key) {
464
+ let found = null;
465
+ activeSettings.forEach(function(setting) {
466
+ if (setting.key === key) {
467
+ found = setting;
468
+ return;
469
+ }
470
+ });
471
+ return found;
472
+ }
473
+
474
+ // Add a new setting.
475
+ function addSetting(key) {
476
+ const row = addRowToTable(newSettingRow(key));
477
+ row.querySelector(".super-settings-key input").focus();
478
+ }
479
+
480
+ function editSetting(setting) {
481
+ const row = addRowToTable(editSettingRow(setting));
482
+ if (row.querySelector(".super-settings-value .js-date-input")) {
483
+ row.querySelector(".super-settings-value .js-date-input").focus();
484
+ } else {
485
+ row.querySelector(".super-settings-value .js-setting-value").focus();
486
+ }
487
+ }
488
+
459
489
  /*** Event Listeners ***/
460
490
 
461
491
  // Listener for showing the setting history modal.
@@ -542,23 +572,17 @@
542
572
  }
543
573
 
544
574
  // Listener for the add setting button.
545
- function addSetting(event) {
575
+ function addSettingListener(event) {
546
576
  event.preventDefault();
547
- const row = addRowToTable(newSettingRow());
548
- row.querySelector(".super-settings-key input").focus();
577
+ addSetting();
549
578
  }
550
579
 
551
580
  // Listener for the edit setting button.
552
- function editSetting(event) {
581
+ function editSettingListener(event) {
553
582
  event.preventDefault();
554
583
  const id = event.target.closest("tr").dataset.id;
555
- const setting = findSetting(id);
556
- const row = addRowToTable(editSettingRow(setting));
557
- if (row.querySelector(".super-settings-value .js-date-input")) {
558
- row.querySelector(".super-settings-value .js-date-input").focus();
559
- } else {
560
- row.querySelector(".super-settings-value .js-setting-value").focus();
561
- }
584
+ setting = findSetting(id);
585
+ editSetting(setting);
562
586
  }
563
587
 
564
588
  // Listener for the restore setting button.
@@ -656,6 +680,18 @@
656
680
  window.location = url;
657
681
  }
658
682
 
683
+ // Open the setting if the URL hash includes #edit=setting.
684
+ function fetchEditHash() {
685
+ const hash = window.location.hash;
686
+ if (hash.startsWith("#edit=")) {
687
+ const name = hash.replace("#edit=", "");
688
+ window.location.hash = "";
689
+ return name;
690
+ } else {
691
+ return null;
692
+ }
693
+ }
694
+
659
695
  // Support integration into single page applications where OAuth2 access tokens are used.
660
696
  // The access token can be passed either in the access_token query parameter per the
661
697
  // OAuth2 standard, or in the URL hash. Passing it in the hash will prevent it from ever
@@ -694,7 +730,7 @@
694
730
  // Bind event listeners for setting controls on a setting table row.
695
731
  function bindSettingControlEvents(parent) {
696
732
  addListener(parent.querySelectorAll(".js-remove-setting"), "click", removeSetting);
697
- addListener(parent.querySelectorAll(".js-edit-setting"), "click", editSetting);
733
+ addListener(parent.querySelectorAll(".js-edit-setting"), "click", editSettingListener);
698
734
  addListener(parent.querySelectorAll(".js-restore-setting"), "click", restoreSetting);
699
735
  addListener(parent.querySelectorAll(".js-show-history"), "click", showHistoryModal);
700
736
  addListener(parent.querySelectorAll(".js-no-op"), "click", noOp);
@@ -802,11 +838,19 @@
802
838
  }
803
839
  }
804
840
 
805
- function fetchActiveSettings() {
841
+ function fetchActiveSettings(editKey) {
806
842
  SuperSettingsAPI.fetchSettings(function(settings_hash) {
807
843
  const settings = settings_hash["settings"];
808
844
  activeSettings = settings;
809
845
  renderSettingsTable(settings);
846
+ if (editKey) {
847
+ const setting = findSettingByKey(editKey);
848
+ if (setting) {
849
+ editSetting(setting);
850
+ } else {
851
+ addSetting(editKey);
852
+ }
853
+ }
810
854
  enableSaveButton();
811
855
  });
812
856
  }
@@ -817,18 +861,20 @@
817
861
  storeAccessToken();
818
862
 
819
863
  addListener(document.querySelector("#super-settings-filter"), "input", filterListener);
820
- addListener(document.querySelector("#super-settings-add-setting"), "click", addSetting);
864
+ addListener(document.querySelector("#super-settings-add-setting"), "click", addSettingListener);
821
865
  addListener(document.querySelector("#super-settings-discard-changes"), "click", refreshPage);
822
866
  addListener(document.querySelector("#super-settings-save-settings"), "click", updateSettings);
823
867
  addListener(document.querySelector("#super-settings-modal"), "click", closeModal);
824
868
  addListener(document.querySelectorAll(".super-settings-sort-control"), "click", setSortOrder);
825
869
 
870
+ const editKey = fetchEditHash();
871
+
826
872
  const queryParams = new URLSearchParams(window.location.search);
827
873
  applyFilter(queryParams.get("filter"));
828
874
 
829
875
  selectSortElement(document.querySelector(".super-settings-sort-control[data-selected=true]"), true);
830
876
 
831
- fetchActiveSettings();
877
+ fetchActiveSettings(editKey);
832
878
 
833
879
  window.onbeforeunload = promptUnsavedChanges;
834
880
  })
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super_settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-12 00:00:00.000000000 Z
11
+ date: 2024-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler