From b88c78e3cf2bef22aa2f1c4d0bf305e303bc15f0 Mon Sep 17 00:00:00 2001 From: Koren Lev Date: Thu, 27 Jul 2017 16:42:15 +0300 Subject: adding calipso ui Change-Id: Ifa6f63daebb07f45580f747341960e898fdb00c4 Signed-off-by: Koren Lev --- .../ui/lib/environment-tree-node-behavior.js | 46 +++++++++++++++ ui/imports/ui/lib/input-model.js | 31 ++++++++++ ui/imports/ui/lib/inventory-tree-node-behavior.js | 66 ++++++++++++++++++++++ ui/imports/ui/lib/select-model.js | 31 ++++++++++ 4 files changed, 174 insertions(+) create mode 100644 ui/imports/ui/lib/environment-tree-node-behavior.js create mode 100644 ui/imports/ui/lib/input-model.js create mode 100644 ui/imports/ui/lib/inventory-tree-node-behavior.js create mode 100644 ui/imports/ui/lib/select-model.js (limited to 'ui/imports/ui/lib') diff --git a/ui/imports/ui/lib/environment-tree-node-behavior.js b/ui/imports/ui/lib/environment-tree-node-behavior.js new file mode 100644 index 0000000..86286a4 --- /dev/null +++ b/ui/imports/ui/lib/environment-tree-node-behavior.js @@ -0,0 +1,46 @@ +///////////////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) and others / +// / +// All rights reserved. This program and the accompanying materials / +// are made available under the terms of the Apache License, Version 2.0 / +// which accompanies this distribution, and is available at / +// http://www.apache.org/licenses/LICENSE-2.0 / +///////////////////////////////////////////////////////////////////////////////////////// +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; + } +}; diff --git a/ui/imports/ui/lib/input-model.js b/ui/imports/ui/lib/input-model.js new file mode 100644 index 0000000..5a5be84 --- /dev/null +++ b/ui/imports/ui/lib/input-model.js @@ -0,0 +1,31 @@ +///////////////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) and others / +// / +// All rights reserved. This program and the accompanying materials / +// are made available under the terms of the Apache License, Version 2.0 / +// which accompanies this distribution, and is available at / +// http://www.apache.org/licenses/LICENSE-2.0 / +///////////////////////////////////////////////////////////////////////////////////////// +/* + * file: input-model.js + */ + +import * as R from 'ramda'; + +export const createInputArgs = function (params) { + let instance = Template.instance(); + + return { + value: params.hash.value, + type: params.hash.type, + placeholder: params.hash.placeholder, + disabled: params.hash.disabled, + setModel: function (value) { + let mainModel = instance.data.model; + let newMainModel = R.assoc(params.hash.key, value, mainModel); + if (instance.data.setModel) { + instance.data.setModel(newMainModel); + } + }, + }; +}; diff --git a/ui/imports/ui/lib/inventory-tree-node-behavior.js b/ui/imports/ui/lib/inventory-tree-node-behavior.js new file mode 100644 index 0000000..ecf9c60 --- /dev/null +++ b/ui/imports/ui/lib/inventory-tree-node-behavior.js @@ -0,0 +1,66 @@ +///////////////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) and others / +// / +// All rights reserved. This program and the accompanying materials / +// are made available under the terms of the Apache License, Version 2.0 / +// which accompanies this distribution, and is available at / +// http://www.apache.org/licenses/LICENSE-2.0 / +///////////////////////////////////////////////////////////////////////////////////////// +import { Inventory } from '/imports/api/inventories/inventories'; +//import * as R from 'ramda'; + +export let InventoryTreeNodeBehavior = { + subscribeGetChildrenFn: function (instance, parent) { + instance.subscribe('inventory.children', + parent.id, parent.type, parent.name, parent.environment); + }, + + subscribeGetFirstChildFn: function (instance, parent) { + instance.subscribe('inventory.first-child', + parent.id, parent.type, parent.name, parent.environment); + }, + + getChildrenFn: function (parent) { + let query = { + $or: [{ + parent_id: parent.id, + parent_type: parent.type, + environment: parent.environment, + show_in_tree: true + }] + }; + + /* + if (R.equals('host_ref', parent.type)) { + let realParent = Inventory.findOne({ + name: parent.name, + environment: parent.environment, + type: 'host' + }); + + if (! R.isNil(realParent)) { + query = R.merge(query, { + $or: R.append({ + environment: parent.environment, + parent_id: realParent.id + }, query.$or) + }); + } + } + */ + + return Inventory.find(query); + }, + + hasChildrenFn: function (parent) { + let query = { + $or: [ + { + parent_id: parent._id + } + ] + }; + + return Inventory.find(query).count() > 0; + } +}; diff --git a/ui/imports/ui/lib/select-model.js b/ui/imports/ui/lib/select-model.js new file mode 100644 index 0000000..da553b5 --- /dev/null +++ b/ui/imports/ui/lib/select-model.js @@ -0,0 +1,31 @@ +///////////////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) and others / +// / +// All rights reserved. This program and the accompanying materials / +// are made available under the terms of the Apache License, Version 2.0 / +// which accompanies this distribution, and is available at / +// http://www.apache.org/licenses/LICENSE-2.0 / +///////////////////////////////////////////////////////////////////////////////////////// +import * as R from 'ramda'; + +export const createSelectArgs = function (params) { + let instance = Template.instance(); + + return { + values: params.hash.values, + type: params.hash.type, + placeholder: params.hash.placeholder, + options: params.hash.options, + multi: params.hash.multi ? params.hash.multi : false, + disabled: params.hash.disabled, + setModel: params.hash.setModel ? params.hash.setModel.fn : + function (values) { + let model = instance.data.model; + let newModel = R.assoc(params.hash.key, values, model); + if (instance.data.setModel) { + instance.data.setModel(newModel); + } + }, + showNullOption: R.isNil(params.hash.showNullOption) ? false : params.hash.showNullOption + }; +}; -- cgit 1.2.3-korg