Commits

Dan Connolly committed 11e0e1e

show just top level accounts

Comments (0)

Files changed (2)

finjax/finjax/static/fin.js

 // todo: consider whether global controllers are fine.
 function AccountsCtrl($xhr) {
     var self = this;
+
     $xhr('GET', '../accounts', function(code, response) {
+	var a;
+	var parents = {};
+	var account_index = {}; // by guid
+	var acct;
+
 	self.accounts = response;
+
+	roots = angular.Array.filter(self.accounts,
+				     function(a) {
+					 return a.account_type == 'ROOT'
+				     });
+	self.root = roots[0];  // TODO: what if there is none?
+
+	for (a = 0; a < self.accounts.length; a++) {
+	    acct = self.accounts[a];
+	    account_index[acct.guid] = acct;
+	}
+	self.account_index = account_index;
+
+	self.children = function(pacct) {
+	    return angular.Array.filter(
+		self.accounts,
+		function(ch) {
+		    return ch.parent_guid == pacct.guid;
+		});
+	};
     });
 }
 

finjax/finjax/static/index.html

   <body ng:controller="AccountsCtrl">
     <h1>Accounts</h1>
 
-    <ul>
-      <li ng:repeat="account in accounts">
-	{{account.name}}
-	<p>{{account.description}}</p>
-      </li>
-    </ul>
+    <table>
+      <tr><th>Account Name</th><th>Type</th></tr>
+      <tr ng:repeat="account in
+		     children(root).$filter({'hidden': false}).$orderBy('name')">
+	<td>{{account.name}}</td><td>{{account.account_type}}</td>
+      </tr>
+    </table>
 
     <script src="http://code.angularjs.org/angular-0.9.12.js" ng:autobind></script>
-    <script src="fin.js"></script>
+    <script src="fin.js" type="text/javascript"></script>
   </body>
 </html>
 <!--
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.