fetching domain data list from firebase

James Peret преди 9 години
родител
ревизия
10de7679e2
променени са 2 файла, в които са добавени 37 реда и са изтрити 10 реда
  1. 13 2
      app/scripts/controllers/addPost.js
  2. 24 8
      app/scripts/controllers/domainsList.js

+ 13 - 2
app/scripts/controllers/addPost.js

@@ -23,7 +23,7 @@
23 23
         url: whoisUrl
24 24
       }).success(function(data) {
25 25
         console.log("Whois lookup successfull");
26
-        $scope.domain.whois = data;
26
+        $scope.mapData(data);
27 27
         $scope.saveToFirebase();
28 28
       }).error(function(data, status, headers, config) {
29 29
         console.log("Whois lookup error");
@@ -37,7 +37,10 @@
37 37
       domainsRef.push({
38 38
         name: $scope.domain.name,
39 39
         userId: UserData.getUser(),
40
-        whois: $scope.domain.whois
40
+        registrar: $scope.domain.registrar,
41
+        registration_date: $scope.domain.registration_date,
42
+        expiration_date: $scope.domain.expiration_date,
43
+        owner: $scope.domain.owner
41 44
       }, function(error) {
42 45
         if (error) {
43 46
           console.log('Error - Domain not created');
@@ -69,4 +72,12 @@
69 72
       return new_data;
70 73
     }
71 74
 
75
+    // Map data from api.who.pm
76
+    $scope.mapData = function(data) {
77
+      $scope.domain.registrar = data.registrar[0];
78
+      $scope.domain.registration_date = data.creation_date[0];
79
+      $scope.domain.expiration_date = data.expiration_date[0];
80
+      $scope.domain.owner = data.contacts.registrant.name;
81
+    }
82
+
72 83
   }]);

+ 24 - 8
app/scripts/controllers/domainsList.js

@@ -7,15 +7,31 @@
7 7
  * # AboutCtrl
8 8
  * Controller of the domainManagerApp
9 9
  */
10
-angular.module('domainManagerApp.domains', ['ui.bootstrap'])
11
-  .controller('DomainsListController', function ($scope, $http) {
12
-    $http({
13
-      method: 'GET',
14
-      url: '/scripts/data.json'
15
-    }).success(function(data) {
16
-      $scope.domains = data.domains;
10
+angular.module('domainManagerApp.domains', ['ui.bootstrap', 'firebase'])
11
+  .controller('DomainsListController',['$scope', '$firebase', function ($scope, $firebase) {
12
+    // $http({
13
+    //   method: 'GET',
14
+    //   url: '/scripts/data.json'
15
+    // }).success(function(data) {
16
+    //   $scope.domains = data.domains;
17
+    // });
18
+
19
+    $scope.domains = [];
20
+
21
+    // Get domain list from firebase
22
+    var ref = new Firebase("https://j1x-cpanel.firebaseio.com/domains");
23
+    ref.on("child_added", function(data) {
24
+      if(!$scope.$$phase) {
25
+        $scope.$apply(function(){
26
+          $scope.domains.push(data.val());
27
+        });
28
+      }
29
+    }, function (errorObject) {
30
+      console.log("The read failed: " + errorObject.code);
17 31
     });
18 32
 
33
+
34
+
19 35
     $scope.oneAtATime = false;
20 36
     $scope.isOpen = false;
21 37
 
@@ -30,4 +46,4 @@ angular.module('domainManagerApp.domains', ['ui.bootstrap'])
30 46
       return color;
31 47
     }
32 48
 
33
-  });
49
+  }]);