Sitefinity - Get Sub Library Name List Template - sitefinity

So I'm making a list template for Sitefinity's document widget. The documents are in a library that is located in another library and I want to display that sub library name at the top of the list. The thing is I cant get that sub library name I can only get the parents name. This will make more sense id you see the screenshots. I would like to have "Child Library" as the title, but can't figure it out.
<ul class="simpleZebraList #Model.CssClass">
#if (Model.Items.Count() > 0)
{
var firstItem = Model.Items.First();
<h4>#firstItem.Fields.Parent.Title</h4>
}
#foreach (var item in Model.Items)
{
<li>
<div class="title">#item.Fields.Title</div>
<div class="link">
<a class="cta" href="#item.Fields.MediaUrl" target="_blank">Download</a>
</div>
</li>
}
#if (Model.ShowPager)
{
#Html.Action("Index", "ContentPager", new
{
currentPage = Model.CurrentPage,
totalPagesCount = Model.TotalPagesCount.Value,
redirectUrlTemplate = ViewBag.RedirectPageUrlTemplate
})
}

You can try this:
cast firstItem.DataItem to Document and then use FolderId property to get the Id of the folder (child library). Then use LibrariesManager to get the folder by that Id and you should be able to get its name.

Related

Razor Pages Tag Helper with Dynamic Parameters Assigning Current Url as Href

I'm running into trouble trying to set anchor tag helper parameters dynamically and looking for some help.
I have a nav that is a view component inside the shared _Layout.cshtml page that populates departments from a model.
#model List<DepartmentModel>
<ul class="nav">
#foreach (var d in Model)
{
<li>
<a asp-page="catalog/departments" asp-route-departmentName="#d.Name" asp-route-departmentId="#d.Id">#d.Name</a>
</li>
}
</ul>
Here is the InvokeAsync() from my View Component class
public async Task<IViewComponentResult> InvokeAsync()
{
var departments = _catalogService.GetNavDepartments();
return View(departments);
}
When I first launch the page, all the hrefs are populating correctly.
"catalog/departments/department-name-1/department-id-1"
"catalog/departments/department-name-2/department-id-2"
"catalog/departments/department-name-3/department-id-3"
If I click on one of the links, like the first link for example, I go to the proper department page "catalog/departments/department-name-1/department-id-1"
However, once I click that first link and navigate to the respective page, all the nav hrefs populate to the current url "catalog/departments/department-name-1/department-id-1" instead of the originally generated hrefs. This makes it so I can't navigate to another department.
Here is my route in the Startup.cs
services.AddRazorPages().AddRazorPagesOptions(options => {
options.Conventions.AddPageRoute("/Catalog/Departments", "{dName}/{dId}");
});
Based on the convention above, it eliminates the "catalog/department" piece of the url but I added it in this description for a sense of what I'm trying to accomplish. Even if I add this template to the page that populates the "catalog/departments" url, I get the same result.
#page "{dName}/{dId}"
Can anyone help me figure out what I am missing? Thanks in advance!
******** UPDATE ********
Currently, the only way I am able to get this to work is by adding the cache tag helper.
<cache>
<ul class="nav">
#foreach (var d in Model)
{
<li>
<a asp-page="catalog/departments" asp-route-departmentName="#d.Name" asp-route-departmentId="#d.Id">#d.Name</a>
</li>
}
</ul>
</cache>
This doesn't seem like a proper fix. Seems more of a hack then anything. Anybody have any ideas? Thanks!

Bootstrap select dropdown not rendering viewbag items

For some reason my list is showing up disabled I am trying to use bootstrap-select here
https://developer.snapappointments.com/bootstrap-select/
This is my code that gets the items there is nothing wrong with it as 3 items exist in the view bag
public void GetStandardLookups(int LookupGroupId) {
List<SelectListItem> listItems = new List<SelectListItem>();
var items = _context.StandardLookups.Where(w => w.LookupGroup == LookupGroupId).ToList();
foreach (var item in items) {
SelectListItem listItem = new SelectListItem();
listItem.Text = item.LookupText;
listItem.Value = item.Id.ToString();
listItems.Add(listItem);
}
if(LookupGroupId == Constants.EnforcmentType)
ViewBag.EnforceMentTypesList = listItems;
if (LookupGroupId == Constants.EnforcmentCategory)
ViewBag.EnforcmentCategoryList = listItems;
}
I Create the dropdown as such after storing in the view bag on the controller action of edit. But when I look at the raw html all i have is. This is three rows of data in the database that should be pulling through and I debugged my code and it is getting three items in list Items.
Nothing selected
I am initializing my bootstrap select as follows
$(function () {
$('.selectpicker').selectpicker();
})
I am producing my drop down as follows.
#Html.DropDownListFor(x => x.Enf_Type, (IEnumerable<SelectListItem>)ViewBag.EnforceMentTypesList, String.Empty, new { #class = "selectpicker form-control" })
My Edit action
I did a test using same bootstrap-select you share with testing data, which work as expected.
its shows the words nothing to select and is disabled non clickable
Please check if the html source of dropdown-toggle button with CSS class 'disabled' like below.
<button type="button" class="btn dropdown-toggle disabled btn-light bs-placeholder" data-toggle="dropdown" role="combobox" aria-owns="bs-select-1" aria-haspopup="listbox" aria-expanded="false" data-id="Enf_Type" tabindex="-1" aria-disabled="true" title="Nothing selected"><div class="filter-option"><div class="filter-option-inner"><div class="filter-option-inner-inner">Nothing selected</div></div> </div></button>
And if rendered <select> element with disabled attribute.
<select class="selectpicker form-control" data-val="true" data-val-required="The Enf_Type field is required." disabled="disabled" id="Enf_Type" name="Enf_Type" tabindex="-98"><option value="">
You can try to programmatically enable a selectpicker with following code snippet.
$('.selectpicker').prop('disabled', false);
$('.selectpicker').selectpicker('refresh');

I am facing an issue in retrieving all the list items using selenium webdriver

Problem : I have a list of items inside a div class msb-container.
.There are 162 items in the list .I want to click the 150th item from the list .There also a scroll bar through which we can go doen to other elemenst and select it
How the html looks like :
<div class="mCSB_container" style="position:relative; top:0;">
<ul id="ul-countries">
<li>
<input id="country-3" type="checkbox" name="c:3">
<label for="country-3">Afghanistan</label>
</li>
<li>
<input id="country-6" type="checkbox" name="c:6">
<label for="country-6">Albania</label>
</li>
---other countries
</li>
</ul>
</div>
How my code looks like :
IList<IWebElement> countryList = driver.FindElements(By.XPath("//*[#id='ul-countries']/li"));
for (int i = 0; i <= countryList.Count; i++)
{
string temp = countryList.ElementAt(i).Text;
if (countryList.ElementAt(i).Text == "Brazil")
{
//do something
}
}
I am getting a correct count of 162 countries but i think they are not filled correctly .As when I try to retrieve the text from even the 15th country it gives me empty result .It only fills the text for those list item which can be seen on the screen .Although when I inspect element I can see all the required data in list item through html but not through my code .I tried to put the sleep to but no luck .
Please provide your inputs to solve the above issue.
|
Kindest Regards
IList<IWebElement> countryList = driver.FindElements(By.XPath("//*[#id='ul-countries']/li"));
for (int i = 0; i <= countryList.Count; i++)
{
string temp = countryList.ElementAt(i).findElement(By.CSS("label")).getText();
if (temp.equals("Brazil"))
{
//do something
}
}

Serve up images from network to View in ASP.NET MVC

I'm trying to load images from my server and then load them to a view:
var files = _directoryInfo.GetFiles()
.Where(x => x.Name.Contains(request.WarrantyReference))
.ToList();
model.Photos = files;
return View(model);
Then in the View im doing:
#if (Model.Photos.Count > 0)
{
#Html.Partial("_Photos", Model.Photos)
}
_Photos:
#model List<FileInfo>
<div class="ui items">
#foreach (var photo in Model)
{
<div class="item">
<div class="image">
<img src="#photo.FullName">
</div>
</div>
}
</div>
But nothing appears, I get the following error in the console:
Not allowed to load local resource:
file://my-server/dataphoto/WX0001 1.jpg
So I was wondering if it is possible to store the photos temporarily on my server to serve them to the View or is there another way around this?
Store the file names (or some identifier) in your Model.
Model
class Model
{
IList<string> Photos { get; set; }
Create an HtmlHelper to display your photo image.
In your example you could store "WX0001 1.jpg" as the photo identifier then when you read the file from the network server you look in a specific directory.
View
#model List<FileInfo>
<div class="ui items">
#foreach (var photo in Model)
{
<div class="item">
<div class="image">
#Html.PhotoImage(photo)
</div>
</div>
}
</div>
public static MvcHtmlString PhotoImage(this HtmlHelper html, string id)
{
var img = new TagBuilder("img");
var your_image_byte_array = read_image_from_server_using_id;
var base64 = Convert.ToBase64String(your_image_byte_array);
img.Attributes.Add("src", String.Format("data:image/gif;base64,{0}", base64));
return MvcHtmlString.Create(img.ToString());
}
Alternatively, have a look at using an Action method to display the image... Convert Byte Array to Image and Display in Razor View
you would need to copy the files somewhere where the ASP.NET user being used for the AppPool serving/hosting the website has access to. Alternatively, give the share the app pool account privileges to read. One other way would be to read the files and store them in a byte[] and finally render it on the screen/view without actually writing the files to disk.

Prestashop subcategories menu inside a subcategory

I am trying to show the subcategories menu of prestashop categories inside all subcategories. By default you only can see the subcategories menu inside a category but you cant see the "brother" subcategories of a subcategory.
I think I only need to make this code to work inside a subcategory because this code works well inside a category:
{foreach from=$subcategories item=subcategory}
<li > <a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'htmlall':'UTF-8'}"
class="cat_name">{$subcategory.name|escape:'htmlall':'UTF-8'}</a>
</li> {/foreach}
Any ideas?
Thanks so much
as always i don't give you a full code, but i tell you how to do it.
in smarty you need to create a function that takes as param number of parent category,
and in this function you need to use Category::getChildren( $id_category );then in smarty you need only take a loop through the smarty function.
regards
and sorry for my English.
For to start i would have created a override file in /override/controllers/, named CategoryController.php
And add this:
<?php
class CategoryController extends CategoryControllerCore
{
public function displayContent()
{
// Get the global smarty object.
global $smarty;
// Get current category's parent.
$parent_category = new Category($this->category->id_parent, self::$cookie->id_lang);
// Get parent category's subcategories (which is current category's siblings, including it self).
$category_siblings = $parent_category->getSubCategories((int)self::$cookie->id_lang)
/* Assign your siblings array to smarty. */
$smarty->assign(
array(
"category_siblings" => $category_siblings
)
);
/* This we run the normal displayContent, but pass the siblings array to
category.tpl */
parent::displayContent();
}
}
?>
And in product-list.tpl file:
<ul>
{foreach from=$category_siblings item=elemento}
<li {if $category->id == $elemento.id_category}class="active"{/if}> {$elemento.name} </li>
{/foreach}
</ul>
via Get sibling categories in category.tpl for the current category in prestashop