ContentStore.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /**
  4. * Licensed Materials - Property of IBM
  5. * IBM Business Analytics (C) Copyright IBM Corp. 2020
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['../../../lib/@waca/dashboard-common/dist/core/APIFactory', './api/ContentStoreAPI', 'underscore'], function (APIFactory, ContentStoreAPI, _) {
  9. var ContentStore = function () {
  10. function ContentStore(ajaxService) {
  11. _classCallCheck(this, ContentStore);
  12. this.ajaxService = ajaxService;
  13. this.baseObjectUrl = 'v1/objects';
  14. }
  15. ContentStore.prototype.getAPI = function getAPI() {
  16. if (!this._api) {
  17. this._api = APIFactory.createAPI(this, [ContentStoreAPI]);
  18. }
  19. return this._api;
  20. };
  21. ContentStore.prototype.get = function get() {
  22. var id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '.my_folders';
  23. var path = this._preparePath(id) + '/items?fields=id,type,defaultName,modificationTime,owner{defaultName,userName,email},version';
  24. return this.ajaxService.get(path).then(function (response) {
  25. return response && response.data.map(function (item) {
  26. return {
  27. id: item.id,
  28. type: item.type,
  29. defaultName: item.defaultName,
  30. modificationTime: item.modificationTime,
  31. owner: {
  32. defaultName: _.isEmpty(item.owner) ? undefined : item.owner[0].defaultName,
  33. userName: _.isEmpty(item.owner) ? undefined : item.owner[0].userName,
  34. email: _.isEmpty(item.owner) ? undefined : item.owner[0].email
  35. },
  36. version: item.version
  37. };
  38. }) || [];
  39. }).catch(function (dfd, error) {
  40. return Promise.reject({
  41. status: error.status
  42. });
  43. });
  44. };
  45. ContentStore.prototype.delete = function _delete(id) {
  46. var path = this._preparePath(id) + '?force=true&recursive=true';
  47. return this.ajaxService.delete(path).then().catch(function (dfd, error) {
  48. return Promise.reject({
  49. status: error.status
  50. });
  51. });
  52. };
  53. ContentStore.prototype.post = function post(id, content) {
  54. var path = this._preparePath(id) + '/items';
  55. return this.ajaxService.post(path, {
  56. contentType: 'application/json',
  57. processData: false,
  58. dataType: 'text',
  59. data: JSON.stringify(content)
  60. }).then().catch(function (dfd, error) {
  61. return Promise.reject({
  62. status: error.status
  63. });
  64. });
  65. };
  66. ContentStore.prototype.put = function put(id, content) {
  67. var path = this._preparePath(id);
  68. return this.ajaxService.put(path, {
  69. contentType: 'application/json',
  70. processData: false,
  71. dataType: 'text',
  72. data: JSON.stringify(content)
  73. }).then().catch(function (dfd, error) {
  74. return Promise.reject({
  75. status: error.status
  76. });
  77. });
  78. };
  79. ContentStore.prototype._preparePath = function _preparePath(id) {
  80. return this.baseObjectUrl + '/' + id;
  81. };
  82. return ContentStore;
  83. }();
  84. return ContentStore;
  85. });
  86. //# sourceMappingURL=ContentStore.js.map