(function () { 'use strict'; var serviceId = 'rulesAdminService'; angular.module('rulesAdmin').factory(serviceId, [rulesAdminService]); function rulesAdminService() { var currentRule; var service = { getRule: getRule, setRule: setRule, createRule: createRule, collection: collection, collectionTypes: collectionTypes, targetValues: targetValues, conditionTypes: conditionTypes, comparisonValues: comparisonValues, logicTypes: logicTypes, targetTypes: targetTypes, outcome: outcome, outcomeTypes: outcomeTypes, createRuleCollection: createRuleCollection }; return service; function getRule() { return currentRule; } function setRule(rule) { currentRule = rule; } function createRule() { return { name: '', shortName: '', description: '', enabled: true, rule: { collection: [], logicType: 'and', type: 'collection', }, outcomes: [ outcome() ] } } function createRuleCollection() { return { collection: [], logicType: 'and', type: 'collection', } } function outcome() { return { ordinal: 0, itemId: null, type: "badge", } } function outcomeTypes() { return [ { name: 'badge', displayName: 'Badge', type: 0 } ] } function collection(type) { if (type == 'singular') { return { activityId: '', condition: { targetType: '', comparison: '', target: '', type: '' }, type: 'singular' } } if (type == 'collection') { return { logicType: 'and', type: 'collection', collection: [] } } } function collectionTypes() { return [ { name: 'singular', type: 0 }, { name: 'binary', type: 1 }, { name: 'collection', type: 2 } ] } function logicTypes() { return [ { name: 'and', displayName: 'AND', type: 1 }, { name: 'or', displayName: 'OR', type: 2 } ] } function conditionTypes(type) { return [ { type: 0, displayName: 'Count', name: 'count' }, { type: 1, displayName: 'Distinct Count', name: 'distinctCount' }, { type: 2, displayName: 'Value', name: 'value' }, { type: 3, displayName: 'RunningTotal', name: 'runningTotal' }, { type: 4, displayName: 'Exists', name: 'exists' } ] } function targetValues(type) { if (type == 'count') { return [] } if (type == 'distinctCount') { return [ { name: 'text1', displayName: 'Text1' }, { name: 'text2', displayName: 'Text2' }, { name: 'int1', displayName: 'Int1' }, { name: 'int2', displayName: 'Int2' }, { name: 'date1', displayName: 'Date1' } ] } if (type == 'value') { return [ { name: 'text1', displayName: 'Text1' }, { name: 'text2', displayName: 'Text2' }, { name: 'int1', displayName: 'Int1' }, { name: 'int2', displayName: 'Int2' }, { name: 'date1', displayName: 'Date1' } ] } if (type == 'runningTotal') { return [ { name: 'int1', displayName: 'Int1' }, { name: 'int2', displayName: 'Int2' } ] } if (type == 'exists') { return [ ] } } function comparisonValues(type, targetValue) { if (type == 'count') { return [] } if (type == 'distinctCount') { return [ { name: 'greaterThanOrEqualTo', type: 4, symbol: '>=' }, ] } if (type == 'value') { if (targetValue == 'text1' || targetValue == 'text2') { return [ { name: 'equalTo', type: 0, symbol: '=' }, { name: 'notEqualTo', type: 5, symbol: '!=' }, ] } else if (targetValue == 'date1') { return [ { name: 'equalTo', type: 0, symbol: '=' }, { name: 'lessThanOrEqualTo', type: 1, symbol: '<=' }, { name: 'lessThan', type: 2, symbol: '<' }, { name: 'greaterThan', type: 3, symbol: '>' }, { name: 'greaterThanOrEqualTo', type: 4, symbol: '>=' }, { name: 'notEqualTo', type: 5, symbol: '!=' } ] } else { return [ { name: 'equalTo', type: 0, symbol: '=' }, { name: 'lessThanOrEqualTo', type: 1, symbol: '<=' }, { name: 'lessThan', type: 2, symbol: '<' }, { name: 'greaterThan', type: 3, symbol: '>' }, { name: 'greaterThanOrEqualTo', type: 4, symbol: '>=' }, { name: 'notEqualTo', type: 5, symbol: '!=' }, { name: 'between', type: 7, symbol: '-' }, ] } } if (type == 'runningTotal') { return [ { name: 'equalTo', type: 0, symbol: '=' }, { name: 'lessThanOrEqualTo', type: 1, symbol: '<=' }, { name: 'lessThan', type: 2, symbol: '<' }, { name: 'greaterThan', type: 3, symbol: '>' }, { name: 'greaterThanOrEqualTo', type: 4, symbol: '>=' }, { name: 'notEqualTo', type: 5, symbol: '!=' }, { name: 'between', type: 7, symbol: '-' }, ] } if (type == 'exists') { return [ ] } } function targetTypes() { return [ { name: 'int', displayName: 'Int', type: 0 }, { name: 'string', displayName: 'String', type: 1 }, { name: 'dateTime', displayName: 'DateTime', type: 2 } ] } } })();