Skip to content

Commit 6397cde

Browse files
authored
Fix/institutions (#265)
* fix(menu): added new items * fix(institutions): updated download logic * fix(institutions): updates * fix(institutions): updated resource pages
1 parent ecf0fef commit 6397cde

File tree

58 files changed

+854
-705
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+854
-705
lines changed

src/app/features/admin-institutions/admin-institutions.component.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import { NgOptimizedImage } from '@angular/common';
88
import { ChangeDetectionStrategy, Component, inject, OnInit } from '@angular/core';
99
import { ActivatedRoute, Router, RouterOutlet } from '@angular/router';
1010

11-
import { resourceTabOptions } from '@osf/features/admin-institutions/constants/resource-tab-option.constant';
1211
import { Primitive } from '@osf/shared/helpers';
12+
import { FetchInstitutionById, InstitutionsSearchSelectors } from '@osf/shared/stores';
1313
import { LoadingSpinnerComponent, SelectComponent } from '@shared/components';
14-
import { FetchInstitutionById, InstitutionsSearchSelectors } from '@shared/stores';
14+
15+
import { resourceTabOptions } from './constants';
16+
import { AdminInstitutionResourceTab } from './enums';
1517

1618
@Component({
1719
selector: 'osf-admin-institutions',
@@ -31,9 +33,8 @@ export class AdminInstitutionsComponent implements OnInit {
3133
fetchInstitution: FetchInstitutionById,
3234
});
3335

34-
selectedTab = 'summary';
35-
3636
resourceTabOptions = resourceTabOptions;
37+
selectedTab = AdminInstitutionResourceTab.Summary;
3738

3839
ngOnInit() {
3940
const institutionId = this.route.snapshot.params['institution-id'];
@@ -42,16 +43,17 @@ export class AdminInstitutionsComponent implements OnInit {
4243
this.actions.fetchInstitution(institutionId);
4344
}
4445

45-
this.selectedTab = this.route.snapshot.firstChild?.routeConfig?.path || 'summary';
46+
this.selectedTab =
47+
(this.route.snapshot.firstChild?.routeConfig?.path as AdminInstitutionResourceTab) ||
48+
AdminInstitutionResourceTab.Summary;
4649
}
4750

4851
onTabChange(selectedValue: Primitive) {
49-
const value = String(selectedValue);
52+
const value = selectedValue as AdminInstitutionResourceTab;
5053
this.selectedTab = value;
51-
const selectedTab = this.resourceTabOptions.find((tab) => tab.value === value);
5254

53-
if (selectedTab) {
54-
this.router.navigate([selectedTab.value], { relativeTo: this.route });
55+
if (this.selectedTab) {
56+
this.router.navigate([this.selectedTab], { relativeTo: this.route });
5557
}
5658
}
5759
}

src/app/features/admin-institutions/components/admin-table/admin-table.component.html

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
<ng-content select="[slot=amount]"></ng-content>
44
</div>
55

6-
<p-menu #downloadMenu [model]="downloadMenuItems()" appendTo="body" popup>
6+
<p-menu #downloadMenu [model]="downloadMenuItems" appendTo="body" popup>
77
<ng-template #item let-item>
8-
<a class="p-menu-item-link ml-1" osfStopPropagation target="_blank" [href]="item.link">
8+
<a
9+
class="p-menu-item-link ml-1"
10+
osfStopPropagation
11+
(click)="downloadClicked.emit(item.value)"
12+
(keydown.enter)="downloadClicked.emit(item.value)"
13+
tabindex="0"
14+
>
915
<i [class]="item.icon"></i>
1016

1117
{{ item.label }}
@@ -39,15 +45,13 @@
3945
</ng-template>
4046
</p-multiselect>
4147

42-
@if (downloadLink()) {
43-
<p-button
44-
icon="fa fa-download text-primary text-xl"
45-
outlined
46-
class="grey-border-color download-button"
47-
severity="info"
48-
(click)="downloadMenu.toggle($event)"
49-
/>
50-
}
48+
<p-button
49+
icon="fa fa-download text-primary text-xl"
50+
outlined
51+
class="grey-border-color download-button"
52+
severity="info"
53+
(click)="downloadMenu.toggle($event)"
54+
/>
5155

5256
@if (reportsLink()) {
5357
<a
@@ -131,6 +135,12 @@
131135
}
132136
</tr>
133137
</ng-template>
138+
139+
<ng-template pTemplate="emptymessage">
140+
<tr>
141+
<td colspan="15" class="text-center">{{ 'adminInstitutions.institutionUsers.noData' | translate }}</td>
142+
</tr>
143+
</ng-template>
134144
</p-table>
135145

136146
@if (isNextPreviousPagination()) {

src/app/features/admin-institutions/components/admin-table/admin-table.component.ts

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ import {
2020
} from '@osf/features/admin-institutions/models';
2121
import { CustomPaginatorComponent } from '@osf/shared/components';
2222
import { StopPropagationDirective } from '@shared/directives';
23-
import { SortOrder } from '@shared/enums';
2423
import { QueryParams } from '@shared/models';
2524

25+
import { DOWNLOAD_OPTIONS } from '../../constants';
26+
import { DownloadType } from '../../enums';
27+
2628
@Component({
2729
selector: 'osf-admin-table',
2830
imports: [
@@ -75,34 +77,13 @@ export class AdminTableComponent {
7577
sortChanged = output<QueryParams>();
7678
iconClicked = output<TableIconClickEvent>();
7779
linkPageChanged = output<string>();
80+
downloadClicked = output<DownloadType>();
7881

79-
downloadLink = input<string>('');
80-
reportsLink = input<string>('');
82+
reportsLink = input<string | undefined>('');
8183

8284
selectedColumns = signal<TableColumn[]>([]);
8385

84-
downloadMenuItems = computed(() => {
85-
const baseUrl = this.downloadLink();
86-
if (!baseUrl) return [];
87-
88-
return [
89-
{
90-
label: 'CSV',
91-
icon: 'fa fa-file-csv',
92-
link: this.createUrl(baseUrl, 'text/csv'),
93-
},
94-
{
95-
label: 'TSV',
96-
icon: 'fa fa-file-alt',
97-
link: this.createUrl(baseUrl, 'text/tab-separated-values'),
98-
},
99-
{
100-
label: 'JSON',
101-
icon: 'fa fa-file-code',
102-
link: this.createUrl(baseUrl, 'application/json'),
103-
},
104-
];
105-
});
86+
downloadMenuItems = DOWNLOAD_OPTIONS;
10687

10788
selectedColumnsComputed = computed(() => {
10889
const selected = this.selectedColumns();
@@ -149,9 +130,10 @@ export class AdminTableComponent {
149130
if (event.field && this.userInitiatedSort) {
150131
this.sortChanged.emit({
151132
sortColumn: event.field,
152-
sortOrder: event.order === -1 ? SortOrder.Desc : SortOrder.Asc,
133+
sortOrder: event.order,
153134
} as QueryParams);
154135
}
136+
155137
this.userInitiatedSort = false;
156138
}
157139

@@ -180,10 +162,6 @@ export class AdminTableComponent {
180162
this.linkPageChanged.emit(link);
181163
}
182164

183-
private createUrl(baseUrl: string, mediaType: string): string {
184-
return `${baseUrl}&acceptMediatype=${encodeURIComponent(mediaType)}`;
185-
}
186-
187165
getLinkUrl(value: string | number | TableCellLink | undefined): string {
188166
if (this.isLink(value)) {
189167
return value.url;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { SelectOption } from '@shared/models';
2+
3+
import { ContactOption } from '../enums';
4+
5+
export const CONTACT_OPTIONS: SelectOption[] = [
6+
{ label: 'adminInstitutions.contact.requestAccess', value: ContactOption.RequestAccess },
7+
{ label: 'adminInstitutions.contact.sendMessage', value: ContactOption.SendMessage },
8+
];
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { DownloadType } from '../enums';
2+
3+
export const DOWNLOAD_FORMATS: Record<DownloadType, string> = {
4+
[DownloadType.CSV]: 'text/csv',
5+
[DownloadType.TSV]: 'text/tab-separated-values',
6+
[DownloadType.JSON]: 'application/json',
7+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { DownloadType } from '../enums';
2+
3+
export const DOWNLOAD_OPTIONS = [
4+
{
5+
value: DownloadType.CSV,
6+
label: 'CSV',
7+
icon: 'fa fa-file-csv',
8+
},
9+
{
10+
value: DownloadType.TSV,
11+
label: 'TSV',
12+
icon: 'fa fa-file-alt',
13+
},
14+
{
15+
value: DownloadType.JSON,
16+
label: 'JSON',
17+
icon: 'fa fa-file-code',
18+
},
19+
];
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
export * from './admin-table-columns.constant';
1+
export * from './contact-options.constant';
22
export * from './department-options.constant';
3+
export * from './download-formats.constant';
4+
export * from './download-options.constant';
35
export * from './preprints-table-columns.constant';
46
export * from './project-table-columns.constant';
57
export * from './registration-table-columns.constant';
68
export * from './resource-tab-option.constant';
9+
export * from './user-table-columns.constant';

src/app/features/admin-institutions/constants/project-table-columns.constant.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ export const projectTableColumns: TableColumn[] = [
4848
sortable: true,
4949
isLink: true,
5050
linkTarget: '_blank',
51+
showIcon: true,
52+
iconClass: 'fa-solid fa-comment text-primary',
53+
iconTooltip: 'adminInstitutions.institutionUsers.sendMessage',
54+
iconAction: 'sendMessage',
5155
},
5256
{
5357
field: 'views',
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { CustomOption } from '@shared/models';
22

3-
export const resourceTabOptions: CustomOption<string>[] = [
4-
{ label: 'adminInstitutions.summary.title', value: 'summary' },
5-
{ label: 'common.search.tabs.users', value: 'users' },
6-
{ label: 'common.search.tabs.projects', value: 'projects' },
7-
{ label: 'common.search.tabs.registrations', value: 'registrations' },
8-
{ label: 'common.search.tabs.preprints', value: 'preprints' },
3+
import { AdminInstitutionResourceTab } from '../enums';
4+
5+
export const resourceTabOptions: CustomOption<AdminInstitutionResourceTab>[] = [
6+
{ label: 'adminInstitutions.summary.title', value: AdminInstitutionResourceTab.Summary },
7+
{ label: 'common.search.tabs.users', value: AdminInstitutionResourceTab.Users },
8+
{ label: 'common.search.tabs.projects', value: AdminInstitutionResourceTab.Projects },
9+
{ label: 'common.search.tabs.registrations', value: AdminInstitutionResourceTab.Registrations },
10+
{ label: 'common.search.tabs.preprints', value: AdminInstitutionResourceTab.Preprints },
911
];

0 commit comments

Comments
 (0)