Blame view

src/app/data/road/road.component.ts 2.96 KB
e74fdc9c   Yarik   Button
1
  import { Component, ViewEncapsulation, AfterViewInit, ViewChild } from '@angular/core';
ad296a58   Yarik   Road
2
  import { TdLoadingService } from '@covalent/core';
7462a6be   Yarik   Authority and con...
3
  import {GridOptions, IGetRowsParams, IRowModel, IFilter} from 'ag-grid/main';
ad296a58   Yarik   Road
4
5
  
  import { StatementBase } from '../../../models/statement.base';
e74fdc9c   Yarik   Button
6
  import { RoadMapComponent } from '../../../components/road-map.component';
ad296a58   Yarik   Road
7
8
9
10
11
12
13
14
15
  
  import { RoadService } from '../../../services/road.service';
  import { RoadCreateService } from '../../../services/road-create.service';
  import { Road } from '../../../models/road';
  import { EditorComponent } from '../../../helpers/editor.component';
  import { RendererComponent } from '../../../helpers/renderer.component';
  import { RoadTypeSelectList } from '../../../models/road-type-select-list';
  
  import { routerTransition } from '../../../animations/router.animation';
dc9a0e3c   Yarik   Road fatality
16
  import {Way} from "../../../models/way";
ad296a58   Yarik   Road
17
18
19
20
21
22
23
24
25
  
  @Component({
      // tslint:disable-next-line:component-selector
      selector: 'road-grid',
      templateUrl: 'road.component.html',
      styleUrls: ['road.scss'],
      encapsulation: ViewEncapsulation.None,
  })
  export class RoadComponent extends StatementBase {
e74fdc9c   Yarik   Button
26
27
    @ViewChild(RoadMapComponent)
    protected mapComponent: RoadMapComponent;
ad296a58   Yarik   Road
28
29
30
31
32
33
34
35
36
37
      public roadTypes: RoadTypeSelectList[];
  
      constructor(
          protected service: RoadService,
          protected dataService: RoadCreateService,
          protected loadingService: TdLoadingService,
      ) {
          super();
      }
  
e74fdc9c   Yarik   Button
38
      public showOnMap(): void {
dc9a0e3c   Yarik   Road fatality
39
40
        let selectedRows: any[] = this.gridOptions.api.getSelectedRows();
          if (selectedRows.length) {
229df284   Yarik   Big map commit
41
42
43
44
45
46
              this.mapComponent.clearWays();
              selectedRows.forEach((row) => {
                  this.service.getRelation(row.id).then(x => {
                      this.mapComponent.setWays(x);
                      return x;
                  });
dc9a0e3c   Yarik   Road fatality
47
              });
229df284   Yarik   Big map commit
48
              this.gridOptions.api.deselectAll();
dc9a0e3c   Yarik   Road fatality
49
          }
e74fdc9c   Yarik   Button
50
51
      }
  
ad296a58   Yarik   Road
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
    protected createColumnDefs(): any[] {
      return [
        {
          headerName: '#',
          width: 30,
          checkboxSelection: true,
          suppressSorting: true,
          suppressMenu: true,
          pinned: true,
        },
        {
          headerName: 'ID',
          field: 'id',
        },
        {
          headerName: 'Назва дороги',
          field: 'name',
          editable: true,
        },
        {
          headerName: 'Індекс дороги',
          field: 'index',
          editable: true,
        },
        {
          headerName: 'Тип дороги',
          field: 'roadTypeId',
          editable: true,
          cellEditorFramework: EditorComponent,
          cellRendererFramework: RendererComponent,
          cellEditorParams: {
            data: this.roadTypes,
            valueCol: 'roadTypeId',
            labelCol: 'name',
          },
        },
      ];
    }
  
    protected initFunction(): void {
      this.dataService.getModels().then((models: any) => {
              this.roadTypes = models.roadTypeSelectListDsM as RoadTypeSelectList[];
        }).then(() => {
              this.bootstrapGrid();
        });
    }
  }