Syntax for a nested expression binding [SAPUI5] - nested

i would like to set the visibility based on the tests of two different conditions. it musst fullfill the tests bellow.
Things that i want to test:
name !== ''
and name is not null
AND
nr === 13;
or nr === 14;
Syntax:
<Button visible="{= {${modelExample>name} !== '' &&amp ${modelExample>name} !== null} && {${modelExample>nr} === 13 || ${modelExample>nr} === 14 } ? true: false}"
Issue: It does give out an error.
Question: What would be the appropriate syntax for this conditionals. Is it even possible to test two different things ?

The readability of expression binding is kinda ...
if your condition get's to complex go for a formatter.(IMO better readability)
Expression Binding
JSONModel
this.getView().setModel(new JSONModel({
name: "",
nr: 10
}), "json");
XML
<Button text="test" visible="{= ${json>/name} && (${json>/nr} === 13 || ${json>/nr} === 14) ? true : false}"/>
Formatter
formatter.js
myCond: function (sName, iNumber) {
if (sName && (iNumber === 13 || iNumber === 14)) {
return true;
} else {
return false;
}
}
XML
<Button text="test" visible="{ parts: ['json>/name', 'json>/nr'], formatter: '.formatter.myCond'}"/>

Related

No fetchJoinCollection in subresource

I'm using api platform 2.6
I'm trying to use "pagination_fetch_join_collection" with SubresourceOperations.
But, it seems that there is no support for FetchJoinCollection (https://www.doctrine-project.org/projects/doctrine-orm/en/current/tutorials/pagination.html)
https://github.com/api-platform/core/blob/main/src/Doctrine/Orm/Extension/PaginationExtension.php#L128
if (null !== $resourceClass) {
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
if (isset($context['collection_operation_name']) && null !== $fetchJoinCollection = $resourceMetadata->getCollectionOperationAttribute($operationName, 'pagination_fetch_join_collection', null, true)) {
return $fetchJoinCollection;
}
if (isset($context['graphql_operation_name']) && null !== $fetchJoinCollection = $resourceMetadata->getGraphqlAttribute($operationName, 'pagination_fetch_join_collection', null, true)) {
return $fetchJoinCollection;
}
}
//[...]
Only support for collection_operation_name & graphql_operation_name
There is any reason for that ?
And, Have you a solution for use fetchJoinCollection properly ?
Thank you.

ajv-errors plugin with fastify 4 in lerna project gives error that compiler schema error

my fastify 3 (ajv6) use this settings:
ajv: {
customOptions: {
allErrors: true,
removeAdditional: true,
jsonPointers: true
},
plugins: [require('ajv-errors')],
},
as ajv 8 removed jsonpointers so i delete it.
but it still throw errors that in my project.
the reproduce project is in this repo, please check.
https://github.com/radiorz/fastify-lerna-ajv-error-demo
error message :
Error compiling schema, function code: const schema26 = scope.schema[20];const obj0 = scope.obj[0];return function validate24(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){let vErrors = null;let errors = 0;if(data && typeof data == "object" && !Array.isArray(data)){if(data.parameters === undefined){const err0 = {instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: "parameters"},message:"must have required property '"+"parameters"+"'"};if(vErrors === null){vErrors = [err0];}else {vErrors.push(err0);}errors++;}for(const key0 in data){if(!(key0 === "parameters")){delete data[key0];}}if(data.parameters !== undefined){let data0 = data.parameters;if(typeof data0 !== "string"){let dataType0 = typeof data0;let coerced0 = undefined;if(dataType0 == 'object' && Array.isArray(data0) && data0.length == 1){data0 = data0[0];dataType0 = typeof data0;if(typeof data0 === "string"){coerced0 = data0;}}if(!(coerced0 !== undefined)){if(dataType0 == "number" || dataType0 == "boolean"){coerced0 = "" + data0;}else if(data0 === null){coerced0 = "";}else {const err1 = {instancePath:instancePath+"/parameters",schemaPath:"#/properties/parameters/type",keyword:"type",params:{type: "string"},message:"must be string"};if(vErrors === null){vErrors = [err1];}else {vErrors.push(err1);}errors++;}}if(coerced0 !== undefined){data0 = coerced0;if(data !== undefined){data["parameters"] = coerced0;}}}}}else {const err2 = {instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"};if(vErrors === null){vErrors = [err2];}else {vErrors.push(err2);}errors++;}if(errors > 0){const emErrors0 = {"required":{"parameters":[]}};let emParamsErrors0;for(const err3 of vErrors){if(((((({"str":"err3"}.keyword !== "errorMessage") && (!{"str":"err3"}.emUsed)) && ({"str":"err3"}.instancePath === instancePath)) && ({"str":"err3"}.keyword in {"str":"emErrors0"})) && ({"str":"err3"}.schemaPath.indexOf("#") === 0)) && (/^/[^/]*$/.test({"str":"err3"}.schemaPath.slice(1)))){emParamsErrors0 = {"str":"emErrors0"}[{"str":"err3"}.keyword][{"str":"err3"}.params[{"str":"emPropParams0"}]];if(emParamsErrors0){{"str":"emParamsErrors0"}.push({"str":"err3"});{"str":"err3"}.emUsed = true;}}}for(const key1 in emErro
having the same error - any solutions?
"fastify": "4.1.0"
"ajv-errors": "^3.0.0"
ajv: {
customOptions: {
allErrors: true,
},
plugins: [AjvErrors],
},
Error: Cannot find module 'ajv'
EDIT: looks like reinstalling node modules fixed this issue - if you're using fasify 4 or above you can use ajv-errors 3 if you're using below fastify version 4 you have to use ajv-errors 1

Why am I getting Undefined instead of Null from a Form drop down list when I haven't selected anything?

So, I have a basic page where I find() data from a collection in my Database and I created it using Node.js, express, MongoDB and ejs. I created a Form so that I can filter data from the rendered table and send it as filters to mongoDb. The form consists of 3 input types, 2 text types and 1 drop down along with a submit button.
My problem lies in the Drop down. When I select a value from the drop down and submit, I get the filtered result. But whenever I leave the drop down as it is and fill any other input field to filter with only those, I dont get back any Data.
Here is the code for my Drop down:
<div class="col-lg-12">
<select class="form-control" name="searchDept">
<option selected disabled value="">Choose Department</option>
<option value="Computer Science Engineering">Computer Science Engineering</option>
<option value="Information Science Engineering">Information Science Engineering</option>
<option value="Electrical & Electronics Engineering">Electrical & Electronics Engineering</option>
<option value="Electronics and Communication Engineering">Electronics and Communication Engineering</option>
<option value="Mechanical Engineering">Mechanical Engineering</option>
<option value="Civil Engineering">Civil Engineering</option>
<option value="Main Office">Main Office</option>
<option value="Admission Office">Admission Office</option>
<option value="Principal Office">Principal Office</option>
</select>
</div>
And in my app.js file, this is my get method:
const searchName = req.body.searchName;
const searchPhone = req.body.searchPhone;
const searchDept = req.body.searchDept;
if (searchName != "" && searchPhone != "" && searchDept != "") {
var searchParameter = { $and: [{visitorName : searchName}, { $and: [{phone : searchPhone}, {deptOfVisit : searchDept}]}]}
} else if (searchName != "" && searchPhone == "" && searchDept != "") {
var searchParameter = { $and: [{visitorName : searchName}, {deptOfVisit : searchDept}]}
} else if (searchName == "" && searchPhone != "" && searchDept != "") {
var searchParameter = { $and: [{phone : searchPhone}, {deptOfVisit : searchDept}]}
} else if (searchName != "" && searchPhone != "" && searchDept == "") {
var searchParameter = { $and: [{visitorName : searchName}, {phone : searchPhone}]}
} else if (searchName != "" && searchPhone == "" && searchDept == "") {
var searchParameter = {visitorName : searchName}
} else if (searchName == "" && searchPhone == "" && searchDept != "") {
var searchParameter = {deptOfVisit : searchDept}
} else if (searchName == "" && searchPhone != "" && searchDept == "") {
var searchParameter = {phone : searchPhone}
} else {
var searchParameter = {}
}
console.log(searchName);
console.log(searchPhone);
console.log(searchDept);
console.log(searchParameter);
var visitorSearch = Visitor.find(searchParameter);
Everything works fine when I select one of those options from the List and I am able to find the right Data and render it. But If I leave the Drop down without selecting anything, I get back no records.
So I tried console logging everything and when I did, I realised it's passing an "Undefined" value instead of null and is getting in the first if statement instead of the one where it should be null.
Test
12345
undefined
{ '$and': [ { visitorName: 'Test' }, { '$and': [Array] } ] }
What am I doing wrong and what should I be doing?
I haven't really found an answer to this but I found myself a work around. I assigned the 2nd option as Selected as that was working without me having to select it and changed the "Choose Department" option to "None". So as #GarrGodfrey said in the comments, req.body get set on a change. I dont know how it works with the second option without me changing it but anyway, If I dont want to search by Department, I click on the Drop Down and select None whose value is "" or null. And the Search happens perfectly.

preventing value compilation errors

Bixby raises "Value Compilation Errors" in the debugger whenever I run a script that brings back Empty Optional Values. The variable model is correct in that these values really are optional, i.e not needed for the user task to succeed. So you can simply ignore the debugger errors and everything will work, EXCEPT that the Story testing tool will report these runs as "failed." This means that the Story tool is almost useless for these cases, and that's a big problem.
Can someone show me how to code to avoid them?
Thanks to a tip from #mincheng I finally figured out how to do this. The key is to delete any object properties that are null, undefined, or empty strings. I loop over my array of objects with the delete function.
// remove undefined properties here
const removeEmpty = (obj) => {
Object.keys(obj).forEach(key => {
if (obj[key] && typeof obj[key] === 'object') removeEmpty(obj[key]);
else if (obj[key] === undefined || obj[key] === null || obj[key] === "") delete obj[key];
});
return obj;
};
for (var i = 0; i < altBrainsData.length; i++) {
//console.log('i is', i);
//console.log('function object', i, 'is', altBrainsData[i])
//console.log(removeEmpty(altBrainsData[i]))
altBrainsData[i] = removeEmpty(altBrainsData[i])
}

how to remove {} empty field in array .. nodejs

i am using below code...but if Status is Empty iss show below result in database...i want to remove if Status is Empty ..
1 Address {}, Status {} save in database.
function CheckStatus(oldJob, newJob) {
var obj = {};
if(newJob && newJob.Status) {
obj.Status= {};
if (oldJob.Status.total !== newJob.Status.total) {
obj.Status.total = newJob.Status.total;
}
if (oldJob.Status.charge_description && oldJob.Status.charge_description !== newJob.Status.charge_description) {
obj.Status.charge_description = newJob.Status.charge_description;
}
}
}
Mongodb
"Job" : {
"_id" : ObjectId("5873b352e7621d08fccc5890"),
"updated_by" : "",
"details" : "{\"current_status\":\"Completed\",\"address\":{},\"Status\":{}}",
"changetype" : "Update",
"datetime" : ISODate("2017-01-09T15:59:14.202Z")
},
please help how what enter in If Condition ( below code not working)
if(obj.address = '{}')
{
console.log('Empty');
}
Setting an object's value to undefined essentially deletes them. You may use the undefined keyword easily as such:
newJob.address = undefined;
How i would check for an empty object and delete its content:
if(Object.keys(newJob.address).length === 0 && obj.constructor === Object){
newJob.address = undefined;
}
Solution is better explained in this question's answers:
How do I test for an empty JavaScript object?

Resources