@@ -264,7 +264,7 @@ export default class SPTermStorePickerService {
264
264
* Retrieve all terms that starts with the searchText
265
265
* @param searchText
266
266
*/
267
- public searchTermsByName ( searchText : string ) : Promise < IPickerTerm [ ] > {
267
+ public searchTermsByName ( searchText : string , termSet : string ) : Promise < IPickerTerm [ ] > {
268
268
if ( Environment . type === EnvironmentType . Local ) {
269
269
// If the running environment is local, load the data from the mock
270
270
return SPTermStoreMockHttpClient . searchTermsByName ( searchText ) ;
@@ -273,6 +273,76 @@ export default class SPTermStorePickerService {
273
273
}
274
274
}
275
275
276
+ private getTermsById ( termId ) {
277
+ var terms = sessionStorage . getItem ( termId ) ;
278
+ if ( terms )
279
+ return JSON . parse ( terms ) ;
280
+ else
281
+ return null ;
282
+ }
283
+
284
+
285
+ private searchTermsBySearchText ( terms , searchText ) {
286
+ if ( terms ) {
287
+ return terms . filter ( ( t ) => { return t . name . toLowerCase ( ) . indexOf ( searchText . toLowerCase ( ) ) > - 1 ; } ) ;
288
+ }
289
+ else
290
+ return [ ] ;
291
+ }
292
+
293
+
294
+ public searchTermsByTermId ( searchText : string , termId : string ) : Promise < IPickerTerm [ ] > {
295
+ if ( Environment . type === EnvironmentType . Local ) {
296
+ // If the running environment is local, load the data from the mock
297
+ return SPTermStoreMockHttpClient . searchTermsByName ( searchText ) ;
298
+ } else {
299
+ return new Promise < IPickerTerm [ ] > ( resolve => {
300
+ var childTerms = this . getTermsById ( termId ) ;
301
+ if ( childTerms ) {
302
+ resolve ( this . searchTermsBySearchText ( childTerms , searchText ) ) ;
303
+ }
304
+ else {
305
+ let data = '<Request xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="Javascript Library"><Actions><ObjectPath Id="1" ObjectPathId="0" /><ObjectIdentityQuery Id="2" ObjectPathId="0" /><ObjectPath Id="4" ObjectPathId="3" /><ObjectIdentityQuery Id="5" ObjectPathId="3" /><ObjectPath Id="7" ObjectPathId="6" /><ObjectIdentityQuery Id="8" ObjectPathId="6" /><ObjectPath Id="10" ObjectPathId="9" /><Query Id="11" ObjectPathId="9"><Query SelectAllProperties="false"><Properties /></Query><ChildItemQuery SelectAllProperties="false"><Properties><Property Name="IsRoot" SelectAll="true" /><Property Name="Id" SelectAll="true" /><Property Name="Name" SelectAll="true" /><Property Name="PathOfTerm" SelectAll="true" /><Property Name="TermSet" SelectAll="true" /></Properties></ChildItemQuery></Query></Actions><ObjectPaths><StaticMethod Id="0" Name="GetTaxonomySession" TypeId="{981cbc68-9edc-4f8d-872f-71146fcbb84f}" /><Method Id="3" ParentId="0" Name="GetDefaultSiteCollectionTermStore" /><Method Id="6" ParentId="3" Name="GetTerm"><Parameters><Parameter Type="String">' + termId + '</Parameter></Parameters></Method><Property Id="9" ParentId="6" Name="Terms" /></ObjectPaths></Request>' ;
306
+
307
+ const reqHeaders = new Headers ( ) ;
308
+ reqHeaders . append ( "accept" , "application/json" ) ;
309
+ reqHeaders . append ( "content-type" , "application/xml" ) ;
310
+
311
+ const httpPostOptions : ISPHttpClientOptions = {
312
+ headers : reqHeaders ,
313
+ body : data
314
+ } ;
315
+
316
+ return this . context . spHttpClient . post ( this . clientServiceUrl , SPHttpClient . configurations . v1 , httpPostOptions ) . then ( ( serviceResponse : SPHttpClientResponse ) => {
317
+ return serviceResponse . json ( ) . then ( ( serviceJSONResponse : any ) => {
318
+ // Retrieve the term collection results
319
+ const termStoreResult : ITerms [ ] = serviceJSONResponse . filter ( ( r : { [ x : string ] : string ; } ) => r [ '_ObjectType_' ] === 'SP.Taxonomy.TermCollection' ) ;
320
+ if ( termStoreResult . length > 0 ) {
321
+ // Retrieve all terms
322
+
323
+ let terms = termStoreResult [ 0 ] . _Child_Items_ ;
324
+
325
+ let returnTerms : IPickerTerm [ ] = [ ] ;
326
+ terms . forEach ( term => {
327
+ returnTerms . push ( {
328
+ key : this . cleanGuid ( term . Id ) ,
329
+ name : term . Name ,
330
+ path : term . PathOfTerm ,
331
+ termSet : this . cleanGuid ( term . TermSet . Id ) ,
332
+ termSetName : term . TermSet . Name
333
+ } ) ;
334
+ } ) ;
335
+ sessionStorage . setItem ( termId , JSON . stringify ( returnTerms ) ) ;
336
+ resolve ( this . searchTermsBySearchText ( returnTerms , searchText ) ) ;
337
+ }
338
+ return null ;
339
+ } ) ;
340
+ } ) ;
341
+ }
342
+ } ) ;
343
+ }
344
+ }
345
+
276
346
/**
277
347
* Searches terms for the given term set
278
348
* @param searchText
0 commit comments