Passing a parameter to a Component on instantiation - qml

I'm creating TableViewColumns during runtime and need to pass the role to the TableViewColumn.
TableView {
model: myModel
onModelChanged: {
var roleList = myModel.customRoleNames
for ( var i = 0; i < roleList.length; ++i ) {
var role = roleList[ i ]
addColumn( /* my column component here */ )
}
}
}
Component {
id: columnComponent
TableViewColumn {
role: /* ??? */
}
}
How can I feed the role to my Component when it's being instantiated?

Ok, I've got it. Here is the solution:
TableView {
id: myTableView
model: myModel
onModelChanged: {
var roleList = myModel.customRoleNames
for ( var i = 0; i < roleList.length; ++i ) {
var role = roleList[ i ]
addColumn( columnComponent.createObject ( myTableView, { "role": role } ) )
}
}
}
Component {
id: columnComponent
TableViewColumn { }
}
This, of course, works for all properties of TableViewColumn, eg.:
addColumn( columnComponent.createObject ( myTableView, { "role": myRole, "title": someTitle } ) )

Related

Can I use optional parameter in path in Jetpack Compose Navigaiton?

I have this navigation graph
fun NavGraphBuilder.manageAvailabilityGraph() {
composable(
"availability/{id}",
arguments = listOf(
navArgument("id") {
type = NavType.StringType
nullable = true
},
),
) {
ManageAvailabilityScreen()
}
}
I thought I can use it for both
navHostController.navigate("availability")
navHostController.navigate("availability/123")
But first one does not work, I get
java.lang.IllegalArgumentException: Navigation destination that matches request NavDeepLinkRequest{ uri=android-app://androidx.navigation/availability } cannot be found in the navigation graph NavGraph(0x0) startDestination={Destination(0xcfbbf7da) route=home}
I fixed it by providing two different routes.
fun NavGraphBuilder.manageAvailabilityGraph() {
composable(
"availability",
) {
ManageAvailabilityScreen()
}
composable(
"availability/{id}",
arguments = listOf(
navArgument("id") {
type = NavType.StringType
nullable = true
},
),
) {
ManageAvailabilityScreen()
}
}
However, I want to know is if it is possible to combine both and just have one route with name "availability", so I don't need to repeat "availability"? And eseentially, both use the same screen.
I tried something like this but does not work.
fun NavGraphBuilder.manageAvailabilityGraph() {
composable(
"availability",
) {
ManageAvailabilityScreen()
navigation(startDestination = "{id}", "{id}") {
composable(
"{id}",
arguments = listOf(
navArgument("id") {
type = NavType.StringType
},
),
) {
ManageAvailabilityScreen()
}
}
}
}
You can mark id as the optional parameter in the route. Refer Documentation
fun NavGraphBuilder.manageAvailabilityGraph() {
composable(
"availability?id={id}",
arguments = listOf(
navArgument("id") {
type = NavType.StringType
nullable = true
},
),
) {
ManageAvailabilityScreen()
}
}
While navigating you can use,
navHostController.navigate("availability")
navHostController.navigate("availability?id=123")

Validator not validating the request in Laravel 8

I am inserting the data. The data is being entering quite fine but whenever I enter a letter the entry is done but that entry is converted to '0'.
This is my controller store function:
public function store(GuidanceReportRequest $request)
{
$stats = GuidanceReport::where('user_id', $request->user_id)->whereDate('created_at', now())->count();
if ($stats > 0) {
Session::flash('warning', 'Record already exists for current date');
return redirect()->route('reports.index');
}
if ((!empty($request->call_per_day[0]) && !empty($request->transfer_per_day[0])) ||
(!empty($request->call_per_day[1]) && !empty($request->transfer_per_day[1])) || (!empty($request->call_per_day[2])
&& !empty($request->transfer_per_day[2]))
) {
foreach ($request->category as $key => $value) {
$catgeory_id = $request->category[$key];
$call_per_day = $request->call_per_day[$key];
$transfer_per_day = $request->transfer_per_day[$key];
if (!empty($catgeory_id) && !empty($call_per_day) && !empty($transfer_per_day)) {
GuidanceReport::create([
"user_id" => $request->user_id,
"categories_id" => $catgeory_id,
"call_per_day" => $call_per_day,
"transfer_per_day" => $transfer_per_day,
]);
}
}
} else {
GuidanceReport::create($request->except('category', 'call_per_day', 'transfer_per_day'));
}
Session::flash('success', 'Data Added successfully!');
return redirect()->route('reports.index');
}
This is my Validation Request code
public function rules()
{
$rules = [];
$request = $this->request;
if ($request->has('transfer_per_day')) {
if (!empty($request->transfer_per_day)) {
$rules['transfer_per_day'] = "numeric";
}
}
if ($request->has('call_per_day')) {
if (!empty($request->call_per_day)) {
$rules['call_per_day'] = "numeric";
}
}
if ($request->has('rea_sign_up')) {
if (!empty($request->rea_sign_up)) {
$rules['rea_sign_up'] = "numeric";
}
}
if ($request->has('tbd_assigned')) {
if (!empty($request->tbd_assigned)) {
$rules['tbd_assigned'] = "numeric";
}
}
if ($request->has('no_of_matches')) {
if (!empty($request->no_of_matches)) {
$rules['no_of_matches'] = "numeric";
}
}
if ($request->has('leads')) {
if (!empty($request->leads)) {
$rules['leads'] = "numeric";
}
}
if ($request->has('conversations')) {
if (!empty($request->conversations)) {
$rules['conversations'] = "numeric";
}
}
return $rules;
}
Although I check the type in which request is being sent from controller and recieved from the request validation and it is Object. So how can I solve the issue.

How to disable a graphql filter if the variable is not set?

I am working on a page with configurable filters. The graphql query looks like:
query GetPlayers(
$offset: Int
$limit: Int
$skillIds: [uuid!] = null
$playerTypeIds: [Int!] = null
$availability: Int = null
$timezones: [String!] = null
$search: String = null
) {
player(
order_by: { total_xp: desc }
offset: $offset
limit: $limit
where: {
availability_hours: { _gte: $availability }
timezone: { _in: $timezones }
player_type_id: { _in: $playerTypeIds }
Player_Skills: { Skill: { id: { _in: $skillIds } } }
_or: [
{ username: { _ilike: $search } }
{ ethereum_address: { _ilike: $search } }
]
}
) {
id
}
}
I would like the default behavior to be to return all entries. I am using Hasura 1.3.3 and null is interpreted as {} which will return all entries. The only problem is the Player_Skills: { Skill: { id: { _in: $skillIds } } } line. There is a join table with foreign keys referring to the players and skills tables, and that line will only return players who have at least one entry in that table.
Is it possible to form a query that will ignore the skills filter if $skillIds is null?

How to send ecommerce data to datalayer in prestashop

I am not a developer but trying to send ecommerce data to datalayer. I can't see any ecommerce data to datalayer in console. I am adding the data to order-confirmation.tpl in prestashop. below is how i am sending data
<Script type = "text / javascript">
dataLayer = ( {
'transactionId' : '{literal} {$order_id} {/literal}' ,
'transactionTotal' : {literal } { $total_a_payment } {/literal } ,
'transactionTax' : { literal } { $tax } { /literal } ,
'transactionShipping' : { literal } { $ expenses_envoice } { /literal
} ,
'transactionProducts' : [ { /literal } { foreach from = $ products
item = product name = products } { /literal }
{
'Sku' : '{literal}{$producto.id_product}{/literal}' ,
'Name' : '{literal}{$producto.name}{/literal}' ,
'Price' : { literal } { $ product . Price_wt } { /literal } ,
'Quantity' : { literal } { $ product . Quantity } { /literal }
} { Literal} {if $ smarty.foreach.productos.iteration! = $ Products
| #count} {literal}, {/ literal } { / if } { /literal }
{ Literal} {/ foreach } ] , { /literal }
'Event' : 'transactionComplete'
} )
</ Script>
{ / Literal }
anyone have experience with prestashop please help. I am using Google Tag Manager for ecommerce tracking. thanks
I had the same issue. You have to also edit file controllers/front/OrderConfirmationController.php.
Find function displayOrderConfirmation and insert something like this part of code:
$order = new Order($this->id_order);
$currency = new Currency($order->id_currency);
/* added part */
$cart = new Cart($order->id_cart);
$products = $cart->getProducts();
$this->context->smarty->assign(array(
'order_id'=> $this->id_order,
'total_a_payment'=> $order->total_paid_tax_incl,
'expenses_envoice'=> $order->total_shipping_tax_incl,
'tax'=> ($order->total_paid_tax_incl - $order->total_paid_tax_excl),
'products' => $products
));
/*end of added*/
Original source: https://www.prestashop.com/forums/topic/618328-variables-for-google-tag-manager/

Realm very slow for adding/updating records

I have this react native application which imports the phone contacts to database. I have about 100 contacts in my phone and it's taking ages...like 1 import per second which is. I'm sure, a mistake I'm doing somewhere even though the code is simple.
realm.write(() => {
for (let i = 0, len = contacts.length; i < len; i++) {
Contact.saveOrUpdate(contacts[i].name, contacts[i].recordID, contacts[i].phoneNumbers);
}
});
saveOrUpdate method:
class Contact {
static saveOrUpdate(name, recordId, phones) {
const save = () => {
let c;
try {
// try an update first
c = realm.create('Contact', {
name: name.toString(),
recordID: recordId.toString()
}, true);
} catch (e) {
// if that fails, create a new contact
console.log("Created " + recordId);
c = realm.create('Contact', {
name: name.toString(),
recordID: recordId.toString()
});
}
c.phones = [];
for (let i = 0, len = phones.length; i < len; i++) {
c.phones.push({
number: phones[i].toString()
});
}
// now run an update with the phone numbers
return realm.create('Contact', c, true);
};
return save();
}
}
My realm schema:
const PhoneNumberSchema = {
name: 'PhoneNumber',
properties: {
number: 'string'
}
};
const ContactSchema = {
name: 'Contact',
primaryKey: 'recordID',
properties: {
recordID: 'string',
name: {
type: 'string',
indexed: true
},
phones: {
type: 'list',
objectType: 'PhoneNumber'
}
}
};
Can anyone spot what am I doing wrong here that it takes so long for 100 contacts to be stored?