Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///<reference path="./../typings/index.d.ts" />
  2.  
  3. import menu from './menu.js';
  4. import {IUserService} from "./modules/services/user.service";
  5. declare var ic3: any;
  6. declare var viz: any;
  7. declare var ic3ready: any;
  8.  
  9.  
  10. interface IReportLink {
  11.     id: string;
  12.     name: string;
  13.     color: string;
  14.     type: string;
  15.     url: string;
  16. }
  17.  
  18. class AppController {
  19.     public menu: any;
  20.     public token: string;
  21.     static $inject: Array<string> = ['userservice'];
  22.  
  23.     constructor(private UserService: IUserService) {
  24.         this.menu = menu;
  25.         this.UserService.getUsersToken().then((response: string) => {
  26.             this.token = response;
  27.             this.getAllReportNames();
  28.         });
  29.     }
  30.  
  31.     private populateMenu(categorizedReports: any): any {
  32.         let reportSections: Array<any> = this.menu.sections[1].pages;
  33.         //benchmarking
  34.         categorizedReports.benchmarking.forEach((reportName: string) => {
  35.             let reportLink: IReportLink = {
  36.                 "id": reportName.replace(/ /g, ""),
  37.                 "name": reportName,
  38.                 "type": "link",
  39.                 "url": "/" + reportName,
  40.                 "color": "90A4AE"
  41.             };
  42.             reportSections[0].pages.push(reportLink);
  43.         });
  44.         //optimization
  45.         categorizedReports.optimization.forEach((reportName: string) => {
  46.             let reportLink: IReportLink = {
  47.                 "id": reportName.replace(/ /g, ""),
  48.                 "name": reportName,
  49.                 "type": "link",
  50.                 "url": "/" + reportName,
  51.                 "color": "90A4AE"
  52.             };
  53.             reportSections[1].pages.push(reportLink);
  54.         });
  55.         //custom
  56.         categorizedReports.custom.forEach((reportName: string) => {
  57.             let reportLink: IReportLink = {
  58.                 "id": reportName.replace(/ /g, ""),
  59.                 "name": reportName,
  60.                 "type": "link",
  61.                 "url": "/" + reportName,
  62.                 "color": "90A4AE"
  63.  
  64.             };
  65.             reportSections[2].pages.push(reportLink);
  66.         });
  67.     }
  68.  
  69.     private getAllReportNames(): any {
  70.         this.getIcCubeReports();
  71.     }
  72.  
  73.     private ic3optionsCallback(): any {
  74.         let ic3reporting = new ic3.Reporting({
  75.             noticesLevel: ic3.NoticeLevel.ERROR,
  76.             dsSettings: {
  77.                 userName: this.token,
  78.                 userPassword: "user6", //currently hardcoded
  79.                 url: "http://localhost:80/icCube/gvi"
  80.             }
  81.         });
  82.  
  83.         ic3reporting.getAllReportNames({
  84.             onSuccess: (gviTable: any) => {
  85.                 this.ic3SetupReportList(gviTable);
  86.             }
  87.         });
  88.     }
  89.  
  90.     private ic3SetupReportList(gviTable: any) {
  91.         let categorizedReports: any = {"benchmarking": [], "optimization": [], "custom": []};
  92.         let _this = this;
  93.         new viz.MdxEntityData(gviTable).forEach(function (report: any) {
  94.             var reportName = report.name;
  95.             categorizedReports[_this.ic3FilterReport(reportName)].push(_this.getReportName(reportName));
  96.         });
  97.         this.populateMenu(categorizedReports);
  98.     }
  99.  
  100.     private getReportName(fullReportName: string) {
  101.         return fullReportName.substring(fullReportName.lastIndexOf('/') + 1, fullReportName.indexOf('.icc-report'));
  102.     }
  103.  
  104.     private ic3FilterReport(reportName: string): string {
  105.         if (reportName.includes("benchmarking")) return 'benchmarking';
  106.         else if (reportName.includes("optimization")) return 'optimization';
  107.         return 'custom';
  108.     }
  109.  
  110.     private getIcCubeReports(): any {
  111.         const ic3root: string = "http://localhost:80/icCube/doc/ic3-report/app/";
  112.         const ic3rootLocal: string = "http://localhost:80/icCube/doc/ic3-report/app-local/";
  113.         var thisCopy = this;
  114.         let options: any = {
  115.             root: ic3root,
  116.             rootLocal: ic3rootLocal,
  117.             // This function starts work just after initialization of reporting framework
  118.             callback: this.ic3optionsCallback.bind(thisCopy)
  119.         };
  120.         ic3ready(options);
  121.     }
  122. }
  123.  
  124.  
  125. export default['userservice', AppController];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement