Skip to content

Commit

Permalink
fix json parse in dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
cviolbarbosa committed May 14, 2024
1 parent 8f5cc6c commit bc66e98
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 84 deletions.
83 changes: 7 additions & 76 deletions helyos_dashboard/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions helyos_dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@
"@ng-bootstrap/ng-bootstrap": "13.1.1",
"@ngx-translate/core": "14.0.0",
"@ngx-translate/http-loader": "7.0.0",
"apollo-cache-inmemory": "1.6.6",
"cheap-ruler": "3.0.2",
"core-js": "3.20.2",
"font-awesome": "4.7.0",
"helyosjs-sdk": "^2.0.4",
"helyosjs-sdk": "^2.0.5",
"js-yaml": "4.1.0",
"lodash": "4.17.21",
"rxjs": "7.8.1",
Expand Down
10 changes: 5 additions & 5 deletions helyos_dashboard/src/app/layout/yards/yards.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h1>Yards </h1>
<th>Lat</th>
<th>Lon</th>
<th>Alt</th>
<th>Map Info</th>
<th title="Optional: JSON data. If you have extensive map data, consider using map objects." >Map Info</th>
<th>Source</th>
</tr>
</thead>
Expand All @@ -40,8 +40,8 @@ <h1>Yards </h1>
<td>{{item.lat}}</td>
<td>{{item.lon}}</td>
<td>{{item.alt}}</td>
<td title="Optional: JSON data. If you have extensive map data, consider using map objects.">{{item.mapData}}</td>
<td>{{item.source}}</td>
<td title="Optional: JSON data. If you have extensive map data, consider using map objects.">
{{item.mapData.length > 200 ? item.mapData.substring(0, 200) + '...' : item.mapData}}</td>
</tr>
</tbody>
</table>
Expand Down Expand Up @@ -116,8 +116,8 @@ <h4>{{selectedItem.name}}</h4>


<div class="row" >
<fieldset class="form-group col-xl-12">
<label> Map data (arbritrary JSON data) </label>
<fieldset class="form-group col-xl-12" title="Optional: JSON data. If you have extensive map data, consider using map objects.">
<label> Map info (arbritrary JSON data) </label>
<textarea class="form-control" [(ngModel)]="selectedItem.mapData" name="mapData"
></textarea>
</fieldset>
Expand Down
23 changes: 22 additions & 1 deletion helyos_dashboard/src/app/layout/yards/yards.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ export class YardsComponent implements OnInit {

list() {
return this.helyosService.methods.yard.list({})
.then( r => this.yards = r );
.then( r => {
this.yards = r.map(yard => {
try {
yard.mapData = JSON.stringify(yard.mapData, null, 2);
} catch (error) {
yard.mapData = '';
}
return yard;
});
});
}


Expand All @@ -40,6 +49,11 @@ export class YardsComponent implements OnInit {
this.helyosService.methods.yard.get(itemId)
.then( (r:any)=> {
this.selectedItem = r;
try {
this.selectedItem.mapData = JSON.stringify(this.selectedItem.mapData, null, 2);
} catch (error) {
this.selectedItem.mapData = '';
}
});
}

Expand All @@ -61,6 +75,13 @@ export class YardsComponent implements OnInit {
delete patch.createdAt;
delete patch.modifiedAt;

try {
patch.mapData = JSON.parse(patch.mapData);
} catch (error) {
alert('Map Info is no a valid JSON');
return;
}

this.helyosService.methods.yard.patch(patch)
.then( r=> {
if (r.message){
Expand Down

0 comments on commit bc66e98

Please sign in to comment.