Tuesday, February 26, 2013

Directives, Buttons, and Directives

For the most part, this is considered a bad-dog thing to do in AngularJs.  But sometimes… it just has to be done.  I came across this after hours and hours of fighting, then I looked deeper into ng-view.  If the directive tag was in a different file loaded in via the view, it will render properly.

Scenario:

Main page and a button.  The button opens a modal with a form.  When the form is submitted, that data is used to make a new directive DOM element on the main page. 

Problem: 

The new instance of the directive is just string on a page.  The directive never get applied.  We want the div on 8888 to say ‘Hello World!.  Without this $compile function, we would see <div>Hello World</div>.  The directive is never applied.

  <div ng-app="poc">
<div ng-controller="mainCtrl">
<div>Test 1 : sanity check</div>
<div xrx-hello-world></div>
<div>Test 2 : applied using getElementById(8888)</div>
<div id="8888">Replace Me</div>
<div xrx-add-button=""></div>
</div>
</div>


  
 
var poc = angular.module('poc', ['ngResource', 'ngSanitize']);

poc.directive("xrxHelloWorld", function () {
return {
priority: 50,
restrict: 'A',
replace: false,
transclude: true,
scope: false,
template: '<div>Hello World</div><div ng-transclude></div>',
};
});

poc.directive('xrxAddButton', function ($compile) {
return {
priority: 50,
restrict: 'A',
replace: false,
transclude: true,
scope: false,
template: '<button>Click</button><div ng-transclude></div>',
link: function (scope, element, attr) {
var btn = angular.element(element.children()[0]);

var handleClick = function () {
var directiveStr = '<div xrx-hello-world></div>';
var directiveDom = angular.element(directiveStr);
var newDomHome = angular.element($('#8888')).html(directiveDom);
$compile(newDomHome);
};
btn.bind('click', handleClick);
}
};
});







Thursday, February 21, 2013

AngularJS ng-click button click notes

Video Link

The presenter in the video nails it when they say 'Extreme Separation' of concerns.  I love this separation, but when prototyping... it makes you think.  Times that by 10 when you have chained directives!

I do think that it's more Angular-esque to use ng-click.

This example shows ng-click with a directive. http://jsfiddle.net/V7Kpb/12/


Quick show hide box
<div class="btn btn-info" ng-model="showSummary"
       ng-click="showSummary = 2/showSummary" 
       ng-init="showSummary=0">
  Show Summary
</div>
<div class="well well-small" ng-show="showSummary">My Text Here</div>



Wednesday, February 20, 2013

Angular Notes for the day

Found a good resource today AngularJs Cheetsheet.  They hid it on the home page of the google group for AngularJs.

Painful lesson earlier this week.  Don't forget the 'ng-transclude' attribute in the HTML for your template!

Nice sample for calling controller methods in html with angular expression on jsFiddle.


<span ng-class="cssActiveIf(folder)">
        <a href="javascript:void(0)">{{folder.name}}</a>
  </span>

function AssetCtrl($scope) {

 $scope.cssActiveIf = function(item) {
        return (item === $scope.selection.currentFolder) ? "active" : "";
    };
}



Wednesday, September 26, 2012

RavenDB Expiration Bundle

In RavenDB there is an expiration bundle.  This is great, think of it as a document retention policy.  Delete me in 90 days from now.  There is an issue in build 960 when you have both replication and expiration bundles installed.  Save ten documents test/1, test/2, and so on.  Set the expiration for 1 minute from now.

In Silverlight you will see the documents, but in 60 seconds you won’t.  The collection will still show a count of 10 documents.  Not the end of the world, the app still works, and no one can READ the documents that have expired.  But they still exist, they will be delete later.

Suppose you want to see the expired documents using the Expired Docs index.  Can’t the Read task prevents this from happening.  They are there and indexed, but there is a trigger that is preventing reads from happening.

This issue is fixed in the next release, but if you have a bunch of deletes on a large data set… it will be interesting to see if the counts are still a bit off in the admin console, possibly even query counts for pagination, just until the index catches up.

Sunday, September 23, 2012

RavenDB Replication

Doing some pre release testing or RavenDB Replication in build 960.  Thought I’d log and share my results.

SetUp

  • Create Two folders 8080 and 8081
  • unzip code base into each one
  • In server folder –> create plugins folder
  • from bundles folder –> copy the dlls for  –> replication, expiration
  • copy in my custom replication conflict resolution dll
  • edit server config -> change ‘get’ to ‘all’
    • change port setting from * to 8080 and 8081 depending on which folder I’m in.
  • Start Servers –> things look good.
  • Testing
    • Stop and start servers, look at logs.

Testing

I have a series of single task executable files I need to run.  Some set up our environment, others push data.

Testing Create Tenants exe
  1. Run exe against server:8080 then server:8081
  2. Check to see if databases are there –> they are all good.
Replication Configuration and Testing
  1. Create a document Test/101 on server:8080, using the Silverlight tool.
    image
    image
  2. Configure Replication and Server:8081 –> follow help docs on RavenDB.net
    image
  3. Wait a bit -> type reset in command line –> nothing happens –> 8081 is not reaching out to 8080 and pulling in the documents
  4. Configure replication on server 8080 to reach out to 8081
  5. Still no replication happening
  6. Added document Test/102 to 8081
  7. Found the error, copy and paste problem
    image
  8. Checking logs after fixed typo
    image
  9. Documents are still not replicating – Adding document test/105 to 8080
  10. Replication was working, but was replication from server:8080/databases/ClientA to server:8081 /databases/default
  11. Changed the Raven/Replication/Destinations documents on both servers to
    {"Url": “http://dfrfrm025080:8080/databases/ClientA/”}
  12. Success, Replication is working.  Going to delete replicated records out of default database to prevent future confusion.
Replication Conflict Resolution Testing
  1. Turn off server:8081 –> using q command in console so I don’t get a bunch of index errors when I start again
  2. server:8080 edit Test/105 –> Change Name from “Jane” to “Tarzan” and Save
  3. Turn off server:8080
  4. start server:8081
  5. Make sure in ClientA database (database and tenant are about the same thing)
  6. Edit Test/105 –> change Name from “Jane” to “Superman” save
  7. Start Server:8080 and wait a bit for things to mesh
  8. Both documents say superman
  9. Now going to do the same thing but in reverse order, since the conflict resolution dll’s are installed on both servers.
  10. server:8081  test/105 – name “IronMan”
  11. server:8080  test/105 – name “Batman”
  12. Restarted both servers to speed things up
  13. Looks good now both say “Batman”
  14. Since I issued a restart, the test is not entirely valid, I’ll monitor this later when I start pushing large amounts of data.

Thursday, August 23, 2012

Zend Server

I'm in a demo of the next version of Zend Server.  The UI is nice.  Permission are a welcome feature.

Tuesday, August 21, 2012

Jimmy’s bad experience with TDD. Was it really TDD?

Jimmy is introduced to test driven development. He has all these shiny tools that have unlimited power. Naturally, he only substitutes his current style (code-> run->point click test) with an automated test test runner. After a few days learning curve Jimmy is happy, he is cranking away on his current project and getting more done than he ever imagined. He has confidence in what he is writing because everything is green. Life is good.

Then all the sudden,some of his tests are not green but red. He reverts his code to a previous version, still red. He reboots his computer, still red. Starts debugging, only to find the data changed. The DBA’s cleaned out all the test data. Jimmy has an idea, he will use his new shiny tools to create scripts to check if the data is in the database, if not, it will populate. He spends a few days getting it just right and working with his unit test. Everything is green again, life is good. He starts coding again. Then his data population scripts start acting funny. The DBA’s changed the structure. Jimmy, while frustrated makes changes.

Then the stakeholder asks Jimmy to make some changes to the site, the changes are not small, but not too big either. But Jimmy finds that to make the changes requires more work than he is used to because he has to refactor his code, then make changes to the test, right in the middle of this process, more database changes come in. Jimmy is getting nervous because he is running out of time. Faced with the reality that is project may be late, he essentially abandons his tests, makes the changes to his code to make the stakeholder happy. He has every intention of coming back to ‘fix his tests’. He never does.

Jimmy is not the biggest fan of unit testing. He avoids it for the next few projects.

Then one day, Jimmy is assigned to a management console project. This project is painful because every little change is a pain to test. He has to run the app, log in, click through 5 different menus, fill out a form with a bunch of required fields and then submit. Development is slow and not very much fun. Jimmy know he can get around some of these problems by shifting his coding style a bit, then he can use his unit testing tools, mainly the test runner, to save some time. But when that project is over, so is the testing. He would like to do more, but bad experiences have soured his enthusiasm for what he thought was TDD. In reality Jimmy never really did TDD.
This story was written for an intro to a presentation on TDD.