Skip to content

Commit

Permalink
v6.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Aymkdn committed Feb 1, 2021
1 parent e67c703 commit 90df9ca
Show file tree
Hide file tree
Showing 42 changed files with 1,867 additions and 343 deletions.
2 changes: 1 addition & 1 deletion browser/sharepointplus.js

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

**Change Log v6.1.4 (February 1, 2021)**

- Added `$SP().list().removeAttachment()`
- Added `$SP().list().getVersions()`
- Added `$SP().list().restoreVersion()`
– Changed `$SP().list().stopWorkflow()` to not use `iframe` and make it work with NodeJS Server Application
- Fixed a Sharepoint bug: if a list has the versioning enabled, then add/remove an attachment will created an empty version which could reset the values for the "Multiple Lines of Text" fields with "Append" option – `$SP().list().addAttachment()` and `$SP().list().removeAttachment()` will restore the previous version to avoid this buggy behavior
- Fixed `$SP().list().get()` with option `json:true` to return an object for each item instead of an array of keys
- Fixed `$SP().list().getWorkflowID()` when there are more than 1 workflow for an item (see https://github.com/Aymkdn/SharepointPlus/issues/162)

**Change Log v6.1.3 (January 8, 2021)**

- Added `$SP().getServerTime()` to return the server time
Expand Down
9 changes: 9 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ var _getContentTypeInfo = _interopRequireDefault(require("./lists/getContentType

var _getContentTypes = _interopRequireDefault(require("./lists/getContentTypes.js"));

var _getVersions = _interopRequireDefault(require("./lists/getVersions.js"));

var _getWorkflowID = _interopRequireDefault(require("./lists/getWorkflowID.js"));

var _hasPermission = _interopRequireDefault(require("./lists/hasPermission.js"));
Expand All @@ -52,6 +54,10 @@ var _parseRecurrence = _interopRequireDefault(require("./lists/parseRecurrence.j

var _remove = _interopRequireDefault(require("./lists/remove.js"));

var _removeAttachment = _interopRequireDefault(require("./lists/removeAttachment.js"));

var _restoreVersion = _interopRequireDefault(require("./lists/restoreVersion.js"));

var _setReadOnly = _interopRequireDefault(require("./lists/setReadOnly.js"));

var _startWorkflow = _interopRequireDefault(require("./lists/startWorkflow.js"));
Expand Down Expand Up @@ -159,6 +165,7 @@ var _default = spInit({
getAttachment: _getAttachment.default,
getContentTypeInfo: _getContentTypeInfo.default,
getContentTypes: _getContentTypes.default,
getVersions: _getVersions.default,
getWorkflowID: _getWorkflowID.default,
hasPermission: _hasPermission.default,
history: _history.default,
Expand All @@ -169,6 +176,8 @@ var _default = spInit({
parse: _parse.default,
parseRecurrence: _parseRecurrence.default,
remove: _remove.default,
removeAttachment: _removeAttachment.default,
restoreVersion: _restoreVersion.default,
setReadOnly: _setReadOnly.default,
startWorkflow: _startWorkflow.default,
startWorkflow2013: _startWorkflow2.default,
Expand Down
79 changes: 71 additions & 8 deletions dist/lists/addAttachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ _Object$defineProperty(exports, "__esModule", {

exports.default = addAttachment;

var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs3/regenerator"));

var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));

var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));

var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice"));

var _ajax = _interopRequireDefault(require("../utils/ajax.js"));
Expand All @@ -20,6 +24,10 @@ var _buildBodyForSOAP2 = _interopRequireDefault(require("./_buildBodyForSOAP.js"

var _arrayBufferToBase = _interopRequireDefault(require("../utils/arrayBufferToBase64.js"));

var _getVersions = _interopRequireDefault(require("./getVersions.js"));

var _restoreVersion = _interopRequireDefault(require("./restoreVersion.js"));

/**
@name $SP().list.addAttachment
@function
Expand Down Expand Up @@ -68,7 +76,6 @@ var _arrayBufferToBase = _interopRequireDefault(require("../utils/arrayBufferToB
function addAttachment(setup) {
var _this = this;

// check if we need to queue it
if (arguments.length === 0) throw "[SharepointPlus 'addAttachment'] the arguments are mandatory.";
if (!this.listID) throw "[SharepointPlus 'addAttachment'] the list ID/Name is required.";
if (!this.url) throw "[SharepointPlus 'addAttachment'] not able to find the URL!"; // we cannot determine the url
Expand All @@ -90,13 +97,69 @@ function addAttachment(setup) {
headers: {
'SOAPAction': 'http://schemas.microsoft.com/sharepoint/soap/AddAttachment'
}
}).then(function (data) {
var res = data.getElementsByTagName('AddAttachmentResult');
res = res.length > 0 ? res[0] : null;
var fileURL = "";
if (res) fileURL = _this.url + "/" + res.firstChild.nodeValue;
if (!fileURL) return _promise.default.reject(res);else return fileURL;
});
}).then(
/*#__PURE__*/
function () {
var _ref = (0, _asyncToGenerator2.default)(
/*#__PURE__*/
_regenerator.default.mark(function _callee(data) {
var res, fileURL, versions, versionID;
return _regenerator.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
res = data.getElementsByTagName('AddAttachmentResult');
res = res.length > 0 ? res[0] : null;
fileURL = "";
if (res) fileURL = _this.url + "/" + res.firstChild.nodeValue;

if (fileURL) {
_context.next = 6;
break;
}

return _context.abrupt("return", _promise.default.reject(res));

case 6:
_context.prev = 6;
_context.next = 9;
return _getVersions.default.call(_this, setup.ID);

case 9:
versions = _context.sent;

if (!(versions.length > 0)) {
_context.next = 14;
break;
}

versionID = versions[versions.length - 1].VersionID;
_context.next = 14;
return _restoreVersion.default.call(_this, {
ID: setup.ID,
VersionID: versionID
});

case 14:
return _context.abrupt("return", fileURL);

case 17:
_context.prev = 17;
_context.t0 = _context["catch"](6);
return _context.abrupt("return", fileURL);

case 20:
case "end":
return _context.stop();
}
}
}, _callee, null, [[6, 17]]);
}));

return function (_x) {
return _ref.apply(this, arguments);
};
}());
}

module.exports = exports.default;
5 changes: 4 additions & 1 deletion dist/lists/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-st

var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));

var _assign = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/assign"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/createClass"));
Expand Down Expand Up @@ -63,7 +65,8 @@ var extendMyObject =
function () {
function extendMyObject(arr) {
(0, _classCallCheck2.default)(this, extendMyObject);
this.attributes = arr;
//this.attributes=arr;
this.attributes = (0, _assign.default)({}, arr);
}

(0, _createClass2.default)(extendMyObject, [{
Expand Down
127 changes: 127 additions & 0 deletions dist/lists/getVersions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
"use strict";

var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");

var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");

_Object$defineProperty(exports, "__esModule", {
value: true
});

exports.default = getVersions;

var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs3/regenerator"));

var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));

var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array"));

var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));

var _info = _interopRequireDefault(require("./info.js"));

var _ajax = _interopRequireDefault(require("../utils/ajax.js"));

/**
@name $SP().list.getVersions
@function
@description When versionning is activated on a list, you can use this function to get the different version label/number for a list item
@param {Number} ID The item ID
@return {Promise} resolve(arrayOflistOfVersions)
@example
$SP().list("My List").getVersions({
ID:1
}).then(function(versions) {
versions.forEach(function(version) {
console.log(version);
// returns:
// - CheckInComment
// - Created
// - VersionID
// - IsCurrentVersion (boolean)
// - VersionLabel (e.g. "1.0", "2.0", …)
})
});
*/
function getVersions(_x) {
return _getVersions.apply(this, arguments);
}

function _getVersions() {
_getVersions = (0, _asyncToGenerator2.default)(
/*#__PURE__*/
_regenerator.default.mark(function _callee(itemID) {
var infos, rootFolder;
return _regenerator.default.wrap(function _callee$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
if (this.listID) {
_context2.next = 2;
break;
}

throw "[SharepointPlus 'getVersions'] the list ID/Name is required.";

case 2:
if (this.url) {
_context2.next = 4;
break;
}

throw "[SharepointPlus 'getVersions'] not able to find the URL!";

case 4:
if (itemID) {
_context2.next = 6;
break;
}

throw "[SharepointPlus 'getVersions'] the item ID is required.";

case 6:
_context2.next = 8;
return _info.default.call(this);

case 8:
infos = _context2.sent;
rootFolder = infos._List.RootFolder; // if no versionning

if (!(infos._List.EnableVersioning !== "True")) {
_context2.next = 12;
break;
}

return _context2.abrupt("return", []);

case 12:
return _context2.abrupt("return", _ajax.default.call(this, {
url: this.url + "/_api/web/GetFileByServerRelativeUrl('" + encodeURIComponent(rootFolder + "/" + itemID + "_.000") + "')/Versions"
}).then(function (res) {
var _context;

if (!res || !res.d || !(0, _isArray.default)(res.d.results)) return [];
return (0, _map.default)(_context = res.d.results).call(_context, function (item) {
return {
CheckInComment: item.CheckInComment,
Created: item.Created,
VersionID: item.ID,
IsCurrentVersion: item.IsCurrentVersion,
VersionLabel: item.VersionLabel
};
});
}));

case 13:
case "end":
return _context2.stop();
}
}
}, _callee, this);
}));
return _getVersions.apply(this, arguments);
}

module.exports = exports.default;
Loading

0 comments on commit 90df9ca

Please sign in to comment.