Skip to content

AutoCms is a simple solution to manage contents

License

Notifications You must be signed in to change notification settings

fth-ship/autocms

 
 

Repository files navigation

autoCms for Meteor.js

A simple solution to manage contents. You can easly list your data in a table, update, delete or insert. ```js meteor add guncebektas:autocms ``` Click here to watch what you can do with the package

How to

Routes

```js // cmsCollections FlowRouter.route('/cms/:collection/:function', { action: function() { BlazeLayout.render("main", { content: 'autoCms' }); } }); FlowRouter.route('/cms/:collection/:function/:id', { action: function() { BlazeLayout.render("main", { content: "autoCms" }); } }); ```

Into Body

```js {{> Template.dynamic template=content}} ```

Rules

```js Players = new Mongo.Collection('players'); // Attach schema for autoForm Players.attachSchema(new SimpleSchema({ name: { type: String, label: "Name", max: 100 }, surname: { type: String, label: "Surname", max: 100 }, picture: { type: String, label: 'Profile Picture', autoform: { afFieldInput: { type: 'fileUpload', collection: 'Images', accept: 'image/*', label: 'Choose a file', previewTemplate: 'filePreview', selectFileBtnTemplate: 'fileButtonSelect', removeFileBtnTemplate: 'fileButtonRemove', onBeforeInsert: function(fileObj) { }, onAfterInsert: function(err, fileObj) { } } }, optional: true } })); // Define rules for autoCms Players.autoCms = { wrapper: { type: 'list' }, title: 'All players', showNo: false, columns: { picture: { type: 'image', width: 40 }, name: { }, surname: { } } } ```

Open links

``` localhost:3000/cms/Players/list localhost:3000/cms/Players/insert ```

The result will be like that

Another example which covers more

```js // First of all create Mongo collections Games = new Mongo.Collection('games'); // Attach schema into collection Games.attachSchema(new SimpleSchema({ title:{ type: String, label: "Title", max: 100 }, date: { type: Date, label: "Due Date", optional: true }, gamer1: { type: String, label: "Gamer 1", autoform: { //type: "select2", options: function () { return Players.find().map(function (p) { return {label: p.name+' '+p.surname, value: p._id}; }); } } }, score1: { type: Number, label: "Score 1", defaultValue: 0 }, gamer2: { type: String, label: "Gamer 2", autoform: { //type: "select2", options: function () { return Players.find().map(function (p) { return {label: p.name+' '+p.surname, value: p._id}; }); } } }, score2: { type: String, label: "Score 2", defaultValue: 0 }, // hide createdBy column createdBy: { type: String, autoform: { type: "hidden", label: false }, autoValue: function () { return Meteor.userId() } } })); // Define rules for autoCms Games.autoCms = { wrapper: { type: 'table', class: 'table table-hover' }, title: 'All games', buttons: { extra: { label: ' Extra', class: 'btn btn-xs btn-success', auth: function() { // default true return true; }, href: function(data) { return location.origin+'/link/'+data; } }, edit: { label: ' Edit', class: 'btn btn-xs btn-default', auth: function() { // default true return true; } }, delete: { label: ' Delete', class: 'btn btn-xs btn-danger', auth: function() { // default true return false; } }, showNavButtons: true, // default true navButtonInsert: { label: '', class: 'btn btn-default' }, navButtonList: { label: '', class: 'btn btn-default' }, showActionButtons: true // default true }, showNo: true, // default true columns: { title: { }, gamer1: function(data){ result = Players.findOne(data); return '

'+result.name+' '+result.surname; }, score1: { class: function(data) { switch(true) { case (data < 3): return 'danger' break; case (data == 3): return 'info'; break; case (data > 3): return 'success'; break; default: return undefined; } } }, gamer2: function(data){ result = Players.findOne(data); return '

'+result.name+' '+result.surname; }, score2: { class: function(data) { switch(true) { case (data < 3): return 'danger' break; case (data == 3): return 'info'; break; case (data > 3): return 'success'; break; default: return undefined; } } } } } // Allow database actions in server if (Meteor.isServer) { Games.allow({ insert: function () { return true; }, update: function () { return true; }, remove: function () { return true; } }); } ```

Open links

``` localhost:3000/cms/Games/list localhost:3000/cms/Games/insert ```

The result will be like that if you add bootstrap

About

AutoCms is a simple solution to manage contents

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 87.1%
  • HTML 12.7%
  • CSS 0.2%