UNPKG

@pnp/spfx-property-controls

Version:

Reusable property pane controls for SharePoint Framework solutions

62 lines 2.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SPRoleDefinitionPickerService = void 0; const tslib_1 = require("tslib"); const sp_http_1 = require("@microsoft/sp-http"); /** * Service implementation to get list & list items from current SharePoint site */ class SPRoleDefinitionPickerService { /** * Service constructor */ constructor(_props, pageContext) { this.props = _props; this.context = pageContext; } /** * Gets the collection of view for a selected list */ getRoleDefinitions() { return tslib_1.__awaiter(this, void 0, void 0, function* () { const webAbsoluteUrl = this.props.webAbsoluteUrl ? this.props.webAbsoluteUrl : this.context.pageContext.web.absoluteUrl; // If the running environment is SharePoint, request the lists REST service const queryUrl = `${webAbsoluteUrl}/_api/web/RoleDefinitions`; const response = yield this.context.spHttpClient.get(queryUrl, sp_http_1.SPHttpClient.configurations.v1, { headers: [ ['accept', 'application/json;odata=nometadata'], ['odata-version', ''] ] }); const roleDefinitions = (yield response.json()); // Check if onViewsRetrieved callback is defined if (this.props.onRoleDefinitionsRetrieved) { //Call onViewsRetrieved const lr = this.props.onRoleDefinitionsRetrieved(roleDefinitions.value); let output; //Conditional checking to see of PromiseLike object or array if (lr instanceof Array) { output = lr; } else { output = yield lr; } roleDefinitions.value = output; } return roleDefinitions; }); } /** * Returns an empty view for when a list isn't selected */ getEmptyViews() { return new Promise((resolve) => { const roleDefinitionData = { value: [] }; resolve(roleDefinitionData); }); } } exports.SPRoleDefinitionPickerService = SPRoleDefinitionPickerService; //# sourceMappingURL=SPRoleDefinitionPickerService.js.map