Remove useless register implementation part 2 (DLUX internal Modules)
[dlux.git] / modules / flow-resources / src / main / resources / flow / flows.services.js
1 define(['app/flow/flows.module'], function(flows) {
2
3   flows.factory('FlowRestangular', function(Restangular, ENV) {
4     return Restangular.withConfig(function(RestangularConfig) {
5       RestangularConfig.setBaseUrl(ENV.getBaseURL("AD_SAL"));
6     });
7   });
8
9   flows.factory('FlowSvc', function (FlowRestangular) {
10     var svc = {
11       base: function (container) {
12         container = container || 'default';
13         return FlowRestangular.one('controller/nb/v2').one('flowprogrammer', container);
14       }
15     };
16
17     svc.delete = function(flowName, flowID, flowType) {
18       return svc.staticFlowUrl('default', flowType, flowID, flowName).remove();
19     };
20
21     svc.flowsUrl = function (container) {
22       return svc.base(container);
23     };
24
25     svc.nodeFlowsUrl = function (container, nodeType, nodeId) {
26       return svc.base(container).one('node', nodeType).one(nodeId);
27     };
28
29     svc.staticFlowUrl = function (container, nodeType, nodeId, name) {
30       return svc.base(container).one('node', nodeType).one(nodeId).one('staticFlow', name);
31     };
32
33     svc.getAll = function (container) {
34       return svc.flowsUrl(container).getList();
35
36     };
37
38     svc.itemData = function (i) {
39       return {
40         state: 'flow.detail',
41         name: i.name,
42         params: {nodeId: i.node.id, nodeType: i.node.type, flowName: i.name},
43       };
44     };
45
46     svc.itemsData = function (data_) {
47       var data = [];
48       angular.forEach(data_.flowConfig, function (value, key) {
49         data.push(svc.itemData(value));
50       });
51       return data;
52     };
53
54     return svc;
55   });
56
57 });