How do I load a MultiObjectPicker with valid States for a PortfolioItem type eg PortfolioItem/FEATURE - rally

I would like to load a MultiObjectPicker with valid States for a PortfolioItem type. I have tried with a custom query using TypeDef._refObjectName, but it does not filter the data.
var stateMultiObjectPicker = Ext.create('Rally.ui.picker.MultiObjectPicker', {
modelType: 'State',
storeConfig: {
fetch: "Name, TypeDef",
//customQuery: '(Name = "Done")', THIS WORKS
customQuery: '(TypeDef._refObjectName = "FEATURE")', // THIS DOES NOT
},
});
this.add(stateMultiObjectPicker);
Is there another way to do this? Any guidance will be appreciated!
Is there a way to use a store instead of a model in a MultiObjectPicker?

Problem solved by using:
customQuery: '(TypeDef.Name = "FEATURE")'

Related

How to use gt/le operator in aurelia slickgrid with Odata

I want to send my own operator in odata request and not use the aurelia slickgrid inbuilt "eq" operator.
This is my column definition
{
id: 'LockoutEndDateUtc', name: 'Status', field: 'LockoutEndDateUtc', minWidth: 85, maxWidth: 95,
type: FieldType.boolean,
sortable: true,
formatter: Formatters.multiple,
params: { formatters: [this.StatusFormatter, Formatters.checkmark] },
filterable: true,
filter: {
collection: [
{ value: 'le ' + (() => {const dt = new Date(); return dt.toISOString().split('.')[0] + "Z";})(), label: 'True' },
{ value: 'gt ' + (() => {const dt = new Date(); return dt.toISOString().split('.')[0] + "Z";})(), label: 'False' }
], //['', 'True', 'False'],
model: Filters.singleSelect,//multipleSelect//singleSelect,
}
}
This is the UI
This is how the request filter looks like..
$filter=(LockoutEndDateUtc%20eq%20le%202022-06-28T12%3A59%3A25Z)
If i remove %20eq from the above request, everything else works. So my question is how to i remove %20eq. Or how do i send my own gt, le in the request.
You can't really do that on a boolean filter (you could however do it on a date filter with operator) and I don't think I've added any ways to provide a custom filter search the way you want to do it, but since you're using OData, you have a bit more control and you could change the query string yourself. To be clear, it's not at all recommended to change the OData query string, it's a last solution trick and at your own risk, but for your use case it might be the only way to achieve what you want.
prepareGrid() {
this.gridOptions = {
// ...
backendServiceApi: {
service: new GridOdataService(),
process: (query) => this.getCustomerApiCall(query),
} as OdataServiceApi
};
}
}
getCustomerApiCall(query: string) {
let finalQuery = query;
// in your case, find the boolean value from the column and modify query
// your logic to modify the query string
// untested code, but it would probably look similar
if (query.includes('LockoutEndDateUtc%20eq%20true')) {
// calculate new date and replace boolean with new date
finalQuery = query.replace('LockoutEndDateUtc%20eq%20true', 'LockoutEndDateUtc%20le%202022-06-28T12%3A59%3A25Z');
}
return finalQuery;
}
Another possible solution but requires a bit more work.
If I'd be using a regular grid, without backend service and without access to the query string, I would probably add an external drop down outside of the grid and also add the date column and then control filters in the grid by using dynamic filtering. You can see a demo at Example 23, the principle is that you keep the column's real nature (date in your case) and filter it, if you want something like a "below today's date" then add an external way of filtering dynamically (a button or a drop down) and control the filter dynamically as shown below (from Example 23)

How will I select a particular object from the array of objects in the mongoose schema?

var mongoose = require("mongoose");
// schema setup
var productSchema = new mongoose.Schema({
type:{
type:String,
required:[true,'a product must have a type']
},
sId:String,
image:String,
products:[{
name:String,
image:String,
price:Number
}]
});
module.exports = mongoose.model("Product",productSchema);
I have made my mongoose schema like this. Now I just want to access a particular object from the array of objects named 'products' using a mongoose query.
Can anyone please tell me how can i do this?? I'll be soo grateful.
You need something like this:
db.collection.find({
"products.name": "name"
},
{
"products.$": 1
})
With this query you will find the product object whose name field is 'name'. Afther that, with the positional operator $ only the matching is returning.
Mongo playground example here
Edit: Note that this query will return multiple subdocuments if exists multiple documents with the array object matching. To filter for a unique element you have to indicate another unique field like this:
db.collection.find({
"sId": "1",
"products.name": "name"
},
{
"products.$": 1
})
Edit to explain how to use find using mongoose.
You can use find or findOne, but the query itself will be the same.
This is pretty simple. You need to use your model described in the question, so the code is somthing like this:
var objectFound = await YourModel.findOne({
"products.name": "name"
},
{
"products.$": 1
})
Where YourModel is the schema defined.

BookshelfJS - 'withRelated' through relational table returns empty results

I've been trying to structure the relations in my database for more efficient querying and joins but after following the guides for '.belongsToMany', '.through' and '.belongsTo' I'm now getting empty results.
I've got a Sound model and a Keyword model which I want to model with a many-to-many relationship (each Sound can have multiple Keywords, and each Keyword can be related to multiple sounds). Based on the documentation '.belongsToMany' would be the relation to use here.
I've set up my models as follows, using a 'sound_keyword' relational table/SoundKeyword relational model (where each entry has it's own unique 'id', a 'soundID', and a 'keywordID'):
var Sound = bookshelf.Model.extend({
tableName: 'sounds',
keywords: function () {
return this.belongsToMany(Keyword, 'sound_keyword', 'id', 'id').through(SoundKeyword, 'id', 'soundID');
},
});
var Keyword = bookshelf.Model.extend({
tableName: 'keywords',
sounds: function () {
return this.belongsToMany(Sound, 'sound_keyword', 'id', 'id').through(SoundKeyword, 'id', 'keywordID');
}
});
where:
var SoundKeyword = bookshelf.Model.extend({
tableName: 'sound_keyword',
sound: function () {
return this.belongsTo(Sound, 'soundID');
},
keyword: function () {
return this.belongsTo(Keyword, 'keywordID');
}
});
From what I've read in the docs and the BookshelfJS GitHub page the above seems to be correct. Despite this when I run the following query I'm getting an empty result set (the Sound in question is related to 3 Keywords in the DB):
var results = await Sound
.where('id', soundID)
.fetch({
withRelated: ['keywords']
})
.then((result) => {
console.log(JSON.stringify(result.related('keywords')));
})
Where am I going wrong with this? Are the relationships not set up correctly (Possibly wrong foreign keys?)? Am I fetching related models incorrectly?
Happy to provide the Knex setup as needed.
UPDATED EDIT:
I had been using the Model-Registry Plugin from the start and had forgotten about it. As it turns out, while the below syntax is correct, it prefers syntax similar to the following (i.e. lowercase 'model', dropping the '.extends' and putting model names in quotes):
var Sound = bookshelf.model('Sound',{
tableName: 'sounds',
keywords: function () {
return this.belongsToMany('Keyword', 'sound_keyword', 'soundID', 'keywordID');
},
});
var Keyword = bookshelf.model('Keyword',{
tableName: 'keywords',
sounds: function () {
return this.belongsToMany('Sound', 'sound_keyword', 'keywordID', 'soundID');
}
});
Hope this can be of help to others.
Seems like removing the '.through' relation and changing the IDs in the '.belongsToMany' call did the trick (as below), though I'm not entirely sure why (the docs seem to imply belongsToMany and .through work well together - possibly redundant?)
var Sound = bookshelf.Model.extend({
tableName: 'sounds',
keywords: function () {
return this.belongsToMany(Keyword, 'sound_keyword', 'soundID', 'keywordID');
},
});
var Keyword = bookshelf.Model.extend({
tableName: 'keywords',
sounds: function () {
return this.belongsToMany(Sound, 'sound_keyword', 'keywordID', 'soundID');
}
});
I did try my original code with soundID and keywordId instead of 'id' (as below), but without the .through relation and that gave the same empty results.

flexigrid Ajax Filter by using flexOptions

I have a page data load in flexigrid, after loading there are several filters, onchange filter i try to reload the grid like this
var data = {name: 'fltr_county', value: $("#fltr_county").val(), name: 'county_ene', value:$("#county_ene").val()}
$('.flexme').flexOptions({params: [ data ]}).flexReload();
But got only 'page=1&rp=25&sortname=Borrower&sortorder=asc&query=&qtype=&county_ene=equal' posting array. Only last param value got.
How i can pass more filter in posting array?
Please help.
Thanks in advance
Im new to Flexigrid.. but faced same situation and used this code.. its working for me.. im hopeful that your problem can be solved..
var query = $("#fltr_county").val();
var data = {"groupOp":"all","rules":[{"field":"fltr_county","op":"ew", "data": '"'+query+'"'}]};
$('#flex2').flexOptions({
filters : data,
qtype : "admin_client_contract_id",
query : query,
}).flexReload();
This works for me:
$('#useTimeRange').change(function() {
if( this.checked ) { //limit events to timestamp range
//alert("Checked " + startTime + " " + endTime);
var data = {name: 'startTime', value: $("#startTime").val()};
var data2= {name: 'endTime', value:$("#endTime").val()};
$('.flex5').flexOptions({params: [ data, data2 ]}).flexReload();
}
Here's my UI and firebug:
according to me In data you are not passing parameters as per as syntax of json
try some thing like this
var data = {name: 'fltr_county', value: $("#fltr_county").val()},{ name: 'county_ene',value:$("#county_ene").val()}
I hope this will help

Initially selected value from store in dijit.form.FilteringSelect

I have a dojo.data.ItemFileReadStore as follows:
var partyStore = new dojo.data.ItemFileReadStore({
id: 'partyStore',
data: {
label:'name',
items:[
{value:'APPLES', name:['Apples']},
{value:'ORANGES', name:['ORANGES']},
{value:'PEARS', name:['PEARS']}
]}
});
and a dijit.form.FilteringSelect as:
var partyList = new dijit.form.FilteringSelect({
id: "partyLookup",
name: 'partyLookup',
store: partyStore,
searchAttr: "name"}, infoDiv);
How can I make the initially selected value be Oranges?
I have tried various entries for the value in the FilteringSelect so have left it out in this example.
Your data store doesn't seem right. Try changing it to:
var partyStore = new dojo.data.ItemFileReadStore({
identifier: 'value',
items:[
{value:'APPLES', name:'Apples'},
{value:'ORANGES', name:'ORANGES'},
{value:'PEARS', name:'PEARS'}
]
});
You can then set the value of the dijit.
partyList.set('value', 'ORANGES');
I had missed off the "identifier" from the store data. It seems without the identifier being set it indexes them ie. 0,1,2,3,4...
Once I set:
identifier: 'value'
the current value of the FilteringSelect comes back as the 'value' form the data.
Sorry to answer my own question, thanks to anyone who helped or took a look.