mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-09 19:13:08 +00:00
101623: Reset in Treeview also resets selectedItems + Provide TreeviewService in root
This commit is contained in:
@@ -13,7 +13,7 @@ import { BrowseByGuard } from './browse-by-guard';
|
|||||||
providers: [
|
providers: [
|
||||||
ItemDataService,
|
ItemDataService,
|
||||||
BrowseService,
|
BrowseService,
|
||||||
BrowseByGuard
|
BrowseByGuard,
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class BrowseByPageModule {
|
export class BrowseByPageModule {
|
||||||
|
@@ -223,13 +223,15 @@ export class VocabularyService {
|
|||||||
* no valid cached version. Defaults to true
|
* no valid cached version. Defaults to true
|
||||||
* @param reRequestOnStale Whether or not the request should automatically be re-
|
* @param reRequestOnStale Whether or not the request should automatically be re-
|
||||||
* requested after the response becomes stale
|
* requested after the response becomes stale
|
||||||
|
* @param constructId Whether constructing the full vocabularyDetail ID
|
||||||
|
* ({vocabularyName}:{detailName}) is still necessary
|
||||||
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
|
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
|
||||||
* {@link HALLink}s should be automatically resolved
|
* {@link HALLink}s should be automatically resolved
|
||||||
* @return {Observable<RemoteData<VocabularyEntryDetail>>}
|
* @return {Observable<RemoteData<VocabularyEntryDetail>>}
|
||||||
* Return an observable that emits VocabularyEntryDetail object
|
* Return an observable that emits VocabularyEntryDetail object
|
||||||
*/
|
*/
|
||||||
findEntryDetailById(id: string, name: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<VocabularyEntryDetail>[]): Observable<RemoteData<VocabularyEntryDetail>> {
|
findEntryDetailById(id: string, name: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, constructId: boolean = true, ...linksToFollow: FollowLinkConfig<VocabularyEntryDetail>[]): Observable<RemoteData<VocabularyEntryDetail>> {
|
||||||
const findId = `${name}:${id}`;
|
const findId: string = (constructId ? `${name}:${id}` : id);
|
||||||
return this.vocabularyEntryDetailDataService.findById(findId, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
|
return this.vocabularyEntryDetailDataService.findById(findId, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -32,7 +32,6 @@ import { NumberPickerComponent } from './number-picker/number-picker.component';
|
|||||||
import { AuthorityConfidenceStateDirective } from './directives/authority-confidence-state.directive';
|
import { AuthorityConfidenceStateDirective } from './directives/authority-confidence-state.directive';
|
||||||
import { SortablejsModule } from 'ngx-sortablejs';
|
import { SortablejsModule } from 'ngx-sortablejs';
|
||||||
import { VocabularyTreeviewComponent } from './vocabulary-treeview/vocabulary-treeview.component';
|
import { VocabularyTreeviewComponent } from './vocabulary-treeview/vocabulary-treeview.component';
|
||||||
import { VocabularyTreeviewService } from './vocabulary-treeview/vocabulary-treeview.service';
|
|
||||||
import { VocabularyTreeviewModalComponent } from './vocabulary-treeview-modal/vocabulary-treeview-modal.component';
|
import { VocabularyTreeviewModalComponent } from './vocabulary-treeview-modal/vocabulary-treeview-modal.component';
|
||||||
import { FormBuilderService } from './builder/form-builder.service';
|
import { FormBuilderService } from './builder/form-builder.service';
|
||||||
import { DsDynamicTypeBindRelationService } from './builder/ds-dynamic-form-ui/ds-dynamic-type-bind-relation.service';
|
import { DsDynamicTypeBindRelationService } from './builder/ds-dynamic-form-ui/ds-dynamic-type-bind-relation.service';
|
||||||
@@ -104,7 +103,6 @@ const DIRECTIVES = [
|
|||||||
useValue: dsDynamicFormControlMapFn
|
useValue: dsDynamicFormControlMapFn
|
||||||
},
|
},
|
||||||
...DYNAMIC_MATCHER_PROVIDERS,
|
...DYNAMIC_MATCHER_PROVIDERS,
|
||||||
VocabularyTreeviewService,
|
|
||||||
DynamicFormLayoutService,
|
DynamicFormLayoutService,
|
||||||
DynamicFormService,
|
DynamicFormService,
|
||||||
DynamicFormValidationService,
|
DynamicFormValidationService,
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
>
|
>
|
||||||
<input class="mr-2" type="checkbox"
|
<input class="mr-2" type="checkbox"
|
||||||
[disabled]="!node.item?.selectable"
|
[disabled]="!node.item?.selectable"
|
||||||
|
[(ngModel)]="node.isSelected"
|
||||||
[checked]="node.isSelected"
|
[checked]="node.isSelected"
|
||||||
(change)="onSelect(node.item)"
|
(change)="onSelect(node.item)"
|
||||||
>
|
>
|
||||||
@@ -65,6 +66,7 @@
|
|||||||
container="body">
|
container="body">
|
||||||
<input class="mr-2" type="checkbox"
|
<input class="mr-2" type="checkbox"
|
||||||
[disabled]="!node.item?.selectable"
|
[disabled]="!node.item?.selectable"
|
||||||
|
[(ngModel)]="node.isSelected"
|
||||||
[checked]="node.isSelected"
|
[checked]="node.isSelected"
|
||||||
(change)="onSelect(node.item)"
|
(change)="onSelect(node.item)"
|
||||||
>
|
>
|
||||||
|
@@ -21,6 +21,7 @@ import { AuthTokenInfo } from '../../../core/auth/models/auth-token-info.model';
|
|||||||
import { authReducer } from '../../../core/auth/auth.reducer';
|
import { authReducer } from '../../../core/auth/auth.reducer';
|
||||||
import { storeModuleConfig } from '../../../app.reducer';
|
import { storeModuleConfig } from '../../../app.reducer';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
|
import { VocabularyService } from '../../../core/submission/vocabularies/vocabulary.service';
|
||||||
|
|
||||||
describe('VocabularyTreeviewComponent test suite', () => {
|
describe('VocabularyTreeviewComponent test suite', () => {
|
||||||
|
|
||||||
@@ -49,6 +50,14 @@ describe('VocabularyTreeviewComponent test suite', () => {
|
|||||||
restoreNodes: jasmine.createSpy('restoreNodes'),
|
restoreNodes: jasmine.createSpy('restoreNodes'),
|
||||||
cleanTree: jasmine.createSpy('cleanTree'),
|
cleanTree: jasmine.createSpy('cleanTree'),
|
||||||
});
|
});
|
||||||
|
const vocabularyServiceStub = jasmine.createSpyObj('VocabularyService', {
|
||||||
|
getVocabularyEntriesByValue: jasmine.createSpy('getVocabularyEntriesByValue'),
|
||||||
|
getEntryDetailParent: jasmine.createSpy('getEntryDetailParent'),
|
||||||
|
findEntryDetailById: jasmine.createSpy('findEntryDetailById'),
|
||||||
|
searchTopEntries: jasmine.createSpy('searchTopEntries'),
|
||||||
|
getEntryDetailChildren: jasmine.createSpy('getEntryDetailChildren'),
|
||||||
|
clearSearchTopRequests: jasmine.createSpy('clearSearchTopRequests')
|
||||||
|
});
|
||||||
|
|
||||||
initialState = {
|
initialState = {
|
||||||
core: {
|
core: {
|
||||||
@@ -77,6 +86,7 @@ describe('VocabularyTreeviewComponent test suite', () => {
|
|||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: VocabularyTreeviewService, useValue: vocabularyTreeviewServiceStub },
|
{ provide: VocabularyTreeviewService, useValue: vocabularyTreeviewServiceStub },
|
||||||
|
{ provide: VocabularyService, useValue: vocabularyServiceStub },
|
||||||
{ provide: NgbActiveModal, useValue: modalStub },
|
{ provide: NgbActiveModal, useValue: modalStub },
|
||||||
provideMockStore({ initialState }),
|
provideMockStore({ initialState }),
|
||||||
ChangeDetectorRef,
|
ChangeDetectorRef,
|
||||||
|
@@ -17,6 +17,8 @@ import { VocabularyTreeFlattener } from './vocabulary-tree-flattener';
|
|||||||
import { VocabularyTreeFlatDataSource } from './vocabulary-tree-flat-data-source';
|
import { VocabularyTreeFlatDataSource } from './vocabulary-tree-flat-data-source';
|
||||||
import { CoreState } from '../../../core/core-state.model';
|
import { CoreState } from '../../../core/core-state.model';
|
||||||
import { lowerCase } from 'lodash/string';
|
import { lowerCase } from 'lodash/string';
|
||||||
|
import { VocabularyService } from '../../../core/submission/vocabularies/vocabulary.service';
|
||||||
|
import { getFirstSucceededRemoteDataPayload } from '../../../core/shared/operators';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component that shows a hierarchical vocabulary in a tree view
|
* Component that shows a hierarchical vocabulary in a tree view
|
||||||
@@ -114,11 +116,13 @@ export class VocabularyTreeviewComponent implements OnDestroy, OnInit {
|
|||||||
* Initialize instance variables
|
* Initialize instance variables
|
||||||
*
|
*
|
||||||
* @param {VocabularyTreeviewService} vocabularyTreeviewService
|
* @param {VocabularyTreeviewService} vocabularyTreeviewService
|
||||||
|
* @param {vocabularyService} vocabularyService
|
||||||
* @param {Store<CoreState>} store
|
* @param {Store<CoreState>} store
|
||||||
* @param {TranslateService} translate
|
* @param {TranslateService} translate
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
private vocabularyTreeviewService: VocabularyTreeviewService,
|
private vocabularyTreeviewService: VocabularyTreeviewService,
|
||||||
|
private vocabularyService: VocabularyService,
|
||||||
private store: Store<CoreState>,
|
private store: Store<CoreState>,
|
||||||
private translate: TranslateService
|
private translate: TranslateService
|
||||||
) {
|
) {
|
||||||
@@ -284,13 +288,22 @@ export class VocabularyTreeviewComponent implements OnDestroy, OnInit {
|
|||||||
* Reset tree resulting from a previous search
|
* Reset tree resulting from a previous search
|
||||||
*/
|
*/
|
||||||
reset() {
|
reset() {
|
||||||
|
this.searchText = '';
|
||||||
|
for (const item of this.selectedItems) {
|
||||||
|
this.subs.push(this.vocabularyService.findEntryDetailById(item, this.vocabularyOptions.name, true, true, false).pipe(
|
||||||
|
getFirstSucceededRemoteDataPayload(),
|
||||||
|
).subscribe((detail: VocabularyEntryDetail) => {
|
||||||
|
this.deselect.emit(detail);
|
||||||
|
}));
|
||||||
|
this.nodeMap.get(item).isSelected = false;
|
||||||
|
}
|
||||||
|
this.selectedItems = [];
|
||||||
|
|
||||||
if (isNotEmpty(this.storedNodeMap)) {
|
if (isNotEmpty(this.storedNodeMap)) {
|
||||||
this.nodeMap = this.storedNodeMap;
|
this.nodeMap = this.storedNodeMap;
|
||||||
this.storedNodeMap = new Map<string, TreeviewFlatNode>();
|
this.storedNodeMap = new Map<string, TreeviewFlatNode>();
|
||||||
this.vocabularyTreeviewService.restoreNodes();
|
this.vocabularyTreeviewService.restoreNodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.searchText = '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -25,7 +25,9 @@ import { VocabularyEntryDetail } from '../../../core/submission/vocabularies/mod
|
|||||||
/**
|
/**
|
||||||
* A service that provides methods to deal with vocabulary tree
|
* A service that provides methods to deal with vocabulary tree
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
export class VocabularyTreeviewService {
|
export class VocabularyTreeviewService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -31,7 +31,6 @@ import { GoogleAnalyticsService } from '../../app/statistics/google-analytics.se
|
|||||||
import { AuthRequestService } from '../../app/core/auth/auth-request.service';
|
import { AuthRequestService } from '../../app/core/auth/auth-request.service';
|
||||||
import { BrowserAuthRequestService } from '../../app/core/auth/browser-auth-request.service';
|
import { BrowserAuthRequestService } from '../../app/core/auth/browser-auth-request.service';
|
||||||
import { BrowserInitService } from './browser-init.service';
|
import { BrowserInitService } from './browser-init.service';
|
||||||
import { VocabularyTreeviewService } from 'src/app/shared/form/vocabulary-treeview/vocabulary-treeview.service';
|
|
||||||
|
|
||||||
export const REQ_KEY = makeStateKey<string>('req');
|
export const REQ_KEY = makeStateKey<string>('req');
|
||||||
|
|
||||||
@@ -111,10 +110,6 @@ export function getRequest(transferState: TransferState): any {
|
|||||||
{
|
{
|
||||||
provide: LocationToken,
|
provide: LocationToken,
|
||||||
useFactory: locationProvider,
|
useFactory: locationProvider,
|
||||||
},
|
|
||||||
{
|
|
||||||
provide: VocabularyTreeviewService,
|
|
||||||
useClass: VocabularyTreeviewService,
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user