UNPKG

@pnp/spfx-property-controls

Version:

Reusable property pane controls for SharePoint Framework solutions

77 lines 3.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SPViewPickerService = void 0; const tslib_1 = require("tslib"); const sp_http_1 = require("@microsoft/sp-http"); const viewPicker_1 = require("../propertyFields/viewPicker"); /** * Service implementation to get list & list items from current SharePoint site */ class SPViewPickerService { /** * Service constructor */ constructor(_props, pageContext) { this.props = _props; this.context = pageContext; } /** * Gets the collection of view for a selected list */ getViews() { return tslib_1.__awaiter(this, void 0, void 0, function* () { if (this.props.listId === undefined || this.props.listId === "") { return this.getEmptyViews(); } const webAbsoluteUrl = this.props.webAbsoluteUrl ? this.props.webAbsoluteUrl : this.context.pageContext.web.absoluteUrl; // If the running environment is SharePoint, request the lists REST service let queryUrl = `${webAbsoluteUrl}/_api/lists(guid'${this.props.listId}')/Views?$select=Title,Id`; // Check if the orderBy property is provided if (this.props.orderBy !== null) { queryUrl += '&$orderby='; switch (this.props.orderBy) { case viewPicker_1.PropertyFieldViewPickerOrderBy.Id: queryUrl += 'Id'; break; case viewPicker_1.PropertyFieldViewPickerOrderBy.Title: queryUrl += 'Title'; break; } // Adds an OData Filter to the list if (this.props.filter) { queryUrl += `&$filter=${encodeURIComponent(this.props.filter)}`; } const response = yield this.context.spHttpClient.get(queryUrl, sp_http_1.SPHttpClient.configurations.v1); const views = (yield response.json()); // Check if onViewsRetrieved callback is defined if (this.props.onViewsRetrieved) { //Call onViewsRetrieved const lr = this.props.onViewsRetrieved(views.value); let output; //Conditional checking to see of PromiseLike object or array if (lr instanceof Array) { output = lr; } else { output = yield lr; } views.value = output; } return views; } }); } /** * Returns an empty view for when a list isn't selected */ getEmptyViews() { return new Promise((resolve) => { const listData = { value: [] }; resolve(listData); }); } } exports.SPViewPickerService = SPViewPickerService; //# sourceMappingURL=SPViewPickerService.js.map