-
Notifications
You must be signed in to change notification settings - Fork 219
/
main.js
135 lines (126 loc) · 4.68 KB
/
main.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
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
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
/* eslint-disable new-cap */
import 'bootstrap/dist/css/bootstrap.min.css';
import './main.scss';
import {Dropdown} from 'bootstrap';
import * as Authorization from './modules/environments/authorization.js';
import * as Environments from './modules/environments/environments.js';
import * as Attributes from './modules/things/attributes.js';
import * as Features from './modules/things/features.js';
import * as FeatureMessages from './modules/things/featureMessages.js';
import * as Fields from './modules/things/fields.js';
import * as SearchFilter from './modules/things/searchFilter.js';
import * as Things from './modules/things/things.js';
import * as ThingsSearch from './modules/things/thingsSearch.js';
import * as ThingsCRUD from './modules/things/thingsCRUD.js';
import * as ThingsSSE from './modules/things/thingsSSE.js';
import * as MessagesIncoming from './modules/things/messagesIncoming.js';
import * as Connections from './modules/connections/connections.js';
import * as ConnectionsCRUD from './modules/connections/connectionsCRUD.js';
import * as ConnectionsMonitor from './modules/connections/connectionsMonitor.js';
import * as Operations from './modules/operations/operations.js';
import * as Policies from './modules/policies/policies.js';
import * as Utils from './modules/utils.js';
import {WoTDescription} from './modules/things/wotDescription.js';
import './modules/utils/crudToolbar.js';
let resized = false;
let mainNavbar;
document.addEventListener('DOMContentLoaded', async function() {
Utils.ready();
await Things.ready();
ThingsSearch.ready();
ThingsCRUD.ready();
ThingsSSE.ready();
MessagesIncoming.ready();
Attributes.ready();
await Fields.ready();
await SearchFilter.ready();
Features.ready();
await FeatureMessages.ready();
Policies.ready();
Connections.ready();
ConnectionsCRUD.ready();
ConnectionsMonitor.ready();
Operations.ready();
Authorization.ready();
await Environments.ready();
const thingDescription = WoTDescription({
itemsId: 'tabItemsThing',
contentId: 'tabContentThing',
}, false);
Things.addChangeListener(thingDescription.onReferenceChanged);
thingDescription.ready();
const featureDescription = WoTDescription({
itemsId: 'tabItemsFeatures',
contentId: 'tabContentFeatures',
}, true);
Features.addChangeListener(featureDescription.onReferenceChanged);
featureDescription.ready();
// make dropdowns not cutting off
new Dropdown(document.querySelector('.dropdown-toggle'), {
popperConfig: {
strategy: 'fixed',
},
});
// make top navbar activating and setting the right auth header
mainNavbar = document.getElementById('mainNavbar');
mainNavbar.querySelectorAll('.nav-link').forEach((e) => {
e.addEventListener('click', (event) => {
mainNavbar.querySelectorAll('.nav-link,.active').forEach((n) => n.classList.remove('active'));
event.currentTarget.classList.add('active');
});
});
// make tables toggle background on selection
document.querySelectorAll('.table').forEach((e) => {
e.addEventListener('click', (event) => {
if (event.target && event.target.tagName === 'TD') {
Array.from(event.target.parentNode.parentNode.children).forEach((n) => {
if (n !== event.target.parentNode) {
n.classList.remove('table-active');
}
});
event.target.parentNode.classList.toggle('table-active');
}
});
});
// make ace editor resize when user changes height
const resizeObserver = new ResizeObserver(() => {
resized = true;
});
document.querySelectorAll('.resizable_pane').forEach((e) => {
resizeObserver.observe(e);
e.addEventListener('mouseup', () => {
if (resized) {
window.dispatchEvent(new Event('resize'));
resized = false;
}
});
});
// Make all input field remove invalid marker on change
const {get, set} = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value');
document.querySelectorAll('input').forEach((input) => {
input.addEventListener('change', (event) => {
event.target.classList.remove('is-invalid');
});
Object.defineProperty(input, 'value', {
get() {
return get.call(this);
},
set(newVal) {
input.classList.remove('is-invalid');
return set.call(this, newVal);
},
});
});
});