How to implement YQL paging? - javascript

I've read the YQL guide, and I keep reviewing http://developer.yahoo.com/yql/guide/yql-o...entables-paging and I have been looking at a few examples, but I'm still left pretty confused how YQL paging works.
The problem that I am trying to tackle is creating a YQL open data table for the Mozilla labs Jetpack Gallery's jetpacks pages http://jetpackgallery.mozillalabs.com/jetpacks
You flip through the pages of jetpacks with the ?page query variable and there is an order_by query variable. You can only see 10 results per page.
Questions:
List item
Should I use or ?
How do I specify the query parameter that indicates the page? in this case it is the 'page' query parameter.
I am assuming I should use: <urls><url>http://jetpackgallery.mozillalabs.com/jetpacks</url></urls> is this correct?
In the execute element, I will need to extract the details for each jetpack on the page? if so how would I organize that for the response.object?
Can anyone provide some help? or perhaps point to a data table that I can look at as a reference? or better documentation on how paging works?

Firstly, you should be looking at the paging model (Your link got compressed above, so I'm just putting it here.
When you use the paging with no <execute></execute> block specified, it will be used in the query string with the URL specified in <url></url>. Just play with the Flickr Photo Search Example, you have to run it in the Console with Diagnostics turned on to look at the changes in the URL. The id attribute is used to insert the number in the query. Just to illustrate here, the paging portion looks like this:
<paging model="page">
<start id="page" default="0" />
<pagesize id="per_page" max="250" />
<total default="10" />
</paging>
For example, querying
select * from flickr.photos.search(10,20) where has_geo="true"`
The URL used was http://api.flickr.com/services/rest/?method=flickr.photos.search&has_geo=true&page=1&per_page=30. As you can see, it actually took the page=1 but asked for per_page=30 and internally truncated the first 10 results so that you get an offset of 10 and a total of 20 results.
The reason why YQL did this is because the model selected is page.
Another example, if you attempt to do this:
select * from flickr.photos.search(249,2) where has_geo="true"
YQL will retrieve both ...&page=1&per_page=250 and ...&page=2&per_page=250 (I've shortened the urls for illustration) as expected to get the results.
The paging variables are also defined in the global scope if you use JavaScript in <execute></execute> section. You can see this being used in the flickr.photos.astro OpenData Table.
I guess that should answer the question for you, since I see that on GitHub, you have been working on how to extract the pages using XPath.
For your case you should have something like:
<paging model="page">
<start id="page" default="1" />
<pagesize id="per_page" max="10" />
<total default="10" />
</paging>
The per_page would be in your internal query but it's used for the YQL to determine the queries needed. Then in your JavaScript could probably do something like:
y.query(
"select * from html where url=#url",
{url: "http://jetpackgallery.mozillalabs.com/jetpacks?page=" + page}
);

Related

Where is extra encoded query coming from and what does it mean?

I've the following in a SI
var serviceAsset=new GlideRecord('u_service_asset');
serviceAsset.addQuery('u_service',service_sys_id);
serviceAsset.addNotNullQuery('u_parent');
serviceAsset.query();
gs.log(serviceAsset.getEncodedQuery());
This prints the following in the logs
u_service=305baa6fdb17d0d44bb6e126059619e1^u_parent!=NULL^sys_idNotValidnull^ORsys_idNotValidnull
What does sys_idNotValidnull mean and why is it getting added as an OR condition?
I've a "Query" Business Rule on the table but that code doesn't seem to be referencing the above.
Business Rule code
(function executeRule(current, previous /*null when async*/) {
var serviceassetquery;
serviceassetquery = current.addEncodedQuery("u_sourcesystem!=Wholesale^ORu_sourcesystem=NULL");
})(current, previous);
So the
sys_idNotValidnull^ORsys_idNotValidnull
part was being added by the Business Rule. And the reason for sys_idNotValidnull presence was because the column u_sourcesystem was NOT present on the table u_service_asset
Duh! It was an invalid column after all that caused all the issue.
Assuming sys_idNotValidnull means "referred sys_id is not exist".
The easiest and best way to get an encoded query as follows:
Navigate to the table.
Build filter and run
Right-click on the bread crumb (You will see copy query option that will give proper encoded query, Please refer to the screenshot attached)
Example of copied query: "active=true^state!=10^ORstate=^sys_idISNOTEMPTY"

How can I get combinationId from array of id_attributes

I use the Cart::updateQty() function in my module for prestashop. I'd like also to use the $id_product_attribute parameter, but I'm unable to find the desired value for this when I have array of id_attributes only.
I need behavior similar to the default selecting product attributes on the product page and then adding it to cart, but I'd like to do this on the server side.
What I was able to find out is that when I'm changing a product attributes on the product page, the html input with id="idCombination"
#idCombination
is being filled with a proper value and then it's being POST'ed with ajax to the server. Unfortunately, I cannot work out how the actual searching is being made and how to do this in js or php code.
Any help would be appreciated.
In a default product page these combinations are transferred with a variable $combination within a ProductController.php with a method assignAttributesGroups() and then defined a js variable inside product.tpl via condition
{if isset($combinations) && $combinations}
{addJsDef combinations=$combinations}
{/if}
after that everithing going on in a product.js file which do all switch job and substitute id="idCombination" after each changing.
So you can to repeat a default approach to implement your requirements even though it looks a bit complicated. Also, I think you don't need such a completed $combination variable with all that information and you can add only that what you need. I hope it clarifies you a direction to work.

SAPUI5: DOM change commands interfere with each other

My List Binding:
<StandardListItem
title="{NewProposalTitle_DE}"
description="Stream: {Stream}, Time: {starttime}"
press="handlePress"
>
I want to change the title's binding to title="{NewProposalTitle_EN}" from the oData model, when the user is english.
I looked into expression binding but this doesn't seem to work with dynamic data:
title="{= {language} === "de" ? {NewProposalTitle_DE} : {NewProposalTitle_EN} }
So I tried a different approach where I iterate through all items from a SAPUI5 List and want to change the (german) title attribute to the english one if the language of the user is english and add a number to the Item's counter attribute.
var Items = this.getView().byId("idList").getItems();
for (var i = 0; i < Items.length; ++i) {
if(language === "en"){
Items[i].setTitle(oData.results[i].Title_EN);
}
Items[i].setCounter(numbers[i]);
}
If the language is german, everything works like a charm and the counter is set correctly, but if the language is english, things get fishy.
When the Title gets updated with the english title, the counter is set back to 0 (default). Even more strange, if the german and the english version of the title are equal (so no change needs to be done) the counter is still shown (i assume SAPUI5 is smart enough to recognize, that no change needs to be done).
I encountered the same problem, when I tried to add a Style Class for the Item:
Items[i].addStyleClass("blue");
again, as long as the title doesn't get changed it works.
I tried changing the order in every possible way without success.
I also tried to setCounter and addStyleClass and omitted the setTitle command but only one affected the DOM.
Please don't translate this way! You might end up overwriting data in your other models. Use the i18n resource models to do your translations! It's the go-to, built in way to translate any text in your application to any other language.
SAPUI5 loads the right ones by default.
If your browser's language is set to German, it will try to load i18n_de_DE.properties first, (not sure of the exact name for German, you'll find out if you look at the network tab of the browser. Could be just _de.properties if there's such a thing as _de_AT or something) before falling back to the default i18n.properties.
If you start an application from any of the usual IDE's like webIDE or eclipse, the model is already created for you.
The idea is to set the title to an identifier, like
<Label text={i18n>MY_TRANSLATABLE_TEXT} />
In your i18n.properties file, you might default to English:
MY_TRANSLATABLE_TEXT=Customer
While your German properties file has
MY_TRANSLATABLE_TEXT=Kunde
The translation is then done for you without trying to mess with the titles directly.
Thank you all for your answers! I figured out a solution for my problem:
In the controller, I check for the users language and update the property binding:
Items[i].bindProperty("title", "NewProposalTitle_EN");
It may not be the most elegant or correct way, but it works for me (at the moment).
I hope you all have a great day!
title="{= {language} === "de" ? {NewProposalTitle_DE} : {NewProposalTitle_EN} }
There are some syntactical issues in your expression binding. Try with this:
title="{= ${language} === 'de' ? ${NewProposalTitle_DE} : ${NewProposalTitle_EN} }"
Besides that, I don't think it's a good idea to put translatable texts into the entity set as properties. I'd recommend to define field label (e.g. for the NewProposal property) translated in each language as a UI text annotation
(such as sap:label).
When an ODataModel is created, the service metadata will be requested immediately with the corresponding language query sap-language =<automatically detected>.
Thus the property labels come already translated from the backend system, contained in the metadata, which you can bind in the view via special property binding syntax. E.g.:
In Metadata
<EntityType Name="BusinessPartner" sap:content-version="1">
<Key>
<PropertyRef Name="BusinessPartnerID" />
</Key>
<Property Name="BusinessPartnerID" Type="Edm.String"
sap:label="Business Partner ID"
sap:creatable="false"
sap:updatable="false"
/>
...
</EntityType>
Property Metadata Binding
<StandardListItem
title="{myModelName>BusinessPartnerID/##sap:label}"
press=".handlePress"
/>

sharepoint Online/365 Jquery, Set Lookup Column Not working e.i ($("select[Title='Column']")

I've been doing some work on Sharepoint Online/365 and have got stuck trying to set the value of a lookup or choice column in NewForm.aspx
Narrowed my problem down to not being able to set lookup/Choice Columns
I have simplified a code on my page down to
//Phase being a Choice Column & Closure a case sensitive valid option
$("select[title='Phase']").val("Closure");
//ProjectName being a Lookup Column & Test2 a case sensitive valid entry in the list
$("select[title='ProjectName']").val("Test2");
I have no problem setting text fields as the following code works fine on a text field I created
$("input[title='TextField']").val("Test2");
I have used the following Jquery libraries 1.7.2/min.js and 1.11.3
Not sure whether you used _spBodyOnLoadFunctionNames.push() method for your logics. Usually you have to wait all SharePoint DOM objects are loaded and then to execute your jQuery code. If you used SharePoint JavaScript library, you probably needs to call ExecuteOrDelayUntilScriptLoaded() to make sure your call is called after curtain SharePoint .js files are loaded.
First Thanks "Verona Chen" and " DIEGO CARRASCAL" because of who i've learnt a few other tricks in SharePoint which will help with other projects.
My original script before the question was trying to use a query string to populate a field in newform.aspx (which i have done on sharepoint 2013 with code i have found here on)
Unforuntaly with sharepoint online/365 This code was no longer working.
This code has fixed my issue (though it does change how a few previous pages are constructed)
Appologies if this doesn't directly answer the above question (as this was me trying to breakdown the overall issue i was having into something simpler and easier to address based on me narrowing down the issue in my original code) however as I am now up and running, it seems only polite to post the outcome.
Prior to code, i have a projects list with a "ProjectName" field. I was sending the field name into a URL and querystring to get mylist/newform.aspx?ProjectName=Test2
I was then trying to pull that Test2 into the lookup field (liked to the project list) "ProjectName" in the list "MyList"
But even when loading the function for my old script with _spBodyOnLoadFunctionNames.push() it wasn't working.
After playing with this for a while and after some looking around i found this peice of code
<script type="text/javascript">
(function () {
var ctx = {};
ctx.Templates = {};
ctx.Templates.Fields = {
'ProjectName': {
'NewForm': renderTaskCategory
}
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctx);
})();
function renderTaskCategory(ctx) {
//extract cat parameter from a query string
var GetProjID = GetUrlKeyValue('ProjID');
//set lookup field value
ctx.CurrentFieldValue = GetProjID;
//default template for rendering Lookup field control
return SPFieldLookup_Edit(ctx);
}
</script>
This means that i have to change my previous url builds to create mylist/newform.aspx?ProjID=2
This script then finds item ID 2 (which happens to be test2 in this case) and puts the title of item 2 in my lookup field ProjectName
Thanks again to those that helped earlier.
And apologies again if this doesn't directly answer the question i originally asked.

php remove single variable value pair from querystring

I have a page that lists out items according to numerous parameters ie variables with values.
listitems.php?color=green&size=small&cat=pants&pagenum=1 etc.
To enable editing of the list, I have a parameter edit=1 which is appended to the above querystring to give:
listitems.php?color=green&size=small&cat=pants&pagenum=1&edit=1
So far so good.
When the user is done editing, I have a link that exits edit mode. I want this link to specify the whole querystring--whatever it may be as this is subject to user choices--except remove the edit=1.
When I had only a few variables, I just listed them out manually in the link but now that there are more, I would like to be able programmatically to just remove the edit=1.
Should I do some sort of a search for edit=1 and then just replace it with nothing?
$qs = str_replace("&edit=1, "", $_SERVER['QUERY_STRING']);
<a href='{$_SERVER['PHP_SELF']}?{$qs}'>return</a>;
Or what would be the cleanest most error-free way to do this.
Note: I have a similar situation when going from page to page where I'd like to take out the pagenum and replace it with a different one. There, since the pagenum varies, I cannot just search for pagenum=1 but would have to search for pagenum =$pagenum if that makes any difference.
You can use parse_str() to parse the query string, remove the unwanted parts and build the new one via http_build_query() like this
parse_str($_SERVER['QUERY_STRING'], $params);
unset($params['edit']);
$new_query_string = http_build_query($params);

Categories

Resources