Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit e0b9047

Browse files
adding features capability to library
1 parent 2a0f91f commit e0b9047

6 files changed

Lines changed: 130 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![Office 365 Developer Patterns and Practices](https://camo.githubusercontent.com/a732087ed949b0f2f84f5f02b8c79f1a9dd96f65/687474703a2f2f692e696d6775722e636f6d2f6c3031686876452e706e67)
22

3-
# JavaScript Core Component
3+
# JavaScript Core Library
44

55
[![npm version](https://badge.fury.io/js/sp-pnp-js.svg)](https://badge.fury.io/js/sp-pnp-js) [![Join the chat at https://gitter.im/OfficeDev/PnP-JS-Core](https://badges.gitter.im/OfficeDev/PnP-JS-Core.svg)](https://gitter.im/OfficeDev/PnP-JS-Core?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Downloads](https://img.shields.io/npm/dm/sp-pnp-js.svg)](https://www.npmjs.com/package/sp-pnp-js) [![bitHound Overall Score](https://www.bithound.io/github/SharePoint/PnP-JS-Core/badges/score.svg)](https://www.bithound.io/github/SharePoint/PnP-JS-Core)
66

src/sharepoint/features.ts

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import { Queryable, QueryableInstance, QueryableCollection } from "./queryable";
2+
3+
/**
4+
* Describes a collection of List objects
5+
*
6+
*/
7+
export class Features extends QueryableCollection {
8+
9+
/**
10+
* Creates a new instance of the Lists class
11+
*
12+
* @param baseUrl The url or Queryable which forms the parent of this fields collection
13+
*/
14+
constructor(baseUrl: string | Queryable, path = "features") {
15+
super(baseUrl, path);
16+
}
17+
18+
/**
19+
* Gets a list from the collection by guid id
20+
*
21+
* @param id The Id of the feature (GUID)
22+
*/
23+
public getById(id: string): Feature {
24+
let feature = new Feature(this);
25+
feature.concat(`('${id}')`);
26+
return feature;
27+
}
28+
29+
/**
30+
* Adds a new list to the collection
31+
*
32+
* @param id The Id of the feature (GUID)
33+
* @param force If true the feature activation will be forced
34+
*/
35+
public add(id: string, force = false): Promise<FeatureAddResult> {
36+
37+
let adder = new Features(this, "add");
38+
return adder.post({
39+
body: JSON.stringify({
40+
featureId: id,
41+
force: force,
42+
featdefScope: 0
43+
})
44+
}).then(data => {
45+
return {
46+
data: data,
47+
feature: this.getById(id)
48+
};
49+
});
50+
}
51+
52+
/**
53+
* Removes (deactivates) a feature from the collection
54+
*
55+
* @param id The Id of the feature (GUID)
56+
* @param force If true the feature deactivation will be forced
57+
*/
58+
public remove(id: string, force = false): Promise<any> {
59+
60+
let remover = new Features(this, "remove");
61+
return remover.post({
62+
body: JSON.stringify({
63+
featureId: id,
64+
force: force
65+
})
66+
});
67+
}
68+
}
69+
70+
export class Feature extends QueryableInstance {
71+
72+
/**
73+
* Creates a new instance of the Lists class
74+
*
75+
* @param baseUrl The url or Queryable which forms the parent of this fields collection
76+
*/
77+
constructor(baseUrl: string | Queryable, path?: string) {
78+
super(baseUrl, path);
79+
}
80+
81+
/**
82+
* Removes (deactivates) a feature from the collection
83+
*
84+
* @param force If true the feature deactivation will be forced
85+
*/
86+
public deactivate(force = false): Promise<any> {
87+
88+
let removeDependency = this.addBatchDependency();
89+
90+
let idGet = new Feature(this).select("DefinitionId");
91+
92+
return idGet.get().then(feature => {
93+
94+
let promise = this.getParent(Features, this.parentUrl, "").remove(feature.DefinitionId, force);
95+
96+
removeDependency();
97+
98+
return promise;
99+
});
100+
}
101+
}
102+
103+
export interface FeatureAddResult {
104+
data: any;
105+
feature: Feature;
106+
}

src/sharepoint/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export {
1818
ChunkedFileUploadProgressData
1919
} from "./files";
2020

21+
export {
22+
FeatureAddResult
23+
} from "./features";
24+
2125
export {
2226
FolderAddResult
2327
} from "./folders";

src/sharepoint/lists.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class Lists extends QueryableCollection {
4040
/**
4141
* Gets a list from the collection by guid id
4242
*
43-
* @param title The Id of the list
43+
* @param id The Id of the list (GUID)
4444
*/
4545
public getById(id: string): List {
4646
let list = new List(this);
@@ -57,7 +57,6 @@ export class Lists extends QueryableCollection {
5757
* @param enableContentTypes If true content types will be allowed and enabled, otherwise they will be disallowed and not enabled
5858
* @param additionalSettings Will be passed as part of the list creation body
5959
*/
60-
/*tslint:disable max-line-length */
6160
public add(title: string, description = "", template = 100, enableContentTypes = false, additionalSettings: TypedHash<string | number | boolean> = {}): Promise<ListAddResult> {
6261

6362
let postBody = JSON.stringify(Util.extend({
@@ -73,7 +72,6 @@ export class Lists extends QueryableCollection {
7372
return { data: data, list: this.getByTitle(title) };
7473
});
7574
}
76-
/*tslint:enable */
7775

7876
/**
7977
* Ensures that the specified list exists in the collection (note: settings are not updated if the list exists,

src/sharepoint/site.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Web } from "./webs";
33
import { UserCustomActions } from "./usercustomactions";
44
import { ContextInfo, DocumentLibraryInformation } from "./types";
55
import { ODataBatch } from "./odata";
6+
import { Features } from "./features";
67

78
/**
89
* Describes a site collection
@@ -27,6 +28,14 @@ export class Site extends QueryableInstance {
2728
return new Web(this, "rootweb");
2829
}
2930

31+
/**
32+
* Gets the active features for this site
33+
*
34+
*/
35+
public get features(): Features {
36+
return new Features(this);
37+
}
38+
3039
/**
3140
* Get all custom actions on a site collection
3241
*

src/sharepoint/webs.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { List } from "./lists";
1515
import { SiteUsers, SiteUser, CurrentUser } from "./siteusers";
1616
import { UserCustomActions } from "./usercustomactions";
1717
import { extractOdataId, ODataBatch } from "./odata";
18+
import { Features } from "./features";
1819

1920

2021
export class Webs extends QueryableCollection {
@@ -107,6 +108,14 @@ export class Web extends QueryableSecurable {
107108
return new Fields(this);
108109
}
109110

111+
/**
112+
* Gets the active features for this web
113+
*
114+
*/
115+
public get features(): Features {
116+
return new Features(this);
117+
}
118+
110119
/**
111120
* Gets the available fields in this web
112121
*

0 commit comments

Comments
 (0)