• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript sp-pnp-js.Web类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中sp-pnp-js.Web的典型用法代码示例。如果您正苦于以下问题:TypeScript Web类的具体用法?TypeScript Web怎么用?TypeScript Web使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Web类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: Web

                const discussionReplies: Promise<IDiscussionReply>[] = replies.map(async (reply) => {

                    web = new Web(_spPageContextInfo.webAbsoluteUrl);
                    let item;
                    // tslint:disable-next-line:prefer-conditional-expression
                    if (isSPO) {
                        item = await web.getList(this.discussionListServerRelativeUrl).items.getById(reply.Id).select("Author/Name", "ParentList/Id").expand("Author/Name", "ParentList/Id").inBatch(batch).get();
                    } else {
                        item = await web.getList(this.discussionListServerRelativeUrl).items.getById(reply.Id).select("Author/Name", "ParentList/Id").expand("Author/Name", "ParentList/Id").get();
                    }

                    const authorProperties = await this.getUserProperties(item.Author.Name);
                    const PictureUrl = authorProperties["PictureUrl"] ? authorProperties["PictureUrl"] : "/_layouts/15/images/person.gif?rev=23";

                    // tslint:disable-next-line:no-object-literal-type-assertion
                    return {
                        Author: {
                            DisplayName: authorProperties["DisplayName"],
                            Id: item.Author.Id,
                            PictureUrl,
                        },
                        Body: reply.Body,
                        Children: [],
                        Edited: reply.Modified,
                        Id: reply.Id,
                        LikedBy: reply.LikedByStringId ? reply.LikedByStringId.results : [],
                        LikesCount: reply.LikesCount ? reply.LikesCount : 0,
                        ParentItemID: reply.ParentItemID,
                        ParentListId: item.ParentList.Id,
                        Posted: reply.Created,
                        UserPermissions: await this.getCurrentUserPermissionsOnItem(reply.Id, item.Author.Name),
                    } as IDiscussionReply;
                });
开发者ID:ScoutmanPt,项目名称:PnP,代码行数:33,代码来源:SocialModule.ts


示例2: deleteReply

    /**
     * Delete a reply in an existing discussion
     * @param replyId the item id to delete
     */
    public async deleteReply(replyId: number): Promise<number> {

        try {
            const web = new Web(_spPageContextInfo.webAbsoluteUrl);
            await web.getList(this.discussionListServerRelativeUrl).items.getById(replyId).delete();
            return replyId;

        } catch (error) {
            Logger.write(`[SocialModule:deleteReply]: ${error}`, LogLevel.Error);
            throw error;
        }
    }
开发者ID:ScoutmanPt,项目名称:PnP,代码行数:16,代码来源:SocialModule.ts


示例3: updateReply

    /**
     * Updates a reply
     * @param replyId The reply id to update
     * @param replyBody The new reply body
     */
    public async updateReply(replyId: number, replyBody: string): Promise<void> {

        try {
            const web = new Web(_spPageContextInfo.webAbsoluteUrl);
            const result = await web.getList(this.discussionListServerRelativeUrl).items.getById(replyId).select("Modified").update({
                Body: replyBody,
            });

            return;

        } catch (error) {
            Logger.write(`[SocialModule:updateReply]: ${error}`, LogLevel.Error);
            throw error;
        }
    }
开发者ID:ScoutmanPt,项目名称:PnP,代码行数:20,代码来源:SocialModule.ts


示例4: constructor

    constructor() {

        this.welcomeMessage = ko.observable("");

        const web = new Web(_spPageContextInfo.webAbsoluteUrl);

        // Get the current user name
        web.getUserById(_spPageContextInfo.userId).get().then((user) => {

            this.welcomeMessage(sprintf.sprintf(i18n.t("welcomeMessage"), user.Title.split(" ")[0]));

        }).catch((errorMesssage) => {

            Logger.write(errorMesssage, LogLevel.Error);
        });
    }
开发者ID:AKrasheninnikov,项目名称:PnP,代码行数:16,代码来源:WelcomeOverlayViewModel.ts


示例5: getCurrentUserPermissionsOnList

    public async getCurrentUserPermissionsOnList(listServerRelativeUrl: string): Promise<DiscussionPermissionLevel[]> {

        const permissionsList = [];

        const web = new Web(_spPageContextInfo.webAbsoluteUrl);
        const permissions = await web.getList(listServerRelativeUrl).getCurrentUserEffectivePermissions();
        const canAddListItems = web.hasPermissions(permissions, PermissionKind.AddListItems);
        const canManageLists = web.hasPermissions(permissions, PermissionKind.ManageLists);

        if (canAddListItems) {
            permissionsList.push(DiscussionPermissionLevel.Add);
        }

        if (canManageLists) {
            permissionsList.push(DiscussionPermissionLevel.ManageLists);
        }

        return permissionsList;
    }
开发者ID:ScoutmanPt,项目名称:PnP,代码行数:19,代码来源:SocialModule.ts


示例6: _getWebProperties

    private async _getWebProperties(webUrl: string, selectFields: string[]): Promise<any> {
        let web = new Web(webUrl);
        let data: any = null;
        // prefix all properties with the expanded field
        selectFields.forEach((value, index, array) => {
            array[index] = "AllProperties/" + value;
        });
        const select = selectFields.join(',');

        try {
            data = await web
                .select(select)
                .expand('AllProperties')
                .usingCaching()
                .get();

        } catch (error) {
            Logger.write('Error loading web properties: ' + error, LogLevel.Error);
        }
        return data.AllProperties;
    }
开发者ID:,项目名称:,代码行数:21,代码来源:


示例7: getCurrentUserPermissionsOnItem

    /**
     * Gets the current user permnissions on a reply
     * @param itemId the item id
     * @param replyAuthorLoginName the reply auhtor name (to check if the current user is the actual author)
     */
    private async getCurrentUserPermissionsOnItem(itemId: number, replyAuthorLoginName: string): Promise<DiscussionPermissionLevel[]> {

        const permissionsList = [];

        const web = new Web(_spPageContextInfo.webAbsoluteUrl);
        const permissions = await web.getList(this.discussionListServerRelativeUrl).items.getById(itemId).getCurrentUserEffectivePermissions();

        const canAddListItems = web.hasPermissions(permissions, PermissionKind.AddListItems);
        const canEditListItems = web.hasPermissions(permissions, PermissionKind.EditListItems);
        const canDeleteListItems = web.hasPermissions(permissions, PermissionKind.DeleteListItems);
        const canManageLists = web.hasPermissions(permissions, PermissionKind.ManageLists);

        if (canManageLists) {
            permissionsList.push(DiscussionPermissionLevel.ManageLists);
            permissionsList.push(DiscussionPermissionLevel.Delete);
            permissionsList.push(DiscussionPermissionLevel.Edit);
        }

        if ((canEditListItems && !canManageLists) || (canDeleteListItems && !canManageLists)) {

            pnp.storage.local.deleteExpired();

            // The "WriteSecurity" property isn't availabe through REST with SharePoint 2013. In this case, we need to get the whole list XML schema to extract this info
            // Not very efficient but we do not have any other option here
            // Not List Item Level Security is different than item permissions so we can't rely on native REST methods (i.e. getCurrentUserEffectivePermissions())
            const writeSecurityStorageKey = String.format("{0}_{1}", _spPageContextInfo.webServerRelativeUrl, "commentsListWriteSecurity");
            let writeSecurity = pnp.storage.local.get(writeSecurityStorageKey);

            if (!writeSecurity) {
                const  list = await web.getList(this.discussionListServerRelativeUrl).select("SchemaXml").get();
                // tslint:disable-next-line:radix
                writeSecurity = parseInt(/WriteSecurity="(\d)"/.exec(list.SchemaXml)[1]);

                pnp.storage.local.put(writeSecurityStorageKey, writeSecurity, pnp.util.dateAdd(new Date(), "minute", 60));
            }

            // 2 = Create items and edit items that were created by the user
            if (writeSecurity === 2) {

                const userLoginNameStorageKey = String.format("{0}_{1}", _spPageContextInfo.webServerRelativeUrl, "currentUserLoginName");
                let currentUserLoginName = pnp.storage.local.get(userLoginNameStorageKey);
                if (!currentUserLoginName) {
                    const currentUser = await web.currentUser.select("LoginName").get();
                    currentUserLoginName = currentUser.LoginName;
                    pnp.storage.local.put(userLoginNameStorageKey, currentUserLoginName, pnp.util.dateAdd(new Date(), "minute", 20));
                }

                // If the current user is the author of the comment
                if (replyAuthorLoginName === currentUserLoginName) {

                    if (canEditListItems) {
                        permissionsList.push(DiscussionPermissionLevel.EditAsAuthor);
                    }

                    if (canDeleteListItems) {
                        permissionsList.push(DiscussionPermissionLevel.DeleteAsAuthor);
                    }
                }
            } else {
                if (canDeleteListItems) {
                    permissionsList.push(DiscussionPermissionLevel.Delete);
                }

                if (canEditListItems) {
                    permissionsList.push(DiscussionPermissionLevel.Edit);
                }
            }
        }

        if (canAddListItems) {
            permissionsList.push(DiscussionPermissionLevel.Add);
        }

        return permissionsList;
    }
开发者ID:ScoutmanPt,项目名称:PnP,代码行数:80,代码来源:SocialModule.ts


示例8: getDiscussionById

    /**
     * Get a disucssion feed by id
     * @param id the id of the associated page
     */
    public async getDiscussionById(associatedPageId: number): Promise<IDiscussion> {

        let web = new Web(_spPageContextInfo.webAbsoluteUrl);

        try {

            const discussion = await web.getList(this.discussionListServerRelativeUrl).items
                .filter(`AssociatedPageId eq ${ associatedPageId }`)
                .select("Id", "Folder", "AssociatedPageId")
                .expand("Folder")
                .top(1)
                .get();
            if (discussion.length > 0) {

                // Get replies from this discussion (i.e. folder)
                const query: CamlQuery = {
                    FolderServerRelativeUrl: `${this.discussionListServerRelativeUrl}/${discussion[0].Folder.Name}`,
                    ViewXml: `<View>
                                    <ViewFields>
                                        <FieldRef Name="Id"></FieldRef>
                                        <FieldRef Name="ParentItemID"></FieldRef>
                                        <FieldRef Name="Created"></FieldRef>
                                        <FieldRef Name="Modified"></FieldRef>
                                        <FieldRef Name="Body"></FieldRef>
                                        <FieldRef Name="ParenListId"></FieldRef>
                                        <FieldRef Name="LikedBy"></FieldRef>
                                        <FieldRef Name="LikesCount"></FieldRef>
                                    </ViewFields>
                                    <Query/>
                                </View>`,
                };

                const replies = await web.getList(this.discussionListServerRelativeUrl).getItemsByCAMLQuery(query);

                // Batch are not supported on Sharepoint 2013
                // https://github.com/SharePoint/PnP-JS-Core/issues/492
                const batch = pnp.sp.createBatch();
                const isSPO = _spPageContextInfo["isSPO"];

                // tslint:disable-next-line:array-type
                const discussionReplies: Promise<IDiscussionReply>[] = replies.map(async (reply) => {

                    web = new Web(_spPageContextInfo.webAbsoluteUrl);
                    let item;
                    // tslint:disable-next-line:prefer-conditional-expression
                    if (isSPO) {
                        item = await web.getList(this.discussionListServerRelativeUrl).items.getById(reply.Id).select("Author/Name", "ParentList/Id").expand("Author/Name", "ParentList/Id").inBatch(batch).get();
                    } else {
                        item = await web.getList(this.discussionListServerRelativeUrl).items.getById(reply.Id).select("Author/Name", "ParentList/Id").expand("Author/Name", "ParentList/Id").get();
                    }

                    const authorProperties = await this.getUserProperties(item.Author.Name);
                    const PictureUrl = authorProperties["PictureUrl"] ? authorProperties["PictureUrl"] : "/_layouts/15/images/person.gif?rev=23";

                    // tslint:disable-next-line:no-object-literal-type-assertion
                    return {
                        Author: {
                            DisplayName: authorProperties["DisplayName"],
                            Id: item.Author.Id,
                            PictureUrl,
                        },
                        Body: reply.Body,
                        Children: [],
                        Edited: reply.Modified,
                        Id: reply.Id,
                        LikedBy: reply.LikedByStringId ? reply.LikedByStringId.results : [],
                        LikesCount: reply.LikesCount ? reply.LikesCount : 0,
                        ParentItemID: reply.ParentItemID,
                        ParentListId: item.ParentList.Id,
                        Posted: reply.Created,
                        UserPermissions: await this.getCurrentUserPermissionsOnItem(reply.Id, item.Author.Name),
                    } as IDiscussionReply;
                });

                if (isSPO) {
                    await batch.execute();
                }

                // Get rating experience settings
                const folderSettings = await web.getFolderByServerRelativeUrl(this.discussionListServerRelativeUrl).properties.select("Ratings_VotingExperience").get();

                const ratingExperience: string = folderSettings.Ratings_x005f_VotingExperience;
                let areLikesEnabled;
                if (ratingExperience) {
                    areLikesEnabled = ratingExperience.localeCompare("Likes") === 0 ? true : false;
                }

                // tslint:disable-next-line:no-object-literal-type-assertion
                return {
                    AreLikesEnabled: areLikesEnabled,
                    AssociatedPageId: discussion[0].AssociatedPageId,
                    Id: discussion[0].Id,
                    Replies: await Promise.all(discussionReplies),
                    Title: discussion[0].Title,
                } as IDiscussion;

//.........这里部分代码省略.........
开发者ID:ScoutmanPt,项目名称:PnP,代码行数:101,代码来源:SocialModule.ts



注:本文中的sp-pnp-js.Web类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript sp-pnp-js.log类代码示例发布时间:2022-05-25
下一篇:
TypeScript sp-pnp-js.Logger类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap