<commit_before>import {ServerService} from '../rest/server';
import {DashboardSummaryData} from '../rest/server';
import {UsageData} from '../rest/server';
import {numeral} from '../base/libs';

export class DashboardController {
    private clusters: any;
    private hosts: any;
    private pools: any;
    private pgs: any;
    private osds: any;
    private objects: any;
    private monitors: any;
    private capacity: any;
    private utilization: any;
    private utilizationByProfile: any;

    static $inject: Array<string> = [
        '$scope',
        '$location',
        '$log',
        'ServerService'
    ];

    constructor(private $scope: ng.IScope,
        private $location: ng.ILocationService,
        private $log: ng.ILogService,
        private serverService: ServerService) {

         this.utilization = { data: {}, config: {} };
         this.utilizationByProfile = {};
         this.capacity = {};
         this.clusters = { total: 0, error: 0 };
         this.hosts = { total: 0, error: 0, unaccepted: 0 };
         this.pgs = { total: 0, error: 0 };
         this.osds = { total: 0, error: 0 };
         this.objects = { total: 0, error: 0 };
         this.pools = { total: 0, down: 0 };
         this.monitors = { total: 0, error: 0 };
         this.serverService.getDashboardSummary().then((summary) => this.loadDashboardData(summary));
    }

    /**
     *This is the callback function called after getting summary data.
    */
    public loadDashboardData(summary: DashboardSummaryData) {
        if (summary.clusterscount.total === 0) {
            this.$location.path('/first');
        }
        else {
            this.formatlUtilizationData(summary.usage);
            this.formatlUtilizationByProfileData(summary.storageprofileusage);
            this.objects.total = summary.objectcnt;
            this.osds.total = summary.slucount.total;
            this.hosts = summary.nodescount;
            this.clusters = summary.clusterscount;
            this.pools = summary.storagecount;<commit_msg>fix redirection in dashboard in case of no clusters<commit_after>import {ServerService} from '../rest/server';
import {ClusterService} from '../rest/clusters';
import {DashboardSummaryData} from '../rest/server';
import {UsageData} from '../rest/server';
import {numeral} from '../base/libs';

export class DashboardController {
    private clusters: any;
    private hosts: any;
    private pools: any;
    private pgs: any;
    private osds: any;
    private objects: any;
    private monitors: any;
    private capacity: any;
    private utilization: any;
    private utilizationByProfile: any;

    static $inject: Array<string> = [
        '$scope',
        '$location',
        '$log',
        'ServerService',
        'ClusterService'
    ];

    constructor(private $scope: ng.IScope,
        private $location: ng.ILocationService,
        private $log: ng.ILogService,
        private serverService: ServerService,
        private clusterService: ClusterService) {

         this.utilization = { data: {}, config: {} };
         this.utilizationByProfile = {};
         this.capacity = {};
         this.clusters = { total: 0, error: 0 };
         this.hosts = { total: 0, error: 0, unaccepted: 0 };
         this.pgs = { total: 0, error: 0 };
         this.osds = { total: 0, error: 0 };
         this.objects = { total: 0, error: 0 };
         this.pools = { total: 0, down: 0 };
         this.monitors = { total: 0, error: 0 };
         this.serverService.getDashboardSummary().then((summary) => this.loadDashboardData(summary));
         // Summary data is returned as empty if there are no clusters in the system.
         // So here we are fetching the cluster list and redirect
         // if no clusters are present
         this.clusterService.getList().then((clusters) => {
             if (clusters.length === 0) {
                 this.$location.path('/first');
             }
         });
    }

    /**
     *This is the callback function called after getting summary data.
    */
    public loadDashboardData(summary: DashboardSummaryData) {
        if (summary.clusterscount.total === 0) {
            this.$location.path('/first');
        }
        else {
            this.formatlUtilizationData(summary.usage);
            this.formatlUtilizationByProfileData(summary.storageprofileusage);
            this.objects.total = summary.objectcnt;
            this.osds.total = summary.slucount.total;
            this.hosts = summary.nodescount;
            this.clusters = summary.clusterscount;
            this.pools = summary.storagecount;
{'fraction_non_alphanumeric': 0.12293657688966117, 'fraction_numerical': 0.007167680278019114, 'mean_word_length': 2.3273121387283235, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3426984', 'n_tokens_mistral': 1310, 'n_tokens_neox': 1261, 'n_words': 333}