]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1620] add a tab to browse artifact content in artifact detail view
authorOlivier Lamy <olamy@apache.org>
Wed, 16 May 2012 22:16:49 +0000 (22:16 +0000)
committerOlivier Lamy <olamy@apache.org>
Wed, 16 May 2012 22:16:49 +0000 (22:16 +0000)
add javascript architecture.

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

archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/search.html

index f3a3a4f6c8eab96e2c018b494e5b5a1cbca9f266..1a80b424a90c8f0bc4574c81f5139f399216d27a 100644 (file)
@@ -151,7 +151,7 @@ define("search",["jquery","i18n","jquery.tmpl","choosen","order!knockout","knock
   }
 
 
-  ArtifactVersionDetailViewModel=function(groupId,artifactId,version){
+  ArtifactVersionDetailViewModel=function(groupId,artifactId,version,repositoryId){
     var mainContent = $("#main-content");
     var self=this;
     this.groupId=groupId;
@@ -159,6 +159,7 @@ define("search",["jquery","i18n","jquery.tmpl","choosen","order!knockout","knock
     this.version=version;
     this.projectVersionMetadata=null;
     this.entries=ko.observableArray([]);
+    this.repositoryId=repositoryId;
 
     displayGroupId=function(groupId){
       displayGroupDetail(groupId,null);
@@ -250,28 +251,40 @@ define("search",["jquery","i18n","jquery.tmpl","choosen","order!knockout","knock
                 if ($(e.target).attr("href")=="#artifact-details-metadatas-content") {
                   $.log("artifact metadata");
                   var metadatasContentDiv=mainContent.find("#artifact-details-metadatas-content" );
-                    var metadatasUrl="restServices/archivaServices/browseService/metadatas/"+encodeURIComponent(groupId);
-                    metadatasUrl+="/"+encodeURIComponent(artifactId);
-                    metadatasUrl+="/"+encodeURIComponent(version);
-                    var selectedRepo=getSelectedBrowsingRepository();
-                    if (selectedRepo){
-                      metadatasUrl+="?repositoryId="+encodeURIComponent(selectedRepo);
+                  var metadatasUrl="restServices/archivaServices/browseService/metadatas/"+encodeURIComponent(groupId);
+                  metadatasUrl+="/"+encodeURIComponent(artifactId);
+                  metadatasUrl+="/"+encodeURIComponent(version);
+                  var selectedRepo=getSelectedBrowsingRepository();
+                  if (selectedRepo){
+                    metadatasUrl+="?repositoryId="+encodeURIComponent(selectedRepo);
+                  }
+                  $.ajax(metadatasUrl, {
+                    type: "GET",
+                    dataType: 'json',
+                    success: function(data) {
+                      var entries= $.map(data,function(e,i){
+                        return new MetadataEntry( e.key, e.value,false);
+                      });
+                      self.entries(entries);
                     }
-                    $.ajax(metadatasUrl, {
-                      type: "GET",
-                      dataType: 'json',
-                      success: function(data) {
-                        var entries= $.map(data,function(e,i){
-                          return new MetadataEntry( e.key, e.value,false);
-                        });
-                        self.entries(entries);
-                      }
-                    });
+                  });
                 }
 
-                if ($(e.target).attr("href")=="#artifact-details-pom-data-content") {
-                  $.log("pom content");
-
+                if ($(e.target).attr("href")=="#artifact-details-file-content") {
+                  $.log("file content:"+self.groupId+":"+self.artifactId+":"+self.version);
+                  var entriesUrl = "restServices/archivaServices/browseService/artifactContentEntries/"+encodeURIComponent(self.groupId);
+                  entriesUrl+="/"+encodeURIComponent(self.artifactId)+"/"+encodeURIComponent(self.version);
+                  entriesUrl+="?repositoryId="+encodeURIComponent(self.repositoryId);
+                  $.ajax(entriesUrl,{
+                    type: "GET",
+                    dataType: 'json',
+                    success: function(data) {
+                      var artifactContentEntryViewModel=
+                          new ArtifactContentEntryViewModel(self.groupId,self.artifactId,self.version,mapArtifactContentEntries(data));
+                      $("#artifact-details-file-content").html($("#artifact_content_main_tmpl").tmpl());
+                      ko.applyBindings(artifactContentEntryViewModel,mainContent.find("#artifact_file_content_div").get(0));
+                    }
+                  });
                 }
 
 
@@ -373,6 +386,53 @@ define("search",["jquery","i18n","jquery.tmpl","choosen","order!knockout","knock
 
   }
 
+  ArtifactContentEntry=function(name,file,depth){
+    this.name=name;
+    this.file=file;
+    this.depth=depth;
+  }
+
+  mapArtifactContentEntries=function(data){
+    if(data==null){
+      return [];
+    }
+    if ( $.isArray(data)){
+      return $.map(data,function(e){
+        return new ArtifactContentEntry(e.name,e.file,e.depth);
+      })
+    }
+    return new ArtifactContentEntry(data.name,data.file,data.depth);
+  }
+
+  ArtifactContentEntryViewModel=function(groupId,artifactId,version,artifactContentEntries){
+    var self=this;
+    this.groupId=groupId;
+    this.artifactId=artifactId;
+    this.version=version;
+    this.artifactContentEntries=ko.observableArray(artifactContentEntries);
+    $.log("size:"+this.artifactContentEntries().length);
+
+    entries=function(){
+      return self.artifactContentEntries;
+    }
+
+    displayPath=function(artifactContentEntry){
+      $.log("ArtifactContentEntryViewModel#displayPath:"+artifactContentEntry.name);
+
+      var entriesUrl = "restServices/archivaServices/browseService/artifactContentEntries/"+encodeURIComponent(self.groupId);
+      entriesUrl+="/"+encodeURIComponent(self.artifactId)+"/"+encodeURIComponent(self.version);
+      entriesUrl+="?repositoryId="+encodeURIComponent(getSelectedBrowsingRepository());
+      entriesUrl+="&p="+encodeURIComponent(artifactContentEntry.name);
+      $.ajax(entriesUrl,{
+        type: "GET",
+        dataType: 'json',
+        success: function(data) {
+          self.artifactContentEntries(mapArtifactContentEntries(data));
+        }
+      });
+
+    }
+  }
 
   MetadataEntry=function(key,value,editable){
     var self=this;
@@ -1172,7 +1232,7 @@ define("search",["jquery","i18n","jquery.tmpl","choosen","order!knockout","knock
         dataType: 'json',
         success: function(data) {
           mainContent.find("#selected_repository" ).html($("#selected_repository_tmpl" ).tmpl({repositories:data,selected:repositoryId}));
-          var artifactVersionDetailViewModel=new ArtifactVersionDetailViewModel(groupId,artifactId,version);
+          var artifactVersionDetailViewModel=new ArtifactVersionDetailViewModel(groupId,artifactId,version,repositoryId);
           artifactVersionDetailViewModel.display(true);
         }
     });
index b9b31a835ee1f33a83ee45337144dc15377db3c7..2c7c1d57d6162555e0250cbdf7850d79d5e210c4 100644 (file)
         <a data-toggle="tab" href="#artifact-details-dependency-tree-content">${$.i18n.prop('artifact.detail.tab.header.dependency.tree')}</a>
       </li>
       <li>
-        <a data-toggle="tab" href="#artifact-details-pom-data-content">${$.i18n.prop('artifact.detail.tab.header.pom.content')}</a>
+        <a data-toggle="tab" href="#artifact-details-file-content">${$.i18n.prop('artifact.detail.tab.header.file.content')}</a>
       </li>
       <li>
         <a data-toggle="tab" href="#artifact-details-used-by-content">${$.i18n.prop('artifact.detail.tab.header.used.by')}</a>
       <div id="artifact-details-dependency-tree-content" class="tab-pane">
       </div>
 
-      <div id="artifact-details-pom-data-content" class="tab-pane">
+      <div id="artifact-details-file-content" class="tab-pane">
       </div>
 
       <div id="artifact-details-used-by-content" class="tab-pane"></div>
       </tr>
     {{/each}}
     </tbody>
+</script>
+
+<script id="artifact_content_main_tmpl" type="text/html">
+  <div id="artifact_file_content_div" data-bind='template:{name:"artifact_content_tmpl"}'>
+  </div>
+</script>
+
+<script id="artifact_content_tmpl" type="text/html">
+    <ul>
+      {{each(i, artifactContentEntry) artifactContentEntries()}}
+        <li data-bind="css: { 'browse-list': artifactContentEntry.file==false }">
+          <a href="#" data-bind="click: function(){displayPath(artifactContentEntry)}">${artifactContentEntry.name}</a>
+        </li>
+      {{/each}}
+    </ul>
 </script>
\ No newline at end of file