]> source.dussan.org Git - archiva.git/commitdiff
Add a service and use ajax to build menus
authorskygo <skygo@unknown>
Mon, 29 Apr 2013 22:38:11 +0000 (22:38 +0000)
committerskygo <skygo@unknown>
Mon, 29 Apr 2013 22:38:11 +0000 (22:38 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-MRM-1756@1477395 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/PluginsService.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultPluginsServices.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/main.js

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 (file)
index 0000000..27f8df0
--- /dev/null
@@ -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 (file)
index 0000000..b47b7e7
--- /dev/null
@@ -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<String> repositoryType = new ArrayList<String>();
+    
+    @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);
+        
+    }
+
+}
index 1b2188b0952cc00fec5147b49adcb955e9197ef2..f2c1f2d8fc5323c3c2db18a6376afc916f13c265 100644 (file)
@@ -68,6 +68,7 @@
       <ref bean="searchService#rest"/>
       <ref bean="commonServices#rest"/>
       <ref bean="browseService#rest"/>
+      <ref bean="pluginsService#rest"/>
       <ref bean="systemStatusService#rest"/>
       <ref bean="reportRepositoriesService#rest" />
       <ref bean="mergeRepositoriesService#rest"/>
index 717c5a4e91284d304b6a0829337575841f81e758..ccf7416d20f78abaf93bf5fcceb15ea3e620ee4a 100644 (file)
@@ -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()}});