Project

General

Profile

« Previous | Next » 

Revision 53742

claimsByToken.component & mailPrefs.component: when Session is expired, redirect to '/user-info' page to show a proper message.

View differences:

modules/uoa-services-library/trunk/ng-openaire-library/src/app/connect/userEmailPreferences/mailPrefs.component.ts
69 69

  
70 70
  getEmailPreferences() {
71 71
    if(!Session.isLoggedIn()){
72
      this.userValidMessage = "User session has expired. Please login again.";
72
      //this.userValidMessage = "User session has expired. Please login again.";
73 73
      if(this.showSaveResetButtons) {
74 74
        this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl":  this._router.url} });
75 75
      }
76
    }else{
76
    } else {
77 77
      this.status = this.errorCodes.LOADING;
78 78
      this.savedMessage = "";
79 79

  
......
123 123
  }
124 124

  
125 125
  changeNotify(notification: any, checked: boolean, index: number) {
126
    this.savedMessage = "";
127
    this.status = this.errorCodes.DONE;
128
    notification.notify = checked;
129
    this.prefsChanged[index] = true;
126
    if(!Session.isLoggedIn()){
127
      //this.userValidMessage = "User session has expired. Please login again.";
128
      if(this.showSaveResetButtons) {
129
        this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl":  this._router.url} });
130
      }
131
    } else {
132
      this.savedMessage = "";
133
      this.status = this.errorCodes.DONE;
134
      notification.notify = checked;
135
      this.prefsChanged[index] = true;
136
    }
130 137
  }
131 138

  
132 139
  changeFrequency(value: number, index: number) {
133
    this.savedMessage = "";
134
    this.status = this.errorCodes.DONE;
135
    if(this.initialNotifications[index].frequency != value) {
136
      this.prefsChanged[index] = true;
140
    if(!Session.isLoggedIn()){
141
      //this.userValidMessage = "User session has expired. Please login again.";
142
      if(this.showSaveResetButtons) {
143
        this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl":  this._router.url} });
144
      }
145
    } else {
146
      this.savedMessage = "";
147
      this.status = this.errorCodes.DONE;
148
      if(this.initialNotifications[index].frequency != value) {
149
        this.prefsChanged[index] = true;
150
      }
137 151
    }
138 152
  }
139 153

  
140 154
  saveNotification(index: number) {
141 155
    if(this.notifications.length > 0 && this.initialNotifications.length > 0) {
142 156
      if(!Session.isLoggedIn()){
143
          this.userValidMessage = "User session has expired. Please login again.";
157
          //this.userValidMessage = "User session has expired. Please login again.";
144 158
          if(this.showSaveResetButtons) {
145 159
            this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl":  this._router.url} });
146 160
          }
147
      }else{
161
      } else {
148 162
        if(JSON.stringify(this.notifications[index]) != JSON.stringify(this.initialNotifications[index])) {
149 163

  
150 164
          this.status = this.errorCodes.LOADING;
......
187 201
  }
188 202

  
189 203
  restoreNotification(index: number) {
190
    if(this.notifications.length > 0 && this.initialNotifications.length > 0) {
191
      this.status = this.errorCodes.LOADING;
192
      this.savedMessage = "";
193
      console.info("Restore Notification");
194
      console.info(this.notifications[index]);
195
      this.notifications[index] = JSON.parse(JSON.stringify( this.initialNotifications[index] ));
196
      console.info(this.initialNotifications[index]);
197
      this.status = this.errorCodes.DONE;
198
      this.prefsChanged[index] = false;
204
    if(!Session.isLoggedIn()){
205
      //this.userValidMessage = "User session has expired. Please login again.";
206
      if(this.showSaveResetButtons) {
207
        this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl":  this._router.url} });
208
      }
209
    } else {
210
      if(this.notifications.length > 0 && this.initialNotifications.length > 0) {
211
        this.status = this.errorCodes.LOADING;
212
        this.savedMessage = "";
213
        console.info("Restore Notification");
214
        console.info(this.notifications[index]);
215
        this.notifications[index] = JSON.parse(JSON.stringify( this.initialNotifications[index] ));
216
        console.info(this.initialNotifications[index]);
217
        this.status = this.errorCodes.DONE;
218
        this.prefsChanged[index] = false;
219
      }
199 220
    }
200 221
  }
201 222
/*
modules/uoa-services-library/trunk/ng-openaire-library/src/app/claims/claimsByToken/claimsByToken.component.ts
1 1
import {Component, ViewChild, ViewChildren, QueryList, Input, ViewEncapsulation} from '@angular/core';
2 2
import {Location}                    from '@angular/common';
3
import {ActivatedRoute, Params}      from '@angular/router';
3
import {ActivatedRoute, Params, Router}      from '@angular/router';
4 4
import {Title, Meta}                 from '@angular/platform-browser';
5 5

  
6 6
import {DataTableDirective}          from 'angular-datatables';
......
12 12

  
13 13
import {ClaimsDatatablePipe}         from '../../utils/pipes/claimsDatatable.pipe';
14 14

  
15
import {Session}                     from '../../login/utils/helper.class';
16 15
import {RouterHelper}                from '../../utils/routerHelper.class';
17 16

  
18 17
import {ModalSelect}                 from '../../utils/modal/selectModal.component';
......
20 19

  
21 20
import {ClaimsByTokenService}        from './claimsByToken.service';
22 21

  
22
import {Session}                     from '../../login/utils/helper.class';
23
import {LoginErrorCodes}             from '../../login/utils/guardHelper.class';
24

  
25

  
23 26
@Component({
24 27
    selector: 'claims-project-manager',
25 28
    templateUrl: 'claimsByToken.component.html',
......
83 86
  public routerHelper:RouterHelper = new RouterHelper();
84 87

  
85 88
  constructor (private route: ActivatedRoute,
89
               private _router: Router,
86 90
               private claimsByTokenService: ClaimsByTokenService,
87 91
               private _meta: Meta, private _title: Title) {
88 92
      this.errorCodes = new ErrorCodes();
......
198 202
  }
199 203

  
200 204
  filterData(row: any, query: string) {
201
    let returnValue: boolean = false;
205
    if(!Session.isLoggedIn()){
206
      console.info(this._router.url);
207
      this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl":  this._router.url} });
208
    } else {
209
      let returnValue: boolean = false;
202 210

  
203
    if(query) {
204
      for(var i=0; i <3; i++){
205
        var r= this.filterQuery(row[i], query);
206
        if(r) {
207
          returnValue = true;
208
          break;
211
      if(query) {
212
        for(var i=0; i <3; i++){
213
          var r= this.filterQuery(row[i], query);
214
          if(r) {
215
            returnValue = true;
216
            break;
217
          }
209 218
        }
219

  
220
        if(!returnValue) {
221
          return false;
222
        }
210 223
      }
211 224

  
212
      if(!returnValue) {
213
        return false;
214
      }
225
      return true;
215 226
    }
216

  
217
    return true;
218 227
  }
219 228

  
220 229
  filterQuery(data, query){
......
226 235
  }
227 236

  
228 237
refreshTable(page:number, whichTable: string) {
238
  if(!Session.isLoggedIn()){
239
    console.info(this._router.url);
240
    this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl":  this._router.url} });
241
  } else {
242
    if(whichTable == "pending") {
243
      var table = $('#table1').DataTable();
244
      table.page( page - 1  ).draw( false );
229 245

  
230
  if(whichTable == "pending") {
231
    var table = $('#table1').DataTable();
232
    table.page( page - 1  ).draw( false );
246
      var info = table.page.info();
247
      console.info("records: "+info.recordsDisplay);
233 248

  
234
    var info = table.page.info();
235
    console.info("records: "+info.recordsDisplay);
249
      this.activePendingPage.page = page;//$event.value;
250
      this.totalPendingResults.count = info.recordsDisplay;
251
    } else if(whichTable == 'curated') {
252
      var table = $('#table2').DataTable();
253
      table.page( page - 1  ).draw( false );
236 254

  
237
    this.activePendingPage.page = page;//$event.value;
238
    this.totalPendingResults.count = info.recordsDisplay;
239
  } else if(whichTable == 'curated') {
240
    var table = $('#table2').DataTable();
241
    table.page( page - 1  ).draw( false );
255
      var info = table.page.info();
256
      console.info("records: "+info.recordsDisplay);
242 257

  
243
    var info = table.page.info();
244
    console.info("records: "+info.recordsDisplay);
245

  
246
    this.activeCuratedPage.page = page;//$event.value;
247
    this.totalCuratedResults.count = info.recordsDisplay;
258
      this.activeCuratedPage.page = page;//$event.value;
259
      this.totalCuratedResults.count = info.recordsDisplay;
260
    }
248 261
  }
249 262

  
250 263
  //table.mfActivePage=$event.value;
......
252 265
}
253 266

  
254 267
  validateJWTandToken() {
268
    if(!Session.isLoggedIn()){
269
      console.info(this._router.url);
270
      this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl":  this._router.url} });
271
    } else {
272
      if(this.openaireId) {
273
        this.pending_status = this.errorCodes.LOADING;
274
        this.curated_status = this.errorCodes.LOADING;
255 275

  
256
    if(this.openaireId) {
257
      this.pending_status = this.errorCodes.LOADING;
258
      this.curated_status = this.errorCodes.LOADING;
276
        this.showTables = false;
277
        this.pending_claims = [];
278
        this.curated_claims = [];
259 279

  
260
      this.showTables = false;
261
      this.pending_claims = [];
262
      this.curated_claims = [];
280
        this.activePendingPage.page = 1;
281
        this.totalPendingResults.count = 0;
282
        this.activeCuratedPage.page = 1;
283
        this.totalCuratedResults.count = 0;
263 284

  
264
      this.activePendingPage.page = 1;
265
      this.totalPendingResults.count = 0;
266
      this.activeCuratedPage.page = 1;
267
      this.totalCuratedResults.count = 0;
285
        this.claimsByTokenService.getClaims(this.openaireId,  this.properties.claimsAPIURL).subscribe(
286
            data => {
287
              //this.closeLoading();
288
              this.accessStatus = "valid";
289
                //console.info(data);
290
                this.claims = data.data;
291
                for(let claim of this.claims) {
292
                  if(claim.targetType == "project") {
293
                    this.project = claim.target;
294
                  } else {
295
                    this.project = claim.source;
296
                  }
297
                  if(claim.curatedBy) {
298
                    this.curated_claims.push(claim);
299
                  } else {
300
                    this.pending_claims.push(claim);
301
                  }
302
                }
268 303

  
269
      this.claimsByTokenService.getClaims(this.openaireId,  this.properties.claimsAPIURL).subscribe(
270
          data => {
271
            //this.closeLoading();
272
            this.accessStatus = "valid";
273
              //console.info(data);
274
              this.claims = data.data;
275
              for(let claim of this.claims) {
276
                if(claim.targetType == "project") {
277
                  this.project = claim.target;
278
                } else {
279
                  this.project = claim.source;
304
                this.totalPendingResults.count = this.pending_claims.length;
305
                this.totalCuratedResults.count = this.curated_claims.length;
306

  
307
                if(this.project) {
308
                  this.updateTitle("Claims For Project Managers - "+this.project.name);
280 309
                }
281
                if(claim.curatedBy) {
282
                  this.curated_claims.push(claim);
310
                this.showTables = true;
311

  
312
                if(!this.triggered) {
313
                  console.info("initial load");
314
                  this.triggerInitialLoad();
283 315
                } else {
284
                  this.pending_claims.push(claim);
316
                  console.info("rerender");
317
                  var table1 = $('#table1').DataTable();
318
                  table1.clear();
319

  
320
                  var table2 = $('#table2').DataTable();
321
                  table2.clear();
322

  
323
                  this.rerender();
285 324
                }
286
              }
287 325

  
288
              this.totalPendingResults.count = this.pending_claims.length;
289
              this.totalCuratedResults.count = this.curated_claims.length;
290

  
291
              if(this.project) {
292
                this.updateTitle("Claims For Project Managers - "+this.project.name);
326
                this.pending_status = this.errorCodes.DONE;
327
                this.curated_status = this.errorCodes.DONE;
328
            },
329
            err => {
330
              if(err.status == '404') {
331
                this.pending_status = this.errorCodes.NOT_FOUND;
332
                this.curated_status = this.errorCodes.NOT_FOUND;
333
              } else if(err.status == '500') {
334
                this.pending_status = this.errorCodes.ERROR;
335
                this.curated_status = this.errorCodes.ERROR;
336
              } else {
337
                this.pending_status = this.errorCodes.NOT_AVAILABLE;
338
                this.curated_status = this.errorCodes.NOT_AVAILABLE;
293 339
              }
294 340
              this.showTables = true;
295 341

  
296 342
              if(!this.triggered) {
297
                console.info("initial load");
298 343
                this.triggerInitialLoad();
299 344
              } else {
300
                console.info("rerender");
301 345
                var table1 = $('#table1').DataTable();
302 346
                table1.clear();
303 347

  
......
307 351
                this.rerender();
308 352
              }
309 353

  
310
              this.pending_status = this.errorCodes.DONE;
311
              this.curated_status = this.errorCodes.DONE;
312
          },
313
          err => {
314
            if(err.status == '404') {
315
              this.pending_status = this.errorCodes.NOT_FOUND;
316
              this.curated_status = this.errorCodes.NOT_FOUND;
317
            } else if(err.status == '500') {
318
              this.pending_status = this.errorCodes.ERROR;
319
              this.curated_status = this.errorCodes.ERROR;
320
            } else {
321
              this.pending_status = this.errorCodes.NOT_AVAILABLE;
322
              this.curated_status = this.errorCodes.NOT_AVAILABLE;
354
              this.accessStatus = "invalid";
355
              console.log(err);
323 356
            }
324
            this.showTables = true;
325

  
326
            if(!this.triggered) {
327
              this.triggerInitialLoad();
328
            } else {
329
              var table1 = $('#table1').DataTable();
330
              table1.clear();
331

  
332
              var table2 = $('#table2').DataTable();
333
              table2.clear();
334

  
335
              this.rerender();
336
            }
337

  
338
            this.accessStatus = "invalid";
339
            console.log(err);
340
          }
341
        );
357
          );
342 358
      } else {
343
        this.accessStatus = "invalid";
359
          this.accessStatus = "invalid";
344 360
      }
361
    }
345 362
  }
346 363

  
347 364
  selectApprove(id:string, event, mode: string) {
348
    var value = event.currentTarget.checked;
349
    if(value){
350
      if(mode == "pending") {
351
        this.selectedRight_PendingMode.add(id);
352
        this.selectedWrong_PendingMode.delete(id);
353
      } else {
354
        this.selectedRight_CuratedMode.add(id);
355
        this.selectedWrong_CuratedMode.delete(id);
365
    if(!Session.isLoggedIn()){
366
      console.info(this._router.url);
367
      this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl":  this._router.url} });
368
    } else {
369
      var value = event.currentTarget.checked;
370
      if(value){
371
        if(mode == "pending") {
372
          this.selectedRight_PendingMode.add(id);
373
          this.selectedWrong_PendingMode.delete(id);
374
        } else {
375
          this.selectedRight_CuratedMode.add(id);
376
          this.selectedWrong_CuratedMode.delete(id);
377
        }
378
      }else{
379
        if(mode == "pending") {
380
          this.selectedRight_PendingMode.delete(id);
381
        }
382
        // } else {
383
        //   this.selectedRight_CuratedMode.delete(id);
384
        //   this.selectedWrong_CuratedMode.add(id);
385
        // }
356 386
      }
357
    }else{
358
      if(mode == "pending") {
359
        this.selectedRight_PendingMode.delete(id);
360
      }
361
      // } else {
362
      //   this.selectedRight_CuratedMode.delete(id);
363
      //   this.selectedWrong_CuratedMode.add(id);
364
      // }
365 387
    }
366 388
  }
367 389

  
368 390
  selectDisapprove(id:string, event, mode: string) {
369
    var value = event.currentTarget.checked;
370
    if(value){
371
      if(mode == "pending") {
372
        this.selectedWrong_PendingMode.add(id);
373
        this.selectedRight_PendingMode.delete(id);
374
      } else {
375
        this.selectedWrong_CuratedMode.add(id);
376
        this.selectedRight_CuratedMode.delete(id);
391
    if(!Session.isLoggedIn()){
392
      console.info(this._router.url);
393
      this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl":  this._router.url} });
394
    } else {
395
      var value = event.currentTarget.checked;
396
      if(value){
397
        if(mode == "pending") {
398
          this.selectedWrong_PendingMode.add(id);
399
          this.selectedRight_PendingMode.delete(id);
400
        } else {
401
          this.selectedWrong_CuratedMode.add(id);
402
          this.selectedRight_CuratedMode.delete(id);
403
        }
404
      }else{
405
        if(mode == "pending") {
406
          this.selectedWrong_PendingMode.delete(id);
407
        }
408
        // } else {
409
        //   this.selectedWrong_CuratedMode.delete(id);
410
        //   this.selectedRight_CuratedMode.add(id);
411
        // }
377 412
      }
378
    }else{
379
      if(mode == "pending") {
380
        this.selectedWrong_PendingMode.delete(id);
381
      }
382
      // } else {
383
      //   this.selectedWrong_CuratedMode.delete(id);
384
      //   this.selectedRight_CuratedMode.add(id);
385
      // }
386 413
    }
387 414
  }
388 415

  
......
415 442
  }
416 443

  
417 444
  cancelEditOfCuration(claim: any) {
418
    console.info("cancelEditOfCuration - approved:"+claim.approved);
419
    if(claim.approved) {
420
      //this.selectedRight_CuratedMode.add(claim.id);
421
      this.selectedWrong_CuratedMode.delete(claim.id);
445
    if(!Session.isLoggedIn()){
446
      console.info(this._router.url);
447
      this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl":  this._router.url} });
422 448
    } else {
423
      this.selectedRight_CuratedMode.delete(claim.id);
424
      //this.selectedWrong_CuratedMode.add(claim.id);
449
      console.info("cancelEditOfCuration - approved:"+claim.approved);
450
      if(claim.approved) {
451
        //this.selectedRight_CuratedMode.add(claim.id);
452
        this.selectedWrong_CuratedMode.delete(claim.id);
453
      } else {
454
        this.selectedRight_CuratedMode.delete(claim.id);
455
        //this.selectedWrong_CuratedMode.add(claim.id);
456
      }
425 457
    }
426 458
  }
427 459

  
428 460
  saveEdited(claim: any, editable_index: number) {
429
    this.curated_status = this.errorCodes.LOADING;
461
    if(!Session.isLoggedIn()){
462
      console.info(this._router.url);
463
      this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl":  this._router.url} });
464
    } else {
465
      this.curated_status = this.errorCodes.LOADING;
430 466

  
431
    let approved: boolean = this.isRight_CuratedMode(claim);
467
      let approved: boolean = this.isRight_CuratedMode(claim);
432 468

  
433
    if(approved == claim.approved) {
434
      this.selectedRight_CuratedMode.delete(claim.id);
435
      this.selectedWrong_CuratedMode.delete(claim.id);
436
      this.editable.delete(editable_index);
469
      if(approved == claim.approved) {
470
        this.selectedRight_CuratedMode.delete(claim.id);
471
        this.selectedWrong_CuratedMode.delete(claim.id);
472
        this.editable.delete(editable_index);
437 473

  
438
      this.curated_status = this.errorCodes.DONE;
474
        this.curated_status = this.errorCodes.DONE;
475
      } else {
476
        let claimCurationInfo: {"id": string, "approved": boolean} = {"id": claim.id, "approved": approved};
477

  
478
        this.claimsByTokenService.updateClaimCuration(claimCurationInfo, this.properties.claimsAPIURL).subscribe(
479
            data => {
480
              console.info(data);
481
              this.selectedRight_CuratedMode.delete(claim.id);
482
              this.selectedWrong_CuratedMode.delete(claim.id);
483
              this.editable.delete(editable_index);
484

  
485
              this.validateJWTandToken();
486
            },
487
            err => {
488
              console.log(err);
489
              this.curated_status = this.errorCodes.NOT_SAVED;
490
            }
491
          );
492
      }
493
    }
494
  }
495

  
496
  saveChanges() {
497
    if(!Session.isLoggedIn()){
498
      console.info(this._router.url);
499
      this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl":  this._router.url} });
439 500
    } else {
440
      let claimCurationInfo: {"id": string, "approved": boolean} = {"id": claim.id, "approved": approved};
441

  
442
      this.claimsByTokenService.updateClaimCuration(claimCurationInfo, this.properties.claimsAPIURL).subscribe(
501
      this.pending_status = this.errorCodes.LOADING;
502
      //this.openLoading();
503
      console.info("Changes Saved!, right-wrong", this.selectedRight_PendingMode, this.selectedWrong_PendingMode);
504
      this.claimsByTokenService.updateClaimsCuration(this.selectedRight_PendingMode, this.selectedWrong_PendingMode, this.properties.claimsAPIURL).subscribe(
443 505
          data => {
506
            //this.closeLoading();
444 507
            console.info(data);
445
            this.selectedRight_CuratedMode.delete(claim.id);
446
            this.selectedWrong_CuratedMode.delete(claim.id);
447
            this.editable.delete(editable_index);
448

  
508
            this.mode = "curated";
509
            this.clearCheckboxes();
449 510
            this.validateJWTandToken();
450 511
          },
451 512
          err => {
513
            //this.closeLoading();
452 514
            console.log(err);
453
            this.curated_status = this.errorCodes.NOT_SAVED;
515
            this.pending_status = this.errorCodes.NOT_SAVED;
454 516
          }
455 517
        );
456 518
    }
457 519
  }
458 520

  
459
  saveChanges() {
460
    this.pending_status = this.errorCodes.LOADING;
461
    //this.openLoading();
462
    console.info("Changes Saved!, right-wrong", this.selectedRight_PendingMode, this.selectedWrong_PendingMode);
463
    this.claimsByTokenService.updateClaimsCuration(this.selectedRight_PendingMode, this.selectedWrong_PendingMode, this.properties.claimsAPIURL).subscribe(
464
        data => {
465
          //this.closeLoading();
466
          console.info(data);
467
          this.mode = "curated";
468
          this.clearCheckboxes();
469
          this.validateJWTandToken();
470
        },
471
        err => {
472
          //this.closeLoading();
473
          console.log(err);
474
          this.pending_status = this.errorCodes.NOT_SAVED;
475
        }
476
      );
477
  }
478

  
479 521
  clearCheckboxes() {
480
    this.pending_status = this.errorCodes.LOADING;
481
    this.selectedRight_PendingMode.clear();
482
    this.selectedWrong_PendingMode.clear();
483
    this.pending_status = this.errorCodes.DONE;
522
    if(!Session.isLoggedIn()){
523
      console.info(this._router.url);
524
      this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl":  this._router.url} });
525
    } else {
526
      this.pending_status = this.errorCodes.LOADING;
527
      this.selectedRight_PendingMode.clear();
528
      this.selectedWrong_PendingMode.clear();
529
      this.pending_status = this.errorCodes.DONE;
530
    }
484 531
  }
485 532

  
486 533
  public openLoading(){

Also available in: Unified diff