@@ -143,18 +143,45 @@ func resourceAlicloudLogDashboardRead(d *schema.ResourceData, meta interface{})
143
143
return WrapError (err )
144
144
}
145
145
}
146
+
147
+ // 先取出charts
146
148
charts := dashboard ["charts" ].([]interface {})
149
+ // 字段清理
147
150
for k , v := range charts {
151
+ // 将charts中的action字段删除
148
152
if action , actionOK := v .(map [string ]interface {})["action" ]; actionOK {
149
153
if action == nil {
150
154
delete (charts [k ].(map [string ]interface {}), "action" )
151
155
}
152
156
}
157
+ // 如果有basicOptions字段请basicOptions中的displayName字段存在,则将display字段中的displayName字段删除
158
+ var display , basicOptions interface {}
159
+ var ok bool
160
+ if display , ok = v .(map [string ]interface {})["display" ]; ! ok {
161
+ continue
162
+ } else if basicOptions , ok = display .(map [string ]interface {})["basicOptions" ]; ! ok {
163
+ continue
164
+ } else if _ , ok = basicOptions .(map [string ]interface {})["displayName" ]; ! ok {
165
+ continue
166
+ } else if _ , ok = display .(map [string ]interface {})["displayName" ]; ok {
167
+ delete (display .(map [string ]interface {}), "displayName" )
168
+ }
153
169
}
154
- sort .Slice (charts , func (i , j int ) bool {
155
- return charts [i ].(map [string ]interface {})["display" ].(map [string ]interface {})["yPos" ].(float64 ) < charts [j ].(map [string ]interface {})["display" ].(map [string ]interface {})["yPos" ].(float64 )
170
+
171
+ // 再将charts按照yPos排序
172
+ sort .SliceStable (charts , func (i , j int ) bool {
173
+ yi := charts [i ].(map [string ]interface {})["display" ].(map [string ]interface {})["yPos" ].(float64 )
174
+ yj := charts [j ].(map [string ]interface {})["display" ].(map [string ]interface {})["yPos" ].(float64 )
175
+ xi := charts [i ].(map [string ]interface {})["display" ].(map [string ]interface {})["xPos" ].(float64 )
176
+ xj := charts [j ].(map [string ]interface {})["display" ].(map [string ]interface {})["xPos" ].(float64 )
177
+ if yj != yi {
178
+ return yi < yj
179
+ }
180
+ return xi < xj
156
181
})
157
- charlist , err := json .Marshal (dashboard ["charts" ])
182
+
183
+ // 最后将charts转为json字符串
184
+ charlist , err := json .Marshal (charts )
158
185
if err != nil {
159
186
return WrapError (err )
160
187
}
0 commit comments