npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sails-hook-cms2

v0.0.18

Published

A simple sails v0.12 admin panel

Downloads

5

Readme

Content Management System for Sails.JS v0.12

Beaware: This hook is still in a very early stages. Its working great, but bugs can occur. Please open an issue and I will try my best to help.

The Vision

An out-of-the-box CMS hook, that you can add to your project, and have a decent Dashboard to edit the data safely.

How

The objective of this sails hook is to provide an easy way to create a simple CMS for your current data structure.
The hook reads the models schema and builds a simple CRUD operations, and creats a Content Management System on top of your current sails project. We did add some extra config options just to make it more personal with what is presented in the dashboard. So you can choose logo and title of the Dashboard, and you can choose what fields should be renamed in the view or simply hide them.

Installation

  • Create a Users model with the fields email, password (md5 based), and role, and add a new user in the DB.
  • Install using npm i git+https://github.com/stuk88/sails-hook-cms.git and then navigate to http://localhost:1337/admin

Routes

This hooks introduces a couple of routes to your application.

  • http://localhost:1337/admin/login Admin login page - Based on Users model
{
'POST /admin/login': function (req, res, next) {
          Users.findOne({email: req.body.email, password: md5(req.body.password), role: 'admin'}).then((user) => {
            if (!user)
              return res.redirect('/admin');

            req.session.userId = user.id;

            return res.redirect(req.query.referer);
          })
        }
}

The query to verify a user is based on Users model. email, password, and role are required fields. The password must be encrypted with md5. (for other better encryption request's please open an issue) The authorizetion is based on saving the user id in the session.

  • http://localhost:1337/admin/logout Logout page

  • http://localhost:1337/admin Dashboard main page

  • http://localhost:1337/admin/:model A list of items

  • http://localhost:1337/admin/:model/create The form to create a new item

  • http://localhost:1337/admin/:model/store Save the new item

  • http://localhost:1337/admin/:model/edit/:modelId The form to edit an item

  • http://localhost:1337/admin/:model/update/:modelId Update an item

  • http://localhost:1337/admin/:model/duplicate/:modelId Duplicate an item

  • http://localhost:1337/admin/:model/delete/:modelId Delete an item

Options

I want this hook to work as plug and play. However if you want more control over the CMS I want to be able to provide those configurations to set things up. The base config file should be in config/misc.js and contains:

module.exports = {
  cms: {

    title: 'App Name', // The name of the app that appears on the logo as alt
    logo_url: '/images/logo.svg',
    styles: [
      // the styles to load in the admin, allows to attach custom styles and redesign the cms as you like
      '/styles/admin.css'
    ]
  }
}

Having for example a model named Book, But we maybe want to change the way it displays to be Books. In this case we can override the model.name with a label Books and removed the createdAt and updatedAt fields.

module.exports = {

  // CMS Extra config (Optional)
  cms: {
    // You can override the model displayed name with label
    label: "Books",
    // This field defines the field to use as the item title, in relation (Assosiation) attributes.
    // Default title field is 'name'
    title: "name",
    
    // Sometimes you dont want to display some attributes
    // so we can hide them.
    // so writing the attribute name, and setting it to false, tell's the CMS to not display the attribute in the table view.
    createdAt:false, 
    updatedAt:false,
    id:true
  },
  
  attributes: {
    // Name attribute could be a instance function too.
    name: 'string',
    description: 'text',
    danum: 'integer',
    dafloat: 'float',
    dadate: 'date',
    dadatetime: 'datetime',
    dabool: 'boolean',
    darray: 'array',
    dajson: 'json',
    enum: {
        type:'string',
        enum: ['a','b','c']
    },
    model: 'categories',
    collection: 'categories'
  }
};

You can help!

  • We need to transform jade templates into pug or ejs to support auto system updates. (Currently we have some major issues because Jade is DEPRECATED).
  • Add support for sails 1.0 (Add another Schema parser)

Support

Please open an issue.