• Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
v3.5.2 Latest
Buy Hosting

New Settings Framework

Scheduled Pinned Locked Moved NodeBB Development
7 Posts 4 Posters 2.7k Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • frissdiegurkeF Offline
    frissdiegurkeF Offline
    frissdiegurke Plugin & Theme Dev
    wrote on last edited by
    #1

    Since many plugin devs may not have noticed the new utility I recently added (PR) to the core that may be helpful to plugin devs, here a short brief:

    I've added a new Settings-Framework that provides the possibility to save whole objects within the database (gets stringified behind the scene).
    The object-structure gets updated whenever it and the version (provided within server-side constructor) change without any work on your side.
    Related to the server-side settings-module you can refer to the single (nested) object-attributes within client-side ACP templates.
    The new client-side settings-methods are settings.sync and settings.persist rather than the old settings.load and settings.save (left there for backwards compatibility).
    Build-in support for many input-types, arrays, selects, textareas, keyboard-keys but easy to expand with your own object-/input-types.

    If you come across an common used field-type you may create a new PR to get it into core 🙂
    (e.g. radio-button support is missing I just realize)

    For a whole (at least more complete than above) overview about what I'm talking see the docs 😉

    As always you have the choice (except you're using windows 😛 ) to put your complaints below or at /dev/null

    A 1 Reply Last reply
    3
  • A Offline
    A Offline
    a_5mith
    replied to frissdiegurke on last edited by
    #2

    @frissdiegurke

    Could this, in theory, be used to say, allow someone to pick their own theme❓ 🙂

    frissdiegurkeF 1 Reply Last reply
    0
  • frissdiegurkeF Offline
    frissdiegurkeF Offline
    frissdiegurke Plugin & Theme Dev
    replied to a_5mith on last edited by
    #3

    @a_5mith Nope 😛 It's just a more powerful way for plugin devs to save the admin-settings in database 😉

    A 1 Reply Last reply
    0
  • A Offline
    A Offline
    a_5mith
    replied to frissdiegurke on last edited by
    #4

    @frissdiegurke Awhhh. 😞 Good job either way buddy. 👍

    1 Reply Last reply
    0
  • SchamperS Offline
    SchamperS Offline
    Schamper Plugin & Theme Dev
    wrote on last edited by Schamper
    #5

    Looks like I have a shitload of refactoring to do for the Shoutbox... Will start using this with the poll plugin though!

    Any plugins that already utilize this new framework that I can "steal" from? 😛

    Edit: nvm, didn't scroll down far enough.

    1 Reply Last reply
    0
  • BriB Offline
    BriB Offline
    Bri Community Rep
    wrote on last edited by
    #6

    Hello @frissdiegurke,

    I've implemented the "new" (I guess, 7 months late) Settings framework in my plugin, but I don't seem to have it working all the way. I know something has been saved to the DB because the panel for my the imgbed's settings reflects it, but I'm still getting default values when I try to pull them out with settings.get()

    For example:
    Structure:

    var defaultSettings = {
    		booleans: {
    			hasMarkdown: true
    		},
    		strings: {
    			extensions: 'jpg,jpeg,gif,gifv,png,svg'
    		}
    	};
    

    Save:

    $('#save').click(function(event) {
    			event.preventDefault();
    			// TODO clean and organize extensions
    			settings.persist('imgbed', wrapper, function persistImgbed() {
    				socket.emit('admin.settings.syncImgbed');
    			})
    		});
    

    Call:

    var	userExt = settings.get().strings.extensions;
    

    userExt still reflects the original defaults....

    frissdiegurkeF 1 Reply Last reply
    0
  • frissdiegurkeF Offline
    frissdiegurkeF Offline
    frissdiegurke Plugin & Theme Dev
    replied to Bri on last edited by
    #7

    @BDHarrington7
    If you're referring to the master-branch the problem is that you cache the value of

    var	userExt = settings.get('strings.extensions');
    

    (and some further operations) once at plugin-start and don't refresh those values after settings.sync(); (within a callback).

    So you need to re-calculate the regex variable within a callback for settings.sync.

    1 Reply Last reply
    0

Copyright © 2023 NodeBB | Contributors
  • Login

  • Don't have an account? Register

  • Login or register to search.
Powered by NodeBB Contributors
  • First post
    Last post
0
  • Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development