123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- /**
- * Licensed Materials - Property of IBM
- * IBM Business Analytics (C) Copyright IBM Corp. 2020
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['../../../lib/@waca/dashboard-common/dist/core/APIFactory', './api/ContentStoreAPI', 'underscore'], function (APIFactory, ContentStoreAPI, _) {
- var ContentStore = function () {
- function ContentStore(ajaxService) {
- _classCallCheck(this, ContentStore);
- this.ajaxService = ajaxService;
- this.baseObjectUrl = 'v1/objects';
- }
- ContentStore.prototype.getAPI = function getAPI() {
- if (!this._api) {
- this._api = APIFactory.createAPI(this, [ContentStoreAPI]);
- }
- return this._api;
- };
- ContentStore.prototype.get = function get() {
- var id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '.my_folders';
- var path = this._preparePath(id) + '/items?fields=id,type,defaultName,modificationTime,owner{defaultName,userName,email},version';
- return this.ajaxService.get(path).then(function (response) {
- return response && response.data.map(function (item) {
- return {
- id: item.id,
- type: item.type,
- defaultName: item.defaultName,
- modificationTime: item.modificationTime,
- owner: {
- defaultName: _.isEmpty(item.owner) ? undefined : item.owner[0].defaultName,
- userName: _.isEmpty(item.owner) ? undefined : item.owner[0].userName,
- email: _.isEmpty(item.owner) ? undefined : item.owner[0].email
- },
- version: item.version
- };
- }) || [];
- }).catch(function (dfd, error) {
- return Promise.reject({
- status: error.status
- });
- });
- };
- ContentStore.prototype.delete = function _delete(id) {
- var path = this._preparePath(id) + '?force=true&recursive=true';
- return this.ajaxService.delete(path).then().catch(function (dfd, error) {
- return Promise.reject({
- status: error.status
- });
- });
- };
- ContentStore.prototype.post = function post(id, content) {
- var path = this._preparePath(id) + '/items';
- return this.ajaxService.post(path, {
- contentType: 'application/json',
- processData: false,
- dataType: 'text',
- data: JSON.stringify(content)
- }).then().catch(function (dfd, error) {
- return Promise.reject({
- status: error.status
- });
- });
- };
- ContentStore.prototype.put = function put(id, content) {
- var path = this._preparePath(id);
- return this.ajaxService.put(path, {
- contentType: 'application/json',
- processData: false,
- dataType: 'text',
- data: JSON.stringify(content)
- }).then().catch(function (dfd, error) {
- return Promise.reject({
- status: error.status
- });
- });
- };
- ContentStore.prototype._preparePath = function _preparePath(id) {
- return this.baseObjectUrl + '/' + id;
- };
- return ContentStore;
- }();
- return ContentStore;
- });
- //# sourceMappingURL=ContentStore.js.map
|