Project

General

Profile

« Previous | Next » 

Revision 62389

View differences:

metrics-enable.component.ts
3 3
import { ConfirmationDialogComponent } from '../../../shared/reusablecomponents/confirmation-dialog.component';
4 4
import { PiwikService } from '../../../services/piwik.service';
5 5
import { RepositoryService } from '../../../services/repository.service';
6
import { PiwikInfo, Repository } from '../../../domain/typeScriptClasses';
7
import { enabledMetricsError, enabledMetricsSuccess, enablingMetrics,
8
         loadingRepoError, loadingRepoMessage } from '../../../domain/shared-messages';
6
import {Country, PiwikInfo, Repository} from '../../../domain/typeScriptClasses';
7
import {
8
  enabledMetricsError, enabledMetricsSuccess, enablingMetrics,
9
  loadingRepoError, loadingRepoMessage, noServiceMessage
10
} from '../../../domain/shared-messages';
9 11
import { AuthenticationService } from '../../../services/authentication.service';
10 12
import { SharedService } from "../../../services/shared.service";
11 13

  
......
25 27
  repo: Repository;
26 28
  oaId: string;
27 29

  
30
  countries: Country[] = [];
31

  
28 32
  modalTitle = 'Confirmation';
29 33
  modalButton = 'Yes, enable it';
30 34
  isModalShown: boolean;
......
60 64

  
61 65
    // this.getRepo();
62 66
    this.isModalShown = false;
63
    let body = document.getElementsByTagName('body')[0];
64
    body.classList.remove("top_bar_active");   //remove the class
65
    body.classList.remove("page_heading_active");
66
    body.classList.remove("landing");
67
    body.classList.add("dashboard");
67
    const body = document.getElementsByTagName('body')[0];
68
    body.classList.remove('top_bar_active');   // remove the class
69
    body.classList.remove('page_heading_active');
70
    body.classList.remove('landing');
71
    body.classList.add('dashboard');
72

  
73
    this.getCountries();
68 74
  }
69 75

  
70 76
  // getRepo(): void {
......
109 115
      const piwik: PiwikInfo = {
110 116
        repositoryId: this.repo.id,
111 117
        openaireId: this.oaId,
112
        repositoryName: this.repo.officialName,
113
        country: this.repo.countryName,
118
        repositoryName: this.repo.officialname,
119
        country: this.getCountryName(this.repo.organizations[0].country),
114 120
        siteId: '',
115 121
        authenticationToken: this.authenticationToken,
116 122
        creationDate: null,
......
121 127
        comment: ''
122 128
      };
123 129

  
124
      this.piwikService.enableMetricsForRepository(this.repo.officialName, this.repo.websiteUrl, piwik).subscribe(
130
      this.piwikService.enableMetricsForRepository(this.repo.officialname, this.repo.websiteurl, piwik).subscribe(
125 131
        response => {
126 132
          console.log(`enableMetrics answered: ${response}`);
127 133
          this.successMessage = enabledMetricsSuccess;
128 134
          this.loadingMessage = '';
129 135

  
130
          //save piwik and update shareRepo
136
          // save piwik and update shareRepo
131 137
          this.repo.piwikInfo = piwik;
132 138
          this.sharedService.setRepository(this.repo);
133 139
        },
......
143 149
      );
144 150
    }
145 151
  }
152

  
153
  getCountries() {
154
    this.repoService.getCountries()
155
      .subscribe(
156
        countries => this.countries = countries.sort(function (a, b) {
157
          if (a.name < b.name) {
158
            return -1;
159
          } else if (a.name > b.name) {
160
            return 1;
161
          } else {
162
            return 0;
163
          }
164
        }),
165
        error => {
166
          this.loadingMessage = '';
167
          this.errorMessage = noServiceMessage;
168
          console.log(error);
169
        }
170
      );
171
  }
172

  
173
  getCountryName(countryCode): string {
174
    for (const country of Object.values(this.countries)) {
175
      if (country.code === countryCode) {
176
        return country.name;
177
      }
178
    }
179
  }
180

  
146 181
}

Also available in: Unified diff