manto07m 3 роки тому
батько
коміт
efb3b93a28
2 змінених файлів з 60 додано та 41 видалено
  1. 56 37
      script/js/jstreeAJAX.js
  2. 4 4
      script/php/get_file_count.php

+ 56 - 37
script/js/jstreeAJAX.js

@@ -1,13 +1,26 @@
-var test;
+/* 
+    0:自動編號         SN項次
+    1:類別             圖名
+    2:X                關鍵字
+    3:X                版次
+    4:檔案數            X
+    5:計畫編號-計畫名稱  計畫編號
+    6:類別ID            計畫名稱
+    7:X                 類別ID
+    8:X                 工程類別
+    9:X                 上一層資料夾
+    10:X                檔案路徑
+*/
 $(document).ready(function () {
-    const types = ["工程概要", "工程計算書", "設計圖", "數量計算書", "工程預算書", "施工規範&特定條款", "設計報告書"];
+    //const types = ["工程概要", "工程計算書", "設計圖", "數量計算書", "工程預算書", "施工規範&特定條款", "設計報告書"];
+    var types = [];
     var path = '';
     var category = '';
     var project_id = '';
     var project_name = '';
     var project = '';
     var blueprint_SN = '';
-    var blueprint_path = '';    
+    var blueprint_path = '';
     var notes = [];
     var tempTable = [];
     var tempTable2 = [];
@@ -162,9 +175,11 @@ $(document).ready(function () {
                 $("#project-id").val(project_id)
                 $("#header").empty();
                 category = $('#treeAjaxHTML').jstree(true).get_node(data.node.parents[0]).text;
+                countFiles(project_id, "false");
 
                 var span = $('<span>' + project + ' > </span>');
                 span.on("click", function (e) {
+                    countFiles(project_id, "false");
                     displayDetail(false, true);
                     is_blueprint2 = false;
                     for (var k = folderPath.length - 1; k > 0; k--) {
@@ -174,23 +189,22 @@ $(document).ready(function () {
                     let i = 1;
                     table.clear().draw();
                     tempTable = [];
-                   
-                   
-                    types.forEach(function (data) {
-                        console.log(data)
-                        if(fileNums[i-1] == null){
+
+
+                    types.forEach(function (element) {
+                        if (fileNums[i - 1] == null) {
                             total = 0;
-                        }else{
-                            total = fileNums[i-1].total;
+                        } else {
+                            total = fileNums[i - 1].total;
                         }
                         let temp = [
                             i,
-                            data,
+                            element.type_name,
                             category,
                             '',
                             total,
                             project,
-
+                            element.type_id
                         ];
                         table.row.add(temp).draw();
 
@@ -205,20 +219,21 @@ $(document).ready(function () {
                 let i = 1;
                 table.clear().draw();
                 tempTable = [];
-                countFiles(project_id, "false");
-                types.forEach(function (data) {
-                    if(fileNums[i-1] == null){
+
+                types.forEach(function (element) {
+                    if (fileNums[i - 1] == null) {
                         total = 0;
-                    }else{
-                        total = fileNums[i-1].total;
+                    } else {
+                        total = fileNums[i - 1].total;
                     }
                     let temp = [
                         i,
-                        data,
+                        element.type_name,
                         category,
                         '',
                         total,
                         project,
+                        element.type_id
                     ];
                     table.row.add(temp).draw();
                     tempTable.push(temp);
@@ -315,7 +330,7 @@ $(document).ready(function () {
             data = ["", "", "null", "", "", "", "", "", "", ""];
         }
         let project_id = data[5].split("-")[0];
-        let SN = data[0];
+        let SN = data[6] != null ? data[6] : 0;
         let is_blueprint = data[1] == "設計圖" || data[1] == "成果圖" ? true : false;
         let note = notes.includes(data[1]) ? data[1] : '';
 
@@ -366,34 +381,30 @@ $(document).ready(function () {
             let type = types[parseInt(data[7]) - 1];
             let path = '';
             //let category = data[8];
-            if (data[7] == 3) {
-                path = data[8] + "/" + data[5] + "-" + data[6] + data[10];
-            } else {
-                path = data[8] + "/" + data[5] + "-" + data[6] + data[10];
-            }
 
+            path = data[8] + "/" + data[5] + "-" + data[6] + data[10];
             $("#plan_code").text(data[5]);
             $("#plan_name").text(data[6]);
-            
-            
+
+
             $("#version").text(data[3]);
             $("#fileName").text(data[1]);
-            if(path.toLowerCase().includes("pdf")){
+            if (path.toLowerCase().includes("pdf")) {
                 PDFObject.embed("./assets/建置資料/" + path, "#pdfFile");
                 $("#download").append('<img src="./assets/images/' + 'pdf-icon.png" style="height: 30px; display: inline-block;"> ');
-            }else{                
+            } else {
                 PDFObject.embed("./assets/notPDF.pdf", "#pdfFile");
-                
-                if(path.toLowerCase().includes("doc")){
+
+                if (path.toLowerCase().includes("doc")) {
                     $("#download").append('<img src="./assets/images/' + 'word-icon.png" style="height: 30px; display: inline-block;"> ');
-                }else if(path.toLowerCase().includes("xls")){
+                } else if (path.toLowerCase().includes("xls")) {
                     $("#download").append('<img src="./assets/images/' + 'excel-icon.png" style="height: 30px; display: inline-block;"> ');
                 }
-                
+
             }
-            console.log( data[10]);
+            console.log(data[10]);
             let fileNames = data[10].split('/');
-            let fileName = fileNames[fileNames.length-1];
+            let fileName = fileNames[fileNames.length - 1];
             $("#download").append('<a target="_blank" href="./assets/建置資料/' + path + '">' + fileName + '</a>');
 
         }
@@ -401,6 +412,7 @@ $(document).ready(function () {
     });
 
     function displayDetail(isFile, isBlueprint) {
+
         table.column(0).visible(isBlueprint);
         table.column(2).visible(isFile);
         table.column(3).visible(isFile);
@@ -410,7 +422,7 @@ $(document).ready(function () {
             $("#SN").text("圖號");
             $("#name").text("圖名");
             $('.nav-tabs a[href="#pdfTab"]').tab('show');
-            //test = table;
+            test = table;
             if (table.rows().count() > 10) {
                 table.page.len(10).draw();
             } else {
@@ -445,6 +457,13 @@ $(document).ready(function () {
             .success(function (response) {
                 console.log(response);
                 fileNums = response;
+                types = [];
+                response.forEach(function (element) {
+                    types.push({
+                        type_id: element.type_id,
+                        type_name: element.type_name
+                    })
+                });
             })
             .error(function (error) {
                 console.log(error);
@@ -489,9 +508,9 @@ $(document).ready(function () {
             countFiles(project_id, "true");
             for (i = 0; i < response.length; i++) {
                 notes[i] = response[i]['notes'];
-                if(fileNums[i] == null){
+                if (fileNums[i] == null) {
                     total = 0;
-                }else{
+                } else {
                     total = fileNums[i].total;
                 }
                 let temp = [

+ 4 - 4
script/php/get_file_count.php

@@ -25,10 +25,10 @@ if ($is_blueprint == "true") {
         array_push($data_array, $row);
     }
 } else {
-    $sql = "SELECT [project_id],[type_id],COUNT(*) AS 'total' FROM [File_Table] WHERE [project_id] = '" . $project_id . "' GROUP BY  [project_id],[type_id]
-    UNION 
-        SELECT [project_id],[type_id],COUNT(*) AS 'total' FROM [Blueprint] WHERE [project_id] = '" . $project_id . "' GROUP BY  [project_id],[type_id] 
-     ORDER BY [project_id];";
+    $sql = "SELECT [project_id],[File_Table].[type_id],[type_name],COUNT(*) AS 'total' ,[filetype_id] FROM [File_Table]  RIGHT JOIN [File_Category] ON [File_Table].[type_id] = [File_Category].[type_id] WHERE [project_id] = '" . $project_id . "' GROUP BY  [project_id],[File_Table].[type_id],[type_name],[filetype_id]
+	UNION 
+SELECT [project_id],[Blueprint].[type_id],[type_name],COUNT(*) AS 'total',[filetype_id] FROM [Blueprint]  RIGHT JOIN [File_Category] ON [Blueprint].[type_id] = [File_Category].[type_id] WHERE [project_id] = '" . $project_id . "' GROUP BY  [project_id],[Blueprint].[type_id],[type_name],[filetype_id]
+	ORDER BY [project_id];";
 
     $fetchResult = sqlsrv_query($conn, $sql);
     while ($row = sqlsrv_fetch_array($fetchResult, SQLSRV_FETCH_ASSOC)) {