dashboardCtrl.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. var dashboardCtrl = angular.module('dashboardCtrl', ['resultsFactory', 'menuService']);
  2. dashboardCtrl.controller('DashboardCtrl', ['$scope', '$rootScope', '$routeParams', '$location', 'Results', 'API', 'Menu', function($scope, $rootScope, $routeParams, $location, Results, API, Menu) {
  3. $scope.runId = $routeParams.runId;
  4. $scope.Menu = Menu.setCurrentPage('dashboard', $scope.runId);
  5. $scope.fromSocialShare = $location.search().share;
  6. function loadResults() {
  7. // Load result if needed
  8. if (!$rootScope.loadedResult || $rootScope.loadedResult.runId !== $routeParams.runId) {
  9. Results.get({runId: $routeParams.runId, exclude: 'toolsResults'}, function(result) {
  10. $rootScope.loadedResult = result;
  11. $scope.result = result;
  12. init();
  13. }, function(err) {
  14. $scope.error = true;
  15. });
  16. } else {
  17. $scope.result = $rootScope.loadedResult;
  18. init();
  19. }
  20. }
  21. function init() {
  22. // By default, Angular sorts object's attributes alphabetically. Countering this problem by retrieving the keys order here.
  23. $scope.categoriesOrder = Object.keys($scope.result.scoreProfiles.generic.categories);
  24. $scope.tweetText = 'I\'ve discovered this cool open-source tool that audits the front-end quality of a web page: ';
  25. }
  26. $scope.showRulePage = function(ruleName) {
  27. $location.path('/result/' + $scope.runId + '/rule/' + ruleName);
  28. };
  29. $scope.testAgain = function() {
  30. API.relaunchTest($scope.result);
  31. };
  32. // When comming from a social shared link, the user needs to click on "See full report" button to display the full dashboard.
  33. $scope.seeFullReport = function() {
  34. $scope.fromSocialShare = false;
  35. $location.search({});
  36. };
  37. $scope.shareOnTwitter = function(message) {
  38. openSocialPopup('https://twitter.com/intent/tweet?text=' + encodeURIComponent(message + 'http://yellowlab.tools'));
  39. };
  40. $scope.shareOnLinkedin = function(message) {
  41. openSocialPopup('https://www.linkedin.com/shareArticle?mini=true&url=http://yellowlab.tools&title=' + encodeURIComponent(message) + '&summary=' + encodeURIComponent('YellowLabTools is a free online tool that analyzes performance and front-end quality of a webpage.'));
  42. };
  43. function openSocialPopup(url) {
  44. var winHeight = 400;
  45. var winWidth = 600;
  46. var winTop = (screen.height / 2) - (winHeight / 2);
  47. var winLeft = (screen.width / 2) - (winWidth / 2);
  48. window.open(url, 'sharer', 'top=' + winTop + ',left=' + winLeft + ',toolbar=0,status=0,width=' + winWidth + ',height=' + winHeight);
  49. }
  50. loadResults();
  51. }]);