How to get Dgraph uid_in to use variable inputs - dgraph

Im trying to change my DB engine to DGraph. Do I really need to change my aplication to use uid rather than using my current ID. I need to do a filter with multiple uid_in usages, and currently my application does this via an ID property. But it looks like I cannot use my ID property I need to use uid. But it looks like when you use uid_in function you cannot use variables.
What is the most efficient way of doing something like below:
{
SQ (func: eq(id, 10000)) {
dgraph.type
F as uid
}
{
Q2(func: has(id)) #filter(uid_in(edgefield, F)) {
dgraph.type
uid
id
expand(_all_) {
id
uid
dgraph.type
}
}
}
}

Now Dgraph latest (20.07.X) have support for uid map in the variable. e.g:
#filter(uid_in(edgefield, uid(F)))
See https://github.com/dgraph-io/dgraph/pull/5320

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().

Add formhandler field data to subject

My goal is to have the Formhandler log UID inside the Admin emails subject.
Inside of my email template I'm using
###value_tx_formhandler_log_inserted_uid### to insert a unique id.
I need to get this value into my Admin emails subject. E.g.
"Order ID: ###value_tx_formhandler_log_inserted_uid###"
I've read various forum posts, each do something different and I ended up with this snippet:
plugin.Tx_Formhandler.settings.predef.form {
# TEMPLATE MARKERS
name = Form1
templateFile = typo3template/typo3/ext/formhandler/form1/default.html
markers {
name = TEXT
name.value = Form1
}
finishers {
1.config {
class = Tx_Formhandler_Finisher_Mail
subject = TEXT
subject.value = ###GP:tx_formhandler_log_inserted_uid###
}
}
[...]
which just yields "{$formhandler.admin.subject}" as the subject.
I also tried other variations like
###LLL:tx_formhandler_log_inserted_uid### or tx_formhandler_log_inserted_uid
The backend field "subject" is empty.
Pasting the HTML placeholder into the backend field didn't work either.
I can't get this to work.
In what way can you access the id you want to insert?
From the notation GP:tx_formhandler_log_inserted_uid I would assume a GET/POST value.
For using this value in typoscript you need to do it like this (or similar: dataWrap):
subject = TEXT
subject.data = GP:tx_formhandler_log_inserted_uid
subject.noTrimWrap = |Order ID: ||
The notation LLL:tx_formhandler_log_inserted_uid would be a language specific text (you would also insert by .data) but it would be a static text for each language.
After a lot of trial and error, I got it working.
First of all, I forgot to specify that I want to configure the admin mail.
Adding admin { fixed the problem of getting only {$formhandler.admin.subject}.
The UID value itself can be accessed with GP:formhandler|tx_formhandler_log_inserted_uid
I combined that with the noTrimWrap as suggested by #bernd-wilke-πφ
The final snippet looks like this:
finishers {
1 {
class = Tx_Formhandler_Finisher_Mail
config {
admin {
subject = TEXT
subject.data = GP:formhandler|tx_formhandler_log_inserted_uid
subject.noTrimWrap = |Order number: ||
}
}
}
}

xPages REST Service Results into Combobox or Typeahead Text Field

I've read all the documentation I can find and watched all the videos I can find and don't understand how to do this. I have set up an xPages REST Service and it works well. Now I want to place the results of the service into either a combobox or typeahead text field. Ideally I would like to know how to do it for both types of fields.
I have an application which has a view containing a list of countries, another view containing a list of states, and another containing a list of cities. I would like the first field to only display the countries field from the list of data it returns in the XPages REST Service. Then, depending upon which country was selected, I would like the states for that country to be listed in another field for selection, etc.
I can see code for calling the REST Service results from a button, or from a dojo grid, but I cannot find how to call it to populate either of the types of fields identified above.
Where would I call the Service for the field? I had thought it would go in the Data area, but perhaps I've just not found the right syntax to use.
November 6, 2017:
I have been following your suggestion, but am still lost as can be. Here's what I currently have in my code:
x$( "#{id:ApplCountry}" ).select2({
placeholder: "select a country",
minimumInputLength: 2,
allowClear : true,
multiple: false,
ajax: {
dataType: 'text/plain',
url: "./Application.xsp/gridData",
quietMillis: 250,
data: function (params) {
return {
search:'[name=]*'+params.term+'*',
page: params.page
};
},
processResults: function (data, page) {
var data = $.map(data, function (obj) {
obj.id = obj.id || obj["#entityid"];
obj.text = obj.text || obj.name;
return obj;
});
},
return {results: data};
}
}
});
I'm using the dataType of 'text/plain' because that was what I understood I should use when gathering data from a domino application. I have tried changing this to json but it makes no difference.
I'm using processResults because I understand this is what should be used in version 4 of select2.
I don't understand the whole use of the hidden field, so I've stayed away from that.
No matter what I do, although my REST service works if I put it directly in the url, I cannot get any data to display in the field. All I want to display in the field is the country code of the document, which is in the field named "name" (not my choice, it's how it came before I imported the data from MySQL.
I have read documentation and watched videos, but still don't really understand how everything fits together. That was my problem with the REST service. If you use it in Dojo, you just put the name of the service in a field on the Dojo element and it's done, so I don't understand why all the additional coding for another type of domino element. Shouldn't it work the same way?
I should point out that at some points it does display the default message, so it does find the field. Just doesn't display the country selections.
I think the issue may be that you are not returning SelectItems to your select2, and that is what it is expecting. When I do something like you are trying, I actually use a bean to generate the selection choices. You may want to try that or I'm putting in the working part of my bean below.
The Utils.getItemValueAsString is a method I use to return either the string value of a field, or if it is not on the document/empty/null an empty string. I took out an if that doesn't relate to this, so there my be a mismatch, but I hope not.
You might be able to jump directly to populating the arrayList, but as I recall I needed to leverage the LinkedHashMap for something.
You should be able to do the same using SSJS, but since that renders to Java before executing, I find this more efficient.
For label/value pairs:
LinkedHashMap lhmap = new LinkedHashMap();
Document doc = null;
Document tmpDoc = null;
allObjects.addElement(doc);
if (dc.getCount() > 0) {
doc = dc.getFirstDocument();
while (doc != null) {
lhmap.put(Utils.getItemValueAsString(doc, LabelField, true), Utils.getItemValueAsString(doc, ValueField, true));
}
tmpDoc = dc.getNextDocument(doc);
doc.recycle();
doc = tmpDoc;
}
}
List<SelectItem> options = new ArrayList<SelectItem>();
Set set = lhmap.entrySet();
Iterator hsItr = set.iterator();
while (hsItr.hasNext()) {
Map.Entry me = (Map.Entry) hsItr.next();
// System.out.println("after: " + hStr);
SelectItem option = new SelectItem();
option.setLabel(me.getKey() + "");
option.setValue(me.getValue() + "");
options.add(option);
}
System.out.println("About to return from generating");
return options;
}
I ended up using straight up SSJS. Worked like a charm - very simple.

Automatically set author and email in tt_news

I know I can configure tt_news to automatically set author and email to a given value, like this:
TCAdefaults.tt_news.author = full name
TCAdefaults.tt_news.author_email = name#domain.tld
But could I retrieve the name an email from the info of the currently logged BE user instead?
To meake it possible to fill the values on every change (if empty), you need to register a hook somewhere ie, in your own extension
typo3conf/ext/yourext/hooks/class.tx_ttnews_hooks.php
class tx_ttnews_hooks {
// hook for prefilling TCA values
function getSingleField_preProcess($table, $field, &$row, $altName, $palette, $extra, $pal, $pObj) {
switch($field) {
case 'author_email':
if($row[$field] == '') {
$row[$field] = $GLOBALS['BE_USER']->user['email'];
}
break;
case 'author':
if($row[$field] == '') {
$row[$field] = $GLOBALS['BE_USER']->user['realName'];
}
break;
}
}
}
and then add this into typo3conf/ext/yourext/ext_localconf.php:
$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tceforms.php']['getSingleFieldClass'][]
= 'EXT:yourext/hooks/class.tx_ttnews_hooks.php:tx_ttnews_hooks';
There is an extension that does what you want. I haven't used it myself, but the description sounds pretty promising.
As another solution, you may write a little bit of php code that adds a dynamic user ts. I only found an example in German, but maybe that's helpful anyway.

KRL and Yahoo Local Search

I'm trying to use Yahoo Local Search in a Kynetx Application.
ruleset avogadro {
meta {
name "yahoo-local-ruleset"
description "use results from Yahoo local search"
author "randall bohn"
key yahoo_local "get-your-own-key"
}
dispatch { domain "example.com"}
global {
datasource local:XML <- "http://local.yahooapis.com/LocalSearchService/V3/localsearch";
}
rule add_list {
select when pageview ".*" setting ()
pre {
ds = datasource:local("?appid=#{keys:yahoo_local()}&query=pizza&zip=#{zip}&results=5");
rs = ds.pick("$..Result");
}
append("body","<ul id='my_list'></ul>");
always {
set ent:pizza rs;
}
}
rule add_results {
select when pageview ".*" setting ()
foreach ent:pizza setting pizza
pre {
title = pizza.pick("$..Title");
}
append("#my_list", "<li>#{title}</li>");
}
}
The list I wind up with is
. [object Object]
and 'title' has
{'$t' => 'Pizza Shop 1'}
I can't figure out how to get just the title. It looks like the 'text content' from the original XML file turns into {'$t' => 'text content'} and the '$t' give problems to pick().
When XML datasources and datasets get converted into JSON, the text value within an XML node gets assigned to $t. You can pick the text of the title by changing your pick statement in the pre block to
title = pizza.pick("$..Title.$t");
Try that and see if that solves your problem.
Side notes on things not related to your question to consider:
1) Thank you for sharing the entire ruleset, what problem you were seeing and what you expected. Made answering your question much easier.
2) The ruleset identifier should not be changed from what AppBuilder or the command-line gem generate for you. Your identifier that is currently
ruleset avogadro {
should look something more like
ruleset a60x304 {
3) You don't need the
setting ()
in the select statement unless you have a capture group in your regular expression
Turns out that pick("$..Title.$t") does work. It looks funny but it works. Less funny than a clown hat I guess.
name = pizza.pick("$..Title.$t");
city = pizza.pick("$..City.$t");
phone = pizza.pick("$..Phone.$t");
list_item = "<li>#{name}/#{city} #{phone}</li>"
Wish I had some pizza right now!