Explorar o código

update image upload

SyuanYu %!s(int64=2) %!d(string=hai) anos
pai
achega
ac28d2c6e6

+ 0 - 4
backstage/collections/routes.py

@@ -44,11 +44,7 @@ def create():
     csliderimg = []
     csliderimgfilename = []
     form.image.data.filename = processImgFile(form.image.data.filename)
-<<<<<<< Updated upstream
-    # for file in form.collectionslider.data: #CURRENTLY UNUSED
-=======
     # for file in form.collectionslider.data:
->>>>>>> Stashed changes
     #     file.filename = processImgFile(file.filename)
     #     csliderimg.append(file)
     #     csliderimgfilename.append(file.filename)

+ 1 - 64
backstage/static/js/editor.js

@@ -199,16 +199,6 @@ axios.get(contentApiUrl).then(({ data }) => {
       //console.log('something changed', block);
     },
   });
-<<<<<<< Updated upstream
-});
-
-function editorSave() {
-  editor
-    .save()
-    .then((outputData) => {
-      var articleinfo = GetMdHeader();
-      var mdContent = '<div class="container-fluid blog_article p-0">\n\n';
-=======
   if ($("#editorjs1").length > 0) {
     console.log("editorjs1存在");
     editorslider = new EditorJS({
@@ -323,7 +313,7 @@ function editorSave() {
               }
             }
             //alert(mdContent);
-
+            mdContent += "</div>\n\n";
             var mdData = articleinfo + "\n\n" + mdContent;
 
             postData = {
@@ -443,36 +433,10 @@ function editorSave() {
         var articleinfo = GetMdHeader();
         var mdContent = '<div class="container-fluid blog_article p-0">\n\n';
         //var headings = new Array();
->>>>>>> Stashed changes
 
         for (i = 0; i < outputData.blocks.length; i++) {
           var paragraphdata = "";
 
-<<<<<<< Updated upstream
-        block = outputData.blocks[i];
-        if (block.type == "header") {
-          mdContent += "## " + block.data.text + "\n";
-        } else if (block.type == "paragraph") {
-          paragraphdata += block.data.text;
-
-          if (paragraphdata != "") {
-            //make sure it's not empty
-            mdContent += paragraphdata + "\n\n";
-          }
-        } else if (block.type == "hr") {
-          mdContent += "\n---\n";
-        } else if (block.type == "image") {
-          iurl = block.data.file.url.split("/");
-          mdContent +=
-            '<img class="img-fluid" alt="' +
-            block.data.caption +
-            '"\n  src="' +
-            iurl[iurl.length - 2] +
-            "/" +
-            iurl[iurl.length - 1] +
-            '"\n  layout="responsive"></img>';
-          if (block.data.caption != "") {
-=======
           //alert(block.type);
           block = outputData.blocks[i];
           if (block.type == "header") {
@@ -507,7 +471,6 @@ function editorSave() {
           } else if (block.type == "delimiter") {
             mdContent += "\n---\n";
           } else if (block.type == "embed") {
->>>>>>> Stashed changes
             mdContent +=
               "\n<iframe src=" +
               block.data.embed.replace("https://www.youtube.com/embed/", "") +
@@ -521,27 +484,8 @@ function editorSave() {
             mdContent += "\n" + tableArrayToHtml(block.data.content) + "\n\n";
             //console.log(tableArrayToHtml(block.data.content));
           }
-<<<<<<< Updated upstream
-          mdContent += "\n\n";
-        } else if (block.type == "delimiter") {
-          mdContent += "\n---\n";
-        } else if (block.type == "embed") {
-          mdContent +=
-            "\n<iframe src=" +
-            block.data.embed.replace("https://www.youtube.com/embed/", "") +
-            'layout="responsive" width="' +
-            block.data.width +
-            '" height="' +
-            block.data.height +
-            '"></iframe>\n\n';
-        } else if (block.type == "table") {
-          mdContent += "\n" + tableArrayToHtml(block.data.content) + "\n\n";
-        }
-      }
-=======
         }
         //alert(mdContent);
->>>>>>> Stashed changes
 
         var mdData = articleinfo + "\n\n" + mdContent;
 
@@ -556,13 +500,6 @@ function editorSave() {
       .catch((error) => {
         console.log("Saving failed: ", error);
       });
-<<<<<<< Updated upstream
-    })
-    .catch((error) => {
-      console.log("Saving failed: ", error);
-    });
-=======
   }
->>>>>>> Stashed changes
 }
 submitButton.onclick = editorSave;

+ 104 - 285
backstage/static/js/yo.js

@@ -1,11 +1,7 @@
 contentApiUrl = `${PORTAL_SERVER}contents?url=`;
 frontMatters = [];
 contentMatters = [];
-<<<<<<< Updated upstream
-tagOptionIds = ['chousetype', 'csize', 'cbudget', 'cbednum'];
-=======
 tagOptionIds = ["chousetype", "csize", "cbudget", "cbednum"];
->>>>>>> Stashed changes
 
 var SwfType = {};
 if (location.pathname.indexOf("system_furniture") >= 0) {
@@ -134,131 +130,102 @@ function updateHeader() {
 // 新增都是create的Py
 // 修改都是writeMd
 
+// mdContent = GetMdHeader(frontMatters);
 // writeMd 修改
 function writeMd() {
-  console.log("frontMatters", frontMatters);
   axios
     .get("/backstage/utils?trantext=" + $("#ccategories").val())
     .then(({ data }) => {
       $("#ccol1").val(data);
     })
     .finally(() => {
-<<<<<<< Updated upstream
-        mdContent = GetMdHeader();
-        mdContent += contentMatters.join("\n");
-        var formData = new FormData();
-        var imagefile = document.querySelector('#cfile');
-        //alert("The type is " + $('#ctype').val());
-        if ($('#ctype').val()=="collection")
-        {
-            var imagefil2 = document.querySelector('#cnewcoverimg');
-            var imagefil3 = document.querySelector('#cnewcomment');
-            formData.append("image1", imagefile.files[0]);
-            formData.append("image2", imagefil2.files[0]);
-            formData.append("image3", imagefil3.files[0]);
-            axios.post('/backstage/multiupload/title', formData, {
-                headers: {
-                    'Content-Type': 'multipart/form-data'
-                }
-            }).then(({ data }) => {
-                //$('#ccomment').val("");
-                console.log(data);
-                if (data.success == "1") {
-                    var imglinks = data.fileurl.split(";;;");
-                    //mdContent = mdContent.replace($('#ccomment').val(), '/img/title/' + data.filelink.substring(data.file.url.lastIndexOf('/') + 1));
-                    console.log(imglinks);
-                    console.log(imagefile, imagefil2, imagefil3);
-                    mdContent = mdContent.replace($('#cfile').val(), '/img/title/' + imglinks[0]);
-                    mdContent = mdContent.replace($('#cnewcoverimg').val(), '/img/title/' + imglinks[1]);
-                    mdContent = mdContent.replace($('#cnewcomment').val(), '/img/title/' + imglinks[2]);
-                }
-                else
-                {
-                    console.log("skipped");
-                }
-                // try split(";;;")
-
-                postData = {
-                    content: mdContent,
-                    url: editTarget
-                };
-                //console.log(mdContent);
-                axios.post(contentApiUrl + editTarget, json = postData).then(({ data }) => {
-                });
-            }).finally(() => {
-                alert('資料已更新'); // test
-                location.reload();
-            });
-        }
-        else
-        {
-            formData.append("image", imagefile.files[0]);
-            axios.post('/backstage/upload/title', formData, {
-                headers: {
-                    'Content-Type': 'multipart/form-data'
-                }
-            }).then(({ data }) => {
-                //alert($('#cfile').val());
-                if (data.success == "1") {
-                    mdContent = mdContent.replace($('#cfile').val(), '/img/title/' + data.file.url.substring(data.file.url.lastIndexOf('/') + 1));
-                }
-    
-                postData = {
-                    content: mdContent,
-                    url: editTarget
-                };
-                //console.log(mdContent);
-                axios.post(contentApiUrl + editTarget, json = postData).then(({ data }) => {
-                });
-            }).finally(() => {
-                alert('資料已更新'); // test
-                location.reload();
-            });
-        }
-=======
-      // if (window.location.pathname == "/backstage/collections") {
-      //     mdContent = setContent();
-      //     // console.log('call setContent()');
-      //   }else {
-      //     mdContent = GetMdHeader();
-      //   }
       mdContent = GetMdHeader(frontMatters);
       mdContent += contentMatters.join("\n");
       var formData = new FormData();
       var imagefile = document.querySelector("#cfile");
-      console.log(imagefile.files);
-      formData.append("image", imagefile.files[0]);
-      axios
-        .post("/backstage/upload/title", formData, {
-          headers: {
-            "Content-Type": "multipart/form-data",
-          },
-        })
-        .then(({ data }) => {
-          $("#cfile").val("");
-          if (data.success == "1") {
-            mdContent = mdContent.replace(
-              $("#cimage").val(),
-              "/img/title/" +
-                data.file.url.substring(data.file.url.lastIndexOf("/") + 1)
-            );
-            //alert(data.file.url.substring(data.file.url.lastIndexOf('/')+1));
-          }
+      //alert("The type is " + $('#ctype').val());
+      if ($("#ctype").val() == "collection") {
+        var imagefil2 = document.querySelector("#cnewcoverimg");
+        var imagefil3 = document.querySelector("#cnewcomment");
+        formData.append("image1", imagefile.files[0]);
+        formData.append("image2", imagefil2.files[0]);
+        formData.append("image3", imagefil3.files[0]);
+        axios
+          .post("/backstage/multiupload/title", formData, {
+            headers: {
+              "Content-Type": "multipart/form-data",
+            },
+          })
+          .then(({ data }) => {
+            //$('#ccomment').val("");
+            console.log(data);
+            if (data.success == "1") {
+              var imglinks = data.fileurl.split(";;;");
+              //mdContent = mdContent.replace($('#ccomment').val(), '/img/title/' + data.filelink.substring(data.file.url.lastIndexOf('/') + 1));
+              console.log(imglinks);
+              console.log(imagefile, imagefil2, imagefil3);
+              mdContent = mdContent.replace(
+                $("#cfile").val(),
+                "/img/title/" + imglinks[0]
+              );
+              mdContent = mdContent.replace(
+                $("#cnewcoverimg").val(),
+                "/img/title/" + imglinks[1]
+              );
+              mdContent = mdContent.replace(
+                $("#cnewcomment").val(),
+                "/img/title/" + imglinks[2]
+              );
+            } else {
+              console.log("skipped");
+            }
+            // try split(";;;")
+
+            postData = {
+              content: mdContent,
+              url: editTarget,
+            };
+            //console.log(mdContent);
+            axios
+              .post(contentApiUrl + editTarget, (json = postData))
+              .then(({ data }) => {});
+          })
+          .finally(() => {
+            alert("資料已更新"); // test
+            location.reload();
+          });
+      } else {
+        formData.append("image", imagefile.files[0]);
+        axios
+          .post("/backstage/upload/title", formData, {
+            headers: {
+              "Content-Type": "multipart/form-data",
+            },
+          })
+          .then(({ data }) => {
+            //alert($('#cfile').val());
+            if (data.success == "1") {
+              mdContent = mdContent.replace(
+                $("#cfile").val(),
+                "/img/title/" +
+                  data.file.url.substring(data.file.url.lastIndexOf("/") + 1)
+              );
+            }
 
-          postData = {
-            content: mdContent,
-            url: editTarget,
-          };
-          //console.log(mdContent);
-          axios
-            .post(contentApiUrl + editTarget, (json = postData))
-            .then(({ data }) => {});
-        })
-        .finally(() => {
-          alert("資料已更新"); // test
-          location.reload();
-        });
->>>>>>> Stashed changes
+            postData = {
+              content: mdContent,
+              url: editTarget,
+            };
+            //console.log(mdContent);
+            axios
+              .post(contentApiUrl + editTarget, (json = postData))
+              .then(({ data }) => {});
+          })
+          .finally(() => {
+            alert("資料已更新"); // test
+            location.reload();
+          });
+      }
     });
 }
 // md的內容解出來
@@ -382,108 +349,6 @@ function parseMd(content) {
                 //alert(line);
                 $('#ccaturl').val(line.replace('caturl: ', '').replaceAll('\"', ''));
             } */
-<<<<<<< Updated upstream
-            if (line.includes('col1: ')) {
-                //alert(line);
-                $('#ccol1').val(line.replace('col1: ', '').replaceAll('\"', ''));
-            }
-            if (line.includes('col2: ')) {
-                //alert(line);
-                $('#ccol2').val(line.replace('col2: ', '').replaceAll('\"', ''));
-            }
-
-            //for blogs
-            if (line.includes('introduction: ')) {
-                //alert(line);
-                $('#cintroduction').val(line.replace('introduction: ', '').replaceAll('\"', '').replaceAll('<br>', '\r\n'));
-            }
-            if (line.includes('question_box_intro: ')) {
-                //alert(line);
-                $('#cquestionboxintro').val(line.replace('question_box_intro: ', '').replaceAll('\"', ''));
-            }
-
-            
-            //for collections
-            if (line.includes('banner_img_text: ')) {
-                //alert(line);
-                $('#ccoverimgtxt').val(line.replace('banner_img_text: ', '').replaceAll('\"', ''));
-            }
-
-            if (line.includes('homeowner: ')) {
-                //alert(line);
-                $('#chomeowner').val(line.replace('homeowner: ', '').replaceAll('\"', ''));
-				
-            }
-
-            if (line.includes('size: ')) {
-                //alert(line);
-                $('#csize').val(line.replace('size: ', '').replaceAll('\"', ''));
-            }
-
-            if (line.includes('bed_num: ')) {
-                //alert(line);
-                $('#cbednum').val(line.replace('bed_num: ', '').replaceAll('\"', ''));
-            }
-
-            if (line.includes('house_cat: ')) {
-                //alert(line);
-                $('#chousetype').val(line.replace('house_cat: ', '').replaceAll('\"', ''));
-            }
-
-            if (line.includes('designer: ')) {
-                //alert(line);
-                $('#cdesigner').val(line.replace('designer: ', '').replaceAll('\"', ''));
-            }
-
-            if (line.includes('space: ')) {
-                //alert(line);
-                $('#cspace').val(line.replace('space: ', '').replaceAll('\"', ''));
-            }
-
-            if (line.includes('loc: ')) {
-                //alert(line);
-                $('#cloc').val(line.replace('loc: ', '').replaceAll('\"', ''));
-            }
-
-            if (line.includes('budget: ')) {
-                //alert(line);
-                $('#cbudget').val(line.replace('budget: ', '').replaceAll('\"', ''));
-            }
-
-            if (line.includes('construction: ')) {
-                //alert(line);
-                $('#cconstruction').val(line.replace('construction: ', '').replaceAll('\"', ''));
-            }
-
-            if (line.includes('collection_name: ')) {
-                //alert(line);
-                $('#ccollname').val(line.replace('collection_name: ', '').replaceAll('\"', ''));
-            }
-
-            if (line.includes('collection_slider: ')) {
-                //alert(line);
-                //$('#ccollslider').val(line.replace('collection_slider: ', '').replaceAll('\"', ''));
-            }
-
-            if (line.includes('comment: ')) {
-                //alert(line);
-                $('#ccomment').val(line.replace('comment: ', '').replaceAll('\"', ''));
-            }
-
-            if (line.includes('cover_img: ')) {
-                //alert(line);
-                $('#ccoverimg').val(line.replace('cover_img: ', '').replaceAll('\"', ''));
-            }
-
-            // back to normal
-            if (line.includes('---')) {
-                isNotFrontMatterCount += 1;
-            }
-            continue;
-        }
-        contentMatters.push(line)
-        /*         if (line.toString().trim() == "") {
-=======
       if (line.includes("col1: ")) {
         //alert(line);
         $("#ccol1").val(line.replace("col1: ", "").replaceAll('"', ""));
@@ -593,7 +458,6 @@ function parseMd(content) {
     }
     contentMatters.push(line);
     /*         if (line.toString().trim() == "") {
->>>>>>> Stashed changes
                     rblocks.push({ 'type': 'br', 'text': line });
                     continue;
                 } */
@@ -657,68 +521,6 @@ function parseMd(content) {
   return rblocks;
 }
 
-<<<<<<< Updated upstream
-function GetMdHeader() {
-    rContent = "";
-    rContent += '---\n';
-    rContent += 'meta_title: "' + $('#cmetattl').val() + '"\n';
-    rContent += 'meta_description: "' + $('#cmetadsc').val() + '"\n';
-    rContent += 'title: "' + $('#ctitle').val() + '"\n';
-    rContent += 'date: ' + $('#cdate').val() + '\n';
-    rContent += 'draft: ' + (!$('#cdraft').is(':checked')) + '\n';
-    rContent += 'type: "' + $('#ctype').val() + '"\n';
-    rContent += 'url: "' + $('#curl').val() + '"\n';
-    //mdContent += 'url: "' + $('#curl').val() + '"\n';
-    if($('#cfile').val()!="" && $('#cfile').val()!=undefined)
-    {
-        rContent += 'image: "' + $('#cfile').val() + '"\n';
-    }
-    else
-    {
-        rContent += 'image: "' + $('#cimage').val() + '"\n';
-    }
-    if ($('#ctype').val() == "collection") {
-        rContent += 'collection_name: "' + $('#ccollname').val() + '"\n';
-        if($('#cnewcoverimg').val()!="" && $('#cnewcoverimg').val()!=undefined)
-        {
-            rContent += 'cover_img: "' + $('#cnewcoverimg').val()+ '"\n';
-        }
-        else
-        {
-            rContent += 'cover_img: "' + $('#ccoverimg').val() + '"\n';
-        }
-        rContent += 'description: "' + $('#cdescription').val().replace(/\r?\n/g, '<br>') + '"\n';
-        //rContent += 'weight: ' + ($('#cweight').val() == 'undefined' ? "" : $('#cweight').val()) + '\n';
-
-        tags = [];
-        for (var toi of tagOptionIds) {
-            if ($('#' + toi).val() != "")
-                tags.push($('#' + toi).val());
-        }
-        rContent += 'tags: "' + tags.join(',') + '"\n';
-        //rContent += 'tags: "' + ($('#ctags').val() == 'undefined' ? "" : $('#ctags').val()) + '"\n';
-
-        rContent += 'banner_img_text: "' + $('#ccoverimgtxt').val() + '"\n';
-        rContent += 'homeowner: "' + $('#chomeowner').val() + '"\n';
-        rContent += 'size: "' + $('#csize').val() + '"\n';
-        rContent += 'bed_num: "' + $('#cbednum').val() + '"\n';
-        rContent += 'house_cat: "' + $('#chousetype').val() + '"\n';
-        rContent += 'designer: "' + $('#cdesigner').val() + '"\n';
-        rContent += 'space: "' + $('#cspace').val() + '"\n';
-        rContent += 'loc: "' + $('#cloc').val() + '"\n';
-        rContent += 'budget: "' + $('#cbudget').val() + '"\n';
-        rContent += 'construction: "' + $('#cconstruction').val() + '"\n';
-        rContent += 'collection_description: "' + $('#ccolldesc').val() + '"\n';
-        rContent += 'collection_slider: "' + '[' + $('#ccollslider').val() + ']' + '"\n';
-        if($('#cnewcomment').val()!="" && $('#cnewcomment').val()!=undefined)
-        {
-            rContent += 'comment: "' + $('#cnewcomment').val() + '"\n';
-        }
-        else
-        {
-            rContent += 'comment: "' + $('#ccomment').val() + '"\n';
-        }
-=======
 function GetMdHeader(result = []) {
   rContent = "";
   rContent += "---\n";
@@ -730,11 +532,25 @@ function GetMdHeader(result = []) {
   rContent += 'type: "' + $("#ctype").val() + '"\n';
   rContent += 'url: "' + $("#curl").val() + '"\n';
   //mdContent += 'url: "' + $('#curl').val() + '"\n';
-  rContent += 'image: "' + $("#cimage").val() + '"\n';
+
+  if ($("#cfile").val() != "" && $("#cfile").val() != undefined) {
+    rContent += 'image: "' + $("#cfile").val() + '"\n';
+  } else {
+    rContent += 'image: "' + $("#cimage").val() + '"\n';
+  }
 
   if ($("#ctype").val() == "collection") {
+
+    if($('#cnewcoverimg').val()!="" && $('#cnewcoverimg').val()!=undefined)
+    {
+        rContent += 'cover_img: "' + $('#cnewcoverimg').val()+ '"\n';
+    }
+    else
+    {
+        rContent += 'cover_img: "' + $('#ccoverimg').val() + '"\n';
+    }
+
     rContent += 'collection_name: "' + $("#ccollname").val() + '"\n';
-    rContent += 'cover_img: "' + $("#ccoverimg").val() + '"\n';
     rContent +=
       'description: "' +
       $("#cdescription").val().replace(/\r?\n/g, "<br>") +
@@ -743,7 +559,6 @@ function GetMdHeader(result = []) {
     tags = [];
     for (var toi of tagOptionIds) {
       if ($("#" + toi).val() != "") tags.push($("#" + toi).val());
->>>>>>> Stashed changes
     }
     rContent += "tags: [" + tags.join(",") + "]\n";
     //rContent += 'tags: "' + ($('#ctags').val() == 'undefined' ? "" : $('#ctags').val()) + '"\n';
@@ -761,7 +576,11 @@ function GetMdHeader(result = []) {
     rContent += 'collection_description: "' + $("#ccolldesc").val() + '"\n';
     // rContent += 'collection_slider: "' + $('#ccollslider').val() + '"\n';
     // rContent += 'collection_slider: []\n';
-    rContent += 'comment: "' + $("#ccomment").val() + '"\n';
+    if ($("#cnewcomment").val() != "" && $("#cnewcomment").val() != undefined) {
+      rContent += 'comment: "' + $("#cnewcomment").val() + '"\n';
+    } else {
+      rContent += 'comment: "' + $("#ccomment").val() + '"\n';
+    }
 
     if (result.length !== 0 && result.blocks) {
       let collection_slider_img = [];

+ 0 - 3
backstage/templates/collections.html

@@ -229,10 +229,7 @@
                 <h4>類型</h4>
               </td>
               <td><select id="chousetype">
-<<<<<<< Updated upstream
-=======
                   <option value="">類型</option>
->>>>>>> Stashed changes
                   <option value="大樓">大樓</option>
                   <option value="透天">透天</option>
                 </select></td>