Ver Fonte

toggle display news in homepage, but pls fix

jason há 2 anos atrás
pai
commit
0a4f18cd67

+ 2 - 0
backstage/blogs/routes.py

@@ -351,12 +351,14 @@ meta_description: "{}"\n
 title: "{}"\n\
 date: {}\n\
 draft: {}\n\
+display: {}\n\
 type: "{}"\n\
 url: "{}"\n\
 image: ""\n\
 ---'''.format(form.title.data, '', form.title.data,
               get_now_time(),
               'true',
+              'false',
               'news',
               '/news/{}'.format(transtitle))
 

+ 25 - 0
backstage/static/js/yo.js

@@ -94,6 +94,21 @@ function toggleDraft(obj, url) {
   });
 }
 
+function toggleDisplay(obj, url) {
+  axios.get(contentApiUrl + url).then(({ data }) => {
+    frontMatters = [];
+    contentMatters = [];
+    aa = data[0]["content"];
+    const content = _.get(data, "0.content", "");
+    blocks = parseMd(aa);
+    editTarget = url;
+    $("#cdisplay").removeAttr("checked");
+    $("#cdisplay").prop("checked", obj.checked);
+    updateHeader();
+    oTitle = "";
+  });
+}
+
 function updateHeader() {
   /* if (oTitle != $('#ctitle').val() && $('#ctitle').val() != "" && oTitle != "") {
       axios.get('/backstage/modTitle/' + oTitle + '/' + $('#ctitle').val()).then(({ data }) => {
@@ -326,6 +341,11 @@ function parseMd(content) {
         $("#cdraft").removeAttr("checked");
         if ($("#cdraft").val() == "false") $("#cdraft").prop("checked", true);
       }
+      if (line.includes("display: ")) {
+        $("#cdisplay").val(line.replace("display: ", "").replaceAll('"', ""));
+        $("#cdisplay").removeAttr("checked");
+        if ($("#cdisplay").val() == "true") $("#cdisplay").prop("checked", true);
+      }
       if (line.includes("type: ")) {
         $("#ctype").val(line.replace("type: ", "").replaceAll('"', ""));
       }
@@ -616,6 +636,11 @@ function GetMdHeader(result = []) {
   rContent += 'title: "' + $("#ctitle").val() + '"\n';
   rContent += "date: " + $("#cdate").val() + "\n";
   rContent += "draft: " + !$("#cdraft").is(":checked") + "\n";
+
+  if ($("#ctype").val() == "news") {
+    rContent += 'display: ' + !$("#cdisplay").is(":checked") + '\n';
+  }
+
   rContent += 'type: "' + $("#ctype").val() + '"\n';
   rContent += 'url: "' + $("#curl").val() + '"\n';
   //mdContent += 'url: "' + $('#curl').val() + '"\n';

+ 1 - 0
backstage/templates/editor.html

@@ -31,6 +31,7 @@
       <div class="d-none">
         <input id="cdate" type="text" /><br />
         <input id="cdraft" type="text" /><br />
+        <input id="cdisplay" type="text" /><br />
         <input id="ctype" type="text" /><br />
         <input id="curl" type="text" /><br />
         <input id="cimage" type="text" /><br />

+ 10 - 1
backstage/templates/news.html

@@ -1,4 +1,4 @@
-{% extends "tables/editor_table.html" %}
+{% extends "tables/editor_table_news.html" %}
 {% block table_body %}
 <script src="https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest"></script>
 <script src="https://cdn.jsdelivr.net/npm/@editorjs/image@latest"></script><!-- Image -->
@@ -12,6 +12,9 @@
     <td class="table__data">{{ news[idx].date }}</td>
     <td class="table__data"><input type="checkbox" {{ 'checked' if (news[idx].draft.lower()=='false' ) }}
         onclick="toggleDraft(this,'{{ news[idx].url }}');" /></td>
+    <td>
+      <td class="table__data"><input type="checkbox" {{ 'checked' if (news[idx].display.lower()=='true' ) }}
+        onclick="toggleDisplay(this,'{{ news[idx].url }}');" /></td>
     <td>
       <div class="d-flex justify-content-center">
         <button class="btn btn_light mr-1" onclick="getHeader('{{ news[idx].url }}');"><b>主資訊</b> <i
@@ -107,6 +110,12 @@
               </td>
               <td><input id="cdraft" type="checkbox" checked="true" /></td>
             </tr>
+            <tr>
+              <td>
+                <h4>是否首頁顯示</h4>
+              </td>
+              <td><input id="cdisplay" type="checkbox" checked="true" /></td>
+            </tr>
           </tbody>
         </table>
         <div class="d-none">

+ 152 - 0
backstage/templates/tables/editor_table_news.html

@@ -0,0 +1,152 @@
+{% extends "layout.html" %}
+{% block main %}
+<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
+<link rel="stylesheet" href="https://jqueryui.com/resources/demos/style.css">
+<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
+<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
+<script type="text/javascript" src="{{url_for('static', filename='config.js')}}"></script>
+<h1 class="h3"><i class="far fa-newspaper mr-3"></i>{{ title }}</h1>
+<table id="example" class="table" cellspacing="0" width="60%">
+  <thead>
+    <tr>
+      <th class="table__head">#</th>
+      <th class="table__head">標題</th>
+      <th class="table__head">日期</th>
+      <!-- <th class="table__head">順序</th> -->
+      <th class="table__head">顯示</th>
+      <th class="table__head">首頁顯示</th>
+      <th style="width:150px;" class="table__head">
+        <button type="button" class="btn__add m-1" data-toggle="modal" data-target="#createModal"><i
+            class="fas fa-plus"></i></button>
+      </th>
+    </tr>
+  </thead>
+  {% block table_body %}{% endblock %}
+</table>
+
+
+{% block main_info_modal_body %}{% endblock %}
+<!-- <div class="modal fade" id="myModal">
+  <div class="modal-dialog">
+    <div class="modal-content">
+
+      <div class="modal-header">
+        <h4 class="modal-title">主資訊修改</h4>
+        <button type="button" class="close" data-dismiss="modal">×</button>
+      </div>
+
+      <div class="modal-body">
+        <table class="table table-bordered">
+          <tbody>
+            <tr>
+              <td>
+                <h4>標題</h4>
+              </td>
+              <td><input class="form-control" id="ctitle" type="text" />
+                <div class="mt-1 text-danger">(建議字數:15 字內)</div>
+              </td>
+            </tr>
+            <tr>
+              <td>
+                <h4>圖片</h4>
+              </td>
+              <td>
+                <input class="form-control" id="cfile" type="file" />
+                <div class="mt-1 text-danger">(建議尺寸/比例:寬 2048px * 高 1365px)</div>
+              </td>
+            </tr>
+            <tr id='sdesc'>
+              <td>
+                <h4>描述</h4>
+              </td>
+              <td><textarea class="form-control" rows="3" id="cdescription"></textarea>
+                <div class="mt-1 text-danger">(建議字數:50 字內)</div>
+              </td>
+            </tr>
+            <tr>
+              <tr id='scat'>
+                <td>
+                  <h4>文章分類</h4>
+                </td>
+                <td><textarea class="form-control" rows="1" id="ccategories"></textarea>
+                  <div class="mt-1 text-danger">(建議字數:15 字內)</div>
+                </td>
+              </tr>
+              <tr>
+              <td>
+                <h4>日期</h4>
+              </td>
+              <td><input class="form-control" id="cdate" type="text" /></td>
+            </tr>
+            <tr>
+              <td>
+                <h4>是否顯示</h4>
+              </td>
+              <td><input id="cdraft" type="checkbox" checked="true" /></td>
+            </tr>
+          </tbody>
+        </table>
+        <div class="d-none">
+          <input id="ctype" type="text" /><br />
+          <input id="curl" type="text" /><br />
+          <input id="cimage" type="text" /><br />
+          <input id="cweight" type="text" /><br />
+          <input id="ctag" type="text" /><br />
+          <input id="ccategories" type="text" /><br />
+          <input id="ccol1" type="text" /><br />
+          <input id="ccol2" type="text" /><br />
+        </div>
+      </div>
+
+      <div class="modal-footer">
+        <button type="button" id="uptbtn" class="btn btn-danger" onclick="updateHeader();">完成修改</button>
+      </div>
+
+    </div>
+  </div>
+</div> -->
+
+<!-- <div id="dialog-form">
+  <input id="ctitle" type="text" /><br />
+  <input id="cdate" type="text" /><br />
+  <input id="cdraft" type="checkbox" checked="true" /><br />
+  <input id="ctype" type="text" /><br />
+  <input id="curl" type="text" /><br />
+  <input id="cimage" type="text" /><br />
+  <input id="cdescription" type="text" /><br />
+  <input id="cweight" type="text" /><br />
+  <input id="ctag" type="text" /><br />
+  <button onclick="updateHeader();location.reload();">完成修改</button>
+</div> -->
+<script>
+  oTitle = "";
+  editTarget = "";
+  frontMatters = [];
+  contentMatters = [];
+  //const contentApiUrl = `${PORTAL_SERVER}contents?url=`;
+
+  //allObjs = JSON.parse(htmlDecode('{{ collections }}'));
+  //console.log(htmlDecode('{{ collections }}'));
+
+</script>
+
+<!-- Modal -->
+<div class="modal fade" id="createModal" tabindex="-1" role="dialog" aria-labelledby="createModalLabel"
+  aria-hidden="true">
+  <div class="modal-dialog" role="document">
+    <div class="modal-content">
+      <div class="modal-header border-0">
+        <h5 class="modal-title modal__title" id="createModalLabel">新增</h5>
+        <button type="button" class="close modal__close" data-dismiss="modal" aria-label="Close">
+          <span class="modal__close__back">
+            <span aria-hidden="true">&times;</span>
+          </span>
+        </button>
+      </div>
+      <div class="modal-body">
+        {% block modal_body %}{% endblock %}
+      </div>
+    </div>
+  </div>
+</div>
+{% endblock main %}

+ 4 - 0
models/contents/routes.py

@@ -36,6 +36,10 @@ def _get_data(file_dir):
             # data_field.remove('draft: ')
             s = line.replace('draft: ', '').strip()
             result['draft'] = s
+        elif 'display: ' in line:
+            # data_field.remove('draft: ')
+            s = line.replace('display: ', '').strip()
+            result['display'] = s
         elif 'url: ' in line:
             data_field.remove('url:')
             s = line.split('"')