@datagrok/compute 1.16.1 → 1.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/package.js +1 -1
- package/dist/package.js.map +1 -1
- package/package.json +2 -2
- package/src/css/model-card.css +1 -1
- package/src/package.ts +19 -118
- package/files/default_data.csv +0 -2425
- package/scripts/trig.js +0 -15
- package/scripts/vmax.js +0 -179
- package/scripts/wrapper.js +0 -8
- package/src/function-parameters-grid.ts +0 -63
- package/src/import-script-generator/store.ts +0 -12
- package/src/import-script-generator/view.ts +0 -185
- package/src/model-catalog-view.ts +0 -84
- package/src/model-handler.ts +0 -165
- package/src/models-widget.ts +0 -118
package/src/model-handler.ts
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import * as grok from 'datagrok-api/grok';
|
|
2
|
-
import * as ui from 'datagrok-api/ui';
|
|
3
|
-
import * as DG from 'datagrok-api/dg';
|
|
4
|
-
import wu from "wu";
|
|
5
|
-
import {ModelCatalogView} from "./model-catalog-view";
|
|
6
|
-
|
|
7
|
-
export class ModelHandler extends DG.ObjectHandler {
|
|
8
|
-
get type() {
|
|
9
|
-
return 'Model';
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
async getById(id: string): Promise<DG.Func> {
|
|
13
|
-
return await grok.dapi.functions.find(id);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async refresh(x: DG.Script): Promise<DG.Func> {
|
|
17
|
-
return await this.getById(x.id);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
getLanguageIcon(language: string) {
|
|
21
|
-
if (language == 'grok')
|
|
22
|
-
return ui.iconSvg('project');
|
|
23
|
-
return ui.iconImage('script', `/images/entities/${language}.png`);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Checks whether this is the handler for [x]
|
|
27
|
-
isApplicable(x: any) {
|
|
28
|
-
return x instanceof DG.Func && x.hasTag('model');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
renderIcon(x: DG.Func, context: any = null): HTMLElement {
|
|
32
|
-
if (x.options['icon'] != null && (x.options['icon'].startsWith('http://') || x.options['icon'].startsWith('https://'))) {
|
|
33
|
-
return ui.iconImage('model-icon', x.options['icon']);
|
|
34
|
-
}
|
|
35
|
-
if (x instanceof DG.Script) {
|
|
36
|
-
return this.getLanguageIcon(x.language);
|
|
37
|
-
}
|
|
38
|
-
x = DG.Func.find({package: x.package.name, name: x.name})[0];
|
|
39
|
-
let iconUrl = x.package.getIconUrl();
|
|
40
|
-
if (x.options['icon'] != null) {
|
|
41
|
-
let packagePathSegments = iconUrl.split('/');
|
|
42
|
-
packagePathSegments.pop();
|
|
43
|
-
packagePathSegments.push(x.options['icon']);
|
|
44
|
-
iconUrl = packagePathSegments.join('/')
|
|
45
|
-
}
|
|
46
|
-
return ui.iconImage(x.package.name, iconUrl);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
renderMarkup(x: DG.Func): HTMLElement {
|
|
50
|
-
let markup = ui.span([this.renderIcon(x), ui.label(x.friendlyName)]);
|
|
51
|
-
markup.ondblclick = (e) => { ModelHandler.openModel(x); }
|
|
52
|
-
markup.onclick = (e) => { ModelHandler.openHelp(x); }
|
|
53
|
-
return markup;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async renderPreview(x: DG.Func) {
|
|
57
|
-
const editorName = x.options.editor ?? 'Compute:RichFunctionViewEditor';
|
|
58
|
-
const editor = await grok.functions.find(editorName);
|
|
59
|
-
if (editor !== null && editor instanceof DG.Func) {
|
|
60
|
-
const viewCall = editor.prepare({'call': x.prepare()});
|
|
61
|
-
await viewCall.call(false, undefined, {processed: true});
|
|
62
|
-
const view = viewCall.getOutputParamValue();
|
|
63
|
-
if (view instanceof DG.View)
|
|
64
|
-
return view;
|
|
65
|
-
}
|
|
66
|
-
//@ts-ignore
|
|
67
|
-
return super.renderPreview(x);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
renderProperties(func: DG.Func) {
|
|
71
|
-
const a = ui.accordion('ComputeModel');
|
|
72
|
-
a.context = func;
|
|
73
|
-
let titleDiv = ui.div([
|
|
74
|
-
ui.span([this.renderIcon(func), ui.label(func.friendlyName), ui.contextActions(func), ui.star(func.id)])]);
|
|
75
|
-
a.addTitle(titleDiv);
|
|
76
|
-
|
|
77
|
-
if (func.description != null)
|
|
78
|
-
titleDiv.appendChild(ui.div([ui.markdown(func.description)], 'model-catalog-description'));
|
|
79
|
-
titleDiv.appendChild(ui.tags(func));
|
|
80
|
-
if ( func.options['dev.status'] != null)
|
|
81
|
-
titleDiv.appendChild(ui.tableFromMap({Status: func.options['dev.status']}));
|
|
82
|
-
|
|
83
|
-
a.end();
|
|
84
|
-
return a.root;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
renderTooltip(x: DG.Func) {
|
|
88
|
-
let h = this.renderMarkup(x);
|
|
89
|
-
h.classList.add('d4-link-label');
|
|
90
|
-
let card = ui.bind(x, ui.divV([
|
|
91
|
-
ui.h2(h),
|
|
92
|
-
ui.divV([ui.divText(x.description, 'ui-description')], {style: {lineHeight: '150%'}})
|
|
93
|
-
]));
|
|
94
|
-
card.ondblclick = (e) => { ModelHandler.openModel(x); }
|
|
95
|
-
return card;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
renderCard(x: DG.Func, context?: any): HTMLElement {
|
|
99
|
-
let h = this.renderMarkup(x);
|
|
100
|
-
h.classList.add('d4-link-label');
|
|
101
|
-
let card = ui.bind(x, ui.h2(h));
|
|
102
|
-
card.ondblclick = (e) => { ModelHandler.openModel(x); }
|
|
103
|
-
card.onclick = (e) => { ModelHandler.openHelp(x); }
|
|
104
|
-
return card;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
static async openHelp(func: DG.Func) {
|
|
108
|
-
if (func.options['readme'] != null) {
|
|
109
|
-
const path = `System:AppData/${func.package.name}/${func.options['readme']}`;
|
|
110
|
-
const readmeText = await grok.dapi.files.readAsText(path);
|
|
111
|
-
|
|
112
|
-
grok.shell.windows.help.showHelp(ui.markdown(readmeText));
|
|
113
|
-
grok.shell.windows.showHelp = true;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
static getModelCatalogView(): ModelCatalogView {
|
|
118
|
-
let modelsView = this.findModelCatalogView();
|
|
119
|
-
if (modelsView == null) {
|
|
120
|
-
let mc: DG.Func = DG.Func.find({package:'Compute', name: 'ModelCatalog'})[0];
|
|
121
|
-
let fc = mc.prepare();
|
|
122
|
-
let view = new ModelCatalogView();
|
|
123
|
-
view.name = 'Models';
|
|
124
|
-
view.parentCall = fc;
|
|
125
|
-
grok.shell.addView(view);
|
|
126
|
-
}
|
|
127
|
-
modelsView = this.findModelCatalogView();
|
|
128
|
-
return modelsView as ModelCatalogView;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
static findModelCatalogView(): ModelCatalogView | undefined {
|
|
132
|
-
return wu(grok.shell.views).find((v) => v.parentCall?.func.name == 'modelCatalog') as ModelCatalogView;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
static openModel(x: DG.Func) {
|
|
136
|
-
let fc = x.prepare();
|
|
137
|
-
fc.edit();
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
static openModelFromFunccall(funcCall: DG.FuncCall) {
|
|
141
|
-
funcCall.edit();
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
static bindModel(fc: DG.FuncCall) {
|
|
145
|
-
let modelsView = ModelHandler.getModelCatalogView();
|
|
146
|
-
fc.aux['showOnTaskBar'] = false;
|
|
147
|
-
if (modelsView != null) {
|
|
148
|
-
let parentCall = modelsView.parentCall;
|
|
149
|
-
if (parentCall != null) {
|
|
150
|
-
parentCall.aux['view'] = modelsView;
|
|
151
|
-
fc.parentCall = parentCall;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
init() {
|
|
157
|
-
setTimeout(() => {
|
|
158
|
-
grok.functions.onBeforeRunAction.subscribe((fc) => {
|
|
159
|
-
if (fc.func.hasTag('model') || fc.func.hasTag('model-editor')) {
|
|
160
|
-
ModelHandler.bindModel(fc);
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
}
|
package/src/models-widget.ts
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import * as grok from 'datagrok-api/grok';
|
|
2
|
-
import * as DG from "datagrok-api/dg";
|
|
3
|
-
import * as ui from "datagrok-api/ui";
|
|
4
|
-
import {ModelHandler} from './model-handler';
|
|
5
|
-
import $ from 'cash-dom';
|
|
6
|
-
const api = <any>window;
|
|
7
|
-
|
|
8
|
-
/*
|
|
9
|
-
|
|
10
|
-
export class ModelsWidget extends DG.Widget {
|
|
11
|
-
caption: string;
|
|
12
|
-
order: string;
|
|
13
|
-
meta: ModelHandler;
|
|
14
|
-
name: string;
|
|
15
|
-
permanentFilter: string;
|
|
16
|
-
objectType: string;
|
|
17
|
-
modelsList: HTMLDivElement;
|
|
18
|
-
|
|
19
|
-
constructor() {
|
|
20
|
-
super(ui.box());
|
|
21
|
-
|
|
22
|
-
this.meta = new ModelHandler();
|
|
23
|
-
this.name = 'Models';
|
|
24
|
-
this.permanentFilter = '#model';
|
|
25
|
-
this.objectType = 'Script';
|
|
26
|
-
|
|
27
|
-
this.caption = super.addProperty('caption', DG.TYPE.STRING, 'Models');
|
|
28
|
-
this.order = super.addProperty('order', DG.TYPE.STRING, '0');
|
|
29
|
-
|
|
30
|
-
let topbar = ui.divH([
|
|
31
|
-
ui.choiceInput('', 'Recent', ['Recent','Newest','Oldest'], (v:string) => {
|
|
32
|
-
this.modelsList.innerHTML = '';
|
|
33
|
-
this.getModels(v);
|
|
34
|
-
}).root,
|
|
35
|
-
ui.link('Open Model Catalog', ()=>{
|
|
36
|
-
grok.functions.call("Compute:ModelCatalog");
|
|
37
|
-
setTimeout(() => {
|
|
38
|
-
for (let v of grok.shell.views)
|
|
39
|
-
if (v.name === 'Models')
|
|
40
|
-
grok.shell.v = v;
|
|
41
|
-
}, 500);
|
|
42
|
-
})
|
|
43
|
-
]);
|
|
44
|
-
topbar.style.justifyContent = 'space-between';
|
|
45
|
-
topbar.style.margin = '0 12px';
|
|
46
|
-
topbar.style.alignItems = 'center';
|
|
47
|
-
|
|
48
|
-
this.modelsList = ui.divV([]);
|
|
49
|
-
this.modelsList.style.marginLeft = '12px';
|
|
50
|
-
|
|
51
|
-
this.root.appendChild(ui.splitV([
|
|
52
|
-
ui.box(topbar, {style:{maxHeight:'40px'}}),
|
|
53
|
-
this.modelsList
|
|
54
|
-
]));
|
|
55
|
-
|
|
56
|
-
DG.ObjectHandler.register(new ModelHandler());
|
|
57
|
-
|
|
58
|
-
this.getModels('updatedOn');
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
async getModels(order:string){
|
|
64
|
-
let b = true;
|
|
65
|
-
let v = order;
|
|
66
|
-
|
|
67
|
-
switch(order){
|
|
68
|
-
case 'Recent':
|
|
69
|
-
v = 'updatedOn';
|
|
70
|
-
break;
|
|
71
|
-
case 'Newest':
|
|
72
|
-
v = 'createdOn';
|
|
73
|
-
break;
|
|
74
|
-
case 'Oldest':
|
|
75
|
-
v = 'createdOn';
|
|
76
|
-
b = false;
|
|
77
|
-
break;
|
|
78
|
-
default:
|
|
79
|
-
v = 'updatedOn';
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
grok.dapi.scripts
|
|
83
|
-
.filter('#model')
|
|
84
|
-
.order(v, b)
|
|
85
|
-
.list()
|
|
86
|
-
.then((scripts) => scripts.map((p) => {
|
|
87
|
-
let d = this.meta.renderMarkup(p);
|
|
88
|
-
d.ondblclick = (e) => {
|
|
89
|
-
ModelsWidget.openModel(p);
|
|
90
|
-
}
|
|
91
|
-
d.style.color = 'var(--blue-1)';
|
|
92
|
-
d.style.margin = '4px 0';
|
|
93
|
-
$(d).find('.ui-label').addClass('ui-link');
|
|
94
|
-
|
|
95
|
-
this.modelsList.append(d)
|
|
96
|
-
}));
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
static openModel(x: DG.Script, parentCall?: DG.FuncCall) {
|
|
100
|
-
let views = []
|
|
101
|
-
for (let v of grok.shell.views)
|
|
102
|
-
views.push(v.name)
|
|
103
|
-
|
|
104
|
-
if (views.includes('Models')){
|
|
105
|
-
let view = new FunctionView(x);
|
|
106
|
-
view.parentCall = parentCall!;
|
|
107
|
-
grok.shell.addView(view);
|
|
108
|
-
}else{
|
|
109
|
-
grok.functions.call("Compute:ModelCatalog");
|
|
110
|
-
setTimeout(() => {
|
|
111
|
-
let view = new FunctionView(x);
|
|
112
|
-
view.parentCall = parentCall!;
|
|
113
|
-
grok.shell.addView(view);
|
|
114
|
-
}, 500)
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
} */
|