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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const rxjs_1 = require("@reactivex/rxjs"); 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 rxjs_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(contentType, fileName, overwrite = true, useChunk = false, propertyName, fileText) { const data = { ContentType: contentType, FileName: fileName, Overwrite: overwrite, UseChunk: useChunk }; if (typeof propertyName !== 'undefined') { data.PropertyName = propertyName; } if (typeof fileText !== 'undefined') { data.FileText = fileText; } const uploadCreation = this._odata.Upload(this.Path, data, true); uploadCreation.subscribe({ next: (response) => { return this._odata.Upload(this.Path, { ContentType: contentType, FileName: fileName, Overwrite: overwrite, ChunkToken: response }, false); } }); return uploadCreation; } } exports.Collection = Collection; //# sourceMappingURL=Collection.js.map |