constructor()

in modules/frontend/app/components/list-of-registered-users/controller.js [40:186]


    constructor($scope, $state, $filter, User, uiGridGroupingConstants, uiGridPinningConstants, AdminData, NotebookData, Confirm, ActivitiesUserDialog) {
        this.$state = $state;
        this.AdminData = AdminData;
        this.ActivitiesDialogFactory = ActivitiesUserDialog;
        this.Confirm = Confirm;
        this.User = User;
        this.NotebookData = NotebookData;

        const dtFilter = $filter('date');

        this.groupBy = 'user';

        this.selected = [];

        this.params = {
            startDate: new Date(),
            endDate: new Date()
        };

        this.uiGridPinningConstants = uiGridPinningConstants;
        this.uiGridGroupingConstants = uiGridGroupingConstants;

        User.read().then((user) => this.user = user);

        const companiesExcludeFilter = (renderableRows) => {
            if (_.isNil(this.params.companiesExclude))
                return renderableRows;

            _.forEach(renderableRows, (row) => {
                row.visible = _.isEmpty(this.params.companiesExclude) ||
                    row.entity.company.toLowerCase().indexOf(this.params.companiesExclude.toLowerCase()) === -1;
            });

            return renderableRows;
        };

        this.actionOptions = [
            {
                action: 'Become this user',
                click: () => this.becomeUser(),
                available: true
            },
            {
                action: 'Revoke admin',
                click: () => this.toggleAdmin(),
                available: true
            },
            {
                action: 'Grant admin',
                click: () => this.toggleAdmin(),
                available: false
            },
            {
                action: 'Add user',
                sref: '.createUser',
                available: true
            },
            {
                action: 'Remove user',
                click: () => this.removeUser(),
                available: true
            },
            {
                action: 'Activity detail',
                click: () => this.showActivities(),
                available: true
            }
        ];

        this._userGridOptions = {
            columnDefs,
            categories
        };

        this.gridOptions = {
            data: [],

            columnDefs,
            categories,

            treeRowHeaderAlwaysVisible: true,
            headerTemplate,
            columnVirtualizationThreshold: 30,
            rowTemplate,
            rowHeight: 46,
            selectWithCheckboxOnly: true,
            suppressRemoveSort: false,
            enableFiltering: true,
            enableSelectAll: true,
            enableRowSelection: true,
            enableFullRowSelection: true,
            enableColumnMenus: false,
            multiSelect: false,
            modifierKeysToMultiSelect: true,
            noUnselect: false,
            fastWatch: true,
            exporterSuppressColumns: ['actions'],
            exporterCsvColumnSeparator: ';',
            rowIdentity: (row) => row._id,
            getRowIdentity: (row) => row._id,
            onRegisterApi: (api) => {
                this.gridApi = api;

                api.selection.on.rowSelectionChanged($scope, this._updateSelected.bind(this));
                api.selection.on.rowSelectionChangedBatch($scope, this._updateSelected.bind(this));

                api.core.on.filterChanged($scope, this._filteredRows.bind(this));
                api.core.on.rowsVisibleChanged($scope, this._filteredRows.bind(this));

                api.grid.registerRowsProcessor(companiesExcludeFilter, 50);

                $scope.$watch(() => this.gridApi.grid.getVisibleRows().length, (rows) => this.adjustHeight(rows));
                $scope.$watch(() => this.params.companiesExclude, () => this.gridApi.grid.refreshRows());
            }
        };

        /**
         * @param {{startDate: number, endDate: number}} params
         */
        const reloadUsers = (params) => {
            AdminData.loadUsers(params)
                .then((data) => {
                    this.gridOptions.data = data;

                    this.companies = _.values(_.groupBy(data, 'company'));
                    this.countries = _.values(_.groupBy(data, 'countryCode'));

                    this._refreshRows();
                });
        };

        const filterDates = _.debounce(() => {
            const sdt = this.params.startDate;
            const edt = this.params.endDate;

            this.exporterCsvFilename = `web_console_users_${dtFilter(sdt, 'yyyy_MM')}.csv`;

            const startDate = Date.UTC(sdt.getFullYear(), sdt.getMonth(), 1);
            const endDate = Date.UTC(edt.getFullYear(), edt.getMonth() + 1, 1);

            reloadUsers({ startDate, endDate });
        }, 250);

        $scope.$on('userCreated', filterDates);
        $scope.$watch(() => this.params.startDate, filterDates);
        $scope.$watch(() => this.params.endDate, filterDates);
    }