Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/1.4.2 #423

Merged
merged 44 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
4e9a4d3
fix(timeMsg): stopTimer when topic is null or publish failed
0721Betty Nov 27, 2020
3eb1ec7
Links Update
duyuxuan Nov 27, 2020
ab7d8f4
japanese translation improvement
duyuxuan Nov 27, 2020
ceedaee
delete br
duyuxuan Nov 27, 2020
90ad0ae
chore(package): remove purge css package
ysfscream Dec 4, 2020
51a8476
feat(script): add edit script page
ysfscream Dec 5, 2020
632495a
feat(editor): add qucik save shortcut
ysfscream Dec 5, 2020
e4590d4
feat(script): add api of the script
ysfscream Dec 7, 2020
a241170
docs(manual): update contact information
ysfscream Dec 8, 2020
874778d
refactor(types): replace require to import
ysfscream Dec 10, 2020
59d1719
feat(script): add use script method
ysfscream Dec 11, 2020
bd59b25
refactor(script): add convert payload by script method
ysfscream Dec 11, 2020
b6b5779
feat(script): add script message prompt
ysfscream Dec 11, 2020
5919556
fix(timeMsg): stopTimer when topic is null or publish failed
0721Betty Nov 27, 2020
ff252d9
Links Update
duyuxuan Nov 27, 2020
96fb2fa
japanese translation improvement
duyuxuan Nov 27, 2020
7aa018d
delete br
duyuxuan Nov 27, 2020
eaf62ae
chore(deps): bump ini from 1.3.5 to 1.3.8
ysfscream Dec 14, 2020
4f993a0
Merge branch 'ysf/mqttx' into dev/1.4.2
ysfscream Dec 14, 2020
c2fc943
chore(package): v1.4.1 -> v1.4.2
ysfscream Dec 14, 2020
2fd1b3e
feat(connection): support optional MQTT connection config, append tim…
oceanlvr Dec 10, 2020
1feb9f9
feat(connections): support append timestamp into clientID for 'connec…
oceanlvr Dec 14, 2020
019b0be
fix(connections): fix can not init payload editor
ysfscream Dec 14, 2020
8ec70da
fix(connections): adjust icon style for 'ConnectionInfo.vue'
oceanlvr Dec 14, 2020
77ba6e7
additional word translation
duyuxuan Dec 14, 2020
f381dc9
fix(connections): fix the unread message count is NaN problem
ysfscream Dec 15, 2020
b255b68
feat(messageList): added pull-up & loading function to messageList & …
0721Betty Dec 15, 2020
aea25e6
refactor(script): refactor script to store state
ysfscream Dec 15, 2020
c1baa22
feat(script): add keyup enter method
ysfscream Dec 15, 2020
b56cfe1
fix(messageList): fix the animation of adding a message
0721Betty Dec 15, 2020
e7eebf7
fix(msgList): fix showMessages value when has search conditions
0721Betty Dec 16, 2020
e1a124c
feat(script): add route to script page on connection page
ysfscream Dec 16, 2020
3c2181a
docs(readme): update mqttx preview image
ysfscream Dec 16, 2020
7596e86
fix(msgList): split showMsgs when received much msgs in one second
0721Betty Dec 16, 2020
ebade9c
fix(connections): fix setMessageListHeight of undefined
ysfscream Dec 16, 2020
50cc064
feature(connections): disable ConnectionInfo table editing when clien…
oceanlvr Dec 14, 2020
d16e2aa
refactor(connection): split function to getter & format code.
oceanlvr Dec 14, 2020
e3ac7e4
feature(connections): disable ConnectionInfo table editing when clien…
oceanlvr Dec 16, 2020
e7a1f1f
docs(manual): update manual
ysfscream Dec 17, 2020
34cd7be
docs(manual): add script example file
ysfscream Dec 17, 2020
ed0b7b1
docs(manual): update manual
ysfscream Dec 17, 2020
bc0fb45
refactor(subscriptions): improve the error message comes from MQTT br…
oceanlvr Dec 17, 2020
6e2b1d5
refactor(lang): add the subscriptions error message
oceanlvr Dec 17, 2020
799c291
refactor(subscriptions): move 'SubscribeErrorReason' to type file, re…
oceanlvr Dec 17, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README-JP.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

## 利用方法

詳細な利用方法については、[ブログ](https://www.emqx.io/blog/mqtt-x-guideline)または[ユーザーマニュアル](./docs/manual.md)を確認してください。
詳細な利用方法については、[ブログ](https://qiita.com/emqx_japan/items/1ff6097fdfe273c5e22f)または[ユーザーマニュアル](./docs/manual-jp.md)を確認してください。

1. MQTT Brokerの準備。

Expand Down
Binary file added assets/emqx_wx.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/mqttx-preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/mqttx-script.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 23 additions & 1 deletion docs/manual-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,24 @@ sudo snap install mqttx

![mqttx-advance](../assets/mqttx-advance.png)

### 脚本

在 v1.4.2 版本以后,MQTT X 新增了脚本编辑功能,在该功能中,用户可编写自定义脚本(JavaScript)对发送和接收到的 `Payload` 进行自定义转化,配合定时发送功能,可实现一些模拟数据上报的自动化测试功能。

> 注意:该功能目前属于测试 Beta 阶段。

点击左侧菜单栏中的 `脚本` 按钮,可进入到脚本编辑页面,在该页面中,用户可在最上方的代码编辑器中,编写 JavaScript 代码,全局只包含一个 `execute` API,用户需要编写一个脚本函数,该函数接收一个 `value` 参数,即为 `Payload`, 函数中便可对 `value` 进行自定义修改转化,最后将该函数作为参数传入到 `execute` 中即可执行自定义编写的函数。

下方还包含了一个 `输入` 和 `输出` 框,可输入预想输入值,点击右边的 `测试` 按钮,便可在 `输出` 框中查看执行结果,输入的值的格式包含了 `JSON` 和 `Plaintext`,方便用户提前调试自定义编写的脚本功能。完成测试后,可点击最右上角的 `保存` 按钮,输入该脚本的名称后就可对该脚本进行保存。保存完成后就可以到连接页面进行使用了。保存完成的脚本还可进行编辑和删除。

在连接页面中,点击右上角的下拉功能菜单,选择 `使用脚本`,在弹出窗中,选择你需要使用的预先保存好的脚本,然后选择应用类型,包含了,发送时,接收时和全部。选择完成后,根据数据类型选择发送或接收的数据格式,正常使用消息的收发,此时如果看到预期效果,便完成了一个完整的脚本使用的功能。如果用户需要取消脚本,可点击顶部状态栏中的红色的 `停止脚本` 按钮,便可停止使用脚本。

该功能具有一定的扩展性和灵活性,需用户配合实际需求来进行使用。

![mqttx-script](../assets/mqttx-script.png)

脚本使用实例可在 [/docs/script-example](https://github.com/emqx/MQTTX/tree/master/docs/script-example) 文件夹中查看,目前提供了两个内置脚本,时间戳转化和温湿度数据模拟。如果在您的使用中有更好的,更实用的脚本也可以提交您的代码到这里,方便让更多的人使用到。

### 其它

1. 连接操作
Expand Down Expand Up @@ -263,4 +281,8 @@ Linux: `vue-cli-service electron:build --linux`
| 方式 | 内容 |
| ---- | ---- |
| QQ 群(EMQ X 官方群3)| 937041105 |
| EMQ X 官方公众号 | <img src="../assets/wx_qr_code.png" width="160" alt="MQTTX Logo"/> |
| EMQ X 官方公众号 | <img src="../assets/wx_qr_code.png" width="160" alt="WeChat QR code"/> |
| EMQ X 微信群(扫码添加后邀请入群)| <img src="../assets/emqx_wx.jpeg" width="160" alt="EMQ X Wechat"/> |
| 微博 | [@emqtt](https://weibo.com/emqtt) |
| Twitter | [@emqtt](https://twitter.com/emqtt/) |
| Slack | [EMQ X](https://slack-invite.emqx.io/) |
18 changes: 18 additions & 0 deletions docs/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,24 @@ In the settings page, you can choose to click the data backup and data recovery

![mqttx-advance](../assets/mqttx-advance.png)

### Script

After the v1.4.2 version, MQTT X has added a script editing function. In this function, users can write custom scripts (JavaScript) to perform custom conversions on sent and received `Payload`. With the timing sending function, realize the automated test function for the simulation data report.

> Note: This feature is test feature in the beta stage

Click the `script` button in the menu bar on the left to enter the script editing page. In this page, users can write JavaScript code in the code editor at the top. There is only one `execute` API globally, and the user needs write a script function that receives a `value` parameter, which is `Payload`, and the function can be customized to modify the `value`, and finally the function can be executed by passing it as a parameter to the `execute` custom-written functions.

There is also an `input` and `output` box below. You can enter the expected input value. Click the `test` button on the right to view the execution result in the `output` box. The format of the input value includes `JSON` With `Plaintext`, it is convenient for users to debug custom-written script functions in advance. After completing the test, you can click the `Save` button in the upper right corner and enter the name of the script to save the script. After saving, you can go to the connection page for use. The saved script can also be edited and deleted.

In the connection page, click the drop-down menu in the upper right corner, select `Use script`, in the pop-up window, select the pre-saved script you need to use, and then select the script to be applied, including: Published, Received, and All. After the selection is completed, select the data format to be sent or received according to the data type, and use the message sending and receiving normally. At this time, if the expected effect is seen, a script function is completed. If the user needs to cancel the script, you can click the red `Stop script` button in the top status bar to stop using the script.

This function is scalable and flexible, and requires users to cooperate with actual needs to use it.

![mqttx-script](../assets/mqttx-script.png)

The script usage examples can be viewed in the [/docs/script-example](https://github.com/emqx/MQTTX/tree/master/docs/script-example) folder. Currently, two built-in scripts are provided, timestamp conversion and temperature and humidity data simulation. If you have a better and more practical script in your use, you can submit your code here, so that more people can use it.

### Others

1. Connection operation
Expand Down
21 changes: 21 additions & 0 deletions docs/script-example/tempAndHum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Simulated temperature and humidity reporting
* @return Return a simulated temperature and humidity JSON data - { "temperature": 23, "humidity": 40 }
* @param value, MQTT Payload - {}
*/

function random(min, max) {
return Math.round(Math.random() * (max - min)) + min
}

function handlePayload(value) {
let _value = value
if (typeof value === 'string') {
_value = JSON.parse(value)
}
_value.temperature = random(10, 30)
_value.humidity = random(20, 40)
return JSON.stringify(_value, null, 2)
}

execute(handlePayload)
18 changes: 18 additions & 0 deletions docs/script-example/timestamp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Convert timestamp to normal time.
* @return Return the UTC time - { "time": "2020-12-17 14:18:07" }
* @param value, MQTT Payload - { "time": 1608185887 }
*/

function handleTimestamp(value) {
let _value = value
if (typeof value === 'string') {
_value = JSON.parse(value)
}
// East Eight District needs an additional 8 hours
const date = new Date(_value.time * 1000 + 8 * 3600 * 1000)
_value.time = date.toJSON().substr(0, 19).replace('T', ' ')
return JSON.stringify(_value, null, 2)
}

execute(handleTimestamp)
12 changes: 3 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "MQTTX",
"version": "1.4.1",
"version": "1.4.2",
"description": "MQTT desktop client",
"author": "EMQ X Team",
"scripts": {
Expand Down Expand Up @@ -39,11 +39,10 @@
"vuex": "^3.0.1",
"vuex-class": "^0.3.2",
"xlsx": "^0.16.8",
"xml-js": "^1.6.11"
"xml-js": "^1.6.11",
"vm2": "latest"
},
"devDependencies": {
"@fullhuman/postcss-purgecss": "^2.1.0",
"@fullhuman/vue-cli-plugin-purgecss": "~2.2.0",
"@types/chai": "^4.1.0",
"@types/chart.js": "^2.9.28",
"@types/fs-extra": "^8.0.0",
Expand Down Expand Up @@ -76,11 +75,6 @@
"vue-cli-plugin-electron-builder": "^1.4.6",
"vue-template-compiler": "^2.6.12"
},
"postcss": {
"plugins": {
"autoprefixer": {}
}
},
"browserslist": [
"> 1%",
"last 2 versions"
Expand Down
16 changes: 3 additions & 13 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
const IN_PRODUCTION = process.env.NODE_ENV === 'production'

module.exports = {
plugins: [
IN_PRODUCTION && require('@fullhuman/postcss-purgecss')({
content: [`./public/**/*.html`, `./src/**/*.vue`, `./src/**/*.scss`],
defaultExtractor (content) {
const contentWithoutStyleBlocks = content.replace(/<style[^]+?<\/style>/gi, '')
return contentWithoutStyleBlocks.match(/[A-Za-z0-9-_/:]*[A-Za-z0-9-_/]+/g) || []
},
whitelist: [],
whitelistPatterns: [ /-(leave|enter|appear)(|-(to|from|active))$/, /^(?!(|.*?:)cursor-move).+-move$/, /^router-link(|-exact)-active$/, /data-v-.*/ ],
})
],
plugins: {
autoprefixer: {},
},
}
22 changes: 22 additions & 0 deletions src/api/script.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import db from '@/database/index'
import { ScriptModel } from '@/views/script/types'

export const createScript = (data: ScriptModel): ScriptModel => {
return db.insert<ScriptModel>('scripts', data)
}

export const loadScripts = (): ScriptModel[] | [] => {
return db.get<ScriptModel[] | []>('scripts')
}

export const deleteScript = (id: string): ScriptModel => {
return db.remove<ScriptModel>('scripts', id)
}

export const updateScript = (id: string, data: ScriptModel): ScriptModel => {
return db.update<ScriptModel>('scripts', id, data)
}

export const loadScript = (id: string): ScriptModel => {
return db.find<ScriptModel>('scripts', id)
}
140 changes: 88 additions & 52 deletions src/assets/font/iconfont.css

Large diffs are not rendered by default.

Binary file modified src/assets/font/iconfont.eot
Binary file not shown.
60 changes: 59 additions & 1 deletion src/assets/font/iconfont.js

Large diffs are not rendered by default.

Loading