@fmsim/machine 0.0.68 → 0.0.69

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,141 +0,0 @@
1
- import { SubscriptionClient } from '@things-factory/restful-subscriptions-transport-ws'
2
- import { Component, ComponentNature, DataSource, RectPath, Shape } from '@hatiolab/things-scene'
3
- import { getRestServiceFullPath } from '@fmsim/api/restful.js'
4
-
5
- const COMPONENT_IMAGE = new URL('../icons/symbol-data-subscription.png', import.meta.url).href
6
-
7
- const NATURE: ComponentNature = {
8
- mutable: false,
9
- resizable: true,
10
- rotatable: true,
11
- properties: [
12
- {
13
- type: 'string',
14
- label: 'tag',
15
- name: 'tag'
16
- }
17
- ],
18
- 'value-property': 'tag',
19
- help: 'scene/component/data-subscription'
20
- }
21
-
22
- export default class DataSubscription extends DataSource(RectPath(Shape)) {
23
- static _image
24
- subscription
25
- client
26
- disposed
27
-
28
- static get image() {
29
- if (!DataSubscription._image) {
30
- DataSubscription._image = new Image()
31
- DataSubscription._image.src = COMPONENT_IMAGE
32
- }
33
-
34
- return DataSubscription._image
35
- }
36
-
37
- dispose() {
38
- if (this.subscription) {
39
- this.subscription.unsubscribe()
40
- }
41
- if (this.client) {
42
- this.client.unsubscribeAll()
43
- this.client.close(true)
44
- }
45
-
46
- super.dispose()
47
- }
48
-
49
- render(context) {
50
- var { left, top, width, height } = this.bounds
51
-
52
- context.beginPath()
53
- this.drawImage(context, DataSubscription.image, left, top, width, height)
54
- }
55
-
56
- ready() {
57
- this._initDataSubscription()
58
- }
59
-
60
- get nature() {
61
- return NATURE
62
- }
63
-
64
- get tag() {
65
- return this.state.tag
66
- }
67
-
68
- set tag(tag) {
69
- this.setState('tag', tag)
70
- }
71
-
72
- _initDataSubscription() {
73
- if (!this.app.isViewMode) return
74
-
75
- this.requestData()
76
- }
77
-
78
- async requestData() {
79
- var { tag } = this.state
80
- var self = this
81
- var query = `"${tag}"`
82
-
83
- let wsKey = this.guid()
84
- var endpoint = getRestServiceFullPath().replace(/^http/, 'ws') + '/ws/fmbServer/' + wsKey
85
- this.client = new SubscriptionClient(
86
- endpoint,
87
- {
88
- reconnect: true,
89
- connectionParams: {
90
- headers: {
91
- /*
92
- 특정 도메인의 데이타만 받고자 하는 경우에, referer 정보를 제공해서 서버에서 서브도메인 정보를 취득하도록 한다.
93
- referer: location.href
94
- 또는, 이미 서브도메인 정보를 알고 있다면,
95
- 'x-things-factory-domain': '[subdomain]'
96
- 을 보낼 수 있다.
97
- 관련 정보를 보내지 않는다면, 사용자가 권한을 가진 모든 도메인의 데이타를 수신하게 된다.
98
- */
99
- referer: location.href
100
- }
101
- }
102
- },
103
- null,
104
- undefined,
105
- wsKey
106
- )
107
-
108
- this.client.onError(e => {
109
- var client = this.client
110
- // 보드가 실행중이면 재시도, 아니면 재연결 취소
111
- if (this.disposed) {
112
- client.reconnect = false
113
-
114
- this.client.unsubscribeAll()
115
- this.client.close(true)
116
- }
117
- })
118
-
119
- this.client.onConnected(() => {
120
- console.log('connected')
121
- })
122
-
123
- this.subscription = this.client.request({ query }).subscribe({
124
- next({ data }) {
125
- if (data) {
126
- self.data = data.data.data
127
- }
128
- }
129
- })
130
- console.log('this.subscription : ', this.subscription)
131
- }
132
-
133
- guid() {
134
- function s4() {
135
- return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)
136
- }
137
- return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4()
138
- }
139
- }
140
-
141
- Component.register('data-subscription', DataSubscription)
@@ -1,45 +0,0 @@
1
- import { getThemes } from '@fmsim/api/restful.js'
2
-
3
- export const themesColorMap = async () => {
4
- var result = (await getThemes())?.data
5
- if (!result || !result.status) {
6
- document.dispatchEvent(
7
- new CustomEvent('notify', {
8
- detail: {
9
- level: 'info',
10
- message: `Fetch Connection List Error!`
11
- }
12
- })
13
- )
14
- }
15
-
16
- const items = ((result && result.themeList.items) || [])
17
- .filter((item: any) => item.type == 'color-map')
18
- .map((item: any) => item.name)
19
-
20
- const sorted = items.sort()
21
-
22
- return [''].concat(sorted)
23
- }
24
-
25
- export const themesColorRange = async () => {
26
- var result = (await getThemes())?.data
27
- if (!result || !result.status) {
28
- document.dispatchEvent(
29
- new CustomEvent('notify', {
30
- detail: {
31
- level: 'info',
32
- message: `Fetch Connection List Error!`
33
- }
34
- })
35
- )
36
- }
37
-
38
- const items = ((result && result.themeList.items) || [])
39
- .filter((item: any) => item.type == 'color-ranges')
40
- .map((item: any) => item.name)
41
-
42
- const sorted = items.sort()
43
-
44
- return [''].concat(sorted)
45
- }
@@ -1,52 +0,0 @@
1
- import gql from 'graphql-tag'
2
-
3
- import { client } from '@operato/graphql'
4
-
5
- export const themesColorMap = async () => {
6
- var response = await client.query({
7
- query: gql`
8
- query {
9
- themes {
10
- items {
11
- name
12
- type
13
- }
14
- }
15
- }
16
- `
17
- })
18
-
19
- if (response.errors) {
20
- return ['']
21
- }
22
-
23
- const items = response.data.themes.items.filter((item: any) => item.type == 'color-map').map((item: any) => item.name)
24
- const sorted = items.sort()
25
-
26
- return [''].concat(sorted)
27
- }
28
-
29
- export const themesColorRange = async () => {
30
- var response = await client.query({
31
- query: gql`
32
- query {
33
- themes {
34
- items {
35
- name
36
- type
37
- }
38
- }
39
- }
40
- `
41
- })
42
- if (response.errors) {
43
- return ['']
44
- }
45
-
46
- const items = response.data.themes.items
47
- .filter((item: any) => item.type == 'color-ranges')
48
- .map((item: any) => item.name)
49
- const sorted = items.sort()
50
-
51
- return [''].concat(sorted)
52
- }