updating ng-repeat list on adding data locally in angularjs - angularjs

I have a table that displays the list of data from websql local database.Onclick of add Button list of doctors are provided to add to the database.The adding is done but problem is that i am not able to update the datalist and see the added record.After page refreshing i could see the added record.Can anybody plz help me here.I am posting my code below.The html view template is as follows:
<table class="table table-hover" >
<tr>
<th>DOCTOR</th>
<th>SPECIALITY</th>
<th>PATCH</th>
<th>CLASS</th>
<th> </th>
</tr>
<tr ng-repeat="doc in listDoctors">
<td>{{ doc.contactName }}</td>
<td>{{ doc.speciality }}</td>
<td>{{ doc.townName }}</td>
<td>{{ doc.class }}</td></tr></table>
Now controller does:
//displays list of doctors
$scope.listDoctors = [];
readData.transaction(sqlDoctorDetails,0)
.then(function (data) {
$scope.listDoctors=data;
});
adds the data to database
$scope.AddToList = function() {
var db = openDatabase("database");
db.transaction(function(tx) {
tx.executeSql(insertStatement);
});
Please help me to improve the code to update the list on adding new entry into the database.
sqlDoctorDetails and insertStatement are my query variables for displaying and inserting data respectively.

In the AddToList function push the latest doctor details which will update the list as well
So whenever you click on the add button and call a controller function:
$scope.addDoctorToDB(doctorDetail){
//add it to the doctor's list
$scope.listDoctors.push(doctorDetail);
//Now do the db operation say calling your add function
this.AddToList();
}

My Angular knowledge is rusty but I think after you insert into the DB you need to either insert to the in-memory model listDoctors or trigger the sqlDoctorDetails query to read the updated data into listDoctors.
Angular observes your model for changes but it doesn't observe the DB behind the model.

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.

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.

AngularJS: Currency Formatting. Change fraction size, thousands separator and fraction separator

I wish to show prices in a specific table within my site to 3 decimal places.
Prices will be shown in Pounds, Dollars and Euros.
My currency filter seems to automatically round the price to 2 decimal places.
Also, if the currency is in Euros, Ideally, I would like to auto change the thousands separator to a . and decimal separator to a ,.
Does angularjs have support for this?
The View
<div ng-controller="SpotController">
<table class="header-table-spot-prices">
<thead>
<tr><th>Spot Prices</th><th>Price</th></tr>
</thead>
<tbody>
<tr ng-repeat="spot in spots">
<td>{{ spot.item }}</td>
<!-- This needs to be 3dp -->
<td>{{ spot.price | currency:spot.currency }}</td>
</tr>
</tbody>
</table>
</div>
This is probably irrelevant at this point since the original post was 2 years ago, but angular's "currency" filter takes in a symbol and a fraction size as parameters.
For example:
<td>{{ spot.price | currency:spot.currency : 3 }}</td>
Would output what you are looking for without the caveat of changing the separators based on currency. You could either create your own currency filter that first uses the angular filter, then checks the condition and alters the separators. This plunker illustrates that.
.filter('myCurrency', ['$filter', function($filter){
return function(input, symbol, fractionSize){
input = $filter('currency')(input, symbol, fractionSize);
if(symbol === '\u20AC'){
var tempString = "###";
input = input.replace(",", tempString).replace(".", ",").replace(tempString, ".");
}
return input;
}
}])
You've probably already solved this for your needs, but putting the answer here just in case anyone else is running into a similar issue and comes across this post.

CakePHP, number of views

Suppose, this is a db table in my project :
<table>
<tr>
<th>id</th>
<th>title</th>
<th>description</th>
<th>created</th>
<th>modified</th>
<th>........</th>
</tr>
<tr>
<td>1</td>
<td>Some Title</td>
<td>Some Description</td>
<td>7/8/2013 8:50</td>
<td>7/8/2013 8:50</td>
<td>........</td>
</tr>
</table>
Now, I want to get the number how many times record 1 (id=1) has been seen. And that is in CakePHP. Is there any easy way to get this information ? I know created and modified are 2 fields whose values are automatically generated by CakePHP. So, is there any field or something that can be used here ? I marked this as ......... . Or, is there any other way to do this ? Thanks.
There's nothing built-in, but it's not hard to make yourself. (The hard part is to not increment the counter when search engine bots access the page if it's reachable to them.)
In the database create a field viewcount INT DEFAULT 0 for example. In the controller, assuming the model is called Model and action is view (replace with actual names), add the code that increments the counter when the page is viewed:
function view( $id ) {
// ....
$this->Model->updateAll(
array( 'Model.viewcount', 'Model.viewcount + 1' ),
array( 'Model.id', $id )
);
}
CakePHP doesn't have an "automatic" viewed field. If you'd like this functionality you have to implement it yourself with the updateAll method:
$this->Model->updateAll(
array('Model.views', 'Model.views + 1'),
array('Model.id', $id)
);

How do I display the name from one sql table linked by an id?

bit of a newbie to mvc. i am having trouble with the following scenario:
I have a view with the following:
<tr>
<% foreach (var game in (IEnumerable<Game>)ViewData["Game"])
{ %>
<td>
<input type="checkbox" name="selectedObjects" value="<%=game.Id%>" />
</td>
<td>
<%=game.GMTDateTime%>
</td>
<td>
<%=game.HomeTeamId%>
</td>
<td>
<%=game.AwayTeamId%>
</td>
<td>
<%=game.Venue%>
</td>
</tr>
All of the data displays OK except for HomeId and AwayId. These two fields are linked to another table called team and each Id in HomeTeamId and AwayTeamId relate to a record in the Team table and each id has a "Name". My problem is how do I display the "Name" from the Team table rather than the Id field shown.
The controller shows:
ViewData["Game"] = dc.Games.GetGames();
The query I am using in linq is:
public static IEnumerable<Game> GetGames(this Table<Game> source)
{
return from c in source
orderby c.GMTDateTime
select c;
}
Assuming you have defined the relationships in your schema, this should work:
<td>
<%=game.Team.Name%>
</td>
<td>
<%=game.Team1.Name%>
</td>
Because there are multiple FKs to the Team table, you will see two properties for Team, Team and Team1 (or similar). You'll need to determine which is which by looking at the generated LINQ code, or by trial and error, i.e., observing the output.
Normally using partial classes I will make additional properties that expose the Team object(s) with better names that make it clear which FK they are for.

Resources