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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 | 1x 1x 1x 1x 1x 34x 59x 435x 37x 435x 8x 8x 8x 3x 6x 6x 26x 4x 6x 22x 22x 1320x 22x 5x 435x 2x 2x 2x 120x 2x 435x 435x 435x 435x 2x 1x 1x 1x 1x 1x 4x 2x 2x 2x 2x 2x 2x 2x 13x 13x 13x 8x 1x 1x 1x 7x 1x 1x 1x 6x 1x 1x 1x 1x 1x 1x 5x 2x 2x 2x 5x 1x 5x 5x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 1x 2x 1x 1x 1x 1x 1x 1x 1x 1x 13x 13x 9x 6x 1x 9x 5x 5x 1x 3x 3x 2x 2x 2x 2x 4x 1x 3x 1x 2x 2x 1x 2x 2x 1x 1x 1x 2x 1x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 412x 361x 1325x 51x 1x 50x 876x 50x 48x 48x 50x 50x 29x 29x 383x 383x 1x 2x 1x 1x 2x 2x 2x 1x 2x 2x 2x 2x 1x 2x 3x 1x 1x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 12x 12x 6x 4x 1x 23x 21x 2x 2x 21x 7x 1x 6x 1x 5x 5x 5x 4x 4x 6x 2x 4x 6x 2x 4x 2x 2x 2x 435x | /** * @module Content * @preferred * * @description Top level base type of sense NET's Type hierarchy. * * Content has the basic properties and functionality that can be reached on all of the inherited types. It's almost the same as an abstract class, it may not be instantiated directly, * but it has the basic methods implemented that can be called on obejcts with derived types. * * Unlike other Content Types it is not autogenerated. * * Actions * ------------------ * * Built-in SenseNet Actions on client-side are methods on the Content object. If you want to use them you have to have a Content which can be made with the Create method that can convert your js Object or JSON * with the proper parameters to a Content with the given type. * ``` * var content = Content.Create('Folder', {DisplayName: 'My folder'}); * ``` * On a Content object the Actions can be called like this way (check below sections for further information about the Actions and their params): * ``` * let contentDelete = content.Delete(false); * ``` * This function returns an Observable so that you can subscribe to it in your code. This way you can work with the response easier defining the three functions of a subscribtion and * using all the super helpful and usable features like filtering, combining, caching, etc. * ``` * contentDelete.subscribe({ * .map(response => response.d) //map and use the reponse's 'd' object as the response * .subscribe({ * next: response => console.log(response), //if the request was successful * error: error => console.error('something wrong occurred: ' + error), //if the request failed * complete: () => console.log('done'), //if the request is done * }) * }); * ``` * Using RxJS you are able to merge, zip or combine multiple Observables, this way you can develope various combinations of Actions with custom functionality. * * Read more about RxJS [here](http://reactivex.io/rxjs) * * And about Reactive Programming [here](https://gist.github.com/staltz/868e7e9bc2a7b8c1f754) it could be helpful not only with ajax request but also with event handling or anything else * related to async data streams. */ /** */ import { Schemas, Security, Enums, ODataHelper, ComplexTypes, ContentTypes } from './SN'; import { ODataRequestOptions, ODataParams, ODataApi } from './ODataApi'; import { Observable } from '@reactivex/rxjs'; import { ActionModel } from './Repository/ActionModel'; import { BaseRepository } from './Repository/BaseRepository'; import { BaseHttpProvider } from './HttpProviders/BaseHttpProvider'; import { ContentSerializer } from './ContentSerializer'; export class Content { private readonly odata: ODataApi<BaseHttpProvider, Content>; /** * An unique identifier for a content */ Id?: number; /** * Name of the Content */ Name?: string; private _type?: string; /** * Type of the Content, e.g.: 'Task' or 'User' */ public get Type(): string { return this._type || this.constructor.name; } public set Type(newType: string) { this._type = newType; } private _isSaved: boolean = false; /** * Indicates if the content is saved into the Repository or is a new Content */ public get IsSaved(): boolean { return this._isSaved; } private _lastSavedFields: this['options'] = {}; protected UpdateLastSavedFields(newFields: this['options']) { this._lastSavedFields = newFields; this._isSaved = true; Object.assign(this, newFields); } /** * Returns a list about the fields with their values, as they are saved into the Repository */ public get SavedFields() { return !this.IsSaved ? {} : JSON.parse(JSON.stringify(this._lastSavedFields)); } /** * Returns a list about the changed fields and their new values */ public GetChanges(): this['options'] { const changedFields: this['options'] = {}; for (let field in this.GetFields()) { if (this[field] !== this._lastSavedFields[field]) { changedFields[field] = this[field]; } } return changedFields; } /** * Returns all Fields based on the Schema, that can be used for API calls (e.g. POSTing a new content) */ public GetFields(skipEmpties?: boolean): this['options'] { const fieldsToPost = {} as this['options']; this.GetSchema().FieldSettings.forEach(s => { ((!skipEmpties && this[s.Name] !== undefined) || (skipEmpties && this[s.Name])) && (fieldsToPost[s.Name] = this[s.Name]); }); return fieldsToPost; } /** * Shows if the content has been changed on client-side since the last load */ public get IsDirty(): boolean { return Object.keys(this.GetChanges()).length > 0; } private _isOperationInProgress: boolean = false; /** * Shows if there are any operation in progress */ public get IsOperationInProgress() { return this._isOperationInProgress; } /** * Indicates that all required fields are filled */ public get IsValid(): boolean { const schema = this.GetSchema(); const missings = schema.FieldSettings .filter(s => s.Compulsory && !(this as any)[s.Name]) return missings.length === 0; } DisplayName?: string; Description?: string; Icon?: string; IsFolder?: boolean; Path?: string; Index?: number; CreationDate?: string; ModificationDate?: string; Versions?: ComplexTypes.DeferredObject; Workspace?: ComplexTypes.DeferredObject; /** * @constructs Content * @param {IContentOptions} options An object implementing IContentOptions interface * @param {IRepository} repository The Repoitory instance */ constructor(public readonly options: IContentOptions, private repository: BaseRepository) { Object.assign(this, options); Object.assign(this._lastSavedFields, options); this.odata = repository.GetODataApi(); } /** * Deletes a content item from the Content Repository (by default the Content is moved to the Trash). * @param permanently {boolean} Determines if the Content should be deleted permanently or moved to the Trash. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let delContent = content.Delete(false); * delContent.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error), * complete: () => console.log('done'), * }); * ``` */ Delete(permanently?: boolean): Observable<any> { if (this.Id) { const fields = this.GetFields(); const observable = this.odata.Delete(this.Id, permanently); observable.subscribe(() => { this.repository['onContentDeletedSubject'].next({ contentData: fields, permanently: permanently || false }); }, (err) => { this.repository['onContentDeleteFailedSubject'].next({ content: this, permanently: permanently || false, error: err }); }) return observable; } return Observable.of(undefined); } /** * Modifies the DisplayName or the DisplayName and the Name of a content item in the Content Repository. * @param {string} newDisplayNameNew display name of the content. * @param {string} newName New name of the content. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let rename = content.Rename('New Title'); * rename.subscribe({ * next: response => { * console.log(response); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ Rename(newDisplayName: string, newName?: string): Observable<this> { if (!this.IsSaved) { throw new Error('Content is not saved. You can rename only saved content!') } let fields: this['options'] = {}; Eif (newDisplayName) { fields.DisplayName = newDisplayName; } Eif (newName) { fields.Name = newName; } return this.Save(fields); } private saveContentInternal(fields?: this['options'], override?: boolean): Observable<this> { const contentType = this.constructor as { new(...args: any[]): any }; const originalFields = this.GetFields(); /** Fields Save logic */ if (fields) { if (!this.Id) { const err = new Error('Content Id not present'); this.repository['onContentModificationFailedSubject'].next({ content: this, change: fields, error: err }); throw err; } if (!this.IsSaved) { const err = new Error('The Content is not saved to the Repository, Save it before updating.') this.repository['onContentModificationFailedSubject'].next({ content: this, change: fields, error: err }); throw err; } if (override) { const request = this.odata.Put(this.Id, contentType, fields) .map(newFields => { this.UpdateLastSavedFields(newFields); this.repository['onContentModifiedSubject'].next({ content: this, originalFields: originalFields, change: fields }); return this; }).share(); request.subscribe(() => { }, err => { this.repository['onContentModificationFailedSubject'].next({ content: this, change: fields, error: err }); }) return request; } else { const request = this.odata.Patch(this.Id, contentType, fields) .map(newFields => { this.UpdateLastSavedFields(newFields); this.repository['onContentModifiedSubject'].next({ content: this, originalFields: originalFields, change: fields }); return this; }).share(); request.subscribe(() => { }, err => { this.repository['onContentModificationFailedSubject'].next({ content: this, change: fields, error: err }); }) return request; } } if (!this.IsSaved) { // Content not saved, verify Path and POST it if (!this.Path) { const err = new Error('Cannot create content without a valid Path specified'); this.repository['onContentCreateFailedSubject'].next({ content: this, error: err }); throw err; } const request = this.odata.Post<this>(this.Path, this.GetFields(true), contentType) .map(resp => { Iif (!resp.Id) { throw Error('Error: No content Id in response!'); } this.UpdateLastSavedFields(resp); this.repository['_loadedContentReferenceCache'][resp.Id] = this; this._isSaved = true; this.repository['onContentCreatedSubject'].next(this); return this; }).share(); request.subscribe(() => { }, err => { this.repository['onContentCreateFailedSubject'].next({ content: this, error: err }); }); return request; } else { // Content saved if (!this.IsDirty) { // No changes, no request return Observable.of(this); } else { if (!this.Id) { throw new Error('Content Id not present'); } const changes = this.GetChanges(); // Patch content const request = this.odata.Patch<this>(this.Id, contentType, changes) .map(resp => { this.UpdateLastSavedFields(resp); this.repository['onContentModifiedSubject'].next({ content: this, change: changes, originalFields: originalFields }); return this; }).share(); request.subscribe(() => { }, err => { this.repository['onContentModificationFailedSubject'].next({ content: this, change: changes, error: err }); }) return request; } } } /** * Saves the content with its given modified fields to the Content Repository. * @params fields {Object} Object with the fields that have to be modified. * @params override {boolean=} [false] Determines whether clear the fields that are not given (true) or leave them and modify only the given fields (false). * @params options {Object=} JSON object with the possible ODATA parameters like select, expand, etc. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let save = content.Save({'Index':2}, true); //Set Index field's value to 2 and clear the rest of the fields. * save.subscribe({ * next: response => { * console.log(response); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ Save(fields?: this['options'], override?: boolean): Observable<this> { this._isOperationInProgress = true; const saveObservable = this.saveContentInternal(fields, override).share(); saveObservable.subscribe(success => { this._isOperationInProgress = false; }, (err) => { this._isOperationInProgress = false; }); return saveObservable; } /** * Method that returns actions of a content. * @params options {Object} JSON object with the possible ODATA parameters like select, expand, etc. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let actions = content.Actions('ListItem'); * actions.subscribe({ * next: response => { * console.log(response); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ Actions(scenario?: string): Observable<ActionModel[]> { let optionList = this.GetDeferredRequestOptions('Actions', new ODataParams({ scenario: scenario })); return this.odata.Get(optionList, Object as { new(...args) }) .map(resp => { return resp.d.Actions; }); } /** * Method that returns allowed child type list of a content. * @params options {Object} JSON object with the possible ODATA parameters like select, expand, etc. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let allowedChildTypes = content.GetAllowedChildTypes(); * allowedChildTypes.subscribe({ * next: response => { * console.log(response); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ GetAllowedChildTypes(options?: ODataParams): Observable<ContentTypes.ContentType[]> { return this.GetDeferredCollection('AllowedChildTypes', options, ContentTypes.ContentType); } /** * Method that returns effective allowed child type list of a content. * @params options {Object} JSON object with the possible ODATA parameters like select, expand, etc. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let allowedChildTypes = content.GetEffectiveAllowedChildTypes(); * allowedChildTypes.subscribe({ * next: response => { * console.log(response); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ GetEffectiveAllowedChildTypes(options?: ODataParams): Observable<ContentTypes.ContentType[]> { return this.GetDeferredCollection('EffectiveAllowedChildTypes', options, ContentTypes.ContentType); } /** * Method that returns owner of a content. * @params options {Object} JSON object with the possible ODATA parameters like select, expand, etc. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let owner = content.GetOwner({select: ['FullName']}); * owner.subscribe({ * next: response => { * console.log(response); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ GetOwner(options?: ODataParams): Observable<ContentTypes.User> { return this.GetDeferredContent('Owner', options, ContentTypes.User); } /** * Method that returns creator of a content. * @params options {Object} JSON object with the possible ODATA parameters like select, expand, etc. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let creator = content.Creator({select: ['FullName']}); * creator.subscribe({ * next: response => { * console.log(response); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ Creator(options?: ODataParams): Observable<ContentTypes.User> { return this.GetDeferredContent('CreatedBy', options, ContentTypes.User); } /** * Method that returns last modifier of a content. * @params options {Object} JSON object with the possible ODATA parameters like select, expand, etc. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let modifier = content.Modifier({select: ['FullName']}); * modifier.subscribe({ * next: response => { * console.log(response); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ Modifier(options?: ODataParams): Observable<ContentTypes.User> { return this.GetDeferredContent('ModifiedBy', options, ContentTypes.User); } /** * Method that returns the user who checked-out the content. * @params options {Object} JSON object with the possible ODATA parameters like select, expand, etc. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let checkedOutBy = content.CheckedOutBy({select: ['FullName']}); * checkedOutBy.subscribe({ * next: response => { * console.log(response); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ CheckedOutBy(options?: ODataParams): Observable<ContentTypes.User> { return this.GetDeferredContent('CheckedOutTo', options, ContentTypes.User); } /** * Method that returns the children of a content. * * Calls the method [FetchContent]{@link ODataApi.FetchContent} with the contents id and the given OData options. * If you leave the options undefined only the Id and the Type fields will be in the response. These two fields are always the part of the reponse whether they're added or not to the options * as selectable. * @params options {Object} JSON object with the possible ODATA parameters like select, expand, etc. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let children = content.Children({select: ['DisplayName']}); * children.subscribe({ * next: response => { * console.log(response); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ Children(options?: ODataParams): Observable<Content[]> { if (!this.Path) { throw new Error('No path specified'); } return this.odata.Fetch(new ODataRequestOptions({ path: this.Path, params: options }), Content).map(resp => { return resp.d.results.map(c => this.repository.HandleLoadedContent(c)); }); } /** * Returns the list of versions. * * Calls the method [GetContent]{@link ODataApi.GetContent} with the contents id and the given OData options. * If you leave the options undefined only the Id and the Type fields will be in the response. These two fields are always the part of the reponse whether they're added or not to the options * as selectable. * @params options {Object} JSON object with the possible ODATA parameters like select, expand, etc. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let versions = content.GetVersions(); * versions.subscribe({ * next: response => { * console.log(response); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ GetVersions(options?: ODataParams): Observable<this[]> { return this.GetDeferredContent('Versions', options, this.constructor as { new() }); } /** * Returns the current Workspace. * * Calls the method [GetContent]{@link ODataApi.GetContent} with the contents id and the given OData options. * If you leave the options undefined only the Id and the Type fields will be in the response. These two fields are always the part of the reponse whether they're added or not to the options * as selectable. * @params options {Object} JSON object with the possible ODATA parameters like select, expand, etc. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let currentWorkspace = content.GetWorkspace(); * currentWorkspace.subscribe({ * next: response => { * console.log(response); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ GetWorkspace(options?: ODataParams): Observable<Content> { return this.GetDeferredContent('Workspace', options, Content); } /** * Checkouts a content item in the Content Repository. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let checkoutContent = content.Checkout(); * checkoutContent.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ Checkout() { return this.odata.CreateCustomAction({ name: 'CheckOut', id: this.Id, isAction: true }); } /** * Checkins a content item in the Content Repository. * @params checkInComments {string=} * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let checkinContent = content.Checkin(); * checkinContent.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ CheckIn(checkInComments?: string) { let action; (typeof checkInComments !== 'undefined') ? action = { name: 'CheckIn', id: this.Id, isAction: true, params: ['checkInComments'] } : action = { name: 'CheckIn', id: this.Id, isAction: true }; return this.odata.CreateCustomAction(action, { data: { 'checkInComments': checkInComments ? checkInComments : '' } }); } /** * Performs an undo check out operation on a content item in the Content Repository. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let undoCheckoutContent = content.UndoCheckout(); * undoCheckoutContent.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ UndoCheckout() { return this.odata.CreateCustomAction({ name: 'UndoCheckOut', id: this.Id, isAction: true }); } /** * Performs a force undo check out operation on a content item in the Content Repository. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let forceUndoCheckoutContent = content.ForceUndoCheckout(); * forceUndoCheckoutContent.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ ForceUndoCheckout() { return this.odata.CreateCustomAction({ name: 'ForceUndoCheckout', id: this.Id, isAction: true }); } /** * Performs an approve operation on a content, the equivalent of calling Approve() on the Content instance in .NET. Also checks whether the content handler of the subject content * inherits GenericContent (otherwise it does not support this operation). This action has no parameters. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let approveContent = content.Approve(); * approveContent.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ Approve() { return this.odata.CreateCustomAction({ name: 'Approve', id: this.Id, isAction: true }); } /** * Performs a reject operation on a content, the equivalent of calling Reject() on the Content instance in .NET. Also checks whether the content handler * of the subject content inherits GenericContent (otherwise it does not support this operation). The reject reason can be supplied in an optional parameter called rejectReason. * @params rejectReason {string} * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let rejectContent = content.Reject(); * rejectContent.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ Reject(rejectReason?: string) { return this.odata.CreateCustomAction({ name: 'Reject', id: this.Id, isAction: true, params: ['rejectReason'] }, { data: { 'rejectReason': rejectReason ? rejectReason : '' } }); } /** * Performs a publish operation on a content, the equivalent of calling Publish() on the Content instance in .NET. Also checks whether the content handler of the subject content * inherits GenericContent (otherwise it does not support this operation). This action has no parameters. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let publishContent = content.Publish(); * publishContent.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ Publish(rejectReason?: string) { return this.odata.CreateCustomAction({ name: 'Publish', id: this.Id, isAction: true }); } /** * Restores an old version of the content. Also checks whether the content handler of the subject content inherits GenericContent (otherwise it does not support this operation). * This action has a single parameter called version where the caller can specify which old version to restore. * @params version {string} Old version to restore. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let restoreVersion = content.RestoreVersion(); * restoreVersion.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ RestoreVersion(version: string) { return this.odata.CreateCustomAction({ name: 'Publish', id: this.Id, isAction: true, requiredParams: ['version'] }, { data: { 'version': version ? version : '' } }); } /** * Restores a deleted content from the Trash. You can call this action only on a TrashBag content that contains the deleted content itself. * @params destination {string=} Path of the target container, where the deleted content will be restored. If it is not provided, the system uses the original path stored on the trash bag content. * @params newname {boolean=} whether to generate a new name automatically if a content with the same name already exists in the desired container (e.g. mydocument(1).docx). * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let restoreContent = content.Restore(); * restoreContent.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ Restore(destination?: string, newname?: boolean) { return this.odata.CreateCustomAction( { name: 'Restore', id: this.Id, isAction: true, params: ['destination', 'newname'] }, { data: { 'destination': destination ? destination : '', 'newname': newname ? newname : '' } }); } /** * Copies one content to another container by a given path. * @params Path {string} * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let moveContent = content.MoveTo('/Root/Sites/Default_Site/NewsDemo/Internal'); * moveContent.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ MoveTo(toPath: string) { Iif (!this.Path) { throw new Error('No Path provided for the content'); } Iif (!this.Name) { throw new Error('No Name provided for the content'); } const request = this.odata.CreateCustomAction({ name: 'MoveTo', id: this.Id, isAction: true, requiredParams: ['targetPath'] } , { data: { 'targetPath': toPath } }); const fromPath = this.Path; const newPath = ODataHelper.joinPaths(toPath, this.Name); request.subscribe(result => { this.Path = newPath; this.UpdateLastSavedFields({ Path: newPath }); this.repository['onContentMovedSubject'].next({ content: this, fromPath, toPath: toPath }) }, err => { this.repository['onContentMoveFailedSubject'].next({ content: this, fromPath, toPath: toPath, err }); }); return request; } /** * Copies one content to another container by a given path. * @params Path {string} * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let copyContent = content.CopyTo('/Root/Sites/Default_Site/NewsDemo/Internal'); * copyContent.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ CopyTo(path: string) { return this.odata.CreateCustomAction({ name: 'CopyTo', id: this.Id, isAction: true, requiredParams: ['targetPath'] }, { data: { 'targetPath': path ? path : '' } }); } /** * Adds the given content types to the Allowed content Type list. * @params contentTypes {string[]} A list of the case sensitive content type names. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let setAllowedChildTypes = content.AddAllowedChildTypes(['Folder','ContentList']]); * setAllowedChildTypes.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ AddAllowedChildTypes(contentTypes: string[]) { return this.odata.CreateCustomAction({ name: 'AddAllowedChildTypes', id: this.Id, isAction: true, requiredParams: ['contentTypes'] }, { data: { 'contentTypes': contentTypes } }); } /** * Removes the given content types from the Allowed content Type list. If the list after removing and the list on the matching CTD are the same, the local list will be removed. * @params contentTypes {string[]} A list of the case sensitive content type names. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let removeAllowedChildTypes = content.RemoveAllowedChildTypes(['Folder','ContentList']]); * removeAllowedChildTypes.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ RemoveAllowedChildTypes(contentTypes: string[]) { return this.odata.CreateCustomAction({ name: 'RemoveAllowedChildTypes', id: this.Id, isAction: true, requiredParams: ['contentTypes'] }, { data: { 'contentTypes': contentTypes } }); } private static _schemaCache: Schemas.Schema<Content>[] = []; /** * Returns the Content Type Schema of the given Content Type; * @param type {string} The name of the Content Type; * @returns {Schemas.Schema} * ```ts * var genericContentSchema = SenseNet.Content.getSchema(Content); * ``` */ public static GetSchema<TType extends Content>(currentType: { new(...args: any[]): TType }): Schemas.Schema<TType> { if (this._schemaCache[currentType.name as any]) { return this._schemaCache[currentType.name as any] as Schemas.Schema<TType>; } const schema = Schemas.SchemaStore.find(s => s.ContentType === currentType) as Schemas.Schema<TType>; if (!schema) { throw new Error(`No Schema for Content Type '${currentType.name}'`) } const parent = Object.getPrototypeOf(currentType); const parentSchema = parent && Schemas.SchemaStore.find(s => s.ContentType === parent); if (parentSchema) { let parentSchema = Content.GetSchema(parent); schema.FieldSettings = schema.FieldSettings.concat(parentSchema.FieldSettings); } this._schemaCache[currentType.name as any] = schema; return schema; } /** * Returns the Content Type Schema of the Content. * @returns {Schemas.Schema} Array of fieldsettings. *```ts * let schema = SenseNet.Content.GetSchema(Content); *``` */ GetSchema(): Schemas.Schema<this> { const contentType = (ContentTypes as any)[this.Type] as { new(...args) }; return Content.GetSchema(contentType || this.constructor as { new(...args: any[]): any }); } /** * Creates a Content object by the given type and options Object that hold the field values. * @param type {string} The Content will be a copy of the given type. * @param options {SenseNet.IContentOptions} Optional list of fields and values. * @returns {SenseNet.Content} * ```ts * var content = SenseNet.Content.Create('Folder', { DisplayName: 'My folder' }); // content is an instance of the Folder with the DisplayName 'My folder' * ``` */ public static Create<T extends Content, O extends T['options']>(newContent: { new(...args: any[]): T }, opt: O, repository: BaseRepository): T { let constructed = new newContent(opt, repository); return constructed; } // Shortcut to repository.HandleLoadedContent() // ToDo: Remove. Deprecated since ~2.1.0 - 2017.07.14. public static HandleLoadedContent: <T extends Content, O extends T['options']>(contentType: { new(...args: any[]): T }, opt: O, repository: BaseRepository) => T = (contentType, contentOptions, repository) => { console.warn('Method Content.HandleLoadedContent is deprecated and will be removed in the upcoming release. Please use repository.HandleLoadedContent instead.') return repository.HandleLoadedContent(contentOptions, contentType); } /** * Sets permissions on the requested content. You can add or remove permissions for one ore more users or groups using this action or even break/unbreak permission inheritance. * @param identities {Security.PermissionRequestBody[]} Permission entry list: array of permission entry objects, containing an identity Id or Path and one or more permission * settings for permission types (see examples below). * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let myPermissionRequestBody = new Security.PermissionRequestBody[ * {identity:"/Root/IMS/BuiltIn/Portal/Visitor", OpenMinor:"allow", Save:"deny"}, * {identity:"/Root/IMS/BuiltIn/Portal/Creators", Custom16:"A", Custom17:"1"} * ]; * let setPermissions = content.SetPermissions(myPermissionRequestBody); * setPermissions.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ /** * Sets permissions on the requested content. You can add or remove permissions for one ore more users or groups using this action or even break/unbreak permission inheritance. * @param inheritance {Security.Inheritance} inheritance: break or unbreak * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let setPermissions = content.SetPermissions({inheritance:"break"}); * setPermissions.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ SetPermissions(arg: Security.Inheritance | Security.PermissionRequestBody[]) { if (arg instanceof Array) { return this.odata.CreateCustomAction({ name: 'SetPermissions', id: this.Id, isAction: true, requiredParams: ['entryList'] }, { data: { 'entryList': arg } }); } else { return this.odata.CreateCustomAction({ name: 'SetPermissions', path: this.Path, isAction: true, requiredParams: ['inheritance'] }, { data: { 'inheritance': arg } }); } }; /** * Gets permissions for the requested content. If no identity is given, all the permission entries will be returned. * * Required permissions to call this action: See permissions. * @params identity {string=} path of the identity whose permissions must be returned (user, group or organizational unit) * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let getPermissions = content.GetPermission('/Root/Sites/Default_Site/workspaces/Project/budapestprojectworkspace/Groups/Members'); * getPermissions.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ GetPermission(identity?: string) { return this.odata.CreateCustomAction({ name: 'GetPermission', id: this.Id, isAction: false, params: ['identity'] }, { data: { 'identity': identity ? identity : '' } }); } /** * Gets if the given user (or if it is not given than the current user) has the specified permissions for the requested content. * * Required permissions to call this action: See permissions. * @params permissions {string[]} list of permission names (e.g. Open, Save) * @params user {string} [CurrentUser] path of the user * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let hasPermission = content.HasPermission(['AddNew', 'Save']); * hasPermission.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ HasPermission(permissions: ('See' | 'Preview' | 'PreviewWithoutWatermark' | 'PreviewWithoutRedaction' | 'Open' | 'OpenMinor' | 'Save' | 'Publish' | 'ForceCheckin' | 'AddNew' | 'Approve' | 'Delete' | 'RecallOldVersion' | 'DeleteOldVersion' | 'SeePermissions' | 'SetPermissions' | 'RunApplication' | 'ManageListsAndWorkspaces' | 'TakeOwnership' | 'Custom01' | 'Custom02' | 'Custom03' | 'Custom04' | 'Custom05' | 'Custom06' | 'Custom07' | 'Custom08' | 'Custom09' | 'Custom10' | 'Custom11' | 'Custom12' | 'Custom13' | 'Custom14' | 'Custom15' | 'Custom16' | 'Custom17' | 'Custom18' | 'Custom19' | 'Custom20' | 'Custom21' | 'Custom22' | 'Custom23' | 'Custom24' | 'Custom25' | 'Custom26' | 'Custom27' | 'Custom28' | 'Custom29' | 'Custom30' | 'Custom31' | 'Custom32')[], identity?: ContentTypes.User | ContentTypes.Group): Observable<boolean> { let params = `permissions=${permissions.join(',')}`; if (identity && identity.Path) { params += `&identity=${identity.Path}` }; return this.repository.Ajax(`${this.GetFullPath()}/HasPermission?${params}`, 'GET', Boolean as { new() }); } /** * Users who have TakeOwnership permission for the current content can modify the Owner of this content. * @params userOrGroup {string} path or the id of the new owner (that can be a Group or a User). The input parameter also supports empty or null string, * in this case the new owner will be the current user. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let takeOwnerShip = content.TakeOwnership({'userGroup':'/Root/IMS/BuiltIn/Portal/Admin'}); * takeOwnerShip.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ TakeOwnership(userOrGroup?: string) { return this.odata.CreateCustomAction({ name: 'TakeOwnership', id: this.Id, isAction: true, params: ['userOrGroup'] }, { data: { 'userOrGroup': userOrGroup ? userOrGroup : '' } }); } /** * Creates or modifies a {Query} content. Use this action instead of creating query content directly using the basic OData create method, because query content can be saved * under a workspace or to the user's profile as a private query. * @params query {string} Query text, composed in Query Builder or written manually (see Query syntax for more details). * @params displayName {string} Desired display name for the query content. Can be empty. * @params queryType {ComplexTypes.SavedQueryType} [Public] Type of the saved query. If an empty value is posted, the default is Public. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let saveQuery = content.SaveQuery({ * 'query':'DisplayName:Africa', * 'displayName': 'My query', * 'queryType': 'Private' * }); * saveQuery.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ SaveQuery(query: string, displayName: string, queryType: Enums.QueryType) { return this.odata.CreateCustomAction({ name: 'SaveQuery', id: this.Id, isAction: true, requiredParams: ['query', 'displayName', 'queryType'] }, { data: { 'query': query, 'displayName': displayName ? displayName : '', queryType: queryType } }); } /** * Gets Query content that are relevant in the current context. The result set will contain two types of content: * * Public queries: query content in the Queries content list of the current workspace. * * Private queries: query content in the Queries content list under the profile of the current user * @params onlyPublic {boolean} if true, only public queries are returned from the current workspace. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let getQueries = content.GetQueries(true); * getQueries.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ GetQueries(onlyPublic: boolean = true) { return this.odata.CreateCustomAction({ name: 'GetQueries', id: this.Id, isAction: false, noCache: true, requiredParams: ['onlyPublic'] }, { data: { 'onlyPublic': onlyPublic } }); } /** * Closes a Multistep saving operation and sets the saving state of a content to Finalized. Can be invoked only on content that are not already finalized. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let finalize = content.FinalizeContent(true); * finalize.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ Finalize() { return this.odata.CreateCustomAction({ name: 'FinalizeContent', id: this.Id, isAction: true }); } /** * Lets administrators take over the lock of a checked out document from another user. A new locker user can be provided using the 'user' parameter (user path or id as string). * If left empty, the current user will take the lock. * @params userId {number=} * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let takeLockOver = content.TakeLockOver(true); * takeLockOver.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ TakeLockOver(userId?: number) { return this.odata.CreateCustomAction({ name: 'TakeLockOver', id: this.Id, isAction: true, params: ['user'] }, { data: { 'user': userId ? userId : '' } }); } /** * These actions perform an indexing operation on a single content or a whole subtree. * @params recursive {boolean=} * @params rebuildLevel {number=} * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let rebuildIndex = content.RebuildIndex(true); * rebuildIndex.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ RebuildIndex(recursive?: boolean, rebuildLevel?: number) { return this.odata.CreateCustomAction({ name: 'RebuildIndex', id: this.Id, isAction: true, params: ['recursive', 'rebuildLevel'] }, { data: { 'recursive': recursive ? recursive : false, 'rebuildLevel': rebuildLevel ? rebuildLevel : 0 } }); } /** * Performs a full reindex operation on the content and the whole subtree. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let rebuildIndexSubtree = content.RebuildIndexSubtree(); * rebuildIndexSubtree.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ RebuildIndexSubtree() { return this.odata.CreateCustomAction({ name: 'RebuildIndexSubtree', id: this.Id, isAction: true }); } /** * Refreshes the index document of the content and the whole subtree using the already existing index data stored in the database. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let refreshIndexSubtree = content.RefreshIndexSubtree(); * refreshIndexSubtree.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ RefreshIndexSubtree() { return this.odata.CreateCustomAction({ name: 'RefreshIndexSubtree', id: this.Id, isAction: true }); } /** * Returns the number of currently existing preview images. If necessary, it can make sure that all preview images are generated and available for a document. * @ params generateMissing {boolean=} * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let checkPreviews = content.CheckPreviews(true); * checkPreviews.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ CheckPreviews(generateMissing?: boolean) { return this.odata.CreateCustomAction({ name: 'CheckPreviews', id: this.Id, isAction: true, params: ['generateMissing'] }, { data: { 'generateMissing': generateMissing ? generateMissing : false } }); } /** * It clears all existing preview images for a document and starts a task for generating new ones. This can be useful in case the preview status of a document has been set to 'error' * before for some reason and you need to force the system to re-generate preview images. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let regeneratePreviews = content.RegeneratePreviews(); * regeneratePreviews.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ RegeneratePreviews() { return this.odata.CreateCustomAction({ name: 'RegeneratePreviews', id: this.Id, isAction: true }); } /** * Returns the number of pages in a document. If there is no information about page count on the content, it starts a preview generation task to determine the page count. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let getPageCount = content.GetPageCount(); * getPageCount.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ GetPageCount() { return this.odata.CreateCustomAction({ name: 'GetPageCount', id: this.Id, isAction: true }); } /** * Gets information about a preview image generated for a specific page in a document. It returns with the path and the dimensions (width/height) of the image. If the image does not exist yet, * it returns with an empty object but it starts a background task to generate that image if a valid page count number was determined'’’. If page count is -1 you need to call GetPageCount action * first. It is OK to call this method periodically for checking if an image is already available. * @params page {number} * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let previewAvailable = content.PreviewAvailable(2); * previewAvailable.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ PreviewAvailable(page: number) { return this.odata.CreateCustomAction({ name: 'PreviewAvailable', id: this.Id, isAction: false, requiredParams: ['page'] }, { data: { 'page': page } }); } /** * Returns the full list of preview images as content items. This method synchronously generates all missing preview images. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let getPreviewImagesForOData = content.GetPreviewImagesForOData(); * getPreviewImagesForOData.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ GetPreviewImagesForOData() { return this.odata.CreateCustomAction({ name: 'GetPreviewImagesForOData', id: this.Id, isAction: false }); } /** * Returns the list of existing preview images (only the first consecutive batch) as objects with a few information (image path, dimensions). It does not generate any new images. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let getExistingPreviewImagesForOData = content.GetExistingPreviewImagesForOData(); * getExistingPreviewImagesForOData.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ GetExistingPreviewImagesForOData() { return this.odata.CreateCustomAction({ name: 'GetExistingPreviewImagesForOData', id: this.Id, isAction: false }); } /** * Returns the list of the AllowedChildTypes which are set on the current Content. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let getAllowedChildTypesFromCTD = content.GetAllowedChildTypesFromCTD(); * getAllowedChildTypesFromCTD.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ GetAllowedChildTypesFromCTD() { return this.odata.CreateCustomAction({ name: 'GetAllowedChildTypesFromCTD', id: this.Id, isAction: false }); } /** * Identity list that contains every users/groups/organizational units that have any permission setting (according to permission level) in the subtree of the context content. * @params level {Security.PermissionLevel} The value is "AllowedOrDenied". "Allowed" or "Denied" are not implemented yet. * @params kind {Security.IdentityKind} The value can be: All, Users, Groups, OrganizationalUnits, UsersAndGroups, UsersAndOrganizationalUnits, GroupsAndOrganizationalUnits * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let getRelatedIdentities = content.GetRelatedIdentities("AllowedOrDenied", "Groups"); * getRelatedIdentities.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ GetRelatedIdentities(level: Security.PermissionLevel, kind: Security.IdentityKind) { return this.odata.CreateCustomAction({ name: 'GetRelatedIdentities', id: this.Id, isAction: true, requiredParams: ['level', 'kind'] }, { data: { 'level': level, 'kind': kind } }); } /** * Permission list of the selected identity with the count of related content. 0 indicates that this permission has no related content so the GUI does not have to display it as a tree node * @params level {Security.PermissionLevel} The value is "AllowedOrDenied". "Allowed" or "Denied" are not implemented yet. * @params explicitOnly {boolean} The value "true" is required because "false" is not implemented yet. * @params member {string} Fully qualified path of the selected identity (e.g. /Root/IMS/BuiltIn/Portal/Visitor). * @params includedTypes {string[]} An item can increment the counters if its type or any ancestor type is found in the 'includedTypes'. Null means filtering off. If the array is empty, there * is no element that increases the counters. This filter can reduce the execution speed dramatically so do not use if it is possible. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let getRelatedPermissions = content.GetRelatedPermissions("AllowedOrDenied", true, "/Root/IMS/BuiltIn/Portal/EveryOne", null); * getRelatedPermissions.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ GetRelatedPermissions(level: Security.PermissionLevel, explicitOnly: boolean, member: string, includedTypes?: string[]) { return this.odata.CreateCustomAction({ name: 'GetRelatedPermissions', id: this.Id, isAction: true, requiredParams: ['level', 'explicitOnly', 'member', 'includedTypes'] }, { data: { 'level': level, 'explicitOnly': explicitOnly, 'member': member, 'includedTypes': includedTypes } }); } /** * Content list that have explicite/effective permission setting for the selected user in the current subtree. * @params level {Security.PermissionLevel} The value is "AllowedOrDenied". "Allowed" or "Denied" are not implemented yet. * @params explicitOnly {boolean} The value "true" is required because "false" is not implemented yet. * @params member {string} Fully qualified path of the selected identity (e.g. /Root/IMS/BuiltIn/Portal/Visitor). * @params permissions {string[]} related permission list. Item names are case sensitive. In most cases only one item is used (e.g. "See" or "Save" etc.) but you can pass any permission * type name (e.g. ["Open","Save","Custom02"]). * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let getRelatedItems = content.GetRelatedItems("AllowedOrDenied", true, "/Root/IMS/BuiltIn/Portal/EveryOne", ["RunApplication"]); * getRelatedItems.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ GetRelatedItems(level: Security.PermissionLevel, explicitOnly: boolean, member: string, permissions: string[]) { return this.odata.CreateCustomAction({ name: 'GetRelatedItems', id: this.Id, isAction: true, requiredParams: ['level', 'explicitOnly', 'member', 'permissions'] }, { data: { 'level': level, 'explicitOnly': explicitOnly, 'member': member, 'permissions': permissions } }); } /** * This structure is designed for getting tree of content that are permitted or denied for groups/organizational units in the selected subtree. The result content are not in a paged list: * they are organized in a tree. * @params level {Security.PermissionLevel} The value is "AllowedOrDenied". "Allowed" or "Denied" are not implemented yet. * @params kind {Security.IdentityKind} The value can be: All, Users, Groups, OrganizationalUnits, UsersAndGroups, UsersAndOrganizationalUnits, GroupsAndOrganizationalUnits * @params permissions {string[]} related permission list. Item names are case sensitive. In most cases only one item is used (e.g. "See" or "Save" etc.) but you can pass any permission * type name (e.g. ["Open","Save","Custom02"]). * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let getRelatedIdentitiesByPermissions = content.GetRelatedIdentitiesByPermissions("AllowedOrDenied", "Groups", ["RunApplication"]); * getRelatedIdentitiesByPermissions.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ GetRelatedIdentitiesByPermissions(level: Security.PermissionLevel, kind: Security.IdentityKind, permissions: string[]) { return this.odata.CreateCustomAction({ name: 'GetRelatedIdentitiesByPermissions', id: this.Id, isAction: true, requiredParams: ['level', 'kind', 'permissions'] }, { data: { 'level': level, 'kind': kind, 'permissions': permissions } }); } /** * This structure is designed for getting tree of content that are permitted or denied for groups/organizational units in the selected subtree. The result content are not in a paged list: * they are organized in a tree. * @params level {Security.PermissionLevel} The value is "AllowedOrDenied". "Allowed" or "Denied" are not implemented yet. * @params member {string} Fully qualified path of the selected identity (e.g. /Root/IMS/BuiltIn/Portal/Visitor). * @params permissions {string[]} related permission list. Item names are case sensitive. In most cases only one item is used (e.g. "See" or "Save" etc.) but you can pass any permission * type name (e.g. ["Open","Save","Custom02"]). * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let getRelatedItemsOneLevel = content.GetRelatedItemsOneLevel("AllowedOrDenied", "/Root/IMS/BuiltIn/Portal/Visitor", ["Open", "RunApplication"]); * getRelatedItemsOneLevel.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ GetRelatedItemsOneLevel(level: Security.PermissionLevel, member: string, permissions: string[]) { return this.odata.CreateCustomAction({ name: 'GetRelatedItemsOneLevel', id: this.Id, isAction: true, requiredParams: ['level', 'member', 'permissions'] }, { data: { 'level': level, 'member': member, 'permissions': permissions } }); } /** * Returns a content collection that represents users who have enough permissions to a requested resource. The permissions effect on the user and through direct or indirect group membership * too. The function parameter is a permission name list that must contain at least one item. * @params permissions {string[]} related permission list. Item names are case sensitive. In most cases only one item is used (e.g. "See" or "Save" etc.) but you can pass any permission * type name (e.g. ["Open","Save","Custom02"]). * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let getAllowedUsers = content.GetAllowedUsers(["Open", "RunApplication"]); * getAllowedUsers.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ GetAllowedUsers(permissions: string[]) { return this.odata.CreateCustomAction({ name: 'GetAllowedUsers', id: this.Id, isAction: true, requiredParams: ['permissions'] }, { data: { 'permissions': permissions } }); } /** * Returns a content collection that represents groups where the given user or group is member directly or indirectly. This function can be used only on a resource content that is * Group or User or any inherited type. If the value of the "directOnly" parameter is false, all indirect members are listed. * @params directOnly {boolean} If the value of the "directOnly" parameter is false, all indirect members are listed. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let getParentGroups = content.GetParentGroups(["Open", "RunApplication"]); * getParentGroups.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ GetParentGroups(directOnly: boolean) { return this.odata.CreateCustomAction({ name: 'GetParentGroups', id: this.Id, isAction: true, requiredParams: ['directOnly'] }, { data: { 'directOnly': directOnly } }); } /** * Administrators can add new members to a group using this action. The list of new members can be provided using the 'contentIds' parameter (list of user or group ids). * @params contentIds {number[]} List of the member ids. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let addMembers = content.AddMembers([ 123, 456, 789 ]); * addMembers.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ AddMembers(contentIds: number[]) { return this.odata.CreateCustomAction({ name: 'AddMembers', id: this.Id, isAction: true, requiredParams: ['contentIds'] }, { data: { 'contentIds': contentIds } }); } /** * Administrators can remove members from a group using this action. The list of removable members can be provided using the 'contentIds' parameter (list of user or group ids). * @params contentIds {number[]} List of the member ids. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. * ``` * let removeMembers = content.RemoveMembers([ 123, 456, 789 ]); * removeMembers.subscribe({ * next: response => { * console.log('success'); * }, * error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value), * complete: () => console.log('done'), * }); * ``` */ RemoveMembers(contentIds: number[]) { return this.odata.CreateCustomAction({ name: 'RemoveMembers', id: this.Id, isAction: true, requiredParams: ['contentIds'] }, { data: { 'contentIds': contentIds } }); } public GetDeferredContent<TReferenceType extends Content, TBaseType extends ContentTypes.GenericContent, K extends keyof TBaseType>( fieldName: K, options?: ODataParams, contentType: { new(...args: any[]): TReferenceType } = Content as { new(...args) }): Observable<TReferenceType> { const requestOptions = this.GetDeferredRequestOptions(fieldName, options); return this.odata.Get(requestOptions).map(resp => Content.Create(contentType, resp.d, this.repository)); } public GetDeferredCollection<TReferenceType extends Content, TBaseType extends ContentTypes.GenericContent, K extends keyof TBaseType>( fieldName: K, options?: ODataParams, contentType: { new(...args: any[]): TReferenceType } = Content as { new(...args) }): Observable<TReferenceType[]> { const requestOptions = this.GetDeferredRequestOptions(fieldName, options); return this.odata.Fetch(requestOptions).map(resp => resp.d.results.map(c => Content.Create(contentType, c, this.repository))); } protected GetDeferredRequestOptions(fieldName: string, options?: ODataParams) { let contentURL; if (this.Id) { contentURL = ODataHelper.getContentUrlbyId(this.Id); } else Iif (this.Path) { contentURL = ODataHelper.getContentURLbyPath(this.Path); } else { throw Error('No Id or Path provided'); } return new ODataRequestOptions({ path: ODataHelper.joinPaths(contentURL, fieldName), params: options }); } /** * Uploads a stream or text to a content binary field (e.g. a file). * @params ContentType {string=} Specific content type name for the uploaded content. If not provided, the system will try to determine it from the current environment: the upload content types configured in the * web.config and the allowed content types in the particular folder. In most cases, this will be File. * @params FileName {string} Name of the uploaded file. * @params Overwrite {bool=True} Whether the upload action should overwrite a content if it already exist with the same name. If false, a new file will be created with a similar name containing an * incremental number (e.g. sample(2).docx). * @params UseChunk {bool=False} Determines whether the system should start a chunk upload process instead of saving the file in one round. Usually this is determined by the size of the file. * It's optional, used in the first request * @params PropertyName {string=Binary} Appoints the binary field of the content where the data should be saved. * @params ChunkToken {string} The response of first request returns this token. It must be posted in all of the subsequent requests without modification. It is used for executing the chunk upload operation. * It's mandatory, except in the first request * @params {FileText} In case you do not have the file as a real file in the file system but a text in the browser, you can provide the raw text in this parameter. * @returns {Observable} Returns an RxJS observable that you can subscribe of in your code. */ public Upload(contentType: string, fileName: string, overwrite?: boolean, useChunk?: boolean, propertyName?: string, fileText?: string) { if (!this.Path) { throw Error('No Path provided!'); } const o = overwrite ? overwrite : true; const data: any = { ContentType: contentType, FileName: fileName, Overwrite: o, UseChunk: useChunk ? useChunk : false }; if (typeof propertyName !== 'undefined') { data['PropertyName'] = propertyName; } if (typeof fileText !== 'undefined') { data['FileText'] = fileText; } let uploadCreation = this.odata.Upload(this.Path, data, true); uploadCreation.subscribe({ next: (response) => { const data = { ContentType: contentType, FileName: fileName, Overwrite: o, ChunkToken: response }; return this.odata.Upload(this.Path as any, data, false); } }); return uploadCreation; } /** * Returns the parent content's Path * @throws if no Path is specified or the content is not saved yet. */ public get ParentPath(): string { if (!this.Path) { throw Error('No Path provided for the Content'); } if (!this.IsSaved) { throw Error('Content has to be saved to retrieve the ParentPath'); } const segments = this.Path.split('/'); segments.pop(); return segments.join('/'); } /** * Indicates if the current Content is the parent a specified Content */ public IsParentOf(childContent: Content): boolean { return this.repository === childContent.repository && this.IsSaved && childContent.ParentPath === this.Path; } /** * Indicates if the current Content is a child a specified Content */ public IsChildOf(parentContent: Content): boolean { return this.repository === parentContent.repository && parentContent.IsSaved && this.ParentPath === parentContent.Path; } /** * Indicates if the current Content is an ancestor of a specified Content */ public IsAncestorOf(descendantContent: Content): boolean { if (!descendantContent.Path || !this.Path) { throw Error('No path provided') } return this.repository === descendantContent.repository && this.IsSaved && descendantContent.Path.indexOf(this.Path + '/') === 0; } /** * Indicates if the current Content is a descendant of a specified Content */ public IsDescendantOf(ancestorContent: Content): boolean { if (!ancestorContent.Path || !this.Path) { throw Error('No path provided') } return this.repository === ancestorContent.repository && ancestorContent.IsSaved && this.Path.indexOf(ancestorContent.Path + '/') === 0; } /** * Returns the full Path for the current content */ GetFullPath(): string { Iif (!this.IsSaved) { throw new Error('Content has to be saved to get the full Path'); } Eif (this.Id) { return ODataHelper.getContentUrlbyId(this.Id); } else if (this.Path) { return ODataHelper.getContentURLbyPath(this.Path); } else { throw new Error('Content Id or Path has to be provided to get the full Path'); } } /** * */ Stringify: () => string = () => ContentSerializer.Stringify(this); } /** * Interface for classes that represent a Content. * * @interface IContentOptions */ export interface IContentOptions { Type?: string; Name?: string; Id?: number; DisplayName?: string; Description?: string; Icon?: string; Index?: number; CreationDate?: string; ModificationDate?: string; IsFolder?: boolean; Path?: string; Versions?: ComplexTypes.DeferredObject; Workspace?: ComplexTypes.DeferredObject; } |