UNPKG

@pnp/sp

Version:

pnp - provides a fluent api for working with SharePoint REST

137 lines 4.5 kB
import { __decorate } from "tslib"; import { body } from "@pnp/queryable"; import { _SPCollection, spInvokableFactory, _SPInstance, deleteable, } from "../spqueryable.js"; import { defaultPath } from "../decorators.js"; import { spPost, spPostMerge } from "../operations.js"; import { encodePath } from "../utils/encode-path-str.js"; let _Views = class _Views extends _SPCollection { /** * Adds a new view to the collection * * @param title The new views's title * @param personalView True if this is a personal view, otherwise false, default = false * @param additionalSettings Will be passed as part of the view creation body */ async add(Title, PersonalView = false, additionalSettings = {}) { const data = await spPost(this, body({ PersonalView, Title, ...additionalSettings, })); return { data, view: this.getById(data.Id), }; } /** * Gets a view by guid id * * @param id The GUID id of the view */ getById(id) { return View(this).concat(`('${id}')`); } /** * Gets a view by title (case-sensitive) * * @param title The case-sensitive title of the view */ getByTitle(title) { return View(this, `getByTitle('${encodePath(title)}')`); } }; _Views = __decorate([ defaultPath("views") ], _Views); export { _Views }; export const Views = spInvokableFactory(_Views); export class _View extends _SPInstance { constructor() { super(...arguments); this.delete = deleteable(); } get fields() { return ViewFields(this); } /** * Updates this view intance with the supplied properties * * @param properties A plain object hash of values to update for the view */ async update(props) { const data = await spPostMerge(this, body(props)); return { data, view: this, }; } // : any = this._update<IViewUpdateResult, ITypedHash<any>>("SP.View", data => ({ data, view: <any>this })); /** * Returns the list view as HTML. * */ renderAsHtml() { return View(this, "renderashtml")(); } /** * Sets the view schema * * @param viewXml The view XML to set */ setViewXml(viewXml) { return spPost(View(this, "SetViewXml"), body({ viewXml })); } } export const View = spInvokableFactory(_View); let _ViewFields = class _ViewFields extends _SPCollection { /** * Gets a value that specifies the XML schema that represents the collection. */ getSchemaXml() { return ViewFields(this, "schemaxml")(); } /** * Adds the field with the specified field internal name or display name to the collection. * * @param fieldTitleOrInternalName The case-sensitive internal name or display name of the field to add. */ add(fieldTitleOrInternalName) { return spPost(ViewFields(this, `addviewfield('${encodePath(fieldTitleOrInternalName)}')`)); } /** * Moves the field with the specified field internal name to the specified position in the collection. * * @param field The case-sensitive internal name of the field to move. * @param index The zero-based index of the new position for the field. */ move(field, index) { return spPost(ViewFields(this, "moveviewfieldto"), body({ field, index })); } /** * Removes all the fields from the collection. */ removeAll() { return spPost(ViewFields(this, "removeallviewfields")); } /** * Removes the field with the specified field internal name from the collection. * * @param fieldInternalName The case-sensitive internal name of the field to remove from the view. */ remove(fieldInternalName) { return spPost(ViewFields(this, `removeviewfield('${encodePath(fieldInternalName)}')`)); } }; _ViewFields = __decorate([ defaultPath("viewfields") ], _ViewFields); export { _ViewFields }; export const ViewFields = spInvokableFactory(_ViewFields); export var ViewScope; (function (ViewScope) { ViewScope[ViewScope["DefaultValue"] = 0] = "DefaultValue"; ViewScope[ViewScope["Recursive"] = 1] = "Recursive"; ViewScope[ViewScope["RecursiveAll"] = 2] = "RecursiveAll"; ViewScope[ViewScope["FilesOnly"] = 3] = "FilesOnly"; })(ViewScope || (ViewScope = {})); //# sourceMappingURL=types.js.map