diff --git a/ejs/observe.ejs b/ejs/observe.ejs index 7427be3..c002c07 100644 --- a/ejs/observe.ejs +++ b/ejs/observe.ejs @@ -39,9 +39,9 @@
diff --git a/js/observe.js b/js/observe.js index ee0232a..058e6a7 100644 --- a/js/observe.js +++ b/js/observe.js @@ -151,4 +151,116 @@ $(function() { } }) } -}) \ No newline at end of file +}) + +function open_storage(){ + var editForm = $('
') + editForm.append($('
')) + editForm.append($('

所有发送到/storage主题下的消息和图片会被自动保存

')) + var messagesContainer = $('
') + var sync_stor = function(){ + messagesContainer.empty() + var sampleMessages = [ + ] + $.getJSON('getImgStore', { + 'projectName': globalProjectName + }, function(res) { + if(res.length==0) + { + messagesContainer.append($('
暂无存储
')) + } + for (let ri = 0; ri < res.length; ri++) { + { + let url = "store/" + globalUserName + "/" + globalProjectName + "/" + res[ri] + if (url.endsWith('.txt')) { + sampleMessages.push({ type: 'text', content: url }) + } else{ + sampleMessages.push({ type: 'image', content: url }) + } + } + } + for(let ji = 0; ji < sampleMessages.length; ji++) { + let msg = sampleMessages[ji] + let messageBox = $('
') + + if (msg.type === 'text') { + $.ajax({ + url: msg.content, + success: function(res) { + messageBox.append($('
').text(res)) + // Add timestamp (sample) + let timeStamp = parseInt(msg.content.split("/")[msg.content.split("/").length - 1].split(".")[0]) + let timeString = new Date(timeStamp).toLocaleString() + let btdiv = $('
') + btdiv.append("" + timeString +"") + let deletebtn = $('') + deletebtn.click(function(){ + $.getJSON('deleteImgStore', { + 'projectName': globalProjectName, + 'filename': msg.content.split("/")[msg.content.split("/").length - 1] + }, function(){ + sync_stor() + }) + }) + btdiv.append(deletebtn) + messageBox.append(btdiv) + } + }) + } else if (msg.type === 'image') { + messageBox.append($('
')) + // Add timestamp (sample) + let timeStamp = parseInt(msg.content.split("/")[msg.content.split("/").length - 1].split(".")[0]) + let timeString = new Date(timeStamp).toLocaleString() + let btdiv = $('
') + btdiv.append("" + timeString +"") + let viewbtn = $('') + viewbtn.click(function(){ + // 全屏显示图片,点击任意退出 + let fullDialog = dialog({ + content: $('
')[0], + cancel: true, + cancelValue: '关闭' + }) + fullDialog.showModal() + + }) + let deletebtn = $('') + deletebtn.click(function(){ + $.getJSON('deleteImgStore', { + 'projectName': globalProjectName, + 'filename': msg.content.split("/")[msg.content.split("/").length - 1] + }, function(){ + sync_stor() + }) + }) + btdiv.append(viewbtn) + btdiv.append(deletebtn) + messageBox.append(btdiv) + } + messagesContainer.prepend(messageBox) + } + }) + } + editForm.append(messagesContainer) + sync_stor() + client.on('message', function(topic, msg) { + if(topic.split("/")[2] == "storage") + sync_stor() + }) + // Bottom section + var bottomDiv = $('
') + var cancelEdit = $('') + bottomDiv.append(cancelEdit) + editForm.append(bottomDiv) + + var modifyDia = dialog({ + content: editForm[0], + cancel: false + }) + + cancelEdit.click(function() { + modifyDia.close().remove() + }) + + modifyDia.showModal() +} \ No newline at end of file