export function mainController()

in ui-modules/app-inspector/app/views/main/main.controller.js [36:102]


export function mainController($scope, $q, brWebNotifications, brBrandInfo) {
    $scope.$emit(HIDE_INTERSTITIAL_SPINNER_EVENT);

    let ctrl = this;

    ctrl.composerUrl = brBrandInfo.blueprintComposerBaseUrl;

    // View mode feature components, required in entity-tree and entity-node directives.
    ctrl.viewMode = VIEW_PARENT_CHILD;
    ctrl.viewModes = new Set([VIEW_PARENT_CHILD]);
    ctrl.viewModesArray = () => Array.from(ctrl.viewModes); // Array from set for ng-repeat component
    ctrl.isDefaultViewMode = () => ctrl.viewMode === VIEW_PARENT_CHILD; // 'parent/child' is a default view mode
    $scope.$watch('ctrl.viewModes', () => {
        if (!ctrl.viewModes.has(ctrl.viewMode)) {
            ctrl.viewMode = VIEW_PARENT_CHILD; // Default to 'parent/child' view if current is not available anymore.
        }
    });

    ctrl.sortReverse = localStorage && localStorage.getItem(savedSortReverse) !== null ?
        JSON.parse(localStorage.getItem(savedSortReverse)) :
        true;
    brWebNotifications.supported.then(() => {
        ctrl.isNotificationsSupported = true;
    }).catch(() => {
        ctrl.isNotificationsSupported = false;
    });

    brWebNotifications.isEnabled().then(() => {
        ctrl.isNotificationsEnabled = true;
    }).catch(() => {
        ctrl.isNotificationsEnabled = false;
    });

    brWebNotifications.getPermission().then(permission => {
        ctrl.isNotificationsBlocked = permission === 'denied';
    });

    ctrl.toggleSortOrder = () => {
        ctrl.sortReverse = !ctrl.sortReverse;
        if (localStorage) {
            try {
                localStorage.setItem(savedSortReverse, JSON.stringify(ctrl.sortReverse));
            } catch (ex) {
                $log.error('Cannot save app sort preferences: ' + ex.message);
            }
        }
    }

    ctrl.toggleNotifications = () => {
        brWebNotifications.isEnabled().then(() => {
            return brWebNotifications.setEnable(false);
        }).then(enable => {
            ctrl.isNotificationsEnabled = enable;
        }).catch(() => {
            brWebNotifications.requestPermission().then(permission => {
                ctrl.isNotificationsBlocked = permission === 'denied';

                if (ctrl.isNotificationsBlocked) {
                    return $q.reject();
                }
                return brWebNotifications.setEnable(permission === 'granted');
            }).then(enable => {
                ctrl.isNotificationsEnabled = enable;
            });
        });
    };
}