|
| 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 | +} |
0 commit comments