aboutsummaryrefslogtreecommitdiffstats
path: root/ui/imports/ui/lib/environment-tree-node-behavior.js
blob: 12f0407a4d2e601c267d9d70f9423083e2c331d5 (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
import { Inventory } from '/imports/api/inventories/inventories';

export let EnvironmentTreeNodeBehavior = {
  subscribeGetChildrenFn: function (instance, env) {
    instance.subscribe('inventory.children',
      env.name, env.type, null, env.name);
  },

  subscribeGetFirstChildFn: function (instance, env) {
    instance.subscribe('inventory.first-child', 
      env.name, env.type, null, env.name);
  },

  getChildrenFn: function (env) {
    let query = {
      $or: [{
        parent_id: env.name,
        parent_type: env.type,
        environment: env.name,
        show_in_tree: true
      }]
    };

    return Inventory.find(query);
  },

  hasChildrenFn: function (env) {
    let query = {
      $or: [
        {
          parent_id: env.name
        }
      ]
    };

    return Inventory.find(query).count() > 0;
  }
};