Reuse Meteor template - Isolating events - coffeescript

I tried:
Template.skillsSearch = $.extend Template.skillsSearch,
rendered: ->
Session.set('s' + #_id, null)
Session.set('searchFocused' + #_id, null)
#_id worked before, I think because it was inside an each statement. Now I do not have this loop and # is {}(no _id in the object).
Suppose I have this:
body
+myTemplate
+myTemplate
How could I get an unique id per template instance? Or, how can I make unique session keys when reusing a template?

This is how I solved it:
template(name='father1')
with 'father1'
+reusedTemplate
template(name='father2')
with 'father2'
+reusedTemplate
template(name='reusedTemplate')
h1 #{aVariable}
Then in coffeescript:
Template.reusedTemplate = $.extend Template.reusedTemplate,
rendered: ->
# Here #data contains whatever you pass in with
# i.e. 'father1' and 'father2' respectively
aVariable: ->
# Here # contains whatever you pass in with
# i.e. 'father1' and 'father2' respectively

Related

Set map id using folium?

I m using folium (Django/Python), I create a map:
def create_map():
m = folium.Map(location=[9.934739, -84.087502], zoom_start=7 )
.....
folium creates the map in JS this way:
var map_e87b2e996ca04be59a5cfedabc0bf1ad = L.map(
"map_e87b2e996ca04be59a5cfedabc0bf1ad",
{
center: [9.934739, -84.087502],
.....
}
);
What I need is a way to set the my own id from folium(Django) instead of the on-the-fly id created by deafult: map_e87b2e996ca04be59a5cfedabc0bf1ad
I need to do this because I want to create custom events on the map that affects others part of the html file where this map is embedded .
The full id is a combination of map._name and map._id If you want to override it, you can use something like:
map = folium.Map()
map._name = "map_name"
map._id = "1"
then if you call it with map.get_name() it will be map_name_1
You could reverse the problem, and rather managing the name yourself, use the specific one folium assigns in your custom HTML/CSS/JS, which you can access via some_map.get_name().

programmatically setting cq:tags save blank value in the node in AEM

I am trying to programmatically extract data from a json string, converts into a string array and adding it as cq:tags property and corresponding values into a node, however when I do so, though cq:tags property is added but with blank values.
My node is something like this: /content/<my project node>/ContentPage/jcr:content
ResourceResolver resolver = CommonUtils.getResourceResolver(resourceResolverFactory);
String[] strValue = tagList.stream().toArray(String[]::new); // tagList has String values in form of array.
Resource resource = resolver.getResource(CONTENT_DATA_NODE);
if (resource != null) {
Node node = resource.adaptTo(Node.class);
if (node != null) {
NodeIterator nodeIterator = node.getNodes();
while (nodeIterator.hasNext()) {
innerNode = nodeIterator.nextNode();
innerNode.setProperty(CQ_TAGS, strValue);
innerNode.getSession().save();
}
}
}
and my sling user mapper service is mybundle.core:datawrite=userdatawriter , also if my resource resolverfactory is null, I get resolver from request directly.
Initially, I thought it could be an access issue, so I programmatically tried with any random property and value:
property: xyz , values: aa,bb,cc,dd
Which is written by my code without any issues,
it is only when programmatically adding cq:tags is when the problem arises. Though I can add cq:tags with any long list of values manually without any issues, either from page properties or in the crxde node itself.
What am I missing here and doing wrong in the code which can not only add cq:tags but also overwrite if cq:tags exists.
P.S: my AEM version is AEM 6.5 SP2
I can see the same thing happen in AEM 6.4.3. Immediately upon saving the property, the value can be read as expected. Here's a few quick examples I ran in the AEM Groovy console.
def node = getNode('/content/screens/we-retail/apps/virtual-showroom/en/jcr:content')
String[] arr = ['a', 'b', 'c'];
String[] tagArr = ['we-retail:equipment', 'we-retail:activity/biking']
node.setProperty('foo', arr)
println node.getProperty('foo').values // prints the a, b,c tags
node.setProperty('cq:tags', tagArr)
session.save()
println node.getProperty('cq:tags').values // prints the a, b,c tags
println node.getProperty('foo').values // prints the a, b,c tags
However, upon inspecting the page in CRXDE, I can see that the property is empty. This does not happen when the values you use match existing tags in AEM. For example:
def node = getNode('/content/screens/we-retail/apps/virtual-showroom/en/jcr:content')
String[] arr = ['a', 'b', 'c'];
String[] tagArr = ['we-retail:equipment', 'we-retail:activity/biking']
node.setProperty('foo', arr)
println node.getProperty('foo').values
node.setProperty('cq:tags', tagArr)
println node.getProperty('cq:tags').values // prints the we-retail tags
session.save()
println node.getProperty('foo').values
println node.getProperty('cq:tags').values // prints the we-retail tags
and the same values are visible in CRXDE.
This behaviour, I believe, is controlled by the Day CQ Tagging Service (com.day.cq.tagging.impl.JcrTagManagerFactoryImpl)
Unchecking the box will disable validation and allow you to persist those values. However, tagging a page with tags that don't exist will cause its own share of problems. Instead, I would suggest making sure to create those tags before using them.

Is there an easy way to add/remove/modify query parameters of a URL in Tritium?

I saw a very manual way of doing this in another post: How do I add a query parameter to a URL?
This doesn't seem very intuitive, but someone there mentioned an easier way to accomplish this using the upcoming "URL scope". Is this feature out yet, and how would I use it?
If you're using the stdlib mixer, you should be able to use the URL scope which provides helper functions for adding, viewing, editing, and removing URL params. Here's a quick example:
$original_url = "http://cuteoverload.com/2013/08/01/buttless-monkey-jams?hi=there"
$new_url = url($original_url) {
log(param("hi"))
param("hello", "world")
remove_param("hi")
}
log($new_url)
Tritium Tester example here: http://tester.tritium.io/9fcda48fa81b6e0b8700ccdda9f85612a5d7442f
Almost forgot, link to docs: http://tritium.io/current (You'll want to click on the URL category).
AFAIK, there's no built-in way of doing so.
I'll post here how I did to append a query param, making sure that it does not get duplicated if already on the url:
Inside your functions/main.ts file, you can declare:
# Adds a query parameter to the URL string in scope.
# The parameter is added as the last parameter in
# the query string.
#
# Sample use:
# $("//a[#id='my_link]") {
# attribute("href") {
# value() {
# appendQueryParameter('MVWomen', '1')
# }
# }
# }
#
# That will add MVwomen=1 to the end of the query string,
# but before any hash arguments.
# It also takes care of deciding if a ? or a #
# should be used.
#func Text.appendQueryParameter(Text %param_name, Text %param_value) {
# this beautiful regex is divided in three parts:
# 1. Get anything until a ? or # is found (or we reach the end)
# 2. Get anything until a # is found (or we reach the end - can be empty)
# 3. Get the remainder (can be empty)
replace(/^([^#\?]*)(\?[^#]*)?(#.*)?$/) {
var('query_symbol', '?')
match(%2, /^\?/) {
$query_symbol = '&'
}
# first, it checks if the %param_name with this %param_value already exists
# if so, we don't do anything
match_not(%2, concat(%param_name, '=', %param_value)) {
# We concatenate the URL until ? or # (%1),
# then the query string (%2), which can be empty or not,
# then the query symbol (either ? or &),
# then the name of the parameter we are appending,
# then an equals sign,
# then the value of the parameter we are appending
# and finally the hash fragment, which can be empty or not
set(concat(%1, %2, $query_symbol, %param_name, '=', %param_value, %3))
}
}
}
The other features you want (remove, modify) can be achieved similarly (by creating a function inside functions/main.ts and leveraging some regex magic).
Hope it helps.

Get typoscript values in extbase framework

I am new to extbase(MVC) Framework , How can we get typoscript values in our extension :
Eg : suppose if i have some typoscript values like:
plugin.tx_some-extname.somevlaueX = XXXX
plugin.tx_some-extname.somevlaueY = yyyy
plugin.tx_some-extname.somevlaueZ = zzzz
how will i get these values in a specific action of our controller .I hope this makes sense ??
Declare values in the settings scope (in the setup field) ie:
plugin.tx_some-extname.settings {
myXsetting = XXXX
}
So the all settings will be accesible in your plugin in $this->settings (as array) :
$valX = $this->settings['myXsetting'];
In TYPO3-7.6 + the whole TypoScript for an extension can be retrieved with
$typoScript = $this->configurationManager->getConfiguration( $this->configurationManager::CONFIGURATION_TYPE_FRAMEWORK);
where for the 1st parameter exist 3 different options:
$this->configurationManager::CONFIGURATION_TYPE_SETTINGS
$this->configurationManager::CONFIGURATION_TYPE_FRAMEWORK
$this->configurationManager::CONFIGURATION_TYPE_FULL_TYPOSCRIPT
optional for the function $this->configurationManager->getConfiguration() the extension-key can be given as 2nd parameter and the plugin-name as 3rd parameter. So the whole command looks like this:
$typoScript = $this->configurationManager->getConfiguration( $this->configurationManager::CONFIGURATION_TYPE_FRAMEWORK, $extensionKey, $pluginName );
Consider that the static template has to be included in the backend-template to return the desired output.
ConfigurationManager is an instance of
TYPO3\CMS\Extbase\Configuration\ConfigurationManager

Dijit/Dojo Inline - Filtering Select - DataStore

I am using an inline filteringselect with datastore, as follows:
I am using ABBR as the identifier and NAME as the value.
The filtering selects and works correctly, but I have two issues.
Firstly, how do I retrieve the ABBR for the selected option NAME?
I have tried various things, including .innerHTML but that only retrieves the selected item name, not the identifier.
Secondly, when using the datastore option, how can I choose the default selected item, for example if it was a scale of 1 to 10 and I wanted 5 as the default selection, how can I do this?
Any ideas and advice would be greatly appreciated.
Mank thanks
dojo.addOnLoad(function() {
// inline store
str = new dojo.data.ItemFileReadStore({data: storeData10})
var itmes;
// for storing the store's items
str.fetch({
onComplete:function(itms){
itmes= itms;
console.log(itms)
}
})
dijit.byId("cmbx1").store = str
dojo.connect(dijit.byId("cmbx1"), 'onChange',function(){
//console.log(arguments);
//get the value u c in screen
var whatvseeinselect = dijit.byId("cmbx1").focusNode.value;
dojo.forEach(itmes, function(itm){
//compare the value u c in screen with store itms. once matched take that item and get the name attr or other attr if u require..
if(whatvseeinselect == str.getValue(itm,"name")){
console.log(str.getValue(itm,"name"));
}
})
})
});
I'm not sure whether this is the correct way.
Hope this helps