Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cde create visualization page #340

Merged
merged 40 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
7252449
Make initial page outline
edlu77 Apr 1, 2024
9754423
Styling and fonts
edlu77 Apr 2, 2024
adaf132
Fix build targets
edlu77 Apr 2, 2024
aa3f7db
Merge branch 'cell-distance-explorer' of https://github.com/hubmapcon…
edlu77 Apr 2, 2024
27dfb9e
Edit output path
edlu77 Apr 2, 2024
d155d74
Switch to browser-esbuild
edlu77 Apr 2, 2024
156a685
Merge branch 'cell-distance-explorer' of https://github.com/hubmapcon…
edlu77 Apr 2, 2024
38c7932
Set up link to create visualization page
edlu77 Apr 2, 2024
74e420d
Fix issues and update logic
edlu77 Apr 3, 2024
d810ef9
Merge branch 'cell-distance-explorer' of https://github.com/hubmapcon…
edlu77 Apr 3, 2024
8e3de2f
Update package-lock.json
edlu77 Apr 3, 2024
38fed02
Improvements
edlu77 Apr 4, 2024
50c295c
Merge branch 'cell-distance-explorer' of https://github.com/hubmapcon…
edlu77 Apr 4, 2024
0c74468
Update package-lock.json
edlu77 Apr 4, 2024
87a9e59
Use reactive form controls
edlu77 Apr 4, 2024
bb25173
Move redirects file
edlu77 Apr 5, 2024
52a157f
Add cell type data service
edlu77 Apr 5, 2024
e387421
Check if data is uploaded when submitting
edlu77 Apr 5, 2024
4d8e542
Merge branch 'cell-distance-explorer' of https://github.com/hubmapcon…
edlu77 Apr 5, 2024
6200201
More changes
edlu77 Apr 12, 2024
e642958
Clean up and requested changes
edlu77 Apr 12, 2024
e6e8bf8
Merge branch 'cell-distance-explorer' of https://github.com/hubmapcon…
edlu77 Apr 12, 2024
b348eac
Use signals for file upload service
edlu77 Apr 12, 2024
149810a
Some tweaks
edlu77 Apr 12, 2024
8c65cc4
Use formBuilder to create and validate form
edlu77 Apr 15, 2024
bc74142
create file upload component
bhushankhope Apr 17, 2024
aa48d95
Merge branch 'cell-distance-explorer' into cde-create-visualization-page
axdanbol Apr 17, 2024
95ddf87
update form and its css
bhushankhope Apr 19, 2024
e1ba83d
create theme and modify cards
bhushankhope Apr 24, 2024
eef7ed0
add states to form field
bhushankhope Apr 25, 2024
dde2ecc
update background size
bhushankhope Apr 26, 2024
f2bf822
add tests for csv loader
bhushankhope May 7, 2024
139a43c
add tests for create vis page
bhushankhope May 9, 2024
392f975
add tests for form control directive
bhushankhope May 9, 2024
8e04576
Merge branch 'cell-distance-explorer' into cde-create-visualization-page
axdanbol May 10, 2024
ff7e3c6
build(cde): :wrench: Increase style files max size
axdanbol May 10, 2024
ad9090c
Merge branch 'cell-distance-explorer' of https://github.com/hubmapcon…
axdanbol May 16, 2024
42d145a
refactor(cde): :recycle: Post merge fixes
axdanbol May 16, 2024
635bc7a
docs(cde): :memo: Increase code doc coverage
axdanbol May 16, 2024
06847ff
refactor(cde): Fix import
axdanbol May 16, 2024
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
2 changes: 1 addition & 1 deletion apps/cde-ui/src/_redirects
edlu77 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/* /index.html 200
/* /index.html 200
2 changes: 0 additions & 2 deletions apps/cde-ui/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
<cde-header></cde-header>
<router-outlet></router-outlet>
<cde-footer></cde-footer>
7 changes: 7 additions & 0 deletions apps/cde-ui/src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ApplicationConfig } from '@angular/core';
import { provideAnimations } from '@angular/platform-browser/animations';
import { Routes, provideRouter } from '@angular/router';
import { CreateVisualizationPageComponent } from './pages/create-visualization-page/create-visualization-page.component';
import { LandingPageComponent } from './pages/landing-page/landing-page.component';
import { provideIcons } from './services/icon-registry/icon-registry.service';
import { provideHttpClient } from '@angular/common/http';
Expand All @@ -12,6 +14,10 @@ const routes: Routes = [
path: 'home',
loadComponent: () => LandingPageComponent,
},
{
path: 'create',
loadComponent: () => CreateVisualizationPageComponent,
},
{
path: '**',
redirectTo: 'home',
Expand All @@ -24,6 +30,7 @@ const routes: Routes = [
export const appConfig: ApplicationConfig = {
providers: [
provideRouter(routes),
provideAnimations(),
provideHttpClient(),
provideIcons([
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ChangeDetectorRef, Directive, OnInit, inject } from '@angular/core';
import { NgControl } from '@angular/forms';

@Directive({
selector: '[cdeMarkEmptyFormControl]',
standalone: true,
// eslint-disable-next-line @angular-eslint/no-host-metadata-property
host: {
'[class.empty]': 'empty',
},
})
export class MarkEmptyFormControlDirective implements OnInit {
empty = true;

private readonly control = inject(NgControl, { self: true });
private readonly cdr = inject(ChangeDetectorRef);

ngOnInit(): void {
this.control.valueChanges?.subscribe((value) => {
this.empty = !value;
this.cdr.markForCheck();
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<div class="column-content">
@if (!file && fileTitle(); as title) {
<h3 class="subtitle">{{ fileTitle() }}</h3>
}
@if (file) {
<div class="upload-success">
<div class="filename">
@if (fileTitle(); as title) {
<h3 class="subtitle">File Loaded:</h3>
} @else {
<span class="loaded-label">File loaded:</span>
}
<span class="column-info-list mat-body-2 file-name">{{ file.name }}</span>
</div>
<button class="remove-file" mat-flat-button (click)="cancelLoad()" type="button" color="primary">
<mat-icon class="material-symbols-rounded">cancel</mat-icon>
Remove CSV
</button>
</div>
} @else {
<button class="upload" mat-flat-button (click)="fileInput.click()" type="button" color="primary">
<mat-icon class="material-symbols-rounded">upload</mat-icon>
Upload CSV
</button>
<input
#fileInput
(change)="load(fileInput)"
type="file"
[attr.accept]="accept()"
name="fileInput"
style="display: none"
/>
}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
:host {
display: block;

.upload-success {
display: flex;
justify-content: space-between;

.filename span {
display: block;
}

.file-name {
font-weight: 300;
}

.remove-file {
align-self: flex-end;
}
}

.upload-colormap .loaded-label {
font-weight: 500;
font-size: 1.5rem;
line-height: 2.25rem;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FileUploadComponent } from './file-upload.component';

describe('FileUploadComponent', () => {
let component: FileUploadComponent;
let fixture: ComponentFixture<FileUploadComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [FileUploadComponent],
}).compileComponents();

fixture = TestBed.createComponent(FileUploadComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { CommonModule } from '@angular/common';
import { ChangeDetectionStrategy, Component, Injector, Signal, effect, inject, input, output } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';

export interface FileLoaderOptions {
signal: AbortSignal;
}

export interface FileLoaderResult<T> {
progress: Signal<number>;
result: Promise<T>;
}

export type FileLoader<T> = (file: File, options: FileLoaderOptions) => FileLoaderResult<T>;

type CleanupFn = () => void;

@Component({
selector: 'cde-file-upload',
standalone: true,
imports: [CommonModule, MatIconModule, MatButtonModule],
templateUrl: './file-upload.component.html',
styleUrl: './file-upload.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class FileUploadComponent<T> {
readonly fileTitle = input<string>();
readonly accept = input.required<string>();
readonly loader = input.required<FileLoader<T>>();

readonly progress = output<number>();
readonly loadStarted = output<File>();
readonly loadCancelled = output<void>();
readonly loadErrored = output<unknown>();
readonly loadCompleted = output<T>();

private readonly injector = inject(Injector);

file?: File;
private cleanup: CleanupFn[] = [];

load(el: HTMLInputElement): void {
if (el.files === null) {
return;
}

const { loader, injector, progress, loadStarted } = this;
const file = (this.file = el.files[0]);
const cleanup: CleanupFn[] = (this.cleanup = []);
const abortController = new AbortController();
const options: FileLoaderOptions = {
signal: abortController.signal,
};
const result = loader()(file, options);
let done = false;

el.files = null;
loadStarted.emit(file);
const progressRef = effect(() => progress.emit(result.progress()), { injector, manualCleanup: true });
this.handleResult(result.result, cleanup, () => done);

cleanup.push(
() => (done = true),
() => progressRef.destroy(),
() => abortController.abort(),
);
}

cancelLoad(): void {
this.runCleanup(this.cleanup);
this.file = undefined;
this.loadCancelled.emit();
}

private runCleanup(fns: CleanupFn[]): void {
for (const fn of fns) {
fn();
}
}

private async handleResult(result: Promise<T>, cleanup: CleanupFn[], isDone: () => boolean): Promise<void> {
const { progress, loadErrored, loadCompleted } = this;
try {
const data = await result;
if (!isDone()) {
progress.emit(1);
loadCompleted.emit(data);
}
} catch (reason) {
if (!isDone()) {
this.file = undefined;
loadErrored.emit(reason);
}
} finally {
this.runCleanup(cleanup);
}
}
}
9 changes: 5 additions & 4 deletions apps/cde-ui/src/app/components/footer/footer.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

.footer-wrapper {
display: grid;
grid-template-columns: 1fr 2fr;
grid-template-columns: minmax(30.8125rem, auto) 2fr;
}

.footer-left {
Expand Down Expand Up @@ -35,8 +35,9 @@

.social-funded {
display: flex;
margin: 8.5rem 24.375rem 0 6.5rem;
gap: 13.875rem;
flex-wrap: wrap;
margin: 8.5rem 6.5rem 0 6.5rem;
column-gap: 13.875rem;

.social-media {
display: flex;
Expand Down Expand Up @@ -108,7 +109,7 @@
}

.disclaimer {
margin: 5rem 6.5rem 8.5rem;
margin: 5rem 6.5rem 8.5rem 6.5rem;
color: hsla(240, 11%, 33%, 1);
span {
display: block;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
:host {
display: block;
margin: 3rem 5rem;
padding: 3rem 5rem;

a {
text-decoration: none;
Expand Down
28 changes: 28 additions & 0 deletions apps/cde-ui/src/app/models/create-visualization-page-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { CellTypeTableData } from '../services/file-upload-service';

export interface ColorMapItem {
cell_id: number;
cell_type: string;
cell_color: [number, number, number];
}

export type ColorMap = ColorMapItem[];

export interface VisualizationSettings {
data: CellTypeTableData[];
anchorCellType?: string;
metadata: MetaData;
colorMap?: ColorMap;
}

export interface MetaData {
title?: string;
sex: string;
thickness?: number;
technology?: string;
age?: number;
pixelSize?: number;
organ?: string;
}

export type CsvType = 'data' | 'colormap';
Loading
Loading