-
Notifications
You must be signed in to change notification settings - Fork 4
/
protocol.js
239 lines (222 loc) · 7.46 KB
/
protocol.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
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
let protocolReady = false
function waitForProtocolReady(callback) {
var interval = setInterval(function() {
if (protocolReady) {
clearInterval(interval);
callback();
}
}, 200);
}
function displayProtocol() {
document.getElementById("maincontent").replaceChildren(prepWindow())
document.getElementById("heading").innerText = "Stackerstan Superprotocolo"
document.getElementById("content").replaceChildren(loadingSign())
waitForProtocolReady(function () {
subscribeidentity()
document.getElementById("content").replaceChildren(renderProtocol())
})
//document.getElementById("content").replaceChildren(renderProtocolObjects(document.getElementById("content").clientWidth))
document.getElementById("details").replaceChildren()
rewriteURL("protocol")
}
function renderProtocol() {
let div = document.createElement("div")
//waitForProtocolReady(function () {
//todo ignition
let rootProtocol = protocolObjects.get("1a54f1f4ceabd11ef562cbb031f4ed0faf4091606fd9998b574dfb1b887e8b5d")
div.appendChild(renderProtocolChildren(rootProtocol))
// })
return div
}
function renderProtocolChildren(item) {
let div = document.createElement("div")
var children = getProtocolChildren(item)
div.appendChild(renderProtocolItem(item))
children.forEach(function (child) {
div.firstChild.childNodes[1].appendChild(renderProtocolChildren(child))
})
return div
}
function getProtocolChildren(e) {
//console.log(e)
let a = Array()
e.tags.forEach(function (tag) {
if (tag[0] === "nests") {
tag.forEach(function (t) {
if (t.length === 64) {
var child = protocolObjects.get(t)
if (child !== undefined) {
a.push(child)
}
}
})
}
})
sortItemsByHeight(a)
return a
}
function renderProtocolItem(item) {
let article = document.createElement("div");
//todo change colours based on status (closed, claimed, open)
article.className = "box" //"message is-dark"// + getProtocolColour(item);
article.onmouseover = function () {
article.style.backgroundColor = "#1c1c1c"
}
article.onmouseleave = function () {
article.style.backgroundColor = "#2f2e2e"
}
tag = document.createElement("span")
tag.className = "tag " + getProtocolColour(item)
tag.innerText = getProtocolObjectType(item)
tagspacer = document.createElement("span")
tagspacer.innerText = " "
content = item.content
split = content.split(/\r?\n/);
heading = split.shift()
content = split
htext = document.createElement("strong")
htext.innerText = heading
var head = document.createElement("div")
head.className = "is-clickable"
head.appendChild(tag)
head.appendChild(tagspacer)
head.appendChild(htext)
var suid = document.createElement("div")
suid.innerText = item.mindmachineUID
suid.style.fontSize = "x-small"
head.appendChild(suid)
//head.className = "content"//"message-header"
head.onclick = function () {
showDetails(item)
}
children = document.createElement("div")
children.id = `childrenof` + item.mindmachineUID
article.appendChild(head)
article.appendChild(children)
return article
}
function getProtocolColour(e) {
let objType = getProtocolObjectType(e)
switch (objType) {
case objType = "Definition": {
return "is-primary"
}
case objType = "Goal": {
return "is-dark"
}
case objType = "Rule": {
return "is-warning"
}
case objType = "Invariant": {
return "is-danger"
}
case objType = "Protocol": {
return "is-link"
}
}
}
function getProtocolObjectType(e) {
var t = ""
e.tags.forEach(function (tag) {
if (tag[0] === "kind") {
t = tag[1]
}
})
return t
}
function newProtocolForm(parentID) {
let div = document.createElement("div")
let protocolText = document.createElement("textarea")
protocolText.placeholder = "Protocol Text"
protocolText.maxLength = 280
protocolText.className = "textarea is-primary"
let typeContainer = document.createElement("div")
typeContainer.className = "select is-primary"
let type = document.createElement("select")
type.appendChild(selectItem("Select"))
type.appendChild(selectItem("Definition"))
type.appendChild(selectItem("Goal"))
type.appendChild(selectItem("Rule"))
type.appendChild(selectItem("Invariant"))
type.appendChild(selectItem("Protocol"))
typeContainer.appendChild(type)
let supersedes = document.createElement("input")
supersedes.type = "text"
supersedes.className = "input is-primary"
supersedes.style = "width: 100%;"
supersedes.placeholder = "OPTIONAL: SUID of the item this supersedes"
let nests = document.createElement("textarea")
nests.placeholder = "IDs of SSP items that should be nested under this item.\nOne\nPer\nLine"
nests.className = "textarea is-primary"
let problemID = document.createElement("input")
problemID.type = "text"
problemID.placeholder = "Problem SUID"
problemID.className = "input is-primary"
let submitbtn = document.createElement("button")
submitbtn.textContent = "Submit"
submitbtn.className = "button is-primary"
submitbtn.onclick = function () {
if (!accountIsInIdentityTree(storedPubkey)) {
alert("You must be in the Identity Tree to do that")
} else {
createNewProtocolItem(problemID.value, protocolText.value, type.value, supersedes.value, nests.value, parentID)
problemID.value = ""
protocolText.value = ""
type.value = ""
supersedes.value = ""
nests.value = ""
}
}
div.appendChild(protocolText)
div.appendChild(problemID)
div.appendChild(supersedes)
div.appendChild(nests)
div.appendChild(typeContainer)
div.appendChild(submitbtn)
return div
}
function selectItem(name) {
opt = document.createElement("option")
opt.value = name.toLowerCase()
opt.innerText = name
return opt
}
function createNewProtocolItem(problemID, text, kind, supersedes, nests, parentID) {
et = makeEvent(text)
signHash(et.id).then(
function (result) {
et.sig = result
sendIt(et)
//send it again because for some reason it fails half the fucking time
sendIt(et)
//todo ignition
//let temp = "9565f8017b13e82d2bb9b9fed9e4c5275feffddd820fe416541dcb70eb1416b5"
sendNewProtocolItem(problemID, et.id, kind, supersedes, nests, parentID)
},
function (error) {
console.log(error)
})
}
function sendNewProtocolItem(problemID, textID, kind, supersedes, nests, parentID) {
// if (parentID.length === 64) {
content = JSON.stringify({
problem: problemID,
text: textID,
kind: kind,
supersedes: supersedes,
nests: nests.split(/\r?\n/),
parent: parentID
})
// } else {
// content = JSON.stringify({title: titleID, description: descriptionID})
// }
p = makeEvent(content, "", 640600)
signHash(p.id).then(
function (result) {
p.sig = result
sendIt(p)
console.log(p)
location.reload()
}
)
}