Ver Fonte

211005 系統櫃後台功能v1

yukyo0821 há 3 anos atrás
pai
commit
227127cfe6

+ 47 - 60
backstage/blogs/routes.py

@@ -1,4 +1,5 @@
 from flask import flash, render_template, Blueprint, request, redirect, url_for
+from flask.app import Flask
 from flask.wrappers import Response
 import requests
 import os
@@ -11,7 +12,6 @@ from backstage.utils import get_now_time, translate
 from backstage.utils.routes import create_content, remove_content, get_trans_title_url_name
 from backstage.config import PORTAL_SERVER, UPLOAD_PATH_MAP
 
-
 blogs_app = Blueprint('blogs', __name__)
 
 SwfType = {
@@ -20,22 +20,34 @@ SwfType = {
     "living_room": "客廳",
     "study_room": "書房",
     "dining_room": "餐廳",
+    "custom_made_system_cabinet": "客製模組系統櫃",
+    "system_cabinet": "模組系統櫃單品",
+}
+SfType = {
+    "custom_made_system_cabinet": "客製模組系統櫃",
+    "system_cabinet": "模組系統櫃單品",
 }
 
 furniturePath = UPLOAD_PATH_MAP[0][0] + '../設計家具'
+sfurniturePath = UPLOAD_PATH_MAP[0][0] + '../模組系統櫃'
 furnitureTypes = []
 furnitureTypeFiles = []
 furnitureFiles = []
 furnitures = []
 
 
-def refreshFur():
+def refreshFur(itype):
+    scanpath = ""
     furnitureTypes.clear()
     furnitureTypeFiles.clear()
     furnitureFiles.clear()
     furnitures.clear()
+    if itype == '單品家具':
+        scanpath = furniturePath
+    else:
+        scanpath = sfurniturePath
 
-    for dirname, dirnames, filenames in os.walk(furniturePath):
+    for dirname, dirnames, filenames in os.walk(scanpath):
         # print path to all subdirectories first.
         for subdirname in dirnames:
             if subdirname.find('.') == -1:
@@ -80,7 +92,16 @@ def refreshFur():
 
 
 def newFur(irequest):
-
+    print(irequest.url)
+    myType = {}
+    myPath = ""
+    print(str(irequest.url).find("system_furniture"))
+    if str(irequest.url).find("system_furniture") >= 0:
+        myType = SfType
+        myPath = sfurniturePath
+    else:
+        myType = SwfType
+        myPath = furniturePath
     ename = get_trans_title_url_name(irequest.args['newSwfName'])
     front_matter = '''---
 title: "{}"
@@ -91,8 +112,8 @@ url: "/{}/{}"
 image: ""
 ---'''.format(irequest.args['newSwfName'], get_now_time(), irequest.args['newSwfDropdown'], irequest.args['newSwfDropdown'], ename)
 
-    newPath = furniturePath + '/' + \
-        SwfType[irequest.args['newSwfDropdown']] + '/' + ename
+    newPath = myPath + '/' + \
+        myType[irequest.args['newSwfDropdown']] + '/' + ename
     if not os.path.exists(newPath):
         os.mkdir(newPath)
     with open(os.path.join(newPath, 'index.md'), 'w', encoding="utf-8") as md:
@@ -108,7 +129,7 @@ def blog_list():
     response = requests.get('{}contents?url=/blog'.format(PORTAL_SERVER))
     if response.status_code == 200:
         sortedData = sorted(response.json(), key=lambda x: x['date'], reverse=True)
-        #print(sortedData)
+        # print(sortedData)
         return render_template('blogs.html',
                                title='設計專欄',
                                legend='設計專欄列表',
@@ -123,6 +144,12 @@ def new_solid_wood_furniture():
     return newFur(request)
 
 
+@blogs_app.route('/backstage/new_system_furniture', methods=['GET'])
+def new_system_furniture():
+    # edit_solid_wood_furniture()
+    return newFur(request)
+
+
 @blogs_app.route('/backstage/del_solid_wood_furniture', methods=['GET'])
 def del_solid_wood_furniture():
     url = request.args.get('url', type=str)
@@ -137,59 +164,7 @@ def del_solid_wood_furniture():
 
 @blogs_app.route('/backstage/edit_solid_wood_furniture', methods=['GET'])
 def edit_solid_wood_furniture():
-    refreshFur()
-    """ furniturePath = UPLOAD_PATH_MAP[0][0] + '../設計家具'
-    furnitureTypes = []
-    furnitureTypeFiles = []
-    furnitureFiles = []
-    furnitures = []
-    for dirname, dirnames, filenames in os.walk(furniturePath):
-        # print path to all subdirectories first.
-        for subdirname in dirnames:
-            if subdirname.find('.') == -1:
-                furnitureTypes.append(subdirname)
-
-        # print path to all filenames.
-        for filename in filenames:
-            if filename.find('_index.md') >= 0:
-                furnitureTypeFiles.append(os.path.join(dirname, filename))
-            if filename.find('index.md') >= 0:
-                furnitureFiles.append(os.path.join(dirname, filename))
-
-    headerStart = False
-    for files in furnitureFiles:
-        tmpfurniture = {}
-        with open(files, 'r', encoding="utf-8") as md:
-            md_line_data = md.readlines()
-            # print(md_line_data)
-        for line in md_line_data:
-            # print(line)
-            if '---' in line:
-                headerStart = not headerStart
-                continue
-            if headerStart:
-                if 'title:' in line:
-                    tmpfurniture['title'] = re.split('"|\n', line)[1]
-                if 'date:' in line:
-                    tmpfurniture['date'] = re.split(':"|\n', line)[0].removeprefix('date: ')
-                if 'draft:' in line:
-                    tmpfurniture['draft'] = re.split(':"|\n', line)[0].removeprefix('draft: ')
-                if 'type:' in line:
-                    tmpfurniture['type'] = re.split('"|\n', line)[1]
-                if 'url:' in line:
-                    tmpfurniture['url'] = re.split('"|\n', line)[1]
-                if 'image:' in line:
-                    tmpfurniture['image'] = re.split('"|\n', line)[1]
-                if 'tags:' in line:
-                    tmpfurniture['tags'] = re.split('"|\n', line)[1]
-        #避免加入類別項目
-        if tmpfurniture['type'] != tmpfurniture['url'].removeprefix('/'):
-            furnitures.append(tmpfurniture) """
-
-    #sortedData = sorted(furnitures, key=lambda x: x['date'], reverse=True)
-    # print(furnitures)
-    """ response = requests.get('{}contents?url=/blog'.format(PORTAL_SERVER))
-    if response.status_code == 200: """
+    refreshFur('單品家具')
     sortedData = sorted(furnitures, key=lambda x: x['date'], reverse=True)
     sortedData = sorted(sortedData, key=lambda x: x['type'])
     return render_template('solid_wood_furniture.html',
@@ -199,6 +174,18 @@ def edit_solid_wood_furniture():
                            )
 
 
+@blogs_app.route('/backstage/edit_system_furniture', methods=['GET'])
+def edit_system_furniture():
+    refreshFur('模組系統櫃')
+    sortedData = sorted(furnitures, key=lambda x: x['date'], reverse=True)
+    sortedData = sorted(sortedData, key=lambda x: x['type'])
+    return render_template('system_furniture.html',
+                           title='模組系統櫃',
+                           legend='模組系統櫃',
+                           furnitures=sortedData, length=len(furnitures),
+                           )
+
+
 @blogs_app.route('/backstage/blog/create/', methods=['POST'])
 def create():
     transcat = ""

+ 29 - 20
backstage/static/js/yo.js

@@ -1,10 +1,20 @@
-SwfType = {
-    "other_furniture": "其他",
-    "master_bedroom": "臥室",
-    "living_room": "客廳",
-    "study_room": "書房",
-    "dining_room": "餐廳",
-};
+
+var SwfType = {};
+if (location.pathname.indexOf('system_furniture') >= 0) {
+    SwfType = {
+        "custom_made_system_cabinet": "客製模組系統櫃",
+        "system_cabinet": "模組系統櫃單品",
+    };
+}
+else {
+    SwfType = {
+        "other_furniture": "其他",
+        "master_bedroom": "臥室",
+        "living_room": "客廳",
+        "study_room": "書房",
+        "dining_room": "餐廳",
+    };
+}
 
 //document.ready
 $(function () {
@@ -361,7 +371,6 @@ function GenSwfDD(obj) {
         op.text = value;
         obj.appendChild(op);
     });
-
 }
 
 function ReplaceSwfType(inContent) {
@@ -406,18 +415,18 @@ function ParseProductSection(inContent) {
             }
         }
     }
-/*     else {
-        editorBlocks.push({
-            type: "image", data: {
-                file: {
-                    url: 'https://bhouse.com.tw/img/logo2.png',
-                    width: 300,
-                    height: 300,
-                },
-                caption: "小寶優居 | " + $('#ctitle').val(),
-            }
-        });
-    } */
+    /*     else {
+            editorBlocks.push({
+                type: "image", data: {
+                    file: {
+                        url: 'https://bhouse.com.tw/img/logo2.png',
+                        width: 300,
+                        height: 300,
+                    },
+                    caption: "小寶優居 | " + $('#ctitle').val(),
+                }
+            });
+        } */
     //editor.api.blocks.render(editorBlocks);
     $('#editorjs')[0].innerHTML = "";
     //alert(editorBlocks);

+ 6 - 0
backstage/templates/layout.html

@@ -92,6 +92,12 @@
               <span class="menu-collapsed">單品家具</span>    
             </div>
           </a>
+          <a href="{{ url_for('blogs.edit_system_furniture') }}" class="bg-dark list-group-item list-group-item-action">
+            <div class="d-flex w-100 justify-content-start align-items-center">
+              <i class="far fa-newspaper mr-3"></i>
+              <span class="menu-collapsed">模組系統櫃</span>    
+            </div>
+          </a>
           <!-- Separator with title -->
           <a href="#" data-toggle="sidebar-colapse" class="bg-dark list-group-item list-group-item-action d-flex align-items-center">
             <div class="d-flex w-100 justify-content-start align-items-center">

+ 1 - 2
backstage/templates/solid_wood_furniture.html

@@ -200,8 +200,7 @@
                 sectionContent = GenProductSection(mimg, specimg);
 
                 var mdContent = GetMdHeader();
-                mdContent = mdContent.replace('draft: ' + (!$('#cdraft').is(':checked')), 'draft: ' + $('#cdraft').val())
-
+                
                 mdContent += '\n' + sectionContent;
                 //GenProductSection(outputData);
                 postData = {

+ 223 - 4
backstage/templates/system_furniture.html

@@ -1,4 +1,223 @@
-{% extends "layout.html" %}
-{% block main %}
-    <h1>system_furniture</h1>
-{% endblock main %}
+{% extends "tables/editor_table.html" %}
+{% block table_body %}
+<!-- <script type="text/javascript" src="/static/config.js"></script> -->
+<script src="https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest"></script>
+<script src="https://cdn.jsdelivr.net/npm/@editorjs/image@latest"></script><!-- Image -->
+<script type="text/javascript" src="/static/js/yo.js"></script>
+<tbody id='swfData'>
+    {% for idx in range(0, length) %}
+    <tr>
+        <td class="table__data">{{ idx + 1 }}</td>
+        <td class="table__data">{{ '[' + furnitures[idx].type + '] ' + furnitures[idx].title }}</td>
+        <td class="table__data">{{ furnitures[idx].date }}</td>
+        <!-- <td class="table__data">1</td> -->
+        <td class="table__data"><input type="checkbox" {{ 'checked' if (furnitures[idx].draft.lower()=='false' ) }}
+                onclick="toggleDraft(this,'{{ furnitures[idx].url }}');" /></td>
+        <td>
+            <div class="d-flex justify-content-center">
+                <button class="btn btn_light mr-1" onclick="getHeader('{{ furnitures[idx].url }}');"><b>修改</b> <i
+                        class="fas fa-pencil-alt"></i></button>
+                <button class="btn__delete" value="delete"
+                    onclick="if(confirm('確定要刪除?')) delfur('{{ furnitures[idx].url }}');"><i
+                        class="fas fa-trash-alt"></i></button>
+            </div>
+
+        </td>
+    </tr>
+    {% endfor %}
+</tbody>
+<script>$('#swfData')[0].innerHTML = ReplaceSwfType($('#swfData')[0].innerHTML);</script>
+{% endblock table_body %}
+
+
+{% block modal_body %}
+
+<div class="form-group">
+    類別:<select id="newSwfDropdown"></select><br />
+    名稱:<input id="newSwfName" type="text" /><br />
+    <!--     敘述:<input id="swfDesc" type="text" /><br />
+    <hr>
+    圖片:
+    <div id="editorjs" style='border:inset 1px;'></div>
+    <hr>
+    定價:<input id="swfPrice" type="text" /><br />
+    顏色:<input id="swfColor" type="text" /><br />
+    尺寸:<input id="swfSize" type="text" /><br />
+    材質:<input id="swfMet" type="text" /><br /> -->
+</div>
+<div class="modal-footer  pb-0 border-0">
+    <button type="button" class="btn btn__cancel" data-dismiss="modal">取消</button>
+    <button type="button" class="btn btn__submitadd" onclick="newfur();">完成</button>
+</div>
+<script>GenSwfDD($('#newSwfDropdown')[0]);</script>
+<script>
+    function newfur() {
+        //alert('/backstage/new_system_furniture?newSwfDropdown='+ $('#newSwfDropdown').val() +'&newSwfName='+$('#newSwfName').val());
+        axios.get('/backstage/new_system_furniture?newSwfDropdown=' + $('#newSwfDropdown').val() + '&newSwfName=' + $('#newSwfName').val()).then((data) => { location.reload() });
+    }
+    function delfur(iurl) {
+        //alert('/backstage/new_system_furniture?newSwfDropdown='+ $('#newSwfDropdown').val() +'&newSwfName='+$('#newSwfName').val());
+        axios.get('/backstage/del_system_furniture?url=' + iurl).then((data) => { location.reload() });
+    }
+</script>
+{% endblock modal_body %}
+
+{% block main_info_modal_body %}
+<style>
+    .image-tool__caption {
+        display: none;
+    }
+</style>
+<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><select id="swfDropdown" onchange="$('#ctype').val(this.value);" disabled></select></td>
+                        </tr>
+                        <tr>
+                            <td>
+                                <h4>敘述</h4>
+                            </td>
+                            <td>
+                                <textarea class="form-control" rows="3" id="swfDesc" type="text" style="width: 100%;"></textarea>
+                                <div class="mt-1 text-danger">(建議字數: 50字內)</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>
+                        <tr>
+                            <td colspan="2"> </td>
+                        </tr>
+                        <tr>
+                            <td>
+                                <h4>單品圖</h4>
+                            </td>
+                            <td>
+                                <div class="form-control" id="editorjs" style='border:inset 1px;'></div>
+                            </td>
+                        </tr>
+                        <tr>
+                            <td>
+                                <h4>定價</h4>
+                            </td>
+                            <td><input class="form-control" id="swfPrice" type="text" style="width: 100%;" /></td>
+                        </tr>
+                        <tr>
+                            <td>
+                                <h4>顏色</h4>
+                            </td>
+                            <td><input class="form-control" id="swfColor" type="text" style="width: 100%;" /></td>
+                        </tr>
+                        <tr>
+                            <td>
+                                <h4>尺寸(mm)</h4>
+                            </td>
+                            <td><input class="form-control" id="swfSize" type="text" style="width: 100%;" /></td>
+                        </tr>
+                        <tr>
+                            <td>
+                                <h4>材質</h4>
+                            </td>
+                            <td><input class="form-control" id="swfMat" type="text" style="width: 100%;" /></td>
+                        </tr>
+                        <tr>
+                            <td>
+                                <h4>備註</h4>
+                            </td>
+                            <td><input class="form-control" id="swfMemo" type="text" style="width: 100%;" /></td>
+                        </tr>
+                        <tr>
+                            <td>
+                                <h4>規格圖</h4>
+                            </td>
+                            <td>
+                                <div class="form-control" id="editorjs1" style='border:inset 1px;'></div>
+                            </td>
+                        </tr>
+                    </tbody>
+                </table>
+                <div class="d-none">
+                    <input class="form-control" id="cfile" type="file" />
+                    <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" class="btn btn__cancel" data-dismiss="modal">取消</button>
+                <button type="button" class="btn btn__submitadd" id='addNewButton'
+                    onclick="UpdateProduct();">完成</button>
+                <!-- <button type="button" id="uptbtn" class="btn btn-danger" onclick="updateHeader();">完成修改</button> -->
+            </div>
+
+        </div>
+    </div>
+</div>
+<script>GenSwfDD($('#swfDropdown')[0]);</script>
+<script>
+
+    function UpdateProduct() {
+        editor.save().then((mimg) => {
+            sectionContent = "";
+            editor1.save().then((specimg) => {
+                sectionContent = GenProductSection(mimg, specimg);
+
+                var mdContent = GetMdHeader();
+                
+                mdContent += '\n' + sectionContent;
+                //GenProductSection(outputData);
+                postData = {
+                    content: mdContent,
+                    url: editTarget
+                };
+
+                /* alert(contentApiUrl);
+                alert(editTarget); */
+                //alert(mdContent);
+                axios.post(contentApiUrl + editTarget, json = postData).then(({ data }) => {
+                    alert('作品資料已儲存');
+                }).finally((data) => { location.reload(); });
+            });
+        }).catch((error) => {
+            console.log('Saving failed: ', error)
+        })
+    };
+</script>
+{% endblock %}