Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/shared/behaviors/comparisonruleprovider.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name":"ComparisonRulesProvider",
"description":"You can register the comparison rules, application wide through the injector.",
"attributes": [

],
"methods": [
{
"name":"addComparison",
"description":"This method adds the comparison rule for a specified key. e.g. \"contains\"."
}
],
"behaviors": ["syncable"]
}
116 changes: 116 additions & 0 deletions src/shared/behaviors/comparisonrulesprovider.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/**
* Created by nemade_g on 4/27/2016.
*/
<script>
/**
* @license
* Copyright (c) 2015 MediaMath Inc. All rights reserved.
* This code may only be used under the BSD style license found at http://mediamath.github.io/strand/LICENSE.txt

*/
(function (scope) {
'use strict'

var comparisonRulesProvider = {
properties: {
},
addComparison:function(key, fn){
var injector = this.getInjector();
this.comparisonFunctions = injector.resolve('comparisonFunctions');
//initially, blank object is registered as a dependenccy for 'comparisonFunctions'.
!this.comparisonFunctions && (this.comparisonFunctions = injector.registerBlank('comparisonFunctions'));
var obj = {};
//User has flexibility to add function directly to be simple. For more control, he can provide other properties for the rule (comparison Function).
// such as validation, display name etc.
if(typeof fn === 'function'){
obj.func = fn;
obj.key = key;
obj.displayName = key;
}else{
fn.key = fn.key || key; //if key is not given in the option , we set it manually here. key is imp to be in the object.
fn.displayName = fn.displayName || key;
obj = fn;
}
(this.comparisonFunctions || (this.comparisonFunctions = {$get:function(){}}))[key] = obj;
},
created: function() {
this.addComparison('exactMatch', {
func: function(item, conf){
var itemValue;
if (conf.column == 'ALL') {
itemValue = JSON.stringify(item);
} else {
itemValue = item[conf.column];
}
itemValue = (itemValue||'').toString();
return itemValue === conf.searchValue;
},
displayName:'Exact Match',
validate:function(item){

var errorMsg = '';
if(!item.searchValue){
errorMsg += 'SearchValue can not be empty';
}
if(item.column === 'ALL'){
errorMsg += '\nExact Match can not be done on All columns, kindly select atleast one column';
}
return errorMsg;
}
});
this.addComparison('contains', {
func:function (item, config) {
var itemValue;
if (config.column && config.column == 'ALL') {
itemValue = JSON.stringify(item);
} else {
itemValue = config.column ? item[config.column] : '';

}
itemValue = (itemValue||'').toString();
return itemValue.search(config.searchValue || '') > -1;
},
displayName:'Contains'
});
this.addComparison('LessThan', function (item, config) {
var itemValue;
if (config.column && config.column == 'ALL') {
itemValue = '';
} else {
itemValue = config.column ? item[config.column] : '';

}
if(!isNaN(itemValue)){
if(config.inclusive){
return itemValue <= parseFloat(config.searchValue);
}else{
return itemValue < parseFloat(config.searchValue);
}
}else{
return false;
}

});
this.addComparison('GreaterThan', function (item, config) {
var itemValue;
if (config.column && config.column == 'ALL') {
itemValue = '';
} else {
itemValue = config.column ? item[config.column] : '';

}
if(!isNaN(itemValue)){
if(config.inclusive){
return itemValue >= parseFloat(config.searchValue);
}else{
return itemValue > parseFloat(config.searchValue);
}
}else{
return false;
}
});
}
};
scope.ComparisonRulesProvider = [scope.Injector, comparisonRulesProvider];
})(window.StrandTraits = window.StrandTraits || {});
</script>
44 changes: 44 additions & 0 deletions src/shared/behaviors/injector.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<script>
/**
* @license
* Copyright (c) 2015 MediaMath Inc. All rights reserved.
* This code may only be used under the BSD style license found at http://mediamath.github.io/strand/LICENSE.txt

*/
(function (scope) {
"use strict";
var dependencies = [];
scope.Injector = {
properties: {
},
getInjector:function() {
var instantiate = function(obj){
if(typeof obj === 'function'){
return new obj();
}else{
return obj;
}
};
return this._injector || {
register: function (key, dependencyObj) {
var obj = instantiate(dependencyObj);
if(obj && obj.$get) {
dependencies[key] = obj.$get();
}else{
throw 'Object can not be registered to injector. It should have $get function.'
}
return dependencies[key];
},
registerBlank:function(key){
return this.register(key, {$get:function(){return {}}});
},
resolve: function (key) {
return dependencies[key];
}
};

}
};

})(window.StrandTraits = window.StrandTraits || {});
</script>
14 changes: 14 additions & 0 deletions src/shared/behaviors/injector.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name":"Injector",
"description":"You can register providers which can be injected anywhere you need in the application.",
"attributes": [

],
"methods": [
{
"name":"getInjector",
"description":"Returns injector object which has methods, register and resolve. Register method, registers the dependency and resolve method gives registered dependency whenever required. "
}
],
"behaviors": ["syncable"]
}
103 changes: 103 additions & 0 deletions src/shared/behaviors/pageable-extended.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<link rel="import" href="../js/datautils.html" />
<link rel="import" href="../js/sync.html" />
<link rel="import" href="domsyncable.html" />
<link rel="import" href="pageable.html">
<script>
/**
* @license
* Copyright (c) 2015 MediaMath Inc. All rights reserved.
* This code may only be used under the BSD style license found at http://mediamath.github.io/strand/LICENSE.txt

*/
(function (scope) {
"use strict";


var PageableExtended = {
properties: {
totalRows: {
type: Number,
value: 0
}
},
ready: function () {
this.parent = this.parentNode;
if ( !this.parent || typeof this.parent.page === "undefined") { return; }
this.page = this.parent.page;
this.pageSize = this.parent.pageSize;

//Fire already queued events before ready.
this.pageDataChangedEvents = this.pageDataChangedEvents || [];
for (var i = 0; i < this.pageDataChangedEvents.length; i++) {
var evt = this.pageDataChangedEvents[i];
this._firePageDataChangedEvent(evt);
}
this.pageDataChangedEvents = [];
this.isReady = true;
this.addEventListener('datachanged', this._dataChanged.bind(this))
},
_dataChanged:function(){
//Reset the page number to 0 after data is changed.
this.gotoFirst();
this._pageChangedExtended();

},
pageDisplayValue:function (pg) {
return +pg + 1;
},
nextPage: function () {
console.time('start nextpage');
var lastpage = this.getLastPageNumber();
if (this.page < lastpage){
var pg = this.page + 1;
this.set('page', pg);
console.time('in if condition post increment.');

}

console.time('start nextpage', this.page);

},
prevPage: function () {
if (this.page > 0)
this.page--;
},
goto: function (pageNum) {
this.set('page', pageNum);
},
gotoFirst: function () {
this.page = 0;
},
getLastPageNumber: function () {
return Math.ceil(this.totalRows / this.pageSize) - 1;
},
gotoLast: function () {

this.page = this.getLastPageNumber();
},
_pageChangedExtended: function () {
//console.log('page changed in _pageChangedExtended');
if (this.isReady) {
this._firePageDataChangedEvent({ name: 'pagedata', page: this.page });
} else {
this._enquePageDataChangedEvent({ name: 'pagedata', page: this.page });
}
},
_firePageDataChangedEvent: function (data) {
data.pageData = this._getPageData();
this.fire('pagedata', data);
},
_enquePageDataChangedEvent: function (data) {
this.pageDataChangedEvents = this.pageDataChangedEvents || [];
this.pageDataChangedEvents.push(data);
}
};

scope.PageableExtended = [
StrandLib.Sync.getBehavior(),
scope.DomSyncable,
scope.Pageable,
PageableExtended
];
}(window.StrandTraits = window.StrandTraits || {}));
</script>
59 changes: 59 additions & 0 deletions src/shared/behaviors/pageable-extended.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"name":"PageableExtended",
"description":"A behavior that requires a base component with _sync exposed, interacts with sync's ajaxpageplugin to provide paging from a dom interface",
"attributes": [
{
"name":"page",
"type":"Number",
"description":"the current page number",
"default": 0,
"required": true
},
{
"name":"pageSize",
"type":"Number",
"description":"the current number of records requested per page",
"default": 10,
"required": true
},
{
"name":"index",
"type":"Number",
"description":"the current record offset. this is used for binding to item recycled UI components",
"default":"0",
"required":false
},
{
"name":"pageOptions",
"type":"Object",
"description":"Configuration object used to configure paging behavior. pageName is used to denote the key used for the paging index, pageSize is used to denote the width or lenght of a page, url, query and body are all booleans used to determine how the paging data should be passed to the ajax call, and pageType is either 'index' or 'offset' depending on if the page is calculated from an index and count or is a single record offset value."
}
],
"methods": [
{
"name":"nextPage",
"description":""
},
{
"name":"prevPage",
"description":""
},
{
"name":"goto",
"description":""
},
{
"name":"gotoFirst",
"description":""
},
{
"name":"getLastPageNumber",
"description":""
},
{
"name":"gotoLast",
"description":""
}
],
"behaviors": ["syncable"]
}
Loading