Nested iron-pages (Polymer1.0) - polymer

<iron-pages attr-for-selected="data-route" selected="{{route}}">
<section data-route="home">
<paper-material elevation="1">
<bortini-home></bortini-home>
</paper-material>
</section>
<section data-route="tv">
<paper-material elevation="1">
<iron-pages attr-for-selected="data-route" selected="{{route}}">
<section data-route="tvList">
<paper-material elevation="1">TV list</paper-material>
</section>
<section data-route="tvAdd">
<paper-material elevation="1">TV Add</paper-material>
</section>
<section data-route="tvEdit">
<paper-material elevation="1">TV edit</paper-material>
</section>
<section data-route="tvView">
<paper-material elevation="1">TV details</paper-material>
</section>
</iron-pages>
</paper-material>
</section>
<section data-route="users">
<paper-material elevation="1">
<h2 class="paper-font-display2">Users</h2>
<p>This is the users section</p>
Rob
</paper-material>
</section>
<section data-route="user-info">
<paper-material elevation="1">
<h2 class="paper-font-display2">
User:<span>{{params.name}}</span>
</h2>
<div>This is <span>{{params.name}}</span>'s section</div>
</paper-material>
</section>
<section data-route="contact">
<paper-material elevation="1">
<h2 class="paper-font-display2">Contact</h2>
<p>This is the contact section</p>
</paper-material>
</section>
</iron-pages>
Also my route looks like -
window.addEventListener('WebComponentsReady', function () {
// We use Page.js for routing. This is a Micro
// client-side router inspired by the Express router
// More info: https://visionmedia.github.io/page.js/
page('/', function () {
app.route = 'home';
});
page('/tv', function () {
app.route = 'tvAdd';
});
page('/tvAdd', function () {
app.route = 'tvAdd';
});
page('/users', function () {
app.route = 'users';
});
page('/users/:name', function (data) {
app.route = 'user-info';
app.params = data.params;
});
page('/contact', function () {
app.route = 'contact';
});
// add #! before urls
page({
hashbang : true
});
});
I am using "page.js" for routing.
When I press "tv" menu, it should show "tvAdd", but it just shows empty screen.
Thanks in advance.

The reason this is happening is because the two <iron-pages> elements are both bound to the same property. To elaborate further, here's an example:
route changes to tv
The parent <iron-pages> element has its selected property changed to tv
The tv page is selected in the parent <iron-pages>
The child <iron-pages> has its selected property changed to tv
There is no tv page in the child <iron-pages>, so nothing is selected inside it and it remains blank.
The same goes for if you were to set route to one of the route names that you use in the child <iron-pages>.
To solve this problem, you must bind both of the <iron-pages> to different properties, the first of which would determine which parent route you are on, and the second of which would determine the child route, if any.
Afterwards, you would just set two properties in your routing callbacks.
Some pseudocode:
<iron-pages attr-for-selected="data-route" selected="{{route}}">
...
<section data-route="tv">
...
<iron-pages attr-for-selected="data-route" selected="{{childRoute}}">
...
<section data-route="tvList">
page('/tvAdd', function () {
app.route = 'tv';
app.childRoute = 'tvAdd';
});

Related

Angular Protactor test getting h1 text from html

I am very new in end to end testing. In my app I have a login page, which I want to show the user when they logout from the app. Now there is a text h1 inside the div. But I am not getting the text from that div and that is why the expected result is different from the actual result.
Here is my login page html.
<div *ngIf="!isLoggedIn" class="login-controller">
<div layout="column" class="login-dialog">
<h1>Here is a heading</h1>
<h2>Second Heading</h2>
<div class="border">
...
</div>
</div>
</div>
Here is my app.po.ts
async getLogInPage(){
return await element(by.css('h1')).getText();
}
async logoutOfApplication() {
var userMenu = element(by.css(".prof-dropbtn > span"));
browser.wait(ExpectedConditions.presenceOf(userMenu), 10000);
await userMenu.click();
var logoutButton = element(by.id("logout"));
await logoutButton.click();
}
Now app.e2e-spec.ts
it('Test for logout', () => {
page.logoutOfApplication();
expect(page.getLogInPage()).toEqual('Here is a heading');
page.loginToApplication("email.com", "demo");
});
If you want get h1 value you have to write like this
it('Test for logout', () => {
page.logoutOfApplication();
expect(element.all(by.css('.login-dialog h1')).getText()).toEqual('Here is a heading');
page.loginToApplication("eamil.com", "demo");
});

DFP ads not always showing on all browsers

We have implemented multiple ads on our site and it has been working fine since recently. We have not touched our line items but created a few new creatives which are currently displaying. However, since this change, we randomly end up with certain ads not showing at all causing blank spaces. We have not touched the initial code or ids. We have tried logging into user accounts and that seems to cause ads to load more often but we still sometimes sit with an empty space block.
I have tried to research this subject but cannot find a solution. I have tried the fixes stated by this site but it did not help.
I have also looked at this discussion where they stated the importance of having a user account, which seemed to help but we still sit with blank spaces instead of ads from time to time.
<div>
<script>
googletag.cmd.push(function() {
googletag.defineSlot('/191675786/bottom_mobile', [300, 250], 'div-gpt-ad-1470805011041-0').addService(googletag.pubads());
googletag.defineSlot('/191675786/top_mobile', [320, 50], 'div-gpt-ad-1470804718031-0').addService(googletag.pubads());
googletag.defineSlot('/191675786/bottom_widescreen', [728, 90], 'div-gpt-ad-1470804049204-0').addService(googletag.pubads());
googletag.defineSlot('/191675786/right_side_1', [300, 600], 'div-gpt-ad-1470775758148-0').addService(googletag.pubads());
googletag.defineSlot('/191675786/middle_mobile', [320, 50], 'div-gpt-ad-1490793232691-0').addService(googletag.pubads());
googletag.defineSlot('/191675786/right_side_2', [300, 250], 'div-gpt-ad-1470775758148-1').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
</div>
<aside class='adverts'>
<div class='mobile-advert text-center'>
<!-- /191675786/top_mobile -->
<div id='div-gpt-ad-1470804718031-0' style='height:50px; width:320px;'>
<script>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1470804718031-0'); });
</script>
</div>
</div>
</aside>
<aside class="adverts padding-medium-top">
<div class="widescreen-advert">
<!-- /191675786/bottom_widescreen -->
<div id="div-gpt-ad-1470804049204-0" style="height:90px; width:728px;">
<script>
googletag.cmd.push(function() { googletag.display("div-gpt-ad-1470804049204-0"); });
</script>
</div>
</div>
</aside>
<section class='rightside-container col-sm-4 col-xs-12'>
<aside class='adverts'>
<div class='mobile-advert text-center'>
<!-- /191675786/bottom_mobile -->
<div id='div-gpt-ad-1470805011041-0' style='height:250px; width:300px;'>
<script>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1470805011041-0'); });
</script>
</div>
</div>
<div class='widescreen-advert'>
<!-- /191675786/right_side_1 -->
<div id='div-gpt-ad-1470775758148-0' style='height:600px; width:300px; margin-bottom: 20px;'>
<script>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1470775758148-0'); });
</script>
</div>
<!-- /191675786/right_side_2 -->
<div id='div-gpt-ad-1470775758148-1' style='height:250px; width:300px;'>
<script>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1470775758148-1'); });
</script>
</div>
</div>
</aside>
</section>
We have not found any solution as of yet and we do not understand why it only show ads sometimes but not always. Correct me if I am wrong but if the code was incorrect, wouldn't that mean that no ads would show ever?

Data binding between 2 sibling elements

Is it possible to pass the bindings from one child to the other child in the parent? The parent doesn't need to use the bindings. It will need to be 2 way.
To put it another way, I need to siblings to share data-bindings.
<app-drawer id="drawer">
<div class='left-bar-container'>
<listings-drawer></listings-drawer>
<!-- Main content -->
<iron-pages
selected="[[page]]"
attr-for-selected="name"
fallback-selection="view404"
role="main">
<my-view1 name="my-view1" form-loading="{{isLoading}}"
pic="{{pics}}" area-code="{{areaCode}}"></my-view1>
I need <listings-drawer></listings-drawer> to have access to form-loading="{{isLoading}}", pic="{{pics}}", and area-code="{{areaCode}}"
<app-drawer id="drawer">
<div class='left-bar-container'>
<listings-drawer loading="{{isLoading}}"
some-pics="{{pics}}" some-area-code="{{areaCode}}"></listings-drawer>
<!-- Main content -->
<iron-pages
selected="[[page]]"
attr-for-selected="name"
fallback-selection="view404"
role="main">
<my-view1 name="my-view1" form-loading="{{isLoading}}"
pic="{{pics}}" area-code="{{areaCode}}"></my-view1>
`
There is no reason the above would not work, assuming those property names were used in the listings-drawer element.

Polymer 1.0 more-routing

Polymer: 1.0.3
More routing: 1.0.0
Having some issues with Polymer "more-routing". Those are -
1) Get this log on console -
[dom-bind::_annotatedComputationEffect]: compute method `urlFor` not defined
2) First level routing works (even though I get those error/warning messages). But second level routing (i mean nested routing) does not work. On "users" page pressing the name doesn't take me to "user-info" page. In fact the name does not appear as a link, it appears as a text. Here is my code -
My "routing.html"--
<link rel="import" href="../bower_components/more-routing/more-routing.html">
<more-routing-config driver="hash"></more-routing-config>
<more-route name="home" path="/"></more-route>
<more-route name="users" path="/users">
<more-route name="user-info" path="/:name"></more-route>
</more-route>
<more-route name="contact" path="/contact"></more-route>
My "index.html" ---
<more-route-selector>
<paper-menu class="list" on-iron-select="onMenuSelect">
<a route="home" href="{{urlFor('home')}}">
<iron-icon icon="home"></iron-icon>
<span>Home</span>
</a>
<a route="users" href="{{urlFor('users')}}">
<iron-icon icon="info"></iron-icon>
<span>Users</span>
</a>
<a route="contact" href="{{urlFor('contact')}}">
<iron-icon icon="mail"></iron-icon>
<span>Contact</span>
</a>
</paper-menu>
</more-route-selector>
<more-route-selector selectedParams="{{params}}">
<iron-pages>
<section route="home">
<paper-material elevation="1">
<bortini-home></bortini-home>
</paper-material>
</section>
<section route="users">
<paper-material elevation="1">
<h2 class="paper-font-display2">Users</h2>
<p>This is the users section</p>
Rob
</paper-material>
</section>
<section route="user-info">
<paper-material elevation="1">
<h2 class="paper-font-display2">
User:<span>{{params.name}}</span>
</h2>
<div>This is <span>{{params.name}}</span>'s section</div>
</paper-material>
</section>
<section route="contact">
<paper-material elevation="1">
<h2 class="paper-font-display2">Contact</h2>
<p>This is the contact section</p>
</paper-material>
</section>
</iron-pages>
</more-route-selector>
With 1.0 (perhaps earlier), Polymer stopped supporting expressions inside data-bindings (Migration Guide - Data binding). Thankfully, you can still call a function in a binding (called a "computed binding").
From what I can tell, the urlFor() method must be slightly too complex to work as a computed binding (the params object isn't a dependent property). I was able to make it work by wrapping urlFor() in a simpler function - one that works as a computed binding - something like this:
<more-routing-config driver="path"></more-routing-config>
<more-route name="users" path="/users">
<more-route name="user-info" path="/:name"></more-route>
</more-route>
<template is="dom-bind">
Rob
</template>
<script>
var template = document.querySelector('template');
template.makeUrl = function(route, name) {
return MoreRouting.urlFor(route, {name:name});
};
</script>
You can also pass variables in your computed binding, as long as they're dependent properties, like the item in a repeating template
<template is="dom-bind">
<template is="dom-repeat" items="{{users}}">
{{item.name}}
</template>
</template>
<script>
var template = document.querySelector('template');
template.makeUrl = function(route, user) {
return MoreRouting.urlFor(route, {name:user.name});
};
</script>

Show/Hide onclick - angularjs

This is what i'm trying to achieve.
section1 will be hidden at page load. When user clicks on Advanced, section1 should show & section2 should hide. On clicking Basic, the opposite should happen. Nothing happens when I click any of the anchor tags now. Where am i going wrong.
<div class="container" ng-init="advstatus=true">
Basic
<br/>
Advanced
<div class="section1" ng-hide="advstatus">
///...
</div>
<section ng-show="advstatus" class="section2">
///...
</section>
</div>
In AngularJS you need to use ng-click instead of onclick.
Also, ng-init isn't supposed to be used unless you're in ng-repeat, which you are not (take a look at the Docs).
You should set up the variable in your controller:
<div ng-app ng-controller="myCtrl" class="container" >
Basic
<br/>
Advanced
<div class="section1" ng-show="!advstatus">
Section 1
</div>
<section ng-show="advstatus" class="section2">
Section 2
</section>
</div>
Controller:
function myCtrl($scope) {
$scope.advstatus = true;
}
JS Fiddle
This one is easy to understand
<div class="section1" ng-show="state1">
Section 1
</div>
<div class="section2" ng-show="state2">
Section 2
</div>
<input type="button" value="Advance" ng-click="sec1_show()" />
<input type="button" value="Basic" ng-click="sec2_show()" />
<script>
function homecntrl($scope) {
$scope.state1 = false;
$scope.state2 = true;
$scope.sec1_show = function () {
$scope.state1 = true;
$scope.state2 = false;
};
$scope.sec2_show = function () {
$scope.state2 = true;
$scope.state1 = false
};
};
</script>
Very simple just do this:
<button ng-click="hideShow=(hideShow ? false : true)">Toggle</button>
<div ng-if="hideShow">hide and show content ...</div>