PageSourceSearch

https://quorumapp.com/ts/BayesNetViewModel.js

js quorumapp.com collected 2026-09-26 04:38:46 UTC 38,850 bytes, 657 lines download raw bytes

1var __assign = (this && this.__assign) || function () {
2    __assign = Object.assign || function(t) {
3        for (var s, i = 1, n = arguments.length; i < n; i++) {
4            s = arguments[i];
5            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6                t[p] = s[p];
7        }
8        return t;
9    };
10    return __assign.apply(this, arguments);
11};
12var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14    return new (P || (P = Promise))(function (resolve, reject) {
15        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18        step((generator = generator.apply(thisArg, _arguments || [])).next());
19    });
20};
21var __generator = (this && this.__generator) || function (thisArg, body) {
22    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24    function verb(n) { return function (v) { return step([n, v]); }; }
25    function step(op) {
26        if (f) throw new TypeError("Generator is already executing.");
27        while (g && (g = 0, op[0] && (_ = 0)), _) try {
28            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29            if (y = 0, t) op = [op[0] & 2, t.value];
30            switch (op[0]) {
31                case 0: case 1: t = op; break;
32                case 4: _.label++; return { value: op[1], done: false };
33                case 5: _.label++; y = op[1]; op = [0]; continue;
34                case 7: op = _.ops.pop(); _.trys.pop(); continue;
35                default:
36                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40                    if (t[2]) _.ops.pop();
41                    _.trys.pop(); continue;
42            }
43            op = body.call(thisArg, _);
44        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46    }
47};
48import { Distiller } from './application.js';
49import { BayesNet } from './BayesNet/BayesNet.js';
50import { Tabs } from './Tabs/Tabs.js';
51import { TabTemplateButton } from './Tabs/TabTemplateButton.js';
52import { TabEditableButton } from './Tabs/TabEditableButton.js';
53import { TreeNode } from './BayesNet/TreeNode.js';
54var BayesNetViewModel = /** @class */ (function () {
55    function BayesNetViewModel(params, componentInfo) {
56        var _this = this;
57        var _a, _b, _c, _d, _e, _f, _g, _h;
58        this.dispose = function () {
59            var questionIds = _this.getQuestionIdsForSet();
60            if (questionIds.size === 0) {
61                return;
62            }
63            Distiller.visibleNodes.remove(function (node) { return questionIds.has(node.id); });
64        };
65        this.loopThroughDates = function () { return __awaiter(_this, void 0, void 0, function () {
66            var outcomesData, dates, i;
67            return __generator(this, function (_a) {
68                switch (_a.label) {
69                    case 0:
70                        Distiller.updatingSimForecasts(true);
71                        return [4 /*yield*/, this.getResolvedNodes()];
72                    case 1:
73                        outcomesData = _a.sent();
74                        dates = outcomesData.uniqueDates;
75                        i = 0;
76                        _a.label = 2;
77                    case 2:
78                        if (!(i < dates.length)) return [3 /*break*/, 5];
79                        this.asOfDate = dates[i];
80                        console.log("As of date: " + this.asOfDate);
81                        return [4 /*yield*/, this.setupPage()];
82                    case 3:
83                        _a.sent();
84                        // NEXT PERSON 
85                        if (i === dates.length - 1) {
86                            console.log("NEXT PERSON");
87                            Distiller.bayesUserIndex(Distiller.bayesUserIndex() + 1);
88                        }
89                        _a.label = 4;
90                    case 4:
91                        i++;
92                        return [3 /*break*/, 2];
93                    case 5: return [2 /*return*/];
94                }
95            });
96        }); };
97        this.preventForecastUpdates = false;
98        this.readOnlyUiParams = [];
99        this.hidingText = ko.observable(false);
100        this.questionSet = ko.observable(null);
101        this.netToRender = ko.observable(null);
102        this.isUserView = false;
103        this.asParticipant = false;
104        this.viewSharedTemplate = false;
105        this.templateNetId = null;
106        this.teamDisplay = false;
107        this.isInAdminView = false;
108        this.userId = null;
109        this.rootElement = null;
110        this.onBayesNetReady = null;
111        this.activeBayesNet = null;
112        this.tabs = null;
113        this.tabsListenersRegistered = false;
114        this.tabsInfo = [];
115        this.getTabsElementId = function () { var _a; return 'bayesNetTabs-' + ((_a = _this.questionSet()) === null || _a === void 0 ? void 0 : _a.setId()); };
116        this.getLoadingSplashId = function () { var _a; return 'bayesNetLoading-' + ((_a = _this.questionSet()) === null || _a === void 0 ? void 0 : _a.setId()); };
117        this.canQuerySelector = function (node) {
118            return !!node && typeof node.querySelector === 'function';
119        };
120        this.getComponentRoot = function () {
121            var _a;
122            var node = _this.rootElement;
123            if (!node) {
124                return null;
125            }
126            if (node.nodeType === Node.ELEMENT_NODE) {
127                var el = node;
128                if (el.classList.contains('bayesNetViewComponent')) {
129                    return el;
130                }
131                if (_this.canQuerySelector(el)) {
132                    var componentRoot = el.querySelector('.bayesNetViewComponent');
133                    if (componentRoot) {
134                        return componentRoot;
135                    }
136                }
137                if (_this.canQuerySelector(el.parentElement)) {
138                    var inParent = el.parentElement.querySelector('.bayesNetViewComponent');
139                    if (inParent) {
140                        return inParent;
141                    }
142                }
143                return el;
144            }
145            // Virtual <!-- ko component --> bindings use a comment node; the template is a sibling.
146            var sibling = node.nextSibling;
147            while (sibling) {
148                if (sibling.nodeType === Node.ELEMENT_NODE) {
149                    var el = sibling;
150                    if (el.classList.contains('bayesNetViewComponent')) {
151                        return el;
152                    }
153                }
154                if (sibling.nodeType === Node.COMMENT_NODE && ((_a = sibling.nodeValue) === null || _a === void 0 ? void 0 : _a.trim().startsWith('/'))) {
155                    break;
156                }
157                sibling = sibling.nextSibling;
158            }
159            return null;
160        };
161        this.queryInComponent = function (selector) {
162            var root = _this.getComponentRoot();
163            if (_this.canQuerySelector(root)) {
164                return root.querySelector(selector);
165            }
166            return document.querySelector(selector);
167        };
168        this.getTabsElement = function () {
169            var _a;
170            var scoped = _this.queryInComponent('.bayesNetViewTabs');
171            if (scoped) {
172                return scoped;
173            }
174            var setId = (_a = _this.questionSet()) === null || _a === void 0 ? void 0 : _a.setId();
175            if (setId) {
176                return document.getElementById(_this.getTabsElementId());
177            }
178            return null;
179        };
180        this.ensureTabs = function () {
181            if (!_this.tabs) {
182                var elem = _this.getTabsElement();
183                if (!elem) {
184                    return null;
185                }
186                _this.tabs = new Tabs({
187                    elem: elem,
188                    open: 0,
189                });
190            }
191            return _this.tabs;
192        };
193        this.findBayesNetContainer = function (bayesNetId) {
194            var root = _this.getComponentRoot();
195            if (_this.canQuerySelector(root)) {
196                var byId = root.querySelector('#' + bayesNetId);
197                if (byId) {
198                    return byId;
199                }
200                var canvasContainer = root.querySelector('.bayesNetViewCanvas > div');
201                if (canvasContainer) {
202                    return canvasContainer;
203                }
204            }
205            return document.getElementById(bayesNetId);
206        };
207        this.beginSetupPage = function (attempt) {
208            if (attempt === void 0) { attempt = 0; }
209            var maxAttempts = 50;
210            if (_this.getTabsElement()) {
211                _this.setupPage();
212                return;
213            }
214            if (attempt < maxAttempts) {
215                var self_1 = _this;
216                requestAnimationFrame(function () { self_1.beginSetupPage(attempt + 1); });
217            }
218            else {
219                console.log('bayes net tabs not ready for setup');
220            }
221        };
222        this.getQuestionIdsForSet = function () {
223            var _a, _b, _c;
224            var questionIds = new Set();
225            var questions = (_c = (_b = (_a = _this.questionSet()) === null || _a === void 0 ? void 0 : _a.surveyQuestions) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : [];
226            questions.forEach(function (question) {
227                var _a, _b;
228                questionIds.add(question.questionId());
229                (_b = (_a = question.siblingQuestions) === null || _a === void 0 ? void 0 : _a.call(question)) === null || _b === void 0 ? void 0 : _b.forEach(function (sibling) {
230                    questionIds.add(sibling.questionId());
231                });
232            });
233            return questionIds;
234        };
235        this.appendToBody = function (elements) {
236            elements.forEach(function (element) {
237                document.body.appendChild(element);
238            });
239        };
240        this.asOfDate = null;
241        this.setupPage = function () { return __awaiter(_this, void 0, void 0, function () {
242            var tabs, tabsElement, questionSetId, response, isInAdminViewResult, data, netId, netToRender, isFirstTabTemplate, isFirstTabEditable, firstTabBayesNetId, getEmptyTabContent, createBayesNetNode, activeTabIndex, newNode, responseBayesNetData, bayesNetData, tabsContainer, tabsContainer, REMAINING_TABS, i, bayesNetId, content, tabBarIsUseful;
243            var _this = this;
244            return __generator(this, function (_a) {
245                switch (_a.label) {
246                    case 0:
247                        console.log("setup page, ", this.asOfDate);
248                        tabs = this.ensureTabs();
249                        if (!this.questionSet()) {
250                            this.hideLoadingScreen();
251                            tabsElement = this.getTabsElement();
252                            if (tabsElement) {
253                                tabsElement.innerHTML = "Error. No question set found";
254                            }
255                            console.log("no question set found");
256                            return [2 /*return*/];
257                        }
258                        if (!tabs) {
259                            console.log("bayes net tabs element not found");
260                            return [2 /*return*/];
261                        }
262                        this.hideLoadingScreen();
263                        questionSetId = this.questionSet().setId();
264                        response = null;
265                        if (!this.asOfDate) return [3 /*break*/, 2];
266                        return [4 /*yield*/, this.loadAllBayesNetDataAsOfDate(this.userId, questionSetId, this.asOfDate)];
267                    case 1:
268                        response = _a.sent();
269                        return [3 /*break*/, 6];
270                    case 2:
271                        if (!this.teamDisplay) return [3 /*break*/, 4];
272                        return [4 /*yield*/, this.loadAllBayesNetDataTeamMedians(this.userId, questionSetId)];
273                    case 3:
274                        response = _a.sent();
275                        return [3 /*break*/, 6];
276                    case 4: return [4 /*yield*/, this.loadAllBayesNetData(this.userId, questionSetId)];
277                    case 5:
278                        response = _a.sent();
279                        _a.label = 6;
280                    case 6: return [4 /*yield*/, this.requestIsAdmin(this.userId)];
281                    case 7:
282                        isInAdminViewResult = _a.sent();
283                        this.isInAdminView = isInAdminViewResult === "true";
284                        // Hide loading screen
285                        this.hideLoadingScreen();
286                        data = null;
287                        try {
288                            data = typeof response === 'string' ? JSON.parse(response) : response;
289                        }
290                        catch (e) {
291                            data = { bayesNets: [], clientQuestionData: [] };
292                        }
293                        if (!data || typeof data !== 'object') {
294                            data = { bayesNets: [], clientQuestionData: [] };
295                        }
296                        if (!Array.isArray(data.bayesNets)) {
297                            data.bayesNets = [];
298                        }
299                        Distiller.addQuestionsToSetsForAdmin([this.questionSet()], data.clientQuestionData || []);
300                        netId = null;
301                        netToRender = [];
302                        isFirstTabTemplate = false;
303                        isFirstTabEditable = false;
304                        if (data.bayesNets.length > 0) {
305                            netToRender = data.bayesNets[0];
306                            netId = netToRender.netId;
307                            isFirstTabTemplate = netToRender.isTemplate;
308                            isFirstTabEditable = netToRender.canEdit;
309                        }
310                        firstTabBayesNetId = "bayes_net_set-0-" + this.questionSet().setId();
311                        // Setup tabs
312                        if (this.isUserView) {
313                            tabs.hideNewTabBtn();
314                            tabs.hideActionBtns();
315                        }
316                        this.tabsInfo = [{
317                                isTemplate: isFirstTabTemplate,
318                                canEdit: isFirstTabEditable,
319                                initialized: false,
320                                bayesNetId: firstTabBayesNetId
321                            }];
322                        if (!this.tabsListenersRegistered) {
323                            this.tabsListenersRegistered = true;
324                            tabs.addOnDeleteListener(function (tabIndex) {
325                                _this.deleteBayesNet(questionSetId, data.bayesNets[tabIndex].netId);
326                                if (data.bayesNets.length > tabIndex) {
327                                    data.bayesNets.splice(tabIndex, 1);
328                                }
329                                _this.tabsInfo.splice(tabIndex, 1);
330                            });
331                            tabs.addOnTabSelectedListener(function (tabIndex) {
332                                TabTemplateButton.setup(_this.tabsInfo[tabIndex].isTemplate, tabs.getElement());
333                                TabEditableButton.setup(_this.tabsInfo[tabIndex].c
333anEdit, tabs.getElement());
334                                var wasInitialized = _this.tabsInfo[tabIndex].initialized;
335                                if (!wasInitialized) {
336                                    _this.setupBayesNet(_this.tabsInfo[tabIndex].bayesNetId, data.bayesNets[tabIndex].netId, data.bayesNets[tabIndex]);
337                                    _this.tabsInfo[tabIndex].initialized = true;
338                                }
339                            });
340                            tabs.addOnActionBtnListener("tabs-template-btn", function (tabIndex) {
341                                if (!data.bayesNets[tabIndex])
342                                    return;
343                                _this.tabsInfo[tabIndex].isTemplate = !_this.tabsInfo[tabIndex].isTemplate;
344                                _this.setBayesNetTemplateState(data.bayesNets[tabIndex].netId, _this.tabsInfo[tabIndex].isTemplate);
345                                TabTemplateButton.setup(_this.tabsInfo[tabIndex].isTemplate, tabs.getElement());
346                            });
347                            tabs.addOnActionBtnListener("tabs-editable-btn", function (tabIndex) {
348                                if (!data.bayesNets[tabIndex])
349                                    return;
350                                _this.tabsInfo[tabIndex].canEdit = !_this.tabsInfo[tabIndex].canEdit;
351                                _this.setBayesNetEditableState(data.bayesNets[tabIndex].netId, _this.tabsInfo[tabIndex].canEdit);
352                                TabEditableButton.setup(_this.tabsInfo[tabIndex].canEdit, tabs.getElement());
353                            });
354                            tabs.addOnRequestNewContentListener(function () {
355                                var bayesNetId = _this.generateNextBayesNetContainerId();
356                                _this.tabsInfo.push({
357                                    isTemplate: false,
358                                    canEdit: false,
359                                    initialized: true,
360                                    bayesNetId: bayesNetId
361                                });
362                                return {
363                                    content: getEmptyTabContent(bayesNetId),
364                                    metadata: { bayesNetId: bayesNetId }
365                                };
366                            });
367                            tabs.addOnSetupNewContentListener(function (metadata) { return __awaiter(_this, void 0, void 0, function () {
368                                var CREATE_NEW_NET_ID, newNode, responseBayesNetData, bayesNetData, activeTabIndex;
369                                return __generator(this, function (_a) {
370                                    switch (_a.label) {
371                                        case 0:
372                                            CREATE_NEW_NET_ID = -1;
373                                            return [4 /*yield*/, createBayesNetNode(CREATE_NEW_NET_ID)];
374                                        case 1:
375                                            newNode = _a.sent();
376                                            return [4 /*yield*/, this.loadBayesNetData(this.userId, questionSetId, newNode.netId)];
377                                        case 2:
378                                            responseBayesNetData = _a.sent();
379                                            bayesNetData = JSON.parse(responseBayesNetData);
380                                            data.bayesNets.push(bayesNetData.bayesNet);
381                                            this.setupBayesNet(metadata.bayesNetId, newNode.netId, bayesNetData.bayesNet);
382                                            activeTabIndex = tabs.getActiveTabIndex();
383                                            TabTemplateButton.setup(this.tabsInfo[activeTabIndex].isTemplate, tabs.getElement());
384                                            TabEditableButton.setup(this.tabsInfo[activeTabIndex].canEdit, tabs.getElement());
385                                            return [2 /*return*/];
386                                    }
387                                });
388                            }); });
389                        }
390                        getEmptyTabContent = function (bayesNetId) {
391                            return "\n            <div class=\"conditionalTreeSubcontainer bayesNetViewCanvas\">\n                <div data-bind=\"attr: { id: '".concat(bayesNetId, "'}\" id='").concat(bayesNetId, "'>
391\n                  <span class=\"loading\">Loading...</span>\n                </div>\n            </div>");
392                        };
393                        createBayesNetNode = function (netId) { return __awaiter(_this, void 0, void 0, function () {
394                            var nodeTemplate, newNodeData, newNode;
395                            return __generator(this, function (_a) {
396                                switch (_a.label) {
397                                    case 0:
398                                        nodeTemplate = {
399                                            id: null,
400                                            netId: netId,
401                                            title: "Untitled node",
402                                            description: "",
403                                            probabilities: [{ name: "True", answerId: null, value: null, simValue: null }, { name: "False", answerId: null, value: null, simValue: null }],
404                                            conditionalProbabilities: [],
405                                            position: { x: 200, y: 80 },
406                                            size: { width: TreeNode.DEFAULT_WIDTH, height: 0 },
407                                            childrenIds: [],
408                                            distributions: []
409                                        };
410                                        return [4 /*yield*/, this.onNodeCreated(nodeTemplate)];
411                                    case 1:
412                                        newNodeData = _a.sent();
413                                        newNode = JSON.parse(newNodeData);
414                                        nodeTemplate.netId = newNode.netId;
415                                        nodeTemplate.probabilities = newNode.probabilities;
416                                        nodeTemplate.id = newNode.id;
417                                        Distiller.addQuestionForNode(this.questionSet(), newNode);
418                                        return [2 /*return*/, nodeTemplate];
419                                }
420                            });
421                        }); };
422                        activeTabIndex = tabs.getActiveTabIndex();
423                        TabTemplateButton.setup(this.tabsInfo[activeTabIndex].isTemplate, tabs.getElement());
424                        TabEditableButton.setup(this.tabsInfo[activeTabIndex].canEdit, tabs.getElement());
425                        tabs.setActiveTabContent(getEmptyTabContent(firstTabBayesNetId));
426                        if (!(!this.isUserView && this.isInAdminView && !this.viewSharedTemplate)) return [3 /*break*/, 11];
427                        if (!(!netToRender.nodes || netToRender.nodes.length == 0)) return [3 /*break*/, 10];
428                        return [4 /*yield*/, createBayesNetNode(netId == null ? -1 : netId)];
429                    case 8:
430                        newNode = _a.sent();
431                        return [4 /*yield*/, this.loadBayesNetData(this.userId, questionSetId, newNode.netId)];
432                    case 9:
433                        responseBayesNetData = _a.sent();
434                        bayesNetData = JSON.parse(responseBayesNetData);
435                        data.bayesNets[0] = bayesNetData.bayesNet;
436                        netToRender = bayesNetData.bayesNet;
437                        _a.label = 10;
438                    case 10: return [3 /*break*/, 12];
439                    case 11:
440                        if (data.bayesNets.length === 0 && this.viewSharedTemplate) {
441                            netToRender = {
442                                netId: this.templateNetId,
443                                nodes: [],
444                                isTemplate: true,
445                                canEdit: true,
446                            };
447                            netId = this.templateNetId;
448                            data.bayesNets = [netToRender];
449                        }
450                        if (data.bayesNets.length === 0) {
451                            tabsContainer = this.getTabsElement();
452                            if (tabsContainer) {
453                                tabsContainer.innerHTML = "Currently there are no questions";
454                            }
455                            return [2 /*return*/];
456                        }
457                        if ((!netToRender.nodes || netToRender.nodes.length === 0) &&
458                            !netToRender.canEdit &&
459                            !this.viewSharedTemplate) {
460                            tabsContainer = this.getTabsElement();
461                            if (tabsContainer) {
462                                tabsContainer.innerHTML = "Currently there are no questions";
463                            }
464                            return [2 /*return*/];
465                        }
466                        _a.label = 12;
467                    case 12:
468                        this.setupBayesNet(firstTabBayesNetId, netId, netToRender);
469                        this.tabsInfo[0].initialized = true;
470                        REMAINING_TABS = 1;
471                        if (data.bayesNets.length > REMAINING_TABS) {
472                            for (i = 1; i < data.bayesNets.length; i++) {
473                                bayesNetId = this.generateNextBayesNetContainerId();
474                                this.tabsInfo.push({
475                                    isTemplate: data.bayesNets[i].isTemplate,
476                                    canEdit: data.bayesNets[i].canEdit,
477                                    initialized: false,
478                                    bayesNetId: bayesNetId
479                                });
480                                content = getEmptyTabContent(bayesNetId);
481                                tabs.addNewTab(content);
482                            }
483                        }
484                        tabBarIsUseful = data.bayesNets.length > 1 || (!this.isUserView && this.isInAdminView);
485                        if (!tabBarIsUseful) {
486                            tabs.hideTabsHeader();
487                        }
488                        //new here for async ? march 16 2024
489                        return [2 /*return*/, data.bayesNets];
490                }
491            });
492        }); };
493        this.generateNextBayesNetContainerId = function () {
494            var index = 1;
495            var getId = function (index) { return "bayes_net_set-" + index + "-" + _this.questionSet().setId(); };
496            var id = getId(index);
497            var found = false;
498            while (!found) {
499                var duplicate = _this.findBayesNetContainer(id);
500                if (duplicate) {
501                    index++;
502                    id = getId(index);
503                }
504                else {
505                    found = true;
506                    break;
507                }
508            }
509            return id;
510        };
511        this.nodeCreatedListener = false;
512        this.nodeModifiedListener = false;
513        this.nodeRemovedListener = false;
514        this.setupBayesNet = function (bayesNetId, netId, data) {
515            var svgContainer = _this.findBayesNetContainer(bayesNetId);
516            if (!svgContainer)
517                return;
518            // Fill the parent canvas frame; BayesNet sizes the SVG from that measured width.
519            svgContainer.style.width = '100%';
520            // Remove loading indicatoe
521            var loading = svgContainer.getElementsByClassName("loading")[0];
522            if (loading)
523                loading.remove();
524            // Load the bayes net
525            var canEditAsAdmin = !_this.isUserView && _this.isInAdminView;
526            var stageNumber = 1;
527            try {
528                var currentUser = Distiller.currentUser && Distiller.currentUser();
529                if (currentUser && typeof currentUser.stageNumber === 'function') {
530                    stageNumber = currentUser.stageNumber();
531                }
532            }
533            catch (e) {
534                stageNumber = 1;
535            }
536            var isEditable = stageNumber === 1
537                && !_this.preventForecastUpdates
538                && (canEditAsAdmin || data.canEdit);
539            var bayesNet = new BayesNet(_this.questionSet(), svgContainer, netId, isEditable, true, _this.preventForecastUpdates, _this.userId, _this.asOfDate, _this.readOnlyUiParams, _this.teamDisplay);
540            bayesNet.setHeight(700);
541            if (!_this.preventForecastUpdates) {
542                //new here from AB 3/21/23
543                bayesNet.setOnNodeCreatedListener(_this.onNodeCreated);
544                bayesNet.setOnNodeModifiedListener(_this.onNodeChanged);
545                bayesNet.setOnNodeRemovedListener(_this.onNodeRemoved);
546            }
547            else {
548                if (_this.asOfDate) {
549                    bayesNet.setOnNodeModifiedListener(_this.onNodeChangedDuringSimulation);
550                }
551            }
552            bayesNet.load(data);
553            _this.activeBayesNet = bayesNet;
554            if (_this.onBayesNetReady) {
555                _this.onBayesNetReady(bayesNet);
556            }
557        };
558        this.onNodeCreated = function (node) { return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
559            return [2 /*return*/, Distiller.httpPostJsonAsync("".concat(Distiller.apiEndpoint, "/api/bayesNet/node/create"), __assign(__assign({}, node), { setId: this.getSetId(), userId: this.userId }), resolve)];
560        }); }); }); };
561        this.onNodeChangedDuringSimulation = function (node) { return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
562            return [2 /*return*/, Distiller.httpPostJsonAsync("".concat(Distiller.apiEndpoint, "/api/bayesNet/node/simulateModify"), __assign(__assign({}, node), { setId: this.getSetId(), userId: this.userId, asOfDate: this.asOfDate }), resolve)];
563        }); }); }); };
564        this.onNodeChanged = function (node) { return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
565            return [2 /*return*/, Distiller.httpPostJsonAsync("".concat(Distiller.apiEndpoint, "/api/bayesNet/node/modify"), __assign(__assign({}
565, node), { setId: this.getSetId(), userId: this.userId }), resolve)];
566        }); }); }); };
567        this.onNodeRemoved = function (selectedNodeId) { return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
568            return [2 /*return*/, Distiller.httpDeleteAsync("".concat(Distiller.apiEndpoint, "/api/bayesNet/node/").concat(this.getSetId(), "/").concat(selectedNodeId), resolve)];
569        }); }); }); };
570        this.loadAllBayesNetData = function (userId, questionSetId) { return new Promise(function (resolve) {
571            var query = [];
572            if (_this.asParticipant) {
573                query.push('asParticipant=1');
574            }
575            if (_this.viewSharedTemplate) {
576                query.push('viewSharedTemplate=1');
577            }
578            if (_this.templateNetId) {
579                query.push('templateNetId=' + encodeURIComponent(String(_this.templateNetId)));
580            }
581            var qs = query.length ? '?' + query.join('&') : '';
582            Distiller.httpGetAsync("".concat(Distiller.apiEndpoint, "/api/bayesNets/").concat(userId, "/").concat(questionSetId).concat(qs), resolve);
583        }); };
584        this.loadAllBayesNetDataTeamMedians = function (userId, questionSetId) { return new Promise(function (resolve) { return Distiller.httpGetAsync("".concat(Distiller.apiEndpoint, "/api/bayesNets/teamMedians/").concat(userId, "/").concat(questionSetId), resolve); }); };
585        this.loadAllBayesNetDataAsOfDate = function (userId, questionSetId, asOfDate) { return new Promise(function (resolve) { return Distiller.httpGetAsync("".concat(Distiller.apiEndpoint, "/api/bayesNetsAsOfDate/").concat(userId, "/").concat(questionSetId, "/").concat(asOfDate), resolve); }); };
586        this.loadBayesNetData = function (userId, questionSetId, netId) { return new Promise(function (resolve) { return Distiller.httpGetAsync("".concat(Distiller.apiEndpoint, "/api/bayesNets/").concat(userId, "/").concat(questionSetId, "/").concat(netId), resolve); }); };
587        this.deleteBayesNet = function (questionSetId, netId) { return new Promise(function (resolve) { return Distiller.httpDeleteAsync("".concat(Distiller.apiEndpoint, "/api/bayesNets/tab"), resolve, { setId: questionSetId, netId: netId }); }); };
588        this.setBayesNetTemplateState = function (netId, isTemplate) { return new Promise(function (resolve) { return Distiller.httpPostAsync("".concat(Distiller.apiEndpoint, "/api/bayesNets/template"), resolve, { netId: netId, isTemplate: isTemplate }); }); };
589        this.setBayesNetEditableState = function (netId, canEdit) { return new Promise(function (resolve) { return Distiller.httpPostAsync("".concat(Distiller.apiEndpoint, "/api/bayesNets/editable"), resolve, { netId: netId, canEdit: canEdit }); }); };
590        this.requestIsAdmin = function (userId) { return new Promise(function (resolve) { return Distiller.httpGetAsync("".concat(Distiller.apiEndpoint, "/api/userIsAdmin/").concat(userId), resolve); }); };
591        this.getSetId = function () { return _this.questionSet().setId(); };
592        this.hideLoadingScreen = function () {
593            var loadingSplash = document.getElementById(_this.getLoadingSplashId())
594                || _this.queryInComponent('.bayesNetViewLoading');
595            if (loadingSplash === null || loadingSplash === void 0 ? void 0 : loadingSplash.parentNode) {
596                loadingSplash.parentNode.removeChild(loadingSplash);
597            }
598            var tabsContainer = _this.getTabsElement();
599            if (tabsContainer) {
600                tabsContainer.style.display = "block";
601                var contents = tabsContainer.querySelectorAll('.tabs__content');
602                for (var i = 0; i < contents.length; i++) {
603                    contents[i].style.display = 'block';
604                }
605            }
606        };
607        this.rootElement = (_a = componentInfo === null || componentInfo === void 0 ? void 0 : componentInfo.element) !== null && _a !== void 0 ? _a : null;
608        this.isUserView = (_b = params === null || params === void 0 ? void 0 : params.isUserView) !== null && _b !== void 0 ? _b : false;
609        this.asParticipant = (_c = params === null || params === void 0 ? void 0 : params.asParticipant) !== null && _c !== void 0 ? _c : false;
610        this.viewSharedTemplate = (_d = params === null || params === void 0 ? void 0 : params.viewSharedTemplate) !== null && _d !== void 0 ? _d : false;
611        var rawTemplateId = params && params.templateNetId;
612        var templateVal = typeof rawTemplateId === 'function' ? rawTemplateId() : rawTemplateId;
613        var parsedTemplateId = templateVal != null ? parseInt(String(templateVal), 10) : NaN;
614        this.templateNetId = Number.isFinite(parsedTemplateId) && parsedTemplateId > 0 ? parsedTemplateId : null;
615        this.teamDisplay = (_e = params === null || params === void 0 ? void 0 : params.teamDisplay) !== null && _e !== void 0 ? _e : false;
616        this.userId = (_f = params === null || params === void 0 ? void 0 : params.userId) !== null && _f !== void 0 ? _f : Distiller.currentUser().userId;
617        this.questionSet((_g = params === null || params === void 0 ? void 0 : params.set) !== null && _g !== void 0 ? _g : params === null || params === void 0 ? void 0 : params.questionSet);
618        this.onBayesNetReady = (params === null || params === void 0 ? void 0 : params.onBayesNetReady) || null;
619        if (Distiller.updatingSimForecasts()) {
620            // this.loopThroughDates(); //comment out in prod
621        }
622        else {
623            var self_2 = this;
624            self_2.beginSetupPage();
625        }
626        if (params === null || params === void 0 ? void 0 : params.hidingText) {
627            this.hidingText(params === null || params === void 0 ? void 0 : params.hidingText);
628        }
629        if (params.preventForecastUpdates) {
630            this.preventForecastUpdates = params.preventForecastUpdates;
631        }
632        if (params.readOnlyUiParams) {
633            this.readOnlyUiParams = params.readOnlyUiParams;
634            Distiller.expandedBayesNodeReadOnlyUiParams(params.readOnlyUiParams);
635        }
636        Distiller.expandedBayesNodeReadOnlyTeamDisplay((_h = params === null || params === void 0 ? void 0 : params.teamDisplay) !== null && _h !== void 0 ? _h : false);
637    }
638    BayesNetViewModel.prototype.getResolvedNodes = function () {
639        return __awaiter(this, void 0, void 0, function () {
640            var _this = this;
641            return __generator(this, function (_a) {
642                return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
643                        return __generator(this, function (_a) {
644                            Distiller.httpGetAsync(Distiller.apiEndpoint + "/api/bayesNets/resolvedNodes/" + this.questionSet().setId(), function (response) {
645                                console.log("response ", response);
646                                response = JSON.parse(response);
647                                resolve(response);
648                            });
649                            return [2 /*return*/];
650                        });
651                    }); })];
652            });
653        });
654    };
655    return BayesNetViewModel;
656}());
657export default BayesNetViewModel;

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.