BackboneJS and HandlebarsJS #unless rendering issue - backbone.js

In my Backbone App I am rendering a View where it loads data from my database. If there is no data, I want it to display a message like "There's no data". I used the #unless-method but my issue is, that this message gets displayed while the data gets loaded/rendered and then it disappears when the data is ready and gets displayed. My Handlebars Template looks like this:
{{#each this}}
<div>
<div>
<article>
{{#if cover_image}}
<img src="{{cover_image}}">
{{else}}
<img src="noimage.jpg" />
{{/if}}
</article>
</div>
<div>
<h2>{{album_title}}</h2>
<h4>
{{#if physicalReleaseDate}}
<time datetime="2014-01-10">({{physicalReleaseDate}})</time>
{{else}}
<time datetime="2014-01-10">({{digitalReleaseDate}})</time>
{{/if}}
</h4>
</div>
<div>
<div>
<ol>
{{#each tracks}}
<li>{{track_title}}<span>{{track_duration}}</span></li>
{{/each}}
</ol>
</div>
</div>
</div>
{{/each}}
{{#unless this}}
<div class="noAlbums">
<h2>There's no data</h2>
</div>
{{/unless}}
Does anyone know how to avoid this?
Thanks in advance...

You need an inverted section
Example from docs:
Model:
{
"repos": []
}
Template:
{{#repos}}<b>{{name}}</b>{{/repos}}
{{^repos}}No repos :({{/repos}}

Related

How can I click on a button on the same element with a specific name?

This is ant-react project.
html:
<div class="list">
<div class="item">
<div>
<div>
<div class="head">
<span>name 1</span>
</div>
<div class="body">
<div>
<button>done</button>
</div>
</div>
</div>
</div>
</div>
<div class="item">
<div>
<div>
<div class="head">
<span>name 2</span>
</div>
<div class="body">
<div>
<button>done</button>
</div>
</div>
</div>
</div>
</div>
js:
cy.get(`div:contains('name1')`)
.should('be.visible')
.invoke('show')
.should('be.visible')
.find('button:contains("Done")').eq(0).click({ multiple: true })
There are a lot of item elements. I need to click on the 'Done' button of the element with name "name 1".
But every time i get error:
Timed out retrying after 4050ms: cy.click() failed because this element is detached from the DOM.
...
Cypress requires elements be attached in the DOM to interact with them.
How can I do it?
You can do something like this. The first parent will go to <div class="head"> and the next parent will move to div just above. Now using within we will make sure that the Done button is clicked for name 1.
cy.contains('span', 'name1')
.parent()
.parent()
.within(() => {
cy.contains('button', 'done').click()
})

Jquery Flexslider in Angular

Our designer has given me jquery flexslider for showing recently viewed items in our project. I need to construct a slider of recently viewed products in angular js, dynamically based on provided flex slider.In my system, recently viewed items are stored as json object( not array).
First of all flexslider is not working, it means sliding feature is not working inside my angular project. I tried to use angular flex slider module from online and tried to iterate my nested object and construct a slider using my data. It is also not working(picture is not showing). My designer asked me to write down a directive, so overall design will not have any problem or any design modification.
Can any of you can help me regarding this
Jquery flex slider dynamic part inside partial as follows
<<div class="recent_summary clearfix">
<h2>RECENTLY VIEWED</h2>
<div class="nav_carousel">
<div class="carousel mini_thumb_slider">
<ul class="stage_nav">
<li ng-repeat="arrObj in recentItems">
<div ng-repeat="arrItem in arrObj.timestamp track by $index">
<div ng-repeat="(wsitekey,item) in arrItem.sites track by $index">
<div ng-repeat="(prokey,proMd5) in item.add_to_cart track by $index">
<div class="product-image mini">
<div class="p_image_innner">
<img ng-src="{{proMd5.image}}" title="{{proMd5.title}} by {{item.info.name}}">
<div class="rateit">
<div class="rateis">
</div>
</div>
<a class="quick-product" data-toggle="modal" data-target="#quick-popup" ng-click="set_current_product_pro(proMd5,item,prokey,wsitekey)">+</a>
</div>
</div>
<div class="caption"><a ng-click="menuShopApi('',item.info.name)">{{item.info.name}}</a></div>
</div>
<div ng-repeat="(prokey,proMd5) in item.failed_to_add_to_cart track by $index">
<div class="product-image mini">
<div class="p_image_innner">
<img ng-src="{{proMd5.image}}" title="{{proMd5.title}} by {{item.info.name}}">
<div class="rateit">
<div class="rateis">
</div>
</div>
<a class="quick-product" data-toggle="modal" data-target="#quick-popup" ng-click="set_current_product_pro(proMd5,item,prokey,wsitekey)">+</a>
</div>
</div>
<div class="caption"><a ng-click="menuShopApi('',item.info.name)">{{item.info.name}}</a></div>
</div>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
Angular flex slider attempt to solve inside partial
<div class="recent_summary clearfix">
<h2>RECENTLY VIEWED</h2>
<div class="nav_carousel">
<div class="carousel mini_thumb_slider">
<ul class="stage_nav">
<li ng-repeat="arrObj in recentItems">
<div ng-repeat="arrItem in arrObj.timestamp track by $index">
<div ng-repeat="(wsitekey,item) in arrItem.sites track by $index">
<flex-slider flex-slide="proMd5 in item.add_to_cart track by $index">
<li>
<div class="product-image mini">
<div class="p_image_innner">
<img ng-src="{{proMd5.image}}" title="{{proMd5.title}} by {{item.info.name}}">
<div class="rateit">
<div class="rateis">
</div>
</div>
<a class="quick-product" data-toggle="modal" data-target="#quick-popup" ng-click="set_current_product_pro(proMd5,item,prokey,wsitekey)">+</a>
</div>
</div>
<div class="caption"><a ng-click="menuShopApi('',item.info.name)">{{item.info.name}}</a></div>
</li>
</flex-slider>
<div ng-repeat="(prokey,proMd5) in item.failed_to_add_to_cart track by $index">
<div class="product-image mini">
<div class="p_image_innner">
<img ng-src="{{proMd5.image}}" title="{{proMd5.title}} by {{item.info.name}}">
<div class="rateit">
<div class="rateis">
</div>
</div>
<a class="quick-product" data-toggle="modal" data-target="#quick-popup" ng-click="set_current_product_pro(proMd5,item,prokey,wsitekey)">+</a>
</div>
</div>
<div class="caption"><a ng-click="menuShopApi('',item.info.name)">{{item.info.name}}</a></div>
</div>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
used scripts
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/flexslider/2.2.2/flexslider.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/flexslider/2.2.2/jquery.flexslider.js"></script>
<script src="https://rawgit.com/wilsonwc/angular-flexslider/master/angular-flexslider.js"></script>
Use Flexsilder without Angular and try this code:
var slider = $('#slider').data('flexslider');
slider.addSlide(obj, position);
or
$('#slider').flexslider('addSlide', obj[, position]);
Because HTML will be rendering after Flexsilder;

Pass string with expression to directive and parse in template

I'm trying to convert a string which contains an expression passed through an attribute, inside the own directive's template. The idea is to do something like this:
<div custom-directive images-source="'staticpath/blah/blah/{{Item.Src}}'"></div>
And, then inside the template, I would have a ngRepeat directive that would iterate thorugh a data set like this:
<ul>
<li ng-repeat="Item in Items">
<img ng-src="{{imagesSource}}{{Item.name}}.{{Item.extension}}" />
</li>
</ul>
The expected result should be something like this:
<ul>
<li ng-repeat="Item in Items">
<img ng-src="staticpath/blah/blah/src1/file1.jpg" />
<img ng-src="staticpath/blah/blah/src2/file2.jpg" />
<img ng-src="staticpath/blah/blah/src3/file3.jpg" />
<img ng-src="staticpath/blah/blah/src4/file4.jpg" />
</li>
</ul>
I tried to invoke $interpolate and $compile directly in my template but I get an empty string.
{{$interpolate(imagesSource)}} and {{$compile(imagesSource)}}
Any ideas?
EDIT:
Imagine the next scenario. We have a directive that will show a list of image galleries. Each image gallery will have: a title, a little description and from 1 to n images.
Ok, let's say we have a constant with the root to the images folder '/media/images/galleries/'. Then, inside the template, when on the ngRepeat loop, I will need to build the path using that constant and one of the properties (in this case we can name it 'subfolder'), but I don't want the own directive to decide which property is needed. (that's why I'd like to pass the expression in the attribute).
The directive:
<div image-galeries images-source="'staticpath/blah/blah/{{Gallery.subfolder}}'">
The template:
<div ng-repeat="Gallery in Galleries">
<h3>{{Gallery.title}}</h3>
<p>{{Gallery.description}}</p>
<ul>
<li ng-repeat="Image in Gallery.Images">
<img ng-src="{{imagesSource}}{{Image.name}}.{{Image.extension}}" />
</li>
</ul>
</div>
And the result:
<div ng-repeat="Gallery in Galleries">
<h3>Gallery 1</h3>
<p>Gallery description 1</p>
<ul>
<li ng-repeat="Image in Gallery.Images">
<img ng-src="staticpath/blah/blah/src1/file1.jpg" />
<img ng-src="staticpath/blah/blah/src1/file2.jpg" />
<img ng-src="staticpath/blah/blah/src1/file3.jpg" />
<img ng-src="staticpath/blah/blah/src1/file4.jpg" />
</li>
</ul>
</div>
<div ng-repeat="Gallery in Galleries">
<h3>Gallery 2</h3>
<p>Gallery description 2</p>
<ul>
<li ng-repeat="Image in Gallery.Images">
<img ng-src="staticpath/blah/blah/src2/file1.jpg" />
<img ng-src="staticpath/blah/blah/src2/file2.jpg" />
</li>
</ul>
</div>
Excuse me please, about my english, I hope it was clear enough :D

how to make angular-gridster widget data content responsive?

i'm using angular-gridster for designing dynamic user dashboard. how can we make gridster widget data content responsive while resizing widget callback, can any one suggest me how to make it responsive.
<div id="gridster" >
<div gridster="gridsterOpts">
<ul>
<li gridster-item="widget" ng-repeat="widget in DashboardControls">
<div class="box">
<div class="box-header">
<h3 style="width: 100%;word-break: break-all; table-layout: fixed;">{{widget.ControlobjectName}}</h3>
<div class="box-header-btns pull-right">
<a title="settings" data-toggle="modal" data-target="#widgetSettingModal" ng-click="openSettings(widget)"><i class="glyphicon glyphicon-cog"></i></a>
<a title="Remove widget" ng-click="remove(widget)"><i class="glyphicon glyphicon-trash"></i></a>
</div>
</div>
<div class="box-content">
<div>
<img class="img-responsive" ng-src="{{widget.ThumbnailPath}}" />
</div>
</div>
</div>
</li>
</ul>
</div>
</div>
You'll have to create a custom directive that is embedded into the widgets (or multiple custom directives). This custom directive can contain logic that responds to the data and changes the content of the widgets.

Using ui-router with Kendo TabStrip

I am trying to implement a Kendo Tab Strip and that applies ui-router to display the contents of the tab. I can get the tab strip to display but not the contents using the ui-view. Anyone have an example of how to make these items work together.
Sample of my html.
<div class="main-template">
<div class="row">
<h3>Welcome to the Dashboard</h3>
<div ng-controller="Navigation">
<div kendo-tab-strip k-content-urls="[ null, null]">
<!-- tab list -->
<ul>
<li class="k-state-active" url="#/invoice">Invoice Management</li>
<li url="#/shipment">Shipment Management</li>
</ul>
</div>
<div ui-view></div>
</div>
</div>
</div>
I was not merging everything together as I should. In the li markup I should have used ui-sref instead of url.
<div class="main-template" style="margin-left: 10px;">
<div class="row">
<h3>Welcome to the Dashboard</h3>
<!--<a ui-sref="invoice">Invoice</a>
<div ui-view></div>-->
<div ng-controller="Navigation">
<div kendo-tab-strip="tabs">
<!-- tab list -->
<ul>
<li class="k-state-active" ui-sref="invoice">Invoice Management</li>
<li ui-sref="shipment">Shipment Management</li>
</ul>
</div>
<div ui-view></div>
</div>
</div>
</div>

Resources