diff --git a/frontend-js/src/main/js/gui/admin/CommentsAdminPanel.js b/frontend-js/src/main/js/gui/admin/CommentsAdminPanel.js index 1f5bc3429ad0be398031de4ece5f08db76de1318..431f3759d6129566bf276537e71b3aab72d1c907 100644 --- a/frontend-js/src/main/js/gui/admin/CommentsAdminPanel.js +++ b/frontend-js/src/main/js/gui/admin/CommentsAdminPanel.js @@ -5,6 +5,7 @@ var Panel = require('../Panel'); var Functions = require('../../Functions'); +var logger = require('../../logger'); var Promise = require("bluebird"); @@ -25,13 +26,64 @@ CommentsAdminPanel.prototype._createGui = function() { }); self.getElement().appendChild(projectsDiv); + var dataDiv = Functions.createElement({ + type : "div", + style : "display:table", + }); + projectsDiv.appendChild(dataDiv); + + var commentsCell = Functions.createElement({ + type : "div", + style : "display:table-cell;width:100%;vertical-align:top", + }); + projectsDiv.appendChild(commentsCell); + + var commentsTable = Functions.createElement({ + type : "table", + name : "commentsTable", + className : "display", + style : "width:100%", + }); + commentsCell.appendChild(commentsTable); + + $(commentsTable).DataTable({ + columns : [ { + title : 'Id', + }, { + title : 'Title', + }, { + title : 'Author', + }, { + title : 'Email', + }, { + title : 'Content', + }, { + title : 'Removed', + }, { + title : 'Pinned', + }, ] + }); + + var projectsCell = Functions.createElement({ + type : "div", + style : "display:table-cell", + }); + projectsDiv.appendChild(projectsCell); + var selectProject = Functions.createElement({ type : "select", name : "projectSelect", }); - selectProject.size = "12" + selectProject.size = "12"; + selectProject.onchange = function() { + return self.onProjectChange(); + }; - projectsDiv.appendChild(selectProject); + projectsCell.appendChild(Functions.createElement({ + type : "h3", + content : "Project", + })); + projectsCell.appendChild(selectProject); } CommentsAdminPanel.prototype.init = function() { @@ -65,6 +117,35 @@ CommentsAdminPanel.prototype.refreshProjects = function() { return ServerConnector.getProjectId(); }).then(function(projectId) { projectSelect.value = projectId; + return self.onProjectChange(); + }).then(function() { + $(window).trigger('resize'); }); }; + +CommentsAdminPanel.prototype.onProjectChange = function() { + var self = this; + var projectSelect = $("[name='projectSelect']", self.getElement())[0]; + return ServerConnector.getComments({ + projectId : projectSelect.value + }).then( + function(comments) { + var dataTable = $($("[name='commentsTable']", self.getElement())[0]).DataTable(); + var data = []; + var toYesNo = function(val) { + if (val) { + return "YES"; + } else { + return "NO"; + } + } + for (var i = 0; i < comments.length; i++) { + var comment = comments[i]; + data.push([ comment.getId(), comment.getTitle(), "", "", comment.getContent(), toYesNo(comment.isRemoved()), + toYesNo(comment.isPinned()) ]); + logger.debug("Add comment: ", comments[i]); + } + dataTable.clear().rows.add(data).draw(); + }); +}; module.exports = CommentsAdminPanel; diff --git a/frontend-js/testFiles/apiCalls/projects/sample/comments/models/all/token=MOCK_TOKEN_ID& b/frontend-js/testFiles/apiCalls/projects/sample/comments/models/all/token=MOCK_TOKEN_ID& new file mode 100644 index 0000000000000000000000000000000000000000..15846794a5557c5c91ec63b989dc156f3118d4a1 --- /dev/null +++ b/frontend-js/testFiles/apiCalls/projects/sample/comments/models/all/token=MOCK_TOKEN_ID& @@ -0,0 +1 @@ +[{"elementId":"1.00,200.00","coord":{"x":1.0,"y":200.0},"pinned":true,"removed":false,"modelId":15781,"author":"test","icon":"icons/comment.png","id":4506,"title":"Comment (coord: 1.00, 200.00)","type":"POINT","content":"hal","email":"email"},{"elementId":"100.00,200.00","coord":{"x":100.0,"y":200.0},"pinned":true,"removed":false,"modelId":15781,"author":"test","icon":"icons/comment.png","id":4507,"title":"Comment (coord: 100.00, 200.00)","type":"POINT","content":"hal","email":"email"},{"elementId":"1.00,200.00","coord":{"x":1.0,"y":200.0},"pinned":true,"removed":false,"modelId":15781,"author":"test","icon":"icons/comment.png","id":4508,"title":"Comment (coord: 1.00, 200.00)","type":"POINT","content":"hal","email":"email"},{"elementId":"1.00,200.00","coord":{"x":1.0,"y":200.0},"pinned":true,"removed":false,"modelId":15781,"author":"test","icon":"icons/comment.png","id":4509,"title":"Comment (coord: 1.00, 200.00)","type":"POINT","content":"hal","email":"email"},{"elementId":"1.00,200.00","coord":{"x":1.0,"y":200.0},"pinned":true,"removed":false,"modelId":15781,"author":"test","icon":"icons/comment.png","id":4510,"title":"Comment (coord: 1.00, 200.00)","type":"POINT","content":"halo","email":"email"},{"elementId":"2.00,12.00","coord":{"x":2.0,"y":12.0},"pinned":false,"removed":false,"modelId":15781,"author":"","icon":"icons/comment.png","id":4511,"title":"Comment (coord: 2.00, 12.00)","type":"POINT","content":"","email":""},{"elementId":"322.43,28.04","coord":{"x":322.4267578125,"y":28.037109374991598},"pinned":false,"removed":false,"modelId":15781,"author":"qwe","icon":"icons/comment.png","id":4512,"title":"Comment (coord: 322.43, 28.04)","type":"POINT","content":"","email":"asd"},{"elementId":"1108.74,525.06","coord":{"x":1108.740234375,"y":525.0585937499997},"pinned":false,"removed":false,"modelId":15781,"author":"qwe","icon":"icons/comment.png","id":4513,"title":"Comment (coord: 1108.74, 525.06)","type":"POINT","content":"","email":"asdxzf"},{"elementId":329158,"coord":{"x":321.5,"y":289.0},"pinned":false,"removed":false,"modelId":15781,"author":"complex12","icon":"icons/comment.png","id":4514,"title":"s12","type":"ALIAS","content":"complex12","email":""},{"elementId":329166,"coord":{"x":70.0,"y":269.0},"pinned":false,"removed":false,"modelId":15781,"author":"cnc","icon":"icons/comment.png","id":4515,"title":"CNC","type":"ALIAS","content":"cnc","email":"cnc"},{"elementId":329173,"coord":{"x":52.0,"y":26.0},"pinned":false,"removed":false,"modelId":15781,"author":"s1","icon":"icons/comment.png","id":4516,"title":"s1","type":"ALIAS","content":"s1","email":""},{"elementId":329175,"coord":{"x":416.0,"y":250.0},"pinned":false,"removed":false,"modelId":15781,"author":"","icon":"icons/comment.png","id":4517,"title":"s13","type":"ALIAS","content":"s13","email":"s13"},{"elementId":"883.81,380.41","coord":{"x":883.81,"y":380.41},"pinned":true,"removed":false,"modelId":15781,"author":"xxx","icon":"icons/comment.png","id":4518,"title":"Comment (coord: 883.81, 380.41)","type":"POINT","content":"","email":"xxx"},{"elementId":"241.01,372.35","coord":{"x":241.00605157081114,"y":372.34797385543044},"pinned":true,"removed":true,"modelId":15781,"author":"","icon":"icons/comment.png","id":4290,"title":"Comment (coord: 241.01, 372.35)","type":"POINT","content":"","email":""},{"elementId":"643.96,144.09","coord":{"x":643.9579684828551,"y":144.0935652248765},"pinned":true,"removed":false,"modelId":15781,"author":"admin ","icon":"icons/comment.png","id":4291,"title":"Comment (coord: 643.96, 144.09)","type":"POINT","content":"dfgfdgdf","email":""},{"elementId":"216.65,370.00","coord":{"x":216.65,"y":370.0},"pinned":false,"removed":false,"modelId":15781,"author":"","icon":"icons/comment.png","id":4671,"title":"Comment (coord: 216.65, 370.00)","type":"POINT","content":"","email":""},{"elementId":"214.10,368.00","coord":{"x":214.1,"y":368.0},"pinned":true,"removed":false,"modelId":15781,"author":"a","icon":"icons/comment.png","id":4672,"title":"Comment (coord: 214.10, 368.00)","type":"POINT","content":"","email":"z"},{"elementId":"82.84,598.00","coord":{"x":82.84,"y":598.0},"pinned":true,"removed":true,"modelId":15781,"author":"admin ","icon":"icons/comment.png","id":4946,"title":"Comment (coord: 82.84, 598.00)","type":"POINT","content":"cont","email":"piotr.gawron@uni.lu"},{"elementId":"219.20,112.00","coord":{"x":219.2,"y":112.0},"pinned":true,"removed":true,"modelId":15781,"author":"admin ","icon":"icons/comment.png","id":4945,"title":"Comment (coord: 219.20, 112.00)","type":"POINT","content":"cont","email":"piotr.gawron@uni.lu"},{"elementId":"386.15,494.00","coord":{"x":386.15,"y":494.0},"pinned":false,"removed":true,"modelId":15781,"author":"x","icon":"icons/comment.png","id":4944,"title":"Comment (coord: 386.15, 494.00)","type":"POINT","content":"","email":""},{"elementId":"497.02,465.00","coord":{"x":497.02,"y":465.0},"pinned":false,"removed":true,"modelId":15781,"author":"x","icon":"icons/comment.png","id":4943,"title":"Comment (coord: 497.02, 465.00)","type":"POINT","content":"","email":""},{"elementId":"457.51,472.00","coord":{"x":457.51,"y":472.0},"pinned":true,"removed":true,"modelId":15781,"author":"xxx3","icon":"icons/comment.png","id":4942,"title":"Comment (coord: 457.51, 472.00)","type":"POINT","content":"","email":""},{"elementId":"681.81,523.00","coord":{"x":681.81,"y":523.0},"pinned":true,"removed":true,"modelId":15781,"author":"xxx3","icon":"icons/comment.png","id":4941,"title":"Comment (coord: 681.81, 523.00)","type":"POINT","content":"","email":""},{"elementId":"737.89,405.00","coord":{"x":737.89,"y":405.0},"pinned":true,"removed":true,"modelId":15781,"author":"xxx3","icon":"icons/comment.png","id":4940,"title":"Comment (coord: 737.89, 405.00)","type":"POINT","content":"","email":""},{"elementId":"484.28,583.00","coord":{"x":484.28,"y":583.0},"pinned":true,"removed":true,"modelId":15781,"author":"xxx2","icon":"icons/comment.png","id":4939,"title":"Comment (coord: 484.28, 583.00)","type":"POINT","content":"","email":""},{"elementId":"144.01,518.00","coord":{"x":144.01,"y":518.0},"pinned":true,"removed":true,"modelId":15781,"author":"xxx","icon":"icons/comment.png","id":4938,"title":"Comment (coord: 144.01, 518.00)","type":"POINT","content":"","email":""},{"elementId":153503,"coord":{"x":888.3333333333334,"y":66.9999999999998},"pinned":true,"removed":true,"modelId":15781,"author":"1","icon":"icons/comment.png","id":4674,"title":"Reaction re27","type":"REACTION","content":"","email":"2"},{"elementId":329178,"coord":{"x":735.0,"y":259.0},"pinned":true,"removed":true,"modelId":15781,"author":"","icon":"icons/comment.png","id":4673,"title":"s23","type":"ALIAS","content":"","email":""},{"elementId":"224.30,556.00","coord":{"x":224.3,"y":556.0},"pinned":false,"removed":false,"modelId":15781,"author":"admin ","icon":"icons/comment.png","id":4947,"title":"Comment (coord: 224.30, 556.00)","type":"POINT","content":"x","email":"piotr.gawron@uni.lu"},{"elementId":"291.84,559.00","coord":{"x":291.84,"y":559.0},"pinned":false,"removed":false,"modelId":15781,"author":"admin ","icon":"icons/comment.png","id":4948,"title":"Comment (coord: 291.84, 559.00)","type":"POINT","content":"x","email":"piotr.gawron@uni.lu"},{"elementId":"345.37,546.00","coord":{"x":345.37,"y":546.0},"pinned":false,"removed":false,"modelId":15781,"author":"admin ","icon":"icons/comment.png","id":4949,"title":"Comment (coord: 345.37, 546.00)","type":"POINT","content":"y","email":"piotr.gawron@uni.lu"},{"elementId":"458.79,598.00","coord":{"x":458.79,"y":598.0},"pinned":false,"removed":false,"modelId":15781,"author":"admin ","icon":"icons/comment.png","id":4950,"title":"Comment (coord: 458.79, 598.00)","type":"POINT","content":"z","email":"piotr.gawron@uni.lu"},{"elementId":"786.31,586.00","coord":{"x":786.31,"y":586.0},"pinned":false,"removed":false,"modelId":15781,"author":"admin ","icon":"icons/comment.png","id":4951,"title":"Comment (coord: 786.31, 586.00)","type":"POINT","content":"q","email":"piotr.gawron@uni.lu"},{"elementId":"570.94,474.00","coord":{"x":570.94,"y":474.0},"pinned":true,"removed":false,"modelId":15781,"author":"admin ","icon":"icons/comment.png","id":4952,"title":"Comment (coord: 570.94, 474.00)","type":"POINT","content":"p","email":"piotr.gawron@uni.lu"},{"elementId":"607.90,463.00","coord":{"x":607.9,"y":463.0},"pinned":true,"removed":false,"modelId":15781,"author":" s","icon":"icons/comment.png","id":4956,"title":"Comment (coord: 607.90, 463.00)","type":"POINT","content":"","email":""},{"elementId":"607.90,463.00","coord":{"x":607.9,"y":463.0},"pinned":true,"removed":false,"modelId":15781,"author":" s","icon":"icons/comment.png","id":4957,"title":"Comment (coord: 607.90, 463.00)","type":"POINT","content":"","email":""},{"elementId":"607.90,463.00","coord":{"x":607.9,"y":463.0},"pinned":true,"removed":false,"modelId":15781,"author":" s","icon":"icons/comment.png","id":4958,"title":"Comment (coord: 607.90, 463.00)","type":"POINT","content":"asd","email":""},{"elementId":"1199.22,26.00","coord":{"x":1199.22,"y":26.0},"pinned":true,"removed":false,"modelId":15781,"author":" x","icon":"icons/comment.png","id":4959,"title":"Comment (coord: 1199.22, 26.00)","type":"POINT","content":"","email":""},{"elementId":"71.37,36.00","coord":{"x":71.37,"y":36.0},"pinned":false,"removed":false,"modelId":15781,"author":"admin ","icon":"icons/comment.png","id":4961,"title":"Comment (coord: 71.37, 36.00)","type":"POINT","content":"test","email":"piotr.gawron@uni.lu"},{"elementId":329173,"coord":{"x":52.0,"y":26.0},"pinned":false,"removed":false,"modelId":15781,"author":"admin ","icon":"icons/comment.png","id":4962,"title":"s1","type":"ALIAS","content":"test","email":""},{"elementId":329179,"coord":{"x":205.0,"y":68.0},"pinned":false,"removed":false,"modelId":15781,"author":"admin ","icon":"icons/comment.png","id":4963,"title":"s2","type":"ALIAS","content":"test2","email":""},{"elementId":329157,"coord":{"x":329.0,"y":59.0},"pinned":true,"removed":false,"modelId":15781,"author":"admin ","icon":"icons/comment.png","id":4964,"title":"s3","type":"ALIAS","content":"test3","email":"piotr.gawron@uni.lu"},{"elementId":153510,"coord":{"x":128.5,"y":47.0},"pinned":false,"removed":false,"modelId":15781,"author":"admin ","icon":"icons/comment.png","id":4965,"title":"Reaction re5","type":"REACTION","content":"xxx","email":"piotr.gawron@uni.lu"},{"elementId":"477.91,184.00","coord":{"x":477.91,"y":184.0},"pinned":false,"removed":false,"modelId":15781,"author":"","icon":"icons/comment.png","id":4966,"title":"Comment (coord: 477.91, 184.00)","type":"POINT","content":"","email":""}] \ No newline at end of file