Bill:
The links Rob Tweed posted will give you a start...actually all you need. If you download the GitHub repo, it contains enough "best practices" in the included demos to get going. What it doesn't cover is AngularJS integration. So I thought I would post an example. A typical task is use ng-repeat to build a table or more sophisticated grid.
For this table we want to display some of the contents of a language localization module that holds all the strings used in our application. The task of the two functions below is to fetch the contents of a Cache global that contains a list of supported countries/languages and pass that information to the controller that renders the table.
To get the data, we use Simon's Tweeds implementation of MicroServices in an Angular data service. This is rudimentary service that simply returns the entire table. We could pass it parameters to refine the search but given the nature of this table, we probably never will.
/*
^LanguageCode(1,"Code") = "af-ZA"
^LanguageCode(1,"Country") = "South Africa"
^LanguageCode(1,"CultureCode") = "0x0436"
^LanguageCode(1,"ISO639x") = "AFK"
^LanguageCode(1,"LanguageName") = "Afrikaans"
*/
// Data service
angular
.module('patsApp.grids')
.factory('LanguageCodeDataService', ['$q',
function($q) {
var deferred = $q.defer();
EWD.sockets.sendMessage({
type : 'getAllLanguageCode',
service : 'patsLocaleServices',
params : {
/* no params for entire global load */
},
done: function(messageObj) {
deferred.resolve(messageObj.message.data)
}
});
return deferred.promise;
}
])
The data is contained in the promise. We use the promise technique because the data fetch is async...we will get the data but we can't be sure the controller will get it to our table before its simple HTML structure is rendered. Heres the controller that uses the data service:
// Controller
angular
.module('patsApp.grids')
.controller('LanguageCodeSummaryTableController', ['$scope', 'LanguageCodeDataService',
function( $scope, LanguageCodeDataService) {
LanguageCodeDataService
.then(function(languageCodeItems) {
$scope.languageCodeItems = languageCodeItems;
},
function(error) {
$scope.error = error;
console.log('++> [LanguageCodeDataService] '+ error)
$scope.languageCodeItems = [];
}
);
if (PATSConfig.cLog.showControllerLog) {console.log('---- > [ Called: LanguageCodeSummaryTableController ]') }
}
]);
We inject the data service into the controller and when it is available it gets added to the $scope of the HTML table object on our page. All the fields (nodes) of the table are present in the $scope.languageCodeItems array but we can use whichever ones make sense for our table display.
Perhaps the coolest thing is that this backend service:
type : 'getAllLanguageCode',
service : 'patsLocaleServices',
managed by node server-side EWD, has all the plumbing to extract the data from the Cache database using javaScript-equivalents of familiar Cache functions such as $get and $order. A web page designer does not need any understanding of HOW
languageCodeItems is populated...they just call data service and build out the grid or table as they desire.
Perhaps even more interesting is that this entire process does not have a single line of COS/MUMPS anywhere! We are using plenty of COS, of course, because that is the language all the business logic of our legacy app is written in. But new features only need COS if we need to do massive high-speed data transformations inside the database itself.
Since EWDjs can call ObjectScript functions from JavaScript, we can continue to use the often arcane and complex functions that provide the app with sophisticated statistical analysis. (They have worked for 30 years...no sense in reinventing mathematics)..
Hope this gives you some insight into how AngularJS can integrate with Cache. Give how slick this is, it is hard to see the advantage of a PDO unless one had a huge amount of happily working PHP apps...but it looks like the code above could be adapted to build one out. (Not, by me...way to much work and with Angular/EWD/Node/Cache (CANE?) I don't see much of a role for PHP. :)
There was a lot I left out here...post is too long already. If you want to see the backend JavaScript that uses EWDjs to get or set the data and/or the html snippets that are populated by the code above let me know and I can share them off list.
jb