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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,7 @@ import { ProjectOverviewToolbarComponent } from './components/project-overview-t
import { RecentActivityComponent } from './components/recent-activity/recent-activity.component';
import { ProjectOverviewModel } from './models';
import { ProjectOverviewComponent } from './project-overview.component';
import {
ClearProjectOverview,
GetComponents,
GetProjectById,
GetProjectStorage,
ProjectOverviewSelectors,
} from './store';
import { ClearProjectOverview, GetComponents, GetProjectById, ProjectOverviewSelectors } from './store';

import { MOCK_PROJECT_OVERVIEW } from '@testing/mocks/project-overview.mock';
import { OSFTestingModule } from '@testing/osf.testing.module';
Expand Down Expand Up @@ -139,7 +133,6 @@ describe('ProjectOverviewComponent', () => {
component.ngOnInit();

expect(store.dispatch).toHaveBeenCalledWith(expect.any(GetProjectById));
expect(store.dispatch).toHaveBeenCalledWith(expect.any(GetProjectStorage));
expect(store.dispatch).toHaveBeenCalledWith(expect.any(GetBookmarksCollectionId));
expect(store.dispatch).toHaveBeenCalledWith(expect.any(GetComponents));
expect(store.dispatch).toHaveBeenCalledWith(expect.any(GetLinkedResources));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ export class ProjectOverviewComponent implements OnInit {

if (projectId) {
this.actions.getProject(projectId);
this.actions.getProjectStorage(projectId);
this.actions.getBookmarksId();
this.actions.getComponents(projectId);
this.actions.getLinkedProjects(projectId);
Expand Down Expand Up @@ -256,6 +255,14 @@ export class ProjectOverviewComponent implements OnInit {
this.actions.getHomeWiki(ResourceType.Project, project.id);
}
});

effect(() => {
const project = this.currentProject();

if (project && this.hasWriteAccess()) {
this.actions.getProjectStorage(project.id);
}
});
}

private setupAddonsEffects(): void {
Expand Down
27 changes: 17 additions & 10 deletions src/app/shared/pipes/file-size.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,24 @@ import { Pipe, PipeTransform } from '@angular/core';
name: 'fileSize',
})
export class FileSizePipe implements PipeTransform {
transform(bytes: number): string {
if (!bytes) {
return '';
} else if (bytes < 1024) {
private readonly SI_UNITS = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
private readonly BINARY_UNITS = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];

transform(bytes: number | null | undefined, si = true): string {
if (bytes == null) return '0 B';

const threshold = si ? 1000 : 1024;
const units = si ? this.SI_UNITS : this.BINARY_UNITS;
const absBytes = Math.abs(bytes);

if (absBytes < threshold) {
return `${bytes} B`;
} else if (bytes < 1024 ** 2) {
return `${(bytes / 1024).toFixed(1)} kB`;
} else if (bytes < 1024 ** 3) {
return `${(bytes / 1024 ** 2).toFixed(1)} MB`;
} else {
return `${(bytes / 1024 ** 3).toFixed(1)} GB`;
}

const exponent = Math.min(Math.floor(Math.log(absBytes) / Math.log(threshold)), units.length - 1);

const value = bytes / Math.pow(threshold, exponent);

return `${value.toFixed(1)} ${units[exponent]}`;
}
}