Initial commit
This commit is contained in:
10
lib/services/IMenuItem.d.ts
vendored
Normal file
10
lib/services/IMenuItem.d.ts
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
export interface IMenuItem {
|
||||
id: string;
|
||||
label: string;
|
||||
icon?: string;
|
||||
hoverText: string;
|
||||
url?: string;
|
||||
pathDepth: number;
|
||||
items?: IMenuItem[];
|
||||
hasChildren: () => boolean;
|
||||
}
|
||||
3
lib/services/IMenuItem.js
Normal file
3
lib/services/IMenuItem.js
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
//# sourceMappingURL=IMenuItem.js.map
|
||||
1
lib/services/IMenuItem.js.map
Normal file
1
lib/services/IMenuItem.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":[],"names":[],"mappings":"","file":"services/IMenuItem.js","sourcesContent":[],"sourceRoot":"..\\..\\src"}
|
||||
9
lib/services/IPickerTerm.d.ts
vendored
Normal file
9
lib/services/IPickerTerm.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
export interface IPickerTerm {
|
||||
name: string;
|
||||
key: string;
|
||||
path: string;
|
||||
termSet: string;
|
||||
termSetName?: string;
|
||||
}
|
||||
export interface IPickerTerms extends Array<IPickerTerm> {
|
||||
}
|
||||
3
lib/services/IPickerTerm.js
Normal file
3
lib/services/IPickerTerm.js
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
//# sourceMappingURL=IPickerTerm.js.map
|
||||
1
lib/services/IPickerTerm.js.map
Normal file
1
lib/services/IPickerTerm.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":[],"names":[],"mappings":"","file":"services/IPickerTerm.js","sourcesContent":[],"sourceRoot":"..\\..\\src"}
|
||||
84
lib/services/ISPTermStorePickerService.d.ts
vendored
Normal file
84
lib/services/ISPTermStorePickerService.d.ts
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* Interfaces for Term store, groups and term sets
|
||||
* This code is a copy from the library @pnp/sp-dev-fx-controls-react
|
||||
*/
|
||||
export interface ITermStore {
|
||||
_ObjectType_: string;
|
||||
_ObjectIdentity_: string;
|
||||
Id: string;
|
||||
Name: string;
|
||||
Groups: IGroups;
|
||||
}
|
||||
export interface IGroups {
|
||||
_ObjectType_: string;
|
||||
_Child_Items_: IGroup[];
|
||||
}
|
||||
export interface IGroup {
|
||||
_ObjectType_: string;
|
||||
_ObjectIdentity_: string;
|
||||
TermSets: ITermSets;
|
||||
Id: string;
|
||||
Name: string;
|
||||
IsSystemGroup: boolean;
|
||||
}
|
||||
export interface ITermSets {
|
||||
_ObjectType_: string;
|
||||
_Child_Items_: ITermSet[];
|
||||
}
|
||||
export interface ITermSet {
|
||||
_ObjectType_: string;
|
||||
_ObjectIdentity_: string;
|
||||
Id: string;
|
||||
CustomSortOrder?: string;
|
||||
Name: string;
|
||||
Description: string;
|
||||
Names: ITermSetNames;
|
||||
Terms?: ITerm[];
|
||||
}
|
||||
export interface ITermSetMinimal {
|
||||
_ObjectType_?: string;
|
||||
_ObjectIdentity_?: string;
|
||||
Id: string;
|
||||
Name: string;
|
||||
}
|
||||
export interface ITermSetNames {
|
||||
[locale: string]: string;
|
||||
}
|
||||
/**
|
||||
* Interfaces for the terms
|
||||
*/
|
||||
export interface ITerms {
|
||||
_ObjectType_: string;
|
||||
_Child_Items_: ITerm[];
|
||||
}
|
||||
/**
|
||||
* Term
|
||||
*/
|
||||
export interface ITerm {
|
||||
_ObjectType_: string;
|
||||
_ObjectIdentity_: string;
|
||||
Id: string;
|
||||
Name: string;
|
||||
Description: string;
|
||||
IsDeprecated: boolean;
|
||||
IsAvailableForTagging: boolean;
|
||||
IsRoot: boolean;
|
||||
PathOfTerm: string;
|
||||
TermSet: ITermSetMinimal;
|
||||
CustomSortOrderIndex?: number;
|
||||
PathDepth?: number;
|
||||
ParentId?: string;
|
||||
TermsCount?: number;
|
||||
LocalCustomProperties?: {
|
||||
[property: string]: any;
|
||||
};
|
||||
}
|
||||
export interface ISuggestTerm {
|
||||
Id: string;
|
||||
DefaultLabel: string;
|
||||
Description: string;
|
||||
IsKeyword: boolean;
|
||||
IsSynonym: boolean;
|
||||
Paths: Array<string>;
|
||||
Synonyms: string;
|
||||
}
|
||||
3
lib/services/ISPTermStorePickerService.js
Normal file
3
lib/services/ISPTermStorePickerService.js
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
//# sourceMappingURL=ISPTermStorePickerService.js.map
|
||||
1
lib/services/ISPTermStorePickerService.js.map
Normal file
1
lib/services/ISPTermStorePickerService.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":[],"names":[],"mappings":"","file":"services/ISPTermStorePickerService.js","sourcesContent":[],"sourceRoot":"..\\..\\src"}
|
||||
7
lib/services/ISPTermStorePickerServiceProps.d.ts
vendored
Normal file
7
lib/services/ISPTermStorePickerServiceProps.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
export interface ISPTermStorePickerServiceProps {
|
||||
termsetNameOrID: string;
|
||||
useSessionStorage: boolean;
|
||||
hideDeprecatedTags: boolean;
|
||||
hideTagsNotAvailableForTagging: boolean;
|
||||
anchorId: string;
|
||||
}
|
||||
3
lib/services/ISPTermStorePickerServiceProps.js
Normal file
3
lib/services/ISPTermStorePickerServiceProps.js
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
//# sourceMappingURL=ISPTermStorePickerServiceProps.js.map
|
||||
1
lib/services/ISPTermStorePickerServiceProps.js.map
Normal file
1
lib/services/ISPTermStorePickerServiceProps.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":[],"names":[],"mappings":"","file":"services/ISPTermStorePickerServiceProps.js","sourcesContent":[],"sourceRoot":"..\\..\\src"}
|
||||
4
lib/services/ITaxonomyNavigationService.d.ts
vendored
Normal file
4
lib/services/ITaxonomyNavigationService.d.ts
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import { IMenuItem } from './IMenuItem';
|
||||
export interface ITaxonomyNavigationService {
|
||||
getMenuItems(): Promise<IMenuItem[]>;
|
||||
}
|
||||
3
lib/services/ITaxonomyNavigationService.js
Normal file
3
lib/services/ITaxonomyNavigationService.js
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
//# sourceMappingURL=ITaxonomyNavigationService.js.map
|
||||
1
lib/services/ITaxonomyNavigationService.js.map
Normal file
1
lib/services/ITaxonomyNavigationService.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":[],"names":[],"mappings":"","file":"services/ITaxonomyNavigationService.js","sourcesContent":[],"sourceRoot":"..\\..\\src"}
|
||||
4
lib/services/ItemDictionary.d.ts
vendored
Normal file
4
lib/services/ItemDictionary.d.ts
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export declare class ItemDictionary<T> {
|
||||
Get(key: string): T;
|
||||
Add(key: string, value: T): void;
|
||||
}
|
||||
14
lib/services/ItemDictionary.js
Normal file
14
lib/services/ItemDictionary.js
Normal file
@@ -0,0 +1,14 @@
|
||||
var ItemDictionary = (function () {
|
||||
function ItemDictionary() {
|
||||
}
|
||||
ItemDictionary.prototype.Get = function (key) {
|
||||
return this[key];
|
||||
};
|
||||
ItemDictionary.prototype.Add = function (key, value) {
|
||||
this[key] = value;
|
||||
};
|
||||
return ItemDictionary;
|
||||
}());
|
||||
export { ItemDictionary };
|
||||
|
||||
//# sourceMappingURL=ItemDictionary.js.map
|
||||
1
lib/services/ItemDictionary.js.map
Normal file
1
lib/services/ItemDictionary.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["services/ItemDictionary.ts"],"names":[],"mappings":"AAAA;IAAA;IAQA,CAAC;IAPU,4BAAG,GAAV,UAAW,GAAW;QAClB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;IAEM,4BAAG,GAAV,UAAW,GAAW,EAAE,KAAQ;QAC5B,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACtB,CAAC;IACL,qBAAC;AAAD,CARA,AAQC,IAAA","file":"services/ItemDictionary.js","sourcesContent":["export class ItemDictionary<T> {\r\n public Get(key: string): T {\r\n return this[key];\r\n }\r\n\r\n public Add(key: string, value: T): void {\r\n this[key] = value;\r\n }\r\n}\r\n"],"sourceRoot":"..\\..\\src"}
|
||||
14
lib/services/MenuItem.d.ts
vendored
Normal file
14
lib/services/MenuItem.d.ts
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import { IMenuItem } from './IMenuItem';
|
||||
import { ITerm } from './ISPTermStorePickerService';
|
||||
export declare class MenuItem implements IMenuItem {
|
||||
level: number;
|
||||
id: string;
|
||||
label: string;
|
||||
hoverText: string;
|
||||
pathDepth: number;
|
||||
url?: string;
|
||||
items?: IMenuItem[];
|
||||
constructor(term: ITerm, level: number, siteCollectionUrl?: string);
|
||||
hasChildren(): boolean;
|
||||
command(): void;
|
||||
}
|
||||
29
lib/services/MenuItem.js
Normal file
29
lib/services/MenuItem.js
Normal file
@@ -0,0 +1,29 @@
|
||||
// tslint:disable:no-any no-string-literal max-line-length
|
||||
var MenuItem = (function () {
|
||||
function MenuItem(term, level, siteCollectionUrl) {
|
||||
this.level = level;
|
||||
this.id = term.Id;
|
||||
this.label = term.Name;
|
||||
this.hoverText = term.LocalCustomProperties['_Sys_Nav_HoverText'];
|
||||
this.pathDepth = term.PathDepth;
|
||||
var rawUrl = term.LocalCustomProperties['_Sys_Nav_SimpleLinkUrl'] || term.LocalCustomProperties['_Sys_Nav_TargetUrl'];
|
||||
if (rawUrl) {
|
||||
this.url = siteCollectionUrl && rawUrl.indexOf('~sitecollection') === 0
|
||||
? siteCollectionUrl + rawUrl.substring('~sitecollection'.length)
|
||||
: rawUrl;
|
||||
}
|
||||
this.items = [];
|
||||
}
|
||||
MenuItem.prototype.hasChildren = function () {
|
||||
return this.items && this.items.length > 0;
|
||||
};
|
||||
MenuItem.prototype.command = function () {
|
||||
if (this.url) {
|
||||
window.location.href = this.url;
|
||||
}
|
||||
};
|
||||
return MenuItem;
|
||||
}());
|
||||
export { MenuItem };
|
||||
|
||||
//# sourceMappingURL=MenuItem.js.map
|
||||
1
lib/services/MenuItem.js.map
Normal file
1
lib/services/MenuItem.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["services/MenuItem.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAK1D;IAQI,kBAAY,IAAW,EAAS,KAAa,EAAE,iBAA0B;QAAzC,UAAK,GAAL,KAAK,CAAQ;QACzC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QAClB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,qBAAqB,CAAC,oBAAoB,CAAC,CAAC;QAClE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAChC,IAAM,MAAM,GAAW,IAAI,CAAC,qBAAqB,CAAC,wBAAwB,CAAC,IAAI,IAAI,CAAC,qBAAqB,CAAC,oBAAoB,CAAC,CAAC;QAChI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;YACT,IAAI,CAAC,GAAG,GAAG,iBAAiB,IAAI,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC;kBACjE,iBAAiB,GAAG,MAAM,CAAC,SAAS,CAAC,iBAAiB,CAAC,MAAM,CAAC;kBAC9D,MAAM,CAAC;QACjB,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IACpB,CAAC;IAEM,8BAAW,GAAlB;QACI,MAAM,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;IAC/C,CAAC;IAEM,0BAAO,GAAd;QACI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YACV,MAAc,CAAC,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC;QAC7C,CAAC;IACL,CAAC;IACL,eAAC;AAAD,CA/BA,AA+BC,IAAA","file":"services/MenuItem.js","sourcesContent":["// tslint:disable:no-any no-string-literal max-line-length\r\n\r\nimport { IMenuItem } from './IMenuItem';\r\nimport { ITerm } from './ISPTermStorePickerService';\r\n\r\nexport class MenuItem implements IMenuItem {\r\n public id: string;\r\n public label: string;\r\n public hoverText: string;\r\n public pathDepth: number;\r\n public url?: string;\r\n public items?: IMenuItem[];\r\n\r\n constructor(term: ITerm, public level: number, siteCollectionUrl?: string) {\r\n this.id = term.Id;\r\n this.label = term.Name;\r\n this.hoverText = term.LocalCustomProperties['_Sys_Nav_HoverText'];\r\n this.pathDepth = term.PathDepth;\r\n const rawUrl: string = term.LocalCustomProperties['_Sys_Nav_SimpleLinkUrl'] || term.LocalCustomProperties['_Sys_Nav_TargetUrl'];\r\n if (rawUrl) {\r\n this.url = siteCollectionUrl && rawUrl.indexOf('~sitecollection') === 0\r\n ? siteCollectionUrl + rawUrl.substring('~sitecollection'.length)\r\n : rawUrl;\r\n }\r\n this.items = [];\r\n }\r\n\r\n public hasChildren(): boolean {\r\n return this.items && this.items.length > 0;\r\n }\r\n\r\n public command(): void {\r\n if (this.url) {\r\n (window as any).location.href = this.url;\r\n }\r\n }\r\n}\r\n"],"sourceRoot":"..\\..\\src"}
|
||||
5
lib/services/MockTaxonomyNavigationService.d.ts
vendored
Normal file
5
lib/services/MockTaxonomyNavigationService.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { IMenuItem } from './IMenuItem';
|
||||
import { ITaxonomyNavigationService } from './ITaxonomyNavigationService';
|
||||
export default class MockTaxonomyNavigationService implements ITaxonomyNavigationService {
|
||||
getMenuItems(): Promise<IMenuItem[]>;
|
||||
}
|
||||
109
lib/services/MockTaxonomyNavigationService.js
Normal file
109
lib/services/MockTaxonomyNavigationService.js
Normal file
@@ -0,0 +1,109 @@
|
||||
import * as uuid from 'uuid';
|
||||
var MockTaxonomyNavigationService = (function () {
|
||||
function MockTaxonomyNavigationService() {
|
||||
}
|
||||
MockTaxonomyNavigationService.prototype.getMenuItems = function () {
|
||||
return new Promise(function (resolve) {
|
||||
resolve([
|
||||
{
|
||||
id: uuid.v4(),
|
||||
label: 'Menu Item 1',
|
||||
url: 'https://www.bing.com',
|
||||
hoverText: 'Hover me!',
|
||||
pathDepth: 1,
|
||||
hasChildren: function () { return true; },
|
||||
items: [
|
||||
{
|
||||
id: uuid.v4(),
|
||||
label: 'Submenu Item 1',
|
||||
hoverText: 'Huch!',
|
||||
url: 'https://www.bing.com',
|
||||
pathDepth: 2,
|
||||
hasChildren: function () { return false; }
|
||||
},
|
||||
{
|
||||
id: uuid.v4(),
|
||||
label: 'Submenu Item 2',
|
||||
hoverText: 'Huch!',
|
||||
url: 'https://www.bing.com',
|
||||
pathDepth: 2,
|
||||
hasChildren: function () { return false; }
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
id: uuid.v4(),
|
||||
label: 'Menu Item 2',
|
||||
hoverText: 'Huch!',
|
||||
url: 'https://www.bing.com',
|
||||
pathDepth: 1,
|
||||
hasChildren: function () { return false; }
|
||||
},
|
||||
{
|
||||
id: uuid.v4(),
|
||||
label: 'Menu Item 3',
|
||||
hoverText: 'Huch!',
|
||||
url: 'https://www.bing.com',
|
||||
pathDepth: 1,
|
||||
hasChildren: function () { return true; },
|
||||
items: [
|
||||
{
|
||||
id: uuid.v4(),
|
||||
label: 'Submenu Item 1',
|
||||
hoverText: 'Huch!',
|
||||
url: 'https://www.bing.com',
|
||||
pathDepth: 2,
|
||||
hasChildren: function () { return false; }
|
||||
},
|
||||
{
|
||||
id: uuid.v4(),
|
||||
label: 'Submenu Item 2',
|
||||
hoverText: 'Huch!',
|
||||
url: 'https://www.bing.com',
|
||||
pathDepth: 2,
|
||||
hasChildren: function () { return true; },
|
||||
items: [
|
||||
{
|
||||
id: uuid.v4(),
|
||||
label: 'Submenu Item 1',
|
||||
hoverText: 'Huch!',
|
||||
url: 'https://www.bing.com',
|
||||
pathDepth: 3,
|
||||
hasChildren: function () { return false; }
|
||||
},
|
||||
{
|
||||
id: uuid.v4(),
|
||||
label: 'Submenu Item 2',
|
||||
hoverText: 'Huch!',
|
||||
url: 'https://www.bing.com',
|
||||
pathDepth: 3,
|
||||
hasChildren: function () { return false; }
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
id: uuid.v4(),
|
||||
label: 'Submenu Item 3',
|
||||
hoverText: 'Huch!',
|
||||
url: 'https://www.bing.com',
|
||||
pathDepth: 2,
|
||||
hasChildren: function () { return false; }
|
||||
},
|
||||
{
|
||||
id: uuid.v4(),
|
||||
label: 'Submenu Item 4',
|
||||
hoverText: 'Huch!',
|
||||
url: 'https://www.bing.com',
|
||||
pathDepth: 2,
|
||||
hasChildren: function () { return false; }
|
||||
}
|
||||
]
|
||||
}
|
||||
]);
|
||||
});
|
||||
};
|
||||
return MockTaxonomyNavigationService;
|
||||
}());
|
||||
export default MockTaxonomyNavigationService;
|
||||
|
||||
//# sourceMappingURL=MockTaxonomyNavigationService.js.map
|
||||
1
lib/services/MockTaxonomyNavigationService.js.map
Normal file
1
lib/services/MockTaxonomyNavigationService.js.map
Normal file
File diff suppressed because one or more lines are too long
76
lib/services/SPTermStorePickerService.d.ts
vendored
Normal file
76
lib/services/SPTermStorePickerService.d.ts
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
import { ITermStore, ITermSet } from './ISPTermStorePickerService';
|
||||
import { ISPTermStorePickerServiceProps } from './ISPTermStorePickerServiceProps';
|
||||
import { IPickerTerm } from './IPickerTerm';
|
||||
import { ApplicationCustomizerContext } from '@microsoft/sp-application-base';
|
||||
/**
|
||||
* Service implementation to manage term stores in SharePoint
|
||||
*/
|
||||
export default class SPTermStorePickerService {
|
||||
private props;
|
||||
private context;
|
||||
private clientServiceUrl;
|
||||
private suggestionServiceUrl;
|
||||
/**
|
||||
* Service constructor
|
||||
*/
|
||||
constructor(props: ISPTermStorePickerServiceProps, context: ApplicationCustomizerContext);
|
||||
getTermLabels(termId: string): Promise<string[]>;
|
||||
/**
|
||||
* Gets the collection of term stores in the current SharePoint env
|
||||
*/
|
||||
getTermStores(): Promise<ITermStore[]>;
|
||||
/**
|
||||
* Gets the current term set
|
||||
*/
|
||||
getTermSet(): Promise<ITermSet>;
|
||||
/**
|
||||
* Retrieve all terms for the given term set
|
||||
* @param termset
|
||||
*/
|
||||
getAllTerms(termset: string, hideDeprecatedTags?: boolean, hideTagsNotAvailableForTagging?: boolean, useSessionStorage?: boolean): Promise<ITermSet>;
|
||||
/**
|
||||
* Retrieve all terms that starts with the searchText
|
||||
* @param searchText
|
||||
*/
|
||||
searchTermsByName(searchText: string): Promise<IPickerTerm[]>;
|
||||
searchTermsByTermId(searchText: string, termId: string): Promise<IPickerTerm[]>;
|
||||
/**
|
||||
* Retrieve all terms for the given term set and anchorId
|
||||
*/
|
||||
getAllTermsByAnchorId(termsetNameOrID: string, anchorId: string, hideDeprecatedTags?: boolean, hideTagsNotAvailableForTagging?: boolean, useSessionStorage?: boolean): Promise<IPickerTerm[]>;
|
||||
/**
|
||||
* Clean the Guid from the Web Service response
|
||||
* @param guid
|
||||
*/
|
||||
cleanGuid(guid: string): string;
|
||||
/**
|
||||
* Get the term set ID by its name
|
||||
* @param termstore
|
||||
* @param termset
|
||||
*/
|
||||
private getTermSetId(termstore, termsetName);
|
||||
private getTermsById(termId, useSessionStorage?);
|
||||
private searchTermsBySearchText(terms, searchText);
|
||||
/**
|
||||
* Searches terms for the given term set
|
||||
* @param searchText
|
||||
* @param termsetId
|
||||
*/
|
||||
private searchTermsByTermSet(searchText);
|
||||
private isGuid(strGuid);
|
||||
/**
|
||||
* Sorting terms based on their path and depth
|
||||
*
|
||||
* @param terms
|
||||
*/
|
||||
private sortTerms(terms);
|
||||
/**
|
||||
* Sort the terms by their path
|
||||
*
|
||||
* @param a term 2
|
||||
* @param b term 2
|
||||
*/
|
||||
private sortTermByPath(a, b);
|
||||
private convertTermToPickerTerm(term);
|
||||
private convertSuggestTermToPickerTerm(term);
|
||||
}
|
||||
574
lib/services/SPTermStorePickerService.js
Normal file
574
lib/services/SPTermStorePickerService.js
Normal file
@@ -0,0 +1,574 @@
|
||||
/* tslint:disable:no-null-keyword max-line-length typedef no-any no-string-literal variable-name */
|
||||
/**
|
||||
* This code is a copy from the library @pnp/sp-dev-fx-controls-react
|
||||
*/
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [0, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
import { SPHttpClient } from '@microsoft/sp-http';
|
||||
import { findIndex } from '@microsoft/sp-lodash-subset';
|
||||
var EmptyGuid = '00000000-0000-0000-0000-000000000000';
|
||||
/**
|
||||
* Service implementation to manage term stores in SharePoint
|
||||
*/
|
||||
var SPTermStorePickerService = (function () {
|
||||
/**
|
||||
* Service constructor
|
||||
*/
|
||||
function SPTermStorePickerService(props, context) {
|
||||
this.props = props;
|
||||
this.context = context;
|
||||
this.clientServiceUrl = this.context.pageContext.web.absoluteUrl + '/_vti_bin/client.svc/ProcessQuery';
|
||||
this.suggestionServiceUrl = this.context.pageContext.web.absoluteUrl + '/_vti_bin/TaxonomyInternalService.json/GetSuggestions';
|
||||
}
|
||||
SPTermStorePickerService.prototype.getTermLabels = function (termId) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var result, data, reqHeaders, httpPostOptions, callResult, jsonResult, node, error_1;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
result = null;
|
||||
_a.label = 1;
|
||||
case 1:
|
||||
_a.trys.push([1, 4, , 5]);
|
||||
data = "<Request AddExpandoFieldTypeSuffix=\"true\" SchemaVersion=\"15.0.0.0\" LibraryVersion=\"16.0.0.0\" ApplicationName=\".NET Library\" xmlns=\"http://schemas.microsoft.com/sharepoint/clientquery/2009\"><Actions><ObjectPath Id=\"8\" ObjectPathId=\"7\" /><ObjectIdentityQuery Id=\"9\" ObjectPathId=\"7\" /><ObjectPath Id=\"11\" ObjectPathId=\"10\" /><ObjectIdentityQuery Id=\"12\" ObjectPathId=\"10\" /><ObjectPath Id=\"14\" ObjectPathId=\"13\" /><ObjectIdentityQuery Id=\"15\" ObjectPathId=\"13\" /><Query Id=\"16\" ObjectPathId=\"13\"><Query SelectAllProperties=\"false\"><Properties><Property Name=\"Labels\" SelectAll=\"true\"><Query SelectAllProperties=\"false\"><Properties /></Query></Property></Properties></Query></Query></Actions><ObjectPaths><StaticMethod Id=\"7\" Name=\"GetTaxonomySession\" TypeId=\"{981cbc68-9edc-4f8d-872f-71146fcbb84f}\" /><Method Id=\"10\" ParentId=\"7\" Name=\"GetDefaultKeywordsTermStore\" /><Method Id=\"13\" ParentId=\"10\" Name=\"GetTerm\"><Parameters><Parameter Type=\"Guid\">" + termId + "</Parameter></Parameters></Method></ObjectPaths></Request>";
|
||||
reqHeaders = new Headers();
|
||||
reqHeaders.append('accept', 'application/json');
|
||||
reqHeaders.append('content-type', 'application/xml');
|
||||
httpPostOptions = {
|
||||
headers: reqHeaders,
|
||||
body: data
|
||||
};
|
||||
return [4 /*yield*/, this.context.spHttpClient.post(this.clientServiceUrl, SPHttpClient.configurations.v1, httpPostOptions)];
|
||||
case 2:
|
||||
callResult = _a.sent();
|
||||
return [4 /*yield*/, callResult.json()];
|
||||
case 3:
|
||||
jsonResult = _a.sent();
|
||||
node = jsonResult.find(function (x) { return x._ObjectType_ === 'SP.Taxonomy.Term'; });
|
||||
if (node && node.Labels && node.Labels._Child_Items_) {
|
||||
result = node.Labels._Child_Items_.map(function (termLabel) { return termLabel.Value; });
|
||||
}
|
||||
return [3 /*break*/, 5];
|
||||
case 4:
|
||||
error_1 = _a.sent();
|
||||
result = null;
|
||||
console.log(error_1.message);
|
||||
return [3 /*break*/, 5];
|
||||
case 5: return [2 /*return*/, result];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Gets the collection of term stores in the current SharePoint env
|
||||
*/
|
||||
SPTermStorePickerService.prototype.getTermStores = function () {
|
||||
var _this = this;
|
||||
// Retrieve the term store name, groups, and term sets
|
||||
var data = '<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName=".NET Library" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009"><Actions><ObjectPath Id="2" ObjectPathId="1" /><ObjectIdentityQuery Id="3" ObjectPathId="1" /><ObjectPath Id="5" ObjectPathId="4" /><ObjectIdentityQuery Id="6" ObjectPathId="4" /><Query Id="7" ObjectPathId="4"><Query SelectAllProperties="false"><Properties><Property Name="Id" ScalarProperty="true" /><Property Name="Name" ScalarProperty="true" /><Property Name="Groups"><Query SelectAllProperties="false"><Properties /></Query><ChildItemQuery SelectAllProperties="false"><Properties><Property Name="Name" ScalarProperty="true" /><Property Name="Id" ScalarProperty="true" /><Property Name="IsSystemGroup" ScalarProperty="true" /><Property Name="TermSets"><Query SelectAllProperties="false"><Properties /></Query><ChildItemQuery SelectAllProperties="false"><Properties><Property Name="Name" ScalarProperty="true" /><Property Name="Id" ScalarProperty="true" /><Property Name="Description" ScalarProperty="true" /><Property Name="Names" ScalarProperty="true" /></Properties></ChildItemQuery></Property></Properties></ChildItemQuery></Property></Properties></Query></Query></Actions><ObjectPaths><StaticMethod Id="1" Name="GetTaxonomySession" TypeId="{981cbc68-9edc-4f8d-872f-71146fcbb84f}" /><Method Id="4" ParentId="1" Name="GetDefaultSiteCollectionTermStore" /></ObjectPaths></Request>';
|
||||
var reqHeaders = new Headers();
|
||||
reqHeaders.append('accept', 'application/json');
|
||||
reqHeaders.append('content-type', 'application/xml');
|
||||
var httpPostOptions = {
|
||||
headers: reqHeaders,
|
||||
body: data
|
||||
};
|
||||
return this.context.spHttpClient.post(this.clientServiceUrl, SPHttpClient.configurations.v1, httpPostOptions).then(function (serviceResponse) {
|
||||
return serviceResponse.json().then(function (serviceJSONResponse) {
|
||||
// Construct results
|
||||
var termStoreResult = serviceJSONResponse.filter(function (r) { return r['_ObjectType_'] === 'SP.Taxonomy.TermStore'; });
|
||||
// Check if term store was retrieved
|
||||
if (termStoreResult.length > 0) {
|
||||
// Check if the termstore needs to be filtered or limited
|
||||
if (_this.props.termsetNameOrID) {
|
||||
return termStoreResult.map(function (termstore) {
|
||||
var termGroups = termstore.Groups._Child_Items_;
|
||||
// Check if the groups have to be limited to a specific term set
|
||||
if (_this.props.termsetNameOrID) {
|
||||
var termsetNameOrId_1 = _this.props.termsetNameOrID;
|
||||
termGroups = termGroups.map(function (group) {
|
||||
group.TermSets._Child_Items_ = group.TermSets._Child_Items_.filter(function (termSet) { return termSet.Name === termsetNameOrId_1 || _this.cleanGuid(termSet.Id).toLowerCase() === _this.cleanGuid(termsetNameOrId_1).toLowerCase(); });
|
||||
return group;
|
||||
});
|
||||
}
|
||||
// Filter out all systen groups
|
||||
termGroups = termGroups.filter(function (group) { return !group.IsSystemGroup; });
|
||||
// Filter out empty groups
|
||||
termGroups = termGroups.filter(function (group) { return group.TermSets._Child_Items_.length > 0; });
|
||||
// Map the new groups
|
||||
termstore.Groups._Child_Items_ = termGroups;
|
||||
return termstore;
|
||||
});
|
||||
}
|
||||
// Return the term store results
|
||||
return termStoreResult;
|
||||
}
|
||||
return [];
|
||||
});
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Gets the current term set
|
||||
*/
|
||||
SPTermStorePickerService.prototype.getTermSet = function () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var termStore;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, this.getTermStores()];
|
||||
case 1:
|
||||
termStore = _a.sent();
|
||||
return [2 /*return*/, this.getTermSetId(termStore, this.props.termsetNameOrID)];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Retrieve all terms for the given term set
|
||||
* @param termset
|
||||
*/
|
||||
SPTermStorePickerService.prototype.getAllTerms = function (termset, hideDeprecatedTags, hideTagsNotAvailableForTagging, useSessionStorage) {
|
||||
if (useSessionStorage === void 0) { useSessionStorage = true; }
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var _this = this;
|
||||
var termsetId, termStore, crntTermSet, childTerms, data, reqHeaders, httpPostOptions;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
termsetId = termset;
|
||||
if (!!this.isGuid(termset)) return [3 /*break*/, 2];
|
||||
return [4 /*yield*/, this.getTermStores()];
|
||||
case 1:
|
||||
termStore = _a.sent();
|
||||
crntTermSet = this.getTermSetId(termStore, termset);
|
||||
if (crntTermSet) {
|
||||
termsetId = this.cleanGuid(crntTermSet.Id);
|
||||
}
|
||||
else {
|
||||
return [2 /*return*/, null];
|
||||
}
|
||||
_a.label = 2;
|
||||
case 2:
|
||||
childTerms = this.getTermsById(termsetId, useSessionStorage);
|
||||
if (childTerms) {
|
||||
return [2 /*return*/, childTerms];
|
||||
}
|
||||
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=\"6\"><Query SelectAllProperties=\"true\"><Properties /></Query></Query><Query Id=\"12\" ObjectPathId=\"9\"><Query SelectAllProperties=\"false\"><Properties /></Query><ChildItemQuery SelectAllProperties=\"false\"><Properties><Property Name=\"IsRoot\" SelectAll=\"true\" /><Property Name=\"Labels\" SelectAll=\"true\" /><Property Name=\"TermsCount\" SelectAll=\"true\" /><Property Name=\"CustomSortOrder\" SelectAll=\"true\" /><Property Name=\"Id\" SelectAll=\"true\" /><Property Name=\"Name\" SelectAll=\"true\" /><Property Name=\"PathOfTerm\" SelectAll=\"true\" /><Property Name=\"Parent\" SelectAll=\"true\" /><Property Name=\"LocalCustomProperties\" SelectAll=\"true\" /><Property Name=\"IsDeprecated\" ScalarProperty=\"true\" /><Property Name=\"IsAvailableForTagging\" ScalarProperty=\"true\" /></Properties></ChildItemQuery></Query></Actions><ObjectPaths><StaticMethod Id=\"0\" Name=\"GetTaxonomySession\" TypeId=\"{981cbc68-9edc-4f8d-872f-71146fcbb84f}\" /><Method Id=\"3\" ParentId=\"0\" Name=\"GetDefaultKeywordsTermStore\" /><Method Id=\"6\" ParentId=\"3\" Name=\"GetTermSet\"><Parameters><Parameter Type=\"Guid\">" + termsetId + "</Parameter></Parameters></Method><Method Id=\"9\" ParentId=\"6\" Name=\"GetAllTerms\" /></ObjectPaths></Request>";
|
||||
reqHeaders = new Headers();
|
||||
reqHeaders.append('accept', 'application/json');
|
||||
reqHeaders.append('content-type', 'application/xml');
|
||||
httpPostOptions = {
|
||||
headers: reqHeaders,
|
||||
body: data
|
||||
};
|
||||
return [2 /*return*/, this.context.spHttpClient.post(this.clientServiceUrl, SPHttpClient.configurations.v1, httpPostOptions).then(function (serviceResponse) {
|
||||
return serviceResponse.json().then(function (serviceJSONResponse) {
|
||||
var termStoreResultTermSets = serviceJSONResponse.filter(function (r) { return r['_ObjectType_'] === 'SP.Taxonomy.TermSet'; });
|
||||
if (termStoreResultTermSets.length > 0) {
|
||||
var termStoreResultTermSet_1 = termStoreResultTermSets[0];
|
||||
termStoreResultTermSet_1.Terms = [];
|
||||
// Retrieve the term collection results
|
||||
var termStoreResultTerms = serviceJSONResponse.filter(function (r) { return r['_ObjectType_'] === 'SP.Taxonomy.TermCollection'; });
|
||||
if (termStoreResultTerms.length > 0) {
|
||||
// Retrieve all terms
|
||||
var terms = termStoreResultTerms[0]._Child_Items_;
|
||||
if (hideDeprecatedTags === true) {
|
||||
terms = terms.filter(function (d) { return d.IsDeprecated === false; });
|
||||
}
|
||||
if (hideTagsNotAvailableForTagging === true) {
|
||||
terms = terms.filter(function (d) { return d.IsAvailableForTagging === true; });
|
||||
}
|
||||
// Clean the term ID and specify the path depth
|
||||
terms = terms.map(function (term) {
|
||||
if (term.IsRoot) {
|
||||
term.CustomSortOrderIndex = (termStoreResultTermSet_1.CustomSortOrder) ? termStoreResultTermSet_1.CustomSortOrder.split(':').indexOf(_this.cleanGuid(term.Id)) : -1;
|
||||
}
|
||||
else {
|
||||
term.CustomSortOrderIndex = (term['Parent'].CustomSortOrder) ? term['Parent'].CustomSortOrder.split(':').indexOf(_this.cleanGuid(term.Id)) : -1;
|
||||
}
|
||||
term.Id = _this.cleanGuid(term.Id);
|
||||
term['PathDepth'] = term.PathOfTerm.split(';').length;
|
||||
term.TermSet = { Id: _this.cleanGuid(termStoreResultTermSet_1.Id), Name: termStoreResultTermSet_1.Name };
|
||||
if (term['Parent']) {
|
||||
term.ParentId = _this.cleanGuid(term['Parent'].Id);
|
||||
}
|
||||
return term;
|
||||
});
|
||||
// Check if the term set was not empty
|
||||
if (terms.length > 0) {
|
||||
// Sort the terms by PathOfTerm and their depth
|
||||
terms = _this.sortTerms(terms);
|
||||
termStoreResultTermSet_1.Terms = terms;
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (useSessionStorage && window.sessionStorage) {
|
||||
window.sessionStorage.setItem(termsetId, JSON.stringify(termStoreResultTermSet_1));
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
// Do nothing, sometimes "storage quota exceeded" error if too many items
|
||||
}
|
||||
return termStoreResultTermSet_1;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
})];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Retrieve all terms that starts with the searchText
|
||||
* @param searchText
|
||||
*/
|
||||
SPTermStorePickerService.prototype.searchTermsByName = function (searchText) {
|
||||
return this.searchTermsByTermSet(searchText);
|
||||
};
|
||||
SPTermStorePickerService.prototype.searchTermsByTermId = function (searchText, termId) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var useSessionStorage, childTerms, _a, termsetNameOrID, hideDeprecatedTags, hideTagsNotAvailableForTagging, terms;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
useSessionStorage = this.props.useSessionStorage;
|
||||
childTerms = this.getTermsById(termId, useSessionStorage);
|
||||
if (!childTerms) return [3 /*break*/, 1];
|
||||
return [2 /*return*/, this.searchTermsBySearchText(childTerms, searchText)];
|
||||
case 1:
|
||||
_a = this.props, termsetNameOrID = _a.termsetNameOrID, hideDeprecatedTags = _a.hideDeprecatedTags, hideTagsNotAvailableForTagging = _a.hideTagsNotAvailableForTagging;
|
||||
return [4 /*yield*/, this.getAllTermsByAnchorId(termsetNameOrID, termId, hideDeprecatedTags, hideTagsNotAvailableForTagging, useSessionStorage)];
|
||||
case 2:
|
||||
terms = _b.sent();
|
||||
if (terms) {
|
||||
return [2 /*return*/, this.searchTermsBySearchText(terms, searchText)];
|
||||
}
|
||||
_b.label = 3;
|
||||
case 3: return [2 /*return*/, null];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Retrieve all terms for the given term set and anchorId
|
||||
*/
|
||||
SPTermStorePickerService.prototype.getAllTermsByAnchorId = function (termsetNameOrID, anchorId, hideDeprecatedTags, hideTagsNotAvailableForTagging, useSessionStorage) {
|
||||
if (useSessionStorage === void 0) { useSessionStorage = true; }
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var _this = this;
|
||||
var returnTerms, childTerms, termSet, terms, anchorTerm_1, anchorTermPath_1, anchorTerms;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
returnTerms = [];
|
||||
childTerms = this.getTermsById(anchorId, useSessionStorage);
|
||||
if (childTerms) {
|
||||
return [2 /*return*/, childTerms];
|
||||
}
|
||||
return [4 /*yield*/, this.getAllTerms(termsetNameOrID, hideDeprecatedTags, hideTagsNotAvailableForTagging)];
|
||||
case 1:
|
||||
termSet = _a.sent();
|
||||
terms = termSet.Terms;
|
||||
if (anchorId) {
|
||||
anchorTerm_1 = terms.filter(function (t) { return t.Id.toLowerCase() === anchorId.toLowerCase(); }).shift();
|
||||
if (anchorTerm_1) {
|
||||
anchorTermPath_1 = anchorTerm_1.PathOfTerm + ";";
|
||||
anchorTerms = terms.filter(function (t) { return t.PathOfTerm.substring(0, anchorTermPath_1.length) === anchorTermPath_1 && t.Id !== anchorTerm_1.Id; });
|
||||
anchorTerms.forEach(function (term) {
|
||||
returnTerms.push(_this.convertTermToPickerTerm(term));
|
||||
});
|
||||
try {
|
||||
if (useSessionStorage && window.sessionStorage) {
|
||||
window.sessionStorage.setItem(anchorId, JSON.stringify(returnTerms));
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
terms.forEach(function (term) {
|
||||
returnTerms.push(_this.convertTermToPickerTerm(term));
|
||||
});
|
||||
}
|
||||
return [2 /*return*/, returnTerms];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Clean the Guid from the Web Service response
|
||||
* @param guid
|
||||
*/
|
||||
SPTermStorePickerService.prototype.cleanGuid = function (guid) {
|
||||
if (guid !== undefined) {
|
||||
return guid.replace('/Guid(', '').replace('/', '').replace(')', '');
|
||||
}
|
||||
else {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Get the term set ID by its name
|
||||
* @param termstore
|
||||
* @param termset
|
||||
*/
|
||||
SPTermStorePickerService.prototype.getTermSetId = function (termstore, termsetName) {
|
||||
if (termstore && termstore.length > 0 && termsetName) {
|
||||
// Get the first term store
|
||||
var ts = termstore[0];
|
||||
// Check if the term store contains groups
|
||||
if (ts.Groups && ts.Groups._Child_Items_) {
|
||||
for (var _i = 0, _a = ts.Groups._Child_Items_; _i < _a.length; _i++) {
|
||||
var group = _a[_i];
|
||||
// Check if the group contains term sets
|
||||
if (group.TermSets && group.TermSets._Child_Items_) {
|
||||
for (var _b = 0, _c = group.TermSets._Child_Items_; _b < _c.length; _b++) {
|
||||
var termSet = _c[_b];
|
||||
// Check if the term set is found
|
||||
if (termSet.Name === termsetName) {
|
||||
return termSet;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
SPTermStorePickerService.prototype.getTermsById = function (termId, useSessionStorage) {
|
||||
if (useSessionStorage === void 0) { useSessionStorage = true; }
|
||||
try {
|
||||
if (useSessionStorage && window.sessionStorage) {
|
||||
var terms = window.sessionStorage.getItem(termId);
|
||||
if (terms) {
|
||||
return JSON.parse(terms);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
SPTermStorePickerService.prototype.searchTermsBySearchText = function (terms, searchText) {
|
||||
if (terms) {
|
||||
return terms.filter(function (t) { return t.name.toLowerCase().indexOf(searchText.toLowerCase()) > -1; });
|
||||
}
|
||||
else {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Searches terms for the given term set
|
||||
* @param searchText
|
||||
* @param termsetId
|
||||
*/
|
||||
SPTermStorePickerService.prototype.searchTermsByTermSet = function (searchText) {
|
||||
var _this = this;
|
||||
return new Promise(function (resolve) {
|
||||
_this.getTermStores().then(function (termStore) {
|
||||
var termSetId = _this.props.termsetNameOrID;
|
||||
if (!_this.isGuid(termSetId)) {
|
||||
// Get the ID of the provided term set name
|
||||
var crntTermSet = _this.getTermSetId(termStore, termSetId);
|
||||
if (crntTermSet) {
|
||||
termSetId = _this.cleanGuid(crntTermSet.Id);
|
||||
}
|
||||
else {
|
||||
resolve(null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (termStore === undefined || termStore.length === 0) {
|
||||
resolve(null);
|
||||
return;
|
||||
}
|
||||
var loc = _this.context.pageContext.cultureInfo.currentUICultureName === 'de-de' ? 1031 : 1033;
|
||||
var data = {
|
||||
start: searchText,
|
||||
lcid: loc !== 0 ? loc : _this.context.pageContext.web.language,
|
||||
sspList: _this.cleanGuid(termStore[0].Id),
|
||||
termSetList: termSetId,
|
||||
anchorId: _this.props.anchorId ? _this.props.anchorId : EmptyGuid,
|
||||
isSpanTermStores: false,
|
||||
isSpanTermSets: false,
|
||||
isIncludeUnavailable: _this.props.hideTagsNotAvailableForTagging === true,
|
||||
isIncludeDeprecated: _this.props.hideDeprecatedTags === true,
|
||||
isAddTerms: false,
|
||||
isIncludePathData: false,
|
||||
excludeKeyword: false,
|
||||
excludedTermset: EmptyGuid
|
||||
};
|
||||
var reqHeaders = new Headers();
|
||||
reqHeaders.append('accept', 'application/json');
|
||||
reqHeaders.append('content-type', 'application/json');
|
||||
var httpPostOptions = {
|
||||
headers: reqHeaders,
|
||||
body: JSON.stringify(data)
|
||||
};
|
||||
return _this.context.spHttpClient.post(_this.suggestionServiceUrl, SPHttpClient.configurations.v1, httpPostOptions).then(function (serviceResponse) {
|
||||
return serviceResponse.json().then(function (serviceJSONResponse) {
|
||||
var groups = serviceJSONResponse.d.Groups;
|
||||
if (groups && groups.length > 0) {
|
||||
// Retrieve the term collection results
|
||||
var terms = groups[0].Suggestions;
|
||||
if (terms.length > 0) {
|
||||
// Retrieve all terms
|
||||
var returnTerms = terms.map(function (term) { return _this.convertSuggestTermToPickerTerm(term); });
|
||||
resolve(returnTerms);
|
||||
return;
|
||||
}
|
||||
}
|
||||
resolve([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
SPTermStorePickerService.prototype.isGuid = function (strGuid) {
|
||||
return /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(strGuid);
|
||||
};
|
||||
/**
|
||||
* Sorting terms based on their path and depth
|
||||
*
|
||||
* @param terms
|
||||
*/
|
||||
SPTermStorePickerService.prototype.sortTerms = function (terms) {
|
||||
// Start sorting by depth
|
||||
var newTermsOrder = [];
|
||||
var itemsToSort = true;
|
||||
var pathLevel = 1;
|
||||
while (itemsToSort) {
|
||||
// Get terms for the current level
|
||||
var crntTerms = terms.filter(function (term) { return term.PathDepth === pathLevel; });
|
||||
if (crntTerms && crntTerms.length > 0) {
|
||||
crntTerms = crntTerms.sort(this.sortTermByPath);
|
||||
if (pathLevel !== 1) {
|
||||
crntTerms = crntTerms.reverse();
|
||||
var _loop_1 = function (crntTerm) {
|
||||
var pathElms = crntTerm.PathOfTerm.split(';');
|
||||
// Last item is not needed for parent path
|
||||
pathElms.pop();
|
||||
// Find the parent item and add the new item
|
||||
var idx = findIndex(newTermsOrder, function (term) { return term.PathOfTerm === pathElms.join(';'); });
|
||||
if (idx !== -1) {
|
||||
newTermsOrder.splice(idx + 1, 0, crntTerm);
|
||||
}
|
||||
else {
|
||||
// Push the item at the end if the parent couldn't be found
|
||||
newTermsOrder.push(crntTerm);
|
||||
}
|
||||
};
|
||||
for (var _i = 0, crntTerms_1 = crntTerms; _i < crntTerms_1.length; _i++) {
|
||||
var crntTerm = crntTerms_1[_i];
|
||||
_loop_1(crntTerm);
|
||||
}
|
||||
}
|
||||
else {
|
||||
newTermsOrder = crntTerms;
|
||||
}
|
||||
++pathLevel;
|
||||
}
|
||||
else {
|
||||
itemsToSort = false;
|
||||
}
|
||||
}
|
||||
return newTermsOrder;
|
||||
};
|
||||
/**
|
||||
* Sort the terms by their path
|
||||
*
|
||||
* @param a term 2
|
||||
* @param b term 2
|
||||
*/
|
||||
SPTermStorePickerService.prototype.sortTermByPath = function (a, b) {
|
||||
if (a.CustomSortOrderIndex === -1) {
|
||||
if (a.PathOfTerm.toLowerCase() < b.PathOfTerm.toLowerCase()) {
|
||||
return -1;
|
||||
}
|
||||
if (a.PathOfTerm.toLowerCase() > b.PathOfTerm.toLowerCase()) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
if (a.CustomSortOrderIndex < b.CustomSortOrderIndex) {
|
||||
return -1;
|
||||
}
|
||||
if (a.CustomSortOrderIndex > b.CustomSortOrderIndex) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
SPTermStorePickerService.prototype.convertTermToPickerTerm = function (term) {
|
||||
return {
|
||||
key: this.cleanGuid(term.Id),
|
||||
name: term.Name,
|
||||
path: term.PathOfTerm,
|
||||
termSet: this.cleanGuid(term.TermSet.Id),
|
||||
termSetName: term.TermSet.Name
|
||||
};
|
||||
};
|
||||
SPTermStorePickerService.prototype.convertSuggestTermToPickerTerm = function (term) {
|
||||
var path = '';
|
||||
var termSetName = '';
|
||||
if (term.Paths && term.Paths.length > 0) {
|
||||
var fullPath = term.Paths[0].replace(/^\[/, '').replace(/\]$/, '');
|
||||
var fullPathParts = fullPath.split(':');
|
||||
path = fullPathParts.join(';') + ';' + term.DefaultLabel;
|
||||
termSetName = fullPathParts[0];
|
||||
}
|
||||
return {
|
||||
key: this.cleanGuid(term.Id),
|
||||
name: term.DefaultLabel,
|
||||
path: path,
|
||||
termSet: EmptyGuid,
|
||||
termSetName: termSetName
|
||||
};
|
||||
};
|
||||
return SPTermStorePickerService;
|
||||
}());
|
||||
export default SPTermStorePickerService;
|
||||
|
||||
//# sourceMappingURL=SPTermStorePickerService.js.map
|
||||
1
lib/services/SPTermStorePickerService.js.map
Normal file
1
lib/services/SPTermStorePickerService.js.map
Normal file
File diff suppressed because one or more lines are too long
11
lib/services/TaxonomyNavigationService.d.ts
vendored
Normal file
11
lib/services/TaxonomyNavigationService.d.ts
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { ITaxonomyNavigationService } from './ITaxonomyNavigationService';
|
||||
import { IMenuItem } from './IMenuItem';
|
||||
import { ApplicationCustomizerContext } from '@microsoft/sp-application-base';
|
||||
export declare class TaxonomyNavigationService implements ITaxonomyNavigationService {
|
||||
private context;
|
||||
private termSetName;
|
||||
private _taxonomyPickerService;
|
||||
private _noTerm;
|
||||
constructor(context: ApplicationCustomizerContext, termSetName: string);
|
||||
getMenuItems(): Promise<IMenuItem[]>;
|
||||
}
|
||||
120
lib/services/TaxonomyNavigationService.js
Normal file
120
lib/services/TaxonomyNavigationService.js
Normal file
@@ -0,0 +1,120 @@
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [0, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
import { sp } from '@pnp/sp';
|
||||
import { MenuItem } from './MenuItem';
|
||||
import SPTermStorePickerService from './SPTermStorePickerService';
|
||||
import { ItemDictionary } from './ItemDictionary';
|
||||
var TaxonomyNavigationService = (function () {
|
||||
function TaxonomyNavigationService(context /*, private lcid: number*/, termSetName) {
|
||||
this.context = context; /*, private lcid: number*/
|
||||
this.termSetName = termSetName;
|
||||
this._noTerm = {
|
||||
_ObjectType_: '',
|
||||
_ObjectIdentity_: '',
|
||||
CustomSortOrderIndex: 0,
|
||||
Description: '',
|
||||
Id: '',
|
||||
IsAvailableForTagging: false,
|
||||
IsDeprecated: false,
|
||||
IsRoot: true,
|
||||
LocalCustomProperties: {
|
||||
_Sys_Nav_HoverText: 'Es wurden keine Terms gefunden. Bitte überprüfen Sie Ihre Einstellungen.',
|
||||
_Sys_Nav_ExcludedProviders: undefined,
|
||||
_Sys_Nav_SimpleLinkUrl: undefined
|
||||
},
|
||||
Name: 'Es wurden keine Terms gefunden. Bitte überprüfen Sie Ihre Einstellungen.',
|
||||
PathOfTerm: '',
|
||||
TermSet: undefined
|
||||
};
|
||||
sp.setup({
|
||||
spfxContext: context
|
||||
});
|
||||
this._taxonomyPickerService = new SPTermStorePickerService({
|
||||
anchorId: '',
|
||||
termsetNameOrID: termSetName,
|
||||
useSessionStorage: true,
|
||||
hideDeprecatedTags: true,
|
||||
hideTagsNotAvailableForTagging: false
|
||||
}, this.context);
|
||||
}
|
||||
// Implement the methods from ITaxonomyNavigationService interface here
|
||||
TaxonomyNavigationService.prototype.getMenuItems = function () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var _this = this;
|
||||
var siteCollectionUrl, termset, itemsDict, menuItems;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
siteCollectionUrl = this.context.pageContext.site.absoluteUrl;
|
||||
return [4 /*yield*/, this._taxonomyPickerService.getAllTerms(this.termSetName)];
|
||||
case 1:
|
||||
termset = _a.sent();
|
||||
itemsDict = new ItemDictionary();
|
||||
menuItems = [];
|
||||
if (!termset || !termset.Terms) {
|
||||
console.warn('No terms found in the term set');
|
||||
return [2 /*return*/, [new MenuItem(this._noTerm, 0, siteCollectionUrl)]];
|
||||
}
|
||||
termset.Terms.forEach(function (term) { return __awaiter(_this, void 0, void 0, function () {
|
||||
var menuItem, parentItem;
|
||||
return __generator(this, function (_a) {
|
||||
menuItem = new MenuItem(term, 0, siteCollectionUrl);
|
||||
itemsDict.Add(term.Id, menuItem);
|
||||
if (menuItem.pathDepth === 1) {
|
||||
menuItems.push(menuItem);
|
||||
}
|
||||
else {
|
||||
parentItem = itemsDict.Get(term.ParentId);
|
||||
if (parentItem) {
|
||||
parentItem.items.push(menuItem);
|
||||
}
|
||||
else {
|
||||
console.warn("Item without parent: " + term.PathOfTerm);
|
||||
}
|
||||
}
|
||||
return [2 /*return*/];
|
||||
});
|
||||
}); });
|
||||
return [2 /*return*/, menuItems];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
return TaxonomyNavigationService;
|
||||
}());
|
||||
export { TaxonomyNavigationService };
|
||||
|
||||
//# sourceMappingURL=TaxonomyNavigationService.js.map
|
||||
1
lib/services/TaxonomyNavigationService.js.map
Normal file
1
lib/services/TaxonomyNavigationService.js.map
Normal file
File diff suppressed because one or more lines are too long
20
lib/services/UserCustomActionService/IUserCustomActionProps.d.ts
vendored
Normal file
20
lib/services/UserCustomActionService/IUserCustomActionProps.d.ts
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
export interface IUserCustomActionProps {
|
||||
Id?: string;
|
||||
Title: string;
|
||||
Name?: string;
|
||||
Description?: string;
|
||||
Location: string;
|
||||
ScriptSrc?: string;
|
||||
ScriptBlock?: string;
|
||||
Url?: string;
|
||||
Sequence?: number;
|
||||
Group?: string;
|
||||
ImageUrl?: string;
|
||||
CommandUIExtension?: string;
|
||||
RegistrationType?: number;
|
||||
RegistrationId?: string;
|
||||
Rights?: {};
|
||||
Scope?: number;
|
||||
ClientSideComponentId?: string;
|
||||
ClientSideComponentProperties?: string;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
//# sourceMappingURL=IUserCustomActionProps.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":[],"names":[],"mappings":"","file":"services/UserCustomActionService/IUserCustomActionProps.js","sourcesContent":[],"sourceRoot":"..\\..\\..\\src"}
|
||||
10
lib/services/UserCustomActionService/IUserCustomActionService.d.ts
vendored
Normal file
10
lib/services/UserCustomActionService/IUserCustomActionService.d.ts
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import { UserCustomActionScope } from './UserCustomActionScope';
|
||||
import { IUserCustomActionProps } from './IUserCustomActionProps';
|
||||
import { UserCustomActionAddResult, UserCustomActionUpdateResult } from '@pnp/sp';
|
||||
export interface IUserCustomActionService {
|
||||
getUserCustomActions(scope: UserCustomActionScope, listId?: string): Promise<IUserCustomActionProps[]>;
|
||||
getUserCustomActionById(scope: UserCustomActionScope, id: string, listId?: string): Promise<IUserCustomActionProps>;
|
||||
addUserCustomAction(scope: UserCustomActionScope, customAction: IUserCustomActionProps, listId?: string): Promise<UserCustomActionAddResult>;
|
||||
updateUserCustomAction(scope: UserCustomActionScope, id: string, props: {}, listId?: string): Promise<UserCustomActionUpdateResult>;
|
||||
deleteUserCustomAction(scope: UserCustomActionScope, customAction: IUserCustomActionProps, listId?: string): Promise<void>;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
//# sourceMappingURL=IUserCustomActionService.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":[],"names":[],"mappings":"","file":"services/UserCustomActionService/IUserCustomActionService.js","sourcesContent":[],"sourceRoot":"..\\..\\..\\src"}
|
||||
5
lib/services/UserCustomActionService/UserCustomActionScope.d.ts
vendored
Normal file
5
lib/services/UserCustomActionService/UserCustomActionScope.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare enum UserCustomActionScope {
|
||||
Web = "web",
|
||||
Site = "site",
|
||||
List = "list",
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
export var UserCustomActionScope;
|
||||
(function (UserCustomActionScope) {
|
||||
UserCustomActionScope["Web"] = "web";
|
||||
UserCustomActionScope["Site"] = "site";
|
||||
UserCustomActionScope["List"] = "list";
|
||||
})(UserCustomActionScope = UserCustomActionScope || (UserCustomActionScope = {}));
|
||||
|
||||
//# sourceMappingURL=UserCustomActionScope.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["services/UserCustomActionService/UserCustomActionScope.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAC7B,oCAAW,CAAA;IACX,sCAAa,CAAA;IACb,sCAAa,CAAA;AACjB,CAAC,EAJW,qBAAqB,GAArB,qBAAqB,KAArB,qBAAqB,QAIhC","file":"services/UserCustomActionService/UserCustomActionScope.js","sourcesContent":["export enum UserCustomActionScope {\r\n Web = 'web',\r\n Site = 'site',\r\n List = 'list'\r\n}\r\n"],"sourceRoot":"..\\..\\..\\src"}
|
||||
13
lib/services/UserCustomActionService/UserCustomActionService.d.ts
vendored
Normal file
13
lib/services/UserCustomActionService/UserCustomActionService.d.ts
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { UserCustomActionAddResult, UserCustomActionUpdateResult } from '@pnp/sp/src/usercustomactions';
|
||||
import { IUserCustomActionService } from './IUserCustomActionService';
|
||||
import { UserCustomActionScope } from './UserCustomActionScope';
|
||||
import { IUserCustomActionProps } from './IUserCustomActionProps';
|
||||
import { ApplicationCustomizerContext } from '@microsoft/sp-application-base';
|
||||
export declare class UserCustomActionService implements IUserCustomActionService {
|
||||
constructor(context: ApplicationCustomizerContext);
|
||||
getUserCustomActions(scope: UserCustomActionScope, listId?: string): Promise<IUserCustomActionProps[]>;
|
||||
getUserCustomActionById(scope: UserCustomActionScope, id: string, listId?: string): Promise<IUserCustomActionProps>;
|
||||
addUserCustomAction(scope: UserCustomActionScope, customAction: IUserCustomActionProps, listId?: string): Promise<UserCustomActionAddResult>;
|
||||
updateUserCustomAction(scope: UserCustomActionScope, id: string, props: {}, listId?: string): Promise<UserCustomActionUpdateResult>;
|
||||
deleteUserCustomAction(scope: UserCustomActionScope, customAction: IUserCustomActionProps, listId?: string): Promise<void>;
|
||||
}
|
||||
210
lib/services/UserCustomActionService/UserCustomActionService.js
Normal file
210
lib/services/UserCustomActionService/UserCustomActionService.js
Normal file
@@ -0,0 +1,210 @@
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [0, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
import { sp } from '@pnp/sp';
|
||||
import { UserCustomActionScope } from './UserCustomActionScope';
|
||||
var UserCustomActionService = (function () {
|
||||
function UserCustomActionService(context) {
|
||||
sp.setup({
|
||||
spfxContext: context
|
||||
});
|
||||
}
|
||||
UserCustomActionService.prototype.getUserCustomActions = function (scope, listId) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var actions, _a, error_1;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
_b.trys.push([0, 9, , 10]);
|
||||
actions = void 0;
|
||||
_a = scope;
|
||||
switch (_a) {
|
||||
case UserCustomActionScope.Web: return [3 /*break*/, 1];
|
||||
case UserCustomActionScope.Site: return [3 /*break*/, 3];
|
||||
case UserCustomActionScope.List: return [3 /*break*/, 5];
|
||||
}
|
||||
return [3 /*break*/, 7];
|
||||
case 1: return [4 /*yield*/, sp.web.userCustomActions.get()];
|
||||
case 2:
|
||||
actions = _b.sent();
|
||||
return [3 /*break*/, 8];
|
||||
case 3: return [4 /*yield*/, sp.site.userCustomActions.get()];
|
||||
case 4:
|
||||
actions = _b.sent();
|
||||
return [3 /*break*/, 8];
|
||||
case 5:
|
||||
if (!listId) {
|
||||
throw new Error('List ID is required for List scope');
|
||||
}
|
||||
return [4 /*yield*/, sp.web.lists.getById(listId).userCustomActions.get()];
|
||||
case 6:
|
||||
actions = _b.sent();
|
||||
return [3 /*break*/, 8];
|
||||
case 7: throw new Error('Invalid scope');
|
||||
case 8: return [2 /*return*/, actions];
|
||||
case 9:
|
||||
error_1 = _b.sent();
|
||||
console.error('Error getting user custom actions: ', error_1);
|
||||
throw error_1;
|
||||
case 10: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
UserCustomActionService.prototype.getUserCustomActionById = function (scope, id, listId) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
try {
|
||||
switch (scope) {
|
||||
case UserCustomActionScope.Web:
|
||||
return [2 /*return*/, sp.web.userCustomActions.getById(id)];
|
||||
case UserCustomActionScope.Site:
|
||||
return [2 /*return*/, sp.site.userCustomActions.getById(id)];
|
||||
case UserCustomActionScope.List:
|
||||
if (!listId) {
|
||||
throw new Error('List ID is required for List scope');
|
||||
}
|
||||
return [2 /*return*/, sp.web.lists.getById(listId).userCustomActions.getById(id)];
|
||||
default:
|
||||
throw new Error('Invalid scope');
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error('Error getting user custom action by ID: ', error);
|
||||
throw error;
|
||||
}
|
||||
return [2 /*return*/];
|
||||
});
|
||||
});
|
||||
};
|
||||
UserCustomActionService.prototype.addUserCustomAction = function (scope, customAction, listId) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
try {
|
||||
switch (scope) {
|
||||
case UserCustomActionScope.Web:
|
||||
return [2 /*return*/, sp.web.userCustomActions.add(customAction)];
|
||||
case UserCustomActionScope.Site:
|
||||
return [2 /*return*/, sp.site.userCustomActions.add(customAction)];
|
||||
case UserCustomActionScope.List:
|
||||
if (!listId) {
|
||||
throw new Error('List ID is required for List scope');
|
||||
}
|
||||
return [2 /*return*/, sp.web.lists.getById(listId).userCustomActions.add(customAction)];
|
||||
default:
|
||||
throw new Error('Invalid scope');
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error('Error adding user custom action: ', error);
|
||||
throw error;
|
||||
}
|
||||
return [2 /*return*/];
|
||||
});
|
||||
});
|
||||
};
|
||||
UserCustomActionService.prototype.updateUserCustomAction = function (scope, id, props, listId) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var result, _a, error_2;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
_b.trys.push([0, 9, , 10]);
|
||||
result = void 0;
|
||||
_a = scope;
|
||||
switch (_a) {
|
||||
case UserCustomActionScope.Web: return [3 /*break*/, 1];
|
||||
case UserCustomActionScope.Site: return [3 /*break*/, 3];
|
||||
case UserCustomActionScope.List: return [3 /*break*/, 5];
|
||||
}
|
||||
return [3 /*break*/, 7];
|
||||
case 1: return [4 /*yield*/, sp.web.userCustomActions.getById(id).update(props)];
|
||||
case 2:
|
||||
result = _b.sent();
|
||||
return [3 /*break*/, 8];
|
||||
case 3: return [4 /*yield*/, sp.site.userCustomActions.getById(id).update(props)];
|
||||
case 4:
|
||||
result = _b.sent();
|
||||
return [3 /*break*/, 8];
|
||||
case 5:
|
||||
if (!listId) {
|
||||
throw new Error('List ID is required for List scope');
|
||||
}
|
||||
return [4 /*yield*/, sp.web.lists.getById(listId).userCustomActions.getById(id).update(props)];
|
||||
case 6:
|
||||
result = _b.sent();
|
||||
return [3 /*break*/, 8];
|
||||
case 7: throw new Error('Invalid scope');
|
||||
case 8: return [2 /*return*/, result];
|
||||
case 9:
|
||||
error_2 = _b.sent();
|
||||
console.error('Error updating user custom action: ', error_2);
|
||||
throw error_2;
|
||||
case 10: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
UserCustomActionService.prototype.deleteUserCustomAction = function (scope, customAction, listId) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
try {
|
||||
switch (scope) {
|
||||
case UserCustomActionScope.Web:
|
||||
return [2 /*return*/, sp.web.userCustomActions.getById(customAction.Id).delete()];
|
||||
case UserCustomActionScope.Site:
|
||||
return [2 /*return*/, sp.site.userCustomActions.getById(customAction.Id).delete()];
|
||||
case UserCustomActionScope.List:
|
||||
if (!listId) {
|
||||
throw new Error('List ID is required for List scope');
|
||||
}
|
||||
return [2 /*return*/, sp.web.lists.getById(listId).userCustomActions.getById(customAction.Id).delete()];
|
||||
default:
|
||||
throw new Error('Invalid scope');
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error('Error deleting user custom action: ', error);
|
||||
throw error;
|
||||
}
|
||||
return [2 /*return*/];
|
||||
});
|
||||
});
|
||||
};
|
||||
return UserCustomActionService;
|
||||
}());
|
||||
export { UserCustomActionService };
|
||||
|
||||
//# sourceMappingURL=UserCustomActionService.js.map
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user