From 4a3ad4c2971ec200fdf8f8bef26712e6e7ff487e Mon Sep 17 00:00:00 2001 From: Eason010212 <1371033826@qq.com> Date: Thu, 31 Aug 2023 22:16:12 +0800 Subject: [PATCH] August-New-Widget --- icons/camera.svg | 1 + icons/database.svg | 1 + icons/mic.svg | 1 + js/lang.js | 25 +- js/projects.js | 158 ++++++-- js/widgets.js | 964 +++++++++++++++++++++++++++++++++++++++++---- 6 files changed, 1042 insertions(+), 108 deletions(-) create mode 100644 icons/camera.svg create mode 100644 icons/database.svg create mode 100644 icons/mic.svg diff --git a/icons/camera.svg b/icons/camera.svg new file mode 100644 index 0000000..409b92c --- /dev/null +++ b/icons/camera.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/database.svg b/icons/database.svg new file mode 100644 index 0000000..237d56f --- /dev/null +++ b/icons/database.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/mic.svg b/icons/mic.svg new file mode 100644 index 0000000..0924cd5 --- /dev/null +++ b/icons/mic.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/js/lang.js b/js/lang.js index 4378be2..8ee4ea7 100644 --- a/js/lang.js +++ b/js/lang.js @@ -25,7 +25,7 @@ var JSLang = { "editProper": "修改项目属性", "viewProject": "查看和编辑项目内容", "illegalCycle": "逻辑视图中存在循环方法,不允许后台运行", - "codeException": "代码内部存在错误", + "codeException": "当前项目的逻辑视图存在无法在后台运行的内容", "loading": "加载中", "loading2": "更改中", "wrongAcc": "用户名或密码错误", @@ -97,7 +97,7 @@ var JSLang = { "widget": "组件", "data": "- 数据 -", "lineChart": "折线图表", - "barChart": "柱状图表", + "barChart": "投票器", "dataTable": "数据表格", "dataMap": "数据地图", "dashboard": "仪表盘", @@ -208,7 +208,12 @@ var JSLang = { "invalidUType": "不正确的组件类别。", "noUnitFound": "未找到组件。", "platformList": "已登录平台", - "deviceList": "已连接设备" + "deviceList": "已连接设备", + "camera": "摄像头", + "mic": "麦克风", + "tinydb": "数据库", + "resolution": "分辨率", + "fps": "帧率" }, "tw": { "syncInterval": "自動更新頻率", @@ -419,7 +424,12 @@ var JSLang = { "invalidUType": "不正確的組件類別。", "noUnitFound": "未找到組件。", "platformList": "已登錄平台", - "deviceList": "已連接設備" + "deviceList": "已連接設備", + "camera": "攝像頭", + "mic": "麥克風", + "tinydb": "數據庫", + "resolution": "分辨率", + "fps": "幀率" }, "en": { "syncInterval": "Auto-sync", @@ -630,7 +640,12 @@ var JSLang = { "invalidUType": "Invalid unit type.", "noUnitFound": "The unit does not exist", "platformList": "Platforms", - "deviceList": "Devices" + "deviceList": "Devices", + "camera": "Camera", + "mic": "Microphone", + "tinydb": "Database", + "resolution": "Resolution", + "fps": "FPS" } } diff --git a/js/projects.js b/js/projects.js index 8ab894d..a8dace5 100644 --- a/js/projects.js +++ b/js/projects.js @@ -511,9 +511,13 @@ function shareKey() { } function switch_mode() { + grid.on("contextmenu", function(e) { + e.preventDefault() + }) grid.removeAttr("hidden") grid2.removeAttr("hidden") grid3.removeAttr("hidden") + if (globalProjectType == DATA_MODE) { $("#projMode").removeClass("btn-primary") $("#projMode").addClass("btn-light") @@ -699,6 +703,8 @@ function view_project(projectName, projectType) { } }) MixIO.log = function(text) { + if(typeof text == "object") + text = JSON.stringify(text) if (jTa2.html()) jTa2.html(jTa2.html() + '
' + '[' + timeStamp2String().substring(11) + '] ' + text) else @@ -895,6 +901,8 @@ function view_project(projectName, projectType) { } else if (topic1.split('/').length == 3 && !isMixly) { var tp = stringendecoder.encodeHtml(topic1.split('/')[2]) var ms = message1.toString() + if(ms.length>500) + ms = "[Too long to display]" if(isJSON(ms)) { var msJSON = JSON.parse(ms) @@ -948,6 +956,8 @@ function view_project(projectName, projectType) { } else if (topic1.split('/').length == 4 && isMixly) { var tp = stringendecoder.encodeHtml(topic1.split('/')[3]) var ms = message1.toString() + if(ms.length>500) + ms = "[Too long to display]" if(isJSON(ms)) { var msJSON = JSON.parse(ms) @@ -1010,6 +1020,14 @@ function view_project(projectName, projectType) { var units_array = $(prev_layout) for (var ct = 0; ct <= units_array.length - 1; ct = ct + 1) { var un = $(units_array[ct]) + var titleHidden = un.attr('title-hidden') + // if no title-hidden attribute, set it to false + if (titleHidden == undefined) + titleHidden = false + if (titleHidden == "true") + titleHidden = true + if (titleHidden == "false") + titleHidden = false var toolkits = { 'input_button': add_button, 'input_slider': add_slider, @@ -1030,9 +1048,10 @@ function view_project(projectName, projectType) { 'decorate_text': add_decorate_text, 'decorate_pic': add_decorate_pic, 'timer': add_timer, - 'ble': add_ble + 'ble': add_ble, + 'camera': add_camera } - toolkits[un.attr('user-type')](un.attr('user-title'), un.attr('user-topic'), un.attr('user-content'), un.attr('style')) + toolkits[un.attr('user-type')](un.attr('user-title'), un.attr('user-topic'), un.attr('user-content'), un.attr('style'), titleHidden) } var topicOuterDiv = $("
") var topicDiv = $("
") @@ -1685,6 +1704,12 @@ function add_widget() { widget_list.append(output_dashboard_add) var input_weather_add = $("
" + JSLang[lang].weather + "
") widget_list.append(input_weather_add) + var input_camera_add = $("
" + JSLang[lang].camera + "
") + widget_list.append(input_camera_add) + var input_mic_add = $("
" + JSLang[lang].mic + "
") + widget_list.append(input_mic_add) + var input_tinydb_add = $("
" + JSLang[lang].tinydb + "
") + widget_list.append(input_tinydb_add) widget_list.append($("
" + JSLang[lang].text + "
")) var input_keyboard_add = $("
" + JSLang[lang].keyboard + "
") widget_list.append(input_keyboard_add) @@ -1763,7 +1788,7 @@ function add_widget() { var confirmEdit = $('') bottomDiv.append(confirmEdit) confirmEdit.click(function() { - if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 11) { + if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 21) { var re = /^[a-z0-9]+$/i; if (getByteLen(topic_input.val()) > 0 && getByteLen(topic_input.val()) < 11 && getByteLen(topic_input_2.val()) > 0 && getByteLen(topic_input_2.val()) < 11) if (true) { @@ -1793,6 +1818,71 @@ function add_widget() { modifyDia.showModal() }) + input_camera_add.children("a").click(function() { + d.close().remove() + var editForm = $('
') + editForm.append($('
')) + editForm.append($('
' + JSLang[lang].unitName + '
')) + var title_input_div = $('
') + var title_input = $("") + title_input_div.append(title_input) + editForm.append(title_input_div) + editForm.append($('
' + JSLang[lang].messTopic + '
')) + var topic_input_div = $('
') + var topic_input = $("") + topic_input_div.append(topic_input) + topic_input.val("camera") + editForm.append(topic_input_div) + // resolution selection + editForm.append($('
' + JSLang[lang].resolution + '
')) + var resolution_input_div = $('
') + var resolution_input = $("") + fps_input_div.append(fps_input) + fps_input.append($("")) + fps_input.append($("")) + editForm.append(fps_input_div) + var bottomDiv = $('
') + var confirmEdit = $('') + bottomDiv.append(confirmEdit) + confirmEdit.click(function() { + if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 21) { + var re = /^[a-z0-9]+$/i; + if (getByteLen(topic_input.val()) > 0 && getByteLen(topic_input.val()) < 11) + if (true) { + if (countSubstr(grid.html(), 'user-title=\"' + title_input.val() + '\"', false) <= 0) { + add_camera(title_input.val(), topic_input.val(), resolution_input.val() + "," + fps_input.val()) + modifyDia.close().remove() + } else + showtext(JSLang[lang].sameUnit) + } else + showtext("") + else + showtext(JSLang[lang].topicLenIllegal) + } else + showtext(JSLang[lang].nameLenIllegal) + }) + var cancelEdit = $('') + cancelEdit.click(function() { + modifyDia.close().remove() + add_widget() + }) + bottomDiv.append(cancelEdit) + editForm.append(bottomDiv) + var modifyDia = dialog({ + content: editForm[0], + cancel: false + }) + modifyDia.showModal() + }) + output_pixel_add.children("a").click(function() { d.close().remove() var editForm = $('
') @@ -1824,7 +1914,7 @@ function add_widget() { xpixel_input.val(30) ypixel_input.val(20) confirmEdit.click(function() { - if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 11) { + if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 21) { var re = /^[a-z0-9]+$/i; if (getByteLen(topic_input.val()) > 0 && getByteLen(topic_input.val()) < 11) if (xpixel_input.val() > 0 && xpixel_input.val() < 101 && ypixel_input.val() > 0 && ypixel_input.val() < 101) { @@ -1891,7 +1981,7 @@ function add_widget() { var confirmEdit = $('') bottomDiv.append(confirmEdit) confirmEdit.click(function() { - if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 11) { + if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 21) { var re = /^[a-z0-9]+$/i; if (getByteLen(topic_input.val()) > 0 && getByteLen(topic_input.val()) < 11) if (true) { @@ -1958,7 +2048,7 @@ function add_widget() { var confirmEdit = $('') bottomDiv.append(confirmEdit) confirmEdit.click(function() { - if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 11) { + if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 21) { var re = /^[a-z0-9]+$/i; if (getByteLen(topic_input.val()) > 0 && getByteLen(topic_input.val()) < 11) if (true) { @@ -2007,7 +2097,7 @@ function add_widget() { var confirmEdit = $('') bottomDiv.append(confirmEdit) confirmEdit.click(function() { - if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 11) { + if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 21) { var re = /^[a-z0-9]+$/i; if (getByteLen(topic_input.val()) > 0 && getByteLen(topic_input.val()) < 11) if (true) { @@ -2074,7 +2164,7 @@ function add_widget() { var confirmEdit = $('') bottomDiv.append(confirmEdit) confirmEdit.click(function() { - if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 11) { + if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 21) { var re = /^[a-z0-9]+$/i; if (getByteLen(topic_input.val()) > 0 && getByteLen(topic_input.val()) < 11) if (true) { @@ -2123,7 +2213,7 @@ function add_widget() { var confirmEdit = $('') bottomDiv.append(confirmEdit) confirmEdit.click(function() { - if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 11) { + if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 21) { var re = /^[a-z0-9]+$/i; if (getByteLen(topic_input.val()) > 0 && getByteLen(topic_input.val()) < 11) if (true) { @@ -2184,7 +2274,7 @@ function add_widget() { var confirmEdit = $('') bottomDiv.append(confirmEdit) confirmEdit.click(function() { - if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 11) { + if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 21) { var re = /^[a-z0-9]+$/i; if (getByteLen(Rtopic_input.val()) > 0 && getByteLen(Rtopic_input.val()) < 11 && getByteLen(Gtopic_input.val()) > 0 && getByteLen(Gtopic_input.val()) < 11 && getByteLen(Btopic_input.val()) > 0 && getByteLen(Btopic_input.val()) < 11) if (re.test(Rtopic_input.val()) && re.test(Gtopic_input.val()) && re.test(Btopic_input.val())) { @@ -2301,7 +2391,7 @@ function add_widget() { if (placecode == "unselected") showtext(JSLang[lang].locationSet) else { - if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 11) { + if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 21) { var re = /^[a-z0-9]+$/i; if (getByteLen(topic_input.val()) > 0 && getByteLen(topic_input.val()) < 11) if (true) { @@ -2351,7 +2441,7 @@ function add_widget() { var confirmEdit = $('') bottomDiv.append(confirmEdit) confirmEdit.click(function() { - if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 11) { + if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 21) { var re = /^[a-z0-9]+$/i; if (getByteLen(topic_input.val()) > 0 && getByteLen(topic_input.val()) < 11) if (true) { @@ -2417,7 +2507,7 @@ function add_widget() { var confirmEdit = $('') bottomDiv.append(confirmEdit) confirmEdit.click(function() { - if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 11) { + if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 21) { var re = /^[a-z0-9]+$/i; if (getByteLen(topic_input.val()) > 0 && getByteLen(topic_input.val()) < 11) if (getByteLen(message_input.val()) > 0) { @@ -2523,7 +2613,7 @@ function add_widget() { var confirmEdit = $('') bottomDiv.append(confirmEdit) confirmEdit.click(function() { - if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 11) { + if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 21) { var re = /^[a-z0-9]+$/i; if (getByteLen(topic_input.val()) > 0 && getByteLen(topic_input.val()) < 11) if (getByteLen(condition1_input2.val()) > 0 && (condition2_input1.val() == "--" || getByteLen(condition2_input2.val()) > 0)) { @@ -2584,7 +2674,7 @@ function add_widget() { var confirmEdit = $('') bottomDiv.append(confirmEdit) confirmEdit.click(function() { - if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 11) { + if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 21) { add_magic(title_input.val(), undefined, color_select.val()) modifyDia.close().remove() } @@ -2624,7 +2714,7 @@ function add_widget() { var confirmEdit = $('') bottomDiv.append(confirmEdit) confirmEdit.click(function() { - if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 11) { + if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 21) { var re = /^[a-z0-9]+$/i; if (getByteLen(topic_input.val()) > 0 && getByteLen(topic_input.val()) < 11) if (true) { @@ -2679,7 +2769,7 @@ function add_widget() { var confirmEdit = $('') bottomDiv.append(confirmEdit) confirmEdit.click(function() { - if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 11) { + if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 21) { var re = /^[a-z0-9]+$/i; if (getByteLen(topic_input.val()) > 0 && getByteLen(topic_input.val()) < 11) if (true) { @@ -2743,7 +2833,7 @@ function add_widget() { var confirmEdit = $('') bottomDiv.append(confirmEdit) confirmEdit.click(function() { - if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 11) { + if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 21) { var re = /^[a-z0-9]+$/i; if (getByteLen(topic_input.val()) > 0 && getByteLen(topic_input.val()) < 11) if (true) { @@ -2811,7 +2901,7 @@ function add_widget() { bottomDiv.append(confirmEdit) confirmEdit.click(function() { if (option_input.val() != "") { - if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 11) { + if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 21) { var re = /^[a-z0-9]+$/i; if (getByteLen(topic_input.val()) > 0 && getByteLen(topic_input.val()) < 11) if (true) { @@ -2878,7 +2968,7 @@ function add_widget() { var confirmEdit = $('') bottomDiv.append(confirmEdit) confirmEdit.click(function() { - if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 11) { + if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 21) { var re = /^[a-z0-9]+$/i; if (getByteLen(topic_input.val()) > 0 && getByteLen(topic_input.val()) < 11) if (true) { @@ -2932,7 +3022,7 @@ function add_widget() { var confirmEdit = $('') bottomDiv.append(confirmEdit) confirmEdit.click(function() { - if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 11) { + if (getByteLen(title_input.val()) > 0 && getByteLen(title_input.val()) < 21) { var re = /^[a-z0-9]+$/i; if (getByteLen(topic_input.val()) > 0 && getByteLen(topic_input.val()) < 11) if (true) { @@ -3001,11 +3091,17 @@ function add_widget() { var text_input = $("