Project

General

Profile

« Previous | Next » 

Revision 60454

[Connect | Trunk]: 1. Add new roles functionllities (subscribe - role-verification). 2. Comment customization. 3. Refactor getting community logic

View differences:

community.component.ts
38 38
  
39 39
  public projectTotal = null;
40 40
  public contentProviderTotal = null;
41

  
41
  
42 42
  public projectsCalculated: boolean = false;
43 43
  public contentProvidersCalculated: boolean = false;
44

  
44
  
45 45
  params: any = {};
46
  properties: EnvProperties;
47

  
46
  properties: EnvProperties = properties;
47
  
48 48
  public errorCodes: ErrorCodes = new ErrorCodes();
49 49
  // Request results of each tab only the one time (first time tab is clicked)
50 50
  private reloadPublications: boolean = true;
51 51
  private reloadDatasets: boolean = true;
52 52
  private reloadSoftware: boolean = true;
53 53
  private reloadOrps: boolean = true;
54

  
54
  
55 55
  // Variables for publications, research data, projects, content providers, related content providers tabs
56 56
  public fetchPublications: FetchResearchResults;
57 57
  public fetchDatasets: FetchResearchResults;
58 58
  public fetchSoftware: FetchResearchResults;
59 59
  public fetchOrps: FetchResearchResults;
60 60
  public searchNumber: number = 5;
61

  
61
  
62 62
  @Input() communityId = null;
63 63
  public community = null;
64

  
64
  
65 65
  public communityInfo = null;
66

  
66
  
67 67
  public showLoading: boolean = true;
68 68
  masterZenodoCommunity = null;
69 69
  zenodoCommunityIdS = [];
70 70
  showAllDescription = false;
71 71
  public thresholdDescription: number = 500;
72 72
  public descriptionDiff: number = 100;
73

  
73
  
74 74
  subscribers: number = 0;
75

  
75
  
76 76
  // TODO Unsubscribe
77 77
  subs: Subscription[] = [];
78

  
78
  
79 79
  @ViewChild(StatisticsForDashboardComponent) statistics: StatisticsForDashboardComponent = null;
80 80
  public activeTab = "summary";
81 81
  public show: string = 'overview';
82
  public analyticsActiveTab:string = "";
82
  public analyticsActiveTab: string = "";
83 83
  public analyticsChecked: boolean = false;
84

  
84
  
85 85
  searchLinkToResults: string = null;
86

  
86
  
87 87
  searchLinkToProjects: string = null;
88 88
  searchLinkToDataProviders: string = null;
89 89
  searchLinkToAdvancedResults: string = null;
90 90
  shareInZenodoPage: string = null;
91 91
  public routerHelper: RouterHelper = new RouterHelper();
92 92
  private user: User;
93

  
93
  
94 94
  @ViewChild(SubscribeComponent) subscribeComponent: SubscribeComponent = null;
95 95
//Search Form
96 96
  selectedEntity;
97 97
  selectedEntitySimpleUrl;
98 98
  selectedEntityAdvancedUrl;
99
  keyword:string ="";
99
  keyword: string = "";
100 100
  customFilter;
101
  placeholderText="Search by title, author, abstract, DOI, orcid... ";
102

  
101
  placeholderText = "Search by title, author, abstract, DOI, orcid... ";
102
  
103 103
  constructor(
104 104
    private element: ElementRef,
105 105
    private route: ActivatedRoute,
......
117 117
    private _zenodoCommunitieService: ZenodoCommunitiesService,
118 118
    private seoService: SEOService,
119 119
    private userManagementService: UserManagementService) {
120

  
120
    
121 121
    var description = "OpenAIRE - Connect, Community Dashboard, research community";
122 122
    var title = "OpenAIRE - Connect";
123 123
    this._meta.updateTag({content: description}, "name='description'");
124 124
    this._meta.updateTag({content: description}, "property='og:description'");
125 125
    this._meta.updateTag({content: title}, "property='og:title'");
126 126
    this._title.setTitle(title);
127

  
127
    
128 128
    this.fetchPublications = new FetchResearchResults(this._searchResearchResultsService);
129 129
    this.fetchDatasets = new FetchResearchResults(this._searchResearchResultsService);
130 130
    this.fetchSoftware = new FetchResearchResults(this._searchResearchResultsService);
131 131
    this.fetchOrps = new FetchResearchResults(this._searchResearchResultsService);
132 132
  }
133

  
133
  
134 134
  public ngOnInit() {
135
    this.properties = properties;
136 135
    this.searchLinkToResults = this.properties.searchLinkToResults;
137 136
    this.searchLinkToProjects = this.properties.searchLinkToProjects;
138 137
    this.searchLinkToDataProviders = this.properties.searchLinkToDataProviders;
139 138
    this.searchLinkToAdvancedResults = this.properties.searchLinkToAdvancedResults;
140 139
    this.shareInZenodoPage = this.properties.shareInZenodoPage;
141
    this.url =properties.domain + properties.baseLink + this._router.url;
140
    this.url = properties.domain + properties.baseLink + this._router.url;
142 141
    this.seoService.createLinkForCanonicalURL(this.url, false);
143 142
    this._meta.updateTag({content: this.url}, "property='og:url'");
144 143
    this.subs.push(this.userManagementService.getUserInfo().subscribe(user => {
145 144
      this.user = user;
146 145
    }));
147
    if (this.communityId != null && this.communityId != '') {
148
      this.customFilter = new SearchCustomFilter("Community", "communityId", this.communityId, "");
149
      this.subs.push(this._communityService.getCommunityByState(this.properties, this.properties.communityAPI + this.communityId).subscribe(
150
        community => {
146
    this.customFilter = new SearchCustomFilter("Community", "communityId", this.communityId, "");
147
    this.subs.push(this._communityService.getCommunityAsObservable().subscribe(
148
      community => {
149
        if(community) {
151 150
          if (typeof document !== 'undefined') {
152 151
            HelperFunctions.scroll();
153 152
          }
154 153
          this.community = community;
155
          if(community.description != null && (community.description.length - this.thresholdDescription <= this.descriptionDiff)) {
154
          if (community.description != null && (community.description.length - this.thresholdDescription <= this.descriptionDiff)) {
156 155
            this.thresholdDescription = community.description.length;
157 156
          }
158

  
157
  
159 158
          if (this.properties.environment == "development") {
160 159
            this.params = {communityId: community.communityId};
161 160
          }
......
184 183
              this.handleError("Error getting list of zenodo communities for community with openaire id: " + this.communityId, error);
185 184
            }
186 185
          ));
187

  
188
          //console.log(community);
189
        }));
190

  
191
      this.countResearchResults("publication");
192
      this.countResearchResults("dataset");
193
      this.countResearchResults("software");
194
      this.countResearchResults("other");
195

  
196
      this.subs.push(this._searchCommunityProjectsService.countTotalProjects(this.properties, this.communityId).subscribe(
197
        projectTotal => {
198
          this.projectTotal = projectTotal;
199
        },
200
        error => {
201
          this.handleError("Error getting number of projects for community with id: " + this.communityId, error);
202
        },
203
        () => {
204
          this.projectsCalculated = true;
205 186
        }
206
      ));
207

  
208
      this.subs.push(this._searchCommunityDataprovidersService.countTotalDataproviders(this.properties, this.communityId).subscribe(
209
        contentProviderTotal => {
210
          this.contentProviderTotal = contentProviderTotal;
211
          //console.log(contentProviderTotal);
212
        },
213
        error => {
214
          this.handleError("Error getting number of content providers for community with id: " + this.communityId, error);
215
        },
216
        () => {
217
          this.contentProvidersCalculated = true;
218
        }
219
      ));
220
      this.subs.push(this.config.communityInformationState.subscribe(
221
        res => {
222
          this.communityInfo = res;
223
        },
224
        error => {
225
          //console.log(error)
226
          this.handleError("Error getting community with id: " + this.communityId, error);
227
        }
228
      ));
229
    }
187
      }));
188
    
189
    this.countResearchResults("publication");
190
    this.countResearchResults("dataset");
191
    this.countResearchResults("software");
192
    this.countResearchResults("other");
193
    
194
    this.subs.push(this._searchCommunityProjectsService.countTotalProjects(this.properties, this.communityId).subscribe(
195
      projectTotal => {
196
        this.projectTotal = projectTotal;
197
      },
198
      error => {
199
        this.handleError("Error getting number of projects for community with id: " + this.communityId, error);
200
      },
201
      () => {
202
        this.projectsCalculated = true;
203
      }
204
    ));
205
    
206
    this.subs.push(this._searchCommunityDataprovidersService.countTotalDataproviders(this.properties, this.communityId).subscribe(
207
      contentProviderTotal => {
208
        this.contentProviderTotal = contentProviderTotal;
209
        //console.log(contentProviderTotal);
210
      },
211
      error => {
212
        this.handleError("Error getting number of content providers for community with id: " + this.communityId, error);
213
      },
214
      () => {
215
        this.contentProvidersCalculated = true;
216
      }
217
    ));
218
    this.subs.push(this.config.communityInformationState.subscribe(
219
      res => {
220
        this.communityInfo = res;
221
      },
222
      error => {
223
        //console.log(error)
224
        this.handleError("Error getting community with id: " + this.communityId, error);
225
      }
226
    ));
230 227
  }
231

  
228
  
232 229
  private searchPublications(page: number, size: number) {
233 230
    this.setActiveTab("publication");
234

  
231
    
235 232
    if (this.reloadPublications &&
236 233
      (this.fetchPublications.searchUtils.status == this.errorCodes.LOADING ||
237 234
        (this.fetchPublications.searchUtils.status == this.errorCodes.DONE && this.fetchPublications.searchUtils.totalResults > 0)
......
241 238
    }
242 239
    this.reloadPublications = false;
243 240
  }
244

  
241
  
245 242
  private searchDatasets(page: number, size: number) {
246 243
    this.setActiveTab("dataset");
247

  
244
    
248 245
    if (this.reloadDatasets &&
249 246
      (this.fetchDatasets.searchUtils.status == this.errorCodes.LOADING ||
250 247
        (this.fetchDatasets.searchUtils.status == this.errorCodes.DONE && this.fetchDatasets.searchUtils.totalResults > 0)
......
254 251
    }
255 252
    this.reloadDatasets = false;
256 253
  }
257

  
254
  
258 255
  private searchSoftware(page: number, size: number) {
259 256
    this.setActiveTab("software");
260

  
257
    
261 258
    if (this.reloadSoftware &&
262 259
      (this.fetchSoftware.searchUtils.status == this.errorCodes.LOADING ||
263 260
        (this.fetchSoftware.searchUtils.status == this.errorCodes.DONE && this.fetchSoftware.searchUtils.totalResults > 0)
......
267 264
    }
268 265
    this.reloadSoftware = false;
269 266
  }
270

  
267
  
271 268
  private searchOrps(page: number, size: number) {
272 269
    this.setActiveTab("other");
273

  
270
    
274 271
    if (this.reloadOrps &&
275 272
      (this.fetchOrps.searchUtils.status == this.errorCodes.LOADING ||
276 273
        (this.fetchOrps.searchUtils.status == this.errorCodes.DONE && this.fetchOrps.searchUtils.totalResults > 0)
......
280 277
    }
281 278
    this.reloadOrps = false;
282 279
  }
283

  
280
  
284 281
  private countResearchResults(resultType: string) {
285 282
    let fetch: FetchResearchResults;
286

  
283
    
287 284
    if (resultType == "publication") {
288 285
      fetch = this.fetchPublications;
289 286
    } else if (resultType == "dataset") {
......
293 290
    } else if (resultType == "other") {
294 291
      fetch = this.fetchOrps;
295 292
    }
296

  
293
    
297 294
    fetch.getNumForCommunity(resultType, this.communityId, this.properties);
298 295
  }
299 296
  
......
306 303
    this.fetchOrps.clearSubscriptions();
307 304
    this.fetchSoftware.clearSubscriptions();
308 305
  }
309

  
306
  
310 307
  isEntityEnabled(entity: string) {
311 308
    return this.communityInfo.entities.some(x => x['pid'] == entity && x['isEnabled'] === true);
312 309
  }
313

  
310
  
314 311
  isRouteEnabled(route: string) {
315 312
    return this.communityInfo.pages.some(x => x['route'] == route && x['isEnabled'] === true);
316 313
  }
317

  
314
  
318 315
  showInvite() {
319 316
    return this.isManager();
320 317
  }
321

  
318
  
322 319
  isManager() {
323 320
    if (!this.user) {
324 321
      return false;
......
330 327
    }
331 328
    return Session.isPortalAdministrator(this.user) || Session.isCommunityCurator(this.user) || index != -1;
332 329
  }
333

  
330
  
334 331
  private handleError(message: string, error) {
335 332
    console.error("Community (component): " + message, error);
336 333
  }
337

  
334
  
338 335
  getSearchPlaceHolder() {
339 336
    var entities = [];
340 337
    if (this.isEntityEnabled("publication")) {
......
351 348
    }
352 349
    return "Search" + ((entities.length > 0) ? (" for " + entities.join(', ') + "...") : "");
353 350
  }
354

  
351
  
355 352
  countOtherGraphs() {
356 353
    var count = 0;
357 354
    if (this.statistics && this.statistics.allowedEntities) {
......
363 360
    }
364 361
    return count;
365 362
  }
366

  
363
  
367 364
  createParams(param) {
368 365
    return StringUtils.quote(StringUtils.URIEncode(param));
369 366
  }
370

  
367
  
371 368
  private setActiveTab(entityType: string) {
372 369
    if (entityType == "other") {
373 370
      this.activeTab = "orp";
......
375 372
      this.activeTab = entityType;
376 373
    }
377 374
  }
378

  
375
  
379 376
  public getParamsForSearchLink(type: string = "") {
380
    if(type) {
377
    if (type) {
381 378
      return this.routerHelper.createQueryParams(['type', 'qf', 'sortBy'], [type, 'false', 'resultdateofacceptance,descending']);
382 379
    } else {
383 380
      return {};
384 381
    }
385 382
  }
386

  
383
  
387 384
  private getEntityName(entityType: string, plural: boolean, full: boolean): string {
388 385
    if (entityType == "publication") {
389 386
      return "publication" + (plural ? "s" : "");
......
395 392
      return (full ? ("other research product" + (plural ? "s" : "")) : "other");
396 393
    }
397 394
  }
398

  
395
  
399 396
  public buildProjectsAndContentProvidesTooltip(): string {
400 397
    let tooltipContent: string = "<div class='uk-margin'>";
401

  
402
    if(this.projectTotal != null  && this.projectTotal > 0 && this.isEntityEnabled('project') && this.isRouteEnabled(this.searchLinkToProjects)) {
398
    
399
    if (this.projectTotal != null && this.projectTotal > 0 && this.isEntityEnabled('project') && this.isRouteEnabled(this.searchLinkToProjects)) {
403 400
      tooltipContent += "<span class='uk-text-bold'>Projects</span>";
404 401
    }
405
    if(this.projectTotal != null  && this.projectTotal > 0 && this.isEntityEnabled('project') && this.isRouteEnabled(this.searchLinkToProjects)
406
      && (this.contentProviderTotal != null  && this.contentProviderTotal > 0 && this.isEntityEnabled('datasource') && this.isRouteEnabled(this.searchLinkToDataProviders))) {
402
    if (this.projectTotal != null && this.projectTotal > 0 && this.isEntityEnabled('project') && this.isRouteEnabled(this.searchLinkToProjects)
403
      && (this.contentProviderTotal != null && this.contentProviderTotal > 0 && this.isEntityEnabled('datasource') && this.isRouteEnabled(this.searchLinkToDataProviders))) {
407 404
      tooltipContent += " and ";
408 405
    }
409
    if(this.contentProviderTotal != null  && this.contentProviderTotal > 0 && this.isEntityEnabled('datasource') && this.isRouteEnabled(this.searchLinkToDataProviders)) {
406
    if (this.contentProviderTotal != null && this.contentProviderTotal > 0 && this.isEntityEnabled('datasource') && this.isRouteEnabled(this.searchLinkToDataProviders)) {
410 407
      tooltipContent += "<span class='uk-text-bold'>Content Providers</span>";
411 408
    }
412

  
409
    
413 410
    tooltipContent += " have been selected as relevant for your community by the gateway curators.";
414 411
    tooltipContent += "</div>";
415

  
412
    
416 413
    return tooltipContent;
417 414
  }
418

  
415
  
419 416
  public buildZenodoCommunitiesTooltip(): string {
420 417
    let tooltipContent: string = "<div class='uk-margin'>";
421

  
418
    
422 419
    tooltipContent += "<span class='uk-text-bold'>Zenodo</span> is a catch-all repository for OpenAIRE.";
423 420
    tooltipContent += "<div class='uk-margin-small-top'>A <span class='uk-text-bold'>Zenodo Community</span> is created and curated by Zenodo users.</div>";
424 421
    tooltipContent += "</div>";
425 422
    return tooltipContent;
426 423
  }
427

  
428
  entityChanged($event){
424
  
425
  entityChanged($event) {
429 426
    this.selectedEntity = $event.entity;
430 427
    this.selectedEntitySimpleUrl = $event.simpleUrl;
431 428
    this.selectedEntityAdvancedUrl = $event.advancedUrl;
432
    if(this.selectedEntity == 'result'){
433
      this.placeholderText ="Search by title, author, abstract, DOI, orcid... ";
434
    }else if(this.selectedEntity == 'project') {
429
    if (this.selectedEntity == 'result') {
430
      this.placeholderText = "Search by title, author, abstract, DOI, orcid... ";
431
    } else if (this.selectedEntity == 'project') {
435 432
      this.placeholderText = "Search by project title, grant id, funder...";
436
    }else if(this.selectedEntity == 'dataprovider') {
433
    } else if (this.selectedEntity == 'dataprovider') {
437 434
      this.placeholderText = "Search by name...";
438
    }else{
435
    } else {
439 436
      this.placeholderText = "Search community content";
440 437
    }
441 438
  }
442

  
443
  goTo(simple:boolean){
444
    let url = (simple)?this.selectedEntitySimpleUrl:this.selectedEntityAdvancedUrl;
439
  
440
  goTo(simple: boolean) {
441
    let url = (simple) ? this.selectedEntitySimpleUrl : this.selectedEntityAdvancedUrl;
445 442
    let parameterNames = [];
446 443
    let parameterValues = [];
447
    if(this.keyword.length > 0) {
444
    if (this.keyword.length > 0) {
448 445
      parameterNames.push("fv0");
449 446
      parameterValues.push(this.keyword);
450 447
      parameterNames.push("f0");
......
452 449
    }
453 450
    this._router.navigate([url], {queryParams: this.routerHelper.createQueryParams(parameterNames, parameterValues)});
454 451
  }
455

  
456
  public countSubscribersEvent($event){
452
  
453
  public countSubscribersEvent($event) {
457 454
    this.subscribers = $event.value;
458 455
  }
459

  
456
  
460 457
  public checkStatistics(type: string) {
461 458
    return !!(this.isEntityEnabled(type)
462 459
      && this.statistics && this.statistics.statisticsDisplay && this.statistics.statisticsDisplay.isActive
......
472 469
          && this.statistics.allowedChartsMode['showInMonitor'][type]
473 470
          && this.statistics.allowedChartsMode['showInMonitor'][type].length > 0)));
474 471
  }
475

  
472
  
476 473
  public initializeAnalyticsActiveTab() {
477
    if(!this.analyticsChecked) {
478
      if(this.checkStatistics("publication")) {
474
    if (!this.analyticsChecked) {
475
      if (this.checkStatistics("publication")) {
479 476
        this.analyticsActiveTab = "publication";
480
      } else if(this.checkStatistics("dataset")) {
477
      } else if (this.checkStatistics("dataset")) {
481 478
        this.analyticsActiveTab = "dataset";
482
      } else if(this.checkStatistics("software")) {
479
      } else if (this.checkStatistics("software")) {
483 480
        this.analyticsActiveTab = "software";
484
      } else if(this.checkStatistics("orp")) {
481
      } else if (this.checkStatistics("orp")) {
485 482
        this.analyticsActiveTab = "orp";
486 483
      }
487 484
    }
488 485
  }
489

  
486
  
490 487
  public showAnalyticsTab() {
491 488
    this.initializeAnalyticsActiveTab();
492 489
    return this.analyticsActiveTab;
493 490
  }
494

  
491
  
495 492
  public onSelectActiveTab(activeTabId) {
496
    if(this.activeTab != "activaTabId") {   // tab really changed
493
    if (this.activeTab != "activaTabId") {   // tab really changed
497 494
      if (activeTabId == 'summary') {
498 495
        this.activeTab = 'summary';
499 496
      } else if (activeTabId == 'publications') {
......
506 503
        this.show = 'overview';
507 504
        this.searchSoftware(1, this.searchNumber);
508 505
      } else if (activeTabId == 'other') {
509
        this.show='overview';
506
        this.show = 'overview';
510 507
        this.searchOrps(1, this.searchNumber);
511 508
      } else if (activeTabId == 'analytics') {
512 509
        this.show = 'analysis';

Also available in: Unified diff