Skip to content

Commit

Permalink
Add statistics pages
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcambien committed Sep 3, 2020
1 parent cd6c5b7 commit 752ada3
Show file tree
Hide file tree
Showing 33 changed files with 1,256 additions and 19 deletions.
18 changes: 17 additions & 1 deletion src/app/+collection-page/collection-page-routing.module.ts
Expand Up @@ -19,6 +19,8 @@ import {
COLLECTION_EDIT_PATH,
COLLECTION_CREATE_PATH
} from './collection-page-routing-paths';
import { MenuItemType } from '../shared/menu/initial-menus-state';
import { LinkMenuItemModel } from '../shared/menu/menu-item/models/link.model';

@NgModule({
imports: [
Expand Down Expand Up @@ -68,7 +70,21 @@ import {
pathMatch: 'full',
canActivate: [AuthenticatedGuard]
}
]
],
data: {
menu: {
public: [{
id: 'statistics',
active: true,
visible: true,
model: {
type: MenuItemType.LINK,
text: 'menu.section.statistics',
link: 'statistics/collections/:id/',
} as LinkMenuItemModel,
}],
},
},
},
])
],
Expand Down
18 changes: 17 additions & 1 deletion src/app/+community-page/community-page-routing.module.ts
Expand Up @@ -11,6 +11,8 @@ import { CommunityBreadcrumbResolver } from '../core/breadcrumbs/community-bread
import { DSOBreadcrumbsService } from '../core/breadcrumbs/dso-breadcrumbs.service';
import { LinkService } from '../core/cache/builders/link.service';
import { COMMUNITY_EDIT_PATH, COMMUNITY_CREATE_PATH } from './community-page-routing-paths';
import { MenuItemType } from '../shared/menu/initial-menus-state';
import { LinkMenuItemModel } from '../shared/menu/menu-item/models/link.model';

@NgModule({
imports: [
Expand Down Expand Up @@ -44,7 +46,21 @@ import { COMMUNITY_EDIT_PATH, COMMUNITY_CREATE_PATH } from './community-page-rou
component: CommunityPageComponent,
pathMatch: 'full',
}
]
],
data: {
menu: {
public: [{
id: 'statistics',
active: true,
visible: true,
model: {
type: MenuItemType.LINK,
text: 'menu.section.statistics',
link: 'statistics/communities/:id/',
} as LinkMenuItemModel,
}],
},
},
},
])
],
Expand Down
18 changes: 17 additions & 1 deletion src/app/+home-page/home-page-routing.module.ts
Expand Up @@ -3,6 +3,8 @@ import { RouterModule } from '@angular/router';

import { HomePageComponent } from './home-page.component';
import { HomePageResolver } from './home-page.resolver';
import { MenuItemType } from '../shared/menu/initial-menus-state';
import { LinkMenuItemModel } from '../shared/menu/menu-item/models/link.model';

@NgModule({
imports: [
Expand All @@ -11,7 +13,21 @@ import { HomePageResolver } from './home-page.resolver';
path: '',
component: HomePageComponent,
pathMatch: 'full',
data: {title: 'home.title'},
data: {
title: 'home.title',
menu: {
public: [{
id: 'statistics',
active: true,
visible: true,
model: {
type: MenuItemType.LINK,
text: 'menu.section.statistics',
link: 'statistics',
} as LinkMenuItemModel,
}],
},
},
resolve: {
site: HomePageResolver
}
Expand Down
16 changes: 16 additions & 0 deletions src/app/+item-page/item-page-routing.module.ts
Expand Up @@ -10,6 +10,8 @@ import { DSOBreadcrumbsService } from '../core/breadcrumbs/dso-breadcrumbs.servi
import { LinkService } from '../core/cache/builders/link.service';
import { UploadBitstreamComponent } from './bitstreams/upload/upload-bitstream.component';
import { UPLOAD_BITSTREAM_PATH, ITEM_EDIT_PATH } from './item-page-routing-paths';
import { MenuItemType } from '../shared/menu/initial-menus-state';
import { LinkMenuItemModel } from '../shared/menu/menu-item/models/link.model';

@NgModule({
imports: [
Expand Down Expand Up @@ -42,6 +44,20 @@ import { UPLOAD_BITSTREAM_PATH, ITEM_EDIT_PATH } from './item-page-routing-paths
canActivate: [AuthenticatedGuard]
}
],
data: {
menu: {
public: [{
id: 'statistics',
active: true,
visible: true,
model: {
type: MenuItemType.LINK,
text: 'menu.section.statistics',
link: 'statistics/items/:id/',
} as LinkMenuItemModel,
}],
},
},
}
])
],
Expand Down
@@ -0,0 +1,109 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CollectionStatisticsPageComponent } from './collection-statistics-page.component';
import { StatisticsTableComponent } from '../statistics-table/statistics-table.component';
import { TranslateModule } from '@ngx-translate/core';
import { ActivatedRoute, Router } from '@angular/router';
import { UsageReportService } from '../../core/submission/usage-report-data.service';
import { of as observableOf } from 'rxjs';
import { RemoteData } from '../../core/data/remote-data';
import { Collection } from '../../core/shared/collection.model';
import { DebugElement } from '@angular/core';
import { By } from '@angular/platform-browser';
import { UsageReport } from '../../core/statistics/models/usage-report.model';
import { SharedModule } from '../../shared/shared.module';
import { CommonModule } from '@angular/common';
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.service';

describe('CollectionStatisticsPageComponent', () => {

let component: CollectionStatisticsPageComponent;
let de: DebugElement;
let fixture: ComponentFixture<CollectionStatisticsPageComponent>;

beforeEach(async(() => {

const activatedRoute = {
data: observableOf({
scope: new RemoteData(
false,
false,
true,
undefined,
Object.assign(new Collection(), {
id: 'collection_id',
}),
)
})
};

const router = {
};

const usageReportService = {
getStatistic: (scope, type) => undefined,
};

spyOn(usageReportService, 'getStatistic').and.callFake(
(scope, type) => observableOf(
Object.assign(
new UsageReport(), {
id: `${scope}-${type}-report`,
points: [],
}
)
)
);

const nameService = {
getName: () => observableOf('test dso name'),
};

TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot(),
CommonModule,
SharedModule,
],
declarations: [
CollectionStatisticsPageComponent,
StatisticsTableComponent,
],
providers: [
{ provide: ActivatedRoute, useValue: activatedRoute },
{ provide: Router, useValue: router },
{ provide: UsageReportService, useValue: usageReportService },
{ provide: DSpaceObjectDataService, useValue: {} },
{ provide: DSONameService, useValue: nameService },
],
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(CollectionStatisticsPageComponent);
component = fixture.componentInstance;
de = fixture.debugElement;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});

it('should resolve to the correct collection', () => {
expect(de.query(By.css('.header')).nativeElement.id)
.toEqual('collection_id');
});

it('should show a statistics table for each usage report', () => {
expect(de.query(By.css('ds-statistics-table.collection_id-TotalVisits-report')).nativeElement)
.toBeTruthy();
expect(de.query(By.css('ds-statistics-table.collection_id-TotalVisitsPerMonth-report')).nativeElement)
.toBeTruthy();
expect(de.query(By.css('ds-statistics-table.collection_id-TopCountries-report')).nativeElement)
.toBeTruthy();
expect(de.query(By.css('ds-statistics-table.collection_id-TopCities-report')).nativeElement)
.toBeTruthy();
});
});
@@ -0,0 +1,41 @@
import { Component } from '@angular/core';
import { StatisticsPageComponent } from '../statistics-page/statistics-page.component';
import { UsageReportService } from '../../core/submission/usage-report-data.service';
import { ActivatedRoute , Router} from '@angular/router';
import { Collection } from '../../core/shared/collection.model';
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';

/**
* Component representing the statistics page for a collection.
*/
@Component({
selector: 'ds-collection-statistics-page',
templateUrl: '../statistics-page/statistics-page.component.html',
styleUrls: ['./collection-statistics-page.component.scss']
})
export class CollectionStatisticsPageComponent extends StatisticsPageComponent<Collection> {

/**
* The report types to show on this statistics page.
*/
types: string[] = [
'TotalVisits',
'TotalVisitsPerMonth',
'TopCountries',
'TopCities',
];

constructor(
protected route: ActivatedRoute,
protected router: Router,
protected usageReportService: UsageReportService,
protected nameService: DSONameService,
) {
super(
route,
router,
usageReportService,
nameService,
);
}
}
Empty file.
@@ -0,0 +1,109 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CommunityStatisticsPageComponent } from './community-statistics-page.component';
import { StatisticsTableComponent } from '../statistics-table/statistics-table.component';
import { TranslateModule } from '@ngx-translate/core';
import { ActivatedRoute, Router } from '@angular/router';
import { UsageReportService } from '../../core/submission/usage-report-data.service';
import { of as observableOf } from 'rxjs';
import { RemoteData } from '../../core/data/remote-data';
import { Community } from '../../core/shared/community.model';
import { DebugElement } from '@angular/core';
import { By } from '@angular/platform-browser';
import { UsageReport } from '../../core/statistics/models/usage-report.model';
import { SharedModule } from '../../shared/shared.module';
import { CommonModule } from '@angular/common';
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.service';

describe('CommunityStatisticsPageComponent', () => {

let component: CommunityStatisticsPageComponent;
let de: DebugElement;
let fixture: ComponentFixture<CommunityStatisticsPageComponent>;

beforeEach(async(() => {

const activatedRoute = {
data: observableOf({
scope: new RemoteData(
false,
false,
true,
undefined,
Object.assign(new Community(), {
id: 'community_id',
}),
)
})
};

const router = {
};

const usageReportService = {
getStatistic: (scope, type) => undefined,
};

spyOn(usageReportService, 'getStatistic').and.callFake(
(scope, type) => observableOf(
Object.assign(
new UsageReport(), {
id: `${scope}-${type}-report`,
points: [],
}
)
)
);

const nameService = {
getName: () => observableOf('test dso name'),
};

TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot(),
CommonModule,
SharedModule,
],
declarations: [
CommunityStatisticsPageComponent,
StatisticsTableComponent,
],
providers: [
{ provide: ActivatedRoute, useValue: activatedRoute },
{ provide: Router, useValue: router },
{ provide: UsageReportService, useValue: usageReportService },
{ provide: DSpaceObjectDataService, useValue: {} },
{ provide: DSONameService, useValue: nameService },
],
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(CommunityStatisticsPageComponent);
component = fixture.componentInstance;
de = fixture.debugElement;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});

it('should resolve to the correct community', () => {
expect(de.query(By.css('.header')).nativeElement.id)
.toEqual('community_id');
});

it('should show a statistics table for each usage report', () => {
expect(de.query(By.css('ds-statistics-table.community_id-TotalVisits-report')).nativeElement)
.toBeTruthy();
expect(de.query(By.css('ds-statistics-table.community_id-TotalVisitsPerMonth-report')).nativeElement)
.toBeTruthy();
expect(de.query(By.css('ds-statistics-table.community_id-TopCountries-report')).nativeElement)
.toBeTruthy();
expect(de.query(By.css('ds-statistics-table.community_id-TopCities-report')).nativeElement)
.toBeTruthy();
});
});

0 comments on commit 752ada3

Please sign in to comment.