LT-275: Creating measure flow component common section
This commit is contained in:
1 parent
9a8eaff560
commit
bbb7dad905
60 files changed
+391
-156
No files matched your search
@@ -0,0 +1,26 @@
|
||||
import { Template } from 'meteor/templating';
|
||||
import { Session } from 'meteor/session';
|
||||
import { ReactiveVar } from 'meteor/reactive-var';
|
||||
|
||||
/**
|
||||
* Global Blaze UI helpers to work with Blaze
|
||||
*/
|
||||
|
||||
// Return the current template instance
|
||||
Template.registerHelper('instance', () => {
|
||||
return Template.instance();
|
||||
});
|
||||
|
||||
// Return the session value for the given key
|
||||
Template.registerHelper('session', key => {
|
||||
return Session.get(key);
|
||||
});
|
||||
|
||||
// Return the value for given parameter regardless if it's reactive or not
|
||||
Template.registerHelper('reactive', parameter => {
|
||||
if (parameter instanceof ReactiveVar) {
|
||||
return parameter.get();
|
||||
}
|
||||
|
||||
return parameter;
|
||||
});
|
||||
@@ -0,0 +1,60 @@
|
||||
import { _ } from 'meteor/underscore';
|
||||
import { Template } from 'meteor/templating';
|
||||
|
||||
/**
|
||||
* Global Blaze UI helpers to manipulate data
|
||||
*/
|
||||
|
||||
// Base extend function to be used by extend and clone helpers
|
||||
const extend = (...argsArray) => {
|
||||
// Create the resulting object
|
||||
const result = argsArray[0] || {};
|
||||
|
||||
// Extract the Spacebars kw hash
|
||||
const kwHash = _.last(argsArray).hash;
|
||||
|
||||
// Extract the given objects
|
||||
const objects = _.initial(argsArray);
|
||||
|
||||
// Iterate over the given objects
|
||||
_.each(objects, current => {
|
||||
// Stop here if the current argument is not an object
|
||||
if (typeof current !== 'object') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Extend the resulting object with the current argument object
|
||||
_.extend(result, current);
|
||||
});
|
||||
|
||||
// Extend the resulting object with the Spacebars kw hash
|
||||
_.extend(result, kwHash);
|
||||
|
||||
// Return the resulting object
|
||||
return result;
|
||||
};
|
||||
|
||||
// Extend the first argument object it with the other argument objects
|
||||
Template.registerHelper('extend', (...argsArray) => {
|
||||
return extend(...argsArray);
|
||||
});
|
||||
|
||||
// Create a new object and extends it with the argument objects
|
||||
Template.registerHelper('clone', (...argsArray) => {
|
||||
const newArgs = argsArray.slice();
|
||||
newArgs.unshift({});
|
||||
return extend(...newArgs);
|
||||
});
|
||||
|
||||
// Choose the first truthy value in the given values
|
||||
Template.registerHelper('choose', (...values) => {
|
||||
let result;
|
||||
_.each(_.initial(values, 1), value => {
|
||||
if (result) {
|
||||
return;
|
||||
}
|
||||
|
||||
result = value;
|
||||
});
|
||||
return result;
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
import { _ } from 'meteor/underscore';
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { Template } from 'meteor/templating';
|
||||
|
||||
/**
|
||||
* Global Blaze UI helpers to development debugging
|
||||
*/
|
||||
|
||||
// Stop here if it's not development environment
|
||||
if (!Meteor.isDevelopment) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Debug some value on console
|
||||
Template.registerHelper('debug', (...values) => {
|
||||
console.debug(...values);
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
import './blaze.js';
|
||||
import './data.js';
|
||||
import './debug.js';
|
||||
import './logical.js';
|
||||
import './number.js';
|
||||
import './string.js';
|
||||
import './typing.js';
|
||||
@@ -0,0 +1,69 @@
|
||||
import { _ } from 'meteor/underscore';
|
||||
import { Template } from 'meteor/templating';
|
||||
|
||||
/**
|
||||
* Global Blaze UI helpers to work with logical operations
|
||||
*/
|
||||
|
||||
// Convert any value into a boolean value
|
||||
Template.registerHelper('bool', value => {
|
||||
return !!value;
|
||||
});
|
||||
|
||||
// Check if two values are identical
|
||||
Template.registerHelper('eq', (a, b) => {
|
||||
return a === b;
|
||||
});
|
||||
|
||||
// Check if two values are different
|
||||
Template.registerHelper('ne', (a, b) => {
|
||||
return a !== b;
|
||||
});
|
||||
|
||||
// Check if the first value is greater than the second one
|
||||
Template.registerHelper('gt', (a, b) => {
|
||||
return a > b;
|
||||
});
|
||||
|
||||
// Check if the first value is lesser than the second one
|
||||
Template.registerHelper('lt', (a, b) => {
|
||||
return a < b;
|
||||
});
|
||||
|
||||
// Check if the first value is greater than or equals the second one
|
||||
Template.registerHelper('gte', (a, b) => {
|
||||
return a >= b;
|
||||
});
|
||||
|
||||
// Check if the first value is lesser than or equals the second one
|
||||
Template.registerHelper('lte', (a, b) => {
|
||||
return a <= b;
|
||||
});
|
||||
|
||||
// Get the boolean negation for the given value
|
||||
Template.registerHelper('not', value => {
|
||||
return !value;
|
||||
});
|
||||
|
||||
// Check if all the given values are true
|
||||
Template.registerHelper('and', (...values) => {
|
||||
let result = true;
|
||||
_.each(_.initial(values, 1), value => value || (result = false));
|
||||
return result;
|
||||
});
|
||||
|
||||
// Check if one of the given values is true
|
||||
Template.registerHelper('or', (...values) => {
|
||||
let result = false;
|
||||
_.each(_.initial(values, 1), value => value && (result = true));
|
||||
return result;
|
||||
});
|
||||
|
||||
// Return the second parameter if the first is true or the third if it's false
|
||||
Template.registerHelper('valueIf', (condition, valueIfTrue, valueIfFalse) => {
|
||||
if (condition) {
|
||||
return valueIfTrue;
|
||||
}
|
||||
|
||||
return valueIfFalse;
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
import { _ } from 'meteor/underscore';
|
||||
import { Template } from 'meteor/templating';
|
||||
|
||||
/**
|
||||
* Global Blaze UI helpers to work with numeric operations
|
||||
*/
|
||||
|
||||
// Sum all the given numbers
|
||||
Template.registerHelper('sum', (...values) => {
|
||||
let result = 0;
|
||||
_.each(_.initial(values, 1), value => (result += (value | 0)));
|
||||
return result;
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
import { _ } from 'meteor/underscore';
|
||||
import { Template } from 'meteor/templating';
|
||||
|
||||
/**
|
||||
* Global Blaze UI helpers to work with Strings
|
||||
*/
|
||||
|
||||
// Concatenate the give strings
|
||||
Template.registerHelper('concat', (...args) => {
|
||||
const values = _.initial(args, 1);
|
||||
let result = '';
|
||||
_.each(values, value => {
|
||||
result += value || '';
|
||||
});
|
||||
return result;
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
import { _ } from 'meteor/underscore';
|
||||
import { Template } from 'meteor/templating';
|
||||
|
||||
/**
|
||||
* Global Blaze UI helpers to work with Strings
|
||||
*/
|
||||
|
||||
// Check if the value's type is undefined
|
||||
Template.registerHelper('isUndefined', value => {
|
||||
return _.isUndefined(value);
|
||||
});
|
||||
|
||||
// Check if the value's type is object
|
||||
Template.registerHelper('isObject', value => {
|
||||
return _.isObject(value);
|
||||
});
|
||||
|
||||
// Check if the value is an array instance
|
||||
Template.registerHelper('isArray', value => {
|
||||
return _.isArray(value);
|
||||
});
|
||||
Reference in new issue
Block a user