UNPKG

@dasch-swiss/dsp-js

Version:

JavaScript library that handles API requests to Knora

206 lines 11.6 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import { catchError, map } from "rxjs"; import { ChildNodeInfoResponse } from "../../../models/admin/child-node-info-response"; import { DeleteChildNodeCommentsResponse } from "../../../models/admin/delete-child-node-comments-response"; import { DeleteListNodeResponse } from "../../../models/admin/delete-list-node-response"; import { DeleteListResponse } from "../../../models/admin/delete-list-response"; import { ListChildNodeResponse } from "../../../models/admin/list-child-node-response"; import { ListInfoResponse } from "../../../models/admin/list-info-response"; import { ListNodeInfoResponse } from "../../../models/admin/list-node-info-response"; import { ListResponse } from "../../../models/admin/list-response"; import { ListsResponse } from "../../../models/admin/lists-response"; import { RepositionChildNodeResponse } from "../../../models/admin/reposition-child-node-response"; import { ApiResponseData } from "../../../models/api-response-data"; import { Endpoint } from "../../endpoint"; /** * An endpoint for working with Knora lists. * @deprecated Use open API docs instead * @category Endpoint Admin */ var ListsEndpointAdmin = /** @class */ (function (_super) { __extends(ListsEndpointAdmin, _super); function ListsEndpointAdmin() { return _super !== null && _super.apply(this, arguments) || this; } /** * Returns a list of lists. */ ListsEndpointAdmin.prototype.getLists = function () { var _this = this; return this.httpGet("").pipe(map(function (ajaxResponse) { return ApiResponseData.fromAjaxResponse(ajaxResponse, ListsResponse, _this.jsonConvert); }), catchError(function (error) { return _this.handleError(error); })); }; /** * Returns a list of lists in a project. * * @param projectIri The IRI of the project. */ ListsEndpointAdmin.prototype.getListsInProject = function (projectIri) { var _this = this; return this.httpGet("?projectIri=" + encodeURIComponent(projectIri)).pipe(map(function (ajaxResponse) { return ApiResponseData.fromAjaxResponse(ajaxResponse, ListsResponse, _this.jsonConvert); }), catchError(function (error) { return _this.handleError(error); })); }; /** * Updates information about a list. * * @param listInfo Information about the list to be created. */ ListsEndpointAdmin.prototype.updateListInfo = function (listInfo) { var _this = this; return this.httpPut("/" + encodeURIComponent(listInfo.listIri), this.jsonConvert.serializeObject(listInfo)).pipe(map(function (ajaxResponse) { return ApiResponseData.fromAjaxResponse(ajaxResponse, ListInfoResponse, _this.jsonConvert); }), catchError(function (error) { return _this.handleError(error); })); }; /** * Updates the name of an existing child node. * * @param listItemIri the Iri of the list item. * @param name the new name to replace the existing name. */ ListsEndpointAdmin.prototype.updateChildName = function (listItemIri, name) { var _this = this; return this.httpPut("/" + encodeURIComponent(listItemIri) + "/name", this.jsonConvert.serializeObject(name)).pipe(map(function (ajaxResponse) { return ApiResponseData.fromAjaxResponse(ajaxResponse, ChildNodeInfoResponse, _this.jsonConvert); }), catchError(function (error) { return _this.handleError(error); })); }; /** * Updates the labels of an existing child node. * * @param listItemIri the Iri of the list item. * @param labels the new labels to replace the existing labels. */ ListsEndpointAdmin.prototype.updateChildLabels = function (listItemIri, labels) { var _this = this; return this.httpPut("/" + encodeURIComponent(listItemIri) + "/labels", this.jsonConvert.serializeObject(labels)).pipe(map(function (ajaxResponse) { return ApiResponseData.fromAjaxResponse(ajaxResponse, ChildNodeInfoResponse, _this.jsonConvert); }), catchError(function (error) { return _this.handleError(error); })); }; /** * Updates the comments of an existing child node. * * @param listItemIri the Iri of the list item. * @param comments the new comments to replace the existing comments. */ ListsEndpointAdmin.prototype.updateChildComments = function (listItemIri, comments) { var _this = this; return this.httpPut("/" + encodeURIComponent(listItemIri) + "/comments", this.jsonConvert.serializeObject(comments)).pipe(map(function (ajaxResponse) { return ApiResponseData.fromAjaxResponse(ajaxResponse, ChildNodeInfoResponse, _this.jsonConvert); }), catchError(function (error) { return _this.handleError(error); })); }; /** * Deletes the comments of an existing child node. * * @param listItemIri the Iri of the list item. */ ListsEndpointAdmin.prototype.deleteChildComments = function (listItemIri) { var _this = this; return this.httpDelete("/comments/" + encodeURIComponent(listItemIri)).pipe(map(function (ajaxResponse) { return ApiResponseData.fromAjaxResponse(ajaxResponse, DeleteChildNodeCommentsResponse, _this.jsonConvert); }), catchError(function (error) { return _this.handleError(error); })); }; /** * Creates a child node in a list. * * @param node The node to be created. */ ListsEndpointAdmin.prototype.createChildNode = function (node) { var _this = this; return this.httpPost("/" + encodeURIComponent(node.parentNodeIri), this.jsonConvert.serializeObject(node)).pipe(map(function (ajaxResponse) { return ApiResponseData.fromAjaxResponse(ajaxResponse, ListNodeInfoResponse, _this.jsonConvert); }), catchError(function (error) { return _this.handleError(error); })); }; /** * Returns information about a list. * * @param iri The IRI of the list. */ ListsEndpointAdmin.prototype.getListInfo = function (iri) { var _this = this; return this.httpGet("/infos/" + encodeURIComponent(iri)).pipe(map(function (ajaxResponse) { return ApiResponseData.fromAjaxResponse(ajaxResponse, ListInfoResponse, _this.jsonConvert); }), catchError(function (error) { return _this.handleError(error); })); }; /** * Returns the parent node if an IRI of a child node is given. * Returns a deleted flag and IRI if an IRI of a root node is given. * * @param iri The IRI of the list. */ ListsEndpointAdmin.prototype.deleteListNode = function (iri) { var _this = this; return this.httpDelete("/" + encodeURIComponent(iri)).pipe(map(function (ajaxResponse) { if (ajaxResponse.response.hasOwnProperty("node")) { // child node return ApiResponseData.fromAjaxResponse(ajaxResponse, DeleteListNodeResponse, _this.jsonConvert); } else { // root node return ApiResponseData.fromAjaxResponse(ajaxResponse, DeleteListResponse, _this.jsonConvert); } }), catchError(function (error) { return _this.handleError(error); })); }; /** * Move child node to a certain position in a list. * Parent node IRI can be the same but only if the position is different. * * @param iri The IRI of the list node to move. * @param repositionRequest The parent node IRI and the position the child node should move to. */ ListsEndpointAdmin.prototype.repositionChildNode = function (iri, repositionRequest) { var _this = this; return this.httpPut("/" + encodeURIComponent(iri) + "/position", this.jsonConvert.serializeObject(repositionRequest)).pipe(map(function (ajaxResponse) { return ApiResponseData.fromAjaxResponse(ajaxResponse, RepositionChildNodeResponse, _this.jsonConvert); }), catchError(function (error) { return _this.handleError(error); })); }; // *** All methods below this point require the "new-list-admin-routes:1=on" feature toggle *** /** * Updates a child node. * * @param nodeInfo Information about the node to be updated. */ ListsEndpointAdmin.prototype.updateChildNode = function (nodeInfo) { var _this = this; if (nodeInfo.name === undefined && nodeInfo.labels === undefined && nodeInfo.comments === undefined) { throw new Error("At least one property is expected from the following properties: name, labels, comments."); } return this.httpPut("/" + encodeURIComponent(nodeInfo.listIri), this.jsonConvert.serializeObject(nodeInfo)).pipe(map(function (ajaxResponse) { return ApiResponseData.fromAjaxResponse(ajaxResponse, ChildNodeInfoResponse, _this.jsonConvert); }), catchError(function (error) { return _this.handleError(error); })); }; /** * Returns information about a list node using the new route. * * @param listItemIri The IRI of the node. */ ListsEndpointAdmin.prototype.getListNodeInfo = function (listItemIri) { var _this = this; return this.httpGet("/" + encodeURIComponent(listItemIri) + "/info").pipe(map(function (ajaxResponse) { if (ajaxResponse.response.hasOwnProperty("listinfo")) { // root node return ApiResponseData.fromAjaxResponse(ajaxResponse, ListInfoResponse, _this.jsonConvert); } else { // child node return ApiResponseData.fromAjaxResponse(ajaxResponse, ListNodeInfoResponse, _this.jsonConvert); } })); }; /** * Creates a list using the old route but with the feature toggle enabled. * * @param listInfo Information about the list to be created. */ ListsEndpointAdmin.prototype.createList = function (listInfo) { var _this = this; return this.httpPost("", this.jsonConvert.serializeObject(listInfo)).pipe(map(function (ajaxResponse) { return ApiResponseData.fromAjaxResponse(ajaxResponse, ListResponse, _this.jsonConvert); }), catchError(function (error) { return _this.handleError(error); })); }; /** * Gets a list using the old route but with the feature toggle enabled * * @param listItemIri The IRI of the list. */ ListsEndpointAdmin.prototype.getList = function (listItemIri) { var _this = this; return this.httpGet("/" + encodeURIComponent(listItemIri)).pipe(map(function (ajaxResponse) { if (ajaxResponse.response.hasOwnProperty("list")) { return ApiResponseData.fromAjaxResponse(ajaxResponse, ListResponse, _this.jsonConvert); } else { return ApiResponseData.fromAjaxResponse(ajaxResponse, ListChildNodeResponse, _this.jsonConvert); } }), catchError(function (error) { return _this.handleError(error); })); }; return ListsEndpointAdmin; }(Endpoint)); export { ListsEndpointAdmin }; //# sourceMappingURL=lists-endpoint-admin.js.map