mirror of
https://github.com/ansible/awx.git
synced 2026-05-06 08:57:35 -02:30
Dynamic search key examples
This commit is contained in:
@@ -16,6 +16,7 @@ class DjangoSearchModel {
|
|||||||
return relatedSearchField.replace(/\__search$/, "");
|
return relatedSearchField.replace(/\__search$/, "");
|
||||||
}
|
}
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.searchExamples = [];
|
||||||
this.related = _.map(relatedSearchFields, trimRelated);
|
this.related = _.map(relatedSearchFields, trimRelated);
|
||||||
// Remove "object" type fields from this list
|
// Remove "object" type fields from this list
|
||||||
for (var key in baseFields) {
|
for (var key in baseFields) {
|
||||||
@@ -27,5 +28,23 @@ class DjangoSearchModel {
|
|||||||
}
|
}
|
||||||
delete baseFields.url;
|
delete baseFields.url;
|
||||||
this.base = baseFields;
|
this.base = baseFields;
|
||||||
|
if(baseFields.id) {
|
||||||
|
this.searchExamples.push("id:>10");
|
||||||
|
}
|
||||||
|
// Loop across the base fields and try find one of type = string and one of type = datetime
|
||||||
|
let stringFound = false,
|
||||||
|
dateTimeFound = false;
|
||||||
|
|
||||||
|
_.forEach(baseFields, (value, key) => {
|
||||||
|
if(!stringFound && value.type === 'string') {
|
||||||
|
this.searchExamples.push(key + ":foobar");
|
||||||
|
stringFound = true;
|
||||||
|
}
|
||||||
|
if(!dateTimeFound && value.type === 'datetime') {
|
||||||
|
this.searchExamples.push(key + ":>=\"2000-01-01T00:00:00Z\"");
|
||||||
|
this.searchExamples.push(key + ":<2000-01-01");
|
||||||
|
dateTimeFound = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ export default ['$q', 'Rest', 'ProcessErrors', '$rootScope', 'Wait', 'DjangoSear
|
|||||||
let concated = '';
|
let concated = '';
|
||||||
angular.forEach(value, function(item){
|
angular.forEach(value, function(item){
|
||||||
if(item && typeof item === 'string') {
|
if(item && typeof item === 'string') {
|
||||||
item = item.replace(/"|'/g, "");
|
item = decodeURIComponent(item).replace(/"|'/g, "");
|
||||||
}
|
}
|
||||||
concated += `${key}=${item}&`;
|
concated += `${key}=${item}&`;
|
||||||
});
|
});
|
||||||
@@ -73,7 +73,7 @@ export default ['$q', 'Rest', 'ProcessErrors', '$rootScope', 'Wait', 'DjangoSear
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(value && typeof value === 'string') {
|
if(value && typeof value === 'string') {
|
||||||
value = value.replace(/"|'/g, "");
|
value = decodeURIComponent(value).replace(/"|'/g, "");
|
||||||
}
|
}
|
||||||
return `${key}=${value}&`;
|
return `${key}=${value}&`;
|
||||||
}
|
}
|
||||||
@@ -128,7 +128,7 @@ export default ['$q', 'Rest', 'ProcessErrors', '$rootScope', 'Wait', 'DjangoSear
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {[paramString] : valueString};
|
return {[paramString] : encodeURIComponent(valueString)};
|
||||||
},
|
},
|
||||||
// decodes a django queryset param into a ui smart-search tag or set of tags
|
// decodes a django queryset param into a ui smart-search tag or set of tags
|
||||||
decodeParam(value, key){
|
decodeParam(value, key){
|
||||||
@@ -164,7 +164,10 @@ export default ['$q', 'Rest', 'ProcessErrors', '$rootScope', 'Wait', 'DjangoSear
|
|||||||
decodedParam = '<=' + decodedParam;
|
decodedParam = '<=' + decodedParam;
|
||||||
split = split.splice(0, split.length-1);
|
split = split.splice(0, split.length-1);
|
||||||
}
|
}
|
||||||
return exclude ? `-${split.join('.')}:${decodedParam}` : `${split.join('.')}:${decodedParam}`;
|
|
||||||
|
let uriDecodedParam = decodeURIComponent(decodedParam);
|
||||||
|
|
||||||
|
return exclude ? `-${split.join('.')}:${uriDecodedParam}` : `${split.join('.')}:${uriDecodedParam}`;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -39,9 +39,7 @@
|
|||||||
<div class="SmartSearch-examples--title">
|
<div class="SmartSearch-examples--title">
|
||||||
<b translate>EXAMPLES:</b>
|
<b translate>EXAMPLES:</b>
|
||||||
</div>
|
</div>
|
||||||
<div class="SmartSearch-examples--search">name:foo</div>
|
<div class="SmartSearch-examples--search" ng-repeat="searchExample in model.searchExamples">{{searchExample}}</div>
|
||||||
<div class="SmartSearch-examples--search">organization.name:Default</div>
|
|
||||||
<div class="SmartSearch-examples--search">id:>10</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="SmartSearch-keyRow">
|
<div class="SmartSearch-keyRow">
|
||||||
|
|||||||
Reference in New Issue
Block a user