Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/app/features/preprints/services/preprints-projects.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { inject, Injectable } from '@angular/core';

import { ENVIRONMENT } from '@core/provider/environment.provider';
import { Primitive, StringOrNull } from '@osf/shared/helpers';
import { ApiData, CreateProjectPayloadJsoApi, IdName, JsonApiResponse, NodeData } from '@osf/shared/models';
import {
ApiData,
CreateProjectPayloadJsoApi,
IdName,
NodeResponseJsonApi,
NodesResponseJsonApi,
} from '@osf/shared/models';
import { JsonApiService } from '@osf/shared/services';

import { PreprintsMapper } from '../mappers';
Expand All @@ -29,7 +35,7 @@ export class PreprintsProjectsService {
params['filter[title]'] = searchTerm;
}

return this.jsonApiService.get<JsonApiResponse<NodeData[], null>>(`${this.apiUrl}/users/me/nodes/`, params).pipe(
return this.jsonApiService.get<NodesResponseJsonApi>(`${this.apiUrl}/users/me/nodes/`, params).pipe(
map((response) => {
return response.data.map((item) => ({
id: item.id,
Expand All @@ -40,7 +46,7 @@ export class PreprintsProjectsService {
}

getProjectById(projectId: string): Observable<IdName> {
return this.jsonApiService.get<JsonApiResponse<NodeData, null>>(`${this.apiUrl}/nodes/${projectId}/`).pipe(
return this.jsonApiService.get<NodeResponseJsonApi>(`${this.apiUrl}/nodes/${projectId}/`).pipe(
map((response) => {
return {
id: response.data.id,
Expand Down Expand Up @@ -114,7 +120,7 @@ export class PreprintsProjectsService {
},
};

return this.jsonApiService.post<JsonApiResponse<NodeData, null>>(`${this.apiUrl}/nodes/`, payload).pipe(
return this.jsonApiService.post<NodeResponseJsonApi>(`${this.apiUrl}/nodes/`, payload).pipe(
map((response) => {
return {
id: response.data.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@ <h2 class="pb-4">{{ 'myProjects.settings.project' | translate }}</h2>
</div>

<div class="flex justify-content-end w-full flex-0 border-top-1 pt-4 border-gray-300">
<p-button
(onClick)="deleteProject.emit()"
severity="danger"
[label]="'myProjects.settings.deleteProject' | translate"
class="btn-full-width sm:w-10rem md:ml-auto"
></p-button>
<p-button (onClick)="deleteProject.emit()" severity="danger" [label]="deleteLabel() | translate"></p-button>
</div>
</form>
</p-card>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Button } from 'primeng/button';
import { Card } from 'primeng/card';
import { Textarea } from 'primeng/textarea';

import { ChangeDetectionStrategy, Component, effect, input, output } from '@angular/core';
import { ChangeDetectionStrategy, Component, computed, effect, input, output } from '@angular/core';
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';

import { TextInputComponent } from '@osf/shared/components';
Expand Down Expand Up @@ -34,6 +34,10 @@ export class SettingsProjectFormCardComponent {
[ProjectFormControls.Description]: new FormControl(''),
});

deleteLabel = computed(() =>
this.projectDetails().parentId ? 'myProjects.settings.deleteComponent' : 'myProjects.settings.deleteProject'
);

constructor() {
this.setupFormEffects();
}
Expand Down
7 changes: 3 additions & 4 deletions src/app/features/project/settings/mappers/settings.mapper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { UserPermissions } from '@osf/shared/enums';
import { InstitutionsMapper } from '@osf/shared/mappers';
import { RegionsMapper } from '@osf/shared/mappers/regions';

import {
NodeDataJsonApi,
Expand Down Expand Up @@ -32,14 +33,12 @@ export class SettingsMapper {
title: data.attributes.title,
description: data.attributes.description,
isPublic: data.attributes.public,
region: {
id: data.embeds?.region.data.id,
name: data.embeds?.region.data.attributes.name,
},
region: RegionsMapper.getRegion(data?.embeds?.region?.data),
affiliatedInstitutions: data.embeds
? InstitutionsMapper.fromInstitutionsResponse(data.embeds.affiliated_institutions)
: [],
currentUserPermissions: data.attributes.current_user_permissions as UserPermissions[],
parentId: data.relationships.parent?.data?.id,
lastFetched: Date.now(),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export interface NodeDetailsModel {
region: IdName;
affiliatedInstitutions: Institution[];
currentUserPermissions: string[];
parentId?: string;
lastFetched: number;
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { InstitutionsJsonApiResponse, NodeData, ResponseDataJsonApi } from '@osf/shared/models';
import {
BaseNodeDataJsonApi,
InstitutionsJsonApiResponse,
RegionDataJsonApi,
ResponseDataJsonApi,
} from '@osf/shared/models';

export type NodeResponseJsonApi = ResponseDataJsonApi<NodeDataJsonApi>;

export interface NodeDataJsonApi extends NodeData {
export interface NodeDataJsonApi extends BaseNodeDataJsonApi {
embeds: NodeEmbedsJsonApi;
}

interface NodeEmbedsJsonApi {
region: {
data: {
id: string;
attributes: {
name: string;
};
};
data: RegionDataJsonApi;
};
affiliated_institutions: InstitutionsJsonApiResponse;
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class SettingsService {
const params = {
'embed[]': ['affiliated_institutions', 'region'],
};

return this.jsonApiService
.get<NodeResponseJsonApi>(`${this.apiUrl}/nodes/${projectId}/`, params)
.pipe(map((response) => SettingsMapper.fromNodeResponse(response.data)));
Expand Down
9 changes: 8 additions & 1 deletion src/app/shared/mappers/regions/regions-mapper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IdName, RegionsResponseJsonApi } from '@osf/shared/models';
import { IdName, RegionDataJsonApi, RegionsResponseJsonApi } from '@osf/shared/models';

export class RegionsMapper {
static fromRegionsResponseJsonApi(response: RegionsResponseJsonApi): IdName[] {
Expand All @@ -7,4 +7,11 @@ export class RegionsMapper {
name: data.attributes.name,
}));
}

static getRegion(data: RegionDataJsonApi): IdName {
return {
id: data.id,
name: data.attributes.name,
};
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IdentifierAttributes } from '@shared/models';

export interface BaseNodeEmbeds {
export interface BaseNodeEmbedsJsonApi {
bibliographic_contributors?: {
data: ContributorResource[];
};
Expand Down
123 changes: 11 additions & 112 deletions src/app/shared/models/nodes/nodes-json-api.model.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
export interface NodeData {
id: string;
type: 'nodes';
attributes: NodeAttributes;
relationships: NodeRelationships;
links: NodeLinks;
lastFetched?: number;
}
import { ResponseJsonApi } from '../common';

export interface NodeResponseModel {
data: NodeData;
meta: NodeMeta;
}
import { BaseNodeDataJsonApi } from './base-node-data-json-api.model';

export type NodesResponseJsonApi = ResponseJsonApi<BaseNodeDataJsonApi[]>;
export type NodeResponseJsonApi = ResponseJsonApi<BaseNodeDataJsonApi>;

export interface UpdateNodeRequestModel {
data: UpdateNodeData;
data: UpdateNodeDataJsonApi;
}

export interface CreateProjectPayloadJsoApi {
Expand Down Expand Up @@ -42,109 +35,15 @@ export interface CreateProjectPayloadJsoApi {
};
}

interface NodeAttributes {
title: string;
description: string;
category: string;
custom_citation: string | null;
date_created: string;
date_modified: string;
registration: boolean;
preprint: boolean;
fork: boolean;
collection: boolean;
tags: string[];
access_requests_enabled: boolean;
node_license: unknown | null;
current_user_can_comment: boolean;
current_user_permissions: string[];
current_user_is_contributor: boolean;
current_user_is_contributor_or_group_member: boolean;
wiki_enabled: boolean;
public: boolean;
subjects: unknown[];
}

interface RelationshipLinks {
related: {
href: string;
meta: Record<string, unknown>;
};
self?: {
href: string;
meta: Record<string, unknown>;
};
}

interface NodeRelationships {
children: { links: RelationshipLinks };
comments: { links: RelationshipLinks };
contributors: { links: RelationshipLinks };
bibliographic_contributors: { links: RelationshipLinks };
implicit_contributors: { links: RelationshipLinks };
files: { links: RelationshipLinks };
settings: {
links: RelationshipLinks;
data: { id: string; type: 'node-setting' };
};
wikis: { links: RelationshipLinks };
forks: { links: RelationshipLinks };
groups: { links: RelationshipLinks };
node_links: { links: RelationshipLinks };
linked_by_nodes: { links: RelationshipLinks };
linked_by_registrations: { links: RelationshipLinks };
parent: {
links: RelationshipLinks;
data: { id: string; type: 'nodes' };
};
identifiers: { links: RelationshipLinks };
affiliated_institutions: { links: RelationshipLinks };
draft_registrations: { links: RelationshipLinks };
registrations: { links: RelationshipLinks };
region: {
links: RelationshipLinks;
data: { id: string; type: 'regions' };
};
root: {
links: RelationshipLinks;
data: { id: string; type: 'nodes' };
};
logs: { links: RelationshipLinks };
linked_nodes: { links: RelationshipLinks };
linked_registrations: { links: RelationshipLinks };
view_only_links: { links: RelationshipLinks };
citation: {
links: RelationshipLinks;
data: { id: string; type: 'citation' };
};
preprints: { links: RelationshipLinks };
storage: {
links: RelationshipLinks;
data: { id: string; type: 'node-storage' };
};
cedar_metadata_records: { links: RelationshipLinks };
subjects_acceptable: { links: RelationshipLinks };
}

interface NodeLinks {
html: string;
self: string;
iri: string;
}

interface NodeMeta {
version: string;
interface UpdateNodeDataJsonApi {
id: string;
type: 'nodes';
attributes: UpdateNodeAttributesJsonApi;
}

interface UpdateNodeAttributes {
interface UpdateNodeAttributesJsonApi {
description?: string;
tags?: string[];
public?: boolean;
title?: string;
}

interface UpdateNodeData {
type: 'nodes';
id: string;
attributes: UpdateNodeAttributes;
}
1 change: 1 addition & 0 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@
"project": "Project",
"saveChanges": "Save Changes",
"deleteProject": "Delete Project",
"deleteComponent": "Delete Component",
"viewOnlyLinks": "View-only Links",
"viewOnlySubtitle": "Create a link to share this project so those who have the link can view—but not edit—the project.",
"viewOnlyTable": {
Expand Down
Loading