Viewing File: /usr/local/cpanel/base/frontend/jupiter/site-monitor/directives/docrootDirective.js
/*
# site-monitor/directives/docrootDirective.js Copyright(c) 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.directive.docroot */
define(
[
"angular",
"lodash",
"cjt/core",
],
function(angular, _, CJT) {
"use strict";
var module = angular.module("cpanel.siteMonitor.docrootDirective", []);
module.value("PAGE", PAGE);
module.directive("docroot", function factory() {
/**
* Generates a docroot link automatically shortening the home dir to
* to an icon and additional title text
*
* @module docroot
* @restrict E
*
* @param {String} docroot full path of the docroot
* @param {String} homedir path of the homedir (will be first part of docroot)
*
* @example
* <docroot homedir="/home/baldr" docroot="/home/baldr/a/docroot" />
*
*/
var TEMPLATE_PATH = "directives/docrootDirective.phtml";
var RELATIVE_PATH = "site-monitor/" + TEMPLATE_PATH;
return {
templateUrl: CJT.config.debug ? CJT.buildFullPath(RELATIVE_PATH) : TEMPLATE_PATH,
restrict: "E",
scope: {
parentID: "@id",
rawDocroot: "@docroot",
homedir: "@"
},
controller: ["$scope", "PAGE", function($scope, PAGE) {
/**
* Converts a full document root into a shortened one and updates $scope.docroot
*
* @private
* @method updateDocroot
* @param {String} newFullDocroot full document root, including the homedir to parse
* @return {String} returns the parsed document root
*
*/
function updateDocroot(newFullDocroot) {
$scope.fullDocroot = encodeURIComponent(newFullDocroot);
var regexp = new RegExp("^" + _.escapeRegExp($scope.homedir) + "/?");
$scope.docroot = newFullDocroot.replace(regexp, "");
$scope.docroot = $scope.docroot === "/" ? "" : $scope.docroot;
return $scope.docroot;
}
$scope.fileManager = PAGE.fileManager;
$scope.$watch("rawDocroot", updateDocroot);
updateDocroot($scope.rawDocroot);
}]
};
});
}
);
Back to Directory
File Manager