From da9e6fc8e0ee2254ac4e41d233fe89e3ffe1bf31 Mon Sep 17 00:00:00 2001 From: Jan Forberg Date: Wed, 31 Jan 2024 12:44:14 +0100 Subject: [PATCH] artifact facets fix --- public/dist/main.js | 2 +- .../js/components/facets-view/facets-view.js | 110 ++++++++++++++---- 2 files changed, 88 insertions(+), 24 deletions(-) diff --git a/public/dist/main.js b/public/dist/main.js index eb4aac3..724d8a0 100644 --- a/public/dist/main.js +++ b/public/dist/main.js @@ -205,7 +205,7 @@ eval("// hinzufügen eines Controllers zum Modul\nfunction ExpandableArrowContro \**************************************************/ /***/ ((module, __unused_webpack_exports, __webpack_require__) => { -eval("const QueryNode = __webpack_require__(/*! ../../query-builder/query-node */ \"./js/query-builder/query-node.js\");\nconst DatabusConstants = __webpack_require__(/*! ../../utils/databus-constants */ \"./js/utils/databus-constants.js\");\nconst DatabusUris = __webpack_require__(/*! ../../utils/databus-uris */ \"./js/utils/databus-uris.js\");\nconst DatabusUtils = __webpack_require__(/*! ../../utils/databus-utils */ \"./js/utils/databus-utils.js\");\n\n/**\n * Manages an array of facets with respect to a parent facets array.\n * Provides some convenient\\ce methods to write to the facets array and\n * read from the parents facets.\n * DO NOT change the parent facets array in here.\n */\nclass FacetSettings {\n\n /**\n * Locally manages a facets array with respect to a parent\n * facets array\n * @param {[type]} facets [description]\n * @param {[type]} parentFacets [description]\n */\n constructor(facets, parentFacets) {\n this.facets = facets;\n this.parentFacets = parentFacets;\n }\n\n /**\n * Change a setting (key, value) to a state (bool)\n * @param {[type]} key [description]\n * @param {[type]} value [description]\n * @param {[type]} setState [description]\n * @return {[type]} [description]\n */\n changeSetting(key, value, targetState) {\n var parentState = this.findParentSettingState(key, value);\n\n if (parentState != targetState) {\n this.createOrAddSetting(key, value, targetState);\n } else {\n this.removeSetting(key, value);\n }\n\n return targetState;\n }\n\n /**\n * Find the checked state specified in the parent setting array (if set)\n * based on a key and value\n * @param {[type]} key [description]\n * @param {[type]} value [description]\n * @return {[type]} [description]\n */\n findParentSettingState(key, value) {\n if (this.parentFacets == undefined) {\n return false;\n }\n\n for (var p in this.parentFacets) {\n var setting = this.parentFacets[p];\n if (setting.key == key && setting.value == value) {\n return setting.checked;\n }\n }\n\n return false;\n }\n\n findOwnSettingState(key, value) {\n for (var p in this.facets) {\n var setting = this.facets[p];\n if (setting.key == key && setting.value == value) {\n return setting.checked;\n }\n }\n\n return false;\n }\n\n isOverride(key, value, state) {\n var parentState = this.findParentSettingState(key, value);\n return parentState != state;\n }\n\n createOrAddSetting(key, value, state) {\n for (var p in this.facets) {\n var setting = this.facets[p];\n if (p == key && setting.value == value) {\n setting.checked = state;\n return;\n }\n }\n\n this.facets[key] = { value: value, checked: state };\n }\n\n removeSetting(key, value) {\n for (var p in this.facets) {\n var setting = this.facets[p];\n if (setting.key == key && setting.value == value) {\n this.facets.splice(p, 1);\n return;\n }\n }\n }\n\n}\n\nfunction FacetsViewController($http, $scope) {\n\n var ctrl = this;\n ctrl.$http = $http;\n ctrl.maxEntries = 6;\n\n ctrl.$onInit = function () {\n\n }\n\n ctrl.$onChanges = function () {\n // create the queries...\n ctrl.isLoading = true;\n\n // wrap the node in the query node class\n ctrl.node = QueryNode.createFrom(ctrl.node);\n ctrl.viewModel = {};\n\n if (ctrl.facets == undefined) {\n ctrl.facets = [];\n }\n\n var queryUri = ctrl.resourceType == 'version' ?\n ctrl.node.uri + '/' + ctrl.node.facetSettings[DatabusUris.DCT_HAS_VERSION][0].value\n : ctrl.node.uri;\n\n // Load the available resource facets\n // TODO: Remove resource type, can be derived from uri\n ctrl.$http.get('/app/utils/facets', {\n params: { uri: queryUri, type: ctrl.resourceType }\n }).then(function (result) {\n\n // Facets data has been loaded\n // Fix artifact facet values for groups\n if (ctrl.resourceType == 'group' && result.data[DatabusUris.DATABUS_ARTIFACT_PROPERTY] != undefined) {\n for (var i in result.data[DatabusUris.DATABUS_ARTIFACT_PROPERTY].values) {\n var value = result.data[DatabusUris.DATABUS_ARTIFACT_PROPERTY].values[i];\n result.data[DatabusUris.DATABUS_ARTIFACT_PROPERTY].values[i]\n = DatabusUtils.uriToName(value);\n }\n }\n\n // Facet setting in this view is\n\n // - SETTING\n // ---- VALUE\n // ---- IS_CHECKED\n\n // Prepare visible facet settings and autofill data based on the facet data returned by the API\n // Create key base entries (unset, not overriden)\n for (var key in result.data) {\n\n var facetData = result.data[key];\n\n // Create a view data object for each facet\n ctrl.viewModel[key] = {};\n ctrl.viewModel[key].key = key;\n ctrl.viewModel[key].label = facetData.label;\n ctrl.viewModel[key].visibleFacetSettings = [];\n ctrl.viewModel[key].autofill = {};\n ctrl.viewModel[key].autofill.values = facetData.values;\n ctrl.viewModel[key].autofill.selectedValues = [];\n ctrl.viewModel[key].autofill.input = '';\n\n\n for (var v in facetData.values) {\n\n var value = facetData.values[v];\n\n ctrl.viewModel[key].visibleFacetSettings.push({\n value: value,\n checked: false,\n isOverride: false\n });\n }\n\n ctrl.viewModel[key].visibleFacetSettings.sort(function(a, b) {\n const valueA = a.value.toUpperCase();\n const valueB = b.value.toUpperCase();\n if (valueA > valueB) {\n return 1;\n }\n if (valueA < valueB) {\n return -1;\n }\n\n return 0;\n });\n\n // Show latest versions first\n if(key == DatabusUris.DCT_HAS_VERSION) {\n ctrl.viewModel[key].visibleFacetSettings.reverse(); \n }\n\n // Only show the top few\n var length = ctrl.viewModel[key].visibleFacetSettings.length;\n ctrl.viewModel[key].visibleFacetSettings.length = Math.min(ctrl.maxEntries, length);\n }\n\n // If we show the browser for a version, remove the version facet\n if (ctrl.resourceType == 'version') {\n delete ctrl.viewModel[DatabusUris.DCT_HAS_VERSION];\n }\n\n // Add the \"Latest Version\" facet to the visible settings of the version facet\n if (ctrl.resourceType != 'version' && ctrl.viewModel[DatabusUris.DCT_HAS_VERSION] != undefined) {\n ctrl.viewModel[DatabusUris.DCT_HAS_VERSION].visibleFacetSettings.unshift({\n value: DatabusConstants.FACET_LATEST_VERSION_VALUE,\n checked: false,\n isOverride: false\n });\n\n // Apply the existing settings to the view model\n var fullFacets = ctrl.node.createFullFacetSettings();\n\n for (var key in fullFacets) {\n var facetSettingList = fullFacets[key];\n\n for (var i in facetSettingList) {\n var facetSetting = facetSettingList[i];\n\n var visibleFacetSetting = ctrl.getOrCreateVisibleFacetSetting(key, facetSetting.value);\n\n if (visibleFacetSetting != null) {\n visibleFacetSetting.checked = facetSetting.checked;\n visibleFacetSetting.isOverride = ctrl.node.isOverride(key, facetSetting.value, facetSetting.checked);\n }\n }\n }\n\n // If we're a group node, check for artifact nodes and add them as facets\n if (ctrl.resourceType == 'group') {\n for (var i in ctrl.node.childNodes) {\n var artifactNode = ctrl.node.childNodes[i];\n var facetValue = DatabusUtils.uriToName(artifactNode.uri)\n var visibleFacetSetting =\n ctrl.getOrCreateVisibleFacetSetting(DatabusUris.DATABUS_ARTIFACT_PROPERTY, facetValue);\n visibleFacetSetting.checked = true;\n visibleFacetSetting.isOverride = true;\n }\n\n if (ctrl.node.childNodes.length == 0) {\n\n // Add artifact nodes per default\n for (var v of ctrl.viewModel[DatabusUris.DATABUS_ARTIFACT_PROPERTY].visibleFacetSettings) {\n var childUri = ctrl.node.uri + '/' + v.value;\n var artifactNode = new QueryNode(childUri, 'databus:artifact');\n QueryNode.addChild(ctrl.node, artifactNode);\n }\n }\n }\n\n ctrl.onChange();\n ctrl.onLoaded();\n }\n\n ctrl.isLoading = false;\n });\n }\n\n ctrl.getFacetLabel = function (value) {\n if (value == DatabusConstants.FACET_LATEST_VERSION_VALUE) {\n return DatabusConstants.FACET_LATEST_VERSION_LABEL;\n }\n\n return value;\n }\n /**\n * Changes the value of a key value (also applies to facets)\n * @param {[type]} key [description]\n * @param {[type]} value [description]\n * @param {[type]} state [description]\n * @return {[type]} [description]\n */\n ctrl.changeFacetValueState = function (key, value, targetState) {\n\n if (ctrl.resourceType == 'group' && key == DatabusUris.DATABUS_ARTIFACT_PROPERTY) {\n\n var childUri = ctrl.node.uri + '/' + value;\n\n if (targetState) {\n var artifactNode = new QueryNode(childUri, 'databus:artifact');\n QueryNode.addChild(ctrl.node, artifactNode);\n } else {\n QueryNode.removeChildByUri(ctrl.node, childUri);\n }\n\n var visibleSetting = ctrl.getOrCreateVisibleFacetSetting(key, value);\n\n if (visibleSetting != null) {\n visibleSetting.checked = targetState;\n visibleSetting.isOverride = targetState;\n }\n }\n else {\n // apply change to view model\n ctrl.node.setFacet(key, value, targetState);\n\n var visibleSetting = ctrl.getOrCreateVisibleFacetSetting(key, value);\n\n if (visibleSetting != null) {\n visibleSetting.checked = targetState;\n visibleSetting.isOverride = ctrl.node.isOverride(key, value, targetState);\n }\n }\n\n if (ctrl.viewModel[key].autofill.selectedValues.length > 0) {\n ctrl.complete(ctrl.viewModel[key]);\n }\n\n ctrl.onChange();\n }\n\n /**\n * Gets or creates a new entry for a key value\n * for a given key and value\n * @param {[type]} key [description]\n * @param {[type]} value [description]\n * @return {[type]} [description]\n */\n ctrl.getOrCreateVisibleFacetSetting = function (key, value) {\n\n if (ctrl.viewModel[key] == undefined) {\n // This is a facet that the node does not have, but a parent has\n\n var label = DatabusUtils.uriToName(key);\n label = label[0].toUpperCase() + label.slice(1);\n\n ctrl.viewModel[key] = {};\n ctrl.viewModel[key].key = key;\n ctrl.viewModel[key].label = label;\n ctrl.viewModel[key].visibleFacetSettings = [];\n ctrl.viewModel[key].autofill = {};\n ctrl.viewModel[key].autofill.values = [];\n ctrl.viewModel[key].autofill.selectedValues = [];\n ctrl.viewModel[key].autofill.input = '';\n }\n\n for (var i in ctrl.viewModel[key].visibleFacetSettings) {\n var facetSetting = ctrl.viewModel[key].visibleFacetSettings[i];\n if (facetSetting.value == value) {\n return facetSetting; // ctrl.facetSettings[key];\n }\n }\n\n var visibleSetting = {\n value: value,\n };\n\n ctrl.viewModel[key].visibleFacetSettings.push(visibleSetting);\n return visibleSetting;\n }\n\n // Get all active facets of a certain key\n ctrl.getActiveFilters = function (key) {\n var activeFilters = [];\n\n for (var f in ctrl.facets[key].items) {\n var filter = ctrl.facets[key].items[f];\n if (filter.checked) {\n activeFilters.push(filter);\n }\n }\n\n return activeFilters;\n }\n\n // Checks whether any filter for a key is set\n ctrl.hasActiveFilters = function (key) {\n for (var f in ctrl.facets[key].items) {\n var filter = ctrl.facets[key].items[f];\n if (filter.checked) {\n return true;\n }\n }\n\n return false;\n }\n\n ctrl.complete = function (facetData) {\n facetData.autofill.selectedValues.length = 0;\n for (var a in facetData.autofill.values) {\n var e = facetData.autofill.values[a];\n if (e.toLowerCase().indexOf(facetData.autofill.input.toLowerCase()) >= 0) {\n\n var include = true;\n\n for (var v in facetData.visibleFacetSettings) {\n var visibleSettings = facetData.visibleFacetSettings[v];\n if (visibleSettings.value == e.toLowerCase()) {\n include = false;\n }\n }\n\n if (include) {\n facetData.autofill.selectedValues.push(e);\n }\n }\n }\n }\n\n // Clears the autofill lists\n ctrl.clearAutofill = function () {\n var self = ctrl;\n for (var f in self.viewModel) {\n var data = self.viewModel[f];\n data.autofill.selectedValues.length = 0;\n }\n }\n}\n\nmodule.exports = FacetsViewController;\n\n\n//# sourceURL=webpack://databus-webapp/./js/components/facets-view/facets-view.js?"); +eval("const QueryNode = __webpack_require__(/*! ../../query-builder/query-node */ \"./js/query-builder/query-node.js\");\nconst DatabusConstants = __webpack_require__(/*! ../../utils/databus-constants */ \"./js/utils/databus-constants.js\");\nconst DatabusUris = __webpack_require__(/*! ../../utils/databus-uris */ \"./js/utils/databus-uris.js\");\nconst DatabusUtils = __webpack_require__(/*! ../../utils/databus-utils */ \"./js/utils/databus-utils.js\");\n\n/**\n * Manages an array of facets with respect to a parent facets array.\n * Provides some convenient\\ce methods to write to the facets array and\n * read from the parents facets.\n * DO NOT change the parent facets array in here.\n */\nclass FacetSettings {\n\n /**\n * Locally manages a facets array with respect to a parent\n * facets array\n * @param {[type]} facets [description]\n * @param {[type]} parentFacets [description]\n */\n constructor(facets, parentFacets) {\n this.facets = facets;\n this.parentFacets = parentFacets;\n }\n\n /**\n * Change a setting (key, value) to a state (bool)\n * @param {[type]} key [description]\n * @param {[type]} value [description]\n * @param {[type]} setState [description]\n * @return {[type]} [description]\n */\n changeSetting(key, value, targetState) {\n var parentState = this.findParentSettingState(key, value);\n\n if (parentState != targetState) {\n this.createOrAddSetting(key, value, targetState);\n } else {\n this.removeSetting(key, value);\n }\n\n return targetState;\n }\n\n /**\n * Find the checked state specified in the parent setting array (if set)\n * based on a key and value\n * @param {[type]} key [description]\n * @param {[type]} value [description]\n * @return {[type]} [description]\n */\n findParentSettingState(key, value) {\n if (this.parentFacets == undefined) {\n return false;\n }\n\n for (var p in this.parentFacets) {\n var setting = this.parentFacets[p];\n if (setting.key == key && setting.value == value) {\n return setting.checked;\n }\n }\n\n return false;\n }\n\n findOwnSettingState(key, value) {\n for (var p in this.facets) {\n var setting = this.facets[p];\n if (setting.key == key && setting.value == value) {\n return setting.checked;\n }\n }\n\n return false;\n }\n\n isOverride(key, value, state) {\n var parentState = this.findParentSettingState(key, value);\n return parentState != state;\n }\n\n createOrAddSetting(key, value, state) {\n for (var p in this.facets) {\n var setting = this.facets[p];\n if (p == key && setting.value == value) {\n setting.checked = state;\n return;\n }\n }\n\n this.facets[key] = { value: value, checked: state };\n }\n\n removeSetting(key, value) {\n for (var p in this.facets) {\n var setting = this.facets[p];\n if (setting.key == key && setting.value == value) {\n this.facets.splice(p, 1);\n return;\n }\n }\n }\n\n}\n\nfunction FacetsViewController($http, $scope) {\n\n var ctrl = this;\n ctrl.$http = $http;\n ctrl.maxEntries = 6;\n\n ctrl.$onInit = function () {\n\n }\n\n ctrl.$onChanges = function () {\n // create the queries...\n ctrl.isLoading = true;\n\n // wrap the node in the query node class\n ctrl.node = QueryNode.createFrom(ctrl.node);\n\n // Holds the view state as json\n ctrl.viewModel = {};\n\n if (ctrl.facets == undefined) {\n ctrl.facets = [];\n }\n\n var queryUri = ctrl.resourceType == 'version' ?\n ctrl.node.uri + '/' + ctrl.node.facetSettings[DatabusUris.DCT_HAS_VERSION][0].value\n : ctrl.node.uri;\n\n // Load the available resource facets\n // TODO: Remove resource type, can be derived from uri\n ctrl.$http.get('/app/utils/facets', {\n params: { uri: queryUri, type: ctrl.resourceType }\n }).then(function (result) {\n\n // Facets data has been loaded\n ctrl.facetsData = result.data;\n\n // Fix artifact facet values for groups, change URIs into artifact names\n var artifactFacetData = ctrl.facetsData[DatabusUris.DATABUS_ARTIFACT_PROPERTY];\n\n if (artifactFacetData != null) {\n for (var i in artifactFacetData.values) {\n artifactFacetData.values[i] = DatabusUtils.uriToName(artifactFacetData.values[i]);\n }\n }\n\n // Facet setting in this view is\n\n // - SETTING\n // ---- VALUE\n // ---- IS_CHECKED\n\n // Prepare visible facet settings and autofill data based on the facet data returned by the API\n // Create key base entries (unset, not overriden)\n for (var key in ctrl.facetsData) {\n\n var facetData = ctrl.facetsData[key];\n\n // Create a view data object for each facet\n ctrl.viewModel[key] = {};\n ctrl.viewModel[key].key = key;\n ctrl.viewModel[key].label = facetData.label;\n ctrl.viewModel[key].visibleFacetSettings = [];\n ctrl.viewModel[key].autofill = {};\n ctrl.viewModel[key].autofill.values = facetData.values;\n ctrl.viewModel[key].autofill.selectedValues = [];\n ctrl.viewModel[key].autofill.input = '';\n\n\n for (var v in facetData.values) {\n var value = facetData.values[v];\n ctrl.viewModel[key].visibleFacetSettings.push({\n value: value,\n checked: false,\n isOverride: false\n });\n }\n\n ctrl.viewModel[key].visibleFacetSettings.sort(function (a, b) {\n const valueA = a.value.toUpperCase();\n const valueB = b.value.toUpperCase();\n if (valueA > valueB) {\n return 1;\n }\n if (valueA < valueB) {\n return -1;\n }\n\n return 0;\n });\n\n // Show latest versions first\n if (key == DatabusUris.DCT_HAS_VERSION) {\n ctrl.viewModel[key].visibleFacetSettings.reverse();\n }\n\n // Only show the top few\n var length = ctrl.viewModel[key].visibleFacetSettings.length;\n ctrl.viewModel[key].visibleFacetSettings.length = Math.min(ctrl.maxEntries, length);\n }\n\n // If we show the browser for a version, remove the version facet\n if (ctrl.resourceType == 'version') {\n delete ctrl.viewModel[DatabusUris.DCT_HAS_VERSION];\n }\n\n // Add the \"Latest Version\" facet to the visible settings of the version facet\n if (ctrl.resourceType != 'version' && ctrl.viewModel[DatabusUris.DCT_HAS_VERSION] != undefined) {\n ctrl.viewModel[DatabusUris.DCT_HAS_VERSION].visibleFacetSettings.unshift({\n value: DatabusConstants.FACET_LATEST_VERSION_VALUE,\n checked: false,\n isOverride: false\n });\n\n // Apply the existing settings to the view model\n var fullFacets = ctrl.node.createFullFacetSettings();\n\n for (var key in fullFacets) {\n var facetSettingList = fullFacets[key];\n\n for (var i in facetSettingList) {\n var facetSetting = facetSettingList[i];\n\n var visibleFacetSetting = ctrl.getOrCreateVisibleFacetSetting(key, facetSetting.value);\n\n if (visibleFacetSetting != null) {\n visibleFacetSetting.checked = facetSetting.checked;\n visibleFacetSetting.isOverride = ctrl.node.isOverride(key, facetSetting.value, facetSetting.checked);\n }\n }\n }\n\n // If we're a group node, check for artifact nodes and add them as facets\n if (ctrl.resourceType == 'group') {\n\n for (var i in ctrl.node.childNodes) {\n var artifactNode = ctrl.node.childNodes[i];\n var facetValue = DatabusUtils.uriToName(artifactNode.uri)\n var visibleFacetSetting =\n ctrl.getOrCreateVisibleFacetSetting(DatabusUris.DATABUS_ARTIFACT_PROPERTY, facetValue);\n visibleFacetSetting.checked = true;\n visibleFacetSetting.isOverride = true;\n }\n\n if (ctrl.node.childNodes.length == 0) {\n\n\n ctrl.updateArtifactFilters(ctrl.node);\n\n var artifactFacetData = ctrl.facetsData[DatabusUris.DATABUS_ARTIFACT_PROPERTY];\n\n if (artifactFacetData != null) {\n\n // Add artifact nodes \n for (var i in artifactFacetData.values) {\n artifactFacetData.values[i] = DatabusUtils.uriToName(artifactFacetData.values[i]);\n }\n }\n\n /*\n // Add artifact nodes per default\n for (var v of ctrl.viewModel[DatabusUris.DATABUS_ARTIFACT_PROPERTY].visibleFacetSettings) {\n var childUri = ctrl.node.uri + '/' + v.value;\n var artifactNode = new QueryNode(childUri, 'databus:artifact');\n QueryNode.addChild(ctrl.node, artifactNode);\n }*/\n\n\n }\n }\n\n ctrl.onChange();\n ctrl.onLoaded();\n }\n\n ctrl.isLoading = false;\n });\n }\n\n ctrl.updateArtifactFilters = function (groupNode) {\n\n // Clear all child nodes\n groupNode.childNodes.length = 0;\n\n var hasCheckedArtifactFacets = false;\n\n for (var setting of ctrl.viewModel[DatabusUris.DATABUS_ARTIFACT_PROPERTY].visibleFacetSettings) {\n hasCheckedArtifactFacets = hasCheckedArtifactFacets || setting.checked;\n }\n\n if (hasCheckedArtifactFacets) {\n\n for (var setting of ctrl.viewModel[DatabusUris.DATABUS_ARTIFACT_PROPERTY].visibleFacetSettings) {\n if (setting.checked) {\n var artifactUri = `${groupNode.uri}/${setting.value}`;\n if (QueryNode.findChildByUri(groupNode, artifactUri) == null) {\n var artifactNode = new QueryNode(artifactUri, 'databus:artifact');\n QueryNode.addChild(groupNode, artifactNode);\n }\n }\n }\n\n } else {\n\n var latestVersionSetting = QueryNode.findFacetSetting(groupNode,\n DatabusUris.DCT_HAS_VERSION,\n DatabusConstants.FACET_LATEST_VERSION_VALUE);\n\n if (latestVersionSetting != undefined && latestVersionSetting.checked) {\n\n var artifactFacetData = ctrl.facetsData[DatabusUris.DATABUS_ARTIFACT_PROPERTY];\n\n if (artifactFacetData != null) {\n\n // Add artifact nodes \n for (var value of artifactFacetData.values) {\n var artifactUri = `${groupNode.uri}/${value}`;\n if (QueryNode.findChildByUri(groupNode, artifactUri) == null) {\n var artifactNode = new QueryNode(artifactUri, 'databus:artifact');\n QueryNode.addChild(groupNode, artifactNode);\n }\n }\n\n }\n }\n }\n\n }\n\n\n ctrl.getFacetLabel = function (value) {\n if (value == DatabusConstants.FACET_LATEST_VERSION_VALUE) {\n return DatabusConstants.FACET_LATEST_VERSION_LABEL;\n }\n\n return value;\n }\n /**\n * Changes the value of a key value (also applies to facets)\n * @param {[type]} key [description]\n * @param {[type]} value [description]\n * @param {[type]} state [description]\n * @return {[type]} [description]\n */\n ctrl.changeFacetValueState = function (key, value, targetState) {\n\n if (ctrl.resourceType == 'group' && key == DatabusUris.DATABUS_ARTIFACT_PROPERTY) {\n\n var visibleSetting = ctrl.getOrCreateVisibleFacetSetting(key, value);\n\n if (visibleSetting != null) {\n visibleSetting.checked = targetState;\n visibleSetting.isOverride = targetState;\n }\n\n ctrl.updateArtifactFilters(ctrl.node);\n\n }\n else {\n // apply change to view model\n ctrl.node.setFacet(key, value, targetState);\n\n var visibleSetting = ctrl.getOrCreateVisibleFacetSetting(key, value);\n\n if (visibleSetting != null) {\n visibleSetting.checked = targetState;\n visibleSetting.isOverride = ctrl.node.isOverride(key, value, targetState);\n }\n }\n\n if (ctrl.viewModel[key].autofill.selectedValues.length > 0) {\n ctrl.complete(ctrl.viewModel[key]);\n }\n\n ctrl.onChange();\n }\n\n /**\n * Gets or creates a new entry for a key value\n * for a given key and value\n * @param {[type]} key [description]\n * @param {[type]} value [description]\n * @return {[type]} [description]\n */\n ctrl.getOrCreateVisibleFacetSetting = function (key, value) {\n\n if (ctrl.viewModel[key] == undefined) {\n // This is a facet that the node does not have, but a parent has\n\n var label = DatabusUtils.uriToName(key);\n label = label[0].toUpperCase() + label.slice(1);\n\n ctrl.viewModel[key] = {};\n ctrl.viewModel[key].key = key;\n ctrl.viewModel[key].label = label;\n ctrl.viewModel[key].visibleFacetSettings = [];\n ctrl.viewModel[key].autofill = {};\n ctrl.viewModel[key].autofill.values = [];\n ctrl.viewModel[key].autofill.selectedValues = [];\n ctrl.viewModel[key].autofill.input = '';\n }\n\n for (var i in ctrl.viewModel[key].visibleFacetSettings) {\n var facetSetting = ctrl.viewModel[key].visibleFacetSettings[i];\n if (facetSetting.value == value) {\n return facetSetting; // ctrl.facetSettings[key];\n }\n }\n\n var visibleSetting = {\n value: value,\n };\n\n ctrl.viewModel[key].visibleFacetSettings.push(visibleSetting);\n return visibleSetting;\n }\n\n // Get all active facets of a certain key\n ctrl.getActiveFilters = function (key) {\n var activeFilters = [];\n\n for (var f in ctrl.facets[key].items) {\n var filter = ctrl.facets[key].items[f];\n if (filter.checked) {\n activeFilters.push(filter);\n }\n }\n\n return activeFilters;\n }\n\n // Checks whether any filter for a key is set\n ctrl.hasActiveFilters = function (key) {\n for (var f in ctrl.facets[key].items) {\n var filter = ctrl.facets[key].items[f];\n if (filter.checked) {\n return true;\n }\n }\n\n return false;\n }\n\n ctrl.complete = function (facetData) {\n facetData.autofill.selectedValues.length = 0;\n for (var a in facetData.autofill.values) {\n var e = facetData.autofill.values[a];\n if (e.toLowerCase().indexOf(facetData.autofill.input.toLowerCase()) >= 0) {\n\n var include = true;\n\n for (var v in facetData.visibleFacetSettings) {\n var visibleSettings = facetData.visibleFacetSettings[v];\n if (visibleSettings.value == e.toLowerCase()) {\n include = false;\n }\n }\n\n if (include) {\n facetData.autofill.selectedValues.push(e);\n }\n }\n }\n }\n\n // Clears the autofill lists\n ctrl.clearAutofill = function () {\n var self = ctrl;\n for (var f in self.viewModel) {\n var data = self.viewModel[f];\n data.autofill.selectedValues.length = 0;\n }\n }\n}\n\nmodule.exports = FacetsViewController;\n\n\n//# sourceURL=webpack://databus-webapp/./js/components/facets-view/facets-view.js?"); /***/ }), diff --git a/public/js/components/facets-view/facets-view.js b/public/js/components/facets-view/facets-view.js index 38eefc0..318046a 100644 --- a/public/js/components/facets-view/facets-view.js +++ b/public/js/components/facets-view/facets-view.js @@ -119,6 +119,8 @@ function FacetsViewController($http, $scope) { // wrap the node in the query node class ctrl.node = QueryNode.createFrom(ctrl.node); + + // Holds the view state as json ctrl.viewModel = {}; if (ctrl.facets == undefined) { @@ -136,12 +138,14 @@ function FacetsViewController($http, $scope) { }).then(function (result) { // Facets data has been loaded - // Fix artifact facet values for groups - if (ctrl.resourceType == 'group' && result.data[DatabusUris.DATABUS_ARTIFACT_PROPERTY] != undefined) { - for (var i in result.data[DatabusUris.DATABUS_ARTIFACT_PROPERTY].values) { - var value = result.data[DatabusUris.DATABUS_ARTIFACT_PROPERTY].values[i]; - result.data[DatabusUris.DATABUS_ARTIFACT_PROPERTY].values[i] - = DatabusUtils.uriToName(value); + ctrl.facetsData = result.data; + + // Fix artifact facet values for groups, change URIs into artifact names + var artifactFacetData = ctrl.facetsData[DatabusUris.DATABUS_ARTIFACT_PROPERTY]; + + if (artifactFacetData != null) { + for (var i in artifactFacetData.values) { + artifactFacetData.values[i] = DatabusUtils.uriToName(artifactFacetData.values[i]); } } @@ -153,9 +157,9 @@ function FacetsViewController($http, $scope) { // Prepare visible facet settings and autofill data based on the facet data returned by the API // Create key base entries (unset, not overriden) - for (var key in result.data) { + for (var key in ctrl.facetsData) { - var facetData = result.data[key]; + var facetData = ctrl.facetsData[key]; // Create a view data object for each facet ctrl.viewModel[key] = {}; @@ -169,9 +173,7 @@ function FacetsViewController($http, $scope) { for (var v in facetData.values) { - var value = facetData.values[v]; - ctrl.viewModel[key].visibleFacetSettings.push({ value: value, checked: false, @@ -179,7 +181,7 @@ function FacetsViewController($http, $scope) { }); } - ctrl.viewModel[key].visibleFacetSettings.sort(function(a, b) { + ctrl.viewModel[key].visibleFacetSettings.sort(function (a, b) { const valueA = a.value.toUpperCase(); const valueB = b.value.toUpperCase(); if (valueA > valueB) { @@ -193,8 +195,8 @@ function FacetsViewController($http, $scope) { }); // Show latest versions first - if(key == DatabusUris.DCT_HAS_VERSION) { - ctrl.viewModel[key].visibleFacetSettings.reverse(); + if (key == DatabusUris.DCT_HAS_VERSION) { + ctrl.viewModel[key].visibleFacetSettings.reverse(); } // Only show the top few @@ -235,6 +237,7 @@ function FacetsViewController($http, $scope) { // If we're a group node, check for artifact nodes and add them as facets if (ctrl.resourceType == 'group') { + for (var i in ctrl.node.childNodes) { var artifactNode = ctrl.node.childNodes[i]; var facetValue = DatabusUtils.uriToName(artifactNode.uri) @@ -246,12 +249,28 @@ function FacetsViewController($http, $scope) { if (ctrl.node.childNodes.length == 0) { + + ctrl.updateArtifactFilters(ctrl.node); + + var artifactFacetData = ctrl.facetsData[DatabusUris.DATABUS_ARTIFACT_PROPERTY]; + + if (artifactFacetData != null) { + + // Add artifact nodes + for (var i in artifactFacetData.values) { + artifactFacetData.values[i] = DatabusUtils.uriToName(artifactFacetData.values[i]); + } + } + + /* // Add artifact nodes per default for (var v of ctrl.viewModel[DatabusUris.DATABUS_ARTIFACT_PROPERTY].visibleFacetSettings) { var childUri = ctrl.node.uri + '/' + v.value; var artifactNode = new QueryNode(childUri, 'databus:artifact'); QueryNode.addChild(ctrl.node, artifactNode); - } + }*/ + + } } @@ -263,6 +282,57 @@ function FacetsViewController($http, $scope) { }); } + ctrl.updateArtifactFilters = function (groupNode) { + + // Clear all child nodes + groupNode.childNodes.length = 0; + + var hasCheckedArtifactFacets = false; + + for (var setting of ctrl.viewModel[DatabusUris.DATABUS_ARTIFACT_PROPERTY].visibleFacetSettings) { + hasCheckedArtifactFacets = hasCheckedArtifactFacets || setting.checked; + } + + if (hasCheckedArtifactFacets) { + + for (var setting of ctrl.viewModel[DatabusUris.DATABUS_ARTIFACT_PROPERTY].visibleFacetSettings) { + if (setting.checked) { + var artifactUri = `${groupNode.uri}/${setting.value}`; + if (QueryNode.findChildByUri(groupNode, artifactUri) == null) { + var artifactNode = new QueryNode(artifactUri, 'databus:artifact'); + QueryNode.addChild(groupNode, artifactNode); + } + } + } + + } else { + + var latestVersionSetting = QueryNode.findFacetSetting(groupNode, + DatabusUris.DCT_HAS_VERSION, + DatabusConstants.FACET_LATEST_VERSION_VALUE); + + if (latestVersionSetting != undefined && latestVersionSetting.checked) { + + var artifactFacetData = ctrl.facetsData[DatabusUris.DATABUS_ARTIFACT_PROPERTY]; + + if (artifactFacetData != null) { + + // Add artifact nodes + for (var value of artifactFacetData.values) { + var artifactUri = `${groupNode.uri}/${value}`; + if (QueryNode.findChildByUri(groupNode, artifactUri) == null) { + var artifactNode = new QueryNode(artifactUri, 'databus:artifact'); + QueryNode.addChild(groupNode, artifactNode); + } + } + + } + } + } + + } + + ctrl.getFacetLabel = function (value) { if (value == DatabusConstants.FACET_LATEST_VERSION_VALUE) { return DatabusConstants.FACET_LATEST_VERSION_LABEL; @@ -281,21 +351,15 @@ function FacetsViewController($http, $scope) { if (ctrl.resourceType == 'group' && key == DatabusUris.DATABUS_ARTIFACT_PROPERTY) { - var childUri = ctrl.node.uri + '/' + value; - - if (targetState) { - var artifactNode = new QueryNode(childUri, 'databus:artifact'); - QueryNode.addChild(ctrl.node, artifactNode); - } else { - QueryNode.removeChildByUri(ctrl.node, childUri); - } - var visibleSetting = ctrl.getOrCreateVisibleFacetSetting(key, value); if (visibleSetting != null) { visibleSetting.checked = targetState; visibleSetting.isOverride = targetState; } + + ctrl.updateArtifactFilters(ctrl.node); + } else { // apply change to view model