How can I get children of a node? - umbraco

How can I get all the children for the News item (in the standard project) in a partialview (razor)?
I've tried:
#{
var homePage = CurrentPage.AncestorsOrSelf(1).First();
var newsItems = homePage.Children.Where(x => x.GetProperty("Name").Value == "News");
}
But I get an error that states I can't do lambda expression, whitout casting it. "News" is a node in my webpage holding children and I want to create a macro listing the children. How and what can I cast it to?

Currently, you are looking for children of the home page, named "News". I think you want to go one level deeper.
I reccomend this approach:
// 1- Get root node
var site = Model.Content.AncestorOrSelf("Site");
// 2- Get news node
var news = site.Descendant("News");
var newsItems = news.Children;
Here you use the document type alias to traverse your tree, this is much more reliable than using names, as those can change. This of course may require to rework some elements.
Hope this helps!

Try this to get all of the news nodes that are children of homepage:
var newsItems = homePage.Children.Where("Name = #0", "News");
Then iterate through the children of News:
foreach (var newsChild in newsItems)
You could skip the first step if you already know the ID of your news node like so:
var newsNode = Umbraco.Content(1234);
This page has plenty of examples:
http://our.umbraco.org/documentation/reference/querying/DynamicNode/Collections#

Related

How to bind an entity object on a Detail page

I am developing a master detail Fiori app using SAP UI5. As the details contains more than 40 columns, I made separate OData services for master & detail.
In Master page, data are coming correctly. Now my task is that on any table line, when user clicks on Detail, next page will be open with details base on two key values of master table.
I'm getting two keys in variables in detail page as follows and it is working fine:
var spayid = jQuery.sap.getUriParameters().get("payid");
var spaydt = jQuery.sap.getUriParameters().get("paydt");
Next, I have created two filters as follows which is also working fine.
var filter1 = new Filter({
path: "Laufi",
operator: FilterOperator.EQ,
value1: spayid
});
var filter2 = new Filter({
path: "Laufd",
operator: FilterOperator.EQ,
value1: spaydt
});
Now I am calling OData service which is also working fine:
var oODataModel = new ODataModel("proxy/http/FIORI-DEV.abc.com:8000/sap/opu/odata/sap/ZASA_FI_pay_D_SRV?sap-client=100", {
json: true,
useBatch: false
});
this.getView().setModel(oODataModel);
I don't know now how to filter data. What should be included in above so that it will filter data according to my filters filer1 and filter2? I have tried following but it is not working.
filters : [ filter1, filter2 ],
json: true,
useBatch: false
I am very good in ABAP but not an expert in SAPUI5. I am in learning phase.
First of all, I was thinking to pass parameters on OData service so that only the required data are fetched. Means my OData call should be like this:
new ODataModel("proxy/http/FIORI-DEV.abc.com:8000/sap/opu/odata/sap/ZASA_FI_PAYMENT_D_SRV/PdetailSet(Laufi= spayid, Laufd = spaydt)?sap-client=100");
But this seems not like possible.
Second option is that I will fetch whole details in OData service and then during binding to table I will apply filter.
The purpose of the sap.ui.model.Filter class is usually to apply filters to lists on the UI. For example, if you have a list of items and you want to limit that list to a subset of items which fulfills certain criteria.
But what you have here appears to be a classic master-detail scenario where you have a list of items and then when the user selects one show more information about that one item.
The usual solution for such a scenario is to assign the full model to the detail-view and then use an element binding (also known as "context binding") on the view to tell it which item to display.
When the source of the item is a click on an element which already had an element binding, then you can actually retrieve the correct binding path from the click event and just apply it to your detail-view.
From one of the official demos:
onItemSelected: function(oEvent) {
var oSelectedItem = oEvent.getSource();
var oContext = oSelectedItem.getBindingContext("products");
var sPath = oContext.getPath();
var oProductDetailPanel = this.byId("productDetailsPanel");
oProductDetailPanel.bindElement({ path: sPath, model: "products" });
}
When you don't have any convenient way to get an element path from, then you have to construct one yourself:
var detailPanel = this.getView().byId("idOfDetailPanel");
detailPanel.bindElement("PdetailSet(Laufi = " + spayid +", Laufd = " + spaydt + ")");
The latter code snippet does of course assume that the oData-service actually supports access with a key consisting of laufi and laufd. This is decided by:
The definition of the key fields of the entity type in the SAP Gateway Service Builder (transaction SEGW)
The ABAP implementation of the method get_entity of the data provider class of that oData-service.

How do I get list of sharepoint items in a folder using Microsoft Graph?

I'm able to make graph calls to get all items in a list but how can we get/filter items inside a list folder ?
It seems not a direct way to achieve it. If I filter using below, I get the error "Field 'FileDirRef' cannot be referenced in filter or orderby as it is not indexed.".
&filter=fields/FileDirRef eq '/sites/lz/Lists/cl/folder'
As a workaround, we can get the list items and then filter the items base on the FileDirRef field in code.
https://graph.microsoft.com/v1.0/sites/lz.sharepoint.com,{Site GUID},{Web GUID}/lists/{List GUID}/items?expand=fields(select=id,Title,FileDirRef)
You could utilize the following query to retrieve items under a sub folder:
https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/drive/root:/{folder-url}:/children
Here is an example using Microsoft Graph .NET Client Library:
var folderUrl = "/Archive/2018"; //relative path
var site = graphClient.Sites[siteId];
var list = site.Lists[listId];
var items = await list.Drive.Root.ItemWithPath(folderUrl).Children.Request().Expand("ListItem").GetAsync();
//print list item details
foreach (var item in items)
{
Console.WriteLine(item.ListItem.WebUrl);
}

Use Content instead of Document in Umbraco (v6)

I would like to update some obsolete code from umbraco v4 in the updated to v6 solution.
I have
entitiesFolder = new umbraco.cms.businesslogic.web.Document(folderId);
entitiesFolder.ReorderChildren(
entitiesFolder.Children.OrderBy(fdoc => fdoc.Text),
refreshEntireCache);
Now the recomendation instead of obsolete Document is to use Umbraco.Core.Models.Content. How? Didn't find (as usual for Umbraco) any documentation about... (
// new version
var toto = new Umbraco.Core.Models.Content(??)
toto.SoirtChildren(???)
Are you doing this from a razor view? If so you can do:
var nodeId = 123;
var myNode = Umbraco.TypedContent(nodeId);
var property = myNode.GetPropertyValue<string>("myStringAlias");
If you're doing it from a class or something you'll have to use something like:
var helper = new UmbracoHelper(UmbracoContext.Current);
var nodeId = 123;
var myNode = helper.TypedContent(nodeId);
(This is untested but it should work..)
If you are just querying data and need to sort it, using the umbracoHelper is a great way to go. It only hits the xml cache in App_Data/umbraco.config, so you don't hit the database.
However, if you are attempting to programatically sort some of the nodes in the content tree, you will need to use the ContentService. You will need to use the ContentService whenever you actually want to programatically modify content nodes. You will also find a similar MediaService for media.
https://our.umbraco.org/Documentation/Reference/Management-v6/Services/ContentService
ApplicationContext.Current.Services.ContentService.Sort(...)

Perfomance issue - .Count in MVC view

For several pages I use a .Count inside a foreach loop
#model ICollection<Item>
foreach(var item in Model)
{
#item.Flight.FlightReservations.count
}
Because of lazy loading the EF makes a round trip to the database for this.
Now I want to fix this by using this or linq version:
Include("List.Flight.FlightReservations")
Doing this makes loading my dbSet take even longer than those foreach round trips
How can I 'load' parts of only 1 object?
I would like to use context.Items.Single(p => p.id == id).Include(.....)
So I only load 1 item fully.
Or any other solutions for this?
(A way to force load item.List.item2.List inside controller)
Any suggestions are welcome :) Thanks
EDIT : now using
Where(..).ToDictionary(item => item, item => item.Flight.FlightReservations.Count);
Also noticed adding an index to my 'clustered index' table helped a little.
Still slow though
var f = _pr.FindBy(duifid);
var result = (from p in f.IngeschrevenVluchten
select new PrestatieModel
{
Eindpos = p.Eindpositie,
Locatie = p.Vlucht.Locatie.Naam,
AantalInschrijvingen = p.Vlucht.Inschrijvingen.Count(),
Vlucht = p.Vlucht
});
This query executes very fast, making a IEnumerable<Model>. But still it loads very slow once sent to the view.
return PartialView(result);

Additional criteria to symfony filter

i'm working on a symfony project to manage a database. First i explain how it works:
In the database, all elements are associated to an unique element 'scene'. When a user accesses the application, chooses what scene he wants to see (it saves that in a user parameter). So when listing elements, the application should only list elements associated with the scene selected by the user.
*Note: all elements have an scene attribute in the table definition.
So my problem comes here:
I developed a listing of an element entities using the help of a sfPropelPager class to paginate. Also added some filters to search in the list, and for that i used the filter system provided by symfony (<element>FormFilter.class.php and stuff).
Now i want the list to not show elements from other scenes than the selected by the user.
How can i do to add additional criteria to the criteria given by the filter class?
or How would you solve the problem?
here is my action code:
public function executeUnidadfilter(sfWebRequest $request){
$this->filter = new BaUnidadorganizativaTblFormFilter();
$c = $this->filter->getCriteria();
$this->filter->bind($request->getParameter($this->filter->getName()));
if($this->filter->isValid()){
$this->pager = new sfPropelPager('BaUnidadorganizativaTbl',$this->sfPropelPagerLines);
echo $this->getUser()->getEscenario();
$this->pager->setCriteria($c);
$this->pager->init();
}else{
$this->pager = new sfPropelPager('BaUnidadorganizativaTbl',$this->sfPropelPagerLines);
$this->pager->init();
}
$this->setTemplate('Unidadlist');
}
*Note: 'scene' mentioned below is Escenario in the code
thank you very much for your time
I solved the problem. The trouble was that i assigned the formfilter generated criteria to my criteria var Before the filter was filled. That's why of the error.
The resulting code is that:
public function executeUnidadfilter(sfWebRequest $request){
$this->filter = new BaUnidadorganizativaTblFormFilter();
$this->filter->bind($request->getParameter($this->filter->getName()));
if($this->filter->isValid()){
$this->pager = new sfPropelPager('BaUnidadorganizativaTbl',$this->sfPropelPagerLines);
$esc = $this->getUser()->getEscenario();
$c = new Criteria();
$c = $this->filter->getCriteria();
$c->addAnd('codigo_escenario',$esc);
$this->pager->setCriteria($c);
$this->pager->init();
}else{
$this->pager = new sfPropelPager('BaUnidadorganizativaTbl',$this->sfPropelPagerLines);
$this->pager->setCriteria($this->filter->getCriteria());
$this->pager->init();
}
$this->message=null;
$this->messageType=null;
$this->setTemplate('Unidadlist');
}

Resources