clinical:active-record

v1.0.15Published 8 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

##clinical:active-record

An ActiveRecord pattern that provides CRUDL templates, using AutoForms and SimpleSchema.

===============================

Installation

meteor add clinical:active-record

===============================

Usage

  1. Define your schema...
1SampleSchema = new SimpleSchema({
2  "name": {
3    type: String,
4    optional: true,
5    defaultValue: "",
6    label: "Name"
7  },
8  "description": {
9    type: String,
10    optional: true,
11    defaultValue: "",
12    label: "Description",
13    autoform: {
14      afFieldInput: {
15        type: "textarea",
16        rows: 10,
17        class: "foo",
18        placeholder: "Lorem ipsum..."
19      }
20    }
21  }
22});
23Records.attachSchema(SampleSchema);
  1. Set up your publications and subscriptions....
1// client/subscriptions.js
2Meteor.subscribe("records");
3
4// server/publications.js
5Meteor.publish("records", function (recordId) {
6  if (recordId) {
7    // if (User.collaborationsContain(
8
9    return Records.findOne({
10      _id: recordId,
11      collaborations: {
12        $in: User.getCollaborations()
13      }
14    });
15  } else
16    return Records.find({
17      collaborations: {
18        $in: User.getCollaborations()
19      }
20  });
21});
  1. Then use the default routes...
1Router.go('/insert/record');
2Router.go('/upsert/record/:id');
3Router.go('/view/record/:id');
4Router.go('/list/records');
5Router.go('/grid/records');
6Router.go('/record/:id');
  1. Or add templates directly to your application...
1<!-- basic upsert/list pattern -->
2{{> recordsUpsertPage }}
3{{> recordsListPage }}
4
5<!-- additional views -->
6{{> recordImageGridPage }}
7{{> recordImageGridPage }}
8{{> recordsTablePage }}

===============================

Cloning/Forking

While ActiveRecord works fine if there's a single schema that you want to create some basic CRUDL user interface for; it's quite likely that you'll want to have multiple schemas, or simply want to modify the default templates somehow.

The recommended approach for using ActiveRecord is to clone it into your application's /packages directory, and to then refactor all the references of Record to the name of whatever you're modeling. You'll want to be sure to rename both the capitalized and non-capitalized versions. Back up your files before doing this refactor!

cd myapp/packages
git clone http://github.com/clinical-meteor/clinical-active-record
cd clinical-active-record
find . -tyope f -print0 | xargs -0 sed -i 's/Record/Foo/g'
find . -tyope f -print0 | xargs -0 sed -i 's/record/foo/g'

===============================

Licensing

MIT. Use as you will.