|
26 | 26 | % regular expression pattern
|
27 | 27 | % - if dataset is a struct, find database using
|
28 | 28 | % the _find API
|
| 29 | +% 'gui': start a GUI and interactively browse datasets |
29 | 30 | %
|
30 | 31 | % admin commands (require database admin credentials):
|
31 | 32 | % 'put': create database, create dataset under a dataset, or
|
|
40 | 41 | % jsonstring: the JSON raw data from the URL
|
41 | 42 | %
|
42 | 43 | % example:
|
| 44 | +% neuroj('gui') % start neuroj client in the GUI mode |
| 45 | +% |
43 | 46 | % res = neuroj('list') % list all databases under res.database
|
44 | 47 | % res = neuroj('list', 'cotilab') % list all dataset under res.dataset
|
45 | 48 | % res = neuroj('list', 'cotilab', 'CSF_Neurophotonics_2025') % list all versions
|
|
66 | 69 | return
|
67 | 70 | end
|
68 | 71 |
|
| 72 | +function loaddb(src, event) |
| 73 | + dbs = neuroj('list'); |
| 74 | + set(lsDb, 'String', (cellfun(@(x) x.id, dbs.database, 'UniformOutput', false))); |
| 75 | +end |
| 76 | + |
| 77 | +function loadds(src, event, keydata) |
| 78 | + get(fmMain, 'SelectionType'); |
| 79 | + if strcmp(get(fmMain, 'SelectionType'), 'open') |
| 80 | + idx = get(src, 'value'); |
| 81 | + dbs = get(src, 'string'); |
| 82 | + dslist = neuroj('list', dbs{idx}); |
| 83 | + set(lsDs, 'string', {dslist.dataset.id}); |
| 84 | + set(lsDb, 'tag', dbs{idx}); |
| 85 | + end |
| 86 | +end |
| 87 | + |
| 88 | +function loaddsdata(src, event, keydata) |
| 89 | + get(fmMain, 'SelectionType'); |
| 90 | + if strcmp(get(fmMain, 'SelectionType'), 'open') |
| 91 | + idx = get(src, 'value'); |
| 92 | + dbs = get(src, 'string'); |
| 93 | + dbid = get(lsDb, 'tag'); |
| 94 | + datasets = jdict(neuroj('get', dbid, dbs{idx})); |
| 95 | + set(lsJSON, 'string', cellfun(@(x) decodevarname(x), datasets.keys(), 'UniformOutput', false), 'value', 1); |
| 96 | + set(lsJSON, 'userdata', datasets); |
| 97 | + set(lsJSON, 'tag', ''); |
| 98 | + end |
| 99 | +end |
| 100 | + |
| 101 | +function expandjsontree(src, event, keydata) |
| 102 | + if (~isa(get(lsJSON, 'userdata'), 'jdict')) |
| 103 | + return |
| 104 | + end |
| 105 | + get(fmMain, 'SelectionType'); |
| 106 | + if strcmp(get(fmMain, 'SelectionType'), 'open') |
| 107 | + idx = get(src, 'value'); |
| 108 | + dbs = get(src, 'string'); |
| 109 | + rootpath = get(lsJSON, 'tag'); |
| 110 | + datasets = get(lsJSON, 'userdata'); |
| 111 | + if (isempty(rootpath)) |
| 112 | + rootpath = '$'; |
| 113 | + end |
| 114 | + if (strcmp(dbs{idx}, '..')) |
| 115 | + rootpath = regexprep(rootpath, '\[[^\]]+\]$', ''); |
| 116 | + else |
| 117 | + rootpath = [rootpath '["' dbs{idx} '"]']; |
| 118 | + end |
| 119 | + |
| 120 | + datasets = datasets.(rootpath); |
| 121 | + try |
| 122 | + subitem = cellfun(@(x) decodevarname(x), datasets.keys(), 'UniformOutput', false); |
| 123 | + if (~strcmp(rootpath, '$')) |
| 124 | + subitem = {'..', subitem{:}}; |
| 125 | + end |
| 126 | + set(lsJSON, 'string', subitem, 'value', 1); |
| 127 | + set(lsJSON, 'tag', rootpath); |
| 128 | + catch |
| 129 | + end |
| 130 | + end |
| 131 | +end |
| 132 | + |
| 133 | +if (nargin == 1 && strcmp(cmd, 'gui')) |
| 134 | + fmMain = figure; |
| 135 | + tbTool = uitoolbar(fmMain); |
| 136 | + btLoadDb = uipushtool(tbTool, 'ClickedCallback', @loaddb); |
| 137 | + if (~isoctavemesh) |
| 138 | + btLoadDb.CData = rand(40, 40, 3); |
| 139 | + end |
| 140 | + lsDb = uicontrol(fmMain, 'tooltipstring', 'Database', 'style', 'listbox', 'units', 'normalized', 'position', [0 0 1 / 5 1], 'Callback', @loadds, 'KeyPressFcn', @loadds); |
| 141 | + lsDs = uicontrol(fmMain, 'tooltipstring', 'Dataset', 'style', 'listbox', 'units', 'normalized', 'position', [1 / 5 0 1 / 4 1], 'Callback', @loaddsdata, 'KeyPressFcn', @loaddsdata); |
| 142 | + lsJSON = uicontrol(fmMain, 'tooltipstring', 'Data', 'style', 'listbox', 'units', 'normalized', 'position', [9 / 20 0 1 - 9 / 20 1], 'Callback', @expandjsontree, 'KeyPressFcn', @expandjsontree); |
| 143 | + return |
| 144 | +end |
| 145 | + |
69 | 146 | dbname = '';
|
70 | 147 | if (~isempty(varargin))
|
71 | 148 | dbname = varargin{1};
|
|
232 | 309 | end
|
233 | 310 | end
|
234 | 311 | end
|
| 312 | + |
| 313 | +end |
0 commit comments