Просмотр исходного кода

项目管理,规范树结构ID等

MaiXinRong 8 лет назад
Родитель
Сommit
b789cb2dd1

+ 11 - 11
modules/pm/models/project.js

@@ -9,14 +9,14 @@ var dbm = require("../../../config/db/db_manager");
 var db = dbm.getCfgConnection("usersManages");
 var Schema = mongoose.Schema;
 var ProjectSchema = new Schema({
+    "ID": Number,
+    "ParentID": Number,
+    "NextSiblingID": Number,
+    "userID": Number,
     "name": String,
     "projType": String,
     "recentDateTime": Date,
     "createDateTime": Date,
-    "id": Number,
-    "parentId": Number,
-    "nextId": Number,
-    "userId": Number,
     "deleted": Boolean,
     'deleteDateTime': Date,
     'fullFolder': Array
@@ -46,7 +46,7 @@ var Schema = db.mongoose.Schema;
 var ProjectsDAO = function(){};
 
 ProjectsDAO.prototype.getUserProjects = function(userId, callback){
-    Projects.find({userId: userId, deleted: { $in: [false, null]}}, '-_id', function(err, templates){
+    Projects.find({userID: userId, deleted: { $in: [false, null]}}, '-_id', function(err, templates){
         if (err) {
             callback(1, 'Error', null);
         } else {
@@ -56,7 +56,7 @@ ProjectsDAO.prototype.getUserProjects = function(userId, callback){
 };
 
 ProjectsDAO.prototype.getUserProject = function (userId, ProjId, callback) {
-    Projects.findOne({userId: userId, id: ProjId}, '-_id', function(err, template){
+    Projects.findOne({userID: userId, ID: ProjId}, '-_id', function(err, template){
         if (err) {
             callback(1, '找不到标段数据', null);
         } else {
@@ -82,9 +82,9 @@ ProjectsDAO.prototype.updateUserProjects = function(userId, datas, callback){
         for (var i = 0; i < datas.length && !hasError; i++){
             data = datas[i];
             if (data.updateType === 'update') {
-                Projects.update({userId: userId, id: data.updateData.id}, data.updateData, updateAll)
+                Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll)
             } else if (data.updateType === 'new') {
-                data.updateData['userId'] = userId;
+                data.updateData['userID'] = userId;
                 if (data.updateData.projType === 'Tender') {
                     data.updateData['createDateTime'] = new Date();
                 }
@@ -92,14 +92,14 @@ ProjectsDAO.prototype.updateUserProjects = function(userId, datas, callback){
                 newProject.save(updateAll);
             } else if (data.updateType === 'delete') {
                 data.updateData['deleteDateTime'] = new Date();
-                Projects.update({userId: userId, id: data.updateData.id}, data.updateData, updateAll);
+                Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll);
             }
         }
     }
 };
 
 ProjectsDAO.prototype.rename = function (userId, projectId, newName, callback){
-    Projects.update({userId: userId, id: projectId}, {name: newName}, function(err){
+    Projects.update({userID: userId, ID: projectId}, {name: newName}, function(err){
        if (err){
            callback(1, '项目不存在.');
        } else {
@@ -110,7 +110,7 @@ ProjectsDAO.prototype.rename = function (userId, projectId, newName, callback){
 
 ProjectsDAO.prototype.beforeOpenProject = function (userId, projectId, updateData, callback){
     updateData['recentDateTime'] = new Date();
-    Projects.update({userId: userId, id: projectId}, updateData, function(err){
+    Projects.update({userID: userId, ID: projectId}, updateData, function(err){
         if (err){
             callback(1, '项目不存在.');
         } else {

+ 20 - 27
web/main/js/main.js

@@ -2,7 +2,7 @@
  * Created by Mai on 2017/3/10.
  */
 
-var Project, pm = '<a href="/pm">项目管理</a>', angleRight = '<i class="fa fa-angle-right fa-fw"></i>';
+var Project;
 
 var GetQueryString = function (name) {
     var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
@@ -10,35 +10,28 @@ var GetQueryString = function (name) {
     if (r != null) return unescape(r[2]); return null;
 };
 
-var LoadFullPath = function (proj) {
-    var fullPath = [], i;
-    fullPath.push(pm);
-    for (i = 0; i < proj.fullFolder.length; i++) {
-        fullPath.push(angleRight, proj.fullFolder[i]);
-    }
-    fullPath.push(angleRight, proj.name)
-    return fullPath;
-};
-
 var LoadData = function () {
-    var fullPath;
+    var loadFullPathHtml = function (proj) {
+        var fullPath = [], i, pm = '<a href="/pm">项目管理</a>', angleRight = '<i class="fa fa-angle-right fa-fw"></i>';
+        fullPath.push(pm);
+        for (i = 0; i < proj.fullFolder.length; i++) {
+            fullPath.push(angleRight, proj.fullFolder[i]);
+        }
+        fullPath.push(angleRight, proj.name)
+        return fullPath.join('');
+    };
+    /*$.post('/getProject', {'data': JSON.stringify({"user_id": userID, "proj_id": GetQueryString('project')})},  function (result) {
+        if (result.error === 0) {
+            Project = result.data;
+            $('#fullpath').html(loadFullPathHtml(Project));
+        } else {
+            alert('error: ' + result.message);
+        };
+    });*/
     GetProject(GetQueryString('project'), function (data) {
         Project = data;
-        fullPath = LoadFullPath(Project);
-        $('#fullpath').html(fullPath.join(''));
+        $('#fullpath').html(loadFullPathHtml(Project));
     });
 };
 
-LoadData();
-
-var setting = {
-    columns: [
-        {
-            data: '',
-            hAlign: '',
-            vAlign: ''
-        },
-    ]
-}
-
-$('#warp-p2')
+LoadData();

+ 66 - 1
web/main/js/main_ajax.js

@@ -2,6 +2,29 @@
  * Created by Mai on 2017/3/10.
  */
 
+var PullData = function (url, data, successCallback, errorCallback) {
+    $.ajax({
+        type:"POST",
+        url: url,
+        data: {'data': JSON.stringify(data)},
+        dataType: 'json',
+        cache: false,
+        timeout: 50000,
+        success: function(result){
+            if (result.error === 0) {
+                successCallback(result.data);
+            } else {
+                alert('error: ' + result.message);
+                errorCallback();
+            }
+        },
+        error: function(jqXHR, textStatus, errorThrown){
+            alert('error ' + textStatus + " " + errorThrown);
+            errorCallback();
+        }
+    });
+};
+
 var GetProject = function (proj_id, callback) {
     $.ajax({
         type:"POST",
@@ -21,4 +44,46 @@ var GetProject = function (proj_id, callback) {
             alert('error ' + textStatus + " " + errorThrown);
         }
     });
-}
+};
+
+var GetBills = function (proj_id, callback) {
+    $.ajax({
+        type: "POST",
+        url: '/getBills',
+        data: {'data': JSON.stringify({"user_id": userID, "proj_id": proj_id})},
+        dataType: 'json',
+        cache: false,
+        timeout: 50000,
+        success: function (result) {
+            if (result.error === 0) {
+                callback(result.data);
+            } else {
+                alert('error: ' + result.message);
+            }
+        },
+        error: function(jqXHR, textStatus, errorThrown){
+            alert('error ' + textStatus + " " + errorThrown);
+        }
+    });
+};
+
+var GetRations = function (proj_id, callback) {
+    $.ajax({
+        type: "POST",
+        url: '/getRations',
+        data: {'data': JSON.stringify({"user_id": userID, "proj_id": proj_id})},
+        dataType: 'json',
+        cache: false,
+        timeout: 50000,
+        success: function (result) {
+            if (result.error === 0) {
+                callback(result.data);
+            } else {
+                alert('error: ' + result.message);
+            }
+        },
+        error: function(jqXHR, textStatus, errorThrown){
+            alert('error ' + textStatus + " " + errorThrown);
+        }
+    });
+};

+ 6 - 6
web/pm/html/project-management.html

@@ -332,7 +332,7 @@
                 </div>
                 <div class="modal-footer">
                     <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
-                    <a href="#" class="btn btn-primary" id='addProjOk'>确定</a>
+                    <a href="javacript:void(0);" class="btn btn-primary" id='addProjOk'>确定</a>
                 </div>
             </div>
         </div>
@@ -359,7 +359,7 @@
                 </div>
                 <div class="modal-footer">
                     <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
-                    <a href="#" class="btn btn-primary" id="addFolderOk">确定</a>
+                    <a href="javacript:void(0);" class="btn btn-primary" id="addFolderOk">确定</a>
                 </div>
             </div>
         </div>
@@ -383,7 +383,7 @@
                 </div>
                 <div class="modal-footer">
                     <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
-                    <a href="#" class="btn btn-primary" id="renameOk">确定</a>
+                    <a href="javacript:void(0);" class="btn btn-primary" id="renameOk">确定</a>
                 </div>
             </div>
         </div>
@@ -405,7 +405,7 @@
                 </div>
                 <div class="modal-footer">
                     <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
-                    <a href="#" class="btn btn-danger" id="deleteProjOk">删除</a>
+                    <a href="javacript:void(0);" class="btn btn-danger" id="deleteProjOk">删除</a>
                 </div>
             </div>
         </div>
@@ -425,7 +425,7 @@
                 </div>
                 <div class="modal-footer">
                     <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
-                    <a href="#" class="btn btn-primary" id="movetoOk">确定</a>
+                    <a href="javacript:void(0);" class="btn btn-primary" id="movetoOk">确定</a>
                 </div>
             </div>
         </div>
@@ -445,7 +445,7 @@
                 </div>
                 <div class="modal-footer">
                     <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
-                    <a href="#" class="btn btn-primary" id="copytoOk">确定</a>
+                    <a href="javacript:void(0);" class="btn btn-primary" id="copytoOk">确定</a>
                 </div>
             </div>
         </div>

+ 38 - 29
web/pm/js/pm_main.js

@@ -4,6 +4,13 @@
 
 var Tree = null, movetoZTree = null, copytoZTree = null;
 var ProjTreeSetting = {
+    tree: {
+        id: 'ID',
+        pid: 'ParentID',
+        nid: 'NextSiblingID',
+        btnColumn: 1,
+        nullId: -1
+    },
     columns: [
         {
             head: '',
@@ -122,7 +129,9 @@ var GetNeedUpdatePreNode = function (parent, next) {
 var GetPreNodeUpdateData = function (pre, nid) {
     var data = {};
     data['updateType'] = 'update';
-    data['updateData'] = {id: pre.id(), nextId: nid};
+    data['updateData'] = {};
+    data.updateData[setting.tree.id] = pre.id();
+    data.updateData[setting.tree.nid] = nid;
     return data;
 }
 // 获取新建项目数据
@@ -131,9 +140,9 @@ var GetAddProjUpdateData = function (parent, next, name) {
     updateData = {};
     updateData['updateType'] = 'new';
     updateData['updateData'] = {};
-    updateData['updateData']['id'] = newId;
-    updateData['updateData']['parentId'] = parent ? parent.id() : -1;
-    updateData['updateData']['nextId'] = next ? next.id() : -1;
+    updateData['updateData'][Tree.setting.tree.id] = newId;
+    updateData['updateData'][Tree.setting.tree.pid] = parent ? parent.id() : -1;
+    updateData['updateData'][Tree.setting.tree.nid] = next ? next.id() : -1;
     updateData['updateData']['name'] = name;
     updateData['updateData']['projType'] = 'Tender';
     datas.push(updateData);
@@ -145,9 +154,9 @@ var GetAddFolderProjUpdateData = function (parent, next, folderName1, folderName
         var data = {};
         data['updateType'] = 'new';
         data['updateData'] = {};
-        data['updateData']['id'] = newId;
-        data['updateData']['parentId'] = parentId;
-        data['updateData']['nextId'] = nextId;
+        data['updateData'][Tree.setting.tree.id] = newId;
+        data['updateData'][Tree.setting.tree.pid] = parentId;
+        data['updateData'][Tree.setting.tree.nid] = nextId;
         data['updateData']['name'] = name;
         data['updateData']['projType'] = projType;
         newId += 1;
@@ -155,8 +164,8 @@ var GetAddFolderProjUpdateData = function (parent, next, folderName1, folderName
         return data;
     }
     folderData1 = addUpdateData(parent.id(), next ? next.id() : -1, folderName1, 'Folder');
-    folderData2 = addUpdateData(folderData1.updateData.id, -1, folderName2, 'Folder');
-    addUpdateData(folderData2.updateData.id, -1, name, 'Tender');
+    folderData2 = addUpdateData(folderData1.updateData[Tree.setting.tree.id], -1, folderName2, 'Folder');
+    addUpdateData(folderData2.updateData[Tree.setting.tree.id], -1, name, 'Tender');
     return datas;
 };
 // 获取新建文件夹数据
@@ -165,9 +174,9 @@ var GetAddForlderUpdateData = function (parent, next, folderName) {
     updateData = {};
     updateData['updateType'] = 'new';
     updateData['updateData'] = {};
-    updateData['updateData']['id'] = newId;
-    updateData['updateData']['parentId'] = parent ? parent.id() : -1;
-    updateData['updateData']['nextId'] = next ? next.id() : -1;
+    updateData['updateData'][Tree.setting.tree.id] = newId;
+    updateData['updateData'][Tree.setting.tree.pid] = parent ? parent.id() : -1;
+    updateData['updateData'][Tree.setting.tree.nid] = next ? next.id() : -1;
     updateData['updateData']['name'] = folderName;
     updateData['updateData']['projType'] = 'Folder';
     datas.push(updateData);
@@ -185,8 +194,8 @@ var GetNextChangeUpdateData = function (datas, node, next) {
         data = {};
         data['updateType'] = 'update';
         data['updateData'] = {};
-        data['updateData']['id'] = node.id();
-        data['updateData']['nextId'] = next ? next.id() : -1;
+        data['updateData'][Tree.setting.tree.id] = node.id();
+        data['updateData'][Tree.setting.tree.nid] = next ? next.id() : -1;
         datas.push(data);
     }
     return data;
@@ -207,7 +216,7 @@ var GetDeleteUpdateData = function (node) {
             var data = {};
             data['updateType'] = 'delete';
             data['updateData'] = {};
-            data['updateData']['id'] = node.id();
+            data['updateData'][Tree.setting.tree.id] = node.id();
             data['updateData']['deleted'] = true;
             if (node.data.projType === 'Tender') {
                 data['updateData']['FullFolder'] = GetfullFolder(node.parent);
@@ -224,8 +233,8 @@ var GetDeleteUpdateData = function (node) {
         updateData = {};
         updateData['updateType'] = 'update';
         updateData['updateData'] = {};
-        updateData['updateData']['id'] = pre.id();
-        updateData['updateData']['nextId'] = node ? node.nid() : -1;
+        updateData['updateData'][Tree.setting.tree.id] = pre.id();
+        updateData['updateData'][Tree.setting.tree.nid] = node ? node.nid() : -1;
         datas.push(updateData);
     }
     datas.push(deleteNodeData(node));
@@ -242,9 +251,9 @@ var GetMoveUpdateData = function (node, parent, next) {
     updateData = {};
     updateData['updateType'] = 'update';
     updateData['updateData'] = {};
-    updateData['updateData']['id'] = node.id();
-    updateData['updateData']['parentId'] = parent ? parent.id() : -1;
-    updateData['updateData']['nextId'] = next ? next.id() : -1;
+    updateData['updateData'][Tree.setting.tree.id] = node.id();
+    updateData['updateData'][Tree.setting.tree.pid] = parent ? parent.id() : -1;
+    updateData['updateData'][Tree.setting.tree.nid] = next ? next.id() : -1;
     datas.push(updateData);
     return datas;
 };
@@ -254,9 +263,9 @@ var GetCopyUpdateData = function (node, parent, next){
     updateData = {};
     updateData['updateType'] = 'new';
     updateData['updateData'] = {};
-    updateData['updateData']['id'] = node.tree.maxNodeId() + 1;
-    updateData['updateData']['parentId'] = parent ? parent.id() : -1;
-    updateData['updateData']['nextId'] = next ? next.id() : -1;
+    updateData['updateData'][Tree.setting.tree.id] = node.tree.maxNodeId() + 1;
+    updateData['updateData'][Tree.setting.tree.pid] = parent ? parent.id() : -1;
+    updateData['updateData'][Tree.setting.tree.nid] = next ? next.id() : -1;
     updateData['updateData']['name'] = node.data.name;
     updateData['updateData']['projType'] = node.data.projType;
     datas.push(updateData);
@@ -266,8 +275,8 @@ var GetCopyUpdateData = function (node, parent, next){
         updateData = {};
         updateData['updateType'] = 'update';
         updateData['updateData'] = {};
-        updateData['updateData']['id'] = pre.id();
-        updateData['updateData']['nextId'] = node.tree.maxNodeId() + 1;
+        updateData['updateData'][Tree.setting.tree.id] = pre.id();
+        updateData['updateData'][Tree.setting.tree.nid] = node.tree.maxNodeId() + 1;
         datas.push(updateData);
     }
     return datas;
@@ -288,8 +297,8 @@ var ConvertTreeToZtree = function (Tree, zTreeObj, filterNode) {
             nodes.forEach(function (node) {
                 if (node !== filterNode) {
                     var data = {};
-                    data['id'] = node.data['id'];
-                    data['pId'] = node.pid();// === -1 ? 0 : node.pid();
+                    data['id'] = node.data[Tree.setting.tree.id];
+                    data['pId'] = node.pid();
                     data['name'] = node.data['name'];
                     data['isParent'] = node.data.projType === 'Folder';//(node.data.projType === 'Folder' && node.children.length === 0);
                     data['open'] = node.data.projType === 'Folder';//node.children.length !== 0;
@@ -418,8 +427,8 @@ var AddFolderProj = function () {
             datas.forEach(function (data) {
                 var parent, next;
                 if (data.updateType === 'new') {
-                    parent = data.updateData.parentId === -1 ?  Tree._root : Tree.findNode(data.updateData.parentId);
-                    next = data.updateData.nextId === -1 ? null : Tree.findNode(data.updateData.nextId);
+                    parent = data.updateData[Tree.setting.tree.pid] === -1 ?  Tree._root : Tree.findNode(data.updateData[Tree.setting.tree.pid]);
+                    next = data.updateData[Tree.setting.tree.nid] === -1 ? null : Tree.findNode(data.updateData[Tree.setting.tree.nid]);
                     Tree.addNodeData(data.updateData, parent, next);
                 }
             });

+ 11 - 7
web/scripts/tree_table.js

@@ -6,11 +6,10 @@
 (function($) {
     var _setting = {
  		tree: {
- 			id: 'id',
- 			pid: 'parentId',
- 			nid: 'nextId',
+ 			id: 'ID',
+ 			pid: 'ParentID',
+ 			nid: 'NextSiblingID',
  			btnColumn: 1,
- 			iconCol: 'projType',
 			nullId: -1
  		},
  		columns: [
@@ -28,7 +27,8 @@
  		dataTemp: {
 			id: -1,
 			parentId: -1,
-			nextId: -1
+			nextId: -1,
+			isTemp: true
  		},
         viewEvent: {
             beforeSelect: null,
@@ -253,6 +253,7 @@
  				if (!next && data[setting.tree.nid] !== setting.tree.nullId) {
  					next = createTempNode(data[setting.tree.nid], setting);
  					next.parent = parent;
+					parent.children.push(next);
  				}
  				node.nextSibling = next;
 
@@ -265,7 +266,10 @@
  					} else {
  						parent.children.splice(parent.childIndex(next), 0, node);
  					}
- 				}
+ 				} else if (parent.childIndex(node) !== parent.childIndex(node.next) - 1) {
+					parent.children.splice(parent.childIndex(node), 1);
+					parent.children.splice(parent.childIndex(next), 0, node);
+				};
 			};
 
  			for (i = 0; i < arrData.length; i++){
@@ -338,7 +342,7 @@
  					if (node.row) {
  						if (pre) {
  							_view._moveRowDom(node, pre.deepestRow());
- 						} else if (parent.id() !== setting.tree.nullId) {
+ 						} else if (parent.id() !== this.setting.tree.nullId) {
                             _view._moveRowDom(node, parent.row);
                         } else if (nextSibling) {
  							_view._moveRowDomBefore(node, nextSibling.row);