1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Observable_1 = require("rxjs/Observable"); const ODataApi_1 = require("./ODataApi"); const SN_1 = require("./SN"); class Collection { constructor(_items, _repository, contentType) { this._items = _items; this._repository = _repository; this.Path = ''; } get _odata() { return this._repository.GetODataApi(); } Items() { return this._items; } Item(id) { return this._items.find((i) => i.Id === id); } Count() { return this._items.length; } Add(content) { const newcontent = this._odata.Post(this.Path, content.GetFields()) .map((resp) => { return this._repository.HandleLoadedContent(resp); }); newcontent .subscribe({ next: (response) => { this._items = [ ...this._items, response ]; } }); return newcontent; } Remove(arg, permanently = false) { if (typeof arg === 'number') { const content = this._items[arg]; if (content && content.Id) { this._items = this._items.slice(0, arg) .concat(this._items.slice(arg + 1)); return this._odata.Delete(content.Id, permanently ? permanently : false); } else { return Observable_1.Observable.of(undefined); } } else { const ids = arg.map((i) => this._items[i].Id); this._items = this._items.filter((item, i) => arg.indexOf(i) > -1); const action = new ODataApi_1.CustomAction({ name: 'DeleteBatch', path: this.Path, isAction: true, requiredParams: ['paths'] }); return this._odata.CreateCustomAction(action, { data: [{ paths: ids }, { permanently }] }); } } Read(path, options) { this.Path = path; const children = this._odata.Fetch({ params: options, path }) .map((items) => { return items.d.results.map((c) => this._repository.HandleLoadedContent(c)); }); return children; } Move(arg, targetPath) { if (typeof arg === 'number') { this._items = this._items.slice(0, arg) .concat(this._items.slice(arg + 1)); const action = new ODataApi_1.CustomAction({ name: 'Move', id: arg, isAction: true, requiredParams: ['targetPath'] }); return this._odata.CreateCustomAction(action, { data: [{ targetPath }] }); } else { const ids = arg.map((i) => this._items[i].Id); this._items = this._items.filter((item, i) => arg.indexOf(i) > -1); const action = new ODataApi_1.CustomAction({ name: 'MoveBatch', path: this.Path, isAction: true, requiredParams: ['paths', 'targetPath'] }); return this._odata.CreateCustomAction(action, { data: [{ paths: ids, targetPath }] }); } } Copy(arg, targetPath) { if (typeof arg === 'number') { const action = new ODataApi_1.CustomAction({ name: 'Copy', id: arg, isAction: true, requiredParams: ['targetPath'] }); return this._odata.CreateCustomAction(action, { data: [{ targetPath }] }); } else { const ids = arg.map((i) => this._items[i].Id); const action = new ODataApi_1.CustomAction({ name: 'CopyBatch', path: this.Path, isAction: true, requiredParams: ['paths', 'targetPath'] }); return this._odata.CreateCustomAction(action, { data: [{ paths: ids, targetPath }] }); } } AllowedChildTypes(options) { const o = {}; if (options) { o.params = options; } o.path = SN_1.ODataHelper.getContentURLbyPath(this.Path); const optionList = o; return this._odata.Get(optionList); } Upload(options) { const uploadRequest = this._repository.UploadTextAsFile(options); uploadRequest.first().subscribe((progress) => { this._items.push(progress.CreatedContent); }); return uploadRequest; } } exports.Collection = Collection; //# sourceMappingURL=Collection.js.map |