Created
May 30, 2014 17:35
-
-
Save bmelton/e5cc4a59252b2ea26b12 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var App = angular.module('App', [ | |
'linkify', 'ngRoute', 'FixBoolean', 'CompatibilityFilter', 'TierFilter', | |
'RevenueFilter', 'SlugifyFilter', 'FixDateFilter', 'FixCategory', | |
'Help', | |
]) | |
// Define authentication headers for API request | |
var auth_headers = { | |
headers: { | |
'Authorization':'apikey tpui:e54b64ad813c66669467daa110bffb25ba27e829' | |
} | |
}; | |
App.config(function ($routeProvider, $locationProvider) { | |
$routeProvider | |
.when('/', { | |
templateUrl: '/partials/index.html' | |
}) | |
.when('/cpe/:id', { | |
templateUrl: '/partials/cpe.html', | |
controller: 'CPEController' | |
}) | |
.when('/software/:id', { | |
templateUrl: '/partials/software.html', | |
controller: 'SoftwareController' | |
}) | |
.when('/version/:id', { | |
templateUrl: '/partials/version.html', | |
controller: 'VersionController' | |
}) | |
.when('/release/:id', { | |
templateUrl: '/partials/release.html', | |
controller: 'ReleaseController' | |
}) | |
.when('/hardware/model/:id', { | |
templateUrl: '/partials/hardware_model.html', | |
controller: 'HardwareModelController' | |
}) | |
.when('/hardware/:id', { | |
templateUrl: '/partials/hardware.html', | |
controller: 'HardwareController' | |
}) | |
.when('/search/:q/:filter_type/:page', { | |
templateUrl: '/partials/search.html', | |
controller: 'SearchController' | |
}) | |
.when('/search/:q', { | |
templateUrl: '/partials/search.html', | |
controller: 'SearchController' | |
}) | |
.when('/search', { | |
controller: 'SearchController' | |
}) | |
.when('/browse/', { | |
templateUrl: '/partials/browse.html', | |
controller: 'BrowseController' | |
}) | |
.when('/browse/:taxonomy_id', { | |
templateUrl: '/partials/browse.html', | |
controller: 'BrowseController' | |
}) | |
.when('/browse/:taxonomy_id/:currentPage', { | |
templateUrl: '/partials/browse.html', | |
controller: 'BrowseController' | |
}) | |
.when('/browse/:taxonomy_id', { | |
templateUrl: '/partials/browse.html', | |
controller: 'BrowseController' | |
}) | |
.when('/manufacturer/:id/:active/:currentPage', { | |
templateUrl: '/partials/manufacturer.html', | |
controller: 'ManufacturerController', | |
reloadOnSearch: false | |
}) | |
.when('/manufacturer/:id/:active', { | |
templateUrl: '/partials/manufacturer.html', | |
controller: 'ManufacturerController', | |
reloadOnSearch: false | |
}) | |
.when('/manufacturer/:id', { | |
templateUrl: '/partials/manufacturer.html', | |
controller: 'ManufacturerController', | |
}) | |
.when('/search/:q/:filter_type', { | |
templateUrl: '/partials/search.html', | |
controller: 'SearchController' | |
}) | |
.when('/search/:q', { | |
templateUrl: '/partials/search.html', | |
controller: 'SearchController' | |
}) | |
.when('/search', { | |
controller: 'SearchController' | |
}) | |
.when('/browse/', { | |
templateUrl: '/partials/browse.html', | |
controller: 'BrowseController' | |
}) | |
.when('/browse/:taxonomy_id', { | |
templateUrl: '/partials/browse.html', | |
controller: 'BrowseController' | |
}) | |
.when('/browse/:taxonomy_id/:currentPage', { | |
templateUrl: '/partials/browse.html', | |
controller: 'BrowseController' | |
}) | |
.when('/browse/:taxonomy_id', { | |
templateUrl: '/partials/browse.html', | |
controller: 'BrowseController' | |
}) | |
.when('/manufacturer/:id/:active/:currentPage', { | |
templateUrl: '/partials/manufacturer.html', | |
controller: 'ManufacturerController', | |
reloadOnSearch: false | |
}) | |
.when('/manufacturer/:id/:active', { | |
templateUrl: '/partials/manufacturer.html', | |
controller: 'ManufacturerController', | |
reloadOnSearch: false | |
}) | |
.when('/manufacturer/:id', { | |
templateUrl: '/partials/manufacturer.html', | |
controller: 'ManufacturerController', | |
reloadOnSearch: false | |
}) | |
.when('/support', { | |
templateUrl: '/partials/support.html' | |
}) | |
.when('/about', { | |
templateUrl: '/partials/about.html' | |
}) | |
.when('/terms', { | |
templateUrl: '/partials/terms.html' | |
}) | |
.when('/privacy', { | |
templateUrl: '/partials/privacy.html' | |
}) | |
.otherwise({redirectTo: '/'}); | |
$locationProvider.html5Mode(true); | |
$locationProvider.hashPrefix('!'); | |
}) | |
var HelpModule = angular.module('Help', []) | |
HelpModule.factory('HelpAPI', function() { | |
return { | |
status: null, | |
message: null, | |
show_helptext: function(message) { | |
this.status = "hello"; | |
this.message = message; | |
}, | |
clear: function() { | |
this.status = null; | |
this.message = null; | |
this.helptext_on = false; | |
} | |
} | |
}) | |
HelpModule.directive('helptext', function() { | |
return { | |
restrict: 'E', | |
scope: {}, | |
replace: true, | |
controller: function($scope, HelpAPI) { | |
$scope.show = false; | |
$scope.api = HelpAPI; | |
$scope.$watch('api.status', toggledisplay); | |
$scope.$watch('api.message', toggledisplay); | |
$scope.hide = function() { | |
$scope.show = false; | |
$scope.helptext_on = false; | |
$scope.api.clear(); | |
}; | |
function toggledisplay() { | |
$scope.helptext_on = !!($scope.api.status && $scope.api.message); | |
$scope.show = !!($scope.api.status && $scope.api.message); | |
} | |
}, | |
templateUrl: "/partials/help.html" | |
}; | |
}); | |
angular.module('CompatibilityFilter', []) | |
.filter('fixCompatibility', function() { | |
return function(input) { | |
if(input) | |
return input.replace("WINDOWS", ""); | |
}; | |
}); | |
angular.module('RevenueFilter', []) | |
.filter('fixRevenue', function() { | |
return function(input) { | |
revenue = input; | |
if(revenue > 1000) { | |
output = "$" + revenue / 1000 + " Billion"; | |
} else if (revenue == null) { | |
output = "0"; | |
} else if (revenue == 0) { | |
output = "0"; | |
} else { | |
output = "$" + revenue + " Million"; | |
} | |
return output; | |
} | |
}); | |
angular.module('SlugifyFilter', []) | |
.filter('slugify', function() { | |
return function(input) { | |
var output = input.toLocaleLowerCase(); | |
output = output.replace(" ", "-"); | |
return output; | |
} | |
}) | |
angular.module('TierFilter', []) | |
.filter('fixTier', function() { | |
return function(input) { | |
if(input == "10") | |
return "Inactive"; | |
return input; | |
} | |
}); | |
angular.module('FixBoolean', []) | |
.filter('fixBoolean', function() { | |
return function(input) { | |
if(input == "1") | |
return "True"; | |
if(input == "0") | |
return "False"; | |
return input; | |
}; | |
}); | |
angular.module('FixCategory', []) | |
.filter('fixcategory', function() { | |
return function(input) { | |
inputParts = input.split("."); | |
if(inputParts[1] == "softwarerelease") { | |
return "software"; | |
} | |
return inputParts[1]; | |
} | |
}) | |
angular.module('FixDateFilter', []) | |
.filter('fixdate', function() { | |
return function(input) { | |
var NAMessage = "Not Available"; | |
if(input == null) | |
output = NAMessage; | |
else if(input == "midnight") | |
output = NAMessage; | |
else if(input == "") | |
output = NAMessage; | |
else if(input == "1900-01-01") | |
output = NAMessage; | |
else | |
output = input; | |
return output; | |
} | |
}) | |
function SearchController($scope, $http, $routeParams) { | |
if($routeParams.q && !$routeParams.filter_type) { | |
window.location = "/search/" + $routeParams.q + "/None"; | |
} | |
$scope.search = {}; | |
$scope.limit = 30; | |
$scope.currentPage = 1; | |
if($routeParams.page) | |
$scope.currentPage = $routeParams.page; | |
$scope.offset = ($scope.currentPage * $scope.limit) - $scope.limit; | |
$scope.prev_page = parseInt($scope.currentPage) - parseInt(1); | |
$scope.next_page = parseInt($scope.currentPage) + parseInt(1); | |
$scope.calculate_pages = function(data, page) { | |
if(!page) | |
$scope.search.current_page = 1; | |
else | |
$scope.search.current_page = page; | |
if(data.start > 0) | |
$scope.search.has_previous = true; | |
if(!data.rows) | |
$scope.search.rows = 20; | |
else | |
$scope.search.rows = data.rows; | |
$scope.search.num_pages = Math.ceil(data.numFound / $scope.search.rows); | |
if($scope.search.current_page < $scope.search.num_pages) | |
$scope.search.has_next = true; | |
$scope.search.start = $scope.search.current_page * $scope.search.rows; | |
}; | |
$scope.nextPage = function() { | |
$scope.search.current_page = $scope.search.current_page + 1; | |
$scope.calculate_pages($scope.data, $scope.search.current_page); | |
$scope.updateResults(); | |
} | |
if($routeParams.q) | |
$scope.search.term = $routeParams.q; | |
if($routeParams.filterType) | |
$scope.search.type = $routeParams.filterType; | |
else | |
$scope.search.type = "None"; | |
$scope.updateResults = function() { | |
if($routeParams.q) { | |
var url = "/solr/select?wt=json&rows=20&start=" + $scope.offset + "&q=" + $routeParams.q; | |
var mfgr_url = url + "&defType=dismax&fq=django_ct:catalog.manufacturer"; | |
var soft_url = url + "&defType=dismax&fq=django_ct:catalog.software"; | |
var hard_url = url + "&defType=dismax&fq=django_ct:catalog.hardwaremodel"; | |
if($routeParams.filter_type && $routeParams.filter_type !== "None") | |
url = url + "&defType=dismax&fq=django_ct:catalog." + $routeParams.filter_type; | |
$scope.url = url | |
$http.get(url) | |
.success(function(data) { | |
$scope.search_results = {}; | |
$scope.data = data.response; | |
$scope.results = data; | |
$scope.results.meta = data.response; | |
$scope.results.meta.limit = $scope.limit; | |
$scope.results.meta.total_count = data.response.numFound; | |
$scope.results.meta.total_pages = Math.ceil($scope.results.meta.total_count / $scope.results.meta.limit); | |
if($scope.results.meta.total_count > $scope.results.meta.limit) | |
$scope.results.meta.has_next = true; | |
if($scope.offset < $scope.limit) | |
$scope.results.meta.has_prev = false; | |
else | |
$scope.results.meta.has_prev = true; | |
// $scope.calculate_pages(data.response); | |
for(var i = 0; i < data.response.docs.length; i++) {; | |
$scope.search_results[i] = data.response.docs[i]; | |
$scope.search.num_results = data.response.numFound; | |
if($scope.search_results[i].django_ct == "catalog.manufacturer") { | |
$scope.search_results[i].url = "/manufacturer/" + $scope.search_results[i].django_id; | |
} | |
if($scope.search_results[i].django_ct == "catalog.software") { | |
$scope.search_results[i].url = "/software/" + $scope.search_results[i].django_id; | |
} | |
if($scope.search_results[i].django_ct == "catalog.hardwaremodel") { | |
$scope.search_results[i].url = "/hardware/model/" + $scope.search_results[i].django_id; | |
} | |
if($scope.search_results[i].django_ct == "catalog.softwarerelease") { | |
$scope.search_results[i].url = "/release/" + $scope.search_results[i].django_id; | |
} | |
}; | |
}); | |
$http.get(mfgr_url) | |
.success(function(data) { | |
$scope.manufacturer_count = data.response.numFound; | |
}); | |
$http.get(soft_url) | |
.success(function(data) { | |
$scope.software_count = data.response.numFound; | |
}); | |
$http.get(hard_url) | |
.success(function(data) { | |
$scope.hardware_count = data.response.numFound; | |
}); | |
$scope.didFound = false; | |
$scope.didYouMean = {}; | |
if($routeParams.q.toLowerCase() == "osx") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "OS X"; | |
$scope.didYouMean.url = "/search/os x"; | |
} | |
if($routeParams.q.toLowerCase() == "os10") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "OS X"; | |
$scope.didYouMean.url = "/search/os x"; | |
} | |
if($routeParams.q.toLowerCase() == "os 10") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "OS X"; | |
$scope.didYouMean.url = "/search/os x"; | |
} | |
if($routeParams.q.toLowerCase() == "att") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "AT&T"; | |
$scope.didYouMean.url = "/manufacturer/4731"; | |
} | |
if($routeParams.q.toLowerCase() == "at&t") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "AT&T"; | |
$scope.didYouMean.url = "/manufacturer/4731"; | |
} | |
if($routeParams.q.toLowerCase() == "ms") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "Microsoft"; | |
$scope.didYouMean.url = "/manufacturer/7365"; | |
} | |
if($routeParams.q.toLowerCase() == "msit") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "Microsoft IT"; | |
$scope.didYouMean.url = "/manufacturer/25258057"; | |
} | |
if($routeParams.q.toLowerCase() == "ms-it") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "Microsoft IT"; | |
$scope.didYouMean.url = "/manufacturer/25258057"; | |
} | |
if($routeParams.q.toLowerCase() == "ms it") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "Microsoft IT"; | |
$scope.didYouMean.url = "/manufacturer/25258057"; | |
} | |
if($routeParams.q.toLowerCase() == "ti ") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "Texas Instruments"; | |
$scope.didYouMean.url = "/manufacturer/16556"; | |
} | |
if($routeParams.q.toLowerCase() == "sales force") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "Salesforce.com"; | |
$scope.didYouMean.url = "/manufacturer/8433"; | |
} | |
if($routeParams.q.toLowerCase() == "sfdc") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "Salesforce.com"; | |
$scope.didYouMean.url = "/manufacturer/8433"; | |
} | |
if($routeParams.q.toLowerCase() == "amazon") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "Amazon.com"; | |
$scope.didYouMean.url = "/manufacturer/14938863"; | |
} | |
if($routeParams.q.toLowerCase() == "aws") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "Amazon.com"; | |
$scope.didYouMean.url = "/manufacturer/14938863"; | |
} | |
if($routeParams.q.toLowerCase() == "ea") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "Electronic Arts"; | |
$scope.didYouMean.url = "/manufacturer/5834"; | |
} | |
if($routeParams.q.toLowerCase() == "ea sports") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "Electronic Arts"; | |
$scope.didYouMean.url = "/manufacturer/5834"; | |
} | |
if($routeParams.q.toLowerCase() == "jpmc") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "JPMorgan Chase & Co"; | |
$scope.didYouMean.url = "/manufacturer/24970642"; | |
} | |
if($routeParams.q.toLowerCase() == "now") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "ServiceNow"; | |
$scope.didYouMean.url = "/manufacturer/41148110"; | |
} | |
if($routeParams.q.toLowerCase() == "snow") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "ServiceNow"; | |
$scope.didYouMean.url = "/manufacturer/41148110"; | |
} | |
if($routeParams.q.toLowerCase() == "service now") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "ServiceNow"; | |
$scope.didYouMean.url = "/manufacturer/41148110"; | |
} | |
if($routeParams.q.toLowerCase() == "amd") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "Advanced Micro Devices"; | |
$scope.didYouMean.url = "/manufacturer/1061834"; | |
} | |
if($routeParams.q.toLowerCase() == "motu") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "Mark of the Unicorn"; | |
$scope.didYouMean.url = "/manufacturer/7212"; | |
} | |
if($routeParams.q.toLowerCase() == "techdata") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "Tech Data"; | |
$scope.didYouMean.url = "/manufacturer/9018"; | |
} | |
if($routeParams.q.toLowerCase() == "usr") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "U.S. Robotics"; | |
$scope.didYouMean.url = "/manufacturer/9331"; | |
} | |
if($routeParams.q.toLowerCase() == "ca") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "CA Technologies"; | |
$scope.didYouMean.url = "/manufacturer/5338"; | |
} | |
if($routeParams.q.toLowerCase() == "catech") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "CA Technologies"; | |
$scope.didYouMean.url = "/manufacturer/5338"; | |
} | |
if($routeParams.q.toLowerCase() == "computer associates") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "CA Technologies"; | |
$scope.didYouMean.url = "/manufacturer/5338"; | |
} | |
if($routeParams.q.toLowerCase() == "network appliance") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "NetApp"; | |
$scope.didYouMean.url = "/manufacturer/5338"; | |
} | |
if($routeParams.q.toLowerCase() == "hp") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "Hewlett-Packard Company"; | |
$scope.didYouMean.url = "/manufacturer/6451"; | |
} | |
if($routeParams.q.toLowerCase() == "ge") { | |
$scope.didFound = true; | |
$scope.didYouMean.term = "General Electric Company"; | |
$scope.didYouMean.url = "/manufacturer/5338"; | |
} | |
} else { | |
$scope.executeSearch = function() { | |
if($scope.search.term) { | |
var url = "/solr/select?wt=json&q=" + $scope.search.term; | |
$http.get(url) | |
.success(function(data) { | |
if(data.response.numFound > 0) { | |
type = data.response.docs[0].django_ct; | |
id = data.response.docs[0].django_id; | |
} | |
if(data.response.numFound == 1) { | |
if(type == "catalog.manufacturer") { | |
redirect_url = "/manufacturer/" + id; | |
} | |
if(type == "catalog.software") { | |
redirect_url = "/software/" + id; | |
} | |
if(type == "catalog.softwarerelease") { | |
redirect_url = "/release/" + id; | |
} | |
if(type == "catalog.hardwaremodel") { | |
} | |
} else { | |
redirect_url = "/search/" + $scope.search.term; | |
} | |
window.location = redirect_url; | |
}) | |
} | |
} | |
} | |
} | |
$scope.updateResults(); | |
} | |
function BrowseController($scope, $http, $routeParams, $q) { | |
// Set limit for API queries | |
$scope.limit = 20; | |
// Default values for current pages and offsets | |
$scope.currentPage = 1; | |
if($routeParams.currentPage){ | |
$scope.currentPage = $routeParams.currentPage; | |
} | |
// Calculate query offsets | |
$scope.offset = ($scope.currentPage * $scope.limit) - $scope.limit; | |
$scope.prev_page = parseInt($scope.currentPage)-parseInt(1); | |
$scope.next_page = parseInt($scope.currentPage)+parseInt(1); | |
// Only use one tab for both hardware and software | |
// This makes things a little cleaner. | |
$scope.tabs = [ | |
{ title: "", active: "active", count: 0 }, | |
]; | |
// API query button | |
$scope.collapsed = true; | |
$scope.explainText = "Show API Queries"; | |
$scope.collapseExplain = function(button) { | |
$scope.collapsed = !$scope.collapsed; | |
if($scope.collapsed == false) { | |
$("#explain").slideDown(); | |
$scope.explainText = "Hide API Queries"; | |
} else { | |
$("#explain").slideUp(); | |
$scope.explainText = "Show API Queries"; | |
} | |
}; | |
// No longer used since we only have 1 tab, | |
// but I figured I'd keep it in case the page changes later. | |
$scope.setTabActive = function(tab) { | |
for(var i = 0; i < $scope.tabs.length; i++) { | |
$scope.tabs[i].active = ""; | |
} | |
tab.tab.active = "active"; | |
}; | |
// Handle when user selects top-level Taxonomy | |
// in the left-bar navigation | |
$scope.selectCategory = function(category) { | |
$scope.timeout = category; | |
$scope.subcategories = null; | |
$scope.selected = category; | |
// Fill out a top-level taxonomy's sub-categories | |
$http.get('/api/v1/taxonomy2012/?format=json&limit=0&cat_taxonomy2012_parent_id=' + category, auth_headers) | |
.success(function(data, status, headers, config){ | |
$scope.subcategories = data.taxonomy2012_list; | |
$scope.timeout = false; | |
}); | |
} | |
// Grab top-level Taxonomy objects to build left nav | |
var categories = $http.get('/api/v1/taxonomy2012/?format=json&cat_taxonomy2012_parent_id=None&limit=0', auth_headers) | |
.success(function(data, status, headers, config){ | |
$scope.categories = data.taxonomy2012_list; | |
}); | |
// Only bother grabbing results if a taxonomy ID was passed via the URL | |
if($routeParams.taxonomy_id) { | |
// Grab taxonomy via passed ID in the URL. | |
var taxonomy = $http.get('/api/v1/taxonomy2012/' + $routeParams.taxonomy_id + '/?format=json' + $routeParams.taxonomy_id, auth_headers) | |
.success(function(data, status, headers, config){ | |
$scope.selectCategory(data.parent_id); // Automatically select to open left nav | |
$scope.taxonomy = data; // Pass taxonomy to template | |
$scope.tabs[0].title = data.software_hardware; // Set title of tab to type of results | |
$scope.show_results = true; // Set template flag to show results | |
// Fire only if Taxonomy is a Software one. | |
if(data.software_hardware=="Software") { | |
var software = $http.get('/api/v1/sw_product/?format=json&limit=' + $scope.limit + '&offset=' + $scope.offset + '&cat_taxonomy2012_id=' + $routeParams.taxonomy_id, auth_headers) | |
.success(function(data, status, headers, config){ | |
$scope.results = data.sw_product_list; | |
$scope.tabs[0].count = data.meta.total_count; | |
$scope.show_software = true; // Show software results table | |
// For pagination | |
$scope.results.meta = data.meta; | |
$scope.results.meta.total_count = data.meta.total_count; | |
$scope.results.meta.limit = data.meta.limit; | |
$scope.results.meta.total_pages = Math.ceil($scope.results.meta.total_count / $scope.results.meta.limit); | |
if($scope.results.meta.total_count > $scope.results.meta.limit){ | |
$scope.results.meta.has_next = true; | |
} | |
// Decide if next / previous buttons should be shown | |
if($scope.offset < $scope.limit){ | |
$scope.results.meta.has_prev = false; | |
} else { | |
$scope.results.meta.has_prev = true; | |
} | |
}). | |
error(function(data, status, headers, config) { | |
// called asynchronously if an error occurs | |
// or server returns response with an error status. | |
}); | |
} | |
// Only fire if the Taxonomy is a Hardware one. | |
if(data.software_hardware == "Hardware") { | |
var hardware = $http.get('/api/v1/hw_product/?format=json&limit=' + $scope.limit + '&offset=' + $scope.offset + '&cat_taxonomy2012_id=' + $routeParams.taxonomy_id, auth_headers) | |
.success(function(data, status, headers, config){ | |
$scope.results = data.hw_product_list; | |
$scope.tabs[0].count = data.meta.total_count; | |
$scope.show_hardware = true; // Show hardware results table | |
// For pagination | |
$scope.results.meta = data.meta; | |
$scope.results.meta.total_count = data.meta.total_count; | |
$scope.results.meta.limit = data.meta.limit; | |
$scope.results.meta.total_pages = Math.ceil($scope.results.meta.total_count / $scope.results.meta.limit); | |
if($scope.results.meta.total_count > $scope.results.meta.limit){ | |
$scope.results.meta.has_next = true; | |
} | |
// Decide if next / previous buttons should be shown | |
if($scope.offset < $scope.limit){ | |
$scope.results.meta.has_prev = false; | |
} else { | |
$scope.results.meta.has_prev = true; | |
} | |
}). | |
error(function(data, status, headers, config) { | |
// called asynchronously if an error occurs | |
// or server returns response with an error status. | |
}); | |
} | |
}). | |
error(function(data, status, headers, config) { | |
// called asynchronously if an error occurs | |
// or server returns response with an error status. | |
}); | |
} | |
}; | |
App.directive('prettyprint', function() { | |
return { | |
restrict: 'C', | |
link: function postLink(scope, element, attrs) { | |
element.html(prettyPrintOne(scope.dom)); | |
} | |
}; | |
}); | |
function ManufacturerController($scope, $sce, $http, $routeParams, $q, $location, HelpAPI) { | |
// Pagination | |
$scope.limit = 30; | |
$scope.currentPage = 1; | |
if($routeParams.currentPage) { | |
$scope.currentPage = $routeParams.currentPage; | |
} | |
$scope.offset = ($scope.currentPage * $scope.limit) - $scope.limit; | |
$scope.prev_page = parseInt($scope.currentPage)-parseInt(1); | |
$scope.next_page = parseInt($scope.currentPage)+parseInt(1); | |
$scope.tabs = [ | |
{ title: "Software", active: "active", count: 0 }, | |
{ title: "Hardware", active: "", count: 0 }, | |
{ title: "CPUs", active: "", count: 0 } | |
]; | |
$scope.setTabActive = function(tab) { | |
for(var i = 0; i < $scope.tabs.length; i++) { | |
$scope.tabs[i].active = ""; | |
} | |
tab.tab.active = "active"; | |
}; | |
$scope.updateTab = function(tab) { } | |
if($routeParams.active) { | |
if($routeParams.active == "Software") { | |
$scope.tabs[0].active = "active"; | |
$scope.tabs[1].active = ""; | |
$scope.tabs[2].active = ""; | |
} | |
if($routeParams.active == "Hardware") { | |
$scope.tabs[0].active = ""; | |
$scope.tabs[1].active = "active"; | |
$scope.tabs[2].active = ""; | |
} | |
if($routeParams.active == "CPUs") { | |
$scope.tabs[0].active = ""; | |
$scope.tabs[1].active = ""; | |
$scope.tabs[2].active = "active"; | |
} | |
} | |
$scope.$on('$routeUpdate', function(scope, next, current) { | |
var tab = $location.search().tab; | |
}); | |
if(!$location.search().tab) | |
$scope.updateTab(0); | |
$scope.selectNew = function(selection) { | |
$scope.selected = selection; | |
if(selection == "manufacturer") { | |
$scope.dom = $scope.manufacturer; | |
$scope.url = $scope.manufacturer_url; | |
} | |
if(selection == "software") { | |
$scope.dom = $scope.software; | |
$scope.url = $scope.software_url; | |
} | |
if(selection == "hardware") { | |
$scope.dom = $scope.hardware; | |
$scope.url = $scope.hardware_url; | |
} | |
if(selection == "cpu") { | |
$scope.dom = $scope.cpu; | |
$scope.url = $scope.cpu_url; | |
} | |
} | |
$scope.selected = "manufacturer"; | |
$scope.collapsed = true; | |
$scope.url = "/api/v1/manufacturer/" + $routeParams.id + "/?format=json"; | |
$scope.collapseExplain = function(button) { | |
$scope.explore = true; | |
}; | |
$scope.manufacturer_url = "/api/v1/manufacturer/" + $routeParams.id + "/?format=json"; | |
$http.get($scope.manufacturer_url, auth_headers) | |
.success(function(data, status, headers, config){ | |
$scope.manufacturer = data; | |
$scope.dom = $scope.manufacturer; | |
document.title = data.manufacturer + " | Technopedia"; | |
}) | |
.error(function(data, status, headers, config) { | |
$scope.error = true; | |
$scope.status = status; | |
}) | |
$scope.software_url = "/api/v1/sw_product/?manufacturer_id=" + $routeParams.id + "&limit=" + $scope.limit + "&offset=" + $scope.offset; | |
var software = $http.get($scope.software_url, auth_headers) | |
.success(function(data, status, headers, config) { | |
$scope.software = data.sw_product_list; | |
$scope.software.meta = data.meta; | |
$scope.software.meta.total_count = data.meta.total_count; | |
$scope.software.meta.limit = data.meta.limit; | |
$scope.software.meta.total_pages = Math.ceil($scope.software.meta.total_count / $scope.software.meta.limit); | |
if($scope.software.meta.total_count > $scope.software.meta.limit) | |
$scope.software.meta.has_next = true; | |
if($scope.offset < $scope.limit) | |
$scope.software.meta.has_prev = false; | |
else | |
$scope.software.meta.has_prev = true; | |
// $scope.software_total_pages = Math.ceil(data.meta.total_count / data.meta.limit); | |
$scope.tabs[0].count = data.meta.total_count; | |
}); | |
$scope.cpu_url = "/api/v1/cpu_model/?cat_manufacturer_id=" + $routeParams.id + "&limit=" + $scope.limit + "&offset=" + $scope.offset; | |
var cpu = $http.get($scope.cpu_url, auth_headers) | |
.success(function(data, status, headers, config) { | |
$scope.cpu = data.cpu_model_list; | |
$scope.cpu.meta = data.meta; | |
$scope.cpu.meta.total_count = data.meta.total_count; | |
$scope.cpu.meta = data.meta; | |
$scope.cpu.meta.total_count = data.meta.total_count; | |
$scope.cpu.meta.limit = data.meta.limit; | |
$scope.cpu.meta.total_pages = Math.ceil($scope.cpu.meta.total_count / $scope.cpu.meta.limit); | |
if($scope.cpu.meta.total_count > $scope.cpu.meta.limit) | |
$scope.cpu.meta.has_next = true; | |
if($scope.offset < $scope.limit) | |
$scope.cpu.meta.has_prev = false; | |
else | |
$scope.cpu.meta.has_prev = true; | |
// $scope.software_total_pages = Math.ceil(data.meta.total_count / data.meta.limit); | |
$scope.tabs[2].count = data.meta.total_count; | |
}); | |
$scope.hardware_url = "/api/v1/hw_product/?manufacturer_id=" + $routeParams.id + "&limit=" + $scope.limit + "&offset=" + $scope.offset; | |
var hardware = $http.get($scope.hardware_url, auth_headers) | |
.success(function(data, status, headers, config) { | |
$scope.tabs[1].count = data.meta.total_count; | |
$scope.hardware = data.hw_product_list; | |
$scope.hardware.meta = data.meta; | |
$scope.hardware.meta.total_count = data.meta.total_count; | |
$scope.hardware.meta.limit = data.meta.limit; | |
$scope.hardware.meta.total_pages = Math.ceil($scope.hardware.meta.total_count / $scope.hardware.meta.limit); | |
if($scope.hardware.meta.total_count > $scope.hardware.meta.limit) | |
$scope.hardware.meta.has_next = true; | |
else | |
$scope.hardware.meta.has_next = false; | |
if($scope.offset < $scope.limit) | |
$scope.hardware.meta.has_prev = false; | |
else | |
$scope.hardware.meta.has_prev = true; | |
}); | |
}; | |
function SoftwareController($scope, $http, $routeParams, $q) { | |
$scope.tabs = [ | |
{ title: "Market Versions", active: "active", count: 0 }, | |
{ title: "CPE Data", active: "", count: 0 }, | |
]; | |
$scope.setTabActive = function(tab) { | |
for(var i = 0; i < $scope.tabs.length; i++) { | |
$scope.tabs[i].active = ""; | |
} | |
tab.tab.active = "active"; | |
}; | |
$scope.selectNew = function(selection) { | |
$scope.selected = selection; | |
if(selection == "software") { | |
$scope.dom = $scope.product; | |
$scope.url = $scope.product_url; | |
} | |
if(selection == "cpe") { | |
$scope.dom = $scope.cpe_uri; | |
$scope.url = $scope.cpe_uri_url; | |
} | |
if(selection == "versions") { | |
$scope.dom = $scope.versions; | |
$scope.url = $scope.versions_url; | |
} | |
} | |
$scope.selected = "software"; | |
$scope.url = "/api/v1/sw_product/" + $routeParams.id + "/?format=json"; | |
$scope.collapsed = true; | |
$scope.collapseExplain = function(button) { | |
$scope.explore = true; | |
}; | |
$scope.product_url = "/api/v1/sw_product/" + $routeParams.id + "/?format=json"; | |
$http.get($scope.product_url, auth_headers) | |
.error(function(data, status, headers, config){ | |
$scope.error = true; | |
$scope.status = status; | |
}) | |
.success(function(data, status, headers, config){ | |
$scope.product = data; | |
document.title = data.manufacturer + " " + data.software + " " + " | Technopedia"; | |
$scope.selectNew("software"); | |
}).then(function() { | |
$scope.manufacturer_url = "/api/v1/manufacturer/" + $scope.product.manufacturer_id + "/"; | |
$http.get($scope.manufacturer_url, auth_headers) | |
.success(function(data, status, headers, config) { | |
$scope.manufacturer = data; | |
$scope.doneLoading = true; | |
}); | |
}); | |
$scope.versions_url = "/api/v1/sw_version_group/?format=json&sw_product_id=" + $routeParams.id; | |
var versions = $http.get($scope.versions_url, auth_headers) | |
.success(function(data, status, headers, config) { | |
$scope.tabs[0].count = data.meta.total_count; | |
$scope.versions = data.sw_version_group_list; | |
}); | |
$scope.cpe_uri_url = "/api/v1/cpe_uri/?cat_sw_product_id=" + $routeParams.id; | |
var cpe_uri = $http.get($scope.cpe_uri_url, auth_headers) | |
.success(function(data, status, headers, config) { | |
$scope.cpe_uri = data.cpe_uri_list; | |
$scope.tabs[1].count = data.meta.total_count; | |
}); | |
}; | |
function VersionController($scope, $http, $routeParams, $q, HelpAPI) { | |
$scope.helptext = function(msg) { HelpAPI.show_helptext(msg); } | |
$scope.tabs = [ | |
{ title: "Releases", active: "active", count: 0 }, | |
]; | |
$scope.selectNew = function(selection) { | |
$scope.selected = selection; | |
if(selection == "versiongroup") { | |
$scope.dom = $scope.version; | |
$scope.url = $scope.version_group_url; | |
} | |
if(selection == "editions") { | |
$scope.dom = $scope.editions; | |
$scope.url = $scope.editions_url; | |
} | |
if(selection == "releases") { | |
$scope.dom = $scope.releases; | |
$scope.url = $scope.releases_url; | |
} | |
} | |
$scope.selected = "versiongroup"; | |
$scope.url = "/api/v1/sw_version_group/" + $routeParams.id + "/?format=json"; | |
$scope.collapsed = true; | |
$scope.collapseExplain = function(button) { | |
$scope.explore = true; | |
}; | |
$scope.version_group_url = "/api/v1/sw_version_group/" + $routeParams.id + "/?format=json"; | |
$http.get($scope.version_group_url, auth_headers) | |
.success(function(data, status, headers, config){ | |
$scope.version = data; | |
document.title = data.sw_product + " " + data.version_group + " | Technopedia"; | |
$scope.selectNew($scope.selected); | |
}) | |
.error(function(data, status, headers, config) { | |
$scope.error = true; | |
$scope.status = status; | |
}) | |
$scope.editions_url = "/api/v1/sw_edition/?sw_product_id=1142809"; | |
$http.get($scope.editions_url, auth_headers) | |
.success(function(data, status, headers, config) { | |
var editions = {}; | |
$scope.editions = data.sw_edition_list; | |
}); | |
$scope.releases_url = "/api/v1/software_extended/?cat_sw_version_group_id=" + $routeParams.id; | |
var releases = $http.get($scope.releases_url, auth_headers) | |
.success(function(data, status, headers, config) { | |
$scope.tabs[0].count = data.meta.total_count; | |
$scope.releases = data.software_extended_list; | |
$scope.doneLoading = true; | |
$scope.manufacturer = data.software_extended_list[0]; | |
$scope.component = data.software_extended_list[0].component; | |
}); | |
}; | |
function ReleaseController($scope, $http, $routeParams, $q) { | |
$scope.tabs = [ | |
{ title: "Release", active: "active", count: 0 }, | |
]; | |
$scope.url = "/api/v1/sw_release/" + $routeParams.id + "/?format=json"; | |
$http.get($scope.url, auth_headers) | |
.success(function(data, status, headers, config){ | |
$scope.release = data; | |
document.title = data.manufacturer + " " + data.sw_product + " " + data.sw_version_group + " | Technopedia"; | |
$scope.selectNew("release"); | |
}) | |
.error(function(data, status, headers, config) { | |
$scope.error = true; | |
$scope.status = status; | |
}) | |
.then(function() { | |
$scope.product_url = "/api/v1/sw_product/" + $scope.release.sw_product_id + "/"; | |
$http.get($scope.product_url, auth_headers) | |
.success(function(data, status, headers, config) { | |
$scope.product = data; | |
}) | |
}) | |
$scope.win7_url = "/api/v1/sw_win7_compatibility/?sw_release_id=" + $routeParams.id; | |
$http.get($scope.win7_url, auth_headers) | |
.success(function(data, status, headers, config) { | |
$scope.win7 = data.sw_win7_compatibility_list[0]; | |
$scope.win7loaded = true; | |
}); | |
$scope.win8_url = "/api/v1/sw_win8_compatibility/?sw_release_id=" + $routeParams.id; | |
$http.get($scope.win8_url, auth_headers) | |
.success(function(data, status, headers, config) { | |
$scope.win8 = data.sw_win8_compatibility_list[0]; | |
$scope.win8loaded = true; | |
}); | |
$scope.winserver_url = "/api/v1/sw_winserver_compatibility/?sw_release_id=" + $routeParams.id; | |
$http.get($scope.winserver_url, auth_headers) | |
.success(function(data, status, headers, config) { | |
$scope.winserver = data.sw_winserver_compatibility_list[0]; | |
$scope.winserverloaded = true; | |
}); | |
$scope.selectNew = function(selection) { | |
$scope.selected = selection; | |
if(selection == "release") { | |
$scope.dom = $scope.release; | |
$scope.url = $scope.url; | |
} | |
if(selection == "win7") { | |
$scope.dom = $scope.win7; | |
$scope.url = $scope.win7_url; | |
} | |
if(selection == "win8") { | |
$scope.dom = $scope.win8; | |
$scope.url = $scope.win8_url; | |
} | |
if(selection == "winserver") { | |
$scope.dom = $scope.winserver | |
$scope.url = $scope.winserver_url; | |
} | |
} | |
$scope.selected = "release"; | |
$scope.collapsed = true; | |
$scope.collapseExplain = function(button) { | |
$scope.explore = true; | |
}; | |
}; | |
function HardwareController($scope, $http, $routeParams, $q, HelpAPI) { | |
$scope.helptext = function(msg) { HelpAPI.show_helptext(msg); } | |
$scope.tabs = [ | |
{ title: "Hardware", active: "active", count: 0 }, | |
{ title: "CPE Data", active: "", count: 0 }, | |
]; | |
$scope.setTabActive = function(tab) { | |
for(var i = 0; i < $scope.tabs.length; i++) { | |
$scope.tabs[i].active = ""; | |
} | |
tab.tab.active = "active"; | |
}; | |
// Handle queries help box | |
$scope.url = "/api/v1/hardware_extended/?cat_hw_product_id=" + $routeParams.id; | |
$scope.collapseExplain = function(button) { | |
$scope.explore = true; | |
}; | |
$scope.selected = "hardware"; | |
$scope.collapsed = true; | |
$scope.collapseExplain = function(button) { | |
$scope.explore = true; | |
}; | |
$scope.hardware_models_url = "/api/v1/hardware_extended/?cat_hw_product_id=" + $routeParams.id + "&limit=0"; | |
$http.get($scope.hardware_models_url, auth_headers) | |
.success(function(data, status, headers, config) { | |
$scope.tabs[0].count = data.meta.total_count; | |
$scope.models = data.hardware_extended_list; | |
$scope.doneLoading = true; | |
}) | |
.error(function(data, status, headers, config) { | |
$scope.error = true; | |
$scope.status = status; | |
}) | |
$scope.hardware_product_url = "/api/v1/hw_product/" + $routeParams.id + "/"; | |
$http.get($scope.hardware_product_url, auth_headers) | |
.success(function(data, status, headers, config) { | |
$scope.product = data; | |
document.title = data.manufacturer + " " + data.product + " " + data.model + " | Technopedia"; | |
$scope.selectNew("hardware"); | |
}) | |
.error(function(data, status, headers, config) { | |
$scope.error = true; | |
$scope.status = status; | |
}) | |
$scope.cpe_uri_url = "/api/v1/cpe_uri/?cat_sw_product_id=" + $routeParams.id; | |
var cpe_uri = $http.get($scope.cpe_uri_url, auth_headers) | |
.success(function(data, status, headers, config) { | |
$scope.cpe_uri = data.cpe_uri_list; | |
$scope.tabs[1].count = data.meta.total_count; | |
}); | |
$scope.selectNew = function(selection) { | |
$scope.selected = selection; | |
if(selection == "hardware") { | |
$scope.dom = $scope.product; | |
$scope.url = $scope.hardware_product_url; | |
} | |
if(selection == "cpe_uri") { | |
$scope.dom = $scope.versions; | |
$scope.url = $scope.versions_url; | |
} | |
if(selection == "models") { | |
$scope.dom = $scope.models; | |
$scope.url = $scope.hardware_models_url; | |
} | |
} | |
}; | |
function CPEController($scope, $http, $routeParams, $q) { | |
$scope.tabs = [ | |
{ title: "CVEs", active: "active", count: 0 }, | |
]; | |
$scope.collapseExplain = function(button) { | |
$scope.explore = true; | |
}; | |
$scope.url = "/api/v1/cpe_uri/" + $routeParams.id + "/"; | |
$http.get($scope.url, auth_headers) | |
.success(function(data, status, headers, config) { | |
$scope.cpe = data; | |
}) | |
.error(function(data, status, headers, config) { | |
$scope.error = true; | |
$scope.status = status; | |
}); | |
$scope.fetchCVEDetail = function(cveid) { | |
$scope.doneLoadingCVEData = false; | |
$cvs_detail_url = "/api/v1/cve/" + cveid + "/"; | |
$scope.cpeid = cveid; | |
$http.get($cvs_detail_url, auth_headers) | |
.success(function(data, status, headers, config) { | |
$scope.detail = data; | |
$scope.doneLoadingCVEData = true; | |
}); | |
$scope.detail = {}; | |
$scope.detail.summary = "Hello"; | |
cve_detail = {}; | |
cve_detail.summary = "Hello"; | |
}; | |
$scope.cpe_cve_url = "/api/v1/cpe_cve/?cat_cpe_uri_id=" + $routeParams.id; | |
$http.get($scope.cpe_cve_url, auth_headers) | |
.success(function(data, status, headers, config) { | |
$scope.cves = data.cpe_cve_list; | |
$scope.doneLoading = true; | |
$scope.selectNew("cves"); | |
}) | |
.error(function(data, status, headers, config) { | |
$scope.error = true; | |
$scope.status = status; | |
}); | |
$scope.selectNew = function(selection) { | |
$scope.selected = selection; | |
if(selection == "cves") { | |
$scope.dom = $scope.cves; | |
$scope.url = $scope.cpe_cve_url; | |
} | |
} | |
}; | |
function HardwareModelController($scope, $http, $routeParams, $q, HelpAPI) { | |
$scope.helptext = function(msg) { HelpAPI.show_helptext(msg); } | |
$scope.tabs = [ | |
{ title: "Lifecycle", active: "active"}, | |
{ title: "Profile", active: ""}, | |
{ title: "Power", active: ""}, | |
]; | |
$scope.setTabActive = function(tab) { | |
for(var i = 0; i < $scope.tabs.length; i++) { | |
$scope.tabs[i].active = ""; | |
} | |
tab.tab.active = "active"; | |
}; | |
$scope.hardware_model_url = "/api/v1/hardware_extended/?cat_hw_model_id=" + $routeParams.id; | |
$http.get($scope.hardware_model_url, auth_headers) | |
.success(function(data, status, headers, config) { | |
$scope.product = data.hardware_extended_list[0]; | |
$scope.model = data.hardware_extended_list[0]; | |
$scope.selectNew("hardwaremodel"); | |
if(typeof(data.hardware_extended_list[0]) == "undefined") { | |
$scope.error = true; | |
$scope.status = "404"; | |
} | |
}) | |
.error(function(data, status, headers, config) { | |
$scope.error = true; | |
$scope.status = status; | |
}) | |
$scope.hardware_model_lifecycle_url = "/api/v1/hw_lifecycle/?cat_hw_model_id=" + $routeParams.id; | |
$http.get($scope.hardware_model_lifecycle_url, auth_headers) | |
.success(function(data, status, headers, config) { | |
$scope.lifecycle = data.hw_lifecycle_list[0]; | |
}); | |
$scope.hardware_model_power_url = "/api/v1/hw_model_power/?cat_hw_model_id=" + $routeParams.id; | |
$http.get($scope.hardware_model_power_url, auth_headers) | |
.success(function(data, status, headers, config) { | |
$scope.power = data.hw_model_power_list[0]; | |
}); | |
$scope.hardware_model_profile_url = "/api/v1/hw_model_profile/?cat_hw_model_id=" + $routeParams.id; | |
$http.get($scope.hardware_model_profile_url, auth_headers) | |
.success(function(data, status, headers, config) { | |
$scope.profile = data.hw_model_profile_list[0]; | |
}); | |
// Handle queries help box | |
$scope.url = "/api/v1/hardware_extended/?cat_hw_product_id=" + $routeParams.id; | |
$scope.collapseExplain = function(button) { | |
$scope.explore = true; | |
}; | |
$scope.selected = "hardwaremodel"; | |
$scope.collapsed = true; | |
$scope.collapseExplain = function(button) { | |
$scope.explore = true; | |
}; | |
$scope.selectNew = function(selection) { | |
$scope.selected = selection; | |
if(selection == "hardwaremodel") { | |
$scope.dom = $scope.product; | |
$scope.url = $scope.hardware_model_url; | |
} | |
if(selection == "lifecycle") { | |
$scope.dom = $scope.lifecycle; | |
$scope.url = $scope.hardware_model_lifecycle_url; | |
} | |
if(selection == "power") { | |
$scope.dom = $scope.power; | |
$scope.url = $scope.hardware_model_power_url | |
} | |
if(selection == "profile") { | |
$scope.dom = $scope.profile; | |
$scope.url = $scope.hardware_model_profile_url; | |
} | |
} | |
$scope.selectNew('hardwaremodel'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment