From ea795bd1ab304cedfc63523b71ab735b7deaa1df Mon Sep 17 00:00:00 2001 From: Jan Forberg Date: Tue, 10 Oct 2023 15:34:29 +0200 Subject: [PATCH] fixed bug in facet sorting --- public/dist/main.js | 2 +- public/js/components/facets-view/facets-view.js | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/public/dist/main.js b/public/dist/main.js index 5b39a8d..b3fe23c 100644 --- a/public/dist/main.js +++ b/public/dist/main.js @@ -195,7 +195,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 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();\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 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?"); /***/ }), diff --git a/public/js/components/facets-view/facets-view.js b/public/js/components/facets-view/facets-view.js index 856304c..38eefc0 100644 --- a/public/js/components/facets-view/facets-view.js +++ b/public/js/components/facets-view/facets-view.js @@ -167,6 +167,7 @@ function FacetsViewController($http, $scope) { ctrl.viewModel[key].autofill.selectedValues = []; ctrl.viewModel[key].autofill.input = ''; + for (var v in facetData.values) { var value = facetData.values[v]; @@ -178,7 +179,18 @@ function FacetsViewController($http, $scope) { }); } - ctrl.viewModel[key].visibleFacetSettings.sort(); + ctrl.viewModel[key].visibleFacetSettings.sort(function(a, b) { + const valueA = a.value.toUpperCase(); + const valueB = b.value.toUpperCase(); + if (valueA > valueB) { + return 1; + } + if (valueA < valueB) { + return -1; + } + + return 0; + }); // Show latest versions first if(key == DatabusUris.DCT_HAS_VERSION) {