-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into coar-notify-7
- Loading branch information
Showing
49 changed files
with
11,173 additions
and
1 deletion.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/app/admin/admin-reports/admin-reports-routing.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { FilteredCollectionsComponent } from './filtered-collections/filtered-collections.component'; | ||
import { FilteredItemsComponent } from './filtered-items/filtered-items.component'; | ||
import { RouterModule } from '@angular/router'; | ||
import { NgModule } from '@angular/core'; | ||
import { I18nBreadcrumbResolver } from '../../core/breadcrumbs/i18n-breadcrumb.resolver'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
RouterModule.forChild([ | ||
{ | ||
path: 'collections', | ||
resolve: { breadcrumb: I18nBreadcrumbResolver }, | ||
data: {title: 'admin.reports.collections.title', breadcrumbKey: 'admin.reports.collections'}, | ||
children: [ | ||
{ | ||
path: '', | ||
component: FilteredCollectionsComponent | ||
} | ||
] | ||
}, | ||
{ | ||
path: 'queries', | ||
resolve: { breadcrumb: I18nBreadcrumbResolver }, | ||
data: {title: 'admin.reports.items.title', breadcrumbKey: 'admin.reports.items'}, | ||
children: [ | ||
{ | ||
path: '', | ||
component: FilteredItemsComponent | ||
} | ||
] | ||
} | ||
]) | ||
] | ||
}) | ||
export class AdminReportsRoutingModule { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { FilteredCollectionsComponent } from './filtered-collections/filtered-collections.component'; | ||
import { RouterModule } from '@angular/router'; | ||
import { SharedModule } from '../../shared/shared.module'; | ||
import { FormModule } from '../../shared/form/form.module'; | ||
import { FilteredItemsComponent } from './filtered-items/filtered-items.component'; | ||
import { AdminReportsRoutingModule } from './admin-reports-routing.module'; | ||
import { NgbAccordionModule } from '@ng-bootstrap/ng-bootstrap'; | ||
import { FiltersComponent } from './filters-section/filters-section.component'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
SharedModule, | ||
RouterModule, | ||
FormModule, | ||
AdminReportsRoutingModule, | ||
NgbAccordionModule | ||
], | ||
declarations: [ | ||
FilteredCollectionsComponent, | ||
FilteredItemsComponent, | ||
FiltersComponent | ||
] | ||
}) | ||
export class AdminReportsModule { | ||
} |
36 changes: 36 additions & 0 deletions
36
src/app/admin/admin-reports/filtered-collections/filtered-collection.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export class FilteredCollection { | ||
|
||
public label: string; | ||
public handle: string; | ||
public communityLabel: string; | ||
public communityHandle: string; | ||
public nbTotalItems: number; | ||
public values = {}; | ||
public allFiltersValue: number; | ||
|
||
public clear() { | ||
this.label = ''; | ||
this.handle = ''; | ||
this.communityLabel = ''; | ||
this.communityHandle = ''; | ||
this.nbTotalItems = 0; | ||
this.values = {}; | ||
this.allFiltersValue = 0; | ||
} | ||
|
||
public deserialize(object: any) { | ||
this.clear(); | ||
this.label = object.label; | ||
this.handle = object.handle; | ||
this.communityLabel = object.community_label; | ||
this.communityHandle = object.community_handle; | ||
this.nbTotalItems = object.nb_total_items; | ||
let valuesPerFilter = object.values; | ||
for (let filter in valuesPerFilter) { | ||
if (valuesPerFilter.hasOwnProperty(filter)) { | ||
this.values[filter] = valuesPerFilter[filter]; | ||
} | ||
} | ||
this.allFiltersValue = object.all_filters_value; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/app/admin/admin-reports/filtered-collections/filtered-collections.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<div class="container"> | ||
<div class="metadata-registry row"> | ||
<div class="col-12"> | ||
|
||
<h1 id="header" class="border-bottom pb-2">{{ "admin.reports.collections.head" | translate }}</h1> | ||
|
||
<div id="metadatadiv"> | ||
<ngb-accordion [closeOthers]="true" activeIds="filters" #acc="ngbAccordion"> | ||
<ngb-panel id="filters"> | ||
<ng-template ngbPanelTitle> | ||
{{ "admin.reports.commons.filters" | translate }} | ||
</ng-template> | ||
<ng-template ngbPanelContent> | ||
<div class="container"> | ||
<div class="row"> | ||
<span class="col-3"></span> | ||
<button class="btn btn-primary mt-1 col-6" (click)="submit()">{{ "admin.reports.button.show-collections" | translate }}</button> | ||
</div> | ||
<ds-filters [filtersForm]="filtersFormGroup()"></ds-filters> | ||
<div class="row"> | ||
<span class="col-3"></span> | ||
<button class="btn btn-primary mt-1 col-6" (click)="submit()">{{ "admin.reports.button.show-collections" | translate }}</button> | ||
</div> | ||
</div> | ||
</ng-template> | ||
</ngb-panel> | ||
<ngb-panel id="collections"> | ||
<ng-template ngbPanelTitle> | ||
{{ "admin.reports.collections.collections-report" | translate }} | ||
</ng-template> | ||
<ng-template ngbPanelContent> | ||
<table id="table" class="table table-striped"> | ||
<thead> | ||
<tr class="header"> | ||
<th rowspan="2">{{ "admin.reports.collections.community" | translate }}</th> | ||
<th rowspan="2">{{ "admin.reports.collections.collection" | translate }}</th> | ||
<th>{{ "admin.reports.collections.nb_items" | translate }}</th> | ||
<th>{{ "admin.reports.collections.match_all_selected_filters" | translate }}</th> | ||
<th *ngFor="let filter of results.summary.values | keyvalue">{{ ("admin.reports.commons.filters." + getGroup(filter.key) + "." + filter.key) | translate }}</th> | ||
</tr> | ||
<tr class="header"> | ||
<th class="num">{{ results.summary.nbTotalItems }}</th> | ||
<th class="num">{{ results.summary.allFiltersValue }}</th> | ||
<th class="num" *ngFor="let filter of results.summary.values | keyvalue">{{ filter.value }}</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr *ngFor="let coll of results.collections"> | ||
<td><a href="/handle/{{ coll.communityHandle }}" rel="noopener noreferrer" target="_blank">{{ coll.communityLabel }}</a></td> | ||
<td><a href="/handle/{{ coll.handle }}" rel="noopener noreferrer" target="_blank">{{ coll.label }}</a></td> | ||
<td class="num">{{ coll.nbTotalItems }}</td> | ||
<td class="num">{{ coll.allFiltersValue }}</td> | ||
<td class="num" *ngFor="let filter of results.summary.values | keyvalue">{{ coll.values[filter.key] || 0 }}</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</ng-template> | ||
</ngb-panel> | ||
</ngb-accordion> | ||
</div> | ||
|
||
</div> | ||
</div> | ||
</div> |
3 changes: 3 additions & 0 deletions
3
src/app/admin/admin-reports/filtered-collections/filtered-collections.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.num { | ||
text-align: center; | ||
} |
83 changes: 83 additions & 0 deletions
83
src/app/admin/admin-reports/filtered-collections/filtered-collections.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { waitForAsync, ComponentFixture, TestBed} from '@angular/core/testing'; | ||
import { NO_ERRORS_SCHEMA } from '@angular/core'; | ||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core'; | ||
import { TranslateLoaderMock } from 'src/app/shared/mocks/translate-loader.mock'; | ||
import { FormBuilder } from '@angular/forms'; | ||
import { FilteredCollectionsComponent } from './filtered-collections.component'; | ||
import { DspaceRestService } from 'src/app/core/dspace-rest/dspace-rest.service'; | ||
import { NgbAccordion, NgbAccordionModule } from '@ng-bootstrap/ng-bootstrap'; | ||
import { HttpClientTestingModule } from '@angular/common/http/testing'; | ||
import { of as observableOf } from 'rxjs'; | ||
import { RawRestResponse } from 'src/app/core/dspace-rest/raw-rest-response.model'; | ||
|
||
describe('FiltersComponent', () => { | ||
let component: FilteredCollectionsComponent; | ||
let fixture: ComponentFixture<FilteredCollectionsComponent>; | ||
let formBuilder: FormBuilder; | ||
|
||
const expected = { | ||
payload: { | ||
collections: [], | ||
summary: { | ||
label: 'Test' | ||
} | ||
}, | ||
statusCode: 200, | ||
statusText: 'OK' | ||
} as RawRestResponse; | ||
|
||
beforeEach(waitForAsync(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [FilteredCollectionsComponent], | ||
imports: [ | ||
NgbAccordionModule, | ||
TranslateModule.forRoot({ | ||
loader: { | ||
provide: TranslateLoader, | ||
useClass: TranslateLoaderMock | ||
} | ||
}), | ||
HttpClientTestingModule | ||
], | ||
providers: [ | ||
FormBuilder, | ||
DspaceRestService | ||
], | ||
schemas: [NO_ERRORS_SCHEMA] | ||
}); | ||
})); | ||
|
||
beforeEach(waitForAsync(() => { | ||
formBuilder = TestBed.inject(FormBuilder); | ||
|
||
fixture = TestBed.createComponent(FilteredCollectionsComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
})); | ||
|
||
it('should create the component', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should be displaying the filters panel initially', () => { | ||
let accordion: NgbAccordion = component.accordionComponent; | ||
expect(accordion.isExpanded('filters')).toBeTrue(); | ||
}); | ||
|
||
describe('toggle', () => { | ||
beforeEach(() => { | ||
spyOn(component, 'getFilteredCollections').and.returnValue(observableOf(expected)); | ||
spyOn(component.results, 'deserialize'); | ||
spyOn(component.accordionComponent, 'expand').and.callThrough(); | ||
component.submit(); | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should be displaying the collections panel after submitting', waitForAsync(() => { | ||
fixture.whenStable().then(() => { | ||
expect(component.accordionComponent.expand).toHaveBeenCalledWith('collections'); | ||
expect(component.accordionComponent.isExpanded('collections')).toBeTrue(); | ||
}); | ||
})); | ||
}); | ||
}); |
70 changes: 70 additions & 0 deletions
70
src/app/admin/admin-reports/filtered-collections/filtered-collections.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Component, ViewChild } from '@angular/core'; | ||
import { FormBuilder, FormGroup } from '@angular/forms'; | ||
import { NgbAccordion } from '@ng-bootstrap/ng-bootstrap'; | ||
import { Observable } from 'rxjs'; | ||
import { RestRequestMethod } from 'src/app/core/data/rest-request-method'; | ||
import { DspaceRestService } from 'src/app/core/dspace-rest/dspace-rest.service'; | ||
import { RawRestResponse } from 'src/app/core/dspace-rest/raw-rest-response.model'; | ||
import { environment } from 'src/environments/environment'; | ||
import { FiltersComponent } from '../filters-section/filters-section.component'; | ||
import { FilteredCollections } from './filtered-collections.model'; | ||
|
||
/** | ||
* Component representing the Filtered Collections content report | ||
*/ | ||
@Component({ | ||
selector: 'ds-report-filtered-collections', | ||
templateUrl: './filtered-collections.component.html', | ||
styleUrls: ['./filtered-collections.component.scss'] | ||
}) | ||
export class FilteredCollectionsComponent { | ||
|
||
queryForm: FormGroup; | ||
results: FilteredCollections = new FilteredCollections(); | ||
@ViewChild('acc') accordionComponent: NgbAccordion; | ||
|
||
constructor( | ||
private formBuilder: FormBuilder, | ||
private restService: DspaceRestService) {} | ||
|
||
ngOnInit() { | ||
this.queryForm = this.formBuilder.group({ | ||
filters: FiltersComponent.formGroup(this.formBuilder) | ||
}); | ||
} | ||
|
||
filtersFormGroup(): FormGroup { | ||
return this.queryForm.get('filters') as FormGroup; | ||
} | ||
|
||
getGroup(filterId: string): string { | ||
return FiltersComponent.getGroup(filterId).id; | ||
} | ||
|
||
submit() { | ||
this | ||
.getFilteredCollections() | ||
.subscribe( | ||
response => { | ||
this.results.deserialize(response.payload); | ||
this.accordionComponent.expand('collections'); | ||
} | ||
); | ||
} | ||
|
||
getFilteredCollections(): Observable<RawRestResponse> { | ||
let params = this.toQueryString(); | ||
if (params.length > 0) { | ||
params = `?${params}`; | ||
} | ||
let scheme = environment.rest.ssl ? 'https' : 'http'; | ||
let urlRestApp = `${scheme}://${environment.rest.host}:${environment.rest.port}${environment.rest.nameSpace}`; | ||
return this.restService.request(RestRequestMethod.GET, `${urlRestApp}/api/contentreport/filteredcollections${params}`); | ||
} | ||
|
||
private toQueryString(): string { | ||
let params = FiltersComponent.toQueryString(this.queryForm.value.filters); | ||
return params; | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/app/admin/admin-reports/filtered-collections/filtered-collections.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { FilteredCollection } from './filtered-collection.model'; | ||
|
||
export class FilteredCollections { | ||
|
||
public collections: Array<FilteredCollection> = []; | ||
public summary: FilteredCollection = new FilteredCollection(); | ||
|
||
public clear() { | ||
this.collections.splice(0, this.collections.length); | ||
this.summary.clear(); | ||
} | ||
|
||
public deserialize(object: any) { | ||
this.clear(); | ||
let summary = object.summary; | ||
this.summary.deserialize(summary); | ||
let collections = object.collections; | ||
for (let i = 0; i < collections.length; i++) { | ||
let collection = collections[i]; | ||
let coll = new FilteredCollection(); | ||
coll.deserialize(collection); | ||
this.collections.push(coll); | ||
} | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/app/admin/admin-reports/filtered-items/filtered-items-model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Item } from 'src/app/core/shared/item.model'; | ||
|
||
export class FilteredItems { | ||
|
||
public items: Item[] = []; | ||
public itemCount: number; | ||
|
||
public clear() { | ||
this.items.splice(0, this.items.length); | ||
} | ||
|
||
public deserialize(object: any, offset: number = 0) { | ||
this.clear(); | ||
this.itemCount = object.itemCount; | ||
let items = object.items; | ||
for (let i = 0; i < items.length; i++) { | ||
let item = items[i]; | ||
item.index = this.items.length + offset + 1; | ||
this.items.push(item); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.