Viewing File: /usr/local/cpanel/base/frontend/jupiter/site-monitor/directives/siteItemListDirective.js

/*
# site-monitor/directives/siteItemListDirective.js
#                                                  Copyright 2021 cPanel, L.L.C.
#                                                           All rights reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited
*/

/* global define: false */

/** @namespace cpanel.siteMonitor.directives.siteItemList */

define(
    [
        "lodash",
        "angular",
        "cjt/core",
        "cjt/util/locale",
        "app/models/domain-type.enum",
        "app/directives/docrootDirective",
        "app/directives/monitorsDirective"
    ],
    function(_, angular, CJT, LOCALE, DomainType) {

        "use strict";

        var module = angular.module("cpanel.siteMonitor.siteItemListDirective", [
            "cpanel.siteMonitor.docrootDirective",
            "cpanel.siteMonitor.monitorsDirective",
        ]);

        module.directive("siteItemList", [ function siteItemList() {

            /**
             * Site Item is a directive that pairs with the item lister to display domains,
             * docroots, monitors and the actions you can take with them. It must be nested
             * within an item lister.
             *
             * @module site-item
             * @restrict EA
             *
             * @example
             * <item-lister>
             *     <site-item-list></site-item-list>
             * </item-lister>
             *
             */

            var TEMPLATE_PATH = "directives/siteItemListDirective.phtml";
            var RELATIVE_PATH = "site-monitor/" + TEMPLATE_PATH;

            return {
                templateUrl: CJT.config.debug ? CJT.buildFullPath(RELATIVE_PATH) : TEMPLATE_PATH,
                restrict: "EA",
                replace: true,
                require: "^itemLister",
                scope: true,
                link: function($scope, $element, $attrs, $parentCtrl) {
                    $scope.LOCALE = LOCALE;
                    $scope.showConfigColumn = $parentCtrl.showConfigColumn;
                    $scope.headers = $parentCtrl.getHeaders();

                    /**
                     * Update the view with sites.
                     *
                     * @param {Site[]} sites
                     */
                    $scope.updateView = function updateView(sites) {
                        $scope.sites = sites;
                    };

                    $parentCtrl.registerViewCallback($scope.updateView.bind($scope));

                    $scope.$on("$destroy", function() {
                        $parentCtrl.deregisterViewCallback($scope.updateView);
                    });
                },
                controller: [
                    "$scope", "ITEM_LISTER_CONSTANTS", "PAGE", "alertService", "$timeout",
                    function($scope, ITEM_LISTER_CONSTANTS, PAGE, alertService, $timeout) {

                    $scope.isRTL = PAGE.isRTL;
                    $scope.DomainType = DomainType;
                    $scope.hasWebServerRole = PAGE.hasWebServerRole;

                    /**
                     * Get the sites for the view.
                     *
                     * @method getSites
                     * @returns {Site[]} list of sites to render.
                     */
                    $scope.getSites = function getSites() {
                        return $scope.sites;
                    };

                    /**
                     * dispatches a ITEM_CLICKED_EVENT event
                     *
                     * @method itemClicked
                     *
                     * @param  {String} type type of action taken.
                     * @param  {String} site the site on which the action occurred.
                     * @return {Boolean} returns the result of the $scope.$emit function
                     *
                     */
                    $scope.itemClicked = function itemClicked(type, site) {
                        $scope.$emit(ITEM_LISTER_CONSTANTS.ITEM_CLICKED_EVENT, { actionType: type, item: site, interactionID: site.domain });
                    };

                    /**
                     * dispatches a ITEM_SELECT_EVENT for the site.
                     *
                     * @param {String} site
                     */
                    $scope.itemSelected = function itemSelected(site) {
                        $scope.$emit(ITEM_LISTER_CONSTANTS.ITEM_SELECT_EVENT, site);
                    };

                    // render again when a monitor change is detected
                    $scope.$on(ITEM_LISTER_CONSTANTS.MONITOR_CHANGE_EVENT, function (event, sites) {
                        $scope.updateView(sites);
                    });
                }]
            };
        } ]);
    }
);
Back to Directory File Manager