Project

General

Profile

« Previous | Next » 

Revision 55338

[Trunk|Connect]: 1. Change search Communities to initialize with one call to the APIs ngOnInit. 2. Contact: Redirect from modal is the same in production and dev

View differences:

modules/uoa-connect-portal/trunk/src/app/searchPages/communities/searchCommunities.component.ts
35 35
  public piwiksub: any;
36 36
  private errorCodes: ErrorCodes;
37 37
  private errorMessages: ErrorMessagesComponent;
38
  public results: SearchResult[] = [];
38
  public results: CommunityInfo[] = [];
39
  public totalResults: CommunityInfo[] = [];
39 40
  public sub: any; public subResults: any;
40 41
  public filters = [];
41 42
  public searchFields:SearchFields = new SearchFields();
......
80 81
      this.searchPage.refineFields = this.refineFields;
81 82
      let queryParams = this.searchPage.getQueryParamsFromUrl(params);
82 83
      this.filters = this.createFilters();
83
      this._getResults(queryParams);
84

  
85
      this.initCommunities(queryParams);
84 86
    });
85 87
  }
86 88

  
......
93 95
    }
94 96
  }
95 97

  
96

  
97 98
  /**
98
   * Return the communities in which user has permission to view or manage.
99
   */
100
  private showCommunities() {
101
    let ret: SearchResult[] = [];
102
    for(let result of this.results) {
103
      if (result.community.status == 'hidden') {
104
        continue;
105
      } else if (result.community.status == "manager") {
106
        let mail = Session.getUserEmail();
107
        if (mail == null) { // no user
108
          continue;
109
        } else if (Session.isCommunityCurator() || Session.isPortalAdministrator()) {
110
          ret.push(result);
111
        } else if (result.community.managers.indexOf(mail) != -1) {
112
          ret.push(result);
113
        }
114
        continue;
115
      }
116
      ret.push(result);
117
    }
118
    this.results = ret;
119
  }
120

  
121
  /**
122
   * Get all communities from Communities API and apply permission access validator,
123
   * keyword searching, filter, paging and sorting.
99
   * Initialize communities from Communities APIs
124 100
   *
125 101
   * @param params
126
   * @private
127 102
   */
128
  private _getResults(params: Map<string, string>){
129
    this.searchUtils.status = this.errorCodes.LOADING;
130
    this.disableForms = true;
131
    this.results = [];
132
    this.searchUtils.totalResults = 0;
103
  private initCommunities(params: Map<string, string>) {
133 104
    this.subResults = this._communitiesService.getCommunities(this.properties, this.properties.communitiesAPI).subscribe(
134 105
        data => {
135 106
          let observables: Observable<boolean>[] = [];
136 107
          for(let i = 0; i < data.length; i++) {
137
            this.results[i] = new SearchResult();
138
            this.results[i].community = data[i];
108
            this.totalResults[i] = data[i];
139 109
            // For Test do not delete them.
140
            //this.results[i].community.description = "EGI is a federated e-Infrastructure set up to provide advanced computing services for research and innovation.EGI is a federated e-Infrastructure set up to provide advanced computing services for research and innovation.EGI is a federated e-Infrastructure set up to provide advanced computing services for research and innovation."
141
            //this.results[i].community.date = new Date(new Date(2012, 0, 1).getTime() + Math.random() * (new Date().getTime() - new Date(2012, 0, 1).getTime()));
142
            observables.push(this._subscribeService.isSubscribedToCommunity(this.results[i].community.communityId, Session.getUserEmail(), this.properties["adminToolsAPIURL"]));
143
            this.results[i].isManager = this.isCommunityManager(this.results[i].community);
110
            //this.results[i].description = "EGI is a federated e-Infrastructure set up to provide advanced computing services for research and innovation.EGI is a federated e-Infrastructure set up to provide advanced computing services for research and innovation.EGI is a federated e-Infrastructure set up to provide advanced computing services for research and innovation."
111
            //this.results[i].date = new Date(new Date(2012, 0, 1).getTime() + Math.random() * (new Date().getTime() - new Date(2012, 0, 1).getTime()));
112
            observables.push(this._subscribeService.isSubscribedToCommunity(this.totalResults[i].communityId, Session.getUserEmail(), this.properties["adminToolsAPIURL"]));
113
            this.totalResults[i].isManager = this.isCommunityManager(this.results[i]);
144 114
          }
145 115
          Observable.forkJoin(observables).subscribe(
146 116
              res => {
147 117
                for(let i = 0; i < res.length; i++) {
148
                  this.results[i].isSubscribed = res[i];
118
                  this.totalResults[i].isSubscribed = res[i];
149 119
                }
150
                this.applyParams(params, this.errorCodes.DONE);
120
                this._getResults(params, this.errorCodes.DONE);
151 121
              },
152 122
              err => {
153 123
                this.handleError('Error getting if user is subscribed', err);
154
                this.applyParams(params, this.errorCodes.MISSING_CONTENT);
124
                this._getResults(params, this.errorCodes.MISSING_CONTENT);
155 125
              }
156 126
          );
157 127
        },
......
165 135
    );
166 136
  }
167 137

  
138

  
168 139
  /**
140
   * Get all communities from Communities API and apply permission access validator,
141
   * keyword searching, filter, paging and sorting.
142
   *
143
   * @param params, status
144
   * @private
145
   */
146
  private _getResults(params: Map<string, string>, status: number){
147
    this.searchUtils.status = this.errorCodes.LOADING;
148
    this.disableForms = true;
149
    this.results = this.totalResults;
150
    this.searchUtils.totalResults = 0;
151
    this.applyParams(params, status);
152
  }
153

  
154
  /**
155
   * Return the communities in which user has permission to view or manage.
156
   */
157
  private showCommunities() {
158
    let ret: CommunityInfo[] = [];
159
    for(let result of this.results) {
160
      if (result.status == 'hidden') {
161
        continue;
162
      } else if (result.status == "manager") {
163
        let mail = Session.getUserEmail();
164
        if (mail == null) { // no user
165
          continue;
166
        } else if (Session.isCommunityCurator() || Session.isPortalAdministrator()) {
167
          ret.push(result);
168
        } else if (result.managers.indexOf(mail) != -1) {
169
          ret.push(result);
170
        }
171
        continue;
172
      }
173
      ret.push(result);
174
    }
175
    this.results = ret;
176
  }
177

  
178
  /**
169 179
   * Apply permission access validator,
170 180
   * keyword searching, filter, paging and sorting.
171 181
   *
......
211 221
   * one of the given words.
212 222
   */
213 223
  private searchForKeywords() {
214
      let ret: SearchResult[] = [];
224
      let ret: CommunityInfo[] = [];
215 225
      let keywords: string[] = this.searchUtils.keyword.split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,-1);
216 226
      for(let i = 0; i < this.results.length; i++) {
217 227
          for(let keyword of keywords) {
218
              if (keyword != '' && (this.results[i].community.title.includes(keyword) || this.results[i].community.shortTitle.includes(keyword) ||
219
                  this.results[i].community.communityId.includes(keyword) || this.results[i].community.description.includes(keyword))) {
228
              if (keyword != '' && (this.results[i].title.includes(keyword) || this.results[i].shortTitle.includes(keyword) ||
229
                  this.results[i].communityId.includes(keyword) || this.results[i].description.includes(keyword))) {
220 230
                  ret.push(this.results[i]);
221 231
                  break;
222 232
              }
......
232 242
   * @param params
233 243
   */
234 244
  private checkFilters(params: Map<string, string>) {
235
    let typeResults: SearchResult[] = this.applyFilter('type', params);
236
    let statusResults: SearchResult[] = this.applyFilter('status' , params);
237
    let roleResults: SearchResult[] = this.applyFilter('role', params);
245
    let typeResults: CommunityInfo[] = this.applyFilter('type', params);
246
    let statusResults: CommunityInfo[] = this.applyFilter('status' , params);
247
    let roleResults: CommunityInfo[] = this.applyFilter('role', params);
238 248
    this.resetFilterNumbers('status');
239 249
    this.updateFilterNumbers(typeResults.filter(value => {
240 250
      return roleResults.includes(value);
......
261 271
   * @param filterId
262 272
   * @param params
263 273
   */
264
  private applyFilter(filterId: string, params: Map<string, string>): SearchResult[] {
265
    let results:SearchResult[] = [];
274
  private applyFilter(filterId: string, params: Map<string, string>): CommunityInfo[] {
275
    let results:CommunityInfo[] = [];
266 276
    let values: string[] = [];
267 277
    if(params.get(filterId) != undefined) {
268 278
      values = (StringUtils.URIDecode(params.get(filterId))).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,-1);
......
273 283
          results.push(this.results[i]);
274 284
        } else {
275 285
          for (let value of values) {
276
            if (this.results[i].community.type == value.replace(/["']/g, "")) {
286
            if (this.results[i].type == value.replace(/["']/g, "")) {
277 287
              results.push(this.results[i]);
278 288
              break;
279 289
            }
......
344 354
     * @param results
345 355
     * @param filterId
346 356
     */
347
  private updateFilterNumbers(results: SearchResult[], filterId: string) {
357
  private updateFilterNumbers(results: CommunityInfo[], filterId: string) {
348 358
    for(let k = 0; k < results.length; k++) {
349 359
      for (let i = 0; i < this.filters.length; i++) {
350 360
        if(this.filters[i].filterId == filterId) {
351 361
            if (this.filters[i].filterId == 'type') {
352 362
                for (let j = 0; j < this.filters[i].values.length; j++) {
353
                    if (results[k].community.type == this.filters[i].values[j].id) {
363
                    if (results[k].type == this.filters[i].values[j].id) {
354 364
                        this.filters[i].values[j].number++;
355 365
                    }
356 366
                }
......
379 389
  private sort() {
380 390
    if(this.searchUtils.sortBy == '') {
381 391
      this.results.sort((left, right): number => {
382
        if (left.community.title > right.community.title) {
392
        if (left.title > right.title) {
383 393
          return 1;
384
        } else if (left.community.title < right.community.title) {
394
        } else if (left.title < right.title) {
385 395
          return -1;
386 396
        } else {
387 397
          return 0;
......
389 399
      })
390 400
    } else if(this.searchUtils.sortBy == 'creationdate,descending') {
391 401
      this.results.sort((left, right): number => {
392
        if (!right.community.date || left.community.date > right.community.date) {
402
        if (!right.date || left.date > right.date) {
393 403
          return -1;
394
        } else if (!left.community.date || left.community.date < right.community.date) {
404
        } else if (!left.date || left.date < right.date) {
395 405
          return 1;
396 406
        } else {
397 407
          return 0;
......
399 409
      })
400 410
    } else if(this.searchUtils.sortBy == 'creationdate,ascending') {
401 411
      this.results.sort((left, right): number => {
402
        if (!right.community.date || left.community.date > right.community.date) {
412
        if (!right.date || left.date > right.date) {
403 413
          return 1;
404
        } else if (!left.community.date || left.community.date < right.community.date) {
414
        } else if (!left.date || left.date < right.date) {
405 415
          return -1;
406 416
        } else {
407 417
          return 0;
......
416 426
  }
417 427

  
418 428
  public queryChanged($event) {
419
    this._getResults($event.params);
429
    this._getResults($event.params, this.errorCodes.DONE);
420 430
  }
421 431

  
422 432
    /**
modules/uoa-connect-portal/trunk/src/app/contact/contact.component.ts
125 125
        this.showLoading = false;
126 126
    }
127 127

  
128
    getProductionPrefix():string{
129
        return (this.properties.environment == "beta")?"beta.":""
130
    }
131

  
132
    isProduction():boolean{
133
        return this.properties.environment!="development";
134

  
135
    }
136

  
137 128
    public goToHome(data: any) {
138
        if(this.isProduction()) {
139
            window.location.hostname = 'https://'+ this.getProductionPrefix() + 'connect.openaire.eu';
140
        } else {
141
            this._router.navigate(['/']);
142
        }
129
        this._router.navigate(['/']);
143 130
    }
144 131

  
145 132
}

Also available in: Unified diff