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

monad-crud

v1.4.0

Published

CRUD component for Monad CMS

Downloads

35

Readme

monad-crud

Easy support for CRUD-style operations for the Monad CMS

Installation

$ npm i monad-crud

Usage

Define routes and components for all pages of your admin that need CRUD support. This example uses foo:

"use strict";

import list from '/path/to/list.html';
import schema from '/path/to/schema.html';

angular.module('my-admin', [])
    .config(['$routeProvider', $routeProvider => {
        $routeProvider.when('/foo/', {
            template: '<foo-list resource="$resolve.resource" count="$resolve.count"></foo-list>',
            resolve: {
                resource: ['monadResource', monadResource => monadResource('/api/foo/')],
                count: ['$http', $http => $http.get('/api/foo/count/').then(result => result.data.count)]
            }
        });
        $routeProvider.when('/foo/:id/', {
            template: '<foo-detail data="$resolve.data" clients="$resolve.clients"></foo-detail>',
            resolve: {
                data: ['monadResource', '$route', (monadResource, $route) => {
                    const res = monadResource('/api/foo/:id/', {id: '@id'});
                    if ($route.current.params.id == 'create') {
                        return {item: res};
                    } else {
                        return {item: res.get({id: $route.current.params.id})};
                    }
                }],
            }
        });
    }])
    .component('fooList', {
        template: list,
        bindings: {resource: '<', count: '<'},
        controller: 'monadListCtrl'
    })
    .component('fooDetail', {
        template: schema,
        bindings: {data: '<'}
    });

Anything in $resolve.data will be watched by monad-crud to determine whether or not to show the "save" button (it is hidden when the form is pristine).

The HTML for the list will typically look something like this:

<div class="container-fluid">
    <monad-list-header create="'/admin/foo/create/'">Invoice</monad-list-header>
    <monad-list-table rows="$ctrl.items" update="'/admin/foo/:id/'">
        <table><tr>
            <!--
            These should specify the fields you want shown in the list
            (typically, not everything is relevant for an overview).
            The `property` attribute specifies the property on the JSON
            objects in the list. `row` is the placeholder for the current
            item in the list.
            -->
            <th property="row.id">ID</th>
            <th property="row.subject">Subject</th>
        </tr></table>
    </monad-list-table>
    <div class="text-center" ng-if="$ctrl.count > 10">
        <ul uib-pagination total-items="$ctrl.count" ng-model="$ctrl.page" boundary-links="true" max-size="10"></ul>
    </div>
</div>

The HTML for the "schema" should contain form fields for everything you want to show or be editable. By convention, we use $ctrl.data.item as the main thing being edited, but really the name is irrelevant as long as it's placed on $ctrl.data.

Wrap the fields in the monadUpdate component:

<monad-update list="/admin/foo/" data="$ctrl.data" type="foo">
    <!-- your form fields -->
</monad-update>

...and that's basically it!