Ternirary operator in compoennt to pass prop to styled component? - styled-components

I have a boolean variable isHere which needs to define some additional styles for a component. If I use className then the prop is passed:
<Item className={isHere ? 'hi' : null}>
// Stuff
</Item>
However when I try and pass a styled component's prop I get an error:
<Item {isHere ? {joined: true} : null}>
// Stuff
</Item>
Syntax error: Unexpected token, expected ... (30:15)

<Item joined={isHere ? true : false}>
// stuff
<LeaveLocation />

Related

XSD (bitwise) logic between two attributes

Is it possible for XSD to apply (bitwise) logic between two XML attributes?
I hope to catch the following schema violation:
<parent mask="0x0007">
<child id="1" value="0x0001"/>
<child id="2" value="0x0002"/>
<child id="x" value="0x0010"/> // catch this!
</parent>
child x can clearly not be masked by its parent.
In simple logic:
if ((value AND mask) != value) then
# child element is invalid
endif
My application can of course catch this during the loading of the XML.
But my application applies schema validation prior to that and it would be grand if we can catch this during that stage.

Is there possibility for FreeMarker to create a directory or package on Android Studio templating?

I'm trying to create a template that has a nested package.
Here's my templating code.
// root/global.xml.ftl
<?xml version="1.0"?>
<globals>
<global id="simpleLayoutName" value="${layoutName}"/>
<global id="excludeMenu" type="boolean" value="true"/>
<global id="resOut" value="${resDir}"/>
<global id="srcOut" value="${srcDir}/${slashedPackageName(packageName)}"/>
<#include "../common/common_globals.xml.ftl" />
</globals>
// root/recipe.xml.ftl
<?xml version="1.0"?>
<recipe>
<#if generateLayout>
<#include "../common/recipe_simple.xml.ftl" />
<open file="${escapeXmlAttribute(resOut)}/layout/${layoutName}.xml"/>
</#if>
<instantiate from="root/src/app_package/SimpleFragment.kt.ftl"
to="${escapeXmlAttribute(srcOut)}/${activityClass}Fragment.kt"/>
</recipe>
// root/template.xml
<?xml version="1.0"?>
<template
format="5"
revision="1"
name="MVVM Activity"
minApi="9"
minBuildApi="14"
description="Creates a new empty activity that uses MVVM Pattern">
<category value="Activity" />
<formfactor value="Mobile" />
<parameter
id="generateLayout"
name="Generate Layout File"
type="boolean"
default="true"
help="If true, a layout file will be generated" />
<parameter
id="layoutName"
name="Layout Name"
type="string"
constraints="layout|unique|nonempty"
suggest="${activityToLayout(activityClass)}"
default="activity_main"
visibility="generateLayout"
help="The name of the layout to create for the activity" />
<parameter
id="packageName"
name="Package name"
type="string"
constraints="package"
default="com.mycompany.myapp" />
<!-- 128x128 thumbnails relative to template.xml -->
<thumbs>
<!-- default thumbnail is required -->
<thumb>template_MVVM_activity.png</thumb>
</thumbs>
<globals file="globals.xml.ftl" />
<execute file="recipe.xml.ftl" />
</template>
// root/src/app_package/SimpleFragment.kt.ftl
package ${packageName}
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
class ${fragmentClass}Fragment : Fragment() {
// TODO: Implement by lazy ViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// TODO: Init or setup view, viewmodel related, etc anything to setup here
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// TODO: Init or setup view, viewmodel related, etc anything to setup here
}
}
But, I didn't find any function to create a directory here: http://freemarker.apache.org/docs
Looks like I'm missing something here, is there anyone ever doing this to achieve creating a package inside output directory.
I quite catch that recipe.xml.ftl able to instantiate new file, but I still didn't try to create a directory instead, is it possible? What should add for from attribute value?
According to this article. By default, you can do this without any extra effort. Just point the new package on recipe.xml.ftl e.g:
<instantiate from="root/src/main/java/model/Simple.kt.ftl"
to="${escapeXmlAttribute(srcOut)}/model/${modelName}.kt"/>
to element will creating the new model package inside your destination directdory.

Passing the being looped element to event handler

How do I pass the element that is being loop to event handler.
foo.hbs
<div>
{{#each products}}
// some html code
<p>{{this}}</p> <!-- output product object -->
<button onclick="foo(this)">Add</button> <!-- output button object-->
<button onclick="foo({{this._id}})">Add</button> <!-- uncaught syntax error -->
{{/each}}
</div>
<script type="text/javascript">
function foo(product) {
console.log(product);
}
</script>
The above code: product argument gives me the HTMLButton instead of product of current iteration.
Question: How do I pass product instead of button element to the handler?
I'm using express-handlerbars.
You can try :
this.parentNode
which refers to html parent.
and in your function:
console.log(product.id);
console.log(typeof(product)); //display object
Console print html, but product is object you sent from onclick. So you can access to any related properties.
Hope it can help.

How to get attribute value of node in xml using xpath in javascript

Hi I am trying to get the user profile properties from sharepoint on client side with javascript.But I am not getting the value of nodes in xml.
How to get them. the xml will look like as:
How to get attribute value of node in xml using xpath
Here I want to get the value which is between <name> tags <Name>AccountName</Name> and between Name tags
want to get the value = abc what will be the xpath expression
Please help
<?xml version="1.0" encoding="utf-8" ?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetUserProfileByNameResponse xmlns="http://microsoft.com/webservices/SharePointPortalServer/UserProfileService">
<GetUserProfileByNameResult>
<Pro pertyData>
<IsPrivacyChanged>false</IsPrivacyChanged>
<IsValueChanged>false</IsValueChanged>
<Name>UserProfile_GUID</N ame>
<Privacy>NotSet</Privacy>
<Values>
<ValueData>
<Value xmlns:q1="http://microsoft.com/wsdl/types/" xsi:type="q1:guid">8ed84415-7330-4857-a7d2- d797d71c439f
</Value>
</ValueData>
</Values>
</PropertyData>
<PropertyData>
<IsPrivacyChanged>false</IsPrivacyChanged>
<Is ValueChanged>false</IsValueChanged>
<Name>AccountName</Name>
<Privacy>NotSet</Privacy>
<Values>
<ValueData>
<Value xsi:type="xsd:string">abc
</Value>
</ValueData>
</Values>
</PropertyData>
</GetUserProfileByNameResult>
</GetUserProfileByNameResponse>
</ soap:Body>
</soap:Envelope>
Please help me in this.
var propertyData = $(responseXML).find("PropertyData").filter(function(e){
return $(this).find("Name").text() == "AccountName";
});
var value = propertyData.length > 0 ? propertyData.find('Value').text() : '';
Since you are trying to retrieve user profile via SharePoint Web Services I would recommend to utilize SPServices library, it hides (almost)all the intricacies when working with SharePoint Web Services from JavaScript. The following example demonstrates how to retrieve user profile using GetUserProfileByName method and process the results:
function getUserProfile(accountName,completeFn) {
var userInfo = {};
$().SPServices({
AccountName: accountName,
operation: 'GetUserProfileByName',
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("PropertyData").each(function() {
userInfo[$(this).find("Name").text()] = $(this).find("Value").text();
});
completeFn(userInfo);
}
});
}
var loginName = 'i:0#.f|membership|username#contoso.onmicrosoft.com';
getUserProfile(loginName,function(info){
console.log(info);
});
You have to traverse through the xml nodes returned from the SPServices. I have written a function for getting the desired user profile property.
function getUPValue(x, p) {
var thisValue = $(x).SPFilterNode("PropertyData").filter(function() {
return $(this).find("Name").text() == p;
}).find("Values").text();
return thisValue;
}
Further to query the user property you just need to call like below,
getUPValue(xData.responseXML, "WorkEmail");
These article provides a detail overview of it over here

Amazon MWS API - SubmitFeed - OrderFulfillment - How to set ShipDate

I need to set Ship Date to current date, when I'm trying to confirm shipment. But I don't know where it to set. In documentation example don't have this attribute.
My XML code:
<?xml version="1.0" encoding="UTF-8"?>
<AmazonEnvelope xsi:noNamespaceSchemaLocation="amzn-envelope.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Header>
<DocumentVersion>1.02</DocumentVersion>
<MerchantIdentifier>XXXXXXXXXXXX</MerchantIdentifier>
</Header>
<MessageType>OrderFulfillment</MessageType>
<Message>
<MessageID>1</MessageID>
<OperationType>Update</OperationType>
<OrderFulfillment>
<AmazonOrderID>103-8280673-5282661</AmazonOrderID>
<FulfillmentDate>2015-01-22T06:30:00</FulfillmentDate>
<FulfillmentData>
<CarrierName>USPS</CarrierName>
<ShipperTrackingNumber>1234567890</ShipperTrackingNumber>
</FulfillmentData>
<Item>
<AmazonOrderItemCode>18531427322146</AmazonOrderItemCode>
<Quantity>1</Quantity>
</Item>
<Item>
<AmazonOrderItemCode>54419133385610</AmazonOrderItemCode>
<Quantity>1</Quantity>
</Item>
</OrderFulfillment>
</Message>
</AmazonEnvelope>
I'm trying to set Ship Date into <OrderFulfillment>, <FulfillmentData> - no result.
I'm trying to write it like <ShipDate>, <ShippingDate>, <ShippedDate> - no result.
Error returned:
<Result>
<MessageID>1</MessageID>
<ResultCode>Error</ResultCode>
<ResultMessageCode>25</ResultMessageCode>
<ResultDescription>We are unable to process the XML feed because one or more items are invalid. Please re-submit the feed.</ResultDescription>
</Result>
Maybe someone knows how to set Ship Date?
The above should fix it. And also, FulfillmentDate can also be the following format:
<FulfillmentDate>2015-01-22T06:30:00Z</FulfillmentDate>
And remove this tag:
<OperationType>Update</OperationType>
I am using same XML feed but without <OperationType>Update</OperationType>
and <item> tag because you don't need tag if you are shipping whole order.
and then I am doing following PHP code
$feed = trim($feed);
$marketplaceIdArray = array("Id" => array($MARKETPLACE_ID));
$feedHandle = #fopen('php://temp', 'rw+');
fwrite($feedHandle, $feed);
rewind($feedHandle); //Sets file pointer at beginning of file
$parameters = array(
'Merchant' => $MERCHANT_ID,
'MarketplaceIdList' => $marketplaceIdArray,
'FeedType' => '_POST_ORDER_FULFILLMENT_DATA_',
'FeedContent' => $feedHandle,
'PurgeAndReplace' => false, //Leave this PurgeAndReplace to false so that it want replace whole product in amazon inventory
'ContentMd5' => base64_encode(md5(stream_get_contents($feedHandle), true))
);
rewind($feedHandle);
$request = new MarketplaceWebService_Model_SubmitFeedRequest($parameters);
Not entirely positive on this but something that our feed contains is
<FulfillmentDate>2015-01-22T06:30:00+00:00</FulfillmentDate>
Instead of
<FulfillmentDate>2015-01-22T06:30:00</FulfillmentDate>
And that's the only thing that is not exactly the same as ours.
EDIT 1: I lied, there is a tag you have that I do not.
<OperationType>Update</OperationType>

Resources