-
Notifications
You must be signed in to change notification settings - Fork 567
[DSpace-CRIS] Bulk Import from Excel File (Frontend) #5135
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
76f97ba
[DURACOM-456] add bulk import functionality
FrancescoMolinaro 8a38ec2
Merge remote-tracking branch 'gitHub/main' into task/main/DURACOM-456
FrancescoMolinaro 7289376
Merge remote-tracking branch 'gitHub/main' into task/main/DURACOM-456
FrancescoMolinaro 7b3ed33
Merge remote-tracking branch 'gitHub/main' into task/main/DURACOM-456
FrancescoMolinaro a9a1d59
Merge remote-tracking branch 'gitHub/main' into task/main/DURACOM-456
FrancescoMolinaro 8a200e7
Merge branch 'task/main/DURACOM-456' of github.com:4Science/dspace-an…
FrancescoMolinaro 5c5003f
Merge remote-tracking branch 'gitHub/main' into task/main/DURACOM-456
FrancescoMolinaro 1accb50
[DURACOM-456] clean up unused property, add guard if selected file is…
FrancescoMolinaro 7c415b0
[DURACOM-456] refactoring
FrancescoMolinaro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,23 @@ | ||
| import { Route } from '@angular/router'; | ||
|
|
||
| import { i18nBreadcrumbResolver } from '../core/breadcrumbs/i18n-breadcrumb.resolver'; | ||
| import { bulkImportGuard } from './bulk-import.guard'; | ||
| import { BulkImportPageComponent } from './bulk-import-page.component'; | ||
| import { bulkImportPageResolver } from './bulk-import-page.resolver'; | ||
|
|
||
| /** | ||
| * RouterModule to help navigate to the page with the bulk import. | ||
| */ | ||
| export const ROUTES: Route[] = [ | ||
| { | ||
| path: ':id', | ||
| component: BulkImportPageComponent, | ||
| resolve: { | ||
| collection: bulkImportPageResolver, | ||
| breadcrumb: i18nBreadcrumbResolver, | ||
| }, | ||
| pathMatch: 'full', | ||
| data: { title: 'bulk-import.title', breadcrumbKey: 'bulk-import' }, | ||
| canActivate: [bulkImportGuard], | ||
| }, | ||
| ]; |
This file contains hidden or 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,27 @@ | ||
| <div class="container"> | ||
| <h2 class="mb-3">{{ 'bulk-import.title' | translate }}</h2> | ||
|
tdonohue marked this conversation as resolved.
Outdated
|
||
| <form [formGroup]="form" (ngSubmit)="submit()"> | ||
| <div class="form-group mb-2"> | ||
| <label for="name">{{ 'bulk-import.collection-name' | translate }}</label> | ||
| <input type="text" class="form-control" id="name" formControlName="name"> | ||
| </div> | ||
| <div class="form-group mb-2"> | ||
| <label for="file">{{ 'bulk-import.file' | translate }}</label> | ||
| <input type="file" (change)="handleFileInput($event)" formControlName="file" id="file" class="form-control-file d-block" requireFile/> | ||
| </div> | ||
| <div class="form-check"> | ||
| <input type="checkbox" formControlName="abortOnError" id="abortOnError" class="form-check-input" /> | ||
| <label for="abortOnError" class="me-5">{{ 'bulk-import.abort-on-error' | translate }}</label> | ||
| </div> | ||
|
|
||
| <button type="submit" class="btn btn-primary float-end" [dsBtnDisabled]="form.invalid" > | ||
| <span> | ||
| {{'bulk-import.submit' | translate}} | ||
| </span> | ||
| </button> | ||
| <button type="button" class="btn btn-outline-secondary float-end me-2" (click)="goBack()"> | ||
| {{'bulk-import.back' | translate}} | ||
| </button> | ||
|
|
||
| </form> | ||
| </div> | ||
This file contains hidden or 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,151 @@ | ||
| import { CommonModule } from '@angular/common'; | ||
| import { NO_ERRORS_SCHEMA } from '@angular/core'; | ||
| import { | ||
| ComponentFixture, | ||
| fakeAsync, | ||
| inject, | ||
| TestBed, | ||
| tick, | ||
| } from '@angular/core/testing'; | ||
| import { | ||
| FormsModule, | ||
| ReactiveFormsModule, | ||
| } from '@angular/forms'; | ||
| import { BrowserModule } from '@angular/platform-browser'; | ||
| import { | ||
| ActivatedRoute, | ||
| Router, | ||
| } from '@angular/router'; | ||
| import { RouterTestingModule } from '@angular/router/testing'; | ||
| import { NotificationsService } from '@dspace/core/notification-system/notifications.service'; | ||
| import { ActivatedRouteStub } from '@dspace/core/testing/active-router.stub'; | ||
| import { NotificationsServiceStub } from '@dspace/core/testing/notifications-service.stub'; | ||
| import { getMockRequestService } from '@dspace/core/testing/request.service.mock'; | ||
| import { RouterMock } from '@dspace/core/testing/router.mock'; | ||
| import { TranslateLoaderMock } from '@dspace/core/testing/translate-loader.mock'; | ||
| import { createSuccessfulRemoteDataObject } from '@dspace/core/utilities/remote-data.utils'; | ||
| import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; | ||
| import { | ||
| TranslateLoader, | ||
| TranslateModule, | ||
| } from '@ngx-translate/core'; | ||
| import { of } from 'rxjs'; | ||
|
|
||
| import { AuthService } from '../core/auth/auth.service'; | ||
| import { DSONameService } from '../core/breadcrumbs/dso-name.service'; | ||
| import { RestResponse } from '../core/cache/response.models'; | ||
| import { ScriptDataService } from '../core/data/processes/script-data.service'; | ||
| import { RequestService } from '../core/data/request.service'; | ||
| import { RequestEntry } from '../core/data/request-entry.model'; | ||
| import { Collection } from '../core/shared/collection.model'; | ||
| import { BulkImportPageComponent } from './bulk-import-page.component'; | ||
|
|
||
| describe('BulkImportPageComponent', () => { | ||
|
|
||
| let component: BulkImportPageComponent; | ||
| let fixture: ComponentFixture<BulkImportPageComponent>; | ||
|
|
||
| let requestService: any; | ||
| let scriptDataService: any; | ||
| let notificationsService: any; | ||
| let route: any; | ||
| let router: RouterMock; | ||
|
|
||
| const collection: Collection = Object.assign(new Collection(), { | ||
| id: '626b80c5-ef15-4b29-8e69-bda89b0a7acf', | ||
| name: 'Test collection', | ||
| }); | ||
|
|
||
| const file: File = new File(['test'], 'test.xls'); | ||
|
|
||
| const fileList: any = { | ||
| item: (index: number) => file, | ||
| length: 10, | ||
| }; | ||
|
|
||
| const authService = jasmine.createSpyObj('authService', { | ||
| isAuthenticated: of(true), | ||
| setRedirectUrl: {}, | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| requestService = getMockRequestService(); | ||
| scriptDataService = jasmine.createSpyObj('scriptDataService', { | ||
| invoke: of(Object.assign(new RequestEntry(), { | ||
| response: new RestResponse(true, 200, 'OK'), | ||
| })), | ||
| }); | ||
| notificationsService = new NotificationsServiceStub(); | ||
|
|
||
| route = new ActivatedRouteStub({}, { | ||
| collection: createSuccessfulRemoteDataObject( collection ), | ||
| }); | ||
| router = new RouterMock(); | ||
|
|
||
| TestBed.configureTestingModule({ | ||
| imports: [CommonModule, NgbModule, FormsModule, ReactiveFormsModule, BrowserModule, RouterTestingModule, | ||
| TranslateModule.forRoot({ | ||
| loader: { | ||
| provide: TranslateLoader, | ||
| useClass: TranslateLoaderMock, | ||
| }, | ||
| }), BulkImportPageComponent], | ||
| providers: [ | ||
| BulkImportPageComponent, | ||
| DSONameService, | ||
| { provide: RequestService, useValue: requestService }, | ||
| { provide: RequestService, useValue: requestService }, | ||
| { provide: ScriptDataService, useValue: scriptDataService }, | ||
| { provide: NotificationsService, useValue: notificationsService }, | ||
| { provide: ActivatedRoute, useValue: route }, | ||
| { provide: Router, useValue: router }, | ||
| { provide: AuthService, useValue: authService }, | ||
| ], | ||
| schemas: [NO_ERRORS_SCHEMA], | ||
| }).compileComponents(); | ||
|
|
||
| }); | ||
|
|
||
| beforeEach(fakeAsync(() => { | ||
| fixture = TestBed.createComponent(BulkImportPageComponent); | ||
| component = fixture.componentInstance; | ||
| fixture.detectChanges(); | ||
| tick(); | ||
| })); | ||
|
|
||
| it('should create BulkImportPageComponent', inject([BulkImportPageComponent], (comp: BulkImportPageComponent) => { | ||
| expect(comp).toBeDefined(); | ||
| })); | ||
|
|
||
| describe('when the user submit the form', () => { | ||
|
|
||
| beforeEach(() => { | ||
| component.form.value.abortOnError = true; | ||
| component.form.value.file = fileList; | ||
| component.setFile(fileList); | ||
| component.submit(); | ||
| }); | ||
|
|
||
| it('should invoke the bulk-import script', () => { | ||
| expect(scriptDataService.invoke).toHaveBeenCalledWith('bulk-import', [ | ||
| { name: '-c', value: '626b80c5-ef15-4b29-8e69-bda89b0a7acf' }, | ||
| { name: '-f', value: 'test.xls' }, | ||
| { name: '-er', value: true }, | ||
| ], [file]); | ||
| }); | ||
|
|
||
| }); | ||
|
|
||
| describe('when the user click on back button', () => { | ||
|
|
||
| beforeEach(() => { | ||
| component.goBack(); | ||
| }); | ||
|
|
||
| it('should nagivate to collection page', () => { | ||
| expect(router.navigateByUrl).toHaveBeenCalledWith('/collections/626b80c5-ef15-4b29-8e69-bda89b0a7acf'); | ||
| }); | ||
|
|
||
| }); | ||
|
|
||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.