diff --git a/custom-recipes/pi-system-af-tree/recipe.py b/custom-recipes/pi-system-af-tree/recipe.py index ed4c7fd..a2d954f 100644 --- a/custom-recipes/pi-system-af-tree/recipe.py +++ b/custom-recipes/pi-system-af-tree/recipe.py @@ -42,6 +42,7 @@ def next_tree_item(tree_data): logger.info("Initialization with config config={}".format(logger.filter_secrets(config))) auth_type, username, password, server_url, is_ssl_check_disabled = get_credentials(config) +is_ssl_check_disabled = config.get("is_ssl_check_disabled", False) # Because no advanced parameter switch network_timer = PerformanceTimer() processing_timer = PerformanceTimer() diff --git a/js/pi-system_treecontroller.js b/js/pi-system_treecontroller.js index 09c97d8..df033fa 100644 --- a/js/pi-system_treecontroller.js +++ b/js/pi-system_treecontroller.js @@ -1,113 +1,162 @@ var app = angular.module('piSystemTreeApp.module', []); -app.service('TreeDataService', function() { +app.service('TreeDataService', function () { // This will store the shared tree data this.treeData = []; // Optional: helper methods - this.setTreeData = function(data) { + this.setTreeData = function (data) { this.treeData = data; }; - this.getTreeData = function() { + this.getTreeData = function () { return this.treeData; }; }); app.controller('AfExplorerFormCtrl', [ - '$scope', - '$stateParams', - 'CodeMirrorSettingService', - 'TreeDataService', - function($scope, $stateParams, CodeMirrorSettingService, TreeDataService) { - + '$scope', + '$stateParams', + 'CodeMirrorSettingService', + 'TreeDataService', + function ($scope, $stateParams, CodeMirrorSettingService, TreeDataService) { + $scope.paramDesc = { 'parameterSetId': 'basic-auth', 'mandatory': true }; - + $scope.treeData = TreeDataService.getTreeData(); $scope.config.attributeList = $scope.config.attributeList || []; $scope.config.selectedAttributes = $scope.config.selectedAttributes || []; - + $scope.editorOptions = CodeMirrorSettingService.get("text/plain"); - $scope.init = function() { - DataikuAPI.plugins.listAccessiblePresets('pi-system', $stateParams.projectKey, 'basic-auth').success(function (data) { - $scope.inlineParams = data.inlineParams; - $scope.inlinePluginParams = data.inlinePluginParams; - $scope.accessiblePresets = []; - if (data.definableInline) { - $scope.accessiblePresets.push({ - name:"INLINE", - label:"Manually defined", usable:true, - description: "Define values for these parameters" - }); - } - data.presets.forEach(function(p) { - $scope.accessiblePresets.push({name:"PRESET " + p.name, label:p.name, usable:p.usable, description:p.description}); - }); - $scope.accessibleParameterSetDescriptions = $scope.accessiblePresets.map(function(p) { - return p.description || 'No description'; - }); - }).error(setErrorInScope.bind($scope.errorScope)); + $scope.init = function () { + DataikuAPI.plugins.listAccessiblePresets('pi-system', $stateParams.projectKey, 'basic-auth').success(function (data) { + $scope.inlineParams = data.inlineParams; + $scope.inlinePluginParams = data.inlinePluginParams; + $scope.accessiblePresets = []; + if (data.definableInline) { + $scope.accessiblePresets.push({ + name: "INLINE", + label: "Manually defined", usable: true, + description: "Define values for these parameters" + }); + } + data.presets.forEach(function (p) { + $scope.accessiblePresets.push({ name: "PRESET " + p.name, label: p.name, usable: p.usable, description: p.description }); + }); + $scope.accessibleParameterSetDescriptions = $scope.accessiblePresets.map(function (p) { + return p.description || 'No description'; + }); + }).error(setErrorInScope.bind($scope.errorScope)); + if ($scope.authConfigured() === true) { + $scope.authSectionVisible = false; + $scope.showTreeData = true; + } + $scope.config.template = $scope.config.template || "-- Any --"; }; - - $scope.getServers = function(){ - $scope.callPythonDo({parameterName: "server_name"}).then(function(data){ + + $scope.getServers = function () { + $scope.callPythonDo({ parameterName: "server_name" }).then(function (data) { $scope.server_name = data.choices; }); }; - $scope.getDatabases = function() { - $scope.callPythonDo({parameterName: "database_name"}).then(function(data){ + $scope.getDatabases = function () { + $scope.callPythonDo({ parameterName: "database_name" }).then(function (data) { $scope.database_name = data.choices; }); }; - - $scope.initializeTree = function(){ - console.log("initialization: "); - console.log($scope.config.treeData); - if (!$scope.config.treeData || $scope.config.treeData.length === 0){ - $scope.callPythonDo({method: "get_children_from_db", parent: $scope.config.database_name}).then(function(data){ + + $scope.authSectionVisible = $scope.authSectionVisible || true; + + $scope.toggleAuthSection = function () { + $scope.authSectionVisible = !$scope.authSectionVisible; + }; + + $scope.authConfigured = function () { + console.log('authConfigured check'); + return $scope.hasPreset() && $scope.config.database_name && $scope.config.database_name.length > 0 && $scope.config.server_name && $scope.config.server_name.length > 0; + } + $scope.explore = function () { + console.log("coucou"); + if ($scope.authConfigured()) { + console.log("here"); + $scope.showTreeData = true; + } + }; + + $scope.hasPreset = function () { + return $scope.config.credentials && $scope.config.credentials.mode && $scope.config.credentials.mode !== 'NONE' && $scope.config.credentials.name + } + + $scope.initializeTree = function () { + console.log("initialization: "); + console.log($scope.config.treeData); + if (!$scope.config.treeData || $scope.config.treeData.length === 0) { + $scope.callPythonDo({ method: "get_children_from_db", parent: $scope.config.database_name }).then(function (data) { console.log("ALX:data2=" + JSON.stringify(data)); TreeDataService.setTreeData(data.choices); - $scope.config.treeData = TreeDataService.getTreeData(); - }); - } + $scope.config.treeData = TreeDataService.getTreeData(); + }); + } }; - - $scope.getChildrenFromDB = function(item){ - console.log("ALX:gcfd:" + JSON.stringify(item)); - return $scope.callPythonDo({ method: "get_children_from_db", parent: item }) - .then(function (data) { - console.log("ALX:data1=" + JSON.stringify(data)); - item.children = data.choices; - item.children.forEach(child => { - child.expanded = false; + + $scope.getChildrenFromDB = function (item) { + console.log("ALX:gcfd:" + JSON.stringify(item)); + return $scope.callPythonDo({ method: "get_children_from_db", parent: item }) + .then(function (data) { + console.log("ALX:data1=" + JSON.stringify(data)); + item.children = data.choices; + item.children.forEach(child => { + child.expanded = false; + }); + console.log(item); + return item; }); - console.log(item); - return item; + } + + $scope.getTemplatesFromDB = function () { + $scope.callPythonDo({ method: "get_templates_from_db" }).then(function (data) { + $scope.config.templates = data.choices; }); - } - - - // Toggle récursif des checkboxes - $scope.toggleChildren = function(node) { - console.log("ALX:tc:" + JSON.stringify(node)); - node.expanded = !node.expanded; - $scope.getChildrenFromDB(node); - if (node.children && node.children.length) { - node.children.forEach(function(child) { - child.expanded = !child.expanded; - $scope.getChildrenFromDB(child); + } + + $scope.activeTab = 'element'; // tab par défaut + + $scope.setTab = function(tab) { + $scope.activeTab = tab; + }; + + $scope.getCategoriesFromDB = function () { + $scope.config.attribute_categories = []; + $scope.config.element_categories = []; + $scope.callPythonDo({ method: "get_attribute_categories_from_db" }).then(function (data) { + $scope.config.attribute_categories = data.choices; + }); + $scope.callPythonDo({ method: "get_element_categories_from_db" }).then(function (data) { + $scope.config.element_categories = data.choices; }); } - - }; - $scope.doSearch = function(element_name, attribute_name){ - $scope.callPythonDo({method: "do_search", element_name: element_name, attribute_name: attribute_name, root_tree: $scope.config.treeData}).then( - function(data){ + // Toggle récursif des checkboxes + $scope.toggleChildren = function (node) { + console.log("ALX:tc:" + JSON.stringify(node)); + node.expanded = !node.expanded; + $scope.getChildrenFromDB(node); + if (node.children && node.children.length) { + node.children.forEach(function (child) { + child.expanded = !child.expanded; + $scope.getChildrenFromDB(child); + }); + } + + }; + + $scope.doSearch = function (element_name, attribute_name) { + $scope.callPythonDo({ method: "do_search", element_name: element_name, attribute_name: attribute_name, root_tree: $scope.config.treeData }).then( + function (data) { TreeDataService.setTreeData(data.choices); $scope.config.treeData = TreeDataService.getTreeData(); $scope.config.attributeList = data.attributes; @@ -116,101 +165,111 @@ app.controller('AfExplorerFormCtrl', [ ); }; - $scope.updateAttributeToOutput = function (attribute) { - if (attribute.checked && $scope.config.selectedAttributes.includes(attribute)) { - $scope.config.selectedAttributes = $scope.config.selectedAttributes.filter(attr => attr.path !== attribute.path); - } - else { - console.log("Adding attribute to output:", attribute); - - if (!$scope.config || !$scope.config.attributeList || $scope.config.selectedAttributes.includes(attribute)) { - return; + $scope.updateAttributeToOutput = function (attribute) { + if (attribute.checked && $scope.config.selectedAttributes.includes(attribute)) { + $scope.config.selectedAttributes = $scope.config.selectedAttributes.filter(attr => attr.path !== attribute.path); } - const attrInConfig = $scope.config.attributeList.find(attr => attr.path === attribute.path); + else { + console.log("Adding attribute to output:", attribute); - if (attrInConfig) { - $scope.config.selectedAttributes.push(attribute); - attrInConfig.checked = true; - } else { - console.warn("Attribute not found in config:", attribute.path); + if (!$scope.config || !$scope.config.attributeList || $scope.config.selectedAttributes.includes(attribute)) { + return; + } + const attrInConfig = $scope.config.attributeList.find(attr => attr.path === attribute.path); + + if (attrInConfig) { + $scope.config.selectedAttributes.push(attribute); + attrInConfig.checked = true; + } else { + console.warn("Attribute not found in config:", attribute.path); + } } - } - }; + }; -$scope.displayAttributes = function(node) { + $scope.displayAttributes = function (node) { - if (!node.children || node.children.length === 0) { + if (!node.children || node.children.length === 0) { $scope.getChildrenFromDB(node).then(newNode => { - processNode(newNode); + processNode(newNode); }); - } else { + } else { processNode(node); - }; - } + }; + } -function processNode(node) { - $scope.config.attributeList = []; - $scope.config.selectedAttributes = []; - node.children.forEach(child => { + function processNode(node) { + if (node.title !== $scope.config.element_name) { + $scope.config.element_name = ""; + } + $scope.config.attributeList = []; + $scope.config.selectedAttributes = []; + node.children.forEach(child => { if (child.type === "attribute") { - $scope.config.attributeList.push({ - "name": child.title, - "path": child.path - }); + $scope.config.attributeList.push({ + "title": child.title, + "path": child.path, + "description": child.description + }); } - }); -} + }); + } -}]); + }]); -app.directive('treeNode', function() { +app.directive('treeNode', function () { return { restrict: 'E', - scope: { node: '=' }, + scope: { + node: '=', // mutable object (tree structure changes) + getChildrenFromDB: '<', // function reference + displayAttributes: '<', // function reference + config: '<' // read/write nested properties only + }, + template: `
- - - - - -
- - {{ node.title }} + + {{ node.title }} +
-
-