Browse Source

토론 전체 로드 방식을 JS로 변경

Surplus_Up (2DU) 6 years ago
parent
commit
1d0d2e033c

+ 2 - 1
language/en-US.json

@@ -87,6 +87,7 @@
         "start" : "Start",
         "pass" : "Passing",
         "file_name" : "File name",
+        "pinned" : "Pinned",
         "_comment_1.1_" : "Time",
             "second" : "Second(s)",
             "hour" : "Hour(s)",
@@ -124,7 +125,7 @@
         "authorize" : "Authorize",
         "indexing" : "DB Indexing",
         "hide_release" : "Unhide",
-        "notice_release" : "Release notice",
+        "pinned_release" : "Unpinned",
         "ban_release" : "Unblock",
         "discussion_tool" : "Discussion tools",
         "discussion_raw" : "Discussion[s] raw",

+ 5 - 4
language/ko-KR.json

@@ -53,7 +53,7 @@
     "file" : "파일",
     "writer" : "작성자",
     "editor" : "에디터",
-    "hide" : "숨",
+    "hide" : "숨기기",
     "check" : "검사",
     "destruction" : "취소",
     "tool" : "도구",
@@ -118,8 +118,8 @@
     "compare_target" : "비교 대상 이름",
     "authorize" : "권한 부여",
     "indexing" : "DB 인덱싱",
-    "hide_release" : "표시",
-    "notice_release" : "릴리즈 노트",
+    "hide_release" : "숨김 해제",
+    "pinned_release" : "고정 해제",
     "ban_release" : "차단 해제",
     "discussion_tool" : "토론 도구",
     "discussion_raw" : "토론 원본",
@@ -290,5 +290,6 @@
     "user_tool" : "사용자 도구",
     "error_401" : "ACL 보기 제한 문서 문구",
     "error_404" : "없는 문서 문구",
-    "skin_info" : "스킨 정보"
+    "skin_info" : "스킨 정보",
+    "pinned" : "고정"
 }

+ 67 - 19
route/api_topic_sub.py

@@ -4,31 +4,79 @@ def api_topic_sub_2(conn, name, sub, time):
     curs = conn.cursor()
 
     if flask.request.args.get('num', None):
-        if flask.request.args.get('over', '0') == '0':
-            curs.execute("select id, data, date, ip from topic where title = ? and sub = ? and id + 0 = ? + 0 order by id + 0 asc", [name, sub, flask.request.args.get('num', '')])
-        elif flask.request.args.get('over', '0') == '1':
-            curs.execute("select id, data, date, ip from topic where title = ? and sub = ? and id + 0 >= ? + 0 order by id + 0 asc", [name, sub, flask.request.args.get('num', '')])
-        else:
-            curs.execute("select id, data, date, ip from topic where title = ? and sub = ? and id + 0 <= ? + 0 order by id + 0 asc", [name, sub, flask.request.args.get('num', '')])
-    elif flask.request.args.get('time', None):
-        if flask.request.args.get('over', '0') == '0':
-            curs.execute("select id, data, date, ip from topic where title = ? and sub = ? and date = ? order by id + 0 asc", [name, sub, flask.request.args.get('time', '')])
-        if flask.request.args.get('over', '0') == '1':
-            curs.execute("select id, data, date, ip from topic where title = ? and sub = ? and date >= ? order by id + 0 asc", [name, sub, flask.request.args.get('time', '')])
-        else:
-            curs.execute("select id, data, date, ip from topic where title = ? and sub = ? and date <= ? order by id + 0 asc", [name, sub, flask.request.args.get('time', '')])
+        curs.execute("select id, data, date, ip, block, top from topic where title = ? and sub = ? and id + 0 = ? + 0 order by id + 0 asc", [
+            name, 
+            sub, 
+            flask.request.args.get('num', '')
+        ])
+    elif flask.request.args.get('top', None):
+        curs.execute("select id, data, date, ip, block, top from topic where title = ? and sub = ? and top = 'O' order by id + 0 asc", [name, sub])
     else:
-        curs.execute("select id, data, date, ip from topic where title = ? and sub = ? order by id + 0 asc", [name, sub])
+        curs.execute("select id, data, date, ip, block, top from topic where title = ? and sub = ? order by id + 0 asc", [name, sub])
 
     data = curs.fetchall()
     if data:
         json_data = {}
+        admin = admin_check(3)
+                    
         for i in data:
-            json_data[i[0]] =   {
-                "data" : i[1],
-                "date" : i[2],
-                "id" : i[3]
-            }
+            if i[4] != 'O' or (i[4] == 'O' and admin == 1):
+                t_data_f = i[1]
+                b_color = ''
+            else:
+                curs.execute("select who from re_admin where what = ? order by time desc limit 1", ['blind (' + name + ' - ' + sub + '#' + str(i[0]) + ')'])
+                who_blind = curs.fetchall()
+                if who_blind:
+                    t_data_f = '[[user:' + who_blind[0][0] + ']] block'
+                    b_color = 'toron_color_grey'
+                else:
+                    t_data_f = 'block'
+                    b_color = 'toron_color_grey'
+
+            if flask.request.args.get('render', None):
+                if i[0] == '1':
+                    s_user = i[3]
+                    
+                if flask.request.args.get('top', None):
+                    t_color = 'toron_color_red'
+                elif i[3] == s_user:
+                    t_color = 'toron_color_green'
+                elif i[5] == '1':
+                    t_color = 'toron_color_blue'
+                else:
+                    t_color = 'toron_color'
+                    
+                ip = ip_pas(i[3])
+                
+                curs.execute('select acl from user where id = ?', [i[3]])
+                u_acl = curs.fetchall()
+                if u_acl and u_acl[0][0] != 'user':
+                    ip += ' <a href="javascript:void(0);" title="' + load_lang('admin') + '">★</a>'
+
+                if admin == 1 or b_color != 'toron_color_grey':
+                    ip += ' <a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/admin/' + i[0] + '">(' + load_lang('discussion_tool') + ')</a>'
+
+                curs.execute("select end from ban where block = ?", [i[3]])
+                if curs.fetchall():
+                    ip += ' <a href="javascript:void(0);" title="' + load_lang('blocked') + '">†</a>'
+                    
+                if t_data_f == '':
+                    t_data_f = '[br]'
+            
+                all_data = '<table id="toron"><tbody><tr><td id="' + t_color + '">'
+                all_data += '<a href="#' + i[0] + '">#' + i[0] + '</a> ' + ip + ' <span style="float: right;">' + i[2] + '</span>'
+                all_data += '</td></tr><tr><td id="' + b_color + '">' + render_set(data = t_data_f) + '</td></tr></tbody></table><hr class=\"main_hr\">'
+                
+                json_data[i[0]] = {
+                    "data" : all_data
+                }
+            else:
+                json_data[i[0]] = {
+                    "data" : t_data_f,
+                    "date" : i[2],
+                    "ip" : i[3],
+                    "block" : i[4],
+                }
 
         return flask.jsonify(json_data)
     else:

+ 11 - 105
route/topic.py

@@ -76,116 +76,22 @@ def topic_2(conn, name, sub):
         
         return redirect('/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '#reload')
     else:
-        curs.execute("select title from rd where title = ? and sub = ? and stop = 'O'", [name, sub])
-        close_data = curs.fetchall()
-        
-        curs.execute("select title from rd where title = ? and sub = ? and stop = 'S'", [name, sub])
-        stop_data = curs.fetchall()
-        
-        display = ''
-        all_data = ''
         data = ''
-        number = 1
+    
+        curs.execute("select title from rd where title = ? and sub = ? and (stop = 'O' or stop = 'S')", [name, sub])
+        close_data = curs.fetchall()
         
-        if (close_data or stop_data) and admin != 1:
+        if close_data and admin != 1:
             display = 'display: none;'
-        
-        curs.execute("select data, id, date, ip, block, top from topic where title = ? and sub = ? order by id + 0 asc", [name, sub])
-        topic = curs.fetchall()
-        
-        curs.execute("select data, id, date, ip from topic where title = ? and sub = ? and top = 'O' order by id + 0 asc", [name, sub])
-        for topic_data in curs.fetchall():                   
-            who_plus = ''
-            
-            curs.execute("select who from re_admin where what = ? order by time desc limit 1", ['notice (' + name + ' - ' + sub + '#' + topic_data[1] + ')'])
-            topic_data_top = curs.fetchall()
-            if topic_data_top:
-                who_plus += ' <span style="margin-right: 5px;">@' + topic_data_top[0][0] + ' </span>'
-                                
-            all_data += '''
-                <table id="toron">
-                    <tbody>
-                        <tr>
-                            <td id="toron_color_red">
-                                <a href="#''' + topic_data[1] + '''">
-                                    #''' + topic_data[1] + '''
-                                </a> ''' + ip_pas(topic_data[3]) + who_plus + ''' <span style="float: right;">''' + topic_data[2] + '''</span>
-                            </td>
-                        </tr>
-                        <tr>
-                            <td>''' + render_set(data = topic_data[0]) + '''</td>
-                        </tr>
-                    </tbody>
-                </table>
-                <hr class=\"main_hr\">
-            '''    
-
-        for topic_data in topic:
-            user_write = topic_data[0]
-
-            if number == 1:
-                start = topic_data[3]
-
-            if topic_data[4] == 'O':
-                blind_data = 'id="toron_color_grey"'
-                
-                if admin != 1:
-                    curs.execute("select who from re_admin where what = ? order by time desc limit 1", ['blind (' + name + ' - ' + sub + '#' + str(number) + ')'])
-                    who_blind = curs.fetchall()
-                    if who_blind:
-                        user_write = '[[user:' + who_blind[0][0] + ']] ' + load_lang('hide')
-                    else:
-                        user_write = load_lang('hide')
-            else:
-                blind_data = ''
-
-            user_write = render_set(data = user_write)
-            ip = ip_pas(topic_data[3])
-            
-            curs.execute('select acl from user where id = ?', [topic_data[3]])
-            user_acl = curs.fetchall()
-            if user_acl and user_acl[0][0] != 'user':
-                ip += ' <a href="javascript:void(0);" title="' + load_lang('admin') + '">★</a>'
-
-            if admin == 1 or blind_data == '':
-                ip += ' <a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/admin/' + str(number) + '">(' + load_lang('discussion_tool') + ')</a>'
-
-            curs.execute("select end from ban where block = ?", [topic_data[3]])
-            if curs.fetchall():
-                ip += ' <a href="javascript:void(0);" title="' + load_lang('blocked') + '">†</a>'
-                    
-            if topic_data[5] == '1':
-                color = '_blue'
-            elif topic_data[3] == start:
-                color = '_green'
-            else:
-                color = ''
-                
-            if user_write == '':
-                user_write = '<br>'
-                         
-            all_data += '''
-                <table id="toron">
-                    <tbody>
-                        <tr>
-                            <td id="toron_color''' + color + '''">
-                                <a href="javascript:void(0);" id="''' + str(number) + '">#' + str(number) + '</a> ' + ip + '''</span>
-                            </td>
-                        </tr>
-                        <tr ''' + blind_data + '''>
-                            <td>''' + user_write + '''</td>
-                        </tr>
-                    </tbody>
-                </table>
-                <hr class=\"main_hr\">
-            '''
-
-            number += 1
+        else:
+            display = ''
 
         if ban != 1 or admin == 1:
             data += '''
-                <div id="plus"></div>
-                <script>topic_load("''' + name + '''", "''' + sub + '''", "''' + str(number) + '''");</script>
+                <div id="top_topic"></div>
+                <div id="main_topic"></div>
+                <div id="plus_topic"></div>
+                <script>topic_top_load("''' + name + '''", "''' + sub + '''");</script>
                 <a id="reload" href="javascript:void(0);" onclick="reload();">(''' + load_lang('reload') + ''')</a> <a href="/topic/''' + url_pas(name) + '''/sub/''' + url_pas(sub) + '''/tool">(''' + load_lang('topic_tool') + ''')</a>
                 <hr class=\"main_hr\">
                 <form style="''' + display + '''" method="post">
@@ -198,6 +104,6 @@ def topic_2(conn, name, sub):
 
         return easy_minify(flask.render_template(skin_check(), 
             imp = [name, wiki_set(), custom(), other2([' (' + load_lang('discussion') + ')', 0])],
-            data = '<h2 id="topic_top_title">' + sub + '</h2>' + all_data + data,
+            data = '<h2 id="topic_top_title">' + sub + '</h2>' + data,
             menu = [['topic/' + url_pas(name), load_lang('list')]]
         ))

+ 8 - 8
route/topic_admin.py

@@ -24,18 +24,18 @@ def topic_admin_2(conn, name, sub, num):
         else:
             is_ban += load_lang('hide')
         
-        is_ban +=   '''
-                        </a>
-                    </li>
-                    <li>
-                        <a href="/topic/''' + url_pas(name) + '/sub/' + url_pas(sub) + '/notice/' + str(num) + '''">
-                    '''
+        is_ban += '''
+                </a>
+            </li>
+            <li>
+                <a href="/topic/''' + url_pas(name) + '/sub/' + url_pas(sub) + '/notice/' + str(num) + '''">
+        '''
 
         curs.execute("select id from topic where title = ? and sub = ? and id = ? and top = 'O'", [name, sub, str(num)])
         if curs.fetchall():
-            is_ban += load_lang('notice_release')
+            is_ban += load_lang('pinned_release')
         else:
-            is_ban += load_lang('notice') + ''
+            is_ban += load_lang('pinned') + ''
         
         is_ban += '</a></li></ul>'
         ban += '<li><a href="/ban/' + url_pas(data[0][1]) + '">'

+ 15 - 10
route/topic_close_list.py

@@ -26,11 +26,11 @@ def topic_close_list_2(conn, name, tool):
         if tool == 'close':
             curs.execute("select sub from rd where title = ? and stop = 'O' order by sub asc", [name])
             
-            sub = load_lang('close') + ''
+            sub = load_lang('close')
         elif tool == 'agree':
             curs.execute("select sub from rd where title = ? and agree = 'O' order by sub asc", [name])
             
-            sub = load_lang('agreement') + ''
+            sub = load_lang('agreement')
         else:
             curs.execute("select sub from rd where title = ? order by date desc", [name])
             
@@ -39,12 +39,12 @@ def topic_close_list_2(conn, name, tool):
             menu = [['w/' + url_pas(name), load_lang('document')]]
             
             plus =  '''
-                    <a href="/topic/''' + url_pas(name) + '''/close">(''' + load_lang('close') + ''')</a> <a href="/topic/''' + url_pas(name) + '''/agree">(''' + load_lang('agreement') + ''')</a>
-                    <hr class=\"main_hr\">
-                    <input placeholder="''' + load_lang('discussion_name') + '''" name="topic" type="text">
-                    <hr class=\"main_hr\">
-                    <button type="submit">''' + load_lang('go') + '''</button>
-                    '''
+                <a href="/topic/''' + url_pas(name) + '''/close">(''' + load_lang('close') + ''')</a> <a href="/topic/''' + url_pas(name) + '''/agree">(''' + load_lang('agreement') + ''')</a>
+                <hr class=\"main_hr\">
+                <input placeholder="''' + load_lang('discussion_name') + '''" name="topic" type="text">
+                <hr class=\"main_hr\">
+                <button type="submit">''' + load_lang('go') + '''</button>
+            '''
 
         for data in curs.fetchall():
             curs.execute("select data, date, ip, block from topic where title = ? and sub = ? and id = '1'", [name, data[0]])
@@ -57,13 +57,18 @@ def topic_close_list_2(conn, name, tool):
                         it_p = 1
                 
                 if it_p != 1:
-                    div += '<h2><a href="/topic/' + url_pas(name) + '/sub/' + url_pas(data[0]) + '">' + data[0] + '</a></h2>'
+                    curs.execute("select id from topic where title = ? and sub = ? order by date desc limit 1", [name, data[0]])
+                    t_data = curs.fetchall()
+                
+                    div += '''
+                        <h2><a href="/topic/''' + url_pas(name) + '''/sub/''' + url_pas(data[0]) + '''">''' + data[0] + '''</a></h2>
+                    '''
 
         if div == '':
             plus = re.sub('^<br>', '', plus)
         
         return easy_minify(flask.render_template(skin_check(), 
             imp = [name, wiki_set(), custom(), other2([' (' + sub + ')', 0])],
-            data =  '<form method="post">' + div + plus + '</form>',
+            data = '<form method="post">' + div + plus + '</form>',
             menu = menu
         ))

+ 24 - 0
views/main_css/js/topic_main_load.js

@@ -0,0 +1,24 @@
+function topic_main_load(name, sub) {
+    var o_data = document.getElementById('main_topic');
+    var url = "/api/topic/" + name + "/sub/" + sub + "?render=1";
+    var n_data = "";
+    var num = 1;
+    
+    var xhr = new XMLHttpRequest();
+    xhr.open("GET", url, true);
+    xhr.send(null);
+
+    xhr.onreadystatechange = function() {
+        if(this.readyState === 4 && this.status === 200) {
+            t_data = JSON.parse(this.responseText);
+            for(key in t_data) {
+                n_data += t_data[key]['data'];
+                num = key;
+            }
+            
+            o_data.innerHTML = n_data;
+            topic_plus_load(name, sub, String(Number(num) + 1));
+        }
+    }
+    
+}

+ 2 - 2
views/main_css/js/topic_load.js → views/main_css/js/topic_plus_load.js

@@ -1,7 +1,7 @@
-function topic_load(name, sub, num) {
+function topic_plus_load(name, sub, num) {
     var test = setInterval(function() {
         var url = "/api/topic/" + name + "/sub/" + sub + "?num=" + num;
-        var doc_data = document.getElementById("plus");
+        var doc_data = document.getElementById("plus_topic");
 
         var xhr = new XMLHttpRequest();
         xhr.open("GET", url, true);

+ 24 - 0
views/main_css/js/topic_top_load.js

@@ -0,0 +1,24 @@
+function topic_top_load(name, sub) {
+    var o_data = document.getElementById('top_topic');
+    var url = "/api/topic/" + name + "/sub/" + sub + "?top=1&render=1";
+    var n_data = "";
+    var num = 1;
+    
+    var xhr = new XMLHttpRequest();
+    xhr.open("GET", url, true);
+    xhr.send(null);
+
+    xhr.onreadystatechange = function() {
+        if(this.readyState === 4 && this.status === 200) {
+            t_data = JSON.parse(this.responseText);
+            for(key in t_data) {
+                n_data += t_data[key]['data'];
+                num = key;
+            }
+            
+            o_data.innerHTML = n_data;
+            topic_main_load(name, sub);
+        }
+    }
+    
+}