Skip to content

Commit

Permalink
feat: add download function for users, clean up institutions and repo…
Browse files Browse the repository at this point in the history
…s feature
  • Loading branch information
holdan-8 committed Jul 18, 2024
1 parent db6d07b commit da28df7
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 34 deletions.
33 changes: 32 additions & 1 deletion frontend/src/app/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
InstitutionSumary as InstitutionSummary,
Repository,
User,
Organization,
} from './types';
import { shareReplay } from 'rxjs/operators';
import { environment } from 'src/environments/environment';
Expand Down Expand Up @@ -148,11 +149,41 @@ async loadAllUsers() {
.get<{
users: User[];
total: number;
}>(`${environment.api}api/UserData`, {})
}>(`${environment.api}api/completeUserData`, {})
.toPromise();
return userData;
}

async loadAllRepositories() {
const repoData = await this.http
.get<{
repositories: Repository[];
total: number;
}>(`${environment.api}api/completeRepositoryData`, {})
.toPromise();
return repoData;
}

async loadAllInstitutions() {
const institutionData = await this.http
.get<{
institutions: Institution[];
total: number;
}>(`${environment.api}api/completeInstitutionData`, {})
.toPromise();
return institutionData;
}

async loadAllOrganizations() {
const organizationData = await this.http
.get<{
organizations: Organization[];
total: number;
}>(`${environment.api}api/completeOrganizationData`, {})
.toPromise();
return organizationData;
}

async loadUserData(config: {
search: string;
sort: string;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/ranking/ranking.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ <h1>
>
<button mat-button (click)="downloadData()" *ngIf="isLoggedIn()">
<mat-icon>cloud_download</mat-icon>
<span>Download List</span>
<span>Download Institution and Organization Data</span>
</button>
<p style="color: gray">
Information on OSS Benchmark updated: {{ latestUdpate | date }}
Expand Down
47 changes: 34 additions & 13 deletions frontend/src/app/ranking/ranking.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class RankingComponent implements OnInit {
sectorFilters: sectorFilter[] = [];
recordFilter = '';
state: Date;
completeInstitutions: Institution[];
institutions: InstitutionSumary[];
window: any = window;
includeForks: boolean = false;
Expand Down Expand Up @@ -201,20 +202,40 @@ export class RankingComponent implements OnInit {
return this.authService.isUserLoggedIn();
}

// trigger export of current view
async downloadData(): Promise<void>{
let institutionData = await this.dataService.loadInstitutionSummaries({
search: this.recordFilter,
sort: this.activeSort,
direction: this.sortDirection,
page: this.page.toString(),
count: "1000",
includeForks: this.includeForks.toString(),
sector: this.checkboxes,
// trigger export of the complete Institutions and organizations data
async downloadData(){
this.dataService
.loadAllInstitutions()
.then((institutionData) => {
console.log("Received institutionData");
if (institutionData && institutionData.institutions) {
console.log("exporting data");
this.completeInstitutions = institutionData.institutions;
this.exportService.exportData(this.completeInstitutions, 'Institutions');
} else {
console.error("Invalid institution data or missing institutions property:");
}
})
.catch((error) => {
console.error("Error loading Institutions:", error);
});
this.institutions = institutionData.institutions;
console.log("exporting data", this.institutions);
this.exportService.exportData(this.institutions, 'InstitutionRanking');

this.dataService
.loadAllOrganizations()
.then((organizationData) => {
console.log("Received organizationData");
if (organizationData && organizationData.organizations) {
console.log("exporting data");
this.exportService.exportData(organizationData.organizations, 'Organizations');
} else {
console.error("Invalid organization data or missing organizations property:");
}
})
.catch((error) => {
console.error("Error loading organizations:", error);
}
);


}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h1>Ranking of {{ numRepositories }} Repositories.</h1>
</mat-checkbox>
<button mat-button (click)="downloadData()" *ngIf="isLoggedIn()">
<mat-icon>cloud_download</mat-icon>
<span>Download List</span>
<span>Download Repository Data</span>
</button>

<!-- <p style="color: gray">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,23 @@ export class RepositoriesRankingComponent implements OnInit {
return this.authService.isUserLoggedIn();
}

// trigger export of current view
// trigger export of the complete repository data
downloadData(){
this.dataService
.loadRepoData({
sort: this.activeSort,
direction: this.sortDirection,
page: "0",
count: "10000000",
includeForks: this.includeForks.toString(),
})
.then((repoData) => {
this.repositories = repoData.repositories;
.loadAllRepositories()
.then((repoData) => {
console.log("Received repoData");
if (repoData && repoData.repositories) {
console.log("exporting data");
this.repositories = repoData.repositories;
this.exportService.exportData(this.repositories, 'repositories');
} else {
console.error("Invalid repository data or missing repository property");
}
)
})
.catch((error) => {
console.error("Error loading repositories:", error);
});

}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/user-ranking/user-ranking.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h1>Ranking of {{ numUsers }} users.</h1>
</mat-form-field>
<button mat-button (click)="downloadData()" *ngIf="isLoggedIn()">
<mat-icon>cloud_download</mat-icon>
<span>Download List</span>
<span>Download User Data</span>
</button>

<!-- <p style="color: gray">
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/user-ranking/user-ranking.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class UserRankingComponent implements OnInit {
this.dataService
.loadAllUsers()
.then((userData) => {
console.log("Received userData:", userData); // Add this line to log the response
console.log("Received userData");
if (userData && userData.users) {
console.log("exporting data");
this.users = userData.users;
Expand Down
31 changes: 28 additions & 3 deletions oss-api/src/api/api.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,40 @@ export class ApiController {
async findTodoInstitution() {
return await this.mongoDbService.findAllTodoInstitutions();
}
// protected controller for the Excel Download the entire User, Institution and Repository Data

// protected controller for the Excel Download of All Users Data
// Users Data
@UseGuards(AuthGuard)
@Get('UserData')
async downloadUserData() {
@Get('completeUserData')
async collectUserData() {
const users = await this.mongoDbService.getAllUsers();
return { users, total: users.length };
}

// repositories Data
@UseGuards(AuthGuard)
@Get('completeRepositoryData')
async collectRepositoryData() {
const repositories = await this.mongoDbService.getAllRepositories();
return { repositories, total: repositories.length };
}

// institutions Data
@UseGuards(AuthGuard)
@Get('completeInstitutionData')
async collectInstitutionData() {
const institutions = await this.mongoDbService.getAllInstitutions();
return { institutions, total: institutions.length };
}

// organizations Data
@UseGuards(AuthGuard)
@Get('completeOrganizationData')
async collectOrganizationData() {
const organizations = await this.mongoDbService.getAllOrganisations();
return { organizations: organizations, total: organizations.length };
}

/***********************************Helper************************************************/
/**
* Handle the instiution query with the given conditions
Expand Down
2 changes: 1 addition & 1 deletion oss-api/src/api/dto/institution-query.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class InstitutionQueryDto implements InstitutionQueryConfig {
direction: 'DESC' | 'ASC';
@IsInt()
@Min(1)
@Max(1000)
@Max(200)
count: number;
@IsInt()
@Min(0)
Expand Down
2 changes: 1 addition & 1 deletion oss-api/src/api/dto/repository-query.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class RepositoryQueryDto implements RepositoryQueryConfig {
direction: 'DESC' | 'ASC';
@IsInt()
@Min(1)
@Max(10000000000)
@Max(200)
count: number;
@IsInt()
@Min(0)
Expand Down

0 comments on commit da28df7

Please sign in to comment.