From 46c4d07af09dd120144e81513d52d900ef8c4b2f Mon Sep 17 00:00:00 2001 From: Alan Davis Date: Sat, 31 Jan 2015 11:53:46 +0000 Subject: [PATCH] Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud) 92620: ACE-3703 - Refactor Repository Admin Console framework to allow the basic framework to work in Community version - Framework base moved to web-client project. - Refactored Enterprise admin console to base from the web-client one. - Empty Community admin console start page git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@94892 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repository/admin/admin-common.lib.js | 169 ++++ .../admin/admin-communitysummary.get.desc.xml | 13 + .../admin/admin-communitysummary.get.html.ftl | 24 + .../admin/admin-communitysummary.get.js | 14 + .../admin-communitysummary.get.properties | 1 + .../repository/admin/admin-root.get.desc.xml | 10 + .../repository/admin/admin-root.get.js | 16 + .../repository/admin/admin-template.ftl | 823 ++++++++++++++++++ .../web-scripts-application-context.xml | 23 +- .../alfresco/web/scripts/WebScriptUtils.java | 125 +++ 10 files changed, 1214 insertions(+), 4 deletions(-) create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/admin/admin-common.lib.js create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/admin/admin-communitysummary.get.desc.xml create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/admin/admin-communitysummary.get.html.ftl create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/admin/admin-communitysummary.get.js create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/admin/admin-communitysummary.get.properties create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/admin/admin-root.get.desc.xml create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/admin/admin-root.get.js create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/admin/admin-template.ftl create mode 100644 source/java/org/alfresco/web/scripts/WebScriptUtils.java diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/admin/admin-common.lib.js b/config/alfresco/templates/webscripts/org/alfresco/repository/admin/admin-common.lib.js new file mode 100644 index 0000000000..c64761a91b --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/admin/admin-common.lib.js @@ -0,0 +1,169 @@ +/* + * Copyright 2005-2015 Alfresco Software, Ltd. All rights reserved. + * + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + */ + +/** + * Repository Admin Console + * + * Common JavaScript library functions. + */ + +/* Admin JavaScript namespace - public functions exposed through this namespace. */ +var Admin = Admin || {}; + +(function() { + + /** + * Return an indexed array of available Admin console tools. + * + * [ + * { + * id: + +<#if !dialog> + + <#-- + Template for a full page view + --> +
+ +
+ ${msg("admin-console.header")}<#if metadata??>${HOSTNAME}${HOSTADDR} +
${msg("admin-console.help")}
+
+ + + +
+ +
+ + + +<#else> + + <#-- + Template for a dialog page view + --> +
+ + + +
+ + + + + +<#macro dialogbuttons save=false close=true> +
+<#-- Template-specific markup --> +<#nested> + <#if save> + <#if close> +
+ + +<#-- + Template section macros. +--> +<#macro section label> +

${label?html}

+
+<#nested> +
+ +<#macro tsection label closed=true> +
+

${label?html} <#if closed>►<#else>▼

+
+
+<#nested> +
+
+
+ + +<#-- + Template field macros and value conversion. +--> +<#function cvalue type value=""> + <#switch type> + <#case "java.util.Date"> + <#if value?has_content> + <#return value?datetime> + <#else> + <#return value> + + <#break> + <#case "boolean"> + <#return value?string> + <#break> + <#case "java.lang.Long"> + <#return value> + <#break> + <#default> + <#return value> + + + +<#macro control attribute> + <#if attribute.readonly> + <@attrfield attribute=attribute /> + <#else> + <#switch attribute.type> + <#case "java.util.Date"> + <@attrtext attribute=attribute /> + <#break> + <#case "boolean"> + <@attrcheckbox attribute=attribute /> + <#break> + <#case "java.lang.Long"> + <@attrtext attribute=attribute /> + <#break> + <#default> + <@attrtext attribute=attribute /> + + + + +<#-- Hidden field --> +<#macro hidden name value="" id=""> + id="${id?html}" name="${name?html}" value="${value?html}" /> + +<#macro attrhidden attribute name=attribute.qname id=""> + <@hidden name=name value=cvalue(attribute.type, attribute.value) id=id /> + + +<#-- Label and simple read-only field --> +<#macro field label="" description="" value="" style=""> +
style="${style?html}"> + <#if label?has_content>${label?html}: + <#if value?has_content>${value?html} + <#if description?has_content>${description?html} + <#nested> +
+ +<#macro attrfield attribute label=attribute.name description="" style=""> + <@field label=label description=description value=cvalue(attribute.type, attribute.value) style=style> + <#nested> + + + +<#-- Label and text input field --> +<#macro text name label="" description="" value="" maxlength=255 id="" style="" controlStyle="" valueStyle="" placeholder="" escape=true> +
style="${style?html}"> + <#if label?has_content>${label?html}: + style="${valueStyle?html}">id="${id?html}" name="${name?html}" value="${value?html}" maxlength="${maxlength?c}" tabindex="0" <#if placeholder?has_content>placeholder="${placeholder?html}" <#if controlStyle?has_content>style="${controlStyle?html}"/> + <#if description?has_content><#if escape>${description?html}<#else>${description} +
+ +<#macro attrtext attribute label=attribute.name description="" maxlength=255 id="" style="" controlStyle="" valueStyle="" placeholder="" escape=true> + <@text name=attribute.qname label=label description=description value=cvalue(attribute.type, attribute.value) maxlength=maxlength id=id style=style controlStyle=controlStyle valueStyle=valueStyle placeholder=placeholder escape=escape /> + + +<#-- Label and password input field --> +<#macro password id name label="" description="" value="" maxlength=255 style="" controlStyle="" visibilitytoggle=false> +
style="${style?html}"> + <#if label?has_content>${label?html}: + style="${controlStyle?html}"/> + <#if visibilitytoggle><@button label=msg("admin-console.password.show")?html onclick="Admin.togglePassword('${id?html}', this);" /> + <#if description?has_content>${description?html} +
+ +<#macro attrpassword attribute label=attribute.name id=attribute.qname description="" maxlength=255 style="" controlStyle="" visibilitytoggle=false populatevalue=false> + <#if populatevalue> + <@password name=attribute.qname label=label id=id description=description value=cvalue(attribute.type, attribute.value) maxlength=maxlength style=style controlStyle=controlStyle visibilitytoggle=visibilitytoggle /> + <#else> + <@password name=attribute.qname label=label id=id description=description maxlength=maxlength style=style controlStyle=controlStyle visibilitytoggle=visibilitytoggle /> + + + +<#-- Label and text area field --> +<#macro textarea name label="" description="" value="" maxlength=255 id="" style="" controlStyle=""> +
style="${style?html}"> + <#if label?has_content>${label?html}: + + <#if description?has_content>${description?html} +
+ +<#macro attrtextarea attribute label=attribute.name description="" maxlength=255 id="" style="" controlStyle=""> + <@textarea name=attribute.qname label=label description=description value=cvalue(attribute.type, attribute.value) maxlength=maxlength id=id style=style controlStyle=controlStyle /> + + +<#-- Label and checkbox boolean field --> +<#macro checkbox name label description="" value="false" id="" style="" controlStyle=""> +
style="${style?html}"> + ${label?html}: + + id="${id?html}" name="" onchange="el('${name?html}').value = (this.checked ? 'true' : 'false');" type="checkbox" <#if value="true">checked="checked" tabindex="0" <#if controlStyle?has_content>style="${controlStyle?html}"/> + true<#else>false" /> + + <#if description?has_content>${description?html} + <#nested> +
+ +<#macro attrcheckbox attribute label=attribute.name description="" id="" style="" controlStyle=""> + <@checkbox name=attribute.qname label=label description=description value=cvalue(attribute.type, attribute.value) id=id style=style controlStyle=controlStyle> + <#nested> + + + +<#-- Status read-only boolean field --> +<#macro status label description="" value="false" style=""> + <#if value != ""> + <#if value="true"><#local tooltip=msg("admin-console.enabled")?html><#else><#local tooltip=msg("admin-console.disabled")?html> +
style="${style?html}"> + ${label?html}: + + enabled<#else>disabled.gif" width="16" height="16" alt="${tooltip}" title="${tooltip}" /> + ${tooltip} + + <#if description?has_content>${description?html} +
+ <#else> +
style="${style?html}"> + ${label?html}: + + ${msg("admin-console.unavailable")} + + <#if description?has_content>${description?html} +
+ + +<#macro attrstatus attribute="" label=attribute.name description="" style=""> + <#-- Special handling for missing attribute - as some JMX objects can be temporarily unavailable --> + <#if attribute?has_content> + <@status label=label description=description value=cvalue(attribute.type, attribute.value) style=style /> + <#else> + <@status label=label description=description value="" style=style /> + + + +<#-- Label and Options Drop-Down list --> +<#macro options name label="" description="" value="" id="" style="" valueStyle="" onchange="" onclick="" escape=true> +
style="${style?html}"> + <#if label?has_content>${label?html}: + style="${valueStyle?html}"> + + + <#if description?has_content><#if escape>${description?html}<#else>${description} +
+ +<#macro option label value> + + +<#macro attroptions attribute label=attribute.name description="" id="" style="" valueStyle="" onchange="" escape=true> + <@options name=attribute.qname label=label description=description value=cvalue(attribute.type, attribute.value) id=id style=style valueStyle="" onchange="" escape=escape> + <#nested> + + + +<#-- Label and Radio Button list --> +<#macro radios name label="" description="" value="" style=""> +
style="${style?html}"> + <#if label?has_content>${label?html}: + +<#assign _name=name> +<#assign _value=value> +<#nested> + + <#if description?has_content>${description?html} +
+ +<#macro radio label value id=""> +
+ id="${id?html}" type="radio" name="${_name?html}" value="${value?html}" <#if value=_value>checked="checked" tabindex="0" /> + ${label?html} +
+ + +<#-- Ordered and Unordered list of values --> +<#macro list listtype label="" description="" value="" style=""> +
style="${style?html}"> + <#if label?has_content>${label?html}: + <${listtype?html}> + <#list value?split(",") as x> +
  • ${x?html}
  • + + + <#if description?has_content>${description?html} +
    + +<#macro ulist label="" description="" value="" style=""> + <@list listtype="ul" label=label description=description value=value style=style /> + +<#macro olist label="" description="" value="" style=""> + <@list listtype="ol" label=label description=description value=value style=style /> + +<#macro attrulist attribute label=attribute.name description="" style=""> + <@ulist label=label description=description value=cvalue(attribute.type, attribute.value) style=style /> + +<#macro attrolist attribute label=attribute.name description="" style=""> + <@olist label=label description=description value=cvalue(attribute.type, attribute.value) style=style /> + + +<#-- Simple button with JavaScript event handler --> +<#macro button label description="" onclick="" style="" id="" class="" disabled="false"> + id="${id?html}" <#if style?has_content>style="${style?html}" type="button" value="${label?html}" onclick="${onclick?html}" <#if disabled="true">disabled="true" /> + <#if description?has_content>${description?html} + diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml index 702c668db6..e11b6ec737 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -1894,9 +1894,24 @@ - - - - + + + + + + + + + utils + + + + + + + + + + diff --git a/source/java/org/alfresco/web/scripts/WebScriptUtils.java b/source/java/org/alfresco/web/scripts/WebScriptUtils.java new file mode 100644 index 0000000000..5a6e5d725d --- /dev/null +++ b/source/java/org/alfresco/web/scripts/WebScriptUtils.java @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2005-2015 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.web.scripts; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.alfresco.repo.jscript.ScriptUtils; +import org.alfresco.repo.web.scripts.RepositoryContainer; +import org.alfresco.service.cmr.admin.RepoUsage; +import org.alfresco.service.cmr.repository.StoreRef; +import org.springframework.extensions.webscripts.WebScript; + +/** + * Override of the JavaScript API ScriptUtils bean "utilsScript" to provide additional + * Remote API methods using objects not available to base Repository project. + *

    + * See "web-scripts-application-context.xml" for bean definition. + * + * @since 4.2.0 + * @since 5.1 (Moved to Remote API project) + * @author Kevin Roast + */ +public class WebScriptUtils extends ScriptUtils +{ + protected RepositoryContainer repositoryContainer; + + public void setRepositoryContainer(RepositoryContainer repositoryContainer) + { + this.repositoryContainer = repositoryContainer; + } + + /** + * Searches for webscript components with the given family name. + * + * @param family the family + * + * @return An array of webscripts that match the given family name + */ + public Object[] findWebScripts(String family) + { + List values = new ArrayList(); + + for (WebScript webscript : this.repositoryContainer.getRegistry().getWebScripts()) + { + if (family != null) + { + Set familys = webscript.getDescription().getFamilys(); + if (familys != null && familys.contains(family)) + { + values.add(webscript.getDescription()); + } + } + else + { + values.add(webscript.getDescription()); + } + } + + return values.toArray(new Object[values.size()]); + } + + public String getHostAddress() + { + try + { + return InetAddress.getLocalHost().getHostAddress(); + } + catch (UnknownHostException e) + { + return "Unknown"; + } + } + + public String getHostName() + { + try + { + return InetAddress.getLocalHost().getHostName(); + } + catch (UnknownHostException e) + { + return "Unknown"; + } + } + + public RepoUsage getRestrictions() + { + return this.services.getRepoAdminService().getRestrictions(); + } + + public RepoUsage getUsage() + { + return this.services.getRepoAdminService().getUsage(); + } + + /** + * Gets the list of repository stores + * + * @return stores + */ + public List getStores() + { + return this.services.getNodeService().getStores(); + } +}