define([],
- function () {
- "use strict";
+function () {
+ 'use strict';
- return {
- NODE_UI_DISPLAY: 1,
- NODE_ALTER: 2,
- NODE_CONDITIONAL: 3,
- NODE_RESTRICTIONS: 4,
- NODE_LINK: 5,
- NODE_LINK_TARGET: 6,
- LOCALE_PREFIX: 'YANGUI_FORM_',
- EV_SRC_MAIN: 'EV_SRC_MAIN',
- EV_FILL_PATH: 'EV_FILL_PATH',
- EV_LIST_CHANGED: 'EV_LIST_CHANGED',
- EV_PARAM_EDIT_SUCC: 'EV_PARAM_EDIT_SUCC',
- MPPREFIX: 'yang-ext:mount',
- NULL_DATA: null,
+ return {
+ NODE_UI_DISPLAY: 1,
+ NODE_ALTER: 2,
+ NODE_CONDITIONAL: 3,
+ NODE_RESTRICTIONS: 4,
+ NODE_LINK: 5,
+ NODE_LINK_TARGET: 6,
+ LOCALE_PREFIX: 'YANGUI_FORM_',
+ EV_SRC_MAIN: 'EV_SRC_MAIN',
+ EV_FILL_PATH: 'EV_FILL_PATH',
+ EV_LIST_CHANGED: 'EV_LIST_CHANGED',
+ EV_PARAM_EDIT_SUCC: 'EV_PARAM_EDIT_SUCC',
+ MPPREFIX: 'yang-ext:mount',
+ NULL_DATA: null,
+ ADVANCED_FILTERING_TYPES: {
+ 'number': ['=', '>', '>=', '<', '<=', 'range'],
+ 'string': ['=', 'contains', 'regExp'],
+ },
+ ALLOWED_LEAF_TYPES_FOR_FILTER: ['string', 'uint32', 'uint8', 'decimal64', 'int16', 'int32', 'int64', 'int8',
+ 'uint16', 'uint64', 'union', 'bits', 'leafref', 'identityref'],
+ ALLOWED_NODE_TYPES_FOR_FILTER: ['case', 'choice', 'container', 'input', 'leaf', 'output', 'rpc'],
+ };
- ADVANCED_FILTERING_TYPES : {'number' : ['=','>','>=','<','<=','range'],'string' : ['=','contains','regExp']},
- ALLOWED_LEAF_TYPES_FOR_FILTER : ['string','uint32','uint8','decimal64','int16','int32','int64','int8','uint16','uint64','union','bits','leafref','identityref'],
- ALLOWED_NODE_TYPES_FOR_FILTER : ['case','choice','container','input','leaf','output','rpc']
- };
-
- }
-);
+});
define([], function () {
'use strict';
- function ApiBuilderService(ArrayUtilsService, PathUtilsService, NodeUtilsService, YangUtilsRestangularService, CustomFuncService){
- var ab = {};
+ function ApiBuilderService(ArrayUtilsService, PathUtilsService, NodeUtilsService, YangUtilsRestangularService,
+ CustomFuncService){
+
+ var service = {
+ Api: Api,
+ SubApi: SubApi,
+ processAllRootNodes: processAllRootNodes,
+ processSingleRootNode: processSingleRootNode,
+ },
+ storageOperations = {
+ config: ['GET', 'PUT', 'POST', 'DELETE'],
+ operational: ['GET'],
+ operations: ['POST'],
+ },
+ nodePathStringCreator = {
+ list: function (node, pathstr) {
+ return pathstr + addNodePathStr(node) + '/' + (node.refKey.length ?
+ (getKeyIndentifiers(node.refKey).join('/') + '/') : '');
+ },
+ container: function (node, pathstr) {
+ return pathstr + addNodePathStr(node) + '/';
+ },
+ rpc: function (node, pathstr) {
+ return pathstr + addNodePathStr(node) + '/';
+ },
+ };
- var Api = function(basePath, module, revision, subApis) {
+ return service;
+
+ /**
+ * Base Api object
+ * @param basePath
+ * @param module
+ * @param revision
+ * @param subApis
+ * @constructor
+ */
+ function Api(basePath, module, revision, subApis) {
this.basePath = basePath;
this.module = module;
this.revision = revision;
this.subApis = subApis || [];
- this.addSubApis = function(subApis) {
+ this.addSubApis = function (subApis) {
var self = this;
- subApis.forEach(function(sa) {
+ subApis.forEach(function (sa) {
sa.parent = self;
self.subApis.push(sa);
});
};
- };
-
- var SubApi = function (pathTemplateString, operations, node, storage, parent) {
+ }
+
+ /**
+ * Base SubApi object
+ * @param pathTemplateString
+ * @param operations
+ * @param node
+ * @param storage
+ * @param parent
+ * @constructor
+ */
+ function SubApi(pathTemplateString, operations, node, storage, parent) {
this.node = node;
this.pathTemplateString = pathTemplateString;
this.operations = operations;
this.custFunct = [];
this.parent = parent ? parent : null;
- this.pathArray = (function(st, path) {
+ this.pathArray = (function (st, path) {
var pathString = (st ? st + '/' : '') + path;
return PathUtilsService.translate(pathString);
- }) (this.storage, this.pathTemplateString);
+ })(this.storage, this.pathTemplateString);
- this.equals = function(pathArray, compareIdentifierValues) {
- return this.pathArray.every(function(pa, i) {
+ this.equals = function (pathArray, compareIdentifierValues) {
+ return this.pathArray.every(function (pa, i) {
pa.equals(pathArray[i], compareIdentifierValues);
});
};
}
};
- this.clone = function(options) {
- var getOption = function(optName) {
+ this.clone = function (options) {
+ var getOption = function (optName) {
var res = null;
- if(options) {
+ if (options) {
res = options[optName] || null;
}
return res;
getOption('storage') || this.storage,
getOption('parent') || this.parent);
- if(getOption('clonePathArray')) {
- clone.pathArray = this.pathArray.map(function(pe) {
+ if (getOption('clonePathArray')) {
+ clone.pathArray = this.pathArray.map(function (pe) {
return pe.clone();
});
}
return clone;
};
- };
+ }
- var removeDuplicatedApis = function(apis) {
+ // TODO: add function's description
+ function removeDuplicatedApis(apis) {
var toRemove = [],
- sortApisByRevision = function(a, b) {
- var dateA = new Date(a.revision+'Z'),
- dateB = new Date(b.revision+'Z');
+ sortApisByRevision = function (a, b) {
+ var dateA = new Date(a.revision + 'Z'),
+ dateB = new Date(b.revision + 'Z');
return dateB - dateA;
};
- apis.forEach(function(a) {
- if(toRemove.indexOf(a) === -1) {
- var sortedApis = apis.filter(function(af) {
+ apis.forEach(function (a) {
+ if (toRemove.indexOf(a) === -1) {
+ var sortedApis = apis.filter(function (af) {
return a.module === af.module;
}).sort(sortApisByRevision);
}
});
- toRemove.forEach(function(a) {
+ toRemove.forEach(function (a) {
apis.splice(apis.indexOf(a), 1);
});
return apis;
- };
+ }
- var isConfigNode = function(node) {
+ // TODO: add function's description
+ function isConfigNode(node) {
var result = false;
- if(node.hasOwnProperty('isConfigStm')) {
+ if (node.hasOwnProperty('isConfigStm')) {
result = node.isConfigStm;
- } else if(node.parent) {
+ } else if (node.parent) {
result = isConfigNode(node.parent);
}
return result;
- };
+ }
- var addNodePathStr = function(node) {
+ // TODO: add function's description
+ function addNodePathStr(node) {
return (!node.parent || (node.parent.module !== node.module) ? node.module + ':' : '') + node.label;
- };
+ }
- var getBasePath = function() {
+ // TODO: add function's description
+ function getBasePath() {
return YangUtilsRestangularService.configuration.baseUrl + '/restconf/';
- };
+ }
- var getApiByModuleRevision = function(apis, module, revision) {
- return apis.filter(function(a) {
+ // TODO: add function's description
+ function getApiByModuleRevision(apis, module, revision) {
+ return apis.filter(function (a) {
return a.module === module && a.revision === revision;
})[0];
- };
+ }
- var getKeyIndentifiers = function(keys) {
+ // TODO: add function's description
+ function getKeyIndentifiers(keys) {
return keys.map(function (k) {
return '{' + k.label + '}';
});
- };
+ }
- var getStoragesByNodeType = function(node) {
+ // TODO: add function's description
+ function getStoragesByNodeType(node) {
var storages = [];
- if(NodeUtilsService.isRootNode(node.type)) {
- if(node.type === 'rpc') {
+ if (NodeUtilsService.isRootNode(node.type)) {
+ if (node.type === 'rpc') {
storages.push('operations');
} else {
storages.push('operational');
- if(isConfigNode(node)) {
+ if (isConfigNode(node)) {
storages.push('config');
}
}
}
return storages;
- };
+ }
- var getOperationsByStorage = function(storage) {
+ // TODO: add function's description
+ function getOperationsByStorage(storage) {
var operations = [];
- if(storageOperations.hasOwnProperty(storage)) {
+ if (storageOperations.hasOwnProperty(storage)) {
operations = storageOperations[storage];
}
return operations;
- };
-
- var storageOperations = {};
-
- storageOperations.config = ['GET', 'PUT', 'POST', 'DELETE'];
- storageOperations.operational = ['GET'];
- storageOperations.operations = ['POST'];
-
- var nodePathStringCreator = {};
+ }
- nodePathStringCreator.list = function(node, pathstr) {
- return pathstr + addNodePathStr(node) + '/' + (node.refKey.length ? (getKeyIndentifiers(node.refKey).join('/') + '/') : '');
- };
-
- nodePathStringCreator.container = function(node, pathstr) {
- return pathstr + addNodePathStr(node) + '/';
- };
-
- nodePathStringCreator.rpc = function(node, pathstr) {
- return pathstr + addNodePathStr(node) + '/';
- };
-
- var createSubApis = function(node, pathstr) {
+ // TODO: add function's description
+ function createSubApis(node, pathstr) {
var storages = getStoragesByNodeType(node);
- return storages.map(function(storage) {
+ return storages.map(function (storage) {
var subApi = new SubApi(pathstr, getOperationsByStorage(storage), node, storage);
return subApi;
});
- };
+ }
- var nodeChildrenProcessor = function(node, pathstr, subApis) {
- if(NodeUtilsService.isRootNode(node.type) && nodePathStringCreator.hasOwnProperty(node.type)) {
+ // TODO: add function's description
+ function nodeChildrenProcessor(node, pathstr, subApis) {
+ if (NodeUtilsService.isRootNode(node.type) && nodePathStringCreator.hasOwnProperty(node.type)) {
var templateStr = nodePathStringCreator[node.type](node, pathstr),
newSubApis = createSubApis(node, templateStr);
ArrayUtilsService.pushElementsToList(subApis, newSubApis);
- node.children.forEach(function(ch) {
+ node.children.forEach(function (ch) {
nodeChildrenProcessor(ch, templateStr, subApis);
});
}
- };
+ }
- //utility function
- var printApis = function(apis) {
+ /**
+ * Function for showing available apis in web browser's console
+ * @param apis
+ */
+ function printApis(apis) {
var co = '';
- apis.forEach(function(a) {
- a.subApis.forEach(function(sa) {
+ apis.forEach(function (a) {
+ a.subApis.forEach(function (sa) {
co += (sa.storage + '/' + sa.pathTemplateString + '\n');
});
});
// console.info(co);
- };
+ }
- ab.processAllRootNodes = function(nodes) {
+ // TODO: add service's description
+ function processAllRootNodes(nodes) {
var apis = [];
- nodes.forEach(function(node) {
+ nodes.forEach(function (node) {
var api = getApiByModuleRevision(apis, node.module, node.moduleRevision),
newApi = false;
- if(!api) {
+ if (!api) {
api = new Api(getBasePath(), node.module, node.moduleRevision);
newApi = true;
}
- api.addSubApis(ab.processSingleRootNode(node));
+ api.addSubApis(processSingleRootNode(node));
- if(newApi) {
+ if (newApi) {
apis.push(api);
}
});
printApis(apis);
return apis;
- };
+ }
- ab.processSingleRootNode = function(node) {
+ // TODO: add service's description
+ function processSingleRootNode(node) {
var templateStr = nodePathStringCreator[node.type](node, ''),
subApis = createSubApis(node, templateStr);
- node.children.forEach(function(ch) {
+ node.children.forEach(function (ch) {
nodeChildrenProcessor(ch, templateStr, subApis);
});
return subApis;
- };
-
- ab.Api = Api;
- ab.SubApi = SubApi;
+ }
- return ab;
}
- ApiBuilderService.$inject=['ArrayUtilsService', 'PathUtilsService', 'NodeUtilsService', 'YangUtilsRestangularService', 'CustomFuncService'];
+ ApiBuilderService.$inject = ['ArrayUtilsService', 'PathUtilsService', 'NodeUtilsService',
+ 'YangUtilsRestangularService', 'CustomFuncService'];
return ApiBuilderService;
-});
\ No newline at end of file
+});
'use strict';
function ArrayUtilsService(){
- var arrayUtils = {};
+ var service = {
+ getFirstElementByCondition: getFirstElementByCondition,
+ pushElementsToList: pushElementsToList,
+ };
+
+ return service;
- arrayUtils.getFirstElementByCondition = function(list, condition) {
- var selItems = list && condition ? list.filter(function(item) {
+ // TODO: add service's description
+ function getFirstElementByCondition(list, condition) {
+ var selItems = list && condition ? list.filter(function (item) {
return condition(item);
}) : [];
return (selItems.length ? selItems[0] : null);
- };
+ }
- arrayUtils.pushElementsToList = function(list, listToAdd) {
- listToAdd.forEach(function(e) {
- list.push(e);
- });
- };
+ // TODO: add service's description
+ function pushElementsToList(list, listToAdd) {
+ Array.prototype.push.apply(list, listToAdd);
+ }
- return arrayUtils;
}
- ArrayUtilsService.$inject=[];
+ ArrayUtilsService.$inject = [];
return ArrayUtilsService;
-});
\ No newline at end of file
+});
function CustomFuncService(){
- var CustFunctionality = function (label, node, callback, viewStr, hideButtonOnSelect) {
+ var service = {
+ createCustomFunctionalityApis: createCustomFunctionalityApis,
+ createNewFunctionality: createNewFunctionality,
+ getMPCustFunctionality: getMPCustFunctionality,
+ };
+
+ return service;
+
+ /**
+ * Base custom functionality object
+ * @param label
+ * @param node
+ * @param callback
+ * @param viewStr
+ * @param hideButtonOnSelect
+ * @constructor
+ */
+ function CustFunctionality(label, node, callback, viewStr, hideButtonOnSelect) {
this.label = label;
this.callback = callback;
this.viewStr = viewStr;
console.warn('no callback set for custom functionality', this.label);
}
};
- };
+ }
- var cmpApiToTemplatePath = function(subApi, templateStr) {
+ // TODO: add function's description
+ function cmpApiToTemplatePath(subApi, templateStr) {
var subApiStr = subApi.storage + '/' + subApi.pathTemplateString;
return subApiStr === templateStr;
- };
-
- var custFunct = {};
+ }
- custFunct.createNewFunctionality = function (label, node, callback, viewStr, hideButtonOnSelect) {
+ // TODO: add service's description
+ function createNewFunctionality(label, node, callback, viewStr, hideButtonOnSelect) {
if (node && callback) {
return new CustFunctionality(label, node, callback, viewStr, hideButtonOnSelect);
} else {
console.error('no node or callback is set for custom functionality');
}
- };
+ }
- custFunct.getMPCustFunctionality = function(funcList) {
- var mpCF = funcList.filter(function(cf) {
+ // TODO: add service's description
+ function getMPCustFunctionality(funcList) {
+ var mpCF = funcList.filter(function (cf) {
return cf.label === 'YANGUI_CUST_MOUNT_POINTS';
});
return mpCF[0];
- };
+ }
- custFunct.createCustomFunctionalityApis = function (apis, module, revision, pathString, label, callback, viewStr, hideButtonOnSelect) {
+ // TODO: add service's description
+ function createCustomFunctionalityApis(apis, module, revision, pathString, label,
+ callback, viewStr, hideButtonOnSelect) {
apis = apis.map(function (item) {
if ((module ? item.module === module : true) && (revision ? item.revision === revision : true)) {
return item;
});
- };
-
- return custFunct;
-
+ }
}
- CustomFuncService.$inject=[];
+ CustomFuncService.$inject = [];
return CustomFuncService;
-});
\ No newline at end of file
+});
'use strict';
function DataBackupService(){
- var bck = {};
- bck.storedData = {};
+ var service = {
+ getToScope: getToScope,
+ storedData: {},
+ storeFromScope: storeFromScope,
+ };
+
+ return service;
- var getKey = function(key) {
+ // TODO: add function's description
+ function getKey(key) {
return key || 'DEFAULT';
- };
+ }
- bck.storeFromScope = function(variables, scope, key) {
+ // TODO: add service's description
+ function storeFromScope(variables, scope, key) {
var data = {};
key = getKey(key);
- variables.forEach(function(k) {
- if(scope.hasOwnProperty(k)) {
+ variables.forEach(function (k) {
+ if (scope.hasOwnProperty(k)) {
data[k] = scope[k];
} else {
- console.warn('scope doesn\'t have variable',k);
+ console.warn('scope doesn\'t have variable', k);
}
});
- bck.storedData[key] = data;
- };
+ service.storedData[key] = data;
+ }
- bck.getToScope = function(variables, scope, key) {
+ // TODO: add service's description
+ function getToScope(variables, scope, key) {
var data = {};
key = getKey(key);
- if(bck.storedData.hasOwnProperty(key)) {
- data = bck.storedData[key];
+ if (service.storedData.hasOwnProperty(key)) {
+ data = service.storedData[key];
- variables.forEach(function(k) {
- if(data.hasOwnProperty(k)) {
+ variables.forEach(function (k) {
+ if (data.hasOwnProperty(k)) {
scope[k] = data[k];
} else {
- console.warn('storet data doesn\'t have variable',k);
+ console.warn('storet data doesn\'t have variable', k);
}
});
}
- };
-
- return bck;
+ }
}
- DataBackupService.$inject=[];
+ DataBackupService.$inject = [];
return DataBackupService;
-});
\ No newline at end of file
+});
'use strict';
function EventDispatcherService(){
- var eD = {};
- var convertArgsToList = function(arg) {
- var argList = [],
- l = arg.length,
- i = 0;
-
- for(i = 0; i < l; i++) {
- argList.push(arg[i]);
- }
-
- return argList;
+ var service = {
+ broadcastHandler: {},
+ dispatch: dispatch,
+ registerHandler: registerHandler
};
- eD.broadcastHandler = {};
+ return service;
- eD.registerHandler = function(source, bcCallback) {
- eD.broadcastHandler[source] = bcCallback;
- };
+ // TODO: add service's description
+ function registerHandler(source, bcCallback) {
+ service.broadcastHandler[source] = bcCallback;
+ }
- eD.dispatch = function() {
- var args = convertArgsToList(arguments),
+ // TODO: add service's description
+ function dispatch() {
+ var args = Array.prototype.slice.call(arguments),
argumentList = args.slice(1),
- handler = eD.broadcastHandler[arguments[0]];
+ handler = service.broadcastHandler[arguments[0]];
- if(handler) {
+ if (handler) {
handler(argumentList);
}
- };
-
- return eD;
+ }
}
- EventDispatcherService.$inject=[];
+ EventDispatcherService.$inject = [];
return EventDispatcherService;
-});
\ No newline at end of file
+});
'use strict';
function FilterNodeWrapperService(constants){
- var nodeWrapperForFilter = {};
- nodeWrapperForFilter.init = function(node){
+ var service = {
+ init: init,
+ wrapForFilter: wrapForFilter,
+ };
+
+ return service;
+
+ // TODO: add service's description
+ function init(node){
node.childrenFilterConditions = function (children){
var allowedNodeTypesForFilter = constants.ALLOWED_NODE_TYPES_FOR_FILTER,
- conditionTypes = function(item){
- return allowedNodeTypesForFilter.some(function(elem){
+ conditionTypes = function (item){
+ return allowedNodeTypesForFilter.some(function (elem){
return elem === item.type;
- });},
- conditionEmptyChildren = function(item){
- return item.children.some(function(child){
+ }); },
+ conditionEmptyChildren = function (item){
+ return item.children.some(function (child){
return (child.type !== 'leaf-list' && child.type !== 'list');
- });},
- conditionChildDescription = function(item){
- return !(item.children.every(function(childDes){
+ }); },
+ conditionChildDescription = function (item){
+ return !(item.children.every(function (childDes){
return childDes.type === 'description';
- }));};
+ })); };
- return children.filter(function(item){
- if(item.parent.type === 'leaf' || item.parent.parent.type === 'leaf'){
+ return children.filter(function (item){
+ if (item.parent.type === 'leaf' || item.parent.parent.type === 'leaf'){
return true;
- }else{
+ } else {
return conditionTypes(item) && conditionEmptyChildren(item) && conditionChildDescription(item);
}
});
};
node.getChildrenForFilter = function () {
- return node.childrenFilterConditions(node.getChildren(null,null,constants.NODE_UI_DISPLAY,null));
+ return node.childrenFilterConditions(node.getChildren(null, null, constants.NODE_UI_DISPLAY, null));
};
node.deepCopyForFilter = function (additionalProperties) {
self = this,
allowedLeafTypesForFilter = constants.ALLOWED_LEAF_TYPES_FOR_FILTER,
- addFilterProps = function(childrenArray){
- if(childrenArray.type === 'leaf' && childrenArray.children && childrenArray.children.length){
- if(childrenArray.children.some(function(item){
- return item.type === 'type' && allowedLeafTypesForFilter.indexOf(item.label) !== -1;
- })){
- childrenArray['filterType'] = '=';
+ addFilterProps = function (childrenArray){
+ if (childrenArray.type === 'leaf' && childrenArray.children && childrenArray.children.length){
+ if (childrenArray.children.some(function (item){
+ return item.type === 'type' && allowedLeafTypesForFilter.indexOf(item.label) !== -1;
+ })){
+ childrenArray.filterType = '=';
}
- if(childrenArray.children.some(function(item){
- return item.type === 'type' && item.label === 'bits';
- })){
- childrenArray['filterBitsValue'] = '';
+ if (childrenArray.children.some(function (item){
+ return item.type === 'type' && item.label === 'bits';
+ })){
+ childrenArray.filterBitsValue = '';
}
- if(childrenArray.children.some(function(item){
- return item.type === 'type' && item.label === 'enumeration';
- })){
- childrenArray['filterSelectboxBitsValue'] = [];
+ if (childrenArray.children.some(function (item){
+ return item.type === 'type' && item.label === 'enumeration';
+ })){
+ childrenArray.filterSelectboxBitsValue = [];
}
}
};
additionalProperties = additionalProperties || ['pathString'];
- additionalProperties.forEach(function(prop) {
+ additionalProperties.forEach(function (prop) {
if (prop !== 'children' && self.hasOwnProperty(prop) && copy.hasOwnProperty(prop) === false) {
copy[prop] = self[prop];
}
this.childrenFilterConditions(this.children).forEach(function (child) {
var childCopy = null;
- if(child.type === 'leaf'){
+ if (child.type === 'leaf'){
childCopy = child.deepCopy();
- }else{
- nodeWrapperForFilter.init(child);
+ } else {
+ init(child);
childCopy = child.deepCopyForFilter();
}
return copy;
};
- };
-
- nodeWrapperForFilter.wrapForFilter = function(node) {
+ }
+ // TODO: add service's description
+ function wrapForFilter(node) {
var comparePropToElemByName = function (propName, elemName) {
- return (propName.indexOf(':') > -1 ? propName.split(':')[1] : propName) === elemName; //TODO also check by namespace - redundancy?
+ // TODO: also check by namespace - redundancy?
+ return (propName.indexOf(':') > -1 ? propName.split(':')[1] : propName) === elemName;
},
wrapperFilter = {
},
leaf: function (node) {
- var auxBuildRequest = node['buildRequest'],
- auxFill = node['fill'],
- auxClear = node['clear'],
+ var auxBuildRequest = node.buildRequest,
+ auxFill = node.fill,
+ auxClear = node.clear,
fnToString = function (string) {
var valueStr = '';
try {
valueStr = fnToString(node.value);
var filterTypeArray = {
- '=': function(element,filterValue,i){
+ '=': function (element, filterValue, i){
return element ? element[i] === filterValue : false;
},
- '>': function(element,filterValue,i){
+ '>': function (element, filterValue, i){
return element ? element[i] > filterValue : false;
},
- '>=': function(element,filterValue,i){
+ '>=': function (element, filterValue, i){
return element ? element[i] >= filterValue : false;
},
- '<': function(element,filterValue,i){
+ '<': function (element, filterValue, i){
return element ? element[i] < filterValue : false;
},
- '<=': function(element,filterValue,i){
+ '<=': function (element, filterValue, i){
return element ? element[i] <= filterValue : false;
},
- 'contains': function(element,filterValue,i){
+ 'contains': function (element, filterValue, i){
return element ? element[i] && element[i].indexOf(filterValue) > -1 : false;
},
- 'regExp': function(element,filterValue,i){
- testRegExp = function (patternString, nodeValue) {
+ 'regExp': function (element, filterValue, i){
+ var testRegExp = function (patternString, nodeValue) {
var pattern = new RegExp(patternString);
return pattern.test(nodeValue);
};
- return element ? testRegExp(filterValue,element[i]) : false;
+ return element ? testRegExp(filterValue, element[i]) : false;
},
- 'range': function(element,from,to,i){
- if(from && to){
+ 'range': function (element, from, to, i){
+ if (from && to){
return element ? element[i] <= to && element[i] >= from : false;
- }else if(from){
+ } else if (from){
return element ? element[i] >= from : false;
- }else{
+ } else {
return element ? element[i] <= to : false;
}
- }};
+ } };
- if (valueStr || (node.filterBitsValue && node.filterBitsValue !== '') || (node.filterSelectboxBitsValue && node.filterSelectboxBitsValue.length) ||
- (node.filterRangeFrom && node.filterRangeFrom !== '') || (node.filterRangeTo && node.filterRangeTo !== '')){
+ if (valueStr || (node.filterBitsValue && node.filterBitsValue !== '') ||
+ (node.filterSelectboxBitsValue && node.filterSelectboxBitsValue.length) ||
+ (node.filterRangeFrom && node.filterRangeFrom !== '') ||
+ (node.filterRangeTo && node.filterRangeTo !== '')){
var reqFilter = {};
- if(node.filterSelectboxBitsValue && node.filterSelectboxBitsValue.length){
+ if (node.filterSelectboxBitsValue && node.filterSelectboxBitsValue.length){
reqFilter.selectboxBitsValue = node.filterSelectboxBitsValue;
- reqFilter.getResult = function(element,filterValue,i){
- var selectSomeFun = function(filterSelectboxBitsValue,el){
- return filterSelectboxBitsValue.some(function(item,$index){
+ reqFilter.getResult = function (element, filterValue, i){
+ var selectSomeFun = function (filterSelectboxBitsValue, el){
+ return filterSelectboxBitsValue.some(function (item){
return item === el;
});
};
- return element[i] && selectSomeFun(filterValue,element[i]);
+ return element[i] && selectSomeFun(filterValue, element[i]);
};
- }else{
- if(node.filterBitsValue && node.filterBitsValue !== ''){
+ } else {
+ if (node.filterBitsValue && node.filterBitsValue !== ''){
reqFilter.bitsValue = node.filterBitsValue;
- }else{
+ } else {
reqFilter.value = valueStr;
}
- if(node.filterType){
+ if (node.filterType){
reqFilter.filterType = node.filterType;
- }else{
+ } else {
reqFilter.filterType = '=';
}
- if(node.filterRangeFrom){
+ if (node.filterRangeFrom){
reqFilter.filterRangeFrom = node.filterRangeFrom;
}
-
- if(node.filterRangeTo){
+ if (node.filterRangeTo){
reqFilter.filterRangeTo = node.filterRangeTo;
}
};
node.fill = function (name, data) {
- if(data){
- if(data.hasOwnProperty('value')){
+ if (data){
+ if (data.hasOwnProperty('value')){
auxFill(name, data.value);
}
var match = '';
- if(data.hasOwnProperty('filterType')){
+ if (data.hasOwnProperty('filterType')){
match = comparePropToElemByName(name, node.label);
- if(match){
+ if (match){
node.filterType = data.filterType;
}
}
- if(data.hasOwnProperty('bitsValue')){
+ if (data.hasOwnProperty('bitsValue')){
match = comparePropToElemByName(name, node.label);
- if(match){
+ if (match){
node.filterBitsValue = data.bitsValue;
}
}
- if(data.hasOwnProperty('selectboxBitsValue')){
+ if (data.hasOwnProperty('selectboxBitsValue')){
match = comparePropToElemByName(name, node.label);
- if(match){
+ if (match){
node.filterSelectboxBitsValue = data.selectboxBitsValue;
}
}
- if(data.hasOwnProperty('filterRangeFrom')){
+ if (data.hasOwnProperty('filterRangeFrom')){
match = comparePropToElemByName(name, node.label);
- if(match){
+ if (match){
node.filterRangeFrom = data.filterRangeFrom;
}
}
- if(data.hasOwnProperty('filterRangeTo')){
+ if (data.hasOwnProperty('filterRangeTo')){
match = comparePropToElemByName(name, node.label);
- if(match){
+ if (match){
node.filterRangeTo = data.filterRangeTo;
}
}
- }else{
+ } else {
console.error('fill data are empty');
}
};
auxClear();
node.value = '';
- if(node.filterType){
+ if (node.filterType){
node.filterType = '=';
}
- if(node.filterBitsValue){
+ if (node.filterBitsValue){
node.filterBitsValue = '';
}
- if(node.filterSelectboxBitsValue){
+ if (node.filterSelectboxBitsValue){
node.filterSelectboxBitsValue = [];
}
- if(node.filterRangeFrom){
+ if (node.filterRangeFrom){
node.filterRangeFrom = '';
}
- if(node.filterRangeTo){
+ if (node.filterRangeTo){
node.filterRangeTo = '';
}
};
},
_listElem: function (node) {
- }
+ },
};
wrapperFilter.wrapAllFilter(node);
- };
-
-
- return nodeWrapperForFilter;
+ }
}
- FilterNodeWrapperService.$inject=['constants'];
+ FilterNodeWrapperService.$inject = ['constants'];
return FilterNodeWrapperService;
-});
\ No newline at end of file
+});
function ListFilteringService(FilterNodeWrapperService, RequestBuilderService){
var wasFound,
- filterResult;
-
-
- var getNodePathInStructure = function (filterRootNode,node) {
- var iterator = -1,
- findNodeInStructure = function (currentParentStructure){
- if(currentParentStructure.children.length && currentParentStructure.type !== 'leaf'){
- if(!(currentParentStructure.children.some(function(element){ return element === node; }))){
- currentParentStructure.children.forEach(function(child,index){
- checkHasSearchedNode(child,node);
- });
- }else{
- wasFound = true;
- }
- }
- },
- checkHasSearchedNode = function (currentParent) {
- if(currentParent === node){
- wasFound = true;
- }else{
- if(currentParent.actElemStructure){
- findNodeInStructure(currentParent.actElemStructure);
- }else{
- findNodeInStructure(currentParent);
- }
- }
- },
- getIndexOfSearchedNode = function (parentNodeStructure) {
- parentNodeStructure.children.forEach(function(elem,index){
- wasFound = false;
- checkHasSearchedNode(elem,node);
- if(wasFound){
- node.searchedPath.push(index);
- }
- });
- if(parentNodeStructure.children[node.searchedPath[iterator]] !== node){
- getSearchedPath(parentNodeStructure.children[node.searchedPath[iterator]]);
- }
- },
- getSearchedPath = function(parentNode){
- iterator++;
- if(parentNode.actElemStructure){
- getIndexOfSearchedNode(parentNode.actElemStructure);
- }else{
- getIndexOfSearchedNode(parentNode);
- }
- };
-
- if(filterRootNode !== node){
- getSearchedPath(filterRootNode);
- }
- },
-
- clearFilterNodes = function(node) {
- node.referenceNode.filterNodes.forEach(function(filterNode){
- filterNode.clear();
- });
- },
-
- loadFilterNodes = function (node) {
- var fillFuc = function(fillNods, prop, filVal){
- fillNods.forEach(function(filterNode){
- filterNode.fill(prop, filVal[prop]);
- });
- };
-
- if(node.referenceNode.filters[node.currentFilter].filteredValues){
- node.referenceNode.filters[node.currentFilter].filteredValues.forEach(function(item){
- for (var prop in item) {
- fillFuc(node.referenceNode.filterNodes, prop, item);
- }
- });
- }
- },
-
- getFilterResult = function(element, filterValue, node){
- for (var i in filterValue){
- if(!filterValue[i].filterType) {
- continue;
- }
-
- if(!filterValue[i].hasOwnProperty('value') && !filterValue[i].hasOwnProperty('selectboxBitsValue') && !filterValue[i].hasOwnProperty('bitsValue') &&
- !filterValue[i].hasOwnProperty('filterRangeFrom') && !filterValue[i].hasOwnProperty('filterRangeTo') && element[i]){
- getFilterResult(element[i],filterValue[i]);
- }else{
- if(filterValue[i].selectboxBitsValue && filterValue[i].selectboxBitsValue.length){
- filterResult = filterValue[i].getResult(element,filterValue[i].selectboxBitsValue,i);
- }else{
- if((filterValue[i].filterRangeFrom && filterValue[i].filterRangeFrom !== '') || (filterValue[i].filterRangeTo && filterValue[i].filterRangeTo !== '')){
- filterResult = filterValue[i].getFilterResult[filterValue[i].filterType](element,filterValue[i].filterRangeFrom,filterValue[i].filterRangeTo,i);
- }else if(filterValue[i].bitsValue && filterValue[i].bitsValue !== ''){
- filterResult = filterValue[i].getFilterResult[filterValue[i].filterType](element,filterValue[i].bitsValue,i);
- }else {
- filterResult = filterValue[i].getFilterResult[filterValue[i].filterType](element,filterValue[i].value,i);
- }
- }
- }
- }
- },
-
- getActElementFilter = function (node) {
- var actData = [];
-
- node.actElemIndex = 0;
- if(node.filteredListData && node.filteredListData.length){
- actData = node.filteredListData[node.actElemIndex];
- }else{
- actData = node.listData[node.actElemIndex];
- }
-
- node.actElemStructure.clear();
- for (var prop in actData) {
- node.actElemStructure.fillListElement(prop, actData[prop]);
- }
+ filterResult,
+ service = {
+ applyFilter: applyFilter,
+ clearFilterData: clearFilterData,
+ createNewFilter: createNewFilter,
+ getFilterData: getFilterData,
+ removeEmptyFilters: removeEmptyFilters,
+ showListFilterWin: showListFilterWin,
+ switchFilter: switchFilter
};
- var listFiltering = {};
+ return service;
- listFiltering.removeEmptyFilters = function (node) {
- if(node.referenceNode && node.referenceNode.filters){
+ // TODO: add service's description
+ function removeEmptyFilters(node) {
+ if (node.referenceNode && node.referenceNode.filters){
var wasDeleted = false;
- node.referenceNode.filters = node.referenceNode.filters.filter(function(filter){
- if(filter.filteredValues && filter.filteredValues.length){
+ node.referenceNode.filters = node.referenceNode.filters.filter(function (filter){
+ if (filter.filteredValues && filter.filteredValues.length){
return true;
- }else{
+ } else {
wasDeleted = true;
return false;
}
});
- if(wasDeleted){
- listFiltering.switchFilter(node,0,true);
+ if (wasDeleted){
+ switchFilter(node, 0, true);
}
}
- };
+ }
- listFiltering.showListFilterWin = function (filterRootNode,node) {
- if(!node.searchedPath.length){
- getNodePathInStructure(filterRootNode,node);
+ // TODO: add service's description
+ function showListFilterWin(filterRootNode, node) {
+ if (!node.searchedPath.length){
+ getNodePathInStructure(filterRootNode, node);
}
- if(!node.referenceNode){
+ if (!node.referenceNode){
node.referenceNode = filterRootNode;
- node.searchedPath.forEach(function(elem){
+ node.searchedPath.forEach(function (elem){
node.referenceNode = node.referenceNode.children[elem];
});
}
- if(!node.referenceNode.filterNodes.length){
+ if (!node.referenceNode.filterNodes.length){
FilterNodeWrapperService.init(node);
node.referenceNode.filterNodes = node.getNewFilterElement();
}
- if(!(node.referenceNode.filters && node.referenceNode.filters.length)){
- node.referenceNode.filters.push({name : 'Filter 1 name', active : 1});
- }else{
- listFiltering.getFilterData(node);
- listFiltering.removeEmptyFilters(node);
+ if (!(node.referenceNode.filters && node.referenceNode.filters.length)){
+ node.referenceNode.filters.push({ name: 'Filter 1 name', active: 1 });
+ } else {
+ getFilterData(node);
+ removeEmptyFilters(node);
}
- };
-
- listFiltering.createNewFilter = function (node) {
- node.referenceNode.filters.push({name : 'Filter ' + (node.referenceNode.filters.length+1) + ' name', active : 1});
+ }
- listFiltering.switchFilter(node,node.referenceNode.filters.length-1);
- };
-
- listFiltering.getFilterData = function (node) {
- node.referenceNode.filters[node.currentFilter].filteredValues = node.referenceNode.filterNodes.map(function(element){
- var requestData = {};
- element.buildRequest(RequestBuilderService, requestData);
- return requestData;
- }).filter(function(item){
- return $.isEmptyObject(item) === false;
+ // TODO: add service's description
+ function createNewFilter(node) {
+ node.referenceNode.filters.push({
+ name: 'Filter ' + (node.referenceNode.filters.length + 1) + ' name',
+ active: 1
});
- };
- listFiltering.switchFilter = function (node,showedFilter,fromRemoveEmptyFilters) {
- if(node.referenceNode.filters.length){
- if(!fromRemoveEmptyFilters){
- listFiltering.getFilterData(node);
+ switchFilter(node, node.referenceNode.filters.length - 1);
+ }
+
+ // TODO: add service's description
+ function getFilterData(node) {
+ node.referenceNode.filters[node.currentFilter].filteredValues =
+ node.referenceNode.filterNodes.map(function (element){
+ var requestData = {};
+ element.buildRequest(RequestBuilderService, requestData);
+ return requestData;
+ }).filter(function (item){
+ return $.isEmptyObject(item) === false;
+ });
+ }
+
+ // TODO: add service's description
+ function switchFilter(node, showedFilter, fromRemoveEmptyFilters) {
+ if (node.referenceNode.filters.length){
+ if (!fromRemoveEmptyFilters){
+ getFilterData(node);
}
clearFilterNodes(node);
node.currentFilter = showedFilter;
loadFilterNodes(node);
- }else{
+ } else {
node.currentFilter = 0;
}
- };
+ }
- listFiltering.applyFilter = function (node) {
- listFiltering.getFilterData(node);
- listFiltering.removeEmptyFilters(node);
+ // TODO: add service's description
+ function applyFilter(node) {
+ getFilterData(node);
+ removeEmptyFilters(node);
- node.filteredListData = node.listData.slice().filter(function(element){
- return node.referenceNode.filters.filter(function(fil){
+ node.filteredListData = node.listData.slice().filter(function (element){
+ return node.referenceNode.filters.filter(function (fil){
return fil.active === 1;
- }).some(function(filter){
- return filter.filteredValues.every(function(filterValue){
+ }).some(function (filter){
+ return filter.filteredValues.every(function (filterValue){
filterResult = null;
- getFilterResult(element,filterValue,node);
+ getFilterResult(element, filterValue, node);
return filterResult;
});
});
});
getActElementFilter(node);
- // console.info('applyFilter node',node,'node.referenceNode.filterNodes',node.referenceNode.filterNodes,'node.referenceNode.filters',node.referenceNode.filters);
- };
+ // console.info('applyFilter node', node, 'node.referenceNode.filterNodes',
+ // node.referenceNode.filterNodes, 'node.referenceNode.filters', node.referenceNode.filters);
+ }
- listFiltering.clearFilterData = function (node, changeAct, filterForClear, removeFilters) {
- if(filterForClear){
+ // TODO: add service's description
+ function clearFilterData(node, changeAct, filterForClear, removeFilters) {
+ if (filterForClear){
filterForClear--;
- if(node.referenceNode.filters.length === 1){
+ if (node.referenceNode.filters.length === 1){
node.referenceNode.filters = [];
- node.referenceNode.filters.push({name : 'Filter 1 name', active : 1});
+ node.referenceNode.filters.push({ name: 'Filter 1 name', active: 1 });
clearFilterNodes(node);
- }else{
- node.referenceNode.filters.splice(filterForClear,1);
+ } else {
+ node.referenceNode.filters.splice(filterForClear, 1);
node.currentFilter = 0;
clearFilterNodes(node);
loadFilterNodes(node);
}
- }else{
- if(removeFilters){
+ } else {
+ if (removeFilters){
node.referenceNode.filters = [];
clearFilterNodes(node);
node.currentFilter = 0;
- }else{
- node.referenceNode.filters.forEach(function(filter){
+ } else {
+ node.referenceNode.filters.forEach(function (filter){
filter.active = 2;
});
- listFiltering.getFilterData(node);
- listFiltering.removeEmptyFilters(node);
+ getFilterData(node);
+ removeEmptyFilters(node);
}
node.filteredListData = [];
}
- if(changeAct){
+ if (changeAct){
getActElementFilter(node);
}
- };
+ }
+
+ // TODO: add function's description
+ function getNodePathInStructure(filterRootNode, node) {
+ var iterator = -1;
+
+ if (filterRootNode !== node){
+ getSearchedPath(filterRootNode);
+ }
+
+ // TODO: add function's description
+ function getSearchedPath(parentNode){
+ iterator++;
+ if (parentNode.actElemStructure){
+ getIndexOfSearchedNode(parentNode.actElemStructure);
+ } else {
+ getIndexOfSearchedNode(parentNode);
+ }
+ }
+
+ // TODO: add function's description
+ function findNodeInStructure(currentParentStructure){
+ if (currentParentStructure.children.length && currentParentStructure.type !== 'leaf'){
+ if (!(currentParentStructure.children.some(function (element){ return element === node; }))){
+ currentParentStructure.children.forEach(function (child){
+ checkHasSearchedNode(child, node);
+ });
+ } else {
+ wasFound = true;
+ }
+ }
+ }
+
+ // TODO: add function's description
+ function getIndexOfSearchedNode(parentNodeStructure) {
+ parentNodeStructure.children.forEach(function (elem, index){
+ wasFound = false;
+ checkHasSearchedNode(elem, node);
+ if (wasFound){
+ node.searchedPath.push(index);
+ }
+ });
+ if (parentNodeStructure.children[node.searchedPath[iterator]] !== node){
+ getSearchedPath(parentNodeStructure.children[node.searchedPath[iterator]]);
+ }
+ }
+
+ // TODO: add function's description
+ function checkHasSearchedNode(currentParent) {
+ if (currentParent === node){
+ wasFound = true;
+ } else {
+ if (currentParent.actElemStructure){
+ findNodeInStructure(currentParent.actElemStructure);
+ } else {
+ findNodeInStructure(currentParent);
+ }
+ }
+ }
+ }
+
+ // TODO: add function's description
+ function clearFilterNodes(node) {
+ node.referenceNode.filterNodes.forEach(function (filterNode){
+ filterNode.clear();
+ });
+ }
+
+ // TODO: add function's description
+ function loadFilterNodes(node) {
+ var fillFuc = function (fillNods, prop, filVal){
+ fillNods.forEach(function (filterNode){
+ filterNode.fill(prop, filVal[prop]);
+ });
+ };
+
+ if (node.referenceNode.filters[node.currentFilter].filteredValues){
+ node.referenceNode.filters[node.currentFilter].filteredValues.forEach(function (item){
+ Object.keys(item).forEach(function (prop) {
+ fillFuc(node.referenceNode.filterNodes, prop, item);
+ });
+ });
+ }
+ }
+
+ // TODO: add function's description
+ function getFilterResult(element, filterValue){
+ for (var i in filterValue){
+ if(!filterValue[i].filterType) {
+ continue;
+ }
+
+ if (!filterValue[i].hasOwnProperty('value') && !filterValue[i].hasOwnProperty('selectboxBitsValue') &&
+ !filterValue[i].hasOwnProperty('bitsValue') && !filterValue[i].hasOwnProperty('filterRangeFrom') &&
+ !filterValue[i].hasOwnProperty('filterRangeTo') && element[i]){
+ getFilterResult(element[i], filterValue[i]);
+ } else {
+ if (filterValue[i].selectboxBitsValue && filterValue[i].selectboxBitsValue.length){
+ filterResult = filterValue[i].getResult(element, filterValue[i].selectboxBitsValue, i);
+ } else {
+ if ((filterValue[i].filterRangeFrom && filterValue[i].filterRangeFrom !== '') ||
+ (filterValue[i].filterRangeTo && filterValue[i].filterRangeTo !== '')){
+ filterResult = filterValue[i].getFilterResult[filterValue[i].filterType](element, filterValue[i].filterRangeFrom, filterValue[i].filterRangeTo, i);
+ } else if (filterValue[i].bitsValue && filterValue[i].bitsValue !== ''){
+ filterResult = filterValue[i].getFilterResult[filterValue[i].filterType](element, filterValue[i].bitsValue, i);
+ } else {
+ filterResult = filterValue[i].getFilterResult[filterValue[i].filterType](element, filterValue[i].value, i);
+ }
+ }
+ }
+ }
+ }
+
+ // TODO: add function's description
+ function getActElementFilter(node) {
+ var actData = [];
+
+ node.actElemIndex = 0;
+ if (node.filteredListData && node.filteredListData.length){
+ actData = node.filteredListData[node.actElemIndex];
+ } else {
+ actData = node.listData[node.actElemIndex];
+ }
+
+ node.actElemStructure.clear();
+ Object.keys(actData).forEach(function (prop) {
+ node.actElemStructure.fillListElement(prop, actData[prop]);
+ });
+ }
- return listFiltering;
}
- ListFilteringService.$inject=['FilterNodeWrapperService', 'RequestBuilderService'];
+ ListFilteringService.$inject = ['FilterNodeWrapperService', 'RequestBuilderService'];
return ListFilteringService;
-});
\ No newline at end of file
+});
'use strict';
function ModuleConnectorService(){
- var isBuildInType = function (type) {
- return ['int8', 'int16', 'int32', 'int64', 'uint8', 'uint16', 'uint32', 'uint64',
- 'decimal64', 'string', 'boolean', 'enumeration', 'bits', 'binary',
- 'leafref', 'identityref', 'empty', 'union', 'instance-identifier'].indexOf(type) > -1;
- };
- var moduleConnector = {},
- linkFunctions = {};
+ var service = {
+ processModuleObjs: processModuleObjs,
+ __test: {
+ isBuildInType: isBuildInType,
+ linkFunctions: linkFunctions,
+ findLinkedStatement: findLinkedStatement,
+ appendChildren: appendChildren,
+ searchModule: searchModule,
+ applyLinks: applyLinks,
+ interConnectModules: interConnectModules,
+ applyModuleRevision: applyModuleRevision,
+ },
+ },
+ linkFunctions = {
+ uses: uses,
+ type: type,
+ };
+
+ return service;
+
+ // TODO: add service's description
+ function processModuleObjs(modules) {
+ var rootNodes = [],
+ augments = [],
+ connectedModules = interConnectModules(modules.slice());
+
+ connectedModules.forEach(function (module) {
+ rootNodes = rootNodes.concat(module.getRoots());
+ augments = augments.concat(module.getAugments());
+ });
+
+ return { rootNodes: rootNodes, augments: augments };
+ }
- linkFunctions.uses = function (usesNode, currentModule) {
+ // TODO: add function's description
+ function uses(usesNode, currentModule) {
var targetType = 'grouping';
return function (modules) {
var data = findLinkedStatement(usesNode, targetType, currentModule, modules),
changed = false;
if (node && module) {
- usesNode.parent.children.splice(usesNode.parent.children.indexOf(usesNode), 1); //delete uses node
+ usesNode.parent.children.splice(usesNode.parent.children.indexOf(usesNode), 1); // delete uses node
for (var i = 0; i < node.children.length; i++) {
applyLinks(node.children[i], module, modules);
}
return changed;
};
- };
+ }
- linkFunctions.type = function (typeNode, currentModule) {
+ // TODO: add function's description
+ function type(typeNode, currentModule) {
var targetType = 'typedef';
if (isBuildInType(typeNode.label) === false) {
changed = false;
if (node) {
- typeNode.parent.children.splice(typeNode.parent.children.indexOf(typeNode), 1); //delete referencing type node
+ // delete referencing type node
+ typeNode.parent.children.splice(typeNode.parent.children.indexOf(typeNode), 1);
typeNode.parent.addChild(node);
changed = true;
}
return false;
};
}
- };
+ }
- var findLinkedStatement = function (node, targetType, currentModule, modules) {
+ // TODO: add function's description
+ function isBuildInType(type) {
+ return ['int8', 'int16', 'int32', 'int64', 'uint8', 'uint16', 'uint32', 'uint64',
+ 'decimal64', 'string', 'boolean', 'enumeration', 'bits', 'binary',
+ 'leafref', 'identityref', 'empty', 'union', 'instance-identifier'].indexOf(type) > -1;
+ }
+
+ // TODO: add function's description
+ function findLinkedStatement(node, targetType, currentModule, modules) {
var sourceNode,
sourceModule,
link = node.label;
var parts = link.split(':'),
targetImport = currentModule.getImportByPrefix(parts[0]);
- sourceModule = targetImport ? searchModule(modules, targetImport.label, targetImport.revisionDate) : null;
+ sourceModule = targetImport ?
+ searchModule(modules, targetImport.label, targetImport.revisionDate) : null;
sourceNode = sourceModule ? sourceModule.searchNode(targetType, parts[1]) : null;
} else {
sourceModule = searchModule(modules, node.module, node.moduleRevision);
sourceNode = sourceModule ? sourceModule.searchNode(targetType, link) : null;
}
- return {node: sourceNode, module: sourceModule};
- };
+ return { node: sourceNode, module: sourceModule };
+ }
- var appendChildren = function (targetNode, sourceNode) {
+ // TODO: add function's description
+ function appendChildren(targetNode, sourceNode) {
sourceNode.children.forEach(function (child) {
targetNode.addChild(child);
});
- };
+ }
- var searchModule = function (modules, moduleName, moduleRevision) {
+ // TODO: add function's description
+ function searchModule(modules, moduleName, moduleRevision) {
var searchResults = modules.filter(function (item) {
return (moduleName === item._name && (moduleRevision ? moduleRevision === item._revision : true));
}),
targetModule = (searchResults && searchResults.length) ? searchResults[0] : null;
return targetModule;
- };
- var applyLinks = function (node, module, modules) {
+ }
+
+ // TODO: add function's description
+ function applyLinks(node, module, modules) {
var changed = false;
- if (linkFunctions.hasOwnProperty(node.type)) { //applying link function to uses.node
+ if (linkFunctions.hasOwnProperty(node.type)) { // applying link function to uses.node
changed = linkFunctions[node.type](node, module)(modules);
}
for (var i = 0; i < node.children.length; i++) {
if (applyLinks(node.children[i], module, modules)) {
- i--; //need to repeat current index because we are deleting uses nodes, so in case there are more uses in row, it would skip second one
+ i--;
+ // need to repeat current index because we are deleting uses nodes,
+ // so in case there are more uses in row, it would skip second one
}
}
return changed;
- };
+ }
- var interConnectModules = function (modules) {
- var rootNodes = [],
- augments = [];
+ // TODO: add function's description
+ function interConnectModules(modules) {
modules.forEach(function (module) {
module.getRoots().concat(module.getRawAugments()).forEach(function (node) {
});
return modules;
- };
+ }
- var applyModuleRevision = function (node, module, revision) {
+ // TODO: add function's description
+ function applyModuleRevision(node, module, revision) {
node.module = module;
node.moduleRevision = revision;
});
return node;
- };
-
- moduleConnector.processModuleObjs = function (modules) {
- var rootNodes = [],
- augments = [],
- connectedModules = interConnectModules(modules.slice());
-
- connectedModules.forEach(function (module) {
- rootNodes = rootNodes.concat(module.getRoots());
- augments = augments.concat(module.getAugments());
- });
-
- return {rootNodes: rootNodes, augments: augments};
- };
-
- moduleConnector.__test = {
- isBuildInType: isBuildInType,
- linkFunctions: linkFunctions,
- findLinkedStatement: findLinkedStatement,
- appendChildren: appendChildren,
- searchModule: searchModule,
- applyLinks: applyLinks,
- interConnectModules: interConnectModules,
- applyModuleRevision: applyModuleRevision
- };
-
- return moduleConnector;
+ }
}
- ModuleConnectorService.$inject=[];
+ ModuleConnectorService.$inject = [];
return ModuleConnectorService;
-});
\ No newline at end of file
+});
'use strict';
function NodeUtilsService(){
- var nu = {};
- nu.isRootNode = function (type) {
- return type === 'container' || type === 'list' || type === 'rpc';
+ var service = {
+ isRootNode: isRootNode,
+ isOnlyOperationalNode: isOnlyOperationalNode,
};
- nu.isOnlyOperationalNode = function (node) {
- return node.hasOwnProperty('isConfigStm') ? node.isConfigStm !== false : true;
- };
+ return service;
- return nu;
+ // TODO: add service's description
+ function isRootNode(type) {
+ return type === 'container' || type === 'list' || type === 'rpc';
+ }
+
+ // TODO: add service's description
+ function isOnlyOperationalNode(node) {
+ return node.hasOwnProperty('isConfigStm') ? node.isConfigStm !== false : true;
+ }
}
- NodeUtilsService.$inject=[];
+ NodeUtilsService.$inject = [];
return NodeUtilsService;
-});
\ No newline at end of file
+});
function NodeWrapperService(constants, RequestBuilderService, RestrictionsService, TypeWrapperService,
ListFilteringService, EventDispatcherService, FilterNodeWrapperService){
- var comparePropToElemByName = function comparePropToElemByName(propName, elemName) {
- // AUGMENT FIX
- // return propName === elemName; //TODO also check by namespace - redundancy?
- return (propName.indexOf(':') > -1 ? propName.split(':')[1] : propName) === elemName; //TODO also check by namespace - redundancy?
+ var service = {
+ case: caseYang,
+ config: config,
+ container: container,
+ checkKeyDuplicity: checkKeyDuplicity,
+ choice: choice,
+ input: input,
+ key: key,
+ leaf: leaf,
+ 'leaf-list': leafList,
+ length: length,
+ list: list,
+ _listElem: _listElem,
+ output: output,
+ pattern: pattern,
+ range: range,
+ rpc: rpc,
+ type: type,
+ wrap: wrap,
+ wrapAll: wrapAll,
+ __test: {
+ comparePropToElemByName: comparePropToElemByName,
+ equalArrays: equalArrays,
+ equalListElems: equalListElems,
+ parseRestrictText: parseRestrictText,
+ getTypes: getTypes,
+ checkListElemKeys: checkListElemKeys,
+ },
};
- var equalArrays = function (arrA, arrB) {
- var match = (arrA.length === arrB.length) && arrA.length > 0;
+ return service;
- if (match) {
- var i = 0;
- while (i < arrA.length && match) {
- var valMatch = arrA[i] === arrB[i];
- match = match && valMatch;
- i++;
+ /**
+ * Service for wrapping list element
+ * @param node
+ * @private
+ */
+ function _listElem(node) {
+ node.refKey = [];
+
+ node.listElemBuildRequest = function (builder, req) {
+ var added = false,
+ objToAdd = builder.createObj();
+
+ node.getChildren(null, null, constants.NODE_UI_DISPLAY).forEach(function (child) {
+ var childAdded = child.buildRequest(builder, objToAdd, node.module);
+ added = added || childAdded;
+ });
+
+ if (added) {
+ builder.insertObjToList(req, objToAdd);
}
- }
- return match;
- };
- var equalListElems = function (listElemA, listElemB, refKey) {
- var getKeyValue = function (data, label, module) {
- if (data && data.hasOwnProperty(label)) {
- return data[label];
- } else if (data && data.hasOwnProperty(module + ':' + label)) {
- return data[module + ':' + label];
- } else {
- return null;
- }
- },
- getKeyArrayValues = function (data, refKey) {
- return refKey.map(function (key) {
- return getKeyValue(data, key.label, key.module);
- }).filter(function (item) {
- return item !== null;
- });
- },
- keyValuesA = getKeyArrayValues(listElemA, refKey);
- var keyValuesB = getKeyArrayValues(listElemB, refKey);
+ return added;
+ };
- return equalArrays(keyValuesA, keyValuesB);
- };
+ node.fillListElement = function (name, data) {
+ var filled = false;
- var checkListElemKeys = function (listData, refKey) {
- var doubleKeyIndexes = [],
- checkedElems = [];
+ node.getChildren(null, null, constants.NODE_UI_DISPLAY).forEach(function (child) {
+ var childFilled = child.fill(name, data);
+ filled = filled || childFilled;
+ });
- listData.forEach(function (item, index) {
- var duplitactes = checkedElems.filter(function (checked) {
- var isDuplicate = equalListElems(item, checked.item, refKey);
- if (isDuplicate && doubleKeyIndexes.indexOf(checked.index) === -1) {
- doubleKeyIndexes.push(checked.index);
- }
- return isDuplicate;
+ return filled;
+ };
+
+ node.isFilled = function () {
+ return node.getChildren(null, null, constants.NODE_UI_DISPLAY).some(function (child) {
+ return child.isFilled();
});
+ };
- if (duplitactes.length) {
- //item is already in checkedElems so we don't need to push it again
- doubleKeyIndexes.push(index);
- } else {
- checkedElems.push({index: index, item: item});
- }
- });
+ node.clear = function () {
+ var nodesToClear = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
- return doubleKeyIndexes;
- };
+ if (nodesToClear.length) {
+ nodesToClear.forEach(function (child) {
+ child.clear();
+ });
+ }
+ };
- var parseRestrictText = function (text) {
- return text.split('|').map(function (elem) {
- var subElems = elem.split('..');
- return subElems.length === 1 ? RestrictionsService.getEqualsFnc(subElems[0]) :
- RestrictionsService.getMinMaxFnc(subElems[0], subElems[1]);
+ node.children.forEach(function (child) {
+ wrapAll(child);
});
- };
+ }
+
+ /**
+ * Service for wrapping list yang element
+ * @param node
+ */
+ function list(node) {
+ node.refKey = [];
+ node.doubleKeyIndexes = [];
+ node.actElemStructure = null;
+ node.actElemIndex = -1;
+ node.listData = [];
+ node.expanded = true;
+ node.filters = [];
+ node.filterNodes = [];
+ node.searchedPath = [];
+ node.referenceNode = null;
+ node.filteredListData = [];
+ node.currentFilter = 0;
+
+ node.toggleExpand = function () {
+ node.expanded = !node.expanded;
+ };
+ node.createStructure = function () {
+ if (node.actElemStructure === null) {
+ var copy = node.deepCopy(['augmentionGroups', 'augmentationId']);
+ _listElem(copy);
+ node.actElemStructure = copy;
+ node.actElemStructure.getActElemIndex = node.getActElemIndex;
+ }
+ };
- var getTypes = function (node) {
- var types = [];
+ node.getActElemIndex = function () {
+ return node.actElemIndex;
+ };
- var getTypesRecursive = function (node, types) {
- types.push(node);
+ node.addListElem = function () {
+ node.createStructure();
+ var newElemData = {};
+ node.listData.push(newElemData);
+ node.changeActElementData(node.listData.length - 1, true);
+ };
- node.getChildren('type').forEach(function (child) {
- getTypesRecursive(child, types);
- });
+ node.buildActElemData = function () {
+ var list = [],
+ result;
+ if (node.actElemStructure) {
+ node.actElemStructure.listElemBuildRequest(RequestBuilderService, list, node.module);
+ result = list[0] ? list[0] : {};
+ }
+ return result;
};
- node.getChildren('type').forEach(function (child) {
- //console.info('child', child);
- getTypesRecursive(child, types);
- });
+ node.changeActElementData = function (index, fromAdd) {
+ var storeData = node.buildActElemData();
+ node.expanded = true;
- return types;
- };
+ if (node.actElemIndex > -1) { // we are changing already existing data
+ if (node.filteredListData && node.filteredListData.length){
+ node.listData[node.listData.indexOf(node.filteredListData[node.actElemIndex])] = storeData;
+ node.filteredListData[node.actElemIndex] = storeData;
+ if (fromAdd){
+ ListFilteringService.clearFilterData(node, true, false);
+ }
+ } else {
+ node.listData[node.actElemIndex] = storeData;
+ }
+ }
+ node.actElemIndex = index;
- var wrapper = {
- wrap: function (node) {
- if (this.hasOwnProperty(node.type)) {
- this[node.type](node);
+ var actData = null;
+ if (!(node.filteredListData && node.filteredListData.length)){
+ actData = node.listData[node.actElemIndex];
+ } else {
+ actData = node.listData[node.listData.indexOf(node.filteredListData[node.actElemIndex])];
}
- },
- wrapAll: function (node) {
- var self = this;
- self.wrap(node);
- node.children.forEach(function (child) {
- self.wrapAll(child);
- });
- },
- checkKeyDuplicity: function (listData, refKey) {
- return checkListElemKeys(listData, refKey);
- },
- leaf: function (node) {
- node.value = '';
- node.valueIsValid = true;
- node.typeChild = node.getChildren('type')[0];
- node.buildRequest = function (builder, req, module) {
- var value = node.typeChild.getValue(),
- labelWithModule = (module !== node.module ? node.module + ':' : '') + node.label;
+ node.actElemStructure.clear();
+ for (var prop in actData) {
+ node.actElemStructure.fillListElement(prop, actData[prop]);
+ }
- if(node.isKey()) {
- EventDispatcherService.dispatch(constants.EV_FILL_PATH, node, value);
- }
+ EventDispatcherService.dispatch(constants.EV_LIST_CHANGED, node.actElemStructure);
+ };
- if (value) {
- builder.insertPropertyToObj(req, labelWithModule, value);
- return true;
- }
+ node.removeListElem = function (elemIndex, fromFilter) {
- return false;
- };
+ if (fromFilter){
+ elemIndex = node.listData.indexOf(node.filteredListData[elemIndex]);
+ }
- node.fill = function (name, data) {
- var match = '';
+ node.listData.splice(elemIndex, 1);
+ node.actElemIndex = node.listData.length - 1;
- match = comparePropToElemByName(name, node.label);
- if (match) {
- node.value = data.toString();
- if (node.typeChild) {
- node.typeChild.fill(node.value);
- }
- }
- return match;
- };
+ if (fromFilter){
+ ListFilteringService.clearFilterData(node, true, false);
+ }
- node.clear = function () {
- node.value = '';
+ if (node.actElemIndex === -1) {
+ node.actElemStructure = null;
+ } else {
+ var actData = node.listData[node.actElemIndex];
- if (node.typeChild) {
- node.typeChild.clear();
+ node.actElemStructure.clear();
+ for (var prop in actData) {
+ node.actElemStructure.fillListElement(prop, actData[prop]);
}
- };
+ }
- node.isFilled = function () {
- var filled = node.typeChild.getValue() ? true : false;
- return filled;
- };
+ EventDispatcherService.dispatch(constants.EV_LIST_CHANGED, node.actElemStructure);
+ };
- node.checkValueType = function () {
- node.valueIsValid = node.typeChild ? node.typeChild.check(node.value) : true;
- };
+ node.buildRequest = function (builder, req, module) {
+ var added = false;
+ // store entered data
+ var storeData = node.buildActElemData(),
+ labelWithModule = (module !== node.module ? node.module + ':' : '') + node.label;
- node.isKey = function() {
- return node.parent && node.parent.type === 'list' && node.parent.refKey && node.parent.refKey.indexOf(node) !== -1;
- };
- },
- type: function (node) {
- TypeWrapperService.wrapAll(node);
- },
- length: function (node) {
- node.restrictions = parseRestrictText(node.label);
- },
- range: function (node) {
- node.restrictions = parseRestrictText(node.label);
- },
- pattern: function (node) {
- node.restrictions = [RestrictionsService.getReqexpValidationFnc(node.label)];
- },
- // enum: function (node) {
- // },
- // bit: function (node) {
- // },
- // position: function (node) {
- // },
- container: function (node) {
- node.expanded = false;
-
- node.toggleExpand = function () {
- node.expanded = !node.expanded;
- };
+ if (node.actElemIndex > -1) {
+ if (node.filteredListData && node.filteredListData.length){
+ node.listData[node.listData.indexOf(node.filteredListData[node.actElemIndex])] = storeData;
+ node.filteredListData[node.actElemIndex] = storeData;
+ } else {
+ node.listData[node.actElemIndex] = storeData;
+ }
+ }
- node.buildRequest = function (builder, req, module) {
- var added = false,
- name = node.label,
- objToAdd = builder.createObj(),
- builderNodes = node.getChildren(null, null, constants.NODE_UI_DISPLAY),
- checkEmptyContainer = function(type, obj) { //TODO: absolete after when statement is implemented
- return !!(type === 'case' || !$.isEmptyObject(objToAdd));
- },
- checkPresence = function(containerNode) {
- return containerNode.children.some(function(ch) {
- return ch.type === 'presence';
- });
- },
- labelWithModule = (module !== node.module ? node.module + ':' : '') + node.label;
+ added = node.listData.filter(function (data) {
+ return $.isEmptyObject(data) === false;
+ }).length > 0;
- if (builderNodes.length) {
- builderNodes.forEach(function (child) {
- var childAdded = child.buildRequest(builder, objToAdd, node.module);
- added = added || childAdded;
- });
- } else {
- added = true;
+ var buildedDataCopy = node.listData.slice().map(function (item) {
+ var newItem = {};
+ for (var prop in item){
+ if (prop !== '$$hashKey'){
+ newItem[prop] = item[prop];
+ }
}
+ return newItem;
+ }).filter(function (item){
+ return Object.keys(item).length !== 0;
+ });
+ // check of listElems keyValues duplicity
+ if (node.filteredListData && node.filteredListData.length){
+ node.doubleKeyIndexes = checkKeyDuplicity(node.filteredListData, node.refKey);
+ } else {
+ node.doubleKeyIndexes = checkKeyDuplicity(node.listData, node.refKey);
+ }
+ if (added) {
+ builder.insertPropertyToObj(req, labelWithModule, buildedDataCopy);
+ }
- if (added && (checkEmptyContainer(node.parent ? node.parent.type : 'blanktype', objToAdd) || checkPresence(node))) {
- builder.insertPropertyToObj(req, labelWithModule, objToAdd);
- }
-
- return added;
- };
+ return added;
+ };
- node.fill = function (name, data) {
- var match = comparePropToElemByName(name, node.label),
- nodesToFill = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
+ node.fill = function (name, array) { // data is array
- if (match && nodesToFill.length) {
- nodesToFill.forEach(function (child) {
- for (var prop in data) {
- child.fill(prop, data[prop]);
- }
- });
+ var match = comparePropToElemByName(name, node.label);
- node.expanded = match;
+ if (match && array.length) {
+ node.createStructure();
+ node.listData = array.slice();
+ node.actElemIndex = node.listData.length - 1;
+ for (var prop in node.listData[node.actElemIndex]) {
+ node.actElemStructure.fillListElement(prop, node.listData[node.actElemIndex][prop]);
}
+ }
- return match;
- };
+ return (match && array.length > 0);
+ };
- node.clear = function () {
- var nodesToClear = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
- node.nodeType = constants.NODE_UI_DISPLAY;
+ node.clear = function () {
+ while (node.listData.length > 0) {
+ node.listData.pop();
+ }
+ while (node.filteredListData.length > 0) {
+ node.filteredListData.pop();
+ }
- if (nodesToClear.length) {
- nodesToClear.forEach(function (child) {
- child.clear();
- });
- }
- };
+ node.actElemIndex = -1;
+ node.actElemStructure = null;
+ node.nodeType = constants.NODE_UI_DISPLAY;
+ };
- node.isFilled = function () {
- return node.getChildren(null, null, constants.NODE_UI_DISPLAY).some(function (child) {
- return child.isFilled();
- });
- };
- },
- rpc: function (node) {
- node.expanded = true;
- node.buildRequest = function (builder, req, module) {
- var added = false,
- name = node.label,
- objToAdd = builder.createObj(),
- builderNodes = node.getChildren(null, null, constants.NODE_UI_DISPLAY),
- labelWithModule = (module !== node.module ? node.module + ':' : '') + node.label;
-
- if (builderNodes.length) {
- builderNodes.forEach(function (child) {
- var childAdded = child.buildRequest(builder, objToAdd, node.module);
- added = added || childAdded;
- });
- } else {
- added = true;
- objToAdd = constants.NULL_DATA;
- }
+ node.isFilled = function () {
+ return node.listData.length > 0;
+ };
- if (added) {
- builder.insertPropertyToObj(req, labelWithModule, objToAdd);
- }
+ node.createListName = function (index) {
+ var name = '',
+ val = '',
+ currentList = null;
- return added;
- };
+ if (node.filteredListData && node.filteredListData.length){
+ currentList = node.filteredListData;
+ } else {
+ currentList = node.listData;
+ }
- node.fill = function (name, data) {
- var filled = false,
- nodesToFill = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
+ if (index > -1) {
+ node.actElemStructure.refKey.forEach(function (key) {
+ if (index === node.getActElemIndex()) {
+ val = key.value !== '' ? key.label + ':' + key.value : '';
+ } else {
+ var prop = '';
+ if (!($.isEmptyObject(currentList[index]))) {
+ if (currentList[index][key.label]) {
+ prop = key.label;
+ } else if (currentList[index][key.module + ':' + key.label]) {
+ prop = key.module + ':' + key.label;
+ }
+ val = prop ? key.label + ':' + currentList[index][prop] : prop;
+ }
+ }
- nodesToFill.forEach(function (child) {
- var childFilled = child.fill(name, data);
- filled = filled || childFilled;
+ name = name ? (name + (val ? (' ' + val) : '')) : (name + (val ? (' <' + val) : ''));
});
+ }
- node.expanded = filled;
+ if (name) {
+ name = name + '>';
+ }
- return filled;
- };
+ return name;
+ };
- node.clear = function () {
- var nodesToClear = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
+ node.getNewFilterElement = function (){
+ return node.getChildrenForFilter().map(function (element){
+ FilterNodeWrapperService.init(element);
+ var copy = element.deepCopyForFilter();
+ wrapAll(copy);
+ FilterNodeWrapperService.wrapForFilter(copy);
+ return copy;
+ });
+ };
+ }
+
+ // TODO: add service's description
+ function config(node) {
+ node.parent.isConfigStm = (node.label === 'true');
+ }
+
+ // TODO: add service's description
+ function key(node) {
+ // do this only on list, not on listElem because deepCopy on list doesn't copy property keys to
+ // listElem => don't do this when button for add new list is clicked
+ if (node.parent.hasOwnProperty('refKey')) {
+ var keyLabels = node.label.split(' '),
+ keyNodes = node.parent.getChildren(null, null, constants.NODE_UI_DISPLAY).filter(function (child) {
+ return keyLabels.indexOf(child.label) > -1;
+ }),
+ getRefKeyArray = function (keys){
+ var refKeyArray = [];
+ keyLabels.forEach(function (keyLabel){
+ var nk = keys.filter(function (k){
+ return keyLabel === k.label;
+ });
- if (nodesToClear.length) {
- nodesToClear.forEach(function (child) {
- child.clear();
+ if ( nk.length ) {
+ refKeyArray.push(nk[0]);
+ }
});
- }
- };
+ return refKeyArray;
+ };
- node.isFilled = function () {
- return node.getChildren(null, null, constants.NODE_UI_DISPLAY).some(function (child) {
- return child.isFilled();
- });
+ node.parent.refKey = getRefKeyArray(keyNodes);
+ }
+ }
+
+ /**
+ * Service for wrapping leaf list yang element
+ * @param node
+ */
+ function leafList(node) {
+ node.value = [];
+ node.expanded = true;
+
+ node.toggleExpand = function () {
+ node.expanded = !node.expanded;
+ };
+
+ node.addListElem = function () {
+ var newElement = {
+ value: '',
};
+ node.value.push(newElement);
+ };
- },
- input: function (node) {
- node.expanded = true;
+ node.removeListElem = function (elem) {
+ node.value.splice(node.value.indexOf(elem), 1);
+ };
- node.buildRequest = function (builder, req, module) {
- var added = false,
- name = node.label,
- objToAdd = builder.createObj(),
- builderNodes = node.getChildren(null, null, constants.NODE_UI_DISPLAY),
- labelWithModule = (module !== node.module ? node.module + ':' : '') + node.label;
+ node.buildRequest = function (builder, req, module) {
+ var valueArray = [],
+ labelWithModule = (module !== node.module ? node.module + ':' : '') + node.label;
- if (builderNodes.length) {
+ for (var i = 0; i < node.value.length; i++) {
+ valueArray.push(node.value[i].value);
+ }
- builderNodes.forEach(function (child) {
- var childAdded = child.buildRequest(builder, objToAdd, node.module);
- added = added || childAdded;
- });
- } else {
- added = true;
- }
+ if (valueArray.length > 0) {
+ builder.insertPropertyToObj(req, labelWithModule, valueArray);
+ return true;
+ }
- if (added) {
- builder.insertPropertyToObj(req, labelWithModule, objToAdd);
- }
+ return false;
- return added;
- };
+ };
- node.fill = function (name, data) {
- var match = comparePropToElemByName(name, node.label),
- nodesToFill = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
- if (match && nodesToFill.length) {
- nodesToFill.forEach(function (child) {
- for (var prop in data) {
- child.fill(prop, data[prop]);
- }
- });
- node.expanded = match;
+ node.fill = function (name, array) {
+ var match = comparePropToElemByName(name, node.label),
+ newLeafListItem;
+
+ if (match) {
+
+ for (var i = 0; i < array.length; i++) {
+ newLeafListItem = {
+ value: array[i],
+ };
+ node.value.push(newLeafListItem);
}
- return match;
- };
+ }
+ return match;
+ };
- node.clear = function () {
- var nodesToClear = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
+ node.clear = function () {
+ node.nodeType = constants.NODE_UI_DISPLAY;
+ node.value = [];
+ };
- if (nodesToClear.length) {
- nodesToClear.forEach(function (child) {
- child.clear();
- });
- }
- };
+ node.isFilled = function () {
+ return node.value.length > 0;
+ };
+ }
- node.isFilled = function () {
- return node.getChildren(null, null, constants.NODE_UI_DISPLAY).some(function (child) {
- return child.isFilled();
- });
- };
+ /**
+ * Service for wrapping choice yang element
+ * @param node
+ */
+ function choice(node) {
+ node.choice = null;
+ node.expanded = true;
- },
- output: function (node) {
- node.expanded = true;
+ node.buildRequest = function (builder, req, module) {
+ var added = false;
- node.buildRequest = function (builder, req) {
- // var added = false,
- // name = node.label,
- // objToAdd = builder.createObj(),
- // builderNodes = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
-
- // if (builderNodes.length) {
- // builderNodes.forEach(function (child) {
- // var childAdded = child.buildRequest(builder, objToAdd);
- // added = added || childAdded;
- // });
- // } else {
- // added = true;
- // }
-
- // if (added) {
- // builder.insertPropertyToObj(req, name, objToAdd);
- // }
-
- // return added;
- };
+ if (node.choice) {
+ added = node.choice.buildRequest(builder, req, module);
+ }
- node.fill = function (name, data) {
- var match = comparePropToElemByName(name, node.label),
- nodesToFill = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
+ return added;
+ };
- if (match && nodesToFill.length) {
- nodesToFill.forEach(function (child) {
- for (var prop in data) {
- child.fill(prop, data[prop]);
- }
- });
- node.expanded = match;
- }
+ node.fill = function (name, data) {
+ var filled = false,
+ nodesToFill = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
- return match;
- };
+ nodesToFill.forEach(function (child) {
+ var childFilled = child.fill(name, data);
- node.clear = function () {
- var nodesToClear = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
+ if (childFilled) {
+ node.choice = child;
+ }
- if (nodesToClear.length) {
- nodesToClear.forEach(function (child) {
- child.clear();
- });
+ filled = filled || childFilled;
+ if (filled) {
+ return false;
}
- };
+ });
- node.isFilled = function () {
- return node.getChildren(null, null, constants.NODE_UI_DISPLAY).some(function (child) {
- return child.isFilled();
- });
- };
+ return filled;
+ };
- },
- case: function (node) {
+ node.clear = function () {
+ node.nodeType = constants.NODE_UI_DISPLAY;
- node.buildRequest = function (builder, req, module) {
- var added = false;
+ if (node.choice) {
+ node.choice.clear();
+ node.choice = null;
+ }
+ };
- node.getChildren(null, null, constants.NODE_UI_DISPLAY).forEach(function (child) {
- var childAdded = child.buildRequest(builder, req, module);
- added = added || childAdded;
- });
+ node.isFilled = function () {
+ return node.choice !== null;
+ };
+ }
- return added;
- };
+ /**
+ * Service for wrapping case yang element
+ * @param node
+ */
+ function caseYang(node) {
- node.fill = function (name, data) {
- var filled = false,
- nodesToFill = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
+ node.buildRequest = function (builder, req, module) {
+ var added = false;
- nodesToFill.forEach(function (child) {
- var childFilled = child.fill(name, data);
- filled = filled || childFilled;
- });
+ node.getChildren(null, null, constants.NODE_UI_DISPLAY).forEach(function (child) {
+ var childAdded = child.buildRequest(builder, req, module);
+ added = added || childAdded;
+ });
- return filled;
- };
+ return added;
+ };
- node.clear = function () {
- var nodesToClear = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
+ node.fill = function (name, data) {
+ var filled = false,
+ nodesToFill = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
- nodesToClear.forEach(function (child) {
- child.clear();
- });
- };
+ nodesToFill.forEach(function (child) {
+ var childFilled = child.fill(name, data);
+ filled = filled || childFilled;
+ });
- node.isFilled = function () {
- return node.getChildren(null, null, constants.NODE_UI_DISPLAY).some(function (child) {
- return child.isFilled();
- });
- };
- },
- choice: function (node) {
- node.choice = null;
- node.expanded = true;
+ return filled;
+ };
- node.buildRequest = function (builder, req, module) {
- var added = false;
+ node.clear = function () {
+ var nodesToClear = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
- if (node.choice) {
- added = node.choice.buildRequest(builder, req, module);
- }
+ nodesToClear.forEach(function (child) {
+ child.clear();
+ });
+ };
- return added;
- };
+ node.isFilled = function () {
+ return node.getChildren(null, null, constants.NODE_UI_DISPLAY).some(function (child) {
+ return child.isFilled();
+ });
+ };
+ }
- node.fill = function (name, data) {
- var filled = false,
- nodesToFill = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
+ /**
+ * Service for wrapping output yang element
+ * @param node
+ */
+ function output(node) {
+ node.expanded = true;
- nodesToFill.forEach(function (child) {
- var childFilled = child.fill(name, data);
+ node.buildRequest = function (builder, req) {
- if (childFilled) {
- node.choice = child;
- }
+ };
- filled = filled || childFilled;
- if (filled) {
- return false;
+ node.fill = function (name, data) {
+ var match = comparePropToElemByName(name, node.label),
+ nodesToFill = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
+
+ if (match && nodesToFill.length) {
+ nodesToFill.forEach(function (child) {
+ for (var prop in data) {
+ child.fill(prop, data[prop]);
}
});
+ node.expanded = match;
+ }
- return filled;
- };
-
- node.clear = function () {
- node.nodeType = constants.NODE_UI_DISPLAY;
-
- if (node.choice) {
- node.choice.clear();
- node.choice = null;
- }
- };
-
- node.isFilled = function () {
- return node.choice !== null;
- };
- },
- 'leaf-list': function (node) {
- node.value = [];
- node.expanded = true;
+ return match;
+ };
- node.toggleExpand = function () {
- node.expanded = !node.expanded;
- };
+ node.clear = function () {
+ var nodesToClear = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
- node.addListElem = function () {
- var newElement = {
- value: ''
- };
- node.value.push(newElement);
- };
+ if (nodesToClear.length) {
+ nodesToClear.forEach(function (child) {
+ child.clear();
+ });
+ }
+ };
- node.removeListElem = function (elem) {
- node.value.splice(node.value.indexOf(elem), 1);
- };
+ node.isFilled = function () {
+ return node.getChildren(null, null, constants.NODE_UI_DISPLAY).some(function (child) {
+ return child.isFilled();
+ });
+ };
- node.buildRequest = function (builder, req, module) {
- var valueArray = [],
- labelWithModule = (module !== node.module ? node.module + ':' : '') + node.label;
+ }
- for (var i = 0; i < node.value.length; i++) {
- valueArray.push(node.value[i].value);
- }
+ // TODO: add service's description
+ function input(node) {
+ node.expanded = true;
- if (valueArray.length > 0) {
- builder.insertPropertyToObj(req, labelWithModule, valueArray);
- return true;
- }
+ node.buildRequest = function (builder, req, module) {
+ var added = false,
+ objToAdd = builder.createObj(),
+ builderNodes = node.getChildren(null, null, constants.NODE_UI_DISPLAY),
+ labelWithModule = (module !== node.module ? node.module + ':' : '') + node.label;
- return false;
+ if (builderNodes.length) {
- };
+ builderNodes.forEach(function (child) {
+ var childAdded = child.buildRequest(builder, objToAdd, node.module);
+ added = added || childAdded;
+ });
+ } else {
+ added = true;
+ }
+ if (added) {
+ builder.insertPropertyToObj(req, labelWithModule, objToAdd);
+ }
- node.fill = function (name, array) {
- var match = comparePropToElemByName(name, node.label),
- newLeafListItem;
+ return added;
+ };
- if (match) {
+ node.fill = function (name, data) {
+ var match = comparePropToElemByName(name, node.label),
+ nodesToFill = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
- for (var i = 0; i < array.length; i++) {
- newLeafListItem = {
- value: array[i]
- };
- node.value.push(newLeafListItem);
+ if (match && nodesToFill.length) {
+ nodesToFill.forEach(function (child) {
+ for (var prop in data) {
+ child.fill(prop, data[prop]);
}
+ });
+ node.expanded = match;
+ }
- }
- return match;
- };
+ return match;
+ };
- node.clear = function () {
- node.nodeType = constants.NODE_UI_DISPLAY;
- node.value = [];
- };
+ node.clear = function () {
+ var nodesToClear = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
- node.isFilled = function () {
- return node.value.length > 0;
- };
+ if (nodesToClear.length) {
+ nodesToClear.forEach(function (child) {
+ child.clear();
+ });
+ }
+ };
- },
- key: function (node) {
- // do this only on list, not on listElem because deepCopy on list doesn't copy property keys to listElem => don't do this when button for add new list is clicked
- if (node.parent.hasOwnProperty('refKey')) {
- var keyLabels = node.label.split(' '),
- keyNodes = node.parent.getChildren(null, null, constants.NODE_UI_DISPLAY).filter(function (child) {
- return keyLabels.indexOf(child.label) > -1;
- }),
- getRefKeyArray = function(keys){
- var refKeyArray = [];
- keyLabels.forEach(function(keyLabel){
- var nk = keys.filter(function(k){
- return keyLabel === k.label;
- });
-
- if ( nk.length ) {
- refKeyArray.push(nk[0]);
- }
- });
- return refKeyArray;
- };
+ node.isFilled = function () {
+ return node.getChildren(null, null, constants.NODE_UI_DISPLAY).some(function (child) {
+ return child.isFilled();
+ });
+ };
- node.parent.refKey = getRefKeyArray(keyNodes);
+ }
+
+ /**
+ * Service for wrapping rpc yang element
+ * @param node
+ */
+ function rpc(node) {
+ node.expanded = true;
+ node.buildRequest = function (builder, req, module) {
+ var added = false,
+ objToAdd = builder.createObj(),
+ builderNodes = node.getChildren(null, null, constants.NODE_UI_DISPLAY),
+ labelWithModule = (module !== node.module ? node.module + ':' : '') + node.label;
+
+ if (builderNodes.length) {
+ builderNodes.forEach(function (child) {
+ var childAdded = child.buildRequest(builder, objToAdd, node.module);
+ added = added || childAdded;
+ });
+ } else {
+ added = true;
+ objToAdd = constants.NULL_DATA;
}
- },
- config: function (node) {
- node.parent.isConfigStm = (node.label === 'true');
- },
- list: function (node) {
- node.refKey = [];
- node.doubleKeyIndexes = [];
- node.actElemStructure = null;
- node.actElemIndex = -1;
- node.listData = [];
- node.expanded = true;
- node.filters = [];
- node.filterNodes = [];
- node.searchedPath = [];
- node.referenceNode = null;
- node.filteredListData = [];
- node.currentFilter = 0;
-
- node.toggleExpand = function () {
- node.expanded = !node.expanded;
- };
- node.createStructure = function () {
- if (node.actElemStructure === null) {
- var copy = node.deepCopy(['augmentionGroups', 'augmentationId']);
- wrapper._listElem(copy);
- node.actElemStructure = copy;
- node.actElemStructure.getActElemIndex = node.getActElemIndex;
- }
- };
+ if (added) {
+ builder.insertPropertyToObj(req, labelWithModule, objToAdd);
+ }
- node.getActElemIndex = function() {
- return node.actElemIndex;
- };
+ return added;
+ };
- node.addListElem = function () {
- node.createStructure();
- var newElemData = {};
- node.listData.push(newElemData);
- node.changeActElementData(node.listData.length - 1,true);
- };
+ node.fill = function (name, data) {
+ var filled = false,
+ nodesToFill = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
- node.buildActElemData = function () {
- var list = [],
- result;
- if (node.actElemStructure) {
- node.actElemStructure.listElemBuildRequest(RequestBuilderService, list, node.module);
- result = list[0] ? list[0] : {};
- }
- return result;
- };
+ nodesToFill.forEach(function (child) {
+ var childFilled = child.fill(name, data);
+ filled = filled || childFilled;
+ });
- node.changeActElementData = function (index,fromAdd) {
- var storeData = node.buildActElemData();
- node.expanded = true;
+ node.expanded = filled;
- if (node.actElemIndex > -1) { //we are changing already existing data
- if(node.filteredListData && node.filteredListData.length){
- node.listData[node.listData.indexOf(node.filteredListData[node.actElemIndex])] = storeData;
- node.filteredListData[node.actElemIndex] = storeData;
- if(fromAdd){
- ListFilteringService.clearFilterData(node, true, false);
- }
- }else{
- node.listData[node.actElemIndex] = storeData;
- }
- }
- node.actElemIndex = index;
+ return filled;
+ };
- var actData = null;
- if(!(node.filteredListData && node.filteredListData.length)){
- actData = node.listData[node.actElemIndex];
- }else{
- actData = node.listData[node.listData.indexOf(node.filteredListData[node.actElemIndex])];
- }
+ node.clear = function () {
+ var nodesToClear = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
- node.actElemStructure.clear();
- for (var prop in actData) {
- node.actElemStructure.fillListElement(prop, actData[prop]);
- }
+ if (nodesToClear.length) {
+ nodesToClear.forEach(function (child) {
+ child.clear();
+ });
+ }
+ };
- EventDispatcherService.dispatch(constants.EV_LIST_CHANGED, node.actElemStructure);
- };
+ node.isFilled = function () {
+ return node.getChildren(null, null, constants.NODE_UI_DISPLAY).some(function (child) {
+ return child.isFilled();
+ });
+ };
- node.removeListElem = function (elemIndex,fromFilter) {
+ }
- if(fromFilter){
- elemIndex = node.listData.indexOf(node.filteredListData[elemIndex]);
- }
+ /**
+ * Service for wrapping container yang element
+ * @param node
+ */
+ function container(node) {
+ node.expanded = false;
- node.listData.splice(elemIndex, 1);
- node.actElemIndex = node.listData.length - 1;
+ node.toggleExpand = function () {
+ node.expanded = !node.expanded;
+ };
- if(fromFilter){
- ListFilteringService.clearFilterData(node,true,false);
- }
+ node.buildRequest = function (builder, req, module) {
+ var added = false,
+ objToAdd = builder.createObj(),
+ builderNodes = node.getChildren(null, null, constants.NODE_UI_DISPLAY),
+ labelWithModule = (module !== node.module ? node.module + ':' : '') + node.label;
- if (node.actElemIndex === -1) {
- node.actElemStructure = null;
- } else {
- var actData = node.listData[node.actElemIndex];
+ if (builderNodes.length) {
+ builderNodes.forEach(function (child) {
+ var childAdded = child.buildRequest(builder, objToAdd, node.module);
+ added = added || childAdded;
+ });
+ } else {
+ added = true;
+ }
- node.actElemStructure.clear();
- for (var prop in actData) {
- node.actElemStructure.fillListElement(prop, actData[prop]);
- }
- }
+ if (added && (checkEmptyContainer(node.parent ? node.parent.type : 'blanktype', objToAdd) ||
+ checkPresence(node))) {
+ builder.insertPropertyToObj(req, labelWithModule, objToAdd);
+ }
- EventDispatcherService.dispatch(constants.EV_LIST_CHANGED, node.actElemStructure);
- };
+ return added;
- node.buildRequest = function (builder, req, module) {
- var added = false;
- //store entered data
- var storeData = node.buildActElemData(),
- labelWithModule = (module !== node.module ? node.module + ':' : '') + node.label;
-
- if (node.actElemIndex > -1) {
- if(node.filteredListData && node.filteredListData.length){
- node.listData[node.listData.indexOf(node.filteredListData[node.actElemIndex])] = storeData;
- node.filteredListData[node.actElemIndex] = storeData;
- }else{
- node.listData[node.actElemIndex] = storeData;
- }
- }
+ // TODO: add function's description
+ function checkPresence(containerNode) {
+ return containerNode.children.some(function (ch) {
+ return ch.type === 'presence';
+ });
+ }
+
+ // TODO: add function's description
+ function checkEmptyContainer(type, obj) { // TODO: absolete after when statement is implemented
+ return !!(type === 'case' || !$.isEmptyObject(objToAdd));
+ }
+ };
- added = node.listData.filter(function (data) {
- return $.isEmptyObject(data) === false;
- }).length > 0;
+ node.fill = function (name, data) {
+ var match = comparePropToElemByName(name, node.label),
+ nodesToFill = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
- var buildedDataCopy = node.listData.slice().map(function (item) {
- var newItem = {};
- for(var prop in item){
- if(prop != '$$hashKey'){
- newItem[prop] = item[prop];
- }
+ if (match && nodesToFill.length) {
+ nodesToFill.forEach(function (child) {
+ for (var prop in data) {
+ child.fill(prop, data[prop]);
}
- return newItem;
- }).filter(function(item){
- return Object.keys(item).length !== 0;
});
- // check of listElems keyValues duplicity
- if(node.filteredListData && node.filteredListData.length){
- node.doubleKeyIndexes = wrapper.checkKeyDuplicity(node.filteredListData, node.refKey);
- }else{
- node.doubleKeyIndexes = wrapper.checkKeyDuplicity(node.listData, node.refKey);
- }
+ node.expanded = match;
+ }
- if (added) {
- builder.insertPropertyToObj(req, labelWithModule, buildedDataCopy);
- }
+ return match;
+ };
- return added;
- };
+ node.clear = function () {
+ var nodesToClear = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
+ node.nodeType = constants.NODE_UI_DISPLAY;
- node.fill = function (name, array) { //data is array
+ if (nodesToClear.length) {
+ nodesToClear.forEach(function (child) {
+ child.clear();
+ });
+ }
+ };
- var match = comparePropToElemByName(name, node.label);
+ node.isFilled = function () {
+ return node.getChildren(null, null, constants.NODE_UI_DISPLAY).some(function (child) {
+ return child.isFilled();
+ });
+ };
+ }
+
+ /**
+ * Service for set patern restriction from yang element
+ * @param node
+ */
+ function pattern(node) {
+ node.restrictions = [RestrictionsService.getReqexpValidationFnc(node.label)];
+ }
+
+ /**
+ * Service for set range restriction from yang element
+ * @param node
+ */
+ function range(node) {
+ node.restrictions = parseRestrictText(node.label);
+ }
+
+ /**
+ * Service for set length restriction from yang element
+ * @param node
+ */
+ function length(node) {
+ node.restrictions = parseRestrictText(node.label);
+ }
+
+ /**
+ * Service for wrapping type yang element
+ * @param node
+ */
+ function type(node) {
+ TypeWrapperService.wrapAll(node);
+ }
+
+ /**
+ * Service for wrapping leaf yang element
+ * @param node
+ */
+ function leaf(node) {
+ node.value = '';
+ node.valueIsValid = true;
+ node.typeChild = node.getChildren('type')[0];
+
+ node.buildRequest = function (builder, req, module) {
+ var value = node.typeChild.getValue(),
+ labelWithModule = (module !== node.module ? node.module + ':' : '') + node.label;
+
+ if (node.isKey()) {
+ EventDispatcherService.dispatch(constants.EV_FILL_PATH, node, value);
+ }
- if (match && array.length) {
- node.createStructure();
- node.listData = array.slice();
- node.actElemIndex = node.listData.length - 1;
- for (var prop in node.listData[node.actElemIndex]) {
- node.actElemStructure.fillListElement(prop, node.listData[node.actElemIndex][prop]);
- }
- }
+ if (value) {
+ builder.insertPropertyToObj(req, labelWithModule, value);
+ return true;
+ }
- return (match && array.length > 0);
- };
+ return false;
+ };
- node.clear = function () {
- while (node.listData.length > 0) {
- node.listData.pop();
- }
- while (node.filteredListData.length > 0) {
- node.filteredListData.pop();
+ node.fill = function (name, data) {
+ var match = '';
+
+ match = comparePropToElemByName(name, node.label);
+ if (match) {
+ node.value = data.toString();
+ if (node.typeChild) {
+ node.typeChild.fill(node.value);
}
+ }
+ return match;
+ };
- node.actElemIndex = -1;
- node.actElemStructure = null;
- node.nodeType = constants.NODE_UI_DISPLAY;
- };
+ node.clear = function () {
+ node.value = '';
- node.isFilled = function () {
- return node.listData.length > 0;
- };
+ if (node.typeChild) {
+ node.typeChild.clear();
+ }
+ };
- node.createListName = function (index) {
- var name = '',
- val = '',
- currentList = null;
+ node.isFilled = function () {
+ var filled = node.typeChild.getValue() ? true : false;
+ return filled;
+ };
- if(node.filteredListData && node.filteredListData.length){
- currentList = node.filteredListData;
- }else{
- currentList = node.listData;
- }
+ node.checkValueType = function () {
+ node.valueIsValid = node.typeChild ? node.typeChild.check(node.value) : true;
+ };
- if (index > -1) {
- node.actElemStructure.refKey.forEach(function (key) {
- var keyLabel = '';
- if(index === node.getActElemIndex()) {
- val = key.value !== '' ? key.label + ':' + key.value : '';
- } else {
- var prop = '';
- if (!($.isEmptyObject(currentList[index]))) {
- if(currentList[index][key.label]) {
- prop = key.label;
- } else if(currentList[index][key.module + ':' + key.label]) {
- prop = key.module + ':' + key.label;
- }
- val = prop ? key.label + ':' + currentList[index][prop] : prop;
- }
- }
+ node.isKey = function () {
+ return node.parent &&
+ node.parent.type === 'list' &&
+ node.parent.refKey && node.parent.refKey.indexOf(node) !== -1;
+ };
+ }
+
+ /**
+ * Service for wrapping single node
+ * @param node
+ */
+ function wrap(node) {
+ if (service.hasOwnProperty(node.type)) {
+ service[node.type](node);
+ }
+ }
+
+ /**
+ * Main service for wrapping nodes
+ * @param node
+ */
+ function wrapAll(node) {
+ service.wrap(node);
+ node.children.forEach(function (child) {
+ service.wrapAll(child);
+ });
+ }
- name = name ? (name + (val ? (' ' + val) : '')) : (name + (val ? (' <' + val) : ''));
- });
- }
+ // TODO: add service's description
+ function checkKeyDuplicity(listData, refKey) {
+ return checkListElemKeys(listData, refKey);
+ }
- if (name) {
- name = name + '>';
- }
+ // TODO: add function's description
+ function comparePropToElemByName(propName, elemName) {
+ // AUGMENT FIX
+ // return propName === elemName; // TODO also check by namespace - redundancy?
- return name;
- };
+ // TODO also check by namespace - redundancy?
+ return (propName.indexOf(':') > -1 ? propName.split(':')[1] : propName) === elemName;
+ }
- node.getNewFilterElement = function (){
- return node.getChildrenForFilter().map(function(element){
- FilterNodeWrapperService.init(element);
- var copy = element.deepCopyForFilter();
- wrapper.wrapAll(copy);
- FilterNodeWrapperService.wrapForFilter(copy);
- return copy;
- });
- };
- },
- _listElem: function (node) {
- node.refKey = [];
+ // TODO: add function's description
+ function equalArrays(arrA, arrB) {
+ var match = (arrA.length === arrB.length) && arrA.length > 0;
+
+ if (match) {
+ var i = 0;
+ while (i < arrA.length && match) {
+ var valMatch = arrA[i] === arrB[i];
+ match = match && valMatch;
+ i++;
+ }
+ }
+ return match;
+ }
- node.listElemBuildRequest = function (builder, req, module) {
- var added = false,
- objToAdd = builder.createObj();
+ // TODO: add function's description
+ function equalListElems(listElemA, listElemB, refKey) {
+ var keyValuesA = getKeyArrayValues(listElemA, refKey),
+ keyValuesB = getKeyArrayValues(listElemB, refKey);
- node.getChildren(null, null, constants.NODE_UI_DISPLAY).forEach(function (child) {
- var childAdded = child.buildRequest(builder, objToAdd, node.module);
- added = added || childAdded;
- });
+ return equalArrays(keyValuesA, keyValuesB);
- if (added) {
- builder.insertObjToList(req, objToAdd);
- }
+ // TODO: add function's description
+ function getKeyValue(data, label, module) {
+ if (data && data.hasOwnProperty(label)) {
+ return data[label];
+ } else if (data && data.hasOwnProperty(module + ':' + label)) {
+ return data[module + ':' + label];
+ } else {
+ return null;
+ }
+ }
- return added;
- };
+ // TODO: add function's description
+ function getKeyArrayValues(data, refKey) {
+ return refKey.map(function (key) {
+ return getKeyValue(data, key.label, key.module);
+ }).filter(function (item) {
+ return item !== null;
+ });
+ }
+ }
- node.fillListElement = function (name, data) {
- var filled = false;
+ // TODO: add function's description
+ function checkListElemKeys(listData, refKey) {
+ var doubleKeyIndexes = [],
+ checkedElems = [];
- node.getChildren(null, null, constants.NODE_UI_DISPLAY).forEach(function (child) {
- var childFilled = child.fill(name, data);
- filled = filled || childFilled;
- });
+ listData.forEach(function (item, index) {
+ var duplitactes = checkedElems.filter(function (checked) {
+ var isDuplicate = equalListElems(item, checked.item, refKey);
+ if (isDuplicate && doubleKeyIndexes.indexOf(checked.index) === -1) {
+ doubleKeyIndexes.push(checked.index);
+ }
+ return isDuplicate;
+ });
- return filled;
- };
+ if (duplitactes.length) {
+ // item is already in checkedElems so we don't need to push it again
+ doubleKeyIndexes.push(index);
+ } else {
+ checkedElems.push({ index: index, item: item });
+ }
+ });
- node.isFilled = function () {
- return node.getChildren(null, null, constants.NODE_UI_DISPLAY).some(function (child) {
- return child.isFilled();
- });
- };
+ return doubleKeyIndexes;
+ }
- node.clear = function () {
- var nodesToClear = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
+ // TODO: add function's description
+ function parseRestrictText(text) {
+ return text.split('|').map(function (elem) {
+ var subElems = elem.split('..');
+ return subElems.length === 1 ? RestrictionsService.getEqualsFnc(subElems[0]) :
+ RestrictionsService.getMinMaxFnc(subElems[0], subElems[1]);
+ });
+ }
- if (nodesToClear.length) {
- nodesToClear.forEach(function (child) {
- child.clear();
- });
- }
- };
+ // TODO: add function's description
+ function getTypes(node) {
+ var types = [];
+
+ var getTypesRecursive = function (node, types) {
+ types.push(node);
- node.children.forEach(function (child) {
- wrapper.wrapAll(child);
+ node.getChildren('type').forEach(function (child) {
+ getTypesRecursive(child, types);
});
- }
- };
+ };
- wrapper.__test = {
- comparePropToElemByName: comparePropToElemByName,
- equalArrays: equalArrays,
- equalListElems: equalListElems,
- parseRestrictText: parseRestrictText,
- getTypes: getTypes,
- checkListElemKeys: checkListElemKeys
- };
+ node.getChildren('type').forEach(function (child) {
+ // console.info('child', child);
+ getTypesRecursive(child, types);
+ });
- return wrapper;
+ return types;
+ }
}
- NodeWrapperService.$inject=['constants', 'RequestBuilderService', 'RestrictionsService', 'TypeWrapperService',
- 'ListFilteringService', 'EventDispatcherService', 'FilterNodeWrapperService'];
+ NodeWrapperService.$inject = ['constants', 'RequestBuilderService', 'RestrictionsService', 'TypeWrapperService',
+ 'ListFilteringService', 'EventDispatcherService', 'FilterNodeWrapperService'];
return NodeWrapperService;
-});
\ No newline at end of file
+});
-define([], function () {
+define(['angular'], function (angular) {
'use strict';
function ParsingJsonService(){
- var pj = {};
+ var service = {
+ parseJson: parseJson,
+ };
- pj.parseJson = function(data, parsingErrorClbk){
+ return service;
+ /**
+ * Util for parsing json with error checking
+ * @param data
+ * @param parsingErrorClbk
+ * @returns {*}
+ */
+ function parseJson(data, parsingErrorClbk){
var result = null;
- try{
+ try {
result = JSON.parse(data);
- }catch(e){
- if(angular.isFunction(parsingErrorClbk)){
- parsingErrorClbk(e);
- }
+ } catch (e){
+ (parsingErrorClbk || angular.noop)(e);
}
finally {
return result;
}
- };
-
- return pj;
+ }
}
- ParsingJsonService.$inject=[];
+ ParsingJsonService.$inject = [];
return ParsingJsonService;
-});
\ No newline at end of file
+});
'use strict';
function PathUtilsService(ArrayUtilsService){
- var pathUtils = {},
- parentPath = '..';
-
- var Idenfitier = function(label, value) {
- this.label = label;
- this.value = value || '';
- };
-
- var PathElem = function (name, module, identifierNames, moduleChanged, revision) {
- this.name = name;
- this.module = module;
- this.identifiers = identifierNames ? identifierNames.map(function(name) {
- return new Idenfitier(name);
- }) : [];
- this.moduleChanged = moduleChanged || false;
- this.revision = revision;
-
- this.equals = function(comparedElem, compareIdentifierValues) {
- var result = this.name === comparedElem.name && this.module === comparedElem.module && this.identifiers.length === comparedElem.identifiers.length;
-
- if(result) {
- var identifiersCnt = this.identifiers.length,
- i;
-
- for(i = 0; i < identifiersCnt && result; i++) {
- result = this.identifiers[i].label === comparedElem.identifiers[i].label;
- if(compareIdentifierValues) {
- result = this.identifiers[i].value === comparedElem.identifiers[i].value;
- }
- }
- }
- return result;
- };
-
- this.hasIdentifier = function () {
- return this.identifiers.length > 0;
- };
-
- this.addIdentifier = function(name) {
- this.identifiers.push(new Idenfitier(name));
- };
-
- this.getIdentifierValues = function() {
- return this.identifiers.map(function(i) {
- return i.value;
- });
- };
-
- this.toString = function () {
- return (this.module ? this.module + ':' : '') + this.name + '/' + (this.hasIdentifier() ? this.getIdentifierValues().join('/') + '/' : '');
- };
-
- this.checkNode = function (node) {
- return (this.module ? this.module === node.module : true) && (this.name ? this.name === node.label : true) && (this.revision ? this.revision === node.moduleRevision : true);
- };
-
- this.clone = function() {
- var copy = new PathElem(this.name, this.module, null, this.moduleChanged, this.revision);
-
- copy.identifiers = this.identifiers.map(function(i) {
- return new Idenfitier(i.label, i.value);
- });
-
- return copy;
- };
- };
-
- var getModuleNodePair = function (pathString, defaultModule) {
- return pathString.indexOf(':') > -1 ? pathString.split(':') : [defaultModule, pathString];
- };
-
- var isIdentifier = function (item) {
- return (item.indexOf('{') === item.indexOf('}')) === false;
- };
-
- var searchForRevisionInImportNodes = function(module, importNodes) {
- var revision = null,
- node = importNodes.filter(function(i) {
- return i.label === module;
- })[0];
-
- if(node) {
- revision = node._revisionDate;
- }
+ var service = {
+ createPathElement: createPathElement,
+ getModuleNameFromPath: getModuleNameFromPath,
+ getStorageAndNormalizedPath: getStorageAndNormalizedPath,
+ fillIdentifiers: fillIdentifiers,
+ findIndexOfStrInPathStr: findIndexOfStrInPathStr,
+ fillListNode: fillListNode,
+ fillListRequestData: fillListRequestData,
+ fillPath: fillPath,
+ search: search,
+ searchNodeByPath: searchNodeByPath,
+ translate: translate,
+ translatePathArray: translatePathArray,
+ __test: {
+ PathElem: PathElem,
+ getModuleNodePair: getModuleNodePair,
+ isIdentifier: isIdentifier,
+ },
+ },
+ parentPath = '..';
- return revision;
- };
+ return service;
- pathUtils.createPathElement = function (name, module, identifierStrings, moduleChanged, revision) {
+ // TODO: add service's description
+ function createPathElement(name, module, identifierStrings, moduleChanged, revision) {
return new PathElem(name, module, identifierStrings, moduleChanged, revision);
- };
+ }
- pathUtils.search = function (node, path) {
+ // TODO: add service's description
+ function search(node, path) {
var pathElem = path.shift(),
selNode = pathElem.name === parentPath ?
node.parent :
if (selNode !== null) {
if (path.length) {
- return pathUtils.search(selNode, path);
+ return search(selNode, path);
} else {
return selNode;
}
} else {
- console.warn('pathUtils.search: cannot find element ',pathElem.name);
+ console.warn('search: cannot find element ', pathElem.name);
return null;
}
- };
+ }
- pathUtils.translate = function(path, prefixConverter, importNodes, getDefaultModuleCallback) {
- var pathStrElements = path.split('/').filter(function(e) {
+ // TODO: add service's description
+ function translate(path, prefixConverter, importNodes, getDefaultModuleCallback) {
+ var pathStrElements = path.split('/').filter(function (e) {
return e !== '';
}),
pathArrayElements = [],
index,
maxIndex = pathStrElements.length,
- getLastElement = function(a) {
+ getLastElement = function (a) {
return pathArrayElements.length > 0 ? pathArrayElements[pathArrayElements.length - 1] : null;
},
- getElementModule = function(e) {
+ getElementModule = function (e) {
return e ? e.module : '';
},
- getModuleChange = function(actModule, lastElemModule) {
+ getModuleChange = function (actModule, lastElemModule) {
return (lastElemModule !== null) ? actModule !== lastElemModule : false;
};
- for(index = 0; index < maxIndex; index += 1) {
+ for (index = 0; index < maxIndex; index += 1) {
var actElem = pathStrElements[index],
lastElem = getLastElement(pathArrayElements);
- if(isIdentifier(actElem) && lastElem) {
+ if (isIdentifier(actElem) && lastElem) {
lastElem.addIdentifier(actElem.slice(1, -1));
} else {
var lastElemModule = getElementModule(lastElem),
defaultModule = getDefaultModuleCallback ? getDefaultModuleCallback() : lastElemModule,
pair = getModuleNodePair(actElem, defaultModule),
- processedModule = (prefixConverter && pair[0] !== lastElemModule) ? prefixConverter(pair[0]) : pair[0],
+ processedModule = (prefixConverter && pair[0] !== lastElemModule) ?
+ prefixConverter(pair[0]) : pair[0],
revision = importNodes ? searchForRevisionInImportNodes(processedModule, importNodes) : null,
- pathElem = pathUtils.createPathElement(pair[1], processedModule, null, getModuleChange(processedModule, lastElemModule), revision);
+ pathElem = createPathElement(pair[1], processedModule, null, getModuleChange(processedModule, lastElemModule), revision);
pathArrayElements.push(pathElem);
}
}
return pathArrayElements;
- };
+ }
- pathUtils.translatePathArray = function(pathArray) {
- var getIdentifiersValues = function(identifiers) {
- return identifiers.map(function(i) {
+ // TODO: add service's description
+ function translatePathArray(pathArray) {
+ var getIdentifiersValues = function (identifiers) {
+ return identifiers.map(function (i) {
return i.value.replace(/\//g, '%2F');
}).join('/');
},
- getLastElem = function(i) {
+ getLastElem = function (i) {
var result = null;
- if((i - 1) >= 0) {
+ if ((i - 1) >= 0) {
result = pathArray[i - 1];
}
return result;
},
- getModuleStr = function(actElem, lastElem) {
- return ((lastElem && actElem.module && lastElem.module !== actElem.module) ? (actElem.module + ':') : '');
+ getModuleStr = function (actElem, lastElem) {
+ return ((lastElem && actElem.module && lastElem.module !== actElem.module) ?
+ (actElem.module + ':') : '');
},
- getIdentifiersStr = function(actElem) {
+ getIdentifiersStr = function (actElem) {
return (actElem.hasIdentifier() ? '/' + getIdentifiersValues(actElem.identifiers) : '');
},
- getElemStr = function(actElem, lastElem) {
+ getElemStr = function (actElem, lastElem) {
return getModuleStr(actElem, lastElem) + actElem.name + getIdentifiersStr(actElem);
};
- return pathArray.map(function(pe, i) {
+ return pathArray.map(function (pe, i) {
return getElemStr(pe, getLastElem(i));
});
- };
+ }
- var trimPath = function(pathString) {
- var searchStr = 'restconf',
- output = pathString;
-
- if(pathString.indexOf(searchStr) > -1) {
- output = pathString.slice(pathString.indexOf(searchStr)+searchStr.length+1);
- }
-
- return output;
- };
-
- var changeTreeDataNode = function(treeApiNode, treeData, prop, val) {
- var sel = treeApiNode ? treeData.filter(function(d) {
- return d.branch.uid === treeApiNode.uid;
- }) : [];
-
- if(sel.length === 1) {
- sel[0].branch[prop] = val;
- }
- };
-
- var changeTreeDataByProp = function(treeData, props, vals) {
- treeData.forEach(function(d, index) {
- props.forEach(function(v, i){
- d.branch[v] = vals[i];
- });
- });
- };
-
- pathUtils.fillPath = function(pathArrayIn, pathString) {
+ // TODO: add service's description
+ function fillPath(pathArrayIn, pathString) {
var pathArray = trimPath(pathString).split('/'),
pathPosition = 0;
- pathArrayIn.forEach(function(pathItem, index){
+ pathArrayIn.forEach(function (pathItem){
if ( pathItem.hasIdentifier() ){
- pathItem.identifiers.forEach(function(identifier){
+ pathItem.identifiers.forEach(function (identifier){
pathPosition++;
identifier.value = pathArray[pathPosition];
});
pathPosition++;
});
- };
-
- var getActElementChild = function(actElem, childLabel) {
- var sel = actElem.children.filter(function(child) {
- return child.label === childLabel;
- }),
- ret = sel.length === 1 ? sel[0] : null;
-
- return ret;
- };
+ }
- pathUtils.getModuleNameFromPath = function(path){
- var pathArray = pathUtils.translate(trimPath(path));
+ // TODO: add service's description
+ function getModuleNameFromPath(path){
+ var pathArray = translate(trimPath(path));
return pathArray.length > 1 ? pathArray[1].module : null;
- };
+ }
- pathUtils.searchNodeByPath = function(pathString, treeApis, treeData, disabledExpand) {
- var pathArray = pathUtils.translate(trimPath(pathString)),
+ // TODO: add service's description
+ function searchNodeByPath(pathString, treeApis, treeData, disabledExpand) {
+ var pathArray = translate(trimPath(pathString)),
module = pathArray.length > 1 ? pathArray[1].module : null,
- selectedTreeApi = module ? treeApis.filter(function(treeApi) {
+ selectedTreeApi = module ? treeApis.filter(function (treeApi) {
return treeApi.module === module;
})[0] : null,
retObj = null;
- if(selectedTreeApi && pathArray.length) {
+ if (selectedTreeApi && pathArray.length) {
var actElem = selectedTreeApi,
continueCondition = true;
if ( !disabledExpand ) {
- changeTreeDataByProp(treeData, ['expanded','selected'], [false, false]);
+ changeTreeDataByProp(treeData, ['expanded', 'selected'], [false, false]);
}
- for(var i = 0; i < pathArray.length && continueCondition; ) {
+ for (var i = 0; i < pathArray.length && continueCondition; ) {
if ( !disabledExpand ) {
changeTreeDataNode(actElem, treeData, 'expanded', true);
}
var nextElem = getActElementChild(actElem, pathArray[i].name);
- if(nextElem !== null) {
+ if (nextElem !== null) {
actElem = nextElem;
i = i + ( actElem && actElem.identifiersLength > 0 ? actElem.identifiersLength + 1 : 1);
} else {
changeTreeDataNode(actElem, treeData, 'selected', true);
}
- if(actElem) {
+ if (actElem) {
retObj = { indexApi: actElem.indexApi, indexSubApi: actElem.indexSubApi };
}
}
return retObj;
- };
+ }
- pathUtils.fillIdentifiers = function(identifiers, label, value) {
- identifiers.some(function(i) {
+ // TODO: add service's description
+ function fillIdentifiers(identifiers, label, value) {
+ identifiers.some(function (i) {
var identifierMatch = i.label === label;
- if(identifierMatch) {
+ if (identifierMatch) {
i.value = value || '';
}
return identifierMatch;
});
- };
+ }
- pathUtils.fillListNode = function(node, label, value) {
- if(node.type === 'list' && node.actElemStructure !== null) {
+ // TODO: add service's description
+ function fillListNode(node, label, value) {
+ if (node.type === 'list' && node.actElemStructure !== null) {
var nodeToFill = node.actElemStructure.getChildren('leaf', label)[0];
- if(nodeToFill) {
+ if (nodeToFill) {
nodeToFill.fill(nodeToFill.label, value);
}
}
- };
+ }
- pathUtils.fillListRequestData = function(data, listLabel, label, value){
+ // TODO: add service's description
+ function fillListRequestData(data, listLabel, label, value){
if ( data.hasOwnProperty(listLabel) && data[listLabel].length ) {
data[listLabel][0][label] = value;
}
- };
+ }
- pathUtils.findIndexOfStrInPathStr = function(pathParts, targetStr) { //pathParts is path string split by '/'
+ // TODO: add service's description
+ function findIndexOfStrInPathStr(pathParts, targetStr) { // pathParts is path string split by '/'
var targetIndex = -1;
- pathParts.some(function(p, i) {
+ pathParts.some(function (p, i) {
var condition = p === targetStr;
- if(condition) {
+ if (condition) {
targetIndex = i;
}
return condition;
});
return targetIndex;
- };
+ }
- pathUtils.getStorageAndNormalizedPath = function(pathStr) {
+ // TODO: add service's description
+ function getStorageAndNormalizedPath(pathStr) {
var pathParts = pathStr.split('/'),
- restconfIndex = pathUtils.findIndexOfStrInPathStr(pathParts, 'restconf'),
+ restconfIndex = findIndexOfStrInPathStr(pathParts, 'restconf'),
storage = pathParts[restconfIndex + 1],
normalizedPath = pathParts.slice(restconfIndex + 1).join('/');
return { storage: storage, normalizedPath: normalizedPath };
- };
+ }
+
+ /**
+ * Base identifier object
+ * @param label
+ * @param value
+ * @constructor
+ */
+ function Identifier(label, value) {
+ this.label = label;
+ this.value = value || '';
+ }
+
+ /**
+ * Base path element object
+ * @param name
+ * @param module
+ * @param identifierNames
+ * @param moduleChanged
+ * @param revision
+ * @constructor
+ */
+ function PathElem(name, module, identifierNames, moduleChanged, revision) {
+ this.name = name;
+ this.module = module;
+ this.identifiers = identifierNames ? identifierNames.map(function (name) {
+ return new Identifier(name);
+ }) : [];
+ this.moduleChanged = moduleChanged || false;
+ this.revision = revision;
+
+ this.equals = function (comparedElem, compareIdentifierValues) {
+ var result = this.name === comparedElem.name &&
+ this.module === comparedElem.module &&
+ this.identifiers.length === comparedElem.identifiers.length;
+
+ if (result) {
+ var identifiersCnt = this.identifiers.length,
+ i;
+
+ for (i = 0; i < identifiersCnt && result; i++) {
+ result = this.identifiers[i].label === comparedElem.identifiers[i].label;
+ if (compareIdentifierValues) {
+ result = this.identifiers[i].value === comparedElem.identifiers[i].value;
+ }
+ }
+ }
- pathUtils.__test = {
- PathElem: PathElem,
- getModuleNodePair: getModuleNodePair,
- isIdentifier: isIdentifier
- };
+ return result;
+ };
+
+ this.hasIdentifier = function () {
+ return this.identifiers.length > 0;
+ };
+
+ this.addIdentifier = function (name) {
+ this.identifiers.push(new Identifier(name));
+ };
+
+ this.getIdentifierValues = function () {
+ return this.identifiers.map(function (i) {
+ return i.value;
+ });
+ };
+
+ this.toString = function () {
+ return (this.module ? this.module + ':' : '') + this.name + '/' + (this.hasIdentifier() ?
+ this.getIdentifierValues().join('/') + '/' : '');
+ };
+
+ this.checkNode = function (node) {
+ return (this.module ? this.module === node.module : true) &&
+ (this.name ? this.name === node.label : true) &&
+ (this.revision ? this.revision === node.moduleRevision : true);
+ };
+
+ this.clone = function () {
+ var copy = new PathElem(this.name, this.module, null, this.moduleChanged, this.revision);
- return pathUtils;
+ copy.identifiers = this.identifiers.map(function (i) {
+ return new Identifier(i.label, i.value);
+ });
+
+ return copy;
+ };
+ }
+
+ // TODO: add function's description
+ function trimPath(pathString) {
+ var searchStr = 'restconf',
+ output = pathString;
+
+ if (pathString.indexOf(searchStr) > -1) {
+ output = pathString.slice(pathString.indexOf(searchStr) + searchStr.length + 1);
+ }
+
+ return output;
+ }
+
+ // TODO: add function's description
+ function changeTreeDataNode(treeApiNode, treeData, prop, val) {
+ var sel = treeApiNode ? treeData.filter(function (d) {
+ return d.branch.uid === treeApiNode.uid;
+ }) : [];
+
+ if (sel.length === 1) {
+ sel[0].branch[prop] = val;
+ }
+ }
+
+ // TODO: add function's description
+ function changeTreeDataByProp(treeData, props, vals) {
+ treeData.forEach(function (d, index) {
+ props.forEach(function (v, i){
+ d.branch[v] = vals[i];
+ });
+ });
+ }
+
+ // TODO: add function's description
+ function getActElementChild(actElem, childLabel) {
+ var sel = actElem.children.filter(function (child) {
+ return child.label === childLabel;
+ }),
+ ret = sel.length === 1 ? sel[0] : null;
+
+ return ret;
+ }
+
+ // TODO: add function's description
+ function getModuleNodePair(pathString, defaultModule) {
+ return pathString.indexOf(':') > -1 ? pathString.split(':') : [defaultModule, pathString];
+ }
+
+ /**
+ * Tool for check if item is identifier
+ * @param item
+ * @returns {boolean}
+ */
+ function isIdentifier(item) {
+ return (item.indexOf('{') === item.indexOf('}')) === false;
+ }
+
+ // TODO: add function's description
+ function searchForRevisionInImportNodes(module, importNodes) {
+ var revision = null,
+ node = importNodes.filter(function (i) {
+ return i.label === module;
+ })[0];
+
+ if (node) {
+ revision = node._revisionDate;
+ }
+
+ return revision;
+ }
}
- PathUtilsService.$inject=['ArrayUtilsService'];
+ PathUtilsService.$inject = ['ArrayUtilsService'];
return PathUtilsService;
-});
\ No newline at end of file
+});
'use strict';
function RequestBuilderService(){
- var transformPropData = function(data) {
- // return data || {};
- return data;
- };
- var builder = {
- createObj: function () {
- return {};
- },
- createList: function () {
- return [];
- },
- insertObjToList: function (list, obj) {
- list.push(obj);
- },
- insertPropertyToObj: function (obj, propName, propData) {
- var data = transformPropData(propData),
- name = propName;
-
- obj[name] = data;
- },
- resultToString: function (obj) {
- return JSON.stringify(obj, null, 4);
- }
+ var service = {
+ createList: createList,
+ createObj: createObj,
+ insertPropertyToObj: insertPropertyToObj,
+ insertObjToList: insertObjToList,
+ resultToString: resultToString,
};
- return builder;
+ return service;
+
+ // TODO: add service's description
+ function createObj() {
+ return {};
+ }
+
+ // TODO: add service's description
+ function createList() {
+ return [];
+ }
+
+ // TODO: add service's description
+ function insertObjToList(list, obj) {
+ list.push(obj);
+ }
+
+ // TODO: add service's description
+ function insertPropertyToObj(obj, propName, propData) {
+ obj[propName] = propData;
+ }
+
+ // TODO: add service's description
+ function resultToString(obj) {
+ return angular.toJson(obj, true);
+ }
}
- RequestBuilderService.$inject=[];
+ RequestBuilderService.$inject = [];
return RequestBuilderService;
-});
\ No newline at end of file
+});
'use strict';
function RestrictionsService(){
- var RestrictionObject = function(fnc, info) {
- this.info = info;
- this.check = fnc;
- };
-
- var convertToInteger = function(value) {
- var strVal = typeof value === 'string' ? value : value.toString(),
- radix = strVal.indexOf('0x') === 0 ? 16 : strVal.indexOf('0') === 0 ? 8 : 10;
- return parseInt(strVal, radix);
+ var service = {
+ getEqualsFnc: getEqualsFnc,
+ getIsDecimalFnc: getIsDecimalFnc,
+ getIsNumberFnc: getIsNumberFnc,
+ getIsUNumberFnc: getIsUNumberFnc,
+ getMinMaxFnc: getMinMaxFnc,
+ getReqexpValidationFnc: getReqexpValidationFnc,
+ isInArray: isInArray,
};
- var restrictions = {};
+ return service;
- restrictions.getEqualsFnc = function (target) {
+ // TODO: add service's description
+ function getEqualsFnc(target) {
var intTarget = parseInt(target);
return new RestrictionObject(
var intVal = convertToInteger(value);
return intVal === intTarget;
},
- 'Value must be equal to '+target
+ 'Value must be equal to ' + target
);
- };
+ }
- restrictions.getMinMaxFnc = function (min, max) {
+ // TODO: add service's description
+ function getMinMaxFnc(min, max) {
var intMin = parseInt(min),
intMax = parseInt(max);
var intVal = convertToInteger(value);
return (intMin <= intVal) && (intVal <= intMax);
},
- 'Value must be in between '+min+' and '+max
+ 'Value must be in between ' + min + ' and ' + max
);
- };
+ }
- restrictions.getReqexpValidationFnc = function (patternString) {
+ // TODO: add service's description
+ function getReqexpValidationFnc(patternString) {
return new RestrictionObject(
function (value) {
var pattern = new RegExp(patternString);
return pattern.test(value.toString());
},
- 'Value must match '+patternString
+ 'Value must match ' + patternString
);
- };
+ }
- restrictions.getIsNumberFnc = function () {
+ // TODO: add service's description
+ function getIsNumberFnc() {
return new RestrictionObject(
function (value) {
var pattern = new RegExp('^[+-]?((0x[0-9A-Fa-f]+)|(0[0-9]+)|([0-9]+))$');
},
'Value must be number (+/-, 0x and 0) prefixed are permitted'
);
- };
+ }
- restrictions.getIsUNumberFnc = function () {
+ // TODO: add service's description
+ function getIsUNumberFnc() {
return new RestrictionObject(
function (value) {
var pattern = new RegExp('^[+]?((0x[0-9A-Fa-f]+)|(0[0-9]+)|([0-9]+))$');
},
'Value must be positive number (+, 0x and 0) prefixed are permitted'
);
- };
+ }
- restrictions.getIsDecimalFnc = function () {
+ // TODO: add service's description
+ function getIsDecimalFnc() {
return new RestrictionObject(
function (value) {
- var pattern = new RegExp("^[-]?[1-9]?[0-9]+[.|,]?[0-9]*$");
+ var pattern = new RegExp('^[-]?[1-9]?[0-9]+[.|,]?[0-9]*$');
return pattern.test(value.toString());
},
'Value must be decimal number - prefix is permitted'
);
- };
+ }
- restrictions.isInArray = function (array) {
+ // TODO: add service's description
+ function isInArray(array) {
return new RestrictionObject(
function (value) {
- return array.some(function(arrVal) {
+ return array.some(function (arrVal) {
return arrVal === value;
});
},
'Value must be in ' + array.toString()
);
- };
+ }
+
+ /**
+ * Base restriction object
+ * @param fnc
+ * @param info
+ * @constructor
+ */
+ function RestrictionObject(fnc, info) {
+ this.info = info;
+ this.check = fnc;
+ }
+ // TODO: add function's description
+ function convertToInteger(value) {
+ var strVal = typeof value === 'string' ? value : value.toString(),
+ radix = strVal.indexOf('0x') === 0 ? 16 : strVal.indexOf('0') === 0 ? 8 : 10;
- return restrictions;
+ return parseInt(strVal, radix);
+ }
}
- RestrictionsService.$inject=[];
+ RestrictionsService.$inject = [];
return RestrictionsService;
-});
\ No newline at end of file
+});
'use strict';
function SyncService($timeout){
- var timeout = 180000;
- var SyncObject = function () {
+ var timeout = 180000,
+ service = {
+ generateObj: function () {
+ return new SyncObject();
+ },
+ };
+
+ return service;
+
+ /**
+ * Base synchronization object
+ * @constructor
+ */
+ function SyncObject() {
this.runningRequests = [];
this.reqId = 0;
this.timeElapsed = 0;
this.spawnRequest = function (digest) {
var id = digest + (this.reqId++).toString();
this.runningRequests.push(id);
- //console.debug('adding request ',id,' total running requests = ',this.runningRequests);
+ // console.debug('adding request ',id,' total running requests = ',this.runningRequests);
return id;
};
if (index > -1) {
this.runningRequests.splice(index, 1);
- //console.debug('removing request ',id,' remaining requests = ',this.runningRequests);
+ // console.debug('removing request ',id,' remaining requests = ',this.runningRequests);
} else {
console.warn('cannot remove request', id, 'from', this.runningRequests, 'index is', index);
}
callback();
}
};
- };
-
- return {
- generateObj: function () {
- return new SyncObject();
- }
- };
+ }
}
- SyncService.$inject=['$timeout'];
+ SyncService.$inject = ['$timeout'];
return SyncService;
-});
\ No newline at end of file
+});
'use strict';
function TypeWrapperService(RestrictionsService){
- var findLeafParent = function (node) {
- if (node.type === 'leaf') {
- return node;
- } else {
- if (node.parent) {
- return findLeafParent(node.parent);
- } else {
- return null;
- }
- }
+
+ var service = {
+ bits: bits,
+ decimal64: decimal64,
+ empty: empty,
+ enumeration: enumeration,
+ int16: int16,
+ int32: int32,
+ int64: int64,
+ int8: int8,
+ _setDefaultProperties: _setDefaultProperties,
+ uint16: uint16,
+ uint32: uint32,
+ uint64: uint64,
+ uint8: uint8,
+ union: union,
+ wrapAll: wrapAll,
+ __test: {
+ findLeafParent: findLeafParent,
+ },
};
- var wrapper = {
- wrapAll: function (node) {
- if (node.type === 'type') {
- this._setDefaultProperties(node);
- }
+ return service;
- if(this.hasOwnProperty(node.label)) {
- this[node.label](node);
- }
- },
- _setDefaultProperties: function (node) {
- var fnToString = function (string) {
- var valueStr = '';
-
- if(string !== null) {
- try {
- valueStr = string.toString();
- } catch (e) {
- console.warn('cannot convert value', node.value);
- }
- }
+ // TODO: add service's description
+ function uint64(node) {
+ node.builtInChecks.push(RestrictionsService.getIsUNumberFnc());
+ node.builtInChecks.push(RestrictionsService.getMinMaxFnc(0, 18446744073709551615));
+ }
- return valueStr;
- };
+ // TODO: add service's description
+ function uint32(node) {
+ node.builtInChecks.push(RestrictionsService.getIsUNumberFnc());
+ node.builtInChecks.push(RestrictionsService.getMinMaxFnc(0, 4294967295));
+ }
- node.leafParent = findLeafParent(node);
- node.builtInChecks = [];
- node.errors = [];
- node.clear = function () {
- };
- node.fill = function () {
- };
- node.performRestrictionsCheck = function (value) {
- var patternRestrictions = node.getChildren('pattern'),
- patternCheck = function(value) {
- return patternRestrictions.map(function(patternNode) {
- return patternNode.restrictions[0];
- }).some(function(patternRestriction) {
- var condition = patternRestriction.check(value);
- if(condition === false) {
- node.errors.push(patternRestriction.info);
- }
- return condition;
- });
- },
- lengthRestrictions = node.getChildren('length'),
- rangeRestrictions = node.getChildren('range'),
- lengthRangeCheck = function(restrictionsContainers, value) {
- return restrictionsContainers[0].restrictions.some(function(restriction) {
- var condition = restriction.check(value);
- if(condition === false) {
- node.errors.push(restriction.info);
- }
- return condition;
- });
- };
-
- var patternCondition = patternRestrictions.length ? patternCheck(value) : true,
- lengthCondition = lengthRestrictions.length && value.length? lengthRangeCheck(lengthRestrictions, value.length) : true,
- rangeCondition = rangeRestrictions.length ? lengthRangeCheck(rangeRestrictions, value) : true;
-
- return patternCondition && lengthCondition && rangeCondition;
- };
- node.performBuildInChecks = function (value) {
- return node.builtInChecks.length ? node.builtInChecks.every(function (restriction) {
- var condition = restriction.check(value);
- if(condition === false) {
- node.errors.push(restriction.info);
- }
- return condition;
- }) : true;
- };
- node.check = function (value) {
- node.errors = [];
- var condition = value !== '' ? node.performBuildInChecks(value) && node.performRestrictionsCheck(value) : true;
- if(condition) {
- node.errors = [];
- }
- return condition;
- };
- node.getValue = function(){
- return fnToString(node.leafParent.value);
- };
- },
- // string: function (node) {
- // },
- // boolean: function (node) {
- // },
- empty: function (node) {
- node.setLeafValue = function (value) {
- node.leafParent.value = value === 1 ? {} : '';
- };
-
- node.clear = function () {
- node.value = null;
- };
-
- node.fill = function (value) {
- node.emptyValue = value === '' ? 1 : ($.isEmptyObject(value) ? 1 : 0);
- node.leafParent.value = parseInt(node.emptyValue, 10) === 1 ? {} : '';
- };
-
- node.getValue = function(){
- return parseInt(node.emptyValue, 10) === 1 ? {} : '';
- };
- },
- enumeration: function (node) {
- node.selEnum = null;
+ // TODO: add service's description
+ function uint16(node) {
+ node.builtInChecks.push(RestrictionsService.getIsUNumberFnc());
+ node.builtInChecks.push(RestrictionsService.getMinMaxFnc(0, 65535));
+ }
- var childNames = [];
- node.getChildren('enum').forEach(function(child) {
- childNames.push(child.label);
+ // TODO: add service's description
+ function uint8(node) {
+ node.builtInChecks.push(RestrictionsService.getIsUNumberFnc());
+ node.builtInChecks.push(RestrictionsService.getMinMaxFnc(0, 255));
+ }
+
+ // TODO: add service's description
+ function int64(node) {
+ node.builtInChecks.push(RestrictionsService.getIsNumberFnc());
+ node.builtInChecks.push(RestrictionsService.getMinMaxFnc(-9223372036854775808, 9223372036854775807));
+ }
+
+ // TODO: add service's description
+ function int32(node) {
+ node.builtInChecks.push(RestrictionsService.getIsNumberFnc());
+ node.builtInChecks.push(RestrictionsService.getMinMaxFnc(-2147483648, 2147483647));
+ }
+
+ // TODO: add service's description
+ function int16(node) {
+ node.builtInChecks.push(RestrictionsService.getIsNumberFnc());
+ node.builtInChecks.push(RestrictionsService.getMinMaxFnc(-32768, 32767));
+ }
+
+ // TODO: add service's description
+ function int8(node) {
+ node.builtInChecks.push(RestrictionsService.getIsNumberFnc());
+ node.builtInChecks.push(RestrictionsService.getMinMaxFnc(-128, 127));
+ }
+
+ // TODO: add service's description
+ function decimal64(node) {
+ node.builtInChecks.push(RestrictionsService.getIsDecimalFnc());
+ }
+
+ // TODO: add service's description
+ function union(node) {
+ node.clear = function () {
+ node.getChildren('type').forEach(function (child) {
+ child.clear();
});
- node.builtInChecks.push(RestrictionsService.isInArray(childNames));
+ };
+ node.fill = function (value) {
+ node.getChildren('type').forEach(function (child) {
+ child.fill(value);
+ });
+ };
- node.setLeafValue = function (value) {
- if(value !== null) {
- node.leafParent.value = value;
- }
- };
+ node.check = function (value) {
+ var condition = false;
+ node.getChildren('type').forEach(function (childType) {
+ var childCondition = childType.check(value);
+ condition = condition || childCondition;
+ });
+ return condition;
+ };
- node.clear = function () {
- node.selEnum = null;
- };
+ node.getChildren('type').forEach(function (childType) {
+ wrapAll(childType);
+ });
+ }
- node.fill = function (value) {
- var selChild = node.getChildren('enum', value)[0];
- node.selEnum = selChild ? selChild : null;
- };
- },
- bits: function (node) {
- var actBitsLen = 0,
- i;
+ // TODO: add service's description
+ function bits(node) {
+ var i;
- node.maxBitsLen = node.getChildren('bit').length;
- node.bitsValues = [];
+ node.maxBitsLen = node.getChildren('bit').length;
+ node.bitsValues = [];
- for (i = 0; i < node.maxBitsLen; i++) {
+ for (i = 0; i < node.maxBitsLen; i++) {
+ node.bitsValues[i] = 0;
+ }
+
+ node.clear = function () {
+ for (i = 0; i < node.bitsValues.length; i++) {
node.bitsValues[i] = 0;
}
+ };
+
+ node.fill = function (value) {
+ var bitLabels = node.getChildren('bit').map(function (bit) {
+ return bit.label;
+ });
- node.clear = function () {
- for (i = 0; i < node.bitsValues.length; i++) {
- node.bitsValues[i] = 0;
+ node.leafParent.value.split(' ').forEach(function (val) {
+ var valIndex = bitLabels.indexOf(val);
+ if (valIndex !== -1) {
+ node.bitsValues[valIndex] = 1;
}
- };
+ });
+ };
- node.fill = function (value) {
- var bitLabels = node.getChildren('bit').map(function(bit) {
+ node.setLeafValue = function (values, fromFilter) {
+ var bitLabels = node.getChildren('bit').map(function (bit) {
return bit.label;
- });
-
- node.leafParent.value.split(' ').forEach(function(val) {
- var valIndex = bitLabels.indexOf(val);
- if(valIndex !== -1) {
- node.bitsValues[valIndex] = 1;
- }
- });
- };
-
- node.setLeafValue = function (values, fromFilter) {
- var bitLabels = node.getChildren('bit').map(function(bit) {
- return bit.label;
- }),
- nodeValue = null;
-
- nodeValue = node.bitsValues.map(function(val, index) {
- if(parseInt(val, 10) === 1) {
- return bitLabels[index];
- } else {
- return null;
- }
- }).filter(function(val) {
- return val !== null;
- }).join(" ");
-
- node.leafParent.value = nodeValue;
- if(fromFilter){
- node.leafParent.filterBitsValue = nodeValue;
+ }),
+ nodeValue = null;
+
+ nodeValue = node.bitsValues.map(function (val, index) {
+ if (parseInt(val, 10) === 1) {
+ return bitLabels[index];
+ } else {
+ return null;
+ }
+ }).filter(function (val) {
+ return val !== null;
+ }).join(' ');
+
+ node.leafParent.value = nodeValue;
+ if (fromFilter){
+ node.leafParent.filterBitsValue = nodeValue;
+ }
+ };
+ }
+
+ // TODO: add service's description
+ function enumeration(node) {
+ node.selEnum = null;
+
+ var childNames = [];
+ node.getChildren('enum').forEach(function (child) {
+ childNames.push(child.label);
+ });
+ node.builtInChecks.push(RestrictionsService.isInArray(childNames));
+
+ node.setLeafValue = function (value) {
+ if (value !== null) {
+ node.leafParent.value = value;
+ }
+ };
+
+ node.clear = function () {
+ node.selEnum = null;
+ };
+
+ node.fill = function (value) {
+ var selChild = node.getChildren('enum', value)[0];
+ node.selEnum = selChild ? selChild : null;
+ };
+ }
+
+ // TODO: add service's description
+ function empty(node) {
+ node.setLeafValue = function (value) {
+ node.leafParent.value = value === 1 ? {} : '';
+ };
+
+ node.clear = function () {
+ node.value = null;
+ };
+
+ node.fill = function (value) {
+ node.emptyValue = value === '' ? 1 : ($.isEmptyObject(value) ? 1 : 0);
+ node.leafParent.value = parseInt(node.emptyValue, 10) === 1 ? {} : '';
+ };
+
+ node.getValue = function (){
+ return parseInt(node.emptyValue, 10) === 1 ? {} : '';
+ };
+ }
+
+ // TODO: add service's description
+ function _setDefaultProperties(node) {
+ var fnToString = function (string) {
+ var valueStr = '';
+
+ if (string !== null) {
+ try {
+ valueStr = string.toString();
+ } catch (e) {
+ console.warn('cannot convert value', node.value);
+ }
+ }
+
+ return valueStr;
+ };
+
+ node.leafParent = findLeafParent(node);
+ node.builtInChecks = [];
+ node.errors = [];
+ node.clear = function () {
+ };
+ node.fill = function () {
+ };
+ node.performRestrictionsCheck = function (value) {
+ var patternRestrictions = node.getChildren('pattern'),
+ patternCheck = function (value) {
+ return patternRestrictions.map(function (patternNode) {
+ return patternNode.restrictions[0];
+ }).some(function (patternRestriction) {
+ var condition = patternRestriction.check(value);
+ if (condition === false) {
+ node.errors.push(patternRestriction.info);
+ }
+ return condition;
+ });
+ },
+ lengthRestrictions = node.getChildren('length'),
+ rangeRestrictions = node.getChildren('range'),
+ lengthRangeCheck = function (restrictionsContainers, value) {
+ return restrictionsContainers[0].restrictions.some(function (restriction) {
+ var condition = restriction.check(value);
+ if (condition === false) {
+ node.errors.push(restriction.info);
+ }
+ return condition;
+ });
+ };
+
+ var patternCondition = patternRestrictions.length ? patternCheck(value) : true,
+ lengthCondition = lengthRestrictions.length && value.length ?
+ lengthRangeCheck(lengthRestrictions, value.length) : true,
+ rangeCondition = rangeRestrictions.length ? lengthRangeCheck(rangeRestrictions, value) : true;
+
+ return patternCondition && lengthCondition && rangeCondition;
+ };
+ node.performBuildInChecks = function (value) {
+ return node.builtInChecks.length ? node.builtInChecks.every(function (restriction) {
+ var condition = restriction.check(value);
+ if (condition === false) {
+ node.errors.push(restriction.info);
}
- };
- },
- // binary: function (node) {
- // },
- // leafref: function (node) {
- // },
- // identityref: function (node) {
- // },
- union: function (node) {
- node.clear = function () {
- node.getChildren('type').forEach(function(child) {
- child.clear();
- });
- };
- node.fill = function (value) {
- node.getChildren('type').forEach(function(child) {
- child.fill(value);
- });
- };
-
- node.check = function (value) {
- var condition = false;
- node.getChildren('type').forEach(function (childType) {
- var childCondition = childType.check(value);
- condition = condition || childCondition;
- });
return condition;
- };
+ }) : true;
+ };
+ node.check = function (value) {
+ node.errors = [];
+ var condition = value !== '' ?
+ node.performBuildInChecks(value) && node.performRestrictionsCheck(value) : true;
+ if (condition) {
+ node.errors = [];
+ }
+ return condition;
+ };
+ node.getValue = function (){
+ return fnToString(node.leafParent.value);
+ };
+ }
- node.getChildren('type').forEach(function (childType) {
- wrapper.wrapAll(childType);
- });
- },
- // 'instance-identifier': function (node) {
- // },
- decimal64: function (node) {
- node.builtInChecks.push(RestrictionsService.getIsDecimalFnc());
- },
- int8: function (node) {
- node.builtInChecks.push(RestrictionsService.getIsNumberFnc());
- node.builtInChecks.push(RestrictionsService.getMinMaxFnc(-128, 127));
- },
- int16: function (node) {
- node.builtInChecks.push(RestrictionsService.getIsNumberFnc());
- node.builtInChecks.push(RestrictionsService.getMinMaxFnc(-32768, 32767));
- },
- int32: function (node) {
- node.builtInChecks.push(RestrictionsService.getIsNumberFnc());
- node.builtInChecks.push(RestrictionsService.getMinMaxFnc(-2147483648, 2147483647));
- },
- int64: function (node) {
- node.builtInChecks.push(RestrictionsService.getIsNumberFnc());
- node.builtInChecks.push(RestrictionsService.getMinMaxFnc(-9223372036854775808, 9223372036854775807));
- },
- uint8: function (node) {
- node.builtInChecks.push(RestrictionsService.getIsUNumberFnc());
- node.builtInChecks.push(RestrictionsService.getMinMaxFnc(0, 255));
- },
- uint16: function (node) {
- node.builtInChecks.push(RestrictionsService.getIsUNumberFnc());
- node.builtInChecks.push(RestrictionsService.getMinMaxFnc(0, 65535));
- },
- uint32: function (node) {
- node.builtInChecks.push(RestrictionsService.getIsUNumberFnc());
- node.builtInChecks.push(RestrictionsService.getMinMaxFnc(0, 4294967295));
- },
- uint64: function (node) {
- node.builtInChecks.push(RestrictionsService.getIsUNumberFnc());
- node.builtInChecks.push(RestrictionsService.getMinMaxFnc(0, 18446744073709551615));
+ // TODO: add service's description
+ function wrapAll(node) {
+ if (node.type === 'type') {
+ _setDefaultProperties(node);
}
- };
- wrapper.__test = {
- findLeafParent: findLeafParent
- };
+ if (service.hasOwnProperty(node.label)) {
+ service[node.label](node);
+ }
+ }
- return wrapper;
+ // TODO: add function's description
+ function findLeafParent(node) {
+ if (node.type === 'leaf') {
+ return node;
+ } else {
+ if (node.parent) {
+ return findLeafParent(node.parent);
+ } else {
+ return null;
+ }
+ }
+ }
}
- TypeWrapperService.$inject=['RestrictionsService'];
+ TypeWrapperService.$inject = ['RestrictionsService'];
return TypeWrapperService;
-});
\ No newline at end of file
+});
'use strict';
function YangUiApisService(YangUtilsRestangularService){
- var apis = {};
+ var service = {
+ getAllModules: getAllModules,
+ getAllApis: getAllApis,
+ getCustomModules: getCustomModules,
+ getModuleSchema: getModuleSchema,
+ getSingleApiInfo: getSingleApiInfo,
+ getSingleModuleInfo: getSingleModuleInfo,
+ };
+
+ return service;
- apis.getAllModules = function() {
+ // TODO: add service's description
+ function getAllModules() {
return YangUtilsRestangularService.one('restconf').one('modules');
- };
+ }
- apis.getModuleSchema = function(name, rev) {
- return YangUtilsRestangularService.one('restconf').one('modules').one('module').one(name).one(rev).one('schema');
- };
+ // ,TODO: add service's description
+ function getModuleSchema(name, rev) {
+ return YangUtilsRestangularService.one('restconf').one('modules')
+ .one('module').one(name).one(rev).one('schema');
+ }
- apis.getSingleModuleInfo = function(modulePath) {
+ // TODO: add service's description
+ function getSingleModuleInfo(modulePath) {
return YangUtilsRestangularService.one('restconf').one('modules').one('module').customGET(modulePath);
- };
+ }
- apis.getAllApis = function() {
+ // TODO: add service's description
+ function getAllApis() {
return YangUtilsRestangularService.one('apidoc').one('apis');
- };
+ }
- apis.getSingleApiInfo = function(apiPath) {
+ // TODO: add service's description
+ function getSingleApiInfo(apiPath) {
return YangUtilsRestangularService.one('apidoc').one('apis').customGET(apiPath);
- };
-
- apis.getCustomModules = function(baseApiPath) {
- return YangUtilsRestangularService.one('restconf').one('modules').customGET(baseApiPath);
- };
+ }
- apis.getCustomModules = function(baseApiPath) {
+ // TODO: add service's description
+ function getCustomModules(baseApiPath) {
return YangUtilsRestangularService.one('restconf').one('modules').customGET(baseApiPath);
- };
-
- return apis;
+ }
}
- YangUiApisService.$inject=['YangUtilsRestangularService'];
+ YangUiApisService.$inject = ['YangUtilsRestangularService'];
return YangUiApisService;
-});
\ No newline at end of file
+});
'use strict';
function YangUtilsRestangularService(Restangular, ENV){
- var isEmptyElement = function(element) {
- return element.hasOwnProperty('id') && element.id === undefined;
- };
- var r = Restangular.withConfig(function(RestangularConfig) {
- RestangularConfig.setBaseUrl(ENV.getBaseURL("MD_SAL"));
- RestangularConfig.setRequestInterceptor(function(elem, operation) {
+ // TODO: add service's description
+ return Restangular.withConfig(function (RestangularConfig) {
+ RestangularConfig.setBaseUrl(ENV.getBaseURL('MD_SAL'));
+ RestangularConfig.setRequestInterceptor(function (elem, operation) {
if (operation === 'post' && isEmptyElement(elem)) {
return null;
} else {
});
});
- return r;
+ // TODO: add function's description
+ function isEmptyElement(element) {
+ return element.hasOwnProperty('id') && element.id === undefined;
+ }
}
- YangUtilsRestangularService.$inject=['Restangular', 'ENV'];
+ YangUtilsRestangularService.$inject = ['Restangular', 'ENV'];
return YangUtilsRestangularService;
-});
\ No newline at end of file
+});
-define([], function () {
+define(['angular'], function (angular) {
'use strict';
function YangUtilsService(YinParserService, NodeWrapperService, RequestBuilderService, SyncService, constants,
ModuleConnectorService, YangUiApisService, EventDispatcherService, ApiBuilderService){
- var utils = {};
+ var service = {
+ getRequestString: getRequestString,
+ generateApiTreeData: generateApiTreeData,
+ generateNodesToApis: generateNodesToApis,
+ objectHandler: objectHandler,
+ prepareHeaders: prepareHeaders,
+ prepareOperation: prepareOperation,
+ prepareRequestData: prepareRequestData,
+ processModules: processModules,
+ processModulesMP: processModulesMP,
+ stripAngularGarbage: stripAngularGarbage,
+ switchConfigOper: switchConfigOper,
+ transformTopologyData: transformTopologyData,
- utils.stripAngularGarbage = function(obj, prop) {
- var strippedObj = {},
- propsToRemove = ['$$hashKey', 'route', 'reqParams', 'parentResource', 'restangularCollection'],
- removeGarbage = function(obj) {
- propsToRemove.forEach(function(p) {
- delete obj[p];
- });
+ };
- return obj;
- };
+ service.errorMessages = {
+ 'method': {
+ 'GET': {
+ '401': 'YANGUI_ERROR_GET_401',
+ '403': 'YANGUI_ERROR_GET_403',
+ '404': 'YANGUI_ERROR_GET_404',
+ '500': 'YANGUI_ERROR_GET_500',
+ '503': 'YANGUI_ERROR_GET_503',
+ },
+ 'POST': {
+ '500': 'YANGUI_ERROR_GET_500',
+ '503': 'YANGUI_ERROR_GET_503',
+ },
+ 'PUT': {
+ '500': 'YANGUI_ERROR_GET_500',
+ '503': 'YANGUI_ERROR_GET_503',
+ },
+ 'DELETE': {
+ '500': 'YANGUI_ERROR_GET_500',
+ '503': 'YANGUI_ERROR_GET_503',
+ },
+ },
+ };
+
+ return service;
- if(obj.hasOwnProperty(prop)) {
+ // TODO: add service's description
+ function stripAngularGarbage(obj, prop) {
+ var strippedObj = {},
+ propsToRemove = ['$$hashKey', 'route', 'reqParams', 'parentResource', 'restangularCollection'];
+
+ if (obj.hasOwnProperty(prop)) {
strippedObj[prop] = obj[prop];
} else {
strippedObj = removeGarbage(obj);
}
return strippedObj;
- };
- utils.switchConfigOper = function(apiStr, swtichTo) {
+ function removeGarbage(obj) {
+ propsToRemove.forEach(function (p) {
+ delete obj[p];
+ });
+
+ return obj;
+ }
+ }
+
+ // TODO: add service's description
+ function switchConfigOper(apiStr, swtichTo) {
var c = 'config',
o = 'operational',
str = apiStr;
- if(apiStr.indexOf(c) === 0) {
+ if (apiStr.indexOf(c) === 0) {
str = swtichTo + apiStr.slice(c.length);
- } else if(apiStr.indexOf(o) === 0) {
+ } else if (apiStr.indexOf(o) === 0) {
str = swtichTo + apiStr.slice(o.length);
}
return str;
- };
+ }
- utils.generateNodesToApis = function (callback, errorCbk) {
+ // TODO: add service's description
+ function generateNodesToApis(callback, errorCbk) {
var allRootNodes = [],
topLevelSync = SyncService.generateObj(),
reqAll = topLevelSync.spawnRequest('all'),
YangUiApisService.getAllModules().get().then(
function (data) {
- utils.processModules(data.modules, function (result, aGroups) {
+ processModules(data.modules, function (result, aGroups) {
allAugmentationGroups = aGroups;
allRootNodes = result.map(function (node) {
var copy = node.deepCopy(['augmentionGroups', 'augmentationId']);
topLevelSync.removeRequest(reqAll);
});
}, function (result) {
- console.error('Error getting API data:', result);
- topLevelSync.removeRequest(reqAll);
- }
- );
+ console.error('Error getting API data:', result);
+ topLevelSync.removeRequest(reqAll);
+ });
topLevelSync.waitFor(function () {
try {
callback(abApis, allRootNodes, allAugmentationGroups);
} catch (e) {
errorCbk(e);
- throw(e); //do not lose debugging info
+ throw (e); // do not lose debugging info
}
});
- };
+ }
- utils.generateApiTreeData = function (apis) {
- var newElem = function (pathElem, array) {
- var getIdentifierStr = function(path){
- return path.identifiers.map(function(identifier){
- return '{' + identifier.label + '}';
- }).join(' ');
- },
- element = {
- label: pathElem.name,
- module: pathElem.module,
- identifier: pathElem.hasIdentifier() ? getIdentifierStr(pathElem) : '',
- identifiersLength: pathElem.identifiers.length,
- children: []
- };
-
- array.push(element);
- },
- fillPath = function (path, array, indexSubApi, indexApi, itemSub, childIndex) {
- var existElem = false,
- arrayIndex = null,
- currentPathItem = path[childIndex],
- continueProcessing = false;
-
- if (childIndex < path.length) {
- if (array.length > 0) {
- existElem = array.some(function (arrayItem, index) {
- var condition = arrayItem.label === currentPathItem.name;
- if (condition) {
- arrayIndex = index;
- }
-
- return condition;
- });
-
- if (!existElem) {
- newElem(currentPathItem, array);
- }
- } else {
- newElem(currentPathItem, array);
- }
-
- arrayIndex = arrayIndex !== null ? arrayIndex : array.length - 1;
- var isContinuing = fillPath(path, array[arrayIndex].children, indexSubApi, indexApi, itemSub, childIndex+1);
- if (isContinuing === false) {
- array[arrayIndex].indexApi = indexApi;
- array[arrayIndex].indexSubApi = indexSubApi;
- }
-
- continueProcessing = true;
- }
-
- return continueProcessing;
- },
- getApisAndPath = function (item, indexApi) {
- var childrenArray = [];
-
- item.subApis.map(function (itemSub, indexSubApi) {
- var childIndex = 0;
- fillPath(itemSub.pathArray, childrenArray, indexSubApi, indexApi, itemSub, childIndex);
- });
-
- return childrenArray;
- },
- dataTree = apis.map(function (item, indexApi) {
+ // TODO: add service's description
+ function generateApiTreeData(apis) {
+ var dataTree = apis.map(function (item, indexApi) {
var apisPath = getApisAndPath(item, indexApi);
return {
label: item.module + (item.revision ? ' rev.' + item.revision : ''),
module: item.module,
revision: item.revision,
- children: apisPath
+ children: apisPath,
};
}),
- sortedDataTree = dataTree.sort(function(a, b) {
+ sortedDataTree = dataTree.sort(function (a, b) {
var sortRes = 0;
- if(a.label < b.label) {
+ if (a.label < b.label) {
sortRes = -1;
}
- if(a.label > b.label) {
+ if (a.label > b.label) {
sortRes = 1;
}
return sortRes;
});
return sortedDataTree;
- };
- utils.processModules = function (loadedModules, callback) {
+ // TODO: add function's description
+ function getApisAndPath(item, indexApi) {
+ var childrenArray = [];
+
+ item.subApis.map(function (itemSub, indexSubApi) {
+ var childIndex = 0;
+ fillPath(itemSub.pathArray, childrenArray, indexSubApi, indexApi, itemSub, childIndex);
+ });
+
+ return childrenArray;
+ }
+
+ // TODO: add function's description
+ function newElem(pathElem, array) {
+ var element = {
+ label: pathElem.name,
+ module: pathElem.module,
+ identifier: pathElem.hasIdentifier() ? getIdentifierStr(pathElem) : '',
+ identifiersLength: pathElem.identifiers.length,
+ children: [],
+ };
+
+ array.push(element);
+
+ // TODO: add function's description
+ function getIdentifierStr(path){
+ return path.identifiers.map(function (identifier){
+ return '{' + identifier.label + '}';
+ }).join(' ');
+ }
+ }
+
+ // TODO: add function's description
+ function fillPath(path, array, indexSubApi, indexApi, itemSub, childIndex) {
+ var existElem = false,
+ arrayIndex = null,
+ currentPathItem = path[childIndex],
+ continueProcessing = false;
+
+ if (childIndex < path.length) {
+ if (array.length > 0) {
+ existElem = array.some(function (arrayItem, index) {
+ var condition = arrayItem.label === currentPathItem.name;
+ if (condition) {
+ arrayIndex = index;
+ }
+
+ return condition;
+ });
+
+ if (!existElem) {
+ newElem(currentPathItem, array);
+ }
+ } else {
+ newElem(currentPathItem, array);
+ }
+
+ arrayIndex = arrayIndex !== null ? arrayIndex : array.length - 1;
+ var isContinuing = fillPath(path, array[arrayIndex].children, indexSubApi, indexApi, itemSub, childIndex + 1);
+ if (isContinuing === false) {
+ array[arrayIndex].indexApi = indexApi;
+ array[arrayIndex].indexSubApi = indexSubApi;
+ }
+
+ continueProcessing = true;
+ }
+
+ return continueProcessing;
+ }
+ }
+
+ // TODO: add service's description
+ function processModules(loadedModules, callback) {
var modules = [],
rootNodes = [],
augments = [],
callback(rootNodes, augmentionGroups);
});
- };
+ }
- utils.processModulesMP = function (loadedModules, basePath, callback) {
+ // TODO: add service's description
+ function processModulesMP(loadedModules, basePath, callback) {
var modules = [],
rootNodes = [],
augments = [],
callback(rootNodes, augmentionGroups);
});
- };
+ }
- utils.getRequestString = function (node) {
+ // TODO: add service's description
+ function getRequestString(node) {
var request = RequestBuilderService.createObj(),
reqStr = '';
reqStr = RequestBuilderService.resultToString(request);
}
return reqStr;
- };
+ }
- utils.transformTopologyData = function (data, callback) {
+ // TODO: add service's description
+ function transformTopologyData(data, callback) {
var links = [],
- nodes = [],
- getNodeIdByText = function getNodeIdByText(inNodes, text) {
- var nodes = inNodes.filter(function (item, index) {
- return item.label === text;
- }),
- nodeId;
-
- if (nodes.length > 0 && nodes[0]) {
- nodeId = nodes[0].id;
- } else {
- return null;
- }
-
- return nodeId;
- };
+ nodes = [];
if (data['network-topology'] && data['network-topology'].topology.length) {
- var topoData = callback ? callback(data['network-topology'].topology) : data['network-topology'].topology[0],
+ var topoData = callback ?
+ callback(data['network-topology'].topology) : data['network-topology'].topology[0],
nodeId = 0,
linkId = 0;
nodes = topoData.hasOwnProperty('node') ? topoData.node.map(function (nodeData) {
- return {'id': (nodeId++).toString(), 'label': nodeData["node-id"], group: nodeData["node-id"].indexOf('host') === 0 ? 'host' : 'switch', value: 20, title: 'Name: <b>' + nodeData["node-id"] + '</b><br>Type: Switch'};
+ return {
+ 'id': (nodeId++).toString(),
+ 'label': nodeData['node-id'],
+ group: nodeData['node-id'].indexOf('host') === 0 ? 'host' : 'switch',
+ value: 20,
+ title: 'Name: <b>' + nodeData['node-id'] + '</b><br>Type: Switch',
+ };
}) : [];
links = topoData.hasOwnProperty('link') ? topoData.link.map(function (linkData) {
- var srcId = getNodeIdByText(nodes, linkData.source["source-node"]),
- dstId = getNodeIdByText(nodes, linkData.destination["dest-node"]),
- srcPort = linkData.source["source-tp"],
- dstPort = linkData.destination["dest-tp"];
+ var srcId = getNodeIdByText(nodes, linkData.source['source-node']),
+ dstId = getNodeIdByText(nodes, linkData.destination['dest-node']),
+ srcPort = linkData.source['source-tp'],
+ dstPort = linkData.destination['dest-tp'];
if (srcId != null && dstId != null) {
- return {id: (linkId++).toString(), 'from': srcId, 'to': dstId, title: 'Source Port: <b>' + srcPort + '</b><br>Dest Port: <b>' + dstPort + '</b>'};
+ return {
+ id: (linkId++).toString(),
+ 'from': srcId,
+ 'to': dstId,
+ title: 'Source Port: <b>' + srcPort + '</b><br>Dest Port: <b>' + dstPort + '</b>',
+ };
}
}) : [];
}
- return {nodes: nodes, links: links};
- };
+ return {
+ nodes: nodes,
+ links: links,
+ };
+
+ function getNodeIdByText(inNodes, text) {
+ var nodes = inNodes.filter(function (item) {
+ return item.label === text;
+ }),
+ nodeId;
- utils.objectHandler = function(obj, objCbk, vauleCbk, arrayCbk){
+ if (nodes.length > 0 && nodes[0]) {
+ nodeId = nodes[0].id;
+ } else {
+ return null;
+ }
+
+ return nodeId;
+ }
+ }
+
+ // TODO: add service's description
+ function objectHandler(obj, objCbk, vauleCbk, arrayCbk){
if ( Array.isArray(obj) ) {
if (angular.isFunction(arrayCbk)) {
arrayCbk(obj);
}
- obj.forEach(function(item){
- utils.objectHandler(item, objCbk, vauleCbk);
+ obj.forEach(function (item){
+ objectHandler(item, objCbk, vauleCbk);
});
} else {
if ( obj !== null && Object.keys(obj).length > 0 && typeof obj !== 'string' ) {
objCbk(obj);
}
- for(var property in obj){
- utils.objectHandler(obj[property], objCbk, vauleCbk);
+ for (var property in obj){
+ objectHandler(obj[property], objCbk, vauleCbk);
}
} else {
if (angular.isFunction(vauleCbk)) {
}
}
}
- };
+ }
- var checkSupApiIdentifiers = function(subApi){
- var pathElement = subApi.pathArray[subApi.pathArray.length-1];
- return pathElement.hasIdentifier() ? pathElement.identifiers : [];
- },
- postRequestData = function(requestData, reqString, subApi){
- var identifiersArray = checkSupApiIdentifiers(subApi),
- lastPathElement = function(path){
- return path.split('/').pop().split(':').pop();
- };
-
- if ( identifiersArray.length ) {
- var pathArray = reqString.split('/'),
- reqObj = null;
-
- identifiersArray.forEach(function(){
- pathArray.pop();
- });
-
- reqString = pathArray.join('/');
- var requestItem = requestData[lastPathElement(reqString)] ? requestData[lastPathElement(reqString)].filter(function(item){
- return identifiersArray.every(function(i){
- return item[i.label] === i.value;
- });
- }) : [];
-
- return requestItem.length ? requestItem[0] : {};
- } else {
- return requestData[lastPathElement(reqString)];
- }
- };
-
- utils.prepareRequestData = function(requestData, operation, reqString, subApi){
+ // TODO: add service's description
+ function prepareRequestData(requestData, operation, reqString, subApi){
var preparedData = requestData;
- if(operation === 'GET'){
+ if (operation === 'GET'){
preparedData = null;
}
- else if(operation === 'POST'){
+ else if (operation === 'POST'){
return postRequestData(requestData, reqString, subApi);
}
return preparedData;
- };
+ }
- utils.prepareOperation = function(operation){
+ // TODO: add service's description
+ function prepareOperation(operation){
return operation === 'DELETE' ? 'REMOVE' : operation;
- };
+ }
+
+ // TODO: add service's description
+ function prepareHeaders(requestData){
+ return requestData === constants.NULL_DATA ?
+ { 'Content-Type': undefined } : { 'Content-Type': 'application/yang.data+json' };
+ }
+
+ // TODO: add function's description
+ function checkSupApiIdentifiers(subApi){
+ var pathElement = subApi.pathArray[subApi.pathArray.length - 1];
+ return pathElement.hasIdentifier() ? pathElement.identifiers : [];
+ }
+
+ // TODO: add function's description
+ function postRequestData(requestData, reqString, subApi){
+ var identifiersArray = checkSupApiIdentifiers(subApi);
+
+ if ( identifiersArray.length ) {
+ var pathArray = reqString.split('/'),
+ reqObj = null;
+
+ identifiersArray.forEach(function (){
+ pathArray.pop();
+ });
- utils.prepareHeaders = function(requestData){
- return requestData === constants.NULL_DATA ? { "Content-Type": undefined} : { "Content-Type": "application/yang.data+json"};
- };
+ reqString = pathArray.join('/');
+ var requestItem = requestData[lastPathElement(reqString)] ?
+ requestData[lastPathElement(reqString)].filter(function (item){
+ return identifiersArray.every(function (i){
+ return item[i.label] === i.value;
+ });
+ }) : [];
- utils.errorMessages = {
- 'method' :
- {
- 'GET': {
- '401':'YANGUI_ERROR_GET_401',
- '403':'YANGUI_ERROR_GET_403',
- '404':'YANGUI_ERROR_GET_404',
- '500':'YANGUI_ERROR_GET_500',
- '503':'YANGUI_ERROR_GET_503'
- },
- 'POST': {
- '500':'YANGUI_ERROR_GET_500',
- '503':'YANGUI_ERROR_GET_503'
- },
- 'PUT': {
- '500':'YANGUI_ERROR_GET_500',
- '503':'YANGUI_ERROR_GET_503'
- },
- 'DELETE': {
- '500':'YANGUI_ERROR_GET_500',
- '503':'YANGUI_ERROR_GET_503'
- }
+ return requestItem.length ? requestItem[0] : {};
+ } else {
+ return requestData[lastPathElement(reqString)];
}
- };
-
- utils.__test = {
- };
-
- return utils;
+ // TODO: add function's description
+ function lastPathElement(path){
+ return path.split('/').pop().split(':').pop();
+ }
+ }
}
- YangUtilsService.$inject=['YinParserService', 'NodeWrapperService', 'RequestBuilderService', 'SyncService', 'constants',
- 'ModuleConnectorService', 'YangUiApisService', 'EventDispatcherService', 'ApiBuilderService'];
+ YangUtilsService.$inject = ['YinParserService', 'NodeWrapperService', 'RequestBuilderService', 'SyncService',
+ 'constants', 'ModuleConnectorService', 'YangUiApisService', 'EventDispatcherService',
+ 'ApiBuilderService'];
return YangUtilsService;
-});
\ No newline at end of file
+});
'use strict';
function YinParserService($http, SyncService, constants, PathUtilsService, YangUiApisService, NodeUtilsService){
- var augmentType = 'augment';
- var path = './assets';
+ var augmentType = 'augment',
+ path = './assets',
+ service = {
+ parseYang: parseYang,
+ parseYangMP: parseYangMP,
+ Augmentations: Augmentations,
+ Module: Module,
+ yangParser: new YangParser(),
+ __test: {
+ path: path,
+ parentTag: parentTag,
+ yangParser: new YangParser(),
+ Augmentation: Augmentation,
+ Module: Module,
+ },
+ };
+
+ return service;
+
+ // TODO: add service's description
+ function parseYangMP(baseApiPath, name, rev, callback, errorCbk) {
+ var path = baseApiPath + '/' + name + '/' + rev + '/schema';
+
+ YangUiApisService.getSingleModuleInfo(path)
+ .then(function (data) {
+ if ($.parseXML(data) !== null) {
+ parseModule(data, callback);
+ } else {
+ loadStaticModule(name, callback, errorCbk);
+ }
+ }, function () {
+ loadStaticModule(name, callback, errorCbk);
+ });
+ }
+
+ // TODO: add service's description
+ function parseYang(name, rev, callback, errorCbk) {
+ YangUiApisService.getModuleSchema(name, rev).get()
+ .then(function (data) {
+ if ($.parseXML(data) !== null) {
+ parseModule(data, callback);
+ } else {
+ loadStaticModule(name, callback, errorCbk);
+ }
+ }, function () {
+ loadStaticModule(name, callback, errorCbk);
+ });
+ }
- var Module = function (name, revision, namespace) {
+ // TODO: add service's description
+ function parentTag(xml) {
+ if (xml.get(0).tagName.toLowerCase() === 'module') {
+ return xml.get(0);
+ } else {
+ return parentTag(xml.parent());
+ }
+ }
+
+ // TODO: add function's description
+ function parseModule(data, callback) {
+ var yangParser = new YangParser();
+
+ var moduleName = $($.parseXML(data).documentElement).attr('name'),
+ moduleNamespace = $($.parseXML(data)).find('namespace').attr('uri'),
+ moduleoduleRevision = $($.parseXML(data)).find('revision').attr('date'),
+ moduleObj = new Module(moduleName, moduleoduleRevision, moduleNamespace);
+
+ yangParser.setCurrentModuleObj(moduleObj);
+ yangParser.parse($.parseXML(data).documentElement, moduleObj);
+
+ yangParser.sync.waitFor(function () {
+ callback(moduleObj);
+ });
+ }
+
+ // TODO: add function's description
+ function loadStaticModule(name, callback, errorCbk) {
+ var yinPath = '/yang2xml/' + name + '.yang.xml';
+ $http.get(path + yinPath).success(function (data) {
+ console.warn('cannot load ' + name + 'from controller, trying loading from static storage');
+ parseModule(data, callback);
+ }).error(function () {
+ console.warn('cannot load file ' + yinPath + 'from static storage');
+ errorCbk();
+ return null;
+ });
+ }
+
+ /**
+ * Base Module object
+ * @param name
+ * @param revision
+ * @param namespace
+ * @constructor
+ */
+ function Module(name, revision, namespace) {
this._name = name;
this._revision = revision;
this._namespace = namespace;
var self = this;
return this.getRawAugments().map(function (augNode) {
- var prefixConverter = function (prefix) {
- var importNode = self.getImportByPrefix(prefix);
- return importNode ? importNode.label : null;
- },
- getDefaultModule = function() {
- return null;
- };
-
augNode.path = PathUtilsService.translate(augNode.pathString, prefixConverter, self._statements.import, getDefaultModule);
return new Augmentation(augNode);
+
+ // TODO: add function's description
+ function prefixConverter(prefix) {
+ var importNode = self.getImportByPrefix(prefix);
+ return importNode ? importNode.label : null;
+ }
+
+ // TODO: add function's description
+ function getDefaultModule() {
+ return null;
+ }
});
};
}
if (searchResults && searchResults.length === 0) {
- //console.warn('no nodes with type', type, 'and name', name, 'found in', this);
+ // console.warn('no nodes with type', type, 'and name', name, 'found in', this);
} else if (searchResults && searchResults.length > 1) {
- //console.warn('multiple nodes with type', type, 'and name', name, 'found in', this);
+ // console.warn('multiple nodes with type', type, 'and name', name, 'found in', this);
} else if (searchResults && searchResults.length === 1) {
searchedNode = searchResults[0];
}
return searchedNode;
};
- };
-
- var Node = function (id, name, type, module, namespace, parent, nodeType, moduleRevision) {
+ }
+
+ /**
+ * Base Node element object
+ * @param id
+ * @param name
+ * @param type
+ * @param module
+ * @param namespace
+ * @param parent
+ * @param nodeType
+ * @param moduleRevision
+ * @constructor
+ */
+ function Node(id, name, type, module, namespace, parent, nodeType, moduleRevision) {
this.id = id;
this.label = name;
this.localeLabel = constants.LOCALE_PREFIX + name.toUpperCase();
};
this.deepCopy = function deepCopy(additionalProperties) {
- var copy = new Node(this.id, this.label, this.type, this.module, this.namespace, null, this.nodeType, this.moduleRevision),
+ var copy = new Node(this.id, this.label, this.type, this.module, this.namespace, null,
+ this.nodeType, this.moduleRevision),
self = this;
additionalProperties = (additionalProperties || []).concat(['pathString']);
- additionalProperties.forEach(function(prop) {
+ additionalProperties.forEach(function (prop) {
if (prop !== 'children' && self.hasOwnProperty(prop) && copy.hasOwnProperty(prop) === false) {
copy[prop] = self[prop];
}
return copy;
};
- this.getCleanCopy = function(){
- return new Node(this.id, this.label, this.type, this.module, this.namespace, null, this.nodeType, this.moduleRevision);
+ this.getCleanCopy = function (){
+ return new Node(this.id, this.label, this.type, this.module, this.namespace, null,
+ this.nodeType, this.moduleRevision);
};
this.getChildren = function (type, name, nodeType, property) {
var filteredChildren = this.children.filter(function (item) {
- return (name != null ? name === item.label : true) && (type != null ? type === item.type : true) && (nodeType != null ? nodeType === item.nodeType : true);
+ return (name != null ? name === item.label : true) &&
+ (type != null ? type === item.type : true) &&
+ (nodeType != null ? nodeType === item.nodeType : true);
});
if (property) {
}
};
- };
+ }
-
-
- var AugmentationsGroup = function(){
+ /**
+ * Base Augment group object
+ * @constructor
+ */
+ function AugmentationsGroup(){
this.obj = {};
- this.addAugumentation = function(augumentation){
+ this.addAugumentation = function (augumentation){
this.obj[augumentation.id] = augumentation;
};
- };
+ }
- var Augmentations = function(){
+ /**
+ * Base augment's groups object
+ * @constructor
+ */
+ function Augmentations(){
this.groups = {};
- this.addGroup = function(groupId){
- this.groups[groupId] = !this.groups.hasOwnProperty(groupId) ? new AugmentationsGroup() : this.groups[groupId];
+ this.addGroup = function (groupId){
+ this.groups[groupId] = !this.groups.hasOwnProperty(groupId) ?
+ new AugmentationsGroup() : this.groups[groupId];
};
- this.getAugmentation = function(node, augId) {
- return this.groups[node.module + ':' + node.label] ? this.groups[node.module + ':' + node.label].obj[augId] : null;
+ this.getAugmentation = function (node, augId) {
+ return this.groups[node.module + ':' + node.label] ?
+ this.groups[node.module + ':' + node.label].obj[augId] : null;
};
- };
+ }
- var Augmentation = function (node) {
+ /**
+ * Base Augment object
+ * @param node
+ * @constructor
+ */
+ function Augmentation(node) {
var self = this;
this.node = node;
this.path = (node.path ? node.path : []);
this.id = node.module + ':' + node.label;
this.expanded = true;
// AUGMENT FIX
- //node.label = node.module + ':' + node.label;
+ // node.label = node.module + ':' + node.label;
this.toggleExpand = function () {
this.expanded = !this.expanded;
};
- this.setAugmentationGroup = function(targetNode, augumentations){
+ this.setAugmentationGroup = function (targetNode, augumentations){
var targetNodeId = targetNode.module + ':' + targetNode.label;
targetNode.augmentionGroups = targetNode.augmentionGroups ? targetNode.augmentionGroups : [];
targetNode.augmentionGroups.push(self.id);
};
this.getTargetNodeToAugment = function (nodeList) {
- return PathUtilsService.search({children: nodeList}, this.path.slice());
+ return PathUtilsService.search({ children: nodeList }, this.path.slice());
};
this.getPathString = function () {
}).join('/');
};
- };
-
- var parentTag = function (xml) {
- if (xml.get(0).tagName.toLowerCase() === 'module') {
- return xml.get(0);
- } else {
- return parentTag(xml.parent());
- }
- };
-
- var parseModule = function(data, callback) {
- var yangParser = new YangParser();
-
- var moduleName = $($.parseXML(data).documentElement).attr('name'),
- moduleNamespace = $($.parseXML(data)).find('namespace').attr('uri'),
- moduleoduleRevision = $($.parseXML(data)).find('revision').attr('date'),
- moduleObj = new Module(moduleName, moduleoduleRevision, moduleNamespace);
-
- yangParser.setCurrentModuleObj(moduleObj);
- yangParser.parse($.parseXML(data).documentElement, moduleObj);
-
- yangParser.sync.waitFor(function () {
- callback(moduleObj);
- });
- };
-
- var loadStaticModule = function(name, callback, errorCbk) {
- var yinPath = '/yang2xml/' + name + '.yang.xml';
- $http.get(path + yinPath).success(function(data) {
- console.warn('cannot load '+ name + 'from controller, trying loading from static storage');
- parseModule(data, callback);
- }).error(function() {
- console.warn('cannot load file '+ yinPath + 'from static storage');
- errorCbk();
- return null;
- });
- };
+ }
- var parseYangMP = function parseYangMP(baseApiPath, name, rev, callback, errorCbk) {
- var path = baseApiPath + '/' + name + '/' + rev + '/schema';
-
- YangUiApisService.getSingleModuleInfo(path).then(
- function (data) {
- if($.parseXML(data) !== null) {
- parseModule(data, callback);
- } else {
- loadStaticModule(name, callback, errorCbk);
- }
- }, function () {
- loadStaticModule(name, callback, errorCbk);
- }
- );
- };
-
- var parseYang = function parseYang(name, rev, callback, errorCbk) {
- YangUiApisService.getModuleSchema(name, rev).get().then(
- function (data) {
- if($.parseXML(data) !== null) {
- parseModule(data, callback);
- } else {
- loadStaticModule(name, callback, errorCbk);
- }
- }, function () {
- loadStaticModule(name, callback, errorCbk);
- }
- );
- };
-
- var YangParser = function () {
+ /**
+ * Base yang xml parser
+ * @constructor
+ */
+ function YangParser() {
this.rootNodes = [];
this.nodeIndex = 0;
this.sync = SyncService.generateObj();
});
};
- this.config = function(xml, parent) {
+ this.config = function (xml, parent) {
var type = 'config',
name = $(xml).attr('value'),
- nodeType = constants.NODE_ALTER,
- node = this.createNewNode(name, type, parent, nodeType);
+ nodeType = constants.NODE_ALTER;
+
+ this.createNewNode(name, type, parent, nodeType);
};
- this.presence = function(xml, parent) {
+ this.presence = function (xml, parent) {
var type = 'presence',
name = $(xml).attr('value'),
- nodeType = constants.NODE_ALTER,
- node = this.createNewNode(name, type, parent, nodeType);
+ nodeType = constants.NODE_ALTER;
+
+ this.createNewNode(name, type, parent, nodeType);
};
this.leaf = function (xml, parent) {
this.augment = function (xml, parent) {
var type = augmentType,
nodeType = constants.NODE_ALTER,
- augmentIndentifier = $(xml).children("ext\\:augment-identifier:first").attr("ext:identifier"),
+ augmentIndentifier = $(xml).children('ext\\:augment-identifier:first').attr('ext:identifier'),
name = augmentIndentifier ? augmentIndentifier : 'augment' + (this.nodeIndex + 1).toString(),
pathString = $(xml).attr('target-node'),
augmentRoot = this.createNewNode(name, type, parent, nodeType);
this.parse(xml, node);
};
- };
-
- return {
- parseYang: parseYang,
- parseYangMP: parseYangMP,
- yangParser: new YangParser(),
- Augmentations: Augmentations,
- Module: Module,
- __test: {
- path: path,
- parentTag: parentTag,
- yangParser: new YangParser(),
- Augmentation: Augmentation,
- Module: Module
- }
- };
+ }
}
- YinParserService.$inject=['$http','SyncService', 'constants', 'PathUtilsService', 'YangUiApisService', 'NodeUtilsService'];
+ YinParserService.$inject = ['$http', 'SyncService', 'constants', 'PathUtilsService', 'YangUiApisService',
+ 'NodeUtilsService'];
return YinParserService;
-});
\ No newline at end of file
+});
'common/yangutils/services/custom-funct.services',\r
];\r
\r
-var constants = [\r
+var constant = [\r
'common/yangutils/constants',\r
];\r
\r
-define(['angular'].concat(services).concat(constants),\r
- function(angular, NodeUtilsService, YangUtilsRestangularService, YangUtilsService, YinParserService, SyncService,\r
- PathUtilsService, ArrayUtilsService, YangUiApisService, NodeWrapperService, RequestBuilderService,\r
- RestrictionsService, TypeWrapperService, ListFilteringService, FilterNodeWrapperService, EventDispatcherService,\r
- ModuleConnectorService, ApiBuilderService, DataBackupService, ParsingJsonService, CustomFuncService,\r
- constants) {\r
+define(['angular'].concat(services).concat(constant),\r
+ function (angular, NodeUtilsService, YangUtilsRestangularService, YangUtilsService, YinParserService, SyncService,\r
+ PathUtilsService, ArrayUtilsService, YangUiApisService, NodeWrapperService, RequestBuilderService,\r
+ RestrictionsService, TypeWrapperService, ListFilteringService, FilterNodeWrapperService,\r
+ EventDispatcherService, ModuleConnectorService, ApiBuilderService, DataBackupService, ParsingJsonService,\r
+ CustomFuncService, constants) {\r
\r
- angular.module('app.common.yangUtils',[])\r
+ 'use strict';\r
+\r
+ angular.module('app.common.yangUtils', [])\r
.service('NodeUtilsService', NodeUtilsService)\r
.service('YangUtilsRestangularService', YangUtilsRestangularService)\r
.service('YangUtilsService', YangUtilsService)\r
\r
.constant('constants', constants);\r
\r
-});\r
+ });\r