2 'common/yangutils/constants',
3 ], function (constants) {
6 angular.module('app.yangman').service('MountPointsConnectorService', MountPointsConnectorService);
8 MountPointsConnectorService.$inject = [
9 'YangUiApisService', 'NodeWrapperService',
10 'YangUtilsService', 'EventDispatcherService',
11 'YinParserService', 'PathUtilsService', 'YangUtilsRestangularService',
14 function MountPointsConnectorService(
15 YangUiApisService, NodeWrapperService,
16 YangUtilsService, EventDispatcherService,
17 YinParserService, PathUtilsService, YangUtilsRestangularService){
19 var mountPrefix = constants.MPPREFIX,
21 addPathElemsToPathArray: addPathElemsToPathArray,
22 alterMpPath: alterMpPath,
23 createCustomButton: createCustomButton,
24 createMPRootNode: createMPRootNode,
25 discoverMountPoints: discoverMountPoints,
26 getMPModulesAPI: getMPModulesAPI,
27 updateMountPointApis: updateMountPointApis,
32 // TODO: add service's description
33 function createMPRootNode(mpNodes) {
35 yangParser = YinParserService.yangParser;
37 yangParser.setCurrentModuleObj(new YinParserService.Module('yang-ext', null, null));
38 node = yangParser.createNewNode('mount', 'container', null, constants.NODE_UI_DISPLAY);
39 NodeWrapperService.wrapAll(node);
41 node.buildRequest = function (builder, req, module) {
43 builderNodes = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
45 if (builderNodes.length) {
46 builderNodes.forEach(function (child) {
47 var childAdded = child.buildRequest(builder, req, module);
54 node.fill = function (name, data) {
55 var nodesToFill = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
57 nodesToFill.forEach(function (child) {
58 var childFilled = child.fill(name, data);
63 mpNodes.forEach(function (mp){
70 // TODO: add service's description
71 function addPathElemsToPathArray(pathElems, pathArray, index) {
72 var updatedPath = pathArray.slice();
74 pathElems.forEach(function (pe, offset) {
75 // pe.disabled = true; //add disabled flag so user won't be able to change it in the UI
76 updatedPath.splice(index + offset, 0, pe);
82 // TODO: add service's description
83 function alterMpPath(path) {
84 var pathParts = path.split('/'),
85 restconfIndex = PathUtilsService.findIndexOfStrInPathStr(pathParts, 'restconf'),
86 mpIndex = PathUtilsService.findIndexOfStrInPathStr(pathParts, mountPrefix),
87 mpPath = path.slice(),
91 mpPathParts = pathParts.slice(mpIndex);
93 var unshiftIndex = restconfIndex !== -1 ? restconfIndex + 1 : 0;
95 mpPathParts.unshift(pathParts[unshiftIndex]);
96 mpPath = mpPathParts.join('/');
103 * function for adding path to mountpoint + yang:ext-mount to mount point patharray so the request string
104 * will be built correctly
105 * @param basePathArray
108 function updateMountPointApis(basePathArray, mpApis) {
109 var actualPath = basePathArray.slice(1); // we don't want to have config/operational storage in path
110 // actualPath.push(PathUtilsService.createPathElement(mountPrefix, null, null, false));
111 // we want to push yang-ext:mount to the path - not if we have yang-ext:mount rootNode
113 mpApis.forEach(function (api) {
114 api.subApis.forEach(function (subApi) {
115 subApi.pathArray = addPathElemsToPathArray(actualPath, subApi.pathArray, 1);
120 // TODO: add service's description
121 function getMPModulesAPI(api) {
122 var apiArray = api.split('/'),
123 yangExtMountStr = mountPrefix;
125 if (apiArray[apiArray.length - 1] !== yangExtMountStr) {
126 apiArray.push(yangExtMountStr);
129 return apiArray.slice(1).join('/');
132 // TODO: add service's description
133 function discoverMountPoints(api, getModulesCbk, callback) {
134 var modulesCbk = getModulesCbk || angular.noop,
136 baseApiPath = getMPModulesAPI(api),
142 YangUtilsRestangularService.setFullResponse(true);
144 time.started = new Date().getMilliseconds();
146 return YangUiApisService.getCustomModules(baseApiPath).then(
147 function (response) {
148 time.finished = new Date().getMilliseconds();
151 status: response.status,
152 statusText: response.statusText,
153 time: (time.finished - time.started),
156 YangUtilsService.processModulesMP(response.data.modules, baseApiPath, function (result, augments) {
157 EventDispatcherService.dispatch(constants.EV_SRC_MAIN, 'Linking modules to Apis');
158 var allRootNodes = result.map(function (node) {
159 var copy = node.deepCopy(['augmentionGroups', 'augmentationId']);
161 NodeWrapperService.wrapAll(copy);
165 var moduleNames = response.data.modules.module.map(function (m) {
169 allRootNodes.forEach(function (n) {
170 if (moduleNames.indexOf(n.module) > -1 && ['container', 'list'].indexOf(n.type) > -1) {
175 callback(mpNodes, augments, reqObj);
176 YangUtilsRestangularService.setFullResponse(false);
179 function (response) {
180 time.finished = new Date().getMilliseconds();
183 status: response.status,
184 statusText: response.statusText,
185 time: (time.finished - time.started),
188 callback([], [], reqObj);
189 YangUtilsRestangularService.setFullResponse(false);
193 // TODO: add service's description
194 function createCustomButton(label, show, click){