]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1576] rewrite proxies connector page
authorOlivier Lamy <olamy@apache.org>
Thu, 9 Feb 2012 23:08:09 +0000 (23:08 +0000)
committerOlivier Lamy <olamy@apache.org>
Thu, 9 Feb 2012 23:08:09 +0000 (23:08 +0000)
refactor to ease edit mode.

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1242596 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors.js
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/proxy-connectors.html
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/knockout.simpleGrid.js

index 36e322689250402e49102b5e7d031c06b5161840..34852932462c1b61c6dafd1d0453d6408f9f9e23 100644 (file)
@@ -241,11 +241,11 @@ $(function() {
       $.log("editProxyConnector");
     }
 
-    removeProxyConnector=function(managedRepositoryConnectorView,targetRepoId){
-      $.log("removeProxyConnector:"+managedRepositoryConnectorView.source()+","+targetRepoId);
-      var url="restServices/archivaServices/proxyConnectorService/removeProxyConnector?";
-      url += "sourceRepoId="+encodeURIComponent(managedRepositoryConnectorView.source());
-      url += "&targetRepoId="+encodeURIComponent(targetRepoId);
+    removeProxyConnector=function(sourceRepoId,targetRepoId){
+      proxyConnector=getProxyConnector(sourceRepoId, targetRepoId);
+      /*var url="restServices/archivaServices/proxyConnectorService/removeProxyConnector?";
+      url += "sourceRepoId="+encodeURIComponent(proxyConnector.sourceRepoId());
+      url += "&targetRepoId="+encodeURIComponent(proxyConnector.targetRepoId());
       $.ajax(url,
         {
           type: "GET",
@@ -261,33 +261,22 @@ $(function() {
             displayRestError(res);
           }
         }
-      );
+      );*/
+      self.proxyConnectors.remove(proxyConnector);
+      self.displayGrid();
     }
 
     this.findUniqueManagedRepos=function(){
-      var sourcesRepos=[];
+      var managedRepositoriesIds=[];
       //sourceRepoId
       for(i=0;i<self.proxyConnectors().length;i++){
-        var curSrcRepo=self.proxyConnectors()[i];
-        var curSrcRepoId=curSrcRepo.sourceRepoId();
-        var curTarget=self.proxyConnectors()[i];
-        var sourceRepo = $.grep(sourcesRepos,
-                                function(srcRepo,idx){
-                                  for (j=0;j<sourcesRepos.length;j++){
-                                    if (srcRepo.source()==curSrcRepoId){
-                                      return true;
-                                    }
-                                  }
-                                  return false;
-                                }
-        );
-        if (sourceRepo.length>0){
-          sourceRepo[0].targetRepos.push(curTarget);
-        } else {
-          sourcesRepos.push(new ManagedRepositoryConnectorView(curSrcRepoId,getManagedRepository(curSrcRepoId).name(),[curTarget]));
+        var curSrcRepoId=self.proxyConnectors()[i].sourceRepoId();
+        if ($.inArray(curSrcRepoId,managedRepositoriesIds)<0){
+          managedRepositoriesIds.push(curSrcRepoId)
         }
       }
-      return sourcesRepos;
+      $.log("managedRepositoriesIds:"+managedRepositoriesIds);
+      return managedRepositoriesIds;
     }
 
     getManagedRepository=function(id){
@@ -305,24 +294,44 @@ $(function() {
                                         return repo.id()==id;
                                       }
                             );
+      $.log("getRemoteRepository:"+id+":"+remoteRepository);
       return ($.isArray(remoteRepository) && remoteRepository.length>0) ? remoteRepository[0]:new RemoteRepository();
     }
 
-    this.getProxyConnector=function(sourceRepoId,targetRepoId){
+    // return remote repositories proxied for a managed repository
+    getRemoteRepositories=function(id){
+      $.log("getRemoteRepositories:"+id);
+      var remoteRepositoryIds=$.grep(self.proxyConnectors(),
+                                   function(repo,idx){
+                                     return repo.sourceRepoId()==id;
+                                   }
+      );
+      $.log("remoteRepositoryIds.length:"+remoteRepositoryIds.length);
+      var remoteRepositories=[];
+      for (i=0;i<remoteRepositoryIds.length;i++){
+        remoteRepositories.push(getRemoteRepository(remoteRepositoryIds[i].targetRepoId()));
+      }
+      return remoteRepositories;
+    }
+
+    getProxyConnector=function(sourceRepoId,targetRepoId){
+      $.log("getProxyConnector:"+sourceRepoId+":"+targetRepoId);
       var proxyConnector=$.grep(self.proxyConnectors(),
                                       function(proxyConnector,idx){
                                         return proxyConnector.sourceRepoId()==sourceRepoId
                                             && proxyConnector.targetRepoId==targetRepoId;
                                       }
                                   );
-      return ($.isArray(proxyConnector) && proxyConnector.length>0) ? proxyConnector[0]:new ProxyConnector();
+      var res = ($.isArray(proxyConnector) && proxyConnector.length>0) ? proxyConnector[0]:new ProxyConnector();
+      $.log("getProxyConnector res:"+res);
+      return res;
     }
 
     showSettings=function(sourceRepoId,targetRepoId){
       var targetContent = $("#proxy-connectors-grid-remoterepo-settings-content-"+sourceRepoId+"-"+targetRepoId);
       targetContent.html("");
       targetContent.append($("#proxy-connectors-remote-settings-popover-tmpl")
-                               .tmpl(self.getProxyConnector(sourceRepoId,targetRepoId)));
+                               .tmpl(getProxyConnector(sourceRepoId,targetRepoId)));
 
       var targetImg = $("#proxy-connectors-grid-remoterepo-settings-edit-"+sourceRepoId+"-"+targetRepoId);
       targetImg.attr("data-content",targetContent.html());
index 667d742ce6f445fcbc8463001f5c67be80100433..69f2557ef87f5381876873df6d07311bc821fa77 100644 (file)
   </thead>
 
   {{each(i, row) itemsOnCurrentPage()}}
-    {{var sourceId = row.source()}}
-    <tr data-bind="css:{ 'modified': row.modified()}">
+    <tr>
       <td>
         <blockquote>
-          <p>${row.source()}</p>
-          <p>${row.sourceName()}</p>
+          <p>${getManagedRepository(row).id()}</p>
+          <p>${getManagedRepository(row).name()}</p>
         </blockquote>
+      </td>
       <td>
-          {{each(j, targetRepo) row.targetRepos()}}
-          {{var targetRepoId = targetRepo.targetRepoId()}}
+        {{each(j, targetRepo) getRemoteRepositories(row)}}
+          {{var targetRepoId = targetRepo.id()}}
           <blockquote>
             <p>${targetRepoId}</p>
             <p>${getRemoteRepository(targetRepoId).name()}</p>
             <p>${getRemoteRepository(targetRepoId).url()}</p>
             <p>
               <a popover-title="${$.i18n.prop('proxy-connectors.grid.remoterepo.settings.popover.title')}"
-                 data-bind="event: { mouseover: function(){ showSettings(sourceId,targetRepoId)},},click: function(){ editProxyConnector(row)}"
-                 id="proxy-connectors-grid-remoterepo-settings-edit-${sourceId}-${targetRepoId}" href="#">
+                 data-bind="event: { mouseover: function(){ showSettings(row,targetRepoId)},},click: function(){ editProxyConnector(row)}"
+                 id="proxy-connectors-grid-remoterepo-settings-edit-${row}-${targetRepoId}" href="#">
                   ${$.i18n.prop('edit')}
               </a>
-                <a href="#" data-bind="click: function(){ removeProxyConnector(row,targetRepoId) }">
+                <a href="#" data-bind="click: function(){ removeProxyConnector(row,targetRepo)}">
                   <img src="images/edit-cut.png" title="${$.i18n.prop('delete')}"/>
                 </a>
               <div id="proxy-connectors-grid-remoterepo-settings-content-${val}-${targetRepoId}" style="display:none"></div>
             </p>
           </blockquote>
-          {{/each}}
+        {{/each}}
       </td>
     </tr>
   {{/each}}
index cc56f592b4895b172616ffcdcf5fc46f7d4e6009..1f38f07433a4de24e51b42cb6f8e3340c3f6effc 100644 (file)
 
           // Render the page links
           var pageLinksContainer = $("#"+allBindings.pageLinksId).get(0);
-          ko.renderTemplate(pageLinksTemplateName, viewModel, { templateEngine: templateEngine }, pageLinksContainer, "replaceNode")
+          if (viewModel.pageLinksUpdateCallBack){
+            ko.renderTemplate(pageLinksTemplateName, viewModel, { templateEngine: templateEngine }, pageLinksContainer, "replaceNode")
               .subscribe(viewModel.pageLinksUpdateCallBack?viewModel.pageLinksUpdateCallBack:function(){});
+          } else {
+            ko.renderTemplate(pageLinksTemplateName, viewModel, { templateEngine: templateEngine }, pageLinksContainer, "replaceNode");
+          }
           if (viewModel.pageLinksUpdateCallBack) viewModel.pageLinksUpdateCallBack();
         }
     };