SHARE
TWEET

Untitled

a guest Oct 18th, 2016 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // The code below is written in Typescript but I am still using Angular 1.x, not Angular 2.x
  2. // I don't like using $rootscope.broadcast.  It feels to heavy handed.  Is there a better way to pass data back from the service to the controller.  Right now I have to return the "totalCount" variable.  Could I be using Promises better to return control to the Controller?  
  3.  
  4.  
  5. // dynamoGrapherController.ts
  6. namespace app {
  7.   interface IDynamoGraph {
  8.     dbAttributesByTable: any;
  9.     limitCounts: number[];
  10.     amChartOptions: any;
  11.     showChart: boolean;
  12.     selectedAttribute: string;
  13.     startDateModel: Date;
  14.     endDateModel: Date;
  15.     resultCount: number;
  16.     totalCount:  number;
  17.  
  18.     submitGraphRequest(): void;
  19.   }
  20.  
  21.   class DynamoGrapher implements IDynamoGraph {
  22.     dbAttributesByTable: any;
  23.     limitCounts: number[];
  24.     amChartOptions: any;
  25.     showChart: boolean;
  26.     selectedAttribute: string;
  27.     startDateModel: Date;
  28.     endDateModel: Date;
  29.     resultCount: number;
  30.     totalCount: number;
  31.  
  32.     static $inject = ["dynamoChartService", "formOptionsService"];
  33.     constructor(private dynamoChartService, formOptionsService) {
  34.       this.limitCounts = formOptionsService.limitCounts;
  35.       this.dbAttributesByTable = formOptionsService.dbAttributesByTable;
  36.       this.amChartOptions = this.dynamoChartService.getChartOptions();
  37.       this.showChart = this.dynamoChartService.showChart;
  38.       this.totalCount = this.dynamoChartService.totalCount;
  39.     }
  40.  
  41.     submitGraphRequest() {
  42.       this.dynamoChartService.submitDynamoRequest({
  43.        searchAttribute: this.selectedAttribute,
  44.         startDateModel: this.startDateModel,
  45.         endDateModel: this.endDateModel,
  46.         limit: this.resultCount
  47.       });
  48.     }
  49.   }
  50.   angular.module("dynamoReports")
  51.       .controller("dynamoGrapherController", DynamoGrapher);
  52. }
  53.  
  54. /// from dynamoChartService.ts
  55.         submitDynamoRequest(parameters) {
  56.             let self = this,
  57.                 attribute = parameters.searchAttribute;
  58.             self.$http({
  59.                 method: "POST",
  60.                 url: "/logreports-dev2/count",
  61.                 data: parameters,
  62.                 headers: {"Content-Type": "application/x-www-form-urlencoded"}
  63.             }).then(function (response) {
  64.                 self.setCategory(attribute);
  65.                 self.setData(self.transformHashToChart(response.data, attribute));
  66. //                self.$rootScope.$broadcast('totalCount', self.totalCount);
  67.                 self.$rootScope.$broadcast(CHART_UPDATE_DATA_EVENT, self.getChartOptions(), CHART_DOM_ID);
  68.                 self.$rootScope.$broadcast(CHART_RENDER_EVENT, self.getChartOptions(), CHART_DOM_ID);
  69.                 self.showChart = true;
  70.             });
  71.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top