Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///<reference path="./../typings/index.d.ts" />
- import menu from './menu.js';
- import {IUserService} from "./modules/services/user.service";
- declare var ic3: any;
- declare var viz: any;
- declare var ic3ready: any;
- interface IReportLink {
- id: string;
- name: string;
- color: string;
- type: string;
- url: string;
- }
- class AppController {
- public menu: any;
- public token: string;
- static $inject: Array<string> = ['userservice'];
- constructor(private UserService: IUserService) {
- this.menu = menu;
- this.UserService.getUsersToken().then((response: string) => {
- this.token = response;
- this.getAllReportNames();
- });
- }
- private populateMenu(categorizedReports: any): any {
- let reportSections: Array<any> = this.menu.sections[1].pages;
- //benchmarking
- categorizedReports.benchmarking.forEach((reportName: string) => {
- let reportLink: IReportLink = {
- "id": reportName.replace(/ /g, ""),
- "name": reportName,
- "type": "link",
- "url": "/" + reportName,
- "color": "90A4AE"
- };
- reportSections[0].pages.push(reportLink);
- });
- //optimization
- categorizedReports.optimization.forEach((reportName: string) => {
- let reportLink: IReportLink = {
- "id": reportName.replace(/ /g, ""),
- "name": reportName,
- "type": "link",
- "url": "/" + reportName,
- "color": "90A4AE"
- };
- reportSections[1].pages.push(reportLink);
- });
- //custom
- categorizedReports.custom.forEach((reportName: string) => {
- let reportLink: IReportLink = {
- "id": reportName.replace(/ /g, ""),
- "name": reportName,
- "type": "link",
- "url": "/" + reportName,
- "color": "90A4AE"
- };
- reportSections[2].pages.push(reportLink);
- });
- }
- private getAllReportNames(): any {
- this.getIcCubeReports();
- }
- private ic3optionsCallback(): any {
- let ic3reporting = new ic3.Reporting({
- noticesLevel: ic3.NoticeLevel.ERROR,
- dsSettings: {
- userName: this.token,
- userPassword: "user6", //currently hardcoded
- url: "http://localhost:80/icCube/gvi"
- }
- });
- ic3reporting.getAllReportNames({
- onSuccess: (gviTable: any) => {
- this.ic3SetupReportList(gviTable);
- }
- });
- }
- private ic3SetupReportList(gviTable: any) {
- let categorizedReports: any = {"benchmarking": [], "optimization": [], "custom": []};
- let _this = this;
- new viz.MdxEntityData(gviTable).forEach(function (report: any) {
- var reportName = report.name;
- categorizedReports[_this.ic3FilterReport(reportName)].push(_this.getReportName(reportName));
- });
- this.populateMenu(categorizedReports);
- }
- private getReportName(fullReportName: string) {
- return fullReportName.substring(fullReportName.lastIndexOf('/') + 1, fullReportName.indexOf('.icc-report'));
- }
- private ic3FilterReport(reportName: string): string {
- if (reportName.includes("benchmarking")) return 'benchmarking';
- else if (reportName.includes("optimization")) return 'optimization';
- return 'custom';
- }
- private getIcCubeReports(): any {
- const ic3root: string = "http://localhost:80/icCube/doc/ic3-report/app/";
- const ic3rootLocal: string = "http://localhost:80/icCube/doc/ic3-report/app-local/";
- var thisCopy = this;
- let options: any = {
- root: ic3root,
- rootLocal: ic3rootLocal,
- // This function starts work just after initialization of reporting framework
- callback: this.ic3optionsCallback.bind(thisCopy)
- };
- ic3ready(options);
- }
- }
- export default['userservice', AppController];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement