Bläddra i källkod

Added assignment image rename

Manuel Gall 3 år sedan
förälder
incheckning
69f9ca690c
6 ändrade filer med 44 tillägg och 4 borttagningar
  1. 10 0
      server/was.rb
  2. 1 0
      server/was.xml
  3. 2 1
      ui/index.html
  4. 26 2
      ui/js/assignment.js
  5. 2 0
      ui/js/design.js
  6. 3 1
      ui/js/imageSlicer.js

+ 10 - 0
server/was.rb

@@ -875,6 +875,15 @@ class GetAssignment < Riddl::Implementation
   end
 end
 
+
+
+class RenameAssignmentImagePath < Riddl::Implementation
+  def response
+    $db.execute("UPDATE assignments SET image = '#{JSON.parse(@p[0].value.read)["url"]}' WHERE ID = #{@r[1]}")
+  end
+end
+
+
 class DeleteAssignment < Riddl::Implementation
   def response
     $db.execute("DELETE FROM assignments WHERE ID = ?", [@r[1]])
@@ -1107,6 +1116,7 @@ server = Riddl::Server.new(File.join(__dir__,'/was.xml'), :host => 'localhost')
       end
       on resource '\d+' do
         run GetAssignment if get
+        run RenameAssignmentImagePath if put 'list'
         run DeleteAssignment if delete
         on resource '\d+' do
           run DeleteSingleAssignment if delete

+ 1 - 0
server/was.xml

@@ -168,6 +168,7 @@
       </resource>
       <resource relative="\d+">
         <get out="list"/>
+        <put in="list"/>
         <delete/>
         <resource relative="\d+">
           <delete/>

+ 2 - 1
ui/index.html

@@ -635,7 +635,7 @@
     <ui-area data-belongs-to-tab="assignment" class="inactive">
       
       <select name="station" id="searchAssingmentStation"></select>
-      <input data-class="input" id="searchAssingmentPattern" type="text" maxlength="20" size="20" value="Pattern">
+      <input data-class="input" id="searchAssingmentPattern" type="text" maxlength="60" size="20" value="Pattern">
       <input data-class="input" id="searchAssingmentText" type="text" maxlength="20" size="20" value="Text">
       
       <a href="javascript:searchAssignmentForm();">Search</a><br>
@@ -743,6 +743,7 @@
         <h1>New Assignment</h1>
         <form id="assignmentform" onsubmit="submitAssignment()">
           <input type="text" class="abbreviationInput width100 url" name="externalImage" id="addExternalImageAssignment">
+          <button type="button" id="updateExternalImageAssignment">Save Image Path</button>
           <a href="#" id="assignmentLupe" onclick="overlayOn($(this), 'assigment');">🔍</a>
           <div class="wasGroup" data-class="mainDiv">
             <div data-class="description" class="wasLeft">

+ 26 - 2
ui/js/assignment.js

@@ -19,15 +19,18 @@ function createAssignmentForm(assID, url){
   if (assID == null){
     $('#storedassignments').css("display", "none");
     $('#assignmentLupe').css("display", "block"); 
-    $('#addExternalImageAssignment').removeAttr('disabled');
+    //$('#addExternalImageAssignment').removeAttr('disabled');
     $('#addExternalImageAssignment').val("");
+    $('#updateExternalImageAssignment').css("display", "none");    
     
   
   }
   else{
     $('#storedassignments').css("display", "block");
+    $('#updateExternalImageAssignment').css("display", "block");  
+    $('#updateExternalImageAssignment').attr('onClick', 'updateImage(' + assID + ')');
     $('#assignmentLupe').css("display", "none");    
-    $('#addExternalImageAssignment').attr('disabled','disabled');
+    //$('#addExternalImageAssignment').attr('disabled','disabled');
     $('#addExternalImageAssignment').val(url);
     
     
@@ -70,6 +73,27 @@ function createAssignmentForm(assID, url){
 }
 
 
+function updateImage(assID){  
+  
+  var newImgUrl = $('#addExternalImageAssignment').val();
+  $.ajax({
+    type: "Put",
+    data: '{"url": "' + newImgUrl + '"}',
+		headers: {"content-id": "list"},
+    contentType: "application/json",
+    url: "../server/assignments/" + assID,
+    success: function(res) {
+      //reload assignmentlist (left)
+        initAssignment();
+      //reload cur assignment (right)
+        createAssignmentForm(assID, newImgUrl)
+    },
+    error: function (request, status, error) {
+      alert(request.responseText + status + error);
+    }
+  });
+  
+}
 
 //called when new image is selected
 function getImgText(imgtext){

+ 2 - 0
ui/js/design.js

@@ -56,6 +56,8 @@ function overlayOn(value, special="") {
                 $(this).attr("src", newSrc).show("fold");
                 resizeAllRect();
                 fillFormName(extra1.url.substring(extra1.url.lastIndexOf('/') + 1).replace(/\.[^/.]+$/, ""));
+                
+                refreshassignments()
           });
         }
         image.src = newSrc;

+ 3 - 1
ui/js/imageSlicer.js

@@ -580,7 +580,6 @@ function submitSlices(skip = false){
 function overlayOnDupliImages(data) {
   
   
-  
   document.getElementById("overlayNotClickable").style.display = "block";
   
   var clone = document.importNode(document.querySelector('#SlicerDupliOverlay').content,true);
@@ -718,6 +717,9 @@ function togglenext(currelement){
 
 
 function refreshassignments(){
+  
+  console.log("Refreshing")
+  
   $(".singleRect").each(function() {
     var main = $(this);
     $(this).find(".RectangleAssignment div").each(function() {