Skip to content

Commit

Permalink
chore(project landing page): use service to get contact type; correct…
Browse files Browse the repository at this point in the history
… identation;
  • Loading branch information
Snehal Kumbhar committed Mar 1, 2021
1 parent 37b3dce commit b688416
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 118 deletions.
@@ -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',
Expand All @@ -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;
}

}
134 changes: 65 additions & 69 deletions src/app/project/board/board.component.html
Expand Up @@ -4,21 +4,21 @@
<div class="content large middle">
<!-- mobile version: status and edit icon displayed before the title -->
<div class="app-toolbar-mobile">
<span class="app-toolbar-action-status">
<span [class.active]="project.status" class="badge status">
<span *ngIf="project.status">Active</span>
<span *ngIf="!project.status">Deactivated</span>
<span class="app-toolbar-action-status">
<span [class.active]="project.status" class="badge status">
<span *ngIf="project.status">Active</span>
<span *ngIf="!project.status">Deactivated</span>
</span>
</span>
<span class="fill-remaining-space-action"></span>
<span class="app-toolbar-action-edit">
<button mat-icon-button
*ngIf="projectAdmin && project.status"
(click)="openDialog('editProject', project.shortname, project.shortcode)"
class="right">
<mat-icon>edit</mat-icon>
</button>
</span>
</span>
<span class="fill-remaining-space-action"></span>
<span class="app-toolbar-action-edit">
<button mat-icon-button
*ngIf="projectAdmin && project.status"
(click)="openDialog('editProject', project.shortname, project.shortcode)"
class="right">
<mat-icon>edit</mat-icon>
</button>
</span>
</div>

<!-- desktop and tablet version -->
Expand Down Expand Up @@ -53,9 +53,7 @@ <h2 class="mat-title">
</div>

<div class="project-info-container flex-panel" *ngIf="!metadataLoading && selectedDataset">

<div class="left-info column">

<section class="project description">
<div class="metadata-property">
<div class="property-label">
Expand Down Expand Up @@ -84,15 +82,15 @@ <h2 class="mat-title">
</ng-template>
<app-dataset-tab-view [metadata]="selectedDataset" [noOfDatasets]="datasetOptions.length"></app-dataset-tab-view>
</mat-tab>

<mat-tab>
<ng-template mat-tab-label>
<mat-icon class="tab-icon">assignment</mat-icon>
Attribution
</ng-template>
<app-attribution-tab-view [attributions]="selectedDataset.qualifiedAttribution" [subProperties]="subProperties"></app-attribution-tab-view>
</mat-tab>

<mat-tab>
<ng-template mat-tab-label>
<mat-icon class="tab-icon">receipt</mat-icon>
Expand All @@ -118,19 +116,17 @@ <h2 class="mat-title">
Dataset(s)
</div>
<div class="sidenav-prop-text">
<mat-radio-group
aria-label="Select a dataset"
name="datasetsList"
fxLayout="column"
(change)="updateDataset($event)">
<mat-radio-button
*ngFor="let ds of datasetOptions"
name="datasetsList"
[checked]="ds.checked"
[value]="ds.id">
{{ ds.name }}
</mat-radio-button>
</mat-radio-group>
<mat-radio-group aria-label="Select a dataset"
name="datasetsList"
fxLayout="column"
(change)="updateDataset($event)">
<mat-radio-button *ngFor="let ds of datasetOptions"
name="datasetsList"
[checked]="ds.checked"
[value]="ds.id">
{{ ds.name }}
</mat-radio-button>
</mat-radio-group>
</div>
</div>
</div>
Expand All @@ -139,12 +135,12 @@ <h2 class="mat-title">
<div class="metadata-property">
<div>
<div class="property-label display-inline-block">Cite as</div>
<button mat-button
matTooltip="Copy citation url"
matTooltipPosition="below"
[cdkCopyToClipboard]="selectedDataset.howToCite"
(click)="copyToClipboard('Citation link')"
class="btn-copy-to-clipboard">
<button mat-button
matTooltip="Copy citation url"
matTooltipPosition="below"
[cdkCopyToClipboard]="selectedDataset.howToCite"
(click)="copyToClipboard('Citation link')"
class="btn-copy-to-clipboard">
<mat-icon [inline]="true" class="icon-arkurl">content_copy</mat-icon>
</button>
</div>
Expand All @@ -155,44 +151,44 @@ <h2 class="mat-title">
</div>

<div class="metadata-box">

<div class="metadata-property">
<div>
<div class="property-label display-inline-block">
Persistent identifier
</div>
<button mat-button
<div class="metadata-property">
<div>
<div class="property-label display-inline-block">
Persistent identifier
</div>
<button mat-button
matTooltip="Copy persistent identifier"
matTooltipPosition="below"
[cdkCopyToClipboard]="selectedProject.id"
(click)="copyToClipboard('Persistent identifier')"
class="btn-copy-to-clipboard">
<mat-icon [inline]="true" class="icon-arkurl">content_copy</mat-icon>
</button>
</div>
<div class="sidenav-prop-text property-value">
<a href="{{ selectedProject.id }}" target="_blank"> {{ selectedProject.id }} </a>
</div>
<mat-icon [inline]="true" class="icon-arkurl">content_copy</mat-icon>
</button>
</div>
<div class="metadata-property">
<div class="property-label display-inline-block">
License
</div>
<div class="sidenav-prop-text property-value">
<p class="p-block" *ngFor="let license of selectedDataset.license">
<a *ngIf="license.url" href="{{ license.url }}" target="_blank"> {{ license.url }} </a>
</p>
</div>
<div class="sidenav-prop-text property-value">
<a href="{{ selectedProject.id }}" target="_blank"> {{ selectedProject.id }} </a>
</div>
<div class="metadata-property" *ngIf="selectedDataset.datePublished">
<div class="property-label">
Publication date
</div>
<div class="sidenav-prop-text property-value">
{{ selectedDataset.datePublished | date:'MMMM d, yyyy' }}
</div>
</div>

<div class="metadata-property">
<div class="property-label display-inline-block">
License
</div>
<div class="sidenav-prop-text property-value">
<p class="p-block" *ngFor="let license of selectedDataset.license">
<a *ngIf="license.url" href="{{ license.url }}" target="_blank"> {{ license.url }} </a>
</p>
</div>
</div>

<div class="metadata-property" *ngIf="selectedDataset.datePublished">
<div class="property-label">
Publication date
</div>
<div class="sidenav-prop-text property-value">
{{ selectedDataset.datePublished | date:'MMMM d, yyyy' }}
</div>
</div>
</div>

<div class="metadata-box">
Expand All @@ -215,12 +211,12 @@ <h2 class="mat-title">
</div>
<div class="sidenav-prop-text">
<a [routerLink]="" (click)="downloadMetadata()">JSON</a>
<!-- Functionality to be implemented -->
<a href *ngFor="let dformat of metadataDownloadFormats" class="download-metadata"> {{ dformat }} </a>
<!-- Functionality to be implemented -->
<a href *ngFor="let dformat of metadataDownloadFormats" class="download-metadata"> {{ dformat }} </a>
</div>
</div>
</div>
</div>

</div>
</div>
</div>
3 changes: 2 additions & 1 deletion src/app/project/board/board.component.ts
Expand Up @@ -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
Expand Down Expand Up @@ -181,7 +182,7 @@ export class BoardComponent implements OnInit {
}
}

getSubProperty(id: string) {
getSubProperty(id: string): object {
return this.subProperties[id];
}

Expand Down
@@ -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',
Expand All @@ -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) {
Expand All @@ -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;
}
}
26 changes: 26 additions & 0 deletions 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;
}

}
Expand Up @@ -26,7 +26,7 @@ import { Organization } from '@dasch-swiss/dsp-js';
<div *ngIf="organisation.email" class="metadata-property">
<div class="property-label display-inline-block">
Email:
Email:
</div>
<div class="display-inline-block add-left-margin">
<a href="mailto:{{ organisation.email }}"> {{ organisation.email }} </a>
Expand Down
Expand Up @@ -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) {
Expand Down

0 comments on commit b688416

Please sign in to comment.