-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsmip-queries.js
181 lines (180 loc) · 4.71 KB
/
smip-queries.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
if (typeof smip === 'undefined')
smip = {};
smip.queries = {
getHistoricalData: function(attrId, starttime, endtime, datatype) {
return {
query: `{
getRawHistoryDataWithSampling(
ids: ["${attrId}"],
startTime: "${starttime}",
endTime: "${endtime}"
maxSamples: 1
) {
id
ts
${datatype}
}
}
`
};
},
getEquipmentsByTypeName: function(typeName, parentId) {
typeName = typeName.toLowerCase();
//TODO: modify query with filter instead of having two almost identical queries
if (parentId != null && parentId != "") {
return {
query: `{
equipments(filter: {typeName: {equalTo: "${typeName}"}, partOfId: {equalTo: "${parentId}"}}) {
displayName
typeName
id
}
}`
}
} else {
return {
query: `{
equipments(filter: {typeName: {equalTo: "${typeName}"}}) {
displayName
typeName
id
}
}`
};
}
},
getEquipmentChildren: function(instanceId, depth) {
//TODO: construct query recursively to depth
return {
query: `{
equipment(id: "${instanceId}") {
id
displayName
childEquipment {
id
displayName
attributes {
id
displayName
}
childEquipment {
id
displayName
attributes {
id
displayName
}
childEquipment {
id
displayName
attributes {
id
displayName
}
childEquipment {
id
displayName
attributes {
id
displayName
}
}
}
}
}
}
}`
};
},
// query to find details of a piece of equipment given its id
getEquipmentById: function (id) {
return {
query: `{
equipments(filter: { id: { equalTo: "${id}" } }) {
displayName
typeName
id
}
}`
};
},
// query to find details of a piece of equipment given its id
getAttributesForEquipmentById: function (id) {
return {
query: `{
attributes(filter: {partOfId: {equalTo: "${id}"}}) {
id
displayName
relativeName
}
}`
};
},
// query to find details of a piece of equipment from a specified place
getEquipmentsInPlace: function (placeId, limit=10) {
return {
query: `{
place(id: "${placeId}") {
id
displayName
equipment(first: ${limit}) {
id
displayName
attributes {
stringValue
displayName
}
}
}}`
};
},
// query to get child equipment from a specified place
getChildEquipmentsInPlace: function(placeId) {
return {
query: `{
places(filter: { partOfId: { equalTo: "${placeId}" } }) {
id
displayName
equipment {
displayName
id
attributes {
displayName
id
dataType
}
childEquipment {
displayName
typeName
id
attributes {
displayName
id
dataType
}
}
}
}
}`
}
},
};
smip.mutations = {
// mutation to update equipment parent
updateEquipmentParent: function(equipmentId, newPlaceId) {
return {
query: `mutation {
updateEquipment(input: { id: "${equipmentId}", patch: { partOfId: "${newPlaceId}" } }) {
place {
id
displayName
parentPlace {
id
displayName
}
}
}
}`
}
},
};