From b6884161f960ac26f7c12fd4792c2282ff8ad15b Mon Sep 17 00:00:00 2001 From: Snehal Kumbhar Date: Mon, 1 Mar 2021 22:09:32 +0100 Subject: [PATCH] chore(project landing page): use service to get contact type; correct identation; --- .../attribution-tab-view.component.ts | 21 +-- src/app/project/board/board.component.html | 134 +++++++++--------- src/app/project/board/board.component.ts | 3 +- .../contacts-tab-view.component.ts | 18 +-- .../project/board/dataset-metadata.service.ts | 26 ++++ .../organisation-template.component.ts | 2 +- .../person-template.component.ts | 2 +- .../project-tab-view.component.ts | 30 ++-- 8 files changed, 118 insertions(+), 118 deletions(-) create mode 100644 src/app/project/board/dataset-metadata.service.ts diff --git a/src/app/project/board/attribution-tab-view/attribution-tab-view.component.ts b/src/app/project/board/attribution-tab-view/attribution-tab-view.component.ts index 684190cf79..e1de2ec87c 100644 --- a/src/app/project/board/attribution-tab-view/attribution-tab-view.component.ts +++ b/src/app/project/board/attribution-tab-view/attribution-tab-view.component.ts @@ -1,5 +1,6 @@ import { Component, Input } from '@angular/core'; import { Attribution, IId, Organization, Person } from '@dasch-swiss/dsp-js'; +import { DatasetMetadataService } from '../dataset-metadata.service'; @Component({ selector: 'app-attribution-tab-view', @@ -14,26 +15,18 @@ export class AttributionTabViewComponent { currentAgent: Person | Organization | IId; + constructor(private _datasetMetadataService: DatasetMetadataService) { + } + // return the type of agent to use correct template to display it - setAgent (agent: Person | Organization | IId) { - let atype = this.getAgentType(agent); + setAgent (agent: Person | Organization | IId): string { + let atype = this._datasetMetadataService.getContactType(agent); if (atype) { this.currentAgent = agent; return atype; } this.currentAgent = this.subProperties[agent.id]; - atype = this.getAgentType(this.currentAgent); + atype = this._datasetMetadataService.getContactType(this.currentAgent); return atype; } - - getAgentType (agent: Person | Organization | IId) { - if (agent instanceof Person) { - return 'person'; - } - if (agent instanceof Organization) { - return 'organisation'; - } - return undefined; - } - } diff --git a/src/app/project/board/board.component.html b/src/app/project/board/board.component.html index 8ffb708ce8..b027d085aa 100644 --- a/src/app/project/board/board.component.html +++ b/src/app/project/board/board.component.html @@ -4,21 +4,21 @@
- - - Active - Deactivated + + + Active + Deactivated + + + + + - - - - -
@@ -53,9 +53,7 @@

-
-
@@ -139,12 +135,12 @@

- \ No newline at end of file + diff --git a/src/app/project/board/board.component.ts b/src/app/project/board/board.component.ts index 6fc3069179..0044e7553e 100644 --- a/src/app/project/board/board.component.ts +++ b/src/app/project/board/board.component.ts @@ -131,6 +131,7 @@ export class BoardComponent implements OnInit { this._dspApiConnection.v2.metadata.getProjectMetadata(this.project.id).subscribe( (response: ProjectsMetadata) => { this.projectsMetadata = response; + this.metadataLoading = false; // create list according to it's type @@ -181,7 +182,7 @@ export class BoardComponent implements OnInit { } } - getSubProperty(id: string) { + getSubProperty(id: string): object { return this.subProperties[id]; } diff --git a/src/app/project/board/contacts-tab-view/contacts-tab-view.component.ts b/src/app/project/board/contacts-tab-view/contacts-tab-view.component.ts index 60b40977aa..f5b4485d8a 100644 --- a/src/app/project/board/contacts-tab-view/contacts-tab-view.component.ts +++ b/src/app/project/board/contacts-tab-view/contacts-tab-view.component.ts @@ -1,5 +1,6 @@ import { Component, Input, OnInit } from '@angular/core'; import { IId, Organization, Person } from '@dasch-swiss/dsp-js'; +import { DatasetMetadataService } from '../dataset-metadata.service'; @Component({ selector: 'app-contacts-tab-view', @@ -15,11 +16,14 @@ export class ContactsTabViewComponent implements OnInit { contactsList = []; contactType: string; + constructor(private _datasetMetadataService: DatasetMetadataService) { + } + ngOnInit() { if (this.contactDetails) { // check which type of array is present - this.contactType = this.getContactType(this.contactDetails[0]); + this.contactType = this._datasetMetadataService.getContactType(this.contactDetails[0]); // if contactType is person or organization if (this.contactType) { @@ -31,18 +35,8 @@ export class ContactsTabViewComponent implements OnInit { for (const contact of this.contactDetails) { this.contactsList.push(this.subProperties[contact.id]); } - this.contactType = this.getContactType(this.contactsList[0]); - - } - } + this.contactType = this._datasetMetadataService.getContactType(this.contactsList[0]); - getContactType(obj: Person | Organization | IId) { - if (obj instanceof Person) { - return 'person'; - } - if (obj instanceof Organization) { - return 'organization'; } - return undefined; } } diff --git a/src/app/project/board/dataset-metadata.service.ts b/src/app/project/board/dataset-metadata.service.ts new file mode 100644 index 0000000000..16dbc91652 --- /dev/null +++ b/src/app/project/board/dataset-metadata.service.ts @@ -0,0 +1,26 @@ +import { Injectable } from '@angular/core'; +import { IId, Organization, Person } from '@dasch-swiss/dsp-js'; + +@Injectable({ + providedIn: 'root' +}) +export class DatasetMetadataService { + + constructor() { } + + /** + * used in project metadata page + * determine if the object is of type Person or Organization or Iid + * @param obj Person | Organization | IId + */ + getContactType(obj: Person | Organization | IId): string { + if (obj instanceof Person) { + return 'person'; + } + if (obj instanceof Organization) { + return 'organization'; + } + return undefined; + } + +} diff --git a/src/app/project/board/organisation-template/organisation-template.component.ts b/src/app/project/board/organisation-template/organisation-template.component.ts index 3c05ff422b..24b7739e70 100644 --- a/src/app/project/board/organisation-template/organisation-template.component.ts +++ b/src/app/project/board/organisation-template/organisation-template.component.ts @@ -26,7 +26,7 @@ import { Organization } from '@dasch-swiss/dsp-js';
- Email: + Email:
{{ organisation.email }} diff --git a/src/app/project/board/person-template/person-template.component.ts b/src/app/project/board/person-template/person-template.component.ts index 32b49b0d43..bba0899bfc 100644 --- a/src/app/project/board/person-template/person-template.component.ts +++ b/src/app/project/board/person-template/person-template.component.ts @@ -17,7 +17,7 @@ export class PersonTemplateComponent implements OnInit { ngOnInit() { // check if members list is the list of [Organization] or [Iid] - let isOrganizationType: boolean = false; + let isOrganizationType = false; // if it is [Organization] if (this.person.memberOf[0] instanceof Organization) { diff --git a/src/app/project/board/project-tab-view/project-tab-view.component.ts b/src/app/project/board/project-tab-view/project-tab-view.component.ts index f4f624a4ae..c0d9230e33 100644 --- a/src/app/project/board/project-tab-view/project-tab-view.component.ts +++ b/src/app/project/board/project-tab-view/project-tab-view.component.ts @@ -1,12 +1,9 @@ import { Component, Input, OnInit } from '@angular/core'; import { - SingleProject, DataManagementPlan, - Person, - Organization, - IId, - Grant + Grant, IId, Organization, Person, SingleProject } from '@dasch-swiss/dsp-js'; +import { DatasetMetadataService } from '../dataset-metadata.service'; @Component({ selector: 'app-project-tab-view', @@ -31,6 +28,9 @@ export class ProjectTabViewComponent implements OnInit { funderType: string; grants = []; + constructor(private _datasetMetadataService: DatasetMetadataService) { + } + ngOnInit() { // get DMP @@ -48,7 +48,7 @@ export class ProjectTabViewComponent implements OnInit { } - getDMP(currenDmps: DataManagementPlan | IId[]) { + getDMP(currenDmps: DataManagementPlan | IId[]): DataManagementPlan[] { if (currenDmps instanceof DataManagementPlan) { return [currenDmps]; } @@ -62,7 +62,7 @@ export class ProjectTabViewComponent implements OnInit { getFunders(flist: any[]) { // check if it is person, organization or IId - this.funderType = this.getFunderType(flist[0]); + this.funderType = this._datasetMetadataService.getContactType(flist[0]); if (this.funderType) { this.funders = flist; @@ -72,17 +72,7 @@ export class ProjectTabViewComponent implements OnInit { for (const funder of flist) { this.funders.push(this.subProperties[funder.id]); } - this.funderType = this.getFunderType(this.funders[0]); - } - - getFunderType(funder: Person | Organization | IId) { - if (funder instanceof Person) { - return 'person'; - } - if (funder instanceof Organization) { - return 'organization'; - } - return undefined; + this.funderType = this._datasetMetadataService.getContactType(this.funders[0]); } getGrants(glist: any[]) { @@ -103,7 +93,7 @@ export class ProjectTabViewComponent implements OnInit { let tmpGrantObj: object; // checck if grant contains person, organization or IId objects - let ftype = this.getFunderType(grant.funder[0]); + let ftype = this._datasetMetadataService.getContactType(grant.funder[0]); let flist = []; if (ftype) { // it is a person of organization object @@ -116,7 +106,7 @@ export class ProjectTabViewComponent implements OnInit { for (const fund of grant.funder) { flist.push(this.subProperties[fund.id]); } - ftype = this.getFunderType(flist[0]); + ftype = this._datasetMetadataService.getContactType(flist[0]); } tmpGrantObj = {