Skip to content

Commit

Permalink
chore(project landing page): correct linter for if..else block; updat…
Browse files Browse the repository at this point in the history
…e service name;
  • Loading branch information
Snehal Kumbhar committed Mar 2, 2021
1 parent dc0ef9c commit d8b4993
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 43 deletions.
@@ -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;
}
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

0 comments on commit d8b4993

Please sign in to comment.