-
Notifications
You must be signed in to change notification settings - Fork 2
/
relateThisEntityToMultipleMBID.js
36 lines (31 loc) · 1.3 KB
/
relateThisEntityToMultipleMBID.js
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
/**
* - Relates the currently edited entity to multiple entities given by their MBIDs.
* - Uses the selected relationship type of the currently active relationship dialog.
*/
import { fetchEntity } from '../internalAPI.js';
import { createRelationship } from '../relationship-editor/createRelationship.js';
/**
* Adds relationships of the given type between the currently edited source entity and the given target entities.
* @param {string[]} mbids MBIDs of the target entities.
* @param {number} linkTypeID Internal ID of the relationship type.
* @param {boolean} [backward] Change the direction of the relationship.
*/
async function relateThisEntityToMultiple(mbids, linkTypeID, backward = false) {
for (let mbid of mbids) {
createRelationship({
target: await fetchEntity(mbid),
linkTypeID,
backward,
});
}
}
const input = prompt('MBIDs of entities which should be related to this entity:');
if (input) {
const mbids = Array.from(input.matchAll(/[0-9a-f-]{36}/gm), (match) => match[0]);
const activeDialog = MB.relationshipEditor.relationshipDialogState;
if (activeDialog) {
// use the selected relationship type of the active dialog
const linkTypeID = activeDialog.linkType.autocomplete.selectedItem.entity.id;
relateThisEntityToMultiple(mbids, linkTypeID, activeDialog.backward);
}
}