I got a simple grid used like this :
<div id="planningGridDiv"
class="gridPatientContent"
style="height: 450px;min-height: 300px;"
ng-style="{height: showScores ? '150px': '450px'}"
ui-grid-resize-columns
ui-grid-selection
ui-grid-cellNav
ui-grid-pinning
ui-grid="myData"
class="grid">
</div>
But when showScores is true and height pass from 450 to 150 px, the grid itself doesn't shrink.
The first container see its height changed, but this part no :
<div role="grid" ui-grid-one-bind-id-grid="'grid-container'" class="ui-grid-render-container ng-isolate-scope ui-grid-render-container-body" ng-style="{ 'margin-left': colContainer.getMargin('left') + 'px', 'margin-right': colContainer.getMargin('right') + 'px' }" ui-grid-render-container="" container-id="'body'" col-container-name="'body'" row-container-name="'body'" bind-scroll-horizontal="true" bind-scroll-vertical="true" enable-horizontal-scrollbar="grid.options.enableHorizontalScrollbar" enable-vertical-scrollbar="grid.options.enableVerticalScrollbar" aria-multiselectable="true" id="1490734763451-grid-container" style="margin-left: 180px; margin-right: 80px;">
I can't find any solution on doc nor stack overflow, but it seems to me that it should. I can use some help for some pointers.
FYI, I found a solution on another stackoverflow question, but I changed it a bit to fit my needs :
$scope.showScoreDiv = function()
{
$scope.showScores = !$scope.showScores;
$timeout(function(){
$scope.gridApi.grid.handleWindowResize();
}, 1);
};
So the main idea is to change the height via ng-style on the grid div, and when you fire your event, here showScores = true called by showScoreDiv(), you have to call gridApi.grid.handleWindowResize().
The timeout is just here to give some time to the div to be set to the good height before calling handleWindowResize().
Related
I am just trying to verifying color for 'footer-top' background image.
Console view for 'footer top' icon is'
Under Styles:
footer .footer-top {
background: #1571c9;
float: left;
margin-top: 55px;
padding: 25px 0;
width: 100%;
Under Elements:
<div class="footer-top">
<div class="sw-layout">
<div class="footer-section">
<h5>More Information</h5>
<ul>
<li>About Us</li>
<li>Contact Us</li>
<li>FAQ</li>
</ul>
</div>
<div class="footer-section hide-for-xs">
<h5>Finance Cards</h5>
<ul>
<div>
<li>Cash Back Finance Cards</li></div>
<li>Points / Rewards Credit Cards</li>
<li>Travel / Air Miles Credit Cards</li>
<li>Islamic Cards</li>
<li>Business Credit Cards</li>
</li>
</ul>
</div><div class="footer-section hide-for-xs">
<h5>Personal Loans</h5>
<ul>
<li>Salary Transfer Loans</li>
<li>Loans Without Salary Transfer
</li>
</ul>
I am using below lines of code :
String FooterTopSectionColour =
driver.findElement(By.className("footer-top")).getCssValue("background");
try {
Assert.assertEquals("#1571c9", FooterTopSectionColour);
System.out.println("Colour matches with : "+
FooterTopSectionColour);
}
catch (Error e)
{e.printStackTrace();
}
In DOM colour is given in Hex value but Selenium is returning in terms of rgb.
You can check below error in console for the same :
java.lang.AssertionError: expected [rgb(21, 113, 201) none repeat scroll 0% 0% / auto padding-box border-box] but found [#1571c9]
at org.testng.Assert.fail(Assert.java:94)
at org.testng.Assert.failNotEquals(Assert.java:513)
at org.testng.Assert.assertEqualsImpl(Assert.java:135)
at org.testng.Assert.assertEquals(Assert.java:116)
at org.testng.Assert.assertEquals(Assert.java:190)
at org.testng.Assert.assertEquals(Assert.java:200)
at tests.homepage.HomePageStepDefinitions.vefify_colour_for_footer_top_section(HomePageStepDefinitions.java:378)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at cucumber.runtime.Utils$1.call(Utils.java:40)
at cucumber.runtime.Timeout.timeout(Timeout.java:16)
at cucumber.runtime.Utils.invoke(Utils.java:34)
at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:38)
at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
at cucumber.runtime.Runtime.runStep(Runtime.java:300)
at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)
at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165)
at cucumber.api.testng.TestNGCucumberRunner.runCucumber(TestNGCucumberRunner.java:63)
at cucumber.api.testng.AbstractTestNGCucumberTests.feature(AbstractTestNGCucumberTests.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:643)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:782)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
So, How can I debug it?
Please once check the code which I have used is correct or not!
And also let me know how to convert hex to rgb and compare it by using selenium? Thanks!
As your DOM colour and the CSS colours are different, you need to convert one format to to other and then you need to compare or assert it.
In the below code, I have added the steps which will convert the RGB values into an Hexa decimal and then assert the condition. And I assume that, if you print 'footerTopSelectionColour' value then it prints in the below format :
rgb(21, 113, 201) none repeat scroll 0% 0% / auto padding-box
border-box
Find the modified lines of your code below :
String footerTopSectionColour = driver.findElement(By.className("footer-top")).getCssValue("background");
try {
// I'm assuming that the value of 'footerTopSelectionColour' value will be like below
// rgb(21, 113, 201) none repeat scroll 0% 0% / auto padding-box border-box
// So first we need to convert colour code from rgb to hexa decimal
String value = footerTopSectionColour.trim();
String[] rgbs = value.split("\\)")[0].split("\\(")[1].split(", ");
long r = Long.parseLong(rgbs[0]);
long g = Long.parseLong(rgbs[1]);
long b = Long.parseLong(rgbs[2]);
String hex = String.format("#%02x%02x%02x", r, g, b);
System.out.println("=> The hex conversion is : "+hex);
// After converting you can assert like below
Assert.assertEquals("#1571c9", hex);
System.out.println("Colour matches with : "+ footerTopSectionColour);
} catch (Exception e) {
e.printStackTrace();
}
I hope this answer helps...
Above ans is working fine in converting value from rgb to hexa but assert statement is failed.
footerTopSectionColour colour is : rgb(21, 113, 201) none repeat scroll 0% 0% / auto padding-box border-box
The hex conversion is : #1571c9
Assert.assertEquals(hex, footerTopSectionColour);
Above line of code is throwing error as it is comparing 2 dissimilar values. So instead , use below assert statement to verify it and it works fine.
Assert.assertEquals("#1571c9", hex);
Does anybody know how to automatically expand a UI-grid that is performing a grouping? I need the grid to open up and start up with it being completely expanded.
Their API and Tutorial reference doesn't explain explicitly enough for me to understand.
My HTML div
<code>
<div id="grid1" ui-grid="resultsGrid" class="myGrid" ui-grid-grouping></div>
</code>
My Javascript
$scope.resultsGrid = {
,columnDefs: [
{ field:'PhoneNum', name:'Phone'},
{ field:'Extension', name:'Extension'},
{ name:'FirstName'},
{ field:'DeptDesc', grouping: {groupPriority: 0}}
]
,onRegisterApi: function(gridApi)
{
$scope.gridApi = gridApi;
}
}
you just need to add
//expand all rows when loading the grid, otherwise it will only display the totals only
$scope.gridApi.grid.registerDataChangeCallback(function() {
$scope.gridApi.treeBase.expandAllRows();
});
in your onRegisterApi: function(gridApi)that should be updated like this onRegisterApi: function(gridApi) so your function will be like this
$scope.resultsGrid.onRegisterApi = function(gridApi) {
//set gridApi on scope
$scope.gridApi = gridApi;
//expand all rows when loading the grid, otherwise it will only display the totals only
$scope.gridApi.grid.registerDataChangeCallback(function() {
$scope.gridApi.treeBase.expandAllRows();
});
};
or you can add botton to expand data like shown in this plunker
My Module - I had to add ui.gridl.selection
<pre>
<code>
angular.module('ddApp',['ngRoute','ngSanitize','ngCookies','ngResource','ui.grid.selection'])
</code>
</pre>
My Controller - Amongh the other Dependency Injected items, I also had to add $timeout
<pre>
<code>
.controller('myCtrl', function(`$`timeout)){}
</code>
</pre>
<pre>
<code>
$timeout(function(){
if($scope.gridApi.grouping.expandAllRows){
$scope.gridApi.grouping.expandAllRows();
}
});
</code>
</pre>
The closest analogy would the selection tutorial, in which we select the first row after the data finishes loading: http://ui-grid.info/docs/#/tutorial/210_selection
$http.get('/data/500_complex.json')
.success(function(data) {
$scope.gridOptions.data = data;
$timeout(function() {
if($scope.gridApi.selection.selectRow){
$scope.gridApi.selection.selectRow($scope.gridOptions.data[0]);
}
});
});
The key understanding is that you can't select (or expand) data that hasn't been loaded yet. So you wait for the data to return from $http, then you give it to the grid, and you wait for 1 digest cycle for the grid to ingest the data and render it - this is what the $timeout does. Then you can call the api to select (or in your case, expand) the data.
So for you, you'd probably have:
$http.get('/data/500_complex.json')
.success(function(data) {
$scope.gridOptions.data = data;
$timeout(function() {
if($scope.gridApi.grouping.expandAllRows){
$scope.gridApi.grouping.expandAllRows();
}
});
});
If you're on the latest unstable, that call will change to $scope.gridApi.treeBase.expandAllRows.
I got an issue with my code, im using hljs to highlight my code snippets which im using. I wrote a template system, as example the general input would be this:
<codeexample params="type: html">
<div style="example_class">Example code</div>
</codeexample>
My template interpreter:
<template id="codeexample">
<div class="code">
<pre><code data-bind="attr: {class: type}, template: { nodes: $componentTemplateNodes, afterRender: $root.handleCode}, visible: false ">
</code></pre>
</div>
</template>
My handleCode function:
this.handleCode = function(element) {
var preCodeTags = $(element).find('pre code');
preCodeTags.each(function(i, block) {
hljs.highlightBlock(block);
block.show(100);
});
}
The problem is that the afterRender function is called already before the template is rendered to my actual template, i used to add a console.log($(element).find('pre code')); which had the result that the length was 0.
[prevObject: jQuery.fn.jQuery.init[3], context: undefined, selector:
"pre code", constructor: function, init: function…]
context: undefined
length: 0
Shouldnt the function afterRender run exactly after the render process?
Is there a known work around? When I use a timeout for 200ms, it works fine, but this is the worst solution in my opinion.
Your afterRender handler isn't quite right. The parameter (element in your case) is actually an array of all elements rendered. From the documentation:
viewModel.myPostProcessingLogic = function(elements) {
// "elements" is an array of DOM nodes just rendered by the template
// You can add custom post-processing logic here
}
So it's not finding the code element successfuly. You could do this instead:
this.handleCode = function(elements) {
var preCodeTags = $(elements).filter('div').find('pre code');
preCodeTags.each(function(i, block) {
hljs.highlightBlock(block);
block.show(100);
});
}
The polymer js docs say you have to listen for the WebComponentsReady event to know when the polymer elements have been set up. What's the equivalent in Dart?
Here's my template:
<template id="order_name" bind repeat>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#order_list" href="#collapseOne">
{{commonName}} ({{scientificName}})
</a>
</div>
<div id="collapseOne" class="accordion-body collapse">
<div class="accordion-inner">
...
</div>
</div>
</div>
</template>
And here's main:
void main() {
OrderList().then((order_data) {
query("#order_name").model = order_data;
print (queryAll(".accordion-heading")); //null
}).catchError((err) => print(err));
query("#my-button").onClick.listen((Event e) {
print (queryAll(".accordion-heading")); //[div,div]
});
}
OrderList is a wrapper around HttpRequest.getString() and returns a future. My thought was to use an event like WebComponenentsReady to know when the template had been fully instantiated. The base question is how can I get at the .accordion-heading divs in main so I can attach listeners to them?
I assume that you are using boot.js. if you are, they should be initialized by the time you program enters main().
According to the spec (https://www.dartlang.org/articles/web-ui/spec.html#main-script):
...you cannot query for children of conditional and iteration nodes. ...To retrieve a component instance you need to defer queries until the end of the event loop, for example using a Timer.run(f).
So the code above needs to be modified like this:
void main() {
OrderList().then((order_data) {
query("#order_name").model = order_data;
print (queryAll(".accordion-heading")); //null
Timer.run( () => print (queryAll(".accordion-heading"))); //[div,div]
}).catchError((err) => print(err));
query("#my-button").onClick.listen((Event e) {
print (queryAll(".accordion-heading")); //[div,div]
});
}
So I'm running through the tutorial for AngularJS:
I have an array defined in the controller and i'm returning different points in the array by calling when i'm looping through ng-repeat {{feature.name}} {{feature.description}}
What i don't understand is lets say i have a third point in the array called "importance" and it's a number from 1 to 10. I don't want to display that number in the html but what i do want to do is apply a different color to the feature if that "importance" number in the array is 10 vs 1
so how do i write an if statement to do this:
i.e.
<p style="**insert if statement: {{if feature.importance == 10}} color:red; {{/if}} **">{{feature.description}}</p>
no idea if that's right but that's what i want to do
I do not think there is if statement available.
For your styling purpose, ng-class can be used.
<p ng-class="{important: feature.importance == 10 }">
ng-switch is also convenient.
-- update --
take a look at:
https://stackoverflow.com/a/18021855/1238847
angular1.2.0RC seems to have ng-if support.
Actually there is a ternary operator in Angular 1.2.0.
<p style="{{feature.importance == 10 ? 'color:red' : ''}}">{{feature.description}}</p>
I think the answer needs an update.
Previously you could use ngIf directive from AngularUI project (code here if you still want to download it), bad news is that it's not maintained any more.
The good news is that it has been added to the official AngularJS repo (unstable branch) and soon will be available in the stable one.
<div ng-if="something"> Foo bar </div>
Will not just hide the DIV element, but remove it from DOM as well (when something is falsy).
ng-class is probably the best answer to your issue, but AngularUI has an "if" directive:
http://angular-ui.github.com/
search for:
Remove elements from the DOM completely instead of just hiding it.
I used "ui-if" to decide if I should render a data value as a label or an input, relative to the current month:
<tbody id="allocationTableBody">
<tr ng-repeat="a in data.allocations">
<td>{{a.monthAbrv}}</td>
<td ui-if="$index < currentMonth">{{a.amounts[0]}}</td>
</tr>
</tbody>
In the case where your priority would be a label, you could create a switch filter to use inside of ng-class as shown in a previous SO answer : https://stackoverflow.com/a/8309832/1036025 (for the switch filter code)
<p ng-class="feature.importance|switch:{'Urgent':'red', 'Warning': 'orange', 'Normal': 'green'}">...</p>
You can also try this line of code below
<div class="{{is_foo && foo.bar}}">
which shows foo.bar if is_foo is true.
This first one is a directive that evaluates whether something should be in the DOM only once and adds no watch listeners to the page:
angular.module('setIf',[]).directive('setIf',function () {
return {
transclude: 'element',
priority: 1000,
terminal: true,
restrict: 'A',
compile: function (element, attr, linker) {
return function (scope, iterStartElement, attr) {
if(attr.waitFor) {
var wait = scope.$watch(attr.waitFor,function(nv,ov){
if(nv) {
build();
wait();
}
});
} else {
build();
}
function build() {
iterStartElement[0].doNotMove = true;
var expression = attr.setIf;
var value = scope.$eval(expression);
if (value) {
linker(scope, function (clone) {
iterStartElement.after(clone);
clone.removeAttr('set-if');
clone.removeAttr('wait-for');
});
}
}
};
}
};
});
This second one is a directive that conditionally applies attributes to elements only once without watch listeners:
i.e.
<div set-attr="{ data-id : post.id, data-name : { value : post.name, condition : post.name != 'FOO' } }"></div>
angular.module('setAttr',[]).directive('setAttr', function() {
return {
restrict: 'A',
priority: 100,
link: function(scope,elem,attrs) {
if(attrs.setAttr.indexOf('{') != -1 && attrs.setAttr.indexOf('}') != -1) {
//you could just angular.isObject(scope.$eval(attrs.setAttr)) for the above but I needed it this way
var data = scope.$eval(attrs.setAttr);
angular.forEach(data, function(v,k){
if(angular.isObject(v)) {
if(v.value && v.condition) {
elem.attr(k,v.value);
elem.removeAttr('set-attr');
}
} else {
elem.attr(k,v);
elem.removeAttr('set-attr');
}
});
}
}
}
});
Of course your can use dynamic versions built into angular:
<div ng-class="{ 'myclass' : item.iscool }"></div>
You can also use the new ng-if added by angularjs which basically replaces ui-if created by the angularui team these will conditionally add and remove things from the DOM and add watch listeners to keep evaluating:
<div ng-if="item.iscool"></div>
What also works is:
<span>{{ varWithValue || 'If empty use this string' }}</span>