dataset-data-details.component.ts 1.43 KB
Newer Older
FORESTIER Fabien's avatar
FORESTIER Fabien committed
1
2
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { DatasetDetailService } from '../../services';
3
4
5
6
7
8
9

@Component({
  selector: 'app-dataset-data-details',
  templateUrl: './dataset-data-details.component.html',
  styleUrls: ['./dataset-data-details.component.scss'],
})
export class DatasetDataDetailsComponent implements OnInit {
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

  private _properties;
  @Input()
  set properties(properties) {
    // Making sure the complex properties values are under objects or array form and not string
    // When properties comme from the map MVT the types are lost and they are always represented as string
    for (const key in properties) {
      if (properties.hasOwnProperty(key)) {
        if (!this._datasetDetailService.dataset.fields.types[key] && typeof properties[key] === 'string') {
          try {
            const parsed = JSON.parse(properties[key]);
            properties[key] = parsed;
          } catch (err) { }
        }
      }
25
26
27
28
29
30
      else if (Array.isArray(properties[key])) {
        try {
          const parsed = JSON.parse(properties[key]);
          properties[key] = parsed;
        } catch (err) { }
      }
31
32
33
34
    }
    this._properties = properties;
  }

35
36
  @Output() close = new EventEmitter<boolean>();

37
38
39
  constructor(
    private _datasetDetailService: DatasetDetailService,
  ) { }
40
41
42
43

  ngOnInit() {
  }

44
45
  get properties() {
    return this._properties;
46
47
48
49
50
51
52
  }

  closeSelf() {
    this.close.emit(true);
  }

}