2 'app/yangman/services/mount-points-connector.services',
3 ], function (yangman) {
6 angular.module('app.yangman').service('ymDisplayMountPoints', DisplayMountPoints);
8 DisplayMountPoints.$inject =
9 ['MountPointsConnectorService', '$timeout', 'YangUtilsService', '$filter', 'ApiBuilderService', 'constants'];
11 function DisplayMountPoints(
12 MountPointsConnectorService, $timeout, YangUtilsService, $filter, ApiBuilderService, constants) {
16 module: ['network-topology', 'opendaylight-inventory', 'network-topology', 'opendaylight-inventory'],
19 'operational/network-topology:network-topology/topology/{topology-id}/node/{node-id}/',
20 'operational/opendaylight-inventory:nodes/node/{id}/',
22 label: 'YANGMAN_CUST_MOUNT_POINTS',
23 hideButtonOnSelect: true,
24 getCallback: displayMountPointsCallback,
27 function displayMountPointsCallback(args) {
28 var controller = args.controller,
30 path = scope.selectedSubApi.buildApiRequestString();
32 scope.rootBroadcast(constants.YANGMAN_SET_LOADING_BOX, true, function () {
33 scope.setLeftPanel(0);
34 $timeout(function () {
35 MountPointsConnectorService.discoverMountPoints(path, getNodesMPData, createMPStructure);
40 * Get Mount point data from received raw data
44 function getNodesMPData(data) {
45 var node = data.node[0];
46 return node && node['netconf-node-inventory:initial-capability'] ?
47 node['netconf-node-inventory:initial-capability'].map(function (c) {
48 return c.slice(c.lastIndexOf(')') + 1);
52 // TODO :: description
53 function findFirstSubApiIndex(subApis) {
54 var firstConfigSubApiIndex = 0;
56 subApis.some(function (sa, index) {
57 var condition = sa.storage === constants.DATA_STORE_CONFIG;
59 firstConfigSubApiIndex = index;
64 return firstConfigSubApiIndex;
68 * Create base params for setup mount points in app
73 function createMPStructure(mpNodes, mpAugments, reqObj) {
75 var mpRootNode = MountPointsConnectorService.createMPRootNode(mpNodes),
76 mountPointApis = ApiBuilderService.processAllRootNodes([mpRootNode]),
77 // root node has isConfigStm undefined, we need to create root config SubApi by hand
78 // if we set the variable isConfigStm to true and then generate the subApis it will do it
79 // incorrectly because, the variable is inherited to children and we would malform the data
80 // we need just to get operational root subApi...
81 rootApi = mountPointApis[0],
82 rootOperSubApi = rootApi.subApis.filter(function (sa) {
83 return sa.pathTemplateString === 'yang-ext:mount/' && sa.storage === constants.DATA_STORE_OPERATIONAL;
87 var rootConfigSubApi = rootOperSubApi.clone(), // clone it and...
88 firstConfigSubApiIndex = findFirstSubApiIndex(rootApi.subApis);
89 // we need to find first index of config
90 // subApi - because generating treeApis depends on order
92 // set storage to config
93 rootConfigSubApi.storage = constants.DATA_STORE_CONFIG;
94 rootConfigSubApi.pathArray[0].name = constants.DATA_STORE_CONFIG;
96 // and add it to rest of the apis
97 rootApi.subApis.splice(firstConfigSubApiIndex, 0, rootConfigSubApi);
98 rootConfigSubApi.parent = rootApi;
101 var mountPointTreeApis = YangUtilsService.generateApiTreeData(mountPointApis),
102 pathItems = path.split('/');
104 MountPointsConnectorService.updateMountPointApis(scope.selectedSubApi.pathArray, mountPointApis);
106 // call initialization after necessary things are loaded
107 controller.initMountPoint(mountPointTreeApis, mountPointApis, mpAugments, reqObj);
110 constants.YANGMAN_SET_MODULE_LIST_TITLE,
111 pathItems[pathItems.length - 1] + ' [ ' + $filter('translate')(constants.YANGMAN_MOUNT_POINT) + ' ]'
114 controller.selectedPluginsButtons.push(
115 MountPointsConnectorService.createCustomButton(constants.YANGMAN_CANCEL_MP, function (){
116 return controller.selectedPlugin.label === constants.YANGMAN_CUST_MOUNT_POINTS;
119 controller.unsetPluginFunctionality();
124 $timeout(function (){
125 controller.selectedPlugin = null;
126 scope.rootBroadcast(constants.YANGMAN_SET_LOADING_BOX, false);
127 scope.rootBroadcast(constants.YANGMAN_SHOW_TOAST, constants.YANGMAN_NO_MOUNT_POINT);