Project

General

Profile

« Previous | Next » 

Revision 49174

Utils of landing pages moved to 'landing-utils' folder | errorMessages.component created to centralize errorMessages according to ErrorCodes in openaireProperties.ts file | http service returning errorCodes and proper display fixed in search and fetch subscriptions (claims, home component, html project report page, csv files, basic info in landing pages, helper component, staticAutocomplete do not return errorCodes yet) | simple searchPages: paging remains when page changes while results load, filters on the left do not change position according to paging

View differences:

searchProjects.component.ts
20 20
                 [baseUrl] = "baseUrl" (queryChange)="queryChanged($event)"
21 21
                 [csvParams]="csvParams" csvPath="projects" advancedSearchLink="/search/advanced/projects"
22 22
                 [disableForms]="disableForms"
23
                 [loadPaging]="loadPaging"
24
                 [oldTotalResults]="oldTotalResults"
23 25
                 searchFormClass="projectsSearchForm">
24 26
    </search-page>
25 27
     `
26 28

  
27 29
})
28 30
export class SearchProjectsComponent {
31
  private errorCodes: ErrorCodes;
32

  
29 33
  public results =[];
30 34
  public filters: Filter[] =[];
31 35
  public baseUrl:string;
......
39 43
  public _location:Location;
40 44
  public csvParams: string;
41 45
  public disableForms: boolean = false;
46
  public loadPaging: boolean = true;
47
  public oldTotalResults: number = 0;
42 48

  
43 49
  @ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
44 50

  
45 51
  constructor (private route: ActivatedRoute, private _searchProjectsService: SearchProjectsService) {
46 52
    console.info(" constructor SearchProjectsComponent "+this.refineFields.length);
47 53

  
48
    var errorCodes:ErrorCodes = new ErrorCodes();
49
    this.searchUtils.status =errorCodes.LOADING;
54
    this.errorCodes = new ErrorCodes();
55
    this.searchUtils.status = this.errorCodes.LOADING;
50 56
    this.searchUtils.page =1;
51 57
    this.baseUrl = OpenaireProperties.getLinkToSearchProjects();
52 58

  
......
59 65
    //get refine field filters  from url parameters
60 66
    var firstLoad = true;
61 67
    this.sub =  this.route.queryParams.subscribe(params => {
68
      if(params['page'] && this.searchUtils.page != params['page']) {
69
        this.loadPaging = false;
70
        this.oldTotalResults = this.searchUtils.totalResults;
71
      }
62 72

  
63
        //get keyword from url parameters
64
        this.searchUtils.keyword = (params['keyword']?params['keyword']:'');
65
        var refine = true;
66
        if(this.searchUtils.page != ((params['page']=== undefined)?1:+params['page']) && this.filters && !firstLoad){
67
          refine = false;
73
      //get keyword from url parameters
74
      this.searchUtils.keyword = (params['keyword']?params['keyword']:'');
75
      var refine = true;
76
      if(this.searchUtils.page != ((params['page']=== undefined)?1:+params['page']) && this.filters && !firstLoad){
77
        refine = false;
68 78

  
69
        }
70
        firstLoad = false;
71
        //get page from url parameters
72
        this.searchUtils.page = (params['page']=== undefined)?1:+params['page'];
73
       var queryParameters = this.searchPage.getQueryParametersFromUrl(params);
74
        this._getResults(queryParameters, refine, this.searchUtils.page, this.searchUtils.size);
79
      }
80
      firstLoad = false;
81
      //get page from url parameters
82
      this.searchUtils.page = (params['page']=== undefined)?1:+params['page'];
83
      var queryParameters = this.searchPage.getQueryParametersFromUrl(params);
84
      this._getResults(queryParameters, refine, this.searchUtils.page, this.searchUtils.size);
75 85
    });
76 86
  }
77 87

  
......
98 108
    //     this.searchPage = new SearchPageComponent(this._location);
99 109
    // }
100 110

  
101
    var errorCodes:ErrorCodes = new ErrorCodes();
102
    this.searchUtils.status = errorCodes.LOADING;
111
    //var errorCodes:ErrorCodes = new ErrorCodes();
112
    this.searchUtils.status = this.errorCodes.LOADING;
103 113
    //this.searchPage.openLoading();
104 114
    this.disableForms = true;
105 115
    this.results = [];
......
116 126
            this.searchPage.checkSelectedFilters(this.filters);
117 127
            // this.filters = this.searchPage.checkSelectedFilters(data[2]);
118 128
            this.searchPage.updateBaseUrlWithParameters(this.filters);
119
            var errorCodes:ErrorCodes = new ErrorCodes();
120
            this.searchUtils.status = errorCodes.DONE;
129
            //var errorCodes:ErrorCodes = new ErrorCodes();
130
            this.searchUtils.status = this.errorCodes.DONE;
121 131
            if(this.searchUtils.totalResults == 0 ){
122
              this.searchUtils.status = errorCodes.NONE;
132
              this.searchUtils.status = this.errorCodes.NONE;
123 133
            }
124 134
            //this.searchPage.closeLoading();
125 135
            this.disableForms = false;
126 136

  
127
            if(this.searchUtils.status == errorCodes.DONE) {
137
            if(this.searchUtils.status == this.errorCodes.DONE) {
128 138
              // Page out of limit!!!
129 139
              let totalPages:any = this.searchUtils.totalResults/(this.searchUtils.size);
130 140
              if(!(Number.isInteger(totalPages))) {
......
132 142
              }
133 143
              if(totalPages < page) {
134 144
                this.searchUtils.totalResults = 0;
135
                this.searchUtils.status = errorCodes.OUT_OF_BOUND;
145
                this.searchUtils.status = this.errorCodes.OUT_OF_BOUND;
136 146
              }
137 147
            }
138 148
        },
......
142 152
            // if( ){
143 153
            //   this.searchUtils.status = ErrorCodes.ERROR;
144 154
            // }
145
            var errorCodes:ErrorCodes = new ErrorCodes();
146
            this.searchUtils.status = errorCodes.ERROR;
155
            //var errorCodes:ErrorCodes = new ErrorCodes();
156
            //this.searchUtils.status = errorCodes.ERROR;
157
            if(err.status == '404') {
158
              this.searchUtils.status = this.errorCodes.NOT_FOUND;
159
            } else if(err.status == '500') {
160
              this.searchUtils.status = this.errorCodes.ERROR;
161
            } else {
162
              this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
163
            }
164

  
147 165
            //this.searchPage.closeLoading();
148 166
            this.disableForms = false;
149 167
        }
......
158 176
            console.info("search Projects for Dataproviders: [Id:"+id+" ]  [total results:"+this.searchUtils.totalResults+"]");
159 177
            this.results = data[1];
160 178

  
161
            var errorCodes:ErrorCodes = new ErrorCodes();
162
            this.searchUtils.status = errorCodes.DONE;
179
            //var errorCodes:ErrorCodes = new ErrorCodes();
180
            this.searchUtils.status = this.errorCodes.DONE;
163 181
            if(this.searchUtils.totalResults == 0 ){
164
              this.searchUtils.status = errorCodes.NONE;
182
              this.searchUtils.status = this.errorCodes.NONE;
165 183
            }
166 184
        },
167 185
        err => {
......
170 188
            // if( ){
171 189
            //   this.searchUtils.status = ErrorCodes.ERROR;
172 190
            // }
173
            var errorCodes:ErrorCodes = new ErrorCodes();
174
            this.searchUtils.status = errorCodes.ERROR;
191
            //var errorCodes:ErrorCodes = new ErrorCodes();
192
            //this.searchUtils.status = errorCodes.ERROR;
193
            if(err.status == '404') {
194
              this.searchUtils.status = this.errorCodes.NOT_FOUND;
195
            } else if(err.status == '500') {
196
              this.searchUtils.status = this.errorCodes.ERROR;
197
            } else {
198
              this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
199
            }
175 200
        }
176 201
    );
177 202
  }
178 203

  
179 204

  
180 205
  public queryChanged($event) {
206
    this.loadPaging = true;
207
    
181 208
    this.urlParams = undefined;
182 209
    var parameters = $event.value;
183 210
    this._getResults(parameters, true, this.searchUtils.page, this.searchUtils.size);

Also available in: Unified diff