Add FAQ and glossary

This patch adds FAQ and glossary
to the readme.md file.
Also this patch adds documentation
for Merlin directives.
Also this patch grunt task for generation
html from markdown.
To run this task run 'grunt md' from the
Merlin directory.

Change-Id: Ifd98fe4d9fa61bf5b7bbd71361763caa93e7ed3e
This commit is contained in:
Paul Karikh 2015-06-25 19:14:03 +03:00
parent a08c69b0d2
commit bf942fef1c
4 changed files with 100 additions and 1 deletions

View File

@ -52,12 +52,24 @@ module.exports = function(grunt){
// run tests once instead of continuously
singleRun: true
}
},
markdown: {
all: {
files: [{
expand: true,
src: './README.md',
dest: './',
ext: '.html'
}]
}
}
});
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-markdown');
grunt.registerTask('test:unit', [
'karma:unit'
]);
grunt.registerTask('md', ['markdown:all'])
};

View File

@ -50,4 +50,69 @@ the **Project** dashboard, **Orchestration** panel group.
4. ``sudo npm install -g grunt-cli``
5. ``grunt test:unit``
For more info please refer to https://wiki.openstack.org/wiki/Merlin
# Glossary:
* Schema - is a main object for describing structure of a model. This object describes how fields and containers are bounded between themselfs, and how the are being modified.
Merlin use schema to validate user input, render forms, fields and models. If you want to define, that if user sets field "type" for "action", that first field in the form should be "Base" - scheme is the place where you should to define it.
* Model - is a prototype for field. Model could describe a different types of fields: strings, text (large string), numer, dictionary, frozendictionary (immutable dictionary), and so on.
* Using models helps to render and validate fields. Uou can extend existing models and create your custom field types. Barricade.js object becames an Merlin object when we add modelMixin.
Field - is an atom of form. Should be inherited from some model (Merlin model or your custom model).
* Panel - visual group of containers.
* Container - Barricade-specific object type (immutable objects, arrays, mutable objects).
### The final structure of UI is defined by:
* the schema
* the actual data this schema is paired with to create Barricade object
* filters and directives being used in an html for rendering the Barricade object provided on the scope
### Merlin filters:
* extractPanels, extractItems, extractRows - used to unpack data from Barricade.js format
into format for convenient template rendering. Also, you can apply a few filters for one Barricade object.
# FAQ
### But where are any controllers?
The are in the app. Сore Merlin code currently doesn't define any controllers because all logic is put into the model, i.e. Barricade objects".
### How can I use Merlin in my app?
You can take a look at the `/mistral/` directory, which contains Workbook builder app based on Merlin. There is some django-code to render view to show dashboard in the Horizon.
And in the `merlin/extensions/mistral/static/mistral` is Merlin based code. `templates/fields` contains definition of additional (Mistral-specific) types of fields.
You can take a look at `merlin/extensions/` directory. In the `/enabled/` dir there is typical panel file to add new panel into Horizon Dashboard.
`mistral.init.js` contains fetching custom mistral templates for fields. In this file Angular 'mistral' module is initialized first time, so it should be loaded before any other scripts defining entities within 'mistral' module.
`mistral.workbook.controllers.js` - contains main controller which contains functions for domain-specific actions. For example, actions for creating and initializing Action and Workflow objects.
Lets take a look at the typical definition.
```
'base-input': {
'@class': fields.dictionary.extend({ // which model we are going to use as prototype
create: function(json, parameters) {
var self = fields.dictionary.create.call(this, json, parameters);
self.setType('frozendict');
return self;
}
}, {
'@required': false,
'?': { //'?' is a marker for Barricade MutableObject
'@class': fields.string.extend({}, {
'@meta': { '@meta' tells Merlin how to render it
'row': 0
}
})
},
'@meta': {
'index': 2,
'title': 'Base Input'
}
})
},
```
### How does Merlin know how to render field, panel or group?
Merlin uses templates for this. Each type of field has its own template with html and css-markup, so you can define filters, directives, on-click events, and rules for filling variables for each type of field.
The same mechanism is implemented for groups and panels.
### How does Merlin gets/sets model value with barricade.js?
Each model has getter/setter, so, when you access to model.value field, if you doing it without param, you calling getter, if you pass any param - you calling a setter. For proper work of this feature we have to use ng-model-options="{getterSetter: true}" ability of angular.js.
Currently angular-ui bootstrap library has a bug which doesn't allow use getterSetter: true, and since it is a problem for autosuggestion feature, we filed a bug (and a patch) to the angular-ui repo (ling), and until it will not be released, we managed to use patched version of this library.
That's why we have ui-bootstrap-tpls-0.13.0.patched.js file in custom-lib directory.

View File

@ -5,6 +5,12 @@
'use strict';
angular.module('merlin')
/*
* Allows to edit field name in-place.
* For example, you have a field named 'Input 1' and you want to replace this name with "Base input" value.
* If you add editable directive to such field, you will get a marker icon near this field,
* and with clicking on this icon you can type new name and save or discard changes.
* */
.directive('editable', function() {
return {
restrict: 'E',
@ -58,6 +64,9 @@
}
};
})
/*
* this directive auto-sets the focus to an input field once it is shown.
* */
.directive('showFocus', function($timeout) {
return function(scope, element, attrs) {
scope.$watch(attrs.showFocus, function(newValue) {
@ -67,6 +76,9 @@
});
}
})
/*
* tells Merlin to render this element as a panel.
* */
.directive('panel', function($parse) {
return {
restrict: 'E',
@ -81,6 +93,9 @@
}
}
})
/*
* tells Merlin to render this element as a group with ability to collapse.
* */
.directive('collapsibleGroup', function() {
return {
restrict: 'E',
@ -102,6 +117,9 @@
}
}
})
/*
* sets up the DOM nodes related to validation of model being edited in this widget (and specifies the name of this model on scope).
* */
.directive('validatableWith', function($parse) {
return {
restrict: 'A',
@ -132,6 +150,9 @@
}
}
})
/*
* retrieves a template by its name which is the same as model's type and renders it, recursive <typed-field></..>-s are possible.
* */
.directive('typedField', ['$compile', 'merlin.templates',
function($compile, templates) {
function updateAutoCompletionDirective(template) {

View File

@ -16,6 +16,7 @@
"grunt-eslint": "7.0.1",
"grunt-html2js": "0.2.9",
"grunt-karma": "0.10.1",
"grunt-markdown": "^0.7.0",
"grunt-open": "0.2.3",
"grunt-protractor-runner": "1.1.4",
"grunt-shell": "1.1.1",