Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(project landing page): use metadata endpoint to get data from backend (DSP-1199) #400

Merged
merged 16 commits into from Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,6 +1,6 @@
import { Component, Input } from '@angular/core';
import { Attribution, IId, Organization, Person } from '@dasch-swiss/dsp-js';
import { DatasetMetadataService } from '../dataset-metadata.service';
import { MetadataService } from '../dataset-metadata.service';

@Component({
selector: 'app-attribution-tab-view',
Expand All @@ -15,18 +15,18 @@ export class AttributionTabViewComponent {

currentAgent: Person | Organization | IId;

constructor(private _datasetMetadataService: DatasetMetadataService) {
constructor(private _metadataService: MetadataService) {
}

// return the type of agent to use correct template to display it
setAgent (agent: Person | Organization | IId): string {
let atype = this._datasetMetadataService.getContactType(agent);
let atype = this._metadataService.getContactType(agent);
if (atype) {
this.currentAgent = agent;
return atype;
} else {
this.currentAgent = this.subProperties[agent.id];
atype = this._metadataService.getContactType(this.currentAgent);
}
this.currentAgent = this.subProperties[agent.id];
atype = this._datasetMetadataService.getContactType(this.currentAgent);
return atype;
}
}
6 changes: 3 additions & 3 deletions src/app/project/board/board.component.ts
Expand Up @@ -138,11 +138,11 @@ export class BoardComponent implements OnInit {
this.projectsMetadata.projectsMetadata.forEach((obj) => {
if (obj instanceof Dataset) {
this.datasetList.push(obj);
}
if (obj instanceof SingleProject) {
} else if (obj instanceof SingleProject) {
this.singleProjectList.push(obj);
} else {
this.subProperties[obj.id] = obj;
}
this.subProperties[obj.id] = obj;
});

const dsOptions = [];
Expand Down
@@ -1,6 +1,6 @@
import { Component, Input, OnInit } from '@angular/core';
import { IId, Organization, Person } from '@dasch-swiss/dsp-js';
import { DatasetMetadataService } from '../dataset-metadata.service';
import { MetadataService } from '../dataset-metadata.service';

@Component({
selector: 'app-contacts-tab-view',
Expand All @@ -16,14 +16,14 @@ export class ContactsTabViewComponent implements OnInit {
contactsList = [];
contactType: string;

constructor(private _datasetMetadataService: DatasetMetadataService) {
constructor(private _metadataService: MetadataService) {
}

ngOnInit() {

if (this.contactDetails) {
// check which type of array is present
this.contactType = this._datasetMetadataService.getContactType(this.contactDetails[0]);
this.contactType = this._metadataService.getContactType(this.contactDetails[0]);

// if contactType is person or organization
if (this.contactType) {
Expand All @@ -35,8 +35,7 @@ export class ContactsTabViewComponent implements OnInit {
for (const contact of this.contactDetails) {
this.contactsList.push(this.subProperties[contact.id]);
}
this.contactType = this._datasetMetadataService.getContactType(this.contactsList[0]);

this.contactType = this._metadataService.getContactType(this.contactsList[0]);
}
}
}
31 changes: 15 additions & 16 deletions src/app/project/board/dataset-metadata.service.ts
Expand Up @@ -2,25 +2,24 @@ import { Injectable } from '@angular/core';
import { IId, Organization, Person } from '@dasch-swiss/dsp-js';

@Injectable({
providedIn: 'root'
providedIn: 'root'
})
export class DatasetMetadataService {
export class MetadataService {

constructor() { }
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';
/**
* 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';
} else if (obj instanceof Organization) {
return 'organization';
}
return undefined;
Comment on lines +21 to +22
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ending else is missing here

Copy link
Contributor Author

@waychal waychal Mar 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my understanding if the case is default (and there is no further code to run in the function, we can add it without using else block. isn't it right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct.

}
if (obj instanceof Organization) {
return 'organization';
}
return undefined;
}

}
Expand Up @@ -3,7 +3,7 @@ import {
DataManagementPlan,
Grant, IId, Organization, Person, SingleProject
} from '@dasch-swiss/dsp-js';
import { DatasetMetadataService } from '../dataset-metadata.service';
import { MetadataService } from '../dataset-metadata.service';

@Component({
selector: 'app-project-tab-view',
Expand All @@ -28,7 +28,7 @@ export class ProjectTabViewComponent implements OnInit {
funderType: string;
grants = [];

constructor(private _datasetMetadataService: DatasetMetadataService) {
constructor(private _metadataService: MetadataService) {
}

ngOnInit() {
Expand Down Expand Up @@ -62,7 +62,7 @@ export class ProjectTabViewComponent implements OnInit {

getFunders(flist: any[]) {
// check if it is person, organization or IId
this.funderType = this._datasetMetadataService.getContactType(flist[0]);
this.funderType = this._metadataService.getContactType(flist[0]);

if (this.funderType) {
this.funders = flist;
Expand All @@ -72,18 +72,16 @@ export class ProjectTabViewComponent implements OnInit {
for (const funder of flist) {
this.funders.push(this.subProperties[funder.id]);
}
this.funderType = this._datasetMetadataService.getContactType(this.funders[0]);
this.funderType = this._metadataService.getContactType(this.funders[0]);
}

getGrants(glist: any[]) {
let tmpGrants: Grant[] = [];

if (glist[0] instanceof Grant) {
tmpGrants = glist;
}
// if it is IId objects array, retrive it's details
// tslint:disable-next-line
else {
} else {
// if it is IId objects array, retrive it's details
for (const iid of glist) {
tmpGrants.push(this.subProperties[iid.id]);
}
Expand All @@ -93,20 +91,18 @@ export class ProjectTabViewComponent implements OnInit {
let tmpGrantObj: object;

// checck if grant contains person, organization or IId objects
let ftype = this._datasetMetadataService.getContactType(grant.funder[0]);
let ftype = this._metadataService.getContactType(grant.funder[0]);
let flist = [];
if (ftype) {
// it is a person of organization object
flist = grant.funder;
}
// tslint:disable-next-line
else {
} else {
// it means it is a IId object. So we need to retrive the details
// of every funder using the id provided here
for (const fund of grant.funder) {
flist.push(this.subProperties[fund.id]);
}
ftype = this._datasetMetadataService.getContactType(flist[0]);
ftype = this._metadataService.getContactType(flist[0]);
}

tmpGrantObj = {
Expand Down