aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wireless-transport/code-Carbon-SR1/apps/dlux/dlux-web/src/common/general/common.general.services.js
blob: 6529ceabee3b383e3b266ce292b2b956ad5ba788 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
define(['common/general/common.general.module'], function(general) {

  general.factory('GeneralRestangular', function(Restangular, ENV) {
    return Restangular.withConfig(function(RestangularConfig) {
      RestangularConfig.setBaseUrl(ENV.baseURL);
    });
  });


  general.factory('SwitchSvc', function (GeneralRestangular) {
    var svc = {
      base: function (container) {
        container = container || 'default';
        return GeneralRestangular.one('controller/nb/v2').one('switchmanager', container);
      },
      data: null
    };

    svc.delete = function(node) {
    /* console.log(node);
      return svc.nodeUrl('default', node.node.type, node.node.id).remove();*/
    };

    // URL for nodes
    svc.nodesUrl = function (container) {
      return svc.base(container).all('nodes');
    };

    // URL for a node
    svc.nodeUrl = function (container, type, id) {
      return svc.base(container).one('node', type).one(id);
    };

    svc.getAll = function (container) {
      return svc.nodesUrl(container).getList();
    };

    svc.getConnectorProperties = function (container, type, id) {
      return svc.nodeUrl(container, type, id).get();
    };

    svc.itemData = function (i) {
      return {
        state: 'node.detail',
        name: i.properties.description.value !== 'None' ? i.properties.description.value : i.node.type + '/' + i.node.id,
        params: {nodeId: i.node.id, nodeType: i.node.type}
      };
    };

    svc.itemsData = function (data_) {
      var data = [];

      angular.forEach(data_.nodeProperties, function (value, key) {
        data.push(svc.itemData(value));
      });

      return data;
    };

    return svc;
  });
});