Project

General

Profile

« Previous | Next » 

Revision 58825

Working on the new version of the oso. Work on the home page almost done

View differences:

countries-table.component.ts
1
import { Component, Input, OnChanges, ViewEncapsulation } from '@angular/core';
2
import { CountryOverview } from '../../domain/overview-data';
1
import { Component, Input, OnChanges } from '@angular/core';
2
import { CountryTableData } from '../../domain/overview-map-data';
3 3

  
4 4
@Component({
5 5
  selector: 'app-countries-table',
6 6
  templateUrl: './countries-table.component.html',
7
  // styleUrls: ['./top-menu.component.css'],
8
  encapsulation: ViewEncapsulation.None
9 7
})
10 8

  
11 9
export class CountriesTableComponent implements OnChanges {
12 10

  
13 11
  @Input() isPercentage: boolean;
14
  @Input() type: string;
15
  @Input() countries: CountryOverview[];
12
  @Input() countries: CountryTableData[];
16 13

  
17 14
  isSortedBy: string;
18 15
  isDescending: boolean = true;
......
20 17
  constructor() {}
21 18

  
22 19
  ngOnChanges() {
23
    this.countries.sort((a, b) => (a['country'] > b['country']) ? 1 : -1);
20
    this.countries.sort((a, b) => (a['name'] > b['name']) ? 1 : -1);
24 21
  }
25 22

  
26 23
  sortBy(field: string) {
......
34 31
    this.isSortedBy = field;
35 32

  
36 33
    if (field !== 'country') {
37
      if (this.isPercentage) {
38
        if (this.isDescending) {
39
          this.countries.sort((a, b) => b[field].percentage - a[field].percentage);
40
        } else {
41
          this.countries.sort((a, b) => a[field].percentage - b[field].percentage);
42
        }
34
      if (this.isDescending) {
35
        this.countries.sort((a, b) => b[field] - a[field]);
43 36
      } else {
44
        if (this.isDescending) {
45
          this.countries.sort((a, b) => b[field].oa - a[field].oa);
46
        } else {
47
          this.countries.sort((a, b) => a[field].oa - b[field].oa);
48
        }
37
        this.countries.sort((a, b) => a[field] - b[field]);
49 38
      }
50 39
    } else {
51 40
      if (this.isDescending) {
52
        this.countries.sort((a, b) => (a[field] < b[field]) ? 1 : -1);
41
        this.countries.sort((a, b) => (a['name'] < b['name']) ? 1 : -1);
53 42
      } else {
54
        this.countries.sort((a, b) => (a[field] > b[field]) ? 1 : -1);
43
        this.countries.sort((a, b) => (a['name'] > b['name']) ? 1 : -1);
55 44
      }
56 45
    }
57 46

  

Also available in: Unified diff