src/connectors/appscript-connector.js
/**
   * initLocations - Get locations from WebPageTest API and update to Locations
   * tab.
   */
Get locations from WebPageTest API and update to Locations
tab.
Get locations from WebPageTest API and update to Locations tab .
initLocations() {
    let locations = this.getList('locationsTab');
    let tabConfig = this.tabConfigs['locationsTab'];
    let sheet = this.getSheet('locationsTab');
    let response = this.apiHandler.fetch(this.locationApiEndpoint);
    if(response.statusCode == 200) {
      let json = JSON.parse(response.body);
      let newLocations = [];
      let pendingByLocation = {}
      Object.keys(json.data).forEach(key => {
        let data = json.data[key];
        let newLocation = {
          id: key,
          name: `${data.labelShort} (${key})`,
          pendingTests: data.PendingTests.Total,
          browsers: data.Browsers,
        };
        newLocation.key = key;
        pendingByLocation[newLocation.name] = newLocation.pendingTests;
        newLocations.push(newLocation);
      });
      for (let i=newLocations.length; i<locations.length; i++) {
        newLocations.push({});
      }
      this.updateList('locationsTab', newLocations);
      let propertyKey = 'webpagetest.pendingTests';
      let tests = this.getTestList({
        filters: ['url', 'webpagetest.settings.location'],
      });
      tests.forEach(test => {
        if (!test.url || !test.webpagetest || !test.webpagetest.settings ||
            !test.webpagetest.settings.location) return;
        test.webpagetest.pendingTests =
            pendingByLocation[test.webpagetest.settings.location];
      });
      this.updateTestList(tests);
    }
  }
initLocations ( ) { let locations = this . getList ( 'locationsTab' ) ; let tabConfig = this . tabConfigs [ 'locationsTab' ] ; let sheet = this . getSheet ( 'locationsTab' ) ; let response = this . apiHandler . fetch ( this . locationApiEndpoint ) ; if ( response . statusCode == 200 ) { let json = JSON . parse ( response . body ) ; let newLocations = [ ] ; let pendingByLocation = { } Object . keys ( json . data ) . forEach ( key => { let data = json . data [ key ] ; let newLocation = { id : key , name : ` ${ data . labelShort } ${ key } ` , pendingTests : data . PendingTests . Total , browsers : data . Browsers , } ; newLocation . key = key ; pendingByLocation [ newLocation . name ] = newLocation . pendingTests ; newLocations . push ( newLocation ) ; } ) ; for ( let i = newLocations . length ; i < locations . length ; i ++ ) { newLocations . push ( { } ) ; } this . updateList ( 'locationsTab' , newLocations ) ; let propertyKey = 'webpagetest.pendingTests' ; let tests = this . getTestList ( { filters : [ 'url' , 'webpagetest.settings.location' ] , } ) ; tests . forEach ( test => { if ( ! test . url || ! test . webpagetest || ! test . webpagetest . settings || ! test . webpagetest . settings . location ) return ; test . webpagetest . pendingTests = pendingByLocation [ test . webpagetest . settings . location ] ; } ) ; this . updateTestList ( tests ) ; } }
initLocations - Get locations from WebPageTest API and update to Locations
 tab.
initLocations - Get locations from WebPageTest API and update to Locations tab .
// Reset locations tab. // Get new locations from remote API. // Add empty rows if the original location list was longer than the new one. // Overrides pending tests to property 'webpagetest.pendingTests'.