Skip to content

Commit 7135f8a

Browse files
committed
Merge branch 'w2p-101127_browse-by-controlled-vocabulary' into w2p-101127_browse-by-controlled-vocabulary-7.6.0-next
Conflicts: src/app/browse-by/browse-by-page.module.ts src/app/shared/form/form.module.ts
2 parents 23b5d52 + 9d08cac commit 7135f8a

7 files changed

Lines changed: 34 additions & 12 deletions

File tree

src/app/core/submission/vocabularies/vocabulary.service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,15 @@ export class VocabularyService {
223223
* no valid cached version. Defaults to true
224224
* @param reRequestOnStale Whether or not the request should automatically be re-
225225
* requested after the response becomes stale
226+
* @param constructId Whether constructing the full vocabularyDetail ID
227+
* ({vocabularyName}:{detailName}) is still necessary
226228
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
227229
* {@link HALLink}s should be automatically resolved
228230
* @return {Observable<RemoteData<VocabularyEntryDetail>>}
229231
* Return an observable that emits VocabularyEntryDetail object
230232
*/
231-
findEntryDetailById(id: string, name: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<VocabularyEntryDetail>[]): Observable<RemoteData<VocabularyEntryDetail>> {
232-
const findId = `${name}:${id}`;
233+
findEntryDetailById(id: string, name: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, constructId: boolean = true, ...linksToFollow: FollowLinkConfig<VocabularyEntryDetail>[]): Observable<RemoteData<VocabularyEntryDetail>> {
234+
const findId: string = (constructId ? `${name}:${id}` : id);
233235
return this.vocabularyEntryDetailDataService.findById(findId, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
234236
}
235237

src/app/shared/form/form.module.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import { NumberPickerComponent } from './number-picker/number-picker.component';
3232
import { AuthorityConfidenceStateDirective } from './directives/authority-confidence-state.directive';
3333
import { SortablejsModule } from 'ngx-sortablejs';
3434
import { VocabularyTreeviewComponent } from './vocabulary-treeview/vocabulary-treeview.component';
35-
import { VocabularyTreeviewService } from './vocabulary-treeview/vocabulary-treeview.service';
3635
import { VocabularyTreeviewModalComponent } from './vocabulary-treeview-modal/vocabulary-treeview-modal.component';
3736
import { FormBuilderService } from './builder/form-builder.service';
3837
import { DsDynamicTypeBindRelationService } from './builder/ds-dynamic-form-ui/ds-dynamic-type-bind-relation.service';
@@ -107,7 +106,6 @@ const DIRECTIVES = [
107106
provide: DYNAMIC_FORM_CONTROL_MAP_FN,
108107
useValue: dsDynamicFormControlMapFn
109108
},
110-
VocabularyTreeviewService,
111109
DynamicFormLayoutService,
112110
DynamicFormService,
113111
DynamicFormValidationService,

src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ <h4 *ngIf="!(loading | async) && dataSource.data.length === 0" class="text-cente
3333
>
3434
<input class="mr-2" type="checkbox"
3535
[disabled]="!node.item?.selectable"
36+
[(ngModel)]="node.isSelected"
3637
[checked]="node.isSelected"
3738
(change)="onSelect(node.item)"
3839
>
@@ -65,6 +66,7 @@ <h4 *ngIf="!(loading | async) && dataSource.data.length === 0" class="text-cente
6566
container="body">
6667
<input class="mr-2" type="checkbox"
6768
[disabled]="!node.item?.selectable"
69+
[(ngModel)]="node.isSelected"
6870
[checked]="node.isSelected"
6971
(change)="onSelect(node.item)"
7072
>

src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { AuthTokenInfo } from '../../../core/auth/models/auth-token-info.model';
2121
import { authReducer } from '../../../core/auth/auth.reducer';
2222
import { storeModuleConfig } from '../../../app.reducer';
2323
import { By } from '@angular/platform-browser';
24+
import { VocabularyService } from '../../../core/submission/vocabularies/vocabulary.service';
2425

2526
describe('VocabularyTreeviewComponent test suite', () => {
2627

@@ -49,6 +50,14 @@ describe('VocabularyTreeviewComponent test suite', () => {
4950
restoreNodes: jasmine.createSpy('restoreNodes'),
5051
cleanTree: jasmine.createSpy('cleanTree'),
5152
});
53+
const vocabularyServiceStub = jasmine.createSpyObj('VocabularyService', {
54+
getVocabularyEntriesByValue: jasmine.createSpy('getVocabularyEntriesByValue'),
55+
getEntryDetailParent: jasmine.createSpy('getEntryDetailParent'),
56+
findEntryDetailById: jasmine.createSpy('findEntryDetailById'),
57+
searchTopEntries: jasmine.createSpy('searchTopEntries'),
58+
getEntryDetailChildren: jasmine.createSpy('getEntryDetailChildren'),
59+
clearSearchTopRequests: jasmine.createSpy('clearSearchTopRequests')
60+
});
5261

5362
initialState = {
5463
core: {
@@ -77,6 +86,7 @@ describe('VocabularyTreeviewComponent test suite', () => {
7786
],
7887
providers: [
7988
{ provide: VocabularyTreeviewService, useValue: vocabularyTreeviewServiceStub },
89+
{ provide: VocabularyService, useValue: vocabularyServiceStub },
8090
{ provide: NgbActiveModal, useValue: modalStub },
8191
provideMockStore({ initialState }),
8292
ChangeDetectorRef,

src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import { VocabularyTreeFlattener } from './vocabulary-tree-flattener';
1717
import { VocabularyTreeFlatDataSource } from './vocabulary-tree-flat-data-source';
1818
import { CoreState } from '../../../core/core-state.model';
1919
import { lowerCase } from 'lodash/string';
20+
import { VocabularyService } from '../../../core/submission/vocabularies/vocabulary.service';
21+
import { getFirstSucceededRemoteDataPayload } from '../../../core/shared/operators';
2022

2123
/**
2224
* Component that shows a hierarchical vocabulary in a tree view
@@ -114,11 +116,13 @@ export class VocabularyTreeviewComponent implements OnDestroy, OnInit {
114116
* Initialize instance variables
115117
*
116118
* @param {VocabularyTreeviewService} vocabularyTreeviewService
119+
* @param {vocabularyService} vocabularyService
117120
* @param {Store<CoreState>} store
118121
* @param {TranslateService} translate
119122
*/
120123
constructor(
121124
private vocabularyTreeviewService: VocabularyTreeviewService,
125+
private vocabularyService: VocabularyService,
122126
private store: Store<CoreState>,
123127
private translate: TranslateService
124128
) {
@@ -284,13 +288,22 @@ export class VocabularyTreeviewComponent implements OnDestroy, OnInit {
284288
* Reset tree resulting from a previous search
285289
*/
286290
reset() {
291+
this.searchText = '';
292+
for (const item of this.selectedItems) {
293+
this.subs.push(this.vocabularyService.findEntryDetailById(item, this.vocabularyOptions.name, true, true, false).pipe(
294+
getFirstSucceededRemoteDataPayload(),
295+
).subscribe((detail: VocabularyEntryDetail) => {
296+
this.deselect.emit(detail);
297+
}));
298+
this.nodeMap.get(item).isSelected = false;
299+
}
300+
this.selectedItems = [];
301+
287302
if (isNotEmpty(this.storedNodeMap)) {
288303
this.nodeMap = this.storedNodeMap;
289304
this.storedNodeMap = new Map<string, TreeviewFlatNode>();
290305
this.vocabularyTreeviewService.restoreNodes();
291306
}
292-
293-
this.searchText = '';
294307
}
295308

296309
/**

src/app/shared/form/vocabulary-treeview/vocabulary-treeview.service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ import { VocabularyEntryDetail } from '../../../core/submission/vocabularies/mod
2525
/**
2626
* A service that provides methods to deal with vocabulary tree
2727
*/
28-
@Injectable()
28+
@Injectable({
29+
providedIn: 'root'
30+
})
2931
export class VocabularyTreeviewService {
3032

3133
/**

src/modules/app/browser-app.module.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import { GoogleAnalyticsService } from '../../app/statistics/google-analytics.se
3131
import { AuthRequestService } from '../../app/core/auth/auth-request.service';
3232
import { BrowserAuthRequestService } from '../../app/core/auth/browser-auth-request.service';
3333
import { BrowserInitService } from './browser-init.service';
34-
import { VocabularyTreeviewService } from 'src/app/shared/form/vocabulary-treeview/vocabulary-treeview.service';
3534

3635
export const REQ_KEY = makeStateKey<string>('req');
3736

@@ -111,10 +110,6 @@ export function getRequest(transferState: TransferState): any {
111110
{
112111
provide: LocationToken,
113112
useFactory: locationProvider,
114-
},
115-
{
116-
provide: VocabularyTreeviewService,
117-
useClass: VocabularyTreeviewService,
118113
}
119114
]
120115
})

0 commit comments

Comments
 (0)