You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ol...@apache.org on 2012/03/26 11:53:37 UTC

svn commit: r1305280 - in /archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva: search.js templates/search.html

Author: olamy
Date: Mon Mar 26 09:53:36 2012
New Revision: 1305280

URL: http://svn.apache.org/viewvc?rev=1305280&view=rev
Log:
start ui to add/delete artifact metadata properties

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

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js?rev=1305280&r1=1305279&r2=1305280&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js Mon Mar 26 09:53:36 2012
@@ -149,6 +149,7 @@ $(function() {
     artifactVersionDetailViewModel.display();
   }
 
+
   ArtifactVersionDetailViewModel=function(groupId,artifactId,version){
     var mainContent = $("#main-content");
     var self=this;
@@ -156,7 +157,7 @@ $(function() {
     this.artifactId=artifactId;
     this.version=version;
     this.projectVersionMetadata=null;
-
+    this.entries=ko.observableArray([]);
 
     displayGroupId=function(groupId){
       displayGroupDetail(groupId,null);
@@ -244,6 +245,29 @@ $(function() {
                   }
                 }
 
+                if ($(e.target).attr("href")=="#artifact-details-metadatas-content") {
+                  $.log("artifact metadata");
+                  var metadatasContentDiv=mainContent.find("#artifact-details-metadatas-content" );
+                  //if( $.trim(metadatasContentDiv.html()).length<1){
+                    //metadatasContentDiv.html(mediumSpinnerImg());
+                    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) {
+                        self.entries([new MetadataEntry("foo","bar")]);
+                      }
+                    });
+                  //}
+                }
+
+
               });
             }
           });
@@ -267,6 +291,69 @@ $(function() {
       var artifactVersionDetailViewModel = new ArtifactVersionDetailViewModel (groupId,artifactId,version)
       artifactVersionDetailViewModel.display();
     }
+
+
+    addProperty=function(){
+      self.entries.push(new MetadataEntry("","",true));
+    }
+
+    deleteProperty=function(entry){
+
+      self.entries.remove(entry);
+    }
+
+    saveProperty=function(entry){
+      var metadatasContentDiv=mainContent.find("#artifact-details-metadatas-content" );
+      //if( $.trim(metadatasContentDiv.html()).length<1){
+        //metadatasContentDiv.html(mediumSpinnerImg());
+        var metadatasUrl="restServices/archivaServices/browseService/metadatas/"+encodeURIComponent(groupId);
+        metadatasUrl+="/"+encodeURIComponent(artifactId);
+        metadatasUrl+="/"+encodeURIComponent(version);
+        metadatasUrl+="/"+encodeURIComponent(entry.key());
+        metadatasUrl+="/"+encodeURIComponent(entry.value());
+        var selectedRepo=getSelectedBrowsingRepository();
+        if (selectedRepo){
+          metadatasUrl+="?repositoryId="+encodeURIComponent(selectedRepo);
+        }
+        $.ajax(metadatasUrl, {
+          type: "PUT",
+          dataType: 'json',
+          success: function(data) {
+            displaySuccessMessage( $.i18n.prop("artifact.metadata.added"));
+            entry.modified(false);
+          }
+        });
+    }
+
+
+    this.gridMetatadasViewModel = new ko.simpleGrid.viewModel({
+      data: self.entries,
+      columns: [
+        {
+          headerText: $.i18n.prop('browse.artifact.metadata.key'),
+          rowText: "key",
+          id: "key"
+        },
+        {
+          headerText: $.i18n.prop('browse.artifact.metadata.value'),
+          rowText: "value",
+          id: "value"
+        }
+      ],
+      pageSize: 10
+    });
+
+  }
+
+
+  MetadataEntry=function(key,value,editable){
+    var self=this;
+    this.key=ko.observable(key);
+    this.key.subscribe(function(newValue){self.modified(true)});
+    this.value=ko.observable(value);
+    this.value.subscribe(function(newValue){self.modified(true)});
+    this.editable=ko.observable(editable);
+    this.modified=ko.observable(false)
   }
 
   TreeEntry=function(artifact,childs){

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/search.html
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/search.html?rev=1305280&r1=1305279&r2=1305280&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/search.html (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/search.html Mon Mar 26 09:53:36 2012
@@ -682,7 +682,12 @@
       </div>
 
       <div id="artifact-details-metadatas-content" class="tab-pane">
-        metadatas
+        <table class="table table-striped table-bordered" id="artifact-details-metadatas-content-table"
+               data-bind="simpleGrid: gridMetatadasViewModel,simpleGridTemplate:'artifact_metadata_properties_tmpl',pageLinksId:'artifactMetadata_Pagination'">
+
+        </table>
+        <div id="artifactMetadata_Pagination"></div>
+        <a href="#" class="btn btn-primary" data-bind="click: addProperty">${$.i18n.prop('browse.artifact.metadatas.add')}</a>
       </div>
 
     </div>
@@ -735,4 +740,36 @@
       </li>
     {{/each}}
     </ul>
+</script>
+
+<script id="artifact_metadata_properties_tmpl" type="text/html">
+    <thead>
+      <tr>
+        {{each(i, columnDefinition) columns}}
+          <th title="${columnDefinition.title }">${columnDefinition.headerText }</th>
+        {{/each}}
+        <th title="${$.i18n.prop('browse.artifact.metadatas.delete')}">${$.i18n.prop('browse.artifact.metadatas.delete')}</th>
+        <th title="${$.i18n.prop('browse.artifact.metadatas.delete')}">${$.i18n.prop('browse.artifact.metadatas.save')}</th>
+      </tr>
+
+    </thead>
+    <tbody>
+    {{each(i, row) itemsOnCurrentPage()}}
+      <tr>
+        {{each(j, columnDefinition) columns}}
+          {{if row.editable}}
+            <td><input type="text" data-bind="value: row[columnDefinition.rowText]"/></td>
+          {{else}}
+            <td>${ typeof columnDefinition.rowText == 'function' ? columnDefinition.rowText(row) : row[columnDefinition.rowText] }</td>
+          {{/if}}
+        {{/each}}
+        <td><a href="#" class="btn btn-danger" data-bind="click: function(){deleteProperty(row)}">${$.i18n.prop('browse.artifact.metadatas.delete')}</a></td>
+        <td>
+          {{if row.modified}}
+            <a href="#" class="btn btn-warning" data-bind="click: function(){saveProperty(row)}">${$.i18n.prop('browse.artifact.metadatas.save')}</a>
+          {{/if}}
+        </td>
+      </tr>
+    {{/each}}
+    </tbody>
 </script>
\ No newline at end of file