ng-repeat not coloring elements properly? - angularjs

I am stumped on why the fields in my data aren't coloring correctly. I used a simple greater than logic to assign an ng-class of either green, or red. I added debug lines to check that inside the function the values are correct, and the bool is correct, but on the main page items are 'randomly' colored incorrectly. Help?
I tried several different things on the values, like parseInt() etc with the same results. As Is, no matter what I put inside the function it displays different colors than expected
<table>
<th><input class="search" type="text" ng-model="searchKey" placeholder="Character" ng-change="setClickedRow(-1)"></th>
<th ng-click="setSort('pval1')">
<div ng-app="KIdash" ng-controller="controller">
Total Matches: {{TotalMatchesFunc()}}
</div>
</th>
<th ng-click="setSort('pval2')">Wins</th>
<th ng-click="setSort('pval3')">Losses</th>
<tbody ng-repeat="ps in PlayerStats | orderBy: sortKey | filter:searchKey">
<tr ng-class="{'main-row-selected': $index == selectedRow,'main-row': $index != selectedRow}" ng-click="setClickedRow($index)">
<td>{{ps.name}}</td>
<td>{{ps.pval1}}</td>
<!-- *** THIS IS THE PART THAT ISNT WORKING CORRECTLY *** -->
<td ng-class="{'green': GreaterWins({{$index}}),'red': !GreaterWins({{$index}})}">{{ps.pval2}}</td>
<td>{{ps.pval3}}</td>
</tr>
<!-- *** COULD THIS SECOND FUNCTION CALL BE POLLUTING MY RESULTS? *** -->
<tr ng-class="{'extra-row-green': GreaterWins({{$index}}),'extra-row-red': !GreaterWins({{$index}})}" ng-show="selectedRow == $index">
<td>Detail: {{ps.detail_p1}}</td>
<td>Detail: {{ps.detail_p2}}</td>
<td>Detail: {{ps.detail_p3}}</td>
<td>Detail: {{ps.detail_p4}}</td>
</tr>
</tbody>
</table>
$scope.GreaterWins = function(z) {
console.log( "bool "
+ Boolean($scope.PlayerStats[z].pval2 > $scope.PlayerStats[z].pval3)
+ " "
+ $scope.PlayerStats[z].pval2 + "vs" + $scope.PlayerStats[z].pval3);
return Boolean($scope.PlayerStats[z].pval2 > $scope.PlayerStats[z].pval3));
};

Two things which i feel is creating issue.
Instead of passing index in function you should pass variable ps as ngRepeat create isolated scope. so some time there is issue.
variable selectedRow should be object as primitive variables has issue in inheritance and two data binding.
try both things your code should work.

I can't really repeat the issue using JSbin, here is the example I made in JSbin.
https://jsbin.com/jadiputoha/edit?html,js,console,output

Related

visualforce emailtemplate issue referencing a list in an Apex class

I suffer an error trying to implement a visualforce emailtemplate. The dev console gives me the following problem on the VF component: Unknown property 'String.Name' (line 0). I can't figure out how to resolve this. Consequently the email template doesnt work & gives me the error: <c:ProductOrderItemList can only contain components with an access level of global.
I aim to send an email from a Product Order (parent). In the email I want to include child records (product order items).
Apex class:
public class ProductOrderTemplate
{
public Id ProductorderID{get;set;}
public List<Product_Order_Item__c> getProductorderItems()
{
List<Product_Order_Item__c> toi;
toi = [SELECT Product_Type__r.Name, Quantity__c FROM Product_Order_Item__c WHERE Product_Order__c =: ProductorderID];
return toi;
}
}
The visualforce component:
<apex:component controller="ProductOrderTemplate" access="global">
<apex:attribute name="ProductOrdId" type="Id" description="Id of the Product order" assignTo="{!ProductorderID}"/>
<table border = "2" cellspacing = "5">
<tr>
<td>Name</td>
<td>Quantity</td>
</tr>
<apex:repeat value="{!ProductorderID}" var="toi">
<tr>
<td>{!toi.Name}</td>
<td>{!toi.Quantity}</td>
</tr>
</apex:repeat>
</table>
</apex:component>
And the email:
<messaging:emailTemplate subject=“Product Order” recipientType="User" relatedToType=“Productorder”>
<messaging:htmlEmailBody >
Hi,<br/>
Below is the list of ... for your Product order {!relatedTo.Name}.<br/><br/>
<c:ProductOrderItemList ProductOrderId="{!relatedTo.Id}" /><br/><br/>
<b>Regards,</b><br/>
{!recipient.FirstName}
</messaging:htmlEmailBody>
</messaging:emailTemplate>
Any help much appreciated! Quite stuck on this. I'm new to visualforce and apex.
​​​​​​​
You might need just a VF email template without component and apex class. Go to Product_Order_Item__c object, find Product_Order__c field definition. Write down the "Child Relationship Name".
Let's say it'll be "Line_Items". You need to add "__r" to the end (why?) and then you can do something like that:
<messaging:emailTemplate subject="Product Order" recipientType="User" relatedToType="Productorder">
<messaging:htmlEmailBody >
<p>here are your line items</p>
<table>
<apex:repeat value="{!relatedTo.Line_Items__r}" var="item">
<tr>
<td>{!item.Name}</td>
<td>{!item.Quantity}</td>
</tr>
</apex:repeat>
</table>
</messaging:htmlEmailBody>
</messaging:emailTemplate>
If you still think you want Apex and component (maybe you want to filter some records out, maybe you want to have them sorted or have a reusable piece of markup to use in multiple emails)...
... the error you're getting is because ProductorderID is a single String (well, Id) variable. But you've used it in a repeat that expects a list/array. A reference to <apex:repeat value="{!ProductorderItems}" var="toi"> should call your getProductorderItems() and work better.

React values multiply in a table

I want to multiply {value.item.itemPrice} and {value.itemCount} and assigned to next<td></td>..I tried using {value.item.itemPrice}*{value.itemCount} but not working.please help me to solve this.I get this values from axios get API call.
<tbody>
{itemList.map((value, key) => (
<tr key={key}>
<td>{value.itemId}</td>
<td>{value.item.itemPrice}</td>
<td>{value.itemCount}</td>
<td>{value.item.itemPrice}*{value.itemCount}</td> //not woring this
</tr>
))}
<tr>
<td></td>
<td></td>
<td>Total</td>
<td>total here</td>
</tr>
</tbody>
When you use {my_var} everything that is inside is executed as javascript code and you can do mathematical operations or whatever you need.
This is how your code would be so that it works as you need.
<td>{value.item.itemPrice * value.itemCount}</td> // this code is ready
Bracket {} will tell JSX parser that the syntax should be interpreted as javascript and return value to be shown. Did you try ?
{value.item.itemPrice * value.itemCount}
Try That:
<td>{value.item.itemPrice * value.itemCount}</td>
you were displaying * as a text because it was outside of the brackets, then it wouldn't multiply

How to subsititute a property name in an angularjs expression with a string

Given a set of columns specified by a user. Which will be contained within displayColumns i.e. ['value1', 'value2', 'value3'] i want to iterate over this set of values to provide me with the correct reference to each value in the model.
I don't know what the syntax is for substituting the column name into an expression so that when angular compiles it, it would look like -> {{device.name.value1.value.value}} ... I've tried [] but that obviously didn't work!
<tbody md-body>
<tr md-row ng-repeat="device in $ctrl.devices track by device.mRID">
<td md-cell ng-click="$ctrl.detailedView($event, device)">{{device.aliasName}}</td>
<td md-cell>{{device.mRID}}</td>
<td md-cell ng-repeat="column in $ctrl.displayColumns">{{device.name.[column].value.value}} {{device.name.[column].unit.symbol}}<td>
</tr>
</tbody>
This is called bracket notation:
{{device.name[column].value.value}} {{device.name[column].unit.sybmol}}
Not this:
{{device.name.[column].value.value}} {{device.name.[column].unit.sybmol}}

Unable to get Text from a Span tag in WebDriver

<tr>
<tr>
<td class="style1" valign="top"> URL : </td>
<td class="style3">
<span id="lblPresenter" class="bord">https://testurl.net</span>
</td>
</tr>
</tr>
enter code here
we1 = driver.findElement(By.xpath("//*[#id='lblPresenter']"));
System.out.println(we1.getAttribute("InnerHTML"));
//I am getting Null as result
or
System.out.println(we1.getText());
//I am not getting any result
strong text
I need to get URL from the above source code .
If any body have a solution please let me know .
In general, XPath should be avoided because it's slower and more error prone. This is a simple scenario that doesn't require an XPath. You can do the same thing using By.id()
WebElement ele = driver.findElement(By.id("lblPresenter"));
System.out.println(ele.getAttribute("innerHTML"));
System.out.println(ele.getText());
One issue with your we1.getAttribute("InnerHTML") is that the i in innerHTML should not be capitalized. Please try the above code and see if that works. If not, please post the results/errors.

Dynamic Text in selenium Webdriver

I m automating a web application and need help at one point.
When even i login to the web app. it ask for the user name(manager id) and then that manager id keep on flashing on home page. Manager id changes with different login credentials.
So i need to keep checking that Manager id.
<tr>
<td>
<center>
<table width="100%" align="center">
<tbody>
<tr/>
<!--comments: To link all the screens-->
<tr>
<tr class="heading3" align="center">
<td style="color: green">Manger Id : mngr8499</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</body>
The manager ID as you can see in DOM is displayed as Manager Id: XXXX
So please help me how to locate these "XXXX" only, out of Manager id: XXXX
To my understanding after using getText() you get Manger Id : mngr8499 but you do not want every time Manager ID with the text and only ID. My Implementation would be to first copy the text in the any String variable and then using String.replaceAll() Method i can get the required text.
Below is the implementation of the same, Please let me know in-case if i am understanding the question wrong.
WebElement mngrid = driver.findElement(By.xpath("//tr[#class='heading3']/td"));
String actual_text = mngrid.getText();
actual_text= actual_text.replace("Manger Id :"," ");
System.out.println(actual_text);
From what I understand, I would use the .getText() method to get the 4 characters within the td using:
driver.findElement(By.cssSelector(".heading3 > td")).getText().substring(17);
If your concern is the refreshing of the html, consider using:
WebDriverWait wait = new WebDriverWait(driver, 10)
wait.until(ExpectedConditions.stalenessOf(By.cssSelector(".heading3 > td"));
When the previous value drops out of the DOM, you can use the new selector to get the refreshed value.

Resources