simov / express-admin

MySQL, MariaDB, PostgreSQL, SQLite admin for Node.js
MIT License
1.18k stars 223 forks source link

Default theme #39

Closed ajax13 closed 10 years ago

ajax13 commented 10 years ago

Hi again,

how can i change the default theme with another theme to be the new default one.(but not with the theme button), thx

simov commented 10 years ago

This is done entirely in the browser.

You can add this into a custom js file:

$(function () {
    if (!window.localStorage.getItem('theme'))
        $('#theme a:contains(Flatly)').trigger('click');
});

Keep in mind that there is a bug inside the current release, so what would normally work:

"some-key": {
    "public": {
        "local": {
            "path": "/absolute/path/to/your/custom/stuff",
            "js": [
                "/default-theme.js"
            ]
        }
    }
}

will throw an error until the new version is out, so you need to add a dummy app key as well:

"app": {
    "path"  : "/absolute/path/to/your/custom/app",
    "slug": "ddd",
    "verbose": "...",
    "mainview": {
        "show": false
    }
}

Or if you already have some custom view defined inside the custom.json file you can just add your default-theme.js file there. That's why the error with the missing app key was missed in the first place - you can have app with public key or just only one of them. Refer to the documentation for the proper json structure - http://simov.github.io/express-admin-site/#customjson

ajax13 commented 10 years ago

thx,

to working well for me i add also another line in the `js` file:
   $(function () {
    if (!window.localStorage.getItem('theme'))
        $('#theme a:contains(Flatly)').trigger('click');
         window.localStorage.setItem('theme','flatly');
}); 
simov commented 10 years ago

No need because it is set on this line - https://github.com/simov/express-admin/blob/master/public/express-admin.js#L172 But yes you are free to write whatever you want to inside your custom files, that's the point!

Closing this.

ajax13 commented 10 years ago

i found another solution:

   changing `theme.html` : 
    (function () {
        var bootstrap = document.getElementById('bootstrap'),
            theme = localStorage.getItem('theme') || 'cerulean';
        bootstrap.href = xAdmin.root+'/bootswatch/'+theme+'/bootstrap.min.css';
    }());

and some changes into theme.json:

[
    {"key": "cerulean",     "name": "Default"},
simov commented 10 years ago

The idea of the custom static files and views (also the events in the next version) is to override and/or extend the core functionality without the need of touching the core of the app.

pathikrit commented 10 years ago

The default theme and layout should be a config that should be put in custom.json?

simov commented 10 years ago

Inside custom.json you can include regular js and css files and define your own behavior there. Since there isn't an option for defining a default theme/layout the quickest solution was to include an additional js file and trigger the button responsible for changing the theme using jquery: https://github.com/simov/express-admin-examples/blob/master/examples/custom/static/theme.js, the files are included here: https://github.com/simov/express-admin-examples/blob/master/examples/config/custom.json#L89

You can pull and run the https://github.com/simov/express-admin-examples repository.