From: skygo Date: Mon, 29 Apr 2013 22:38:11 +0000 (+0000) Subject: Add a service and use ajax to build menus X-Git-Tag: archiva-2.0.0-RC1~342^2~10 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a98c867b7fc38b83f0c0452d811c0edb20c8e4ee;p=archiva.git Add a service and use ajax to build menus git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-MRM-1756@1477395 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/PluginsService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/PluginsService.java new file mode 100644 index 000000000..27f8df0a6 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/PluginsService.java @@ -0,0 +1,45 @@ +package org.apache.archiva.rest.api.services; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.redback.authorization.RedbackAuthorization; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +/** + * contains some services for plugins + * + * @author Eric Barboni + * @since 1.4-M4 + */ +@Path( "/pluginsService/" ) +public interface PluginsService +{ + + @Path( "getAdminPlugins" ) + @GET + @Produces( { MediaType.TEXT_PLAIN } ) + @RedbackAuthorization( noRestriction = true ) + String getAdminPlugins( ) + throws ArchivaRestServiceException; + +} diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultPluginsServices.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultPluginsServices.java new file mode 100644 index 000000000..b47b7e7a1 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultPluginsServices.java @@ -0,0 +1,76 @@ +package org.apache.archiva.rest.services; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.apache.archiva.rest.api.services.ArchivaRestServiceException; +import org.springframework.stereotype.Service; + +import javax.inject.Inject; +import org.apache.archiva.rest.api.services.PluginsService; +import org.springframework.context.ApplicationContext; +import org.springframework.core.io.Resource; + +/** + * @author Eric Barboni + */ +@Service( "pluginsService#rest" ) +public class DefaultPluginsServices + implements PluginsService +{ + + private List repositoryType = new ArrayList(); + + @Inject + public DefaultPluginsServices( ApplicationContext applicationContext ) + { + Resource[] xmlResources; + try { + xmlResources = applicationContext.getResources( "/**/repository/**/main.js" ); + for (Resource rc : xmlResources) + { + String tmp = rc.getURL().toString(); + tmp = tmp.substring( tmp.lastIndexOf("repository") + 11, tmp.length() - 8 ); + repositoryType.add( tmp ); + } + } catch (IOException ex) { + + } + + } + + @Override + public String getAdminPlugins() + throws ArchivaRestServiceException + { + // rebuild + String baseRepo = "archiva/admin/repository/"; + StringBuilder sb = new StringBuilder(); + for (String repoType : repositoryType) + { + sb.append( baseRepo ).append( repoType ).append( "/main" ).append( "|" ); + } + + return sb.substring( 0, sb.length() - 1); + + } + +} diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml index 1b2188b09..f2c1f2d8f 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml @@ -68,6 +68,7 @@ + diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/main.js b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/main.js index 717c5a4e9..ccf7416d2 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/main.js +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/main.js @@ -226,15 +226,21 @@ function(jquery,ui,sammy,tmpl,i18n,jqueryCookie,bootstrap,archivaSearch,jqueryVa this.administrationMenuItems = ko.observableArray([ {text: $.i18n.prop('menu.administration'), id: null} ]); - - var myrepplugins = "archiva/admin/repository/legacy/main|archiva/admin/repository/maven2/main"; - $.each(myrepplugins.split("|"), function(key, value) { - alert(value); - require([value], function() { + var pluginsURL = "restServices/archivaServices/pluginsService/getAdminPlugins"; + $.ajax(pluginsURL, { + type: "GET", + dataType: 'text', + success: function(data) { + $.each(data.split("|"), function(key, value) { + require([value], function() { showMenu(self.administrationMenuItems); }); }); + } + }); + //var myrepplugins = "archiva/admin/repository/legacy/main|archiva/admin/repository/maven2/main"; + self.administrationMenuItems.push({ text : $.i18n.prop('menu.network-proxies') , id: "menu-network-proxies-list-a" , href: "#networkproxies" , redback: "{permissions: ['archiva-manage-configuration']}", func: function(){displayNetworkProxies()}}); self.administrationMenuItems.push({ text : $.i18n.prop('menu.repository-scanning') , id: "menu-repository-scanning-list-a" , href: "#scanningList" , redback: "{permissions: ['archiva-manage-configuration']}", func: function(){displayRepositoryScanning()}}); self.administrationMenuItems.push({ text : $.i18n.prop('menu.runtime-configuration') , id: "menu-runtime-configuration-list-a" , href: "#runtimeconfig" , redback: "{permissions: ['archiva-manage-configuration']}", func: function(){displayRuntimeConfiguration()}});