Vue Conditional Class Binding - class

I am trying to dynamically render class based off actionTypeCreate. This is a method that simply returns a boolean value based off the prop actionType that is passed. I am triggering this method on the mounted hook and confirmed it is returning properly.
Now I am trying to return the class value of 'col-md-4' if actionTypeCreate. If not actionTypeCreate I want to return the class 'col-md-6'.
This is what I have but it is not working:
:class="{toggleActionType : 'col-md-4' ? 'col-md-6'}"
I tried to reference this existing question, but I did not get it.

You can do it as follows:
:class="{'col-md-4' : toggleActionType , 'col-md-6' : !toggleActionType }"

According to the Vue documentation itself you can do it in two ways. First, you can use Array Syntax and this is broadly used to apply a list of classes.
Array Syntax
:class="[toggleActionType ? 'col-md-4' : 'col-md-6']"
Or you can do it as normal by Object Syntax but it does not accept ternary operations, so you have to do it this way:
Object Syntax
:class="{'col-md-4' : toggleActionType , 'col-md-6' : !toggleActionType}"

Try this:
:class="[toggleActionType : 'col-md-4' ? 'col-md-6']"

Related

Drools : how to assign value to variable "from" predefined method when using PackageDescr to generate rule?

How can I generate something like this in my rule using PackageDescr ?
$var: Number (doubleValue > 100 ) from myPredefinedFunction()
I tried the following :
PatternDescr pt = new PatternDescr("Number","$var");
RelationalExprDescr ex = new RelationalExprDescr(">", false, null, new ExprConstraintDescr("myPredefinedFunction()"), new ExprConstraintDescr("100"));
pt.addConstraint(ex);
but this is what I get :
$var : Number( myPredefinedFunction() > 100 )
You're trying to set the myPredefinedFuntion() as a constraint. Constraints are the part of the drools declaration between the parentheses, eg. MyObject( foo == "bar" ) ... the foo == "bar" is a constraint.
Instead you need to set the source using the setSource method. This is the 'from' part of the declaration. This method takes a instance of a PatternSourceDescr subclass -- likely a FromDescr for this particular scenario.
(Alternatively, you might need setResource instead of setSource. The problem with using internal-only APIs is that they're not documented and subject to change without notice. I strongly suggest not going down this route.)

how to handle empty array for text widget in build method?

How would I handle the objectA[0].name (a string) in the build method if the array is empty?
Text(objectB.objectC.objectA[0].name),
Assuming the array is objectC you can do something like:
Text(objectC.isEmpty? "" :objectC[0].name)
You can read more about ternary operators in dart here
There isn't a great way to do this inline but with a simple extension method to return the original null or the iterable depending on whether the item is null or empty you can make it work.
First
Extension Method
(requires dart v2.7 - update in your pubspec.yaml file)
extension IterableExtension<T> on Iterable<T> {
Iterable<T> get nullWhenEmpty =>
this == null || this.isEmpty ? null : this;
}
Second
To handle null values while you're traversing an object you can use the Dart's conditional member access operator (?.). This operator will only continue with the right-hand side if the left-hand side of the operator is not null. Use the elementAt method on a an iterable to be able to use the ?. operator in the chain. Then, use the ?. operations with the if null operator (??) to get your default value.
Solution
final String value = objectB?.objectC?.objectA?.nullWhenEmpty?.elementAt(0)?.name;
Text(value ?? 'Default Text');
You can, of course, inline the above code instead of using an additional variable.
Resources
Dart Language Tour: Other Operators
Dart Language Tour: Classes
Maybe checking if the list has an element, using isNotEmpty
child: (objectB.objectC.objectA.isNotEmpty)
? Text(objectB.objectC.objectA[0].name)
: Container(),

get an element index in ocl collection ? [ocl_Eclipse]

i'm working on the following domain :
my domain diagram
i want to express the folowing constraint :
" a succession of two actions of Type Rotate is not allowed "
i tried this declaration but eclipse is not recognizing indexOf(element ) :
class Choreography
{
property actions : Action[+|1] { ordered composes };
attribute name : String[?];
/*Succession of two actions of Type is not permitted */
invariant rotate_succ:
self.actions->asSequence()->forAll(a1:Action,a2:Action
|
a1.oclIsTypeOf(Rotate) and (indexOf(a1)=indexOf(a2)+1) implies
not a2.oclIsTypeOf(Rotate)
)
;
Does anyone have an idea about how to work with the index of a random element from an ocl colletion ?
The
OrderedCollection(T):indexOf(obj : OclAny[?]) : Integer[1]
operation requires an OrderedCollection (Sequence/OrderedSet) as its source and an OclAny as its argument. You have not identified a source so OCL will consider first an implicit iterator leading to an
a1.indexOf(a1)
a2.indexOf(a1)
ambiguity which would be an error if an Action had an indexOf operation. Then it considers an implicit self which also fails since there is no Choreography.indexOf() operation.
I presume you meant
self.actions->indexOf(a1)
etc etc, or more readably put self.actions in a let-variable for multi-use.
(Use of oclIsTypeOf is very rarely right. Use oclIsKindOf unless you have a specific intent.)
(self.actions is already an OrderedCollection so there is no need for the asSequence()).
Your use of indexOf will lead to quadratic performance. Better to use indexes - something like:
let theActions = self.actions in
Sequence{1..theActions->size()-1}->forAll(index |
theActions->at(index).oclIsKindOf(Rotate)
implies not theActions->at(index+1).oclIsKindOf(Rotate))

Not able to write beamSql data to BigQuery

I'm trying to write beamSql data to BigQuery as shown below :
final_out1.apply(BigQueryIO.<TableRow>Write
.named("Write")
.to("my-project:data_id1.tables_test")
.withSchema(schema)
.withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_TRUNCATE))
.withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED));
I'm getting error on named(), the error :
The method named(String) is undefined for the type BigQueryIO.Write
Any idea what this means ?
EDIT
The format function that I defined :
final_out1.apply(BigQueryIO.<TableRow>write()
.withSchema(schema)
.to("beta-194409:data_id1.tables_test"));
/* .withFormatFunction(fin -> new TableRow().
set("SalesComponent", fin.getSalesComponent()).
set("DuetoValue", fin.getDuetoValue()).
set("ModelIteration", fin.getMo//delIteration())) */
//.withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_TRUNCATE).withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED));
There is no such method named() for class BigQueryIO.Write so this error makes sense.
You can specify a transform name as the first parameter of the apply() method.
final_out1.apply("Write", BigQueryIO.<TableRow>.write()
.to("my-project:data_id1.tables_test")
.withSchema(schema)
.withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_TRUNCATE))
.withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED));
Note: Use BigQueryIO.write() instead of BigQueryIO.Write.

Populating the list in g.select

I need to programmatically load a list.
Instead of:
<g:select
name="cars"
from="${Car.list()}"
value="${person?.cars*.id}"
optionKey="id"
multiple="true" />
I would like to do it this because, the list is not always coming from the same source
g.select(name : searchfield.fieldName,
class : "fillWidth searchfield",
multiple : "true",
from : ${ searchfield.fieldFrom },
optionKey : searchfield.fieldKey,
optionValue : searchfield.fieldValue)
The from does not load. with the list, I get an error message:
No signature of method: sample.SearchTagLib.$() is applicable for argument types: (sample.SearchTagLib$_getSelectField_closure5) values: [sample.SearchTagLib$_getSelectField_closure5#1187b50] Possible solutions: is(java.lang.Object), any(), use([Ljava.lang.Object;), any(groovy.lang.Closure), wait(), grep()
You don't need the ${} in the from option
g.select(name : searchfield.fieldName,
class : "fillWidth searchfield",
multiple : "true",
from : searchfield.fieldFrom,
optionKey : searchfield.fieldKey,
optionValue : searchfield.fieldValue)
In Groovy code ${} is a way to put Groovy expressions inside double quoted GStrings, if you're not in a GString you can just use the expression directly without wrapping it in ${}.
Edit from your comment
The fieldFrom at this point is a string which would get its value from a database. So the value in the DB is "Car.list()" which in the prototype I need to convert to a bound able or execute-able line of code.
It's not generally recommended to allow your app to execute arbitrary snippets of Groovy code provided by users (for obvious security reasons). As long as the code snippets come from a secure source such as a trusted admin user then fair enough, it is possible using GroovyShell
def from = new GroovyShell().evaluate(searchfield.fieldFrom)
but this is likely to be rather inefficient, creating a new classloader and parsing and compiling a whole Groovy script class every time. If the fieldFrom values are intended to always be pulling something from the database (i.e. they'll always be something like Car.list() or Vehicle.findAllByNumberOfWheelsGreaterThan(2), rather than arbitrary Groovy like [1,2,3]) then it might be better to store HQL expressions in fieldFrom and run them using executeQuery
def from = AnyDomainClass.executeQuery(searchfield.fieldFrom)
(executeQuery is a static GORM method, you need to call it on a specific domain class but it can return results of any type). The HQL equivalent of Car.list() would be "from Car", the equivalent of Vehicle.findAllByNumberOfWheelsGreaterThan(2) would be "from Vehicle where numberOfWheels > 2", etc.
I think you need to use strings as the attribute name:
g.select('name' : searchfield.fieldName,
'class' : "fillWidth searchfield",
'multiple' : "true",
'from' : ${ searchfield.fieldFrom },
'optionKey' : searchfield.fieldKey,
'optionValue' : searchfield.fieldValue)