Skip to content

Commit

Permalink
III-6018 - Progress on loading query form url params inside modal
Browse files Browse the repository at this point in the history
  • Loading branch information
brampauwelyn committed Mar 5, 2024
1 parent ad00c6f commit 80ce5a6
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 7 deletions.
86 changes: 84 additions & 2 deletions dist/udb3-angular.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions dist/udb3-angular.min.js

Large diffs are not rendered by default.

72 changes: 72 additions & 0 deletions src/search/components/query-editor.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,78 @@ function QueryEditorController(
]
};
};

console.log('queryFields', queryFields);

qe.groupedQueryTree = searchHelper.getQueryTree() || qe.getDefaultQueryTree();

// init query modal?
var queryString = window.location.search;
console.log('queryString', queryString);
console.log('queryBuilder', queryBuilder);
/* jshint ignore:start */
var urlParams = new URLSearchParams(queryString);
console.log('urlParams', urlParams);
var currentQuery = {};
currentQuery.queryString = urlParams.get('query');
console.log('currentQuery', currentQuery);
var initialQuery = queryBuilder.parseQueryString(currentQuery);
console.log('initialQuery', initialQuery);
var root = qe.groupedQueryTree;
console.log('old root', root);

var groups = queryBuilder.groupQueryTree(initialQuery);
console.log('initialGroups', groups);
console.log('fieldTypeTransformers', fieldTypeTransformers);

var newGroupNodes = groups.nodes.map(function(group) {
group.nodes = group.nodes.map(function(node) {
const foundQueryField = queryFields.find(function(queryField) {
return queryField.field === node.field;
});
if (foundQueryField) {
node.name = foundQueryField.name;
node.type = foundQueryField.type;

// TODO this could probably be done better
var foundQueryKey = Object.keys(initialQuery).find(function(key) {
return initialQuery[key].field === node.field &&
initialQuery[key].term === node.term &&
typeof initialQuery[key].transformer === 'string';
})

console.log('foundObjectInQuery', foundQueryKey);

node.transformer = foundQueryKey && initialQuery[foundQueryKey].transformer ?
initialQuery[foundQueryKey].transformer :
_.first(fieldTypeTransformers[foundQueryField.type]);
// node.transformer = node.transformer ? node.transformer : '+';
}
return node;
})
return group;
});

console.log('newGroupNodes', newGroupNodes);
// var group = {
// type: 'group',
// operator: initialQuery.operator,
// nodes: [
// {
// field: initialQuery.left.field,
// name: 'title',
// term: initialQuery.left.term,
// fieldType: 'tokenized-string',
// transformer: '+'
// }
// ]
// };
// root.nodes.push(group);

root.nodes = newGroupNodes;

/* jshint ignore:end */

// Holds options for both term and choice query-field types
qe.transformers = {};
qe.termOptions = _.groupBy(taxonomyTerms, function (term) {
Expand Down Expand Up @@ -233,6 +303,8 @@ function QueryEditorController(
]
};

console.log('subgroup', group);

parentGroup.nodes.splice(fieldIndex + 1, 0, group);
};

Expand Down
8 changes: 8 additions & 0 deletions src/search/services/query-builder.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ function LuceneQueryBuilder(LuceneQueryParser, QueryTreeValidator, QueryTreeTran
};

this.parseQueryString = function (query) {
console.log('parse query', query);
try {
query.queryTree = LuceneQueryParser.parse(query.queryString);
} catch (e) {
console.log('e', e);
query.errors.push(e.message);
}

Expand All @@ -44,6 +46,7 @@ function LuceneQueryBuilder(LuceneQueryParser, QueryTreeValidator, QueryTreeTran
* @param {string} queryString
*/
this.createQuery = function (queryString) {
console.log('createQuery', queryString);
var query = {
originalQueryString: queryString,
queryString: queryString,
Expand Down Expand Up @@ -330,7 +333,10 @@ function LuceneQueryBuilder(LuceneQueryParser, QueryTreeValidator, QueryTreeTran
*
* @return {object} - A grouped field information tree
*/

// probably use this?
this.groupQueryTree = function (queryTree) {
console.log('in group query tree?');
var groupedFieldTree = {
type: 'root',
nodes: [],
Expand All @@ -354,6 +360,7 @@ function LuceneQueryBuilder(LuceneQueryParser, QueryTreeValidator, QueryTreeTran
};
groupedFieldTree.nodes.push(group);
} else {
console.log('in else of groupQueryTree');
this.groupNode(queryTree, groupedFieldTree);
this.cleanUpGroupedFieldTree(groupedFieldTree);
}
Expand Down Expand Up @@ -510,6 +517,7 @@ function LuceneQueryBuilder(LuceneQueryParser, QueryTreeValidator, QueryTreeTran
* @param {object} [fieldGroup] - Keeps track of the current field group
*/
this.groupNode = function (branch, fieldTree, fieldGroup) {
console.log('in group node');
// if the operator is implicit, you're dealing with grouped terms eg: field:(term1 term2)
if (branch.operator === implicitToken) {
branch.operator = 'OR';
Expand Down
3 changes: 3 additions & 0 deletions src/search/services/search-helper.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function SearchHelper(LuceneQueryBuilder, $rootScope) {
var queryTree = null;

this.clearQueryTree = function () {
console.log('clearQueryTree');
queryTree = null;
};

Expand All @@ -43,6 +44,7 @@ function SearchHelper(LuceneQueryBuilder, $rootScope) {
};

this.setQueryTree = function (groupedQueryTree) {
console.log('setQueryTree', groupedQueryTree);
var queryString = LuceneQueryBuilder.unparseGroupedTree(groupedQueryTree);
var newQuery = LuceneQueryBuilder.createQuery(queryString);
LuceneQueryBuilder.isValid(newQuery);
Expand All @@ -61,6 +63,7 @@ function SearchHelper(LuceneQueryBuilder, $rootScope) {
};

this.getQueryTree = function () {
console.log('getQueryTree?');
return angular.copy(queryTree);
};
}

0 comments on commit 80ce5a6

Please sign in to comment.