aboutsummaryrefslogtreecommitdiff
path: root/src/js/arching-kaos-web-ui-settings.js
blob: 802e770010208545096df47b48483ce2f6f03a55 (plain)
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
/* Arching Kaos Settings
 *
 * Kaotisk Hund - 2024
 *
 * @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0
 *
 */
/*
 * We will be using browser's localStorage for the clients to configure their
 * desired way to visit the web-ui.
 *
 * Proposed setting values:
 *   - Scan Stellar Asset or not
 *   - Stellar Asset to scan for addresses
 *   - ipfs gateway to use for retrieving ipfs parts (can change targeted swarm)
 *   - ring to local node (must running API locally see ../arching-kaos-tools
 *     repo)
 *   - have a follow nodeInfo/zchain list and load these
 *   - depth of retrieving at once (per zchain) (ak-enter -l X -n <zchain>)
 *
 * TODO: Make up a configuration item as well but there we could store locally
 * kays or other more personal stuff. Need to encrypt these with a password too!
 *
 */
var default_settings = {
    ipfs: {
        gateway: {
            list: [
                'https://ipfs.arching-kaos.com/',
                'http://gw.ipfs.z.kaotisk-hund.com/',
                'http://localhost:8080/'
            ],
            active: 0
        }
    },
    stellar: {
        asset: {
            list: [
                {
                    code: 'ARCHINGKAOS',
                    issuer: 'GB4QVKD6NW3CSNO5TNPARAWNPPXOPSSTKB35XCWB7PUNBIQTK3DVELB2'
                },
                {
                    code: 'KAOTISKHUND',
                    issuer: 'GDLJKMETTIXAVTZ2XXR2LHUITT7GZBNWEKQDN7V7SP4MURVY6266BIMO'
                }
            ],
            active: 0
        },
        variableNames: {
            list: [
                'config',
                'ak-config',
                'kh-config'
            ],
            active: 0
        },
        horizon: {
            list: [
                'https://horizon.stellar.org/',
                'http://horizon.stellar.z.kaotisk-hund.com/'
            ],
            active: 0
        },
        scan: true
    },
    ak: {
        settings : {
            seekDepth: 10,
        },
        connect: {
            list: [
                'http://127.0.0.1:8610',
                'http://[fc59:6076:6299:6776:c13d:fbb2:1226:ead0]:8610',
                'http://api.aknet.z.kaotisk-hund.com/'
            ],
            active: 0
        },
        scan: false
    }
}

// TODO: Make up a settings configuration page to set this up initially rather
// than forcing visitors to just save them into their local storage.
//
// We are overriding the settings each time to test our changes
// with the settings above.
//
// if ( window.localStorage.getItem("ak-settings") === null ) {
//    window.localStorage.setItem("ak-settings", JSON.stringify(default_settings));
// }
// var activeSettings = JSON.parse(window.localStorage.getItem("ak-settings"));
//
// All comments above are replaced by temporary initializing without saving
// anything in the localStorage
var activeSettings = default_settings;

// Also, remove any settings stored from previous runs
window.localStorage.removeItem("ak-settings");

// Full functionality for Stellar intergration, requires clearnet connection
// However, we have other ways of running the WEB-UI, eg locally or via a
// cjdns-based ipfs gateway.
if (( location.origin === "http://z.kaotisk-hund.com") ||
    ( location.origin === "http://gw.ipfs.z.kaotisk-hund.com") ||
    ( location.origin === "http://[fc59:6076:6299:6776:c13d:fbb2:1226:ead0]")) {
    activeSettings.ipfsSelectedGatewayAddress = 1;
    activeSettings.horizonSelectedAddress = 1;
} else if ( location.origin === "http://localhost:3000" ) {
    activeSettings.ipfsSelectedGatewayAddress = 2;
} else {
    activeSettings.ipfsSelectedGatewayAddress = 0;
}

var settingsPage = document.querySelector('#settings-section');

var settingsKeys = Object.keys(activeSettings);

function renderCheck(container, value){
    var checkbox = document.createElement('input');
    checkbox.type = 'checkbox';
    if (value === true){
        checkbox.checked = true;
    }
    container.appendChild(checkbox);
}

function renderList(container, value){
    var selectOptions = document.createElement('select');
    for ( i = 0 ; i < value.list.length; i++ ){
        var option = document.createElement("option");
        if ( i === value.active ) {
            option.selected = true;
        };
        option.innerText = value.list[i];
        option.value = i;
        selectOptions.appendChild(option);
    }
    container.appendChild(selectOptions);
}

function renderAssets(container, value){
    var selectOptions = document.createElement('select');
    for ( i = 0 ; i < value.list.length; i++ ){
        var option = document.createElement("option");
        if ( i === value.active ) {
            option.selected = true;
        };
        option.innerText = value.list[i].code + "-" + value.list[i].issuer;
        option.value = i;
        selectOptions.appendChild(option);
    }
    container.appendChild(selectOptions);
}

function settingPlaceToDOM(key, value){
    var container = document.createElement("details");
    container.innerText=key;
    if ( Array.isArray(value) ){
        var ul = document.createElement("select");
        value.map((v)=>{
            if (v.constructor.name === "Object"){
                Object.keys(v).forEach((value)=>{
                    var li = document.createElement("option");
                    li.innerText = value + ': ' + v[value];
                    li.value = value;
                    ul.appendChild(li);
                });
            } else {
                var li = document.createElement("option");
                li.innerText = v;
                li.value = v;
                ul.appendChild(li);
            }
        });
        container.appendChild(ul);
    } else if (value.constructor.name === "Object" ) {
        console.log("KEY: "+key);
        switch (key){
            case 'ipfs':
                var label = document.createElement('summary');
                label.innerText = "Gateway";
                container.appendChild(label);
                renderList(container, value.gateway);

                break;
            case 'stellar':
                var label = document.createElement('summary');
                label.innerText = "Stellar";
                container.appendChild(label);
                renderAssets(container, value.asset);

                var label = document.createElement('summary');
                label.innerText = "Variable Names";
                container.appendChild(label);
                renderList(container, value.variableNames);

                var label = document.createElement('summary');
                label.innerText = "Horizon";
                container.appendChild(label);
                renderList(container, value.horizon);

                var label = document.createElement('summary');
                label.innerText = "Scan";
                container.appendChild(label);
                renderCheck(container, value.scan);
                break;
            case 'ak':
                var label = document.createElement('summary');
                label.innerText = "Connect";
                container.appendChild(label);
                renderList(container, value.connect);
                break;
            default:
                container.innerText += " unknonwn lol";
        }
    } else {
        console.log(`Settings value: ${value}, type: ${typeof(value)}`);
//        container.innerText = value;
    }
    settingsPage.appendChild(container);
}

settingsKeys.forEach(
    (value) => {
        settingPlaceToDOM(value, activeSettings[value]);
    }
);

/* Small dump as pre text */
var predump = document.createElement('pre');
predump.innerText = JSON.stringify(activeSettings, null, 2);
settingsPage.appendChild(predump);
/* END of: Small dump as pre text */

// console.log(activeSettings.ipfsGatewayAddress[activeSettings.ipfsSelectedGatewayAddress]);

// vim: tabstop=4 shiftwidth=4 expandtab softtabstop=4
// @license-end