-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·343 lines (303 loc) · 18.2 KB
/
index.html
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<!doctype html>
<html>
<head>
<title>The DNAP Studio</title>
<meta name="description" content="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="vendor/font-awesome/css/font-awesome.min.css" />
<link rel="stylesheet" href="vendor/css/spectrum.css" />
<link rel="stylesheet" href="dist/formbuilder.css" />
</head>
<body>
<header><a href="." style="text-decoration:none;"><span class="logo"></span></a> <h1>DNAP Studio | <small>reference implementation of a Persona IDE</small></h1></header>
<article>
<div class='fb-main'></div>
</article>
<footer>
<table>
<tr>
<td>
<p>Hi there! Welcome to the official reference implementation of a DNAP Studio. The Studio is an Integrated Development Environment (IDE) for Personas - apps built using Cwa Script. If you already know how to use this tool - <b>The DNAP Studio</b>, then please proceed as you wish. Otherwise, if you need to learn how to use this or have inquiries about the technology, visit our docs or contact us here - <a target="_blank" href="https://chwezi.tech/dna/">CHWEZI.TECH</a></p>
<!-- p> Learn more about
<a target="_blank" href="https://nuscribes.com/scribes_app/book/40/read/#Studio">The Studio</a>,
<a target="_blank" href="https://nuscribes.com/scribes_app/book/40/read/#Histrion">Histrion</a>,
<a target="_blank" href="https://nuscribes.com/scribes_app/book/40/read/#Theatre">Theatre</a>,
and Diviner, that are all part of the cutting-edge nu data & cloud technology platform called
<a target="_blank" href="https://nuscribes.com/scribes_app/book/40/read/?#chapter-500">Project Okot (P'Okot)</a> - another up-to-date solution for businesses and individuals, brought to you by the NuChwezi Labs
</p -->
</td>
<td>
<a target="_blank" href="https://nuchwezi.com">
<span class="logo-nuchwezi"></span>
</a>
</td>
</tr>
</table>
</footer>
<script src="vendor/js/vendor.js"></script>
<script src="vendor/js/qrcode.js"></script>
<script src="vendor/js/jquery.qrcode.js"></script>
<script src="vendor/js/FileSaver.js"></script>
<script src="vendor/js/Blob.js"></script>
<script src="vendor/js/spectrum.js"></script>
<script src="vendor/js/randomColor.min.js"></script>
<script src="dist/formbuilder.js"></script>
<script>
function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
var defaultQRCODE_SIZE = 200;
var defaultQRCODE_EXPORT_SIZE = 500;
var defaultEXPORT_SIZE_H = 400;
var defaultEXPORT_SIZE_W = 1000;
function make_qrcode(selector,data,size){
$(selector).empty();
$(selector).qrcode({
render: 'canvas',
width: size,
height: size,
text: data
});
}
function init_fb(persona){
fb = null;
if(persona) {
fb = new Formbuilder({
selector: '.fb-main',
bootstrapData: persona.fields
});
$('#app-name').val(persona.app.name);
$('#app-color').spectrum();
$('#app-color').spectrum('set', persona.app.color);
$('#publish-channel').val(persona.app.channel);
$('#app-brand-image').val(persona.app.brand_image);
$('#theatre-uri').val(persona.app.theatre_address);
$('#transport-mode').val(persona.app.transport_mode);
$('#app-description').val(persona.app.description);
if(persona.app.uuid)
window.app_uuid = persona.app.uuid;
else
window.app_uuid = undefined;
}
else {
fb = new Formbuilder({
selector: '.fb-main',
});
$('#app-color').spectrum();
$('#app-color').spectrum('set', randomColor() );
$('#theatre-uri').val('https://chwezi.tech/api/act/create/').attr({'title': 'Your data will be hosted by us by default, but you can point to your own servers'});
$('#transport-mode').val('POST');
}
if(fb == null)
return;
fb.on('save', function(payload){
console.log(payload);
if(window.publish_persona){
$('#code').html('<span class="publish-status">Wait as this persona is published...</span>');
$.ajax({
url: 'https://chwezi.tech/api/persona/create/',
type: 'POST',
data: payload,
contentType: "application/json",
success: function(data){
data = JSON.parse(data);
console.log(data)
make_qrcode('#code',data.api, defaultQRCODE_EXPORT_SIZE);
var btn_use_app = $('<a/>', {'target': '_blank', 'href': data.app, 'class': 'fb-button', 'style': 'margin:10px'}).text('START USING THIS APP!');
var btn_app_stats = $('<a/>', {'target': '_blank', 'href': data.analytics, 'class': 'fb-button', 'style': 'margin:10px'}).text('ANALYTICS FOR THIS APP!');
$('#code').prepend(
btn_use_app,
btn_app_stats
);
try{
var persona = JSON.parse(payload);
ga('send', 'event', 'App-Publish', 'success', persona.app.name, 10);
btn_use_app.click(function(e){
ga('send', 'event', {
eventCategory: 'Histrion-Link',
eventAction: 'click',
eventLabel: event.target.href,
eventValue: 10,
transport: 'beacon'
});
});
btn_app_stats.click(function(e){
ga('send', 'event', {
eventCategory: 'Diviner-Link',
eventAction: 'click',
eventLabel: event.target.href,
eventValue: 10,
transport: 'beacon'
});
});
}catch(e){}
},
error: function(){
$('#code').html('<span class="publish-failed">Publishing of this persona failed. Ensure that this studio has access to persona publishing facility, such as a theatre. Contact tech[at]nuchwezi[dot]com, for access to a reliable, first-class theatre implementation, or get access to the entire suite of technologies on the DNAP.</span>');
try{
var persona = JSON.parse(payload);
ga('send', 'event', 'App-Publish-Failure', 'error', persona.app.name, -5);
}catch(e){}
}
});
window.publish_persona = false;
}
if(window.download_persona){
var appName = JSON.parse(payload).app.name.replace(/\s+/g,"_") || "Persona";
var persona_file_name = appName + "-" + (new Date()).toISOString() + ".persona";
$('#code').html('<span class="publish-status">Please save the generated Persona file: ' + persona_file_name + '</span>');
saveAs(new Blob([payload], { type: "application/json+persona" }), persona_file_name)
window.download_persona = false;
try{
var persona = JSON.parse(payload);
ga('send', 'event', 'App-Download', 'success', persona.app.name, 8);
}catch(e){}
}
})
$('#import-persona-file').on('change',function(evt){
var files = evt.target.files;
var file = files[0];
var reader = new FileReader();
reader.onload = function() {
console.log(this.result);
try{
var persona = JSON.parse(this.result);
init_fb(persona);
ga('send', 'event', 'App-Import', 'file', persona.app.name, 8);
$('#code').html('<span class="publish-status">A new persona has been imported. You can now proceed with modifying it...</span>');
}catch(e){
$('#code').html('<span class="publish-failed">Parsing or loading the import persona failed! Check the input against the standard persona specifications, and whether it can be accessed by this Studio, and then try again.</span>');
ga('send', 'event', 'App-Import-Failure', 'file', 'Error', -3);
}
}
reader.readAsText(file);
});
$('#js-import-persona-json').on('click',function(evt){
var personaJSON = $('#import-persona-input').val();
try{
var persona = JSON.parse(personaJSON);
init_fb(persona);
$('#code').html('<span class="publish-status">A new persona has been imported. You can now proceed with modifying it...</span>');
ga('send', 'event', 'App-Import', 'json', persona.app.name, 5);
}catch(e){
$('#code').html('<span class="publish-failed">Parsing or loading the import persona failed! Check the input against the standard persona specifications, and whether it can be accessed by this Studio, and then try again.</span>');
ga('send', 'event', 'App-Import-Failure', 'json', 'Error', -1);
}
});
$('#js-import-persona-uri').on('click',function(evt){
$.ajax({
url: $('#import-persona-uri').val(),
type: 'GET',
success: function(data){
console.log(data)
try{
var persona = (typeof data === 'string' || data instanceof String) ? JSON.parse(data): data;
init_fb(persona);
$('#code').html('<span class="publish-status">A new persona has been imported. You can now proceed with modifying it...</span>');
ga('send', 'event', 'App-Import', 'url', persona.app.name, 10);
}catch(e){
$('#code').html('<span class="publish-failed">Parsing or loading the import persona failed! Check the input against the standard persona specifications, and whether it can be accessed by this Studio, and then try again.</span>');
}
},
error: function(){
$('#code').html('<span class="publish-failed">Parsing or loading the import persona failed! Check the input against the standard persona specifications, and whether it can be accessed by this Studio, and then try again.</span>');
ga('send', 'event', 'App-Import-Failure', 'url', 'Error', -5);
}
});
});
}
/* used in the persona encoding functions... */
function generateUUID(){
var d = new Date().getTime();
if(window.performance && typeof window.performance.now === "function"){
d += performance.now(); //use high-precision timer if available
}
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = (d + Math.random()*16)%16 | 0;
d = Math.floor(d/16);
return (c=='x' ? r : (r&0x3|0x8)).toString(16);
});
window.app_uuid = uuid;
return uuid;
}
$(function(){
// first, we check if the studio needs to be bootstrapped some way...
var query = getUrlVars();
if(query.purl != undefined){
//first, initialize normally...
init_fb();
$('#code').html('<span class="publish-status">The persona specified in the URL is being loaded. Please wait...</span>');
// then go on and fetch the persona to bootstrap with...
$.ajax({
url: query.purl,
async: true,
crossDomain: true,
type: 'GET',
success: function(data){
console.log(data)
try{
var persona = (typeof data === 'string' || data instanceof String) ? JSON.parse(data): data;
if(query.t != undefined){
delete persona.app.uuid; // we don't want to override the default
}
init_fb(persona);
$('#code').html('<span class="publish-status">The Studio has been bootstrapped with the specified persona. You can now proceed with modifying it as you wish...</span>');
ga('send', 'event', 'App-Bootstrap', 'url', persona.app.name, 10);
}catch(e){
$('#code').html('<span class="publish-failed">Parsing or loading the persona specified in the URL failed! Check the resource linked to, against the standard persona specifications, and whether it can be accessed by this Studio, and then try again.</span>');
ga('send', 'event', 'App-Bootstrap-Failure', 'url', 'Error', -5);
}
},
error: function(){
$('#code').html('<span class="publish-failed">Parsing or loading the persona specified in the URL failed! Check the resource linked to, against the standard persona specifications, and whether it can be accessed by this Studio, and then try again.</span>');
}
});
}
else {
init_fb();
}
});
$(document).on('ready',function(){
$.ajax ({
url: 'https://chwezi.tech/api/template/personas/?t=' + (new Date()).toISOString(),
//url: 'https://api.myjson.com/bins/13os2',
success: function(data){
data = JSON.parse(data);
console.log(data);
var tholder = $('#template-entries');
$.each(data,function(i,t){
tholder.append(
$('<div/>', { 'class': 'app-template' }).
append(
$('<b>' + t.name + '</b>', {'class': 'app-template-name'}),
$('<a/>', { 'href': t.studio, 'title': 'Click to edit this template directly in The Studio', class: 'app-template-link' }).append(
$('<img/>', {src: t.image || 'https://i.postimg.cc/pryKmDW2/161121-00029098300-TOOLBOX.jpg', 'class':'app-template-img' })
),
'<p>' + t.description + '</p>',
'<hr/>'
)
);
});
}
});
});
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-51296531-6', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>