WIP Domain listing app with automatic status checking. Buitl with AngularJS.

addPost.js 3.2KB

    'use strict'; /** * @ngdoc function * @name domainManagerApp.controller:MainCtrl * @description * # MainCtrl * Controller of the domainManagerApp */ angular.module('domainManagerApp.addPost', ['firebase', 'domainManagerApp.userData']) .controller('AddPostController', ['$scope', 'UserData', '$firebase', '$http', function ($scope, UserData, $firebase, $http) { $scope.AddDomain = function() { console.log('Creating domain ' + $scope.domain.name); $scope.whoisLookup(); } $scope.whoisLookup = function() { // Whois domain lookup console.log("Whois lookup..."); var whoisUrl = 'https://j1x-whois.herokuapp.com/lookup.json?url=' + $scope.domain.name; $http({ method: 'GET', url: whoisUrl }).success(function(data) { console.log("Whois lookup successfull"); $scope.mapData(data); $scope.saveToFirebase(); }).error(function(data, status, headers, config) { console.log("Whois lookup error"); }); } $scope.saveToFirebase = function() { // Save to Firebase var firebaseObj = new Firebase("https://j1x-cpanel.firebaseio.com/"); var domainsRef = firebaseObj.child("domains"); domainsRef.push({ name: $scope.domain.name, userId: UserData.getUser(), registrar: $scope.domain.registrar, registration_date: $scope.domain.registration_date, expiration_date: $scope.domain.expiration_date, owner: $scope.domain.owner }, function(error) { if (error) { console.log('Error - Domain not created'); } else { console.log('Domain created'); } }); } $scope.parseWhoisData = function(data) { var new_data = []; console.log(data); for (var i = 0; i < data.length; i++) { var keys = {}; if (data[i] != ""){ keys = data[i].split(": ") console.log(data[i]); console.log(keys); if(keys.length >= 2){ var hash = new Array(); hash[keys[0]] = keys[1]; hash[0].replace(/\s+/g,"_").replace(/\.+/g,"_").replace(/\#+/g,"_").replace(/\$+/g,"_").replace(/\//g,"_").replace(/\[+/g,"_").replace(/\[+/g,"_"); console.log(hash); new_data.push(hash); } } } console.log(new_data); return new_data; } // Map data from api.who.pm $scope.mapData = function(data) { console.log(data); // Data: Registrar if(data.registrar != undefined){ $scope.domain.registrar = data.registrar; } else { $scope.domain.registrar = ""; } // Data: Creation Date if(data.created_on != undefined) { $scope.domain.registration_date = data.created_on; } else { $scope.domain.registration_date = ""; } // Data: Expiration Date if(data.expires_on != undefined) { $scope.domain.expiration_date = data.expires_on; } else { $scope.domain.expiration_date = ""; } // Data Owner if(data.owner != undefined) { $scope.domain.owner = data.owner; } else { $scope.domain.owner = ""; } } }]);