-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #773 from geonetwork/DF/add-csv-support
[Datafeeder] Add CSV support
- Loading branch information
Showing
29 changed files
with
646 additions
and
27 deletions.
There are no files selected for viewing
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
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
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
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
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
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
4 changes: 4 additions & 0 deletions
4
...er/src/app/presentation/pages/dataset-validation-csv-page/dataset-validation-csv-page.css
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,4 @@ | ||
:host { | ||
display: flex; | ||
flex: 1; | ||
} |
113 changes: 113 additions & 0 deletions
113
...r/src/app/presentation/pages/dataset-validation-csv-page/dataset-validation-csv-page.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,113 @@ | ||
<div class="flex-1 flex items-center dataset-validation-bg"> | ||
<div class="container mx-auto pt-16 pb-16 w-full h-full flex flex-col"> | ||
<div class="text-5xl font-bold" translate> | ||
datafeeder.datasetValidation.title | ||
</div> | ||
<div class="pb-4 pt-4"> | ||
<gn-ui-step-bar | ||
[steps]="numberOfSteps" | ||
[currentStep]="1" | ||
type="primary" | ||
></gn-ui-step-bar> | ||
</div> | ||
<div | ||
class="text-2xl font-bold" | ||
translate | ||
[translateParams]="{ number: numOfEntities }" | ||
> | ||
datafeeder.datasetValidation.datasetInformation | ||
</div> | ||
|
||
<div class="flex flex-col gap-10 pb-10 pt-5 flex-1"> | ||
<div class="flex gap-4 w-full"> | ||
<div> | ||
<gn-ui-dropdown-selector | ||
[title]="'datafeeder.validation.csv.delimiter' | translate" | ||
[choices]="delimiterChoices" | ||
(selectValue)="selectDelimiter($event)" | ||
[selected]="csvDelimiter" | ||
[extraBtnClass]="'secondary min-w-full'" | ||
ariaName="search-sort-by" | ||
> | ||
</gn-ui-dropdown-selector> | ||
</div> | ||
<div> | ||
<gn-ui-dropdown-selector | ||
[title]="'datafeeder.validation.csv.quoteChar' | translate" | ||
[choices]="quoteCharChoices" | ||
(selectValue)="selectQuoteChar($event)" | ||
[selected]="quoteChar" | ||
[extraBtnClass]="'secondary min-w-full'" | ||
ariaName="search-sort-by" | ||
> | ||
</gn-ui-dropdown-selector> | ||
</div> | ||
<div> | ||
<gn-ui-dropdown-selector | ||
[title]="'datafeeder.validation.csv.lat.field' | translate" | ||
[choices]="latLngChoices" | ||
(selectValue)="selectLatLng($event, true)" | ||
[selected]="latField" | ||
[extraBtnClass]="'secondary min-w-full' + (latLngValid ? '' : ' !border-red-500')" | ||
ariaName="search-sort-by" | ||
> | ||
</gn-ui-dropdown-selector> | ||
</div> | ||
<div> | ||
<gn-ui-dropdown-selector | ||
[title]="'datafeeder.validation.csv.lng.field' | translate" | ||
[choices]="latLngChoices" | ||
(selectValue)="selectLatLng($event, false)" | ||
[selected]="lngField" | ||
[extraBtnClass]="'secondary min-w-full' + (latLngValid ? '' : ' !border-red-500')" | ||
ariaName="search-sort-by" | ||
> | ||
</gn-ui-dropdown-selector> | ||
</div> | ||
</div> | ||
<div> | ||
<div class="pb-2" translate> | ||
datafeeder.datasetValidationCsv.lineNumbers | ||
</div> | ||
<div | ||
class="relative overflow-x-auto shadow-md sm:rounded-lg border rounded-2xl" | ||
> | ||
<table | ||
class="bg-white w-full table-auto border-separate border-spacing-0" | ||
> | ||
<tbody> | ||
<tr | ||
*ngFor="let row of csvData; let isFirstRow = first" | ||
class="{{isFirstRow ? 'uppercase font-bold' : ''}} rounded-2xl bg-white border-b bg-secondary-white" | ||
> | ||
<td | ||
*ngFor="let value of row; let isOdd = odd; let columnIndex = index;" | ||
class="{{isOdd? 'bg-slate-100' : ''}} {{isFirstRow ? 'border-b' : ''}} text-sm px-2 py-2 border-spacing-0 border-separate max-w-[200px] whitespace-nowrap text-ellipsis overflow-hidden" | ||
[title]="value" | ||
> | ||
{{value}} | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="flex items-center justify-between"> | ||
<p | ||
class="text-sm" | ||
[innerHTML]="'datafeeder.datasetValidationCsv.explicitLineNumbers' | translate" | ||
></p> | ||
<gn-ui-button | ||
(buttonClick)="submitValidation()" | ||
[disabled]="!isValid()" | ||
type="primary" | ||
extraClass="rounded-full px-20" | ||
> | ||
<span class="uppercase text-white font-bold" translate> | ||
datafeeder.datasetValidation.submitButton | ||
</span> | ||
</gn-ui-button> | ||
</div> | ||
</div> | ||
</div> |
117 changes: 117 additions & 0 deletions
117
...rc/app/presentation/pages/dataset-validation-csv-page/dataset-validation-csv-page.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,117 @@ | ||
import { NO_ERRORS_SCHEMA } from '@angular/core' | ||
import { ComponentFixture, TestBed } from '@angular/core/testing' | ||
import { ActivatedRoute, Router } from '@angular/router' | ||
import { | ||
AnalysisStatusEnumApiModel, | ||
UploadJobStatusApiModel, | ||
} from '@geonetwork-ui/data-access/datafeeder' | ||
import { of } from 'rxjs' | ||
import { WizardService } from '@geonetwork-ui/feature/editor' | ||
import { DatafeederFacade } from '../../../store/datafeeder.facade' | ||
import { DatasetValidationCsvPageComponent } from './dataset-validation-csv-page' | ||
import { UtilI18nModule } from '@geonetwork-ui/util/i18n' | ||
import { TranslateModule } from '@ngx-translate/core' | ||
|
||
const jobMock: UploadJobStatusApiModel = { | ||
jobId: '1234', | ||
status: AnalysisStatusEnumApiModel.Done, | ||
progress: 100, | ||
datasets: [ | ||
{ | ||
name: 'f_name', | ||
featureCount: 36, | ||
format: 'CSV', | ||
options: { | ||
quoteChar: '"', | ||
csv: 'IlllYXIiLCJNYWtlIiwiTW9kZWwiLCJMZW5ndGgiCiIxOTk3IiwiRm9yZCIsIkUzNTAiLCIyLjM1IgoiMjAwMCIsIk1lcmN1cnkiLCJDb3VnYXIiLCIyLjM4Ig==', | ||
}, | ||
}, | ||
], | ||
} | ||
|
||
const facadeMock = { | ||
upload$: of(jobMock), | ||
} | ||
|
||
const wizardServiceMock = { | ||
getConfigurationStepNumber: jest.fn(() => 6), | ||
initialize: jest.fn(), | ||
getWizardFieldData: jest.fn(() => null), | ||
} | ||
|
||
const activatedRouteMock = { | ||
params: of({ id: 1 }), | ||
} | ||
|
||
const routerMock = { | ||
navigate: jest.fn(), | ||
} | ||
|
||
describe('DatasetValidationCsvPageComponent', () => { | ||
let component: DatasetValidationCsvPageComponent | ||
let fixture: ComponentFixture<DatasetValidationCsvPageComponent> | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [DatasetValidationCsvPageComponent], | ||
imports: [UtilI18nModule, TranslateModule.forRoot()], | ||
schemas: [NO_ERRORS_SCHEMA], | ||
providers: [ | ||
{ | ||
provide: WizardService, | ||
useValue: wizardServiceMock, | ||
}, | ||
{ | ||
provide: DatafeederFacade, | ||
useValue: facadeMock, | ||
}, | ||
{ provide: ActivatedRoute, useValue: activatedRouteMock }, | ||
{ provide: Router, useValue: routerMock }, | ||
], | ||
}).compileComponents() | ||
}) | ||
|
||
it('should create', () => { | ||
createComponent() | ||
expect(component).toBeTruthy() | ||
}) | ||
|
||
describe('Job DONE', () => { | ||
beforeEach(() => { | ||
createComponent() | ||
fixture.detectChanges() | ||
}) | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy() | ||
}) | ||
|
||
it('should contain the correct csvData', () => { | ||
expect(component.csvData).toEqual([ | ||
['Year', 'Make', 'Model', 'Length'], | ||
['1997', 'Ford', 'E350', '2.35'], | ||
['2000', 'Mercury', 'Cougar', '2.38'], | ||
]) | ||
}) | ||
}) | ||
|
||
describe('Job ERROR', () => { | ||
beforeEach(() => { | ||
jobMock.status = AnalysisStatusEnumApiModel.Error | ||
createComponent() | ||
}) | ||
|
||
it('route to validation page', () => { | ||
expect(routerMock.navigate).toHaveBeenCalledWith(['/'], { | ||
relativeTo: activatedRouteMock, | ||
queryParams: { error: 'analysis' }, | ||
}) | ||
}) | ||
}) | ||
|
||
function createComponent() { | ||
fixture = TestBed.createComponent(DatasetValidationCsvPageComponent) | ||
component = fixture.componentInstance | ||
fixture.detectChanges() | ||
} | ||
}) |
Oops, something went wrong.