If I'm iterating through an ArrayModel using .each_with_index, is there a way to make rendering decisions based on the current index compared with the results of a Promise (at the moment, this comparison returns an error about comparing a Numeric with a Promise)?
In practice, I have a list that renders ten items by default, and a user can ask to render 20, 30, etc. If I have the user selection change the query, then the entire list re-renders, which is slow. If I have their selection change {{ if index < selected_limit }} from false to true, then only the newly-showing items re-render. But this only works if comparison of index against a Promise (selected_limit) can be done. Is there a way to do that?
Yes, if bindings can take promises, so what you can do is return a new promise that resolves to true or false and the if binding will update once that promises resolves.
{{ store.todo.each_with_index do |todo, index| }}
{{ if todo.selected_limit.then {|limit| index < limit } }}
....
{{ end }}
{{ end }}
Let me know if that makes since. Calling .then on the promise will pass in the value as an argument once it resolves, but the result of .then {...} will be a new promise.
You should be able to use .value for the comparison, that's how I did it in a project myself.
{{ store.players.each do |player| }}
{{ unless player == current_player.value }}
<table class='player'>
<tr><td>{{ player.name }}</td></tr>
<tr><td><button e-click='add_vote(player.id)'>+1</button></td></tr>
</table>
{{end}}
{{end}}
Related
In a R plumber script in which I use future I need to assign some variables to the global environment (so that a variable created in one API can be retrieved from another API) but it does not work as expected.
I created a simple example. Here you can see the main script to run in R:
### Set the asynchronous coding
library(promises) ; library(future)
future::plan("multisession")
## Plumber app
library(plumber)
pr <- pr("APIs_TestAsync.R")
pr %>% pr_run()
and here the script to save as "APIs_TestAsync.R":
#* Test 1
#* #get test1
#* #serializer unboxedJSON
#* #tag TestFuture
function() {
# Create a dataset
df<-data.frame(A=c("a", "a", "a", "b", "b", "c"), B=c(1,2,3,4,5,6))
assign("Test1", df, .GlobalEnv)
return(
list(SUM=sum(df$B))
)
}
#* Test 2
#* #get test2
#* #serializer unboxedJSON
#* #tag TestFuture
function() {
# Create a future promise
Prom<-future({
# Wait for 10 seconds (needed to test the asynchronous functions)
Sys.sleep(10)
# Create a dataset
df<-data.frame(A=c("a", "a", "a", "b", "b", "c"), B=c(1,2,3,4,5,6))
assign("Test2", df, .GlobalEnv)
# Store the list in Prom
return(
list(SUM=sum(df$B))
)
}, seed=T) # Close future promise
return(Prom) # Return Prom to the API
}
You'll see that the first API (not using future) manages to assign Test1 to the global environment but that the second API does not assign Test2.
I tried several ways of assignment, different environment names, explored the futureAssign function but did not manage to make it work...
If you have any idea it would be greatly appreciated!
I have a json field that is either absent or is set to true. But in my document I want it to show up as "Yes" or "No". I tried the following conditional expression ():
{% conditional-section expr(`my_field` = true) %}Yes{% end-section %}{% conditional-section expr(`my_field`!= true) %}No{% end-section %}
But when I call the Adobe Document Generation API, the PDF I get still has these template tags. For some reason it is not being detected. How can I achieve this?
I know I asked a question above in the comment, but I think I can take a stab at answering this now. So right now there is not a way to say "if a value is NOT present or present and equal to yes." There's a few ways you can handle this, but I think the easiest would be to change your data. To be clear, I don't mean change your database or anything, but keep in mind that before you call our API, you can massage the data a bit. So if the absence of my_field means yes, I'd do something like this (JavaScript):
if(!mydata.my_field) {
mydata.my_field = 'yes';
}
You could then do something like this:
{% conditional-section expr(my_field = "yes") %}
Yes
{% end-section %}
{% conditional-section expr(my_field = "no") %}
No
{% end-section %}
However, this will not be on the same line. As I said, this is a known issue. If you need it as such, again, I'd use the idea of massaging your data first. You could do something like this (again, JavaScript, but could be done in any language):
if(!mydata.my_field) {
mydata.my_field = 'yes';
}
if(mydata.my_field === 'yes') mydata.my_field_value = 'Yes';
else mydata.my_field_value = 'No';
All I did there was, based on the value of my_field, set another variable. In your Word template you can then simplify even more by just using {{my_field_value}}
With Document Generation being so flexible, you've got multiple different ways of solving a problem.
I have found this works for me:
{{my_field ? "Yes" : "No"}}
Is it possible to give multiple values as input in a string parameter in the Jenkins job..?
If yes, what will be the syntax and how are we calling that in a for loop so the values take one after the other.?
This is for a declarative job in Jenkins.
Thank you for the help in advance
parameters {
string(name: "usernames", value: list.join (","), description: "enter the user names")
}
stages{
need the syntax for this --> //for user in usernames list
do
$echo ---> username
this username which print will be called in my curl command one after the other.
so please do help me with the right path
Generally it is only possible to pass one string.
That being said, since you are using strings you can encode whatever data you want in them.
Suppose you want to pass the pipeline a list of strings myList with values ['foo', 'bar', 'baz']. In the calling job you could simply do:
build ... parameters(string(name: "myString", value: myList.join(",")))
which passes 'foo, bar, baz' to the called job. There you could parse it out again:
params.myString.split(',') // results in ['foo', 'bar', 'baz']
To iterate over this, you could use a for-in loop or a list function like each or collect.
In order to iterate over all the elements you receive you can use the each method
stages {
stage("Iterate over parameters"){
script{
def userNames = params.userNamesString.split(',')
userNames.each { user ->
echo "$user"
}
}
}
}
Alternativly (instead of the userNames.each block you can just use a for-in statement:
for(userName in userNames){
echo "$userName"
}
For more informations on this please have a look at the links I included in my previous answer.
Is there a helper function in phalcon (volt) to create Links to routes with GET-Parameters ? I have pagination-links on which I want to add ?cat=category and ?year=year depending on whether they are set or not.
First
Previous
Next
Last
so that
http://site.tld/tags/xyz?page=2
would become:
http://site.tld/tags/xyz?cat=a&year=b&page=2
or this, if cat is not set or null:
http://site.tld/tags/xyz?year=b&page=2
edit
this way it seems to work:
First
Previous
Next
Last
the rest happens in the controller
IMO it's easier to do that in the controller than using volt.
First, generate the base URL for your pagination links with the URL Service:
$pagingUrl = $this->url->get('tags/' . $tagname->tag);
Now you can get 'cat' and 'year' with something like $this->request->getPost('cat'); to check if it's set and append it to $pagingUrl as GET parameters. Leave a '&page=' at end of the $pagingUrl to easily append the page number later.
Set $page and $pagingUrl as variables for your view so you can easily access it from volt:
$this->view->setVar('page', $page);
$this->view->setVar('pagingUrl', $pagingUrl);
Finally in the view you could use something like that:
{{ link_to(pagingUrl ~ '1', 'First') }}
{{ link_to(pagingUrl ~ page.before, 'Previous') }}
{{ link_to(pagingUrl ~ page.next, 'Next') }}
{{ link_to(pagingUrl ~ page.last, 'Last') }}
EDIT
The solutions above seems hackish because Phalcon designers aimed to work more with clean URLs than explicit GET parameters. If you were passing your parameters this way, your TagController could have an action that supports pagination like this:
class TagController
{
...
public function ListAction($page = 1, $category = 'default-cat', $year = 1997)
{
...
Working that way you can easily create links like these:
tags/list
tags/list/2/stuff
tags/list/9/stuff/2014
http://jsfiddle.net/x3azn/s7gFD/1/
I have a filter that filters user input, but once every three times or twice, if you type a letter in the box, it would go through. try typing the following if you dont' understand what I mean.
ddd
asdfgg
vckzvdd
qwertt
hopefully u get the message.
and it wont appear ifyou type
dfadfasdf,
which is good but we cannot assume.
Your parser is, for some reason, not executed on duplicate key presses. So if you type "aa" or "bb" or "cc", you end up with "a", or "b", or "c" left in the box with the parser having never run. I can't really answer why that's happening, but I can suggest an alternative:
Is there a reason you're coupling a filter with this directive? You can just as easily accomplish the same task with the directive alone, and (to me anyway) it seems cleaner:
app.directive('filteredInput', function($filter){
var dirLink = function(s,e,a,c){
console.log(s);
console.log(a);
s.$watch(a.ngModel, function(v) {
//if (pattern.indexOf('numbers') != -1){
s[a.ngModel] = s[a.ngModel].replace(/[^\d.]/g, "");
//}
});
}
return{
require: 'ngModel',
scope: true,
link: dirLink
}
});
http://jsfiddle.net/s7gFD/2/