datagrok-api
Advanced tools
Comparing version 0.89.21 to 0.89.22
@@ -19,3 +19,3 @@ import * as _chem from './src/chem.js'; | ||
export {time, timeAsync, Utils, LruCache} from './src/utils.js'; | ||
export {JsEntityMeta} from './ui'; | ||
export {JsEntityMeta, EntityMetaDartProxy} from './ui'; | ||
@@ -22,0 +22,0 @@ export let chem = _chem; |
{ | ||
"name": "datagrok-api", | ||
"version": "0.89.21", | ||
"version": "0.89.22", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -13,3 +13,3 @@ import { | ||
LogEvent, | ||
LogEventType | ||
LogEventType, Package | ||
} from "./entities"; | ||
@@ -686,4 +686,13 @@ import {ViewLayout} from "./view"; | ||
/** Rename file | ||
* @param { File | String} file | ||
* @param {string} newName | ||
* @returns {Promise} */ | ||
rename(file, newName) { | ||
return new Promise((resolve, reject) => | ||
grok_Dapi_UserFiles_Rename(file, newName, () => resolve(), (e) => reject(e))); | ||
} | ||
/** List file | ||
* @param {File | String | String} file | ||
* @param {File | String} file | ||
* @param {boolean} recursive | ||
@@ -722,11 +731,10 @@ * @param {string} searchPattern | ||
/** Write file | ||
* @param {File | String} file | ||
* @param String data | ||
* @returns {Promise} */ | ||
writeAsText(file, data) { | ||
return new Promise((resolve, reject) => | ||
/** Write file | ||
* @param {File | String} file | ||
* @param String data | ||
* @returns {Promise} */ | ||
writeAsText(file, data) { | ||
return new Promise((resolve, reject) => | ||
grok_Dapi_UserFiles_WriteAsText(file, data, () => resolve(), (e) => reject(e))); | ||
} | ||
} | ||
} |
@@ -29,4 +29,12 @@ import * as rxjs from 'rxjs'; | ||
grok_Map_Set(d, prop, DG.toDart(value)); | ||
return true; | ||
}, | ||
deleteProperty: function (target, prop) { | ||
grok_Map_Delete(d, DG.toDart(prop)); | ||
return true; | ||
}, | ||
has: function (target, prop) { | ||
return grok_Map_Has(d, DG.toDart(prop)); | ||
} | ||
}) | ||
}); | ||
} | ||
@@ -33,0 +41,0 @@ } |
@@ -24,4 +24,14 @@ import {TYPE} from "./const"; | ||
/** Entity name | ||
/** Entity friendly name | ||
* @type {string} */ | ||
get friendlyName() { | ||
return grok_Entity_Get_FriendlyName(this.d); | ||
} | ||
set friendlyName(x) { | ||
return grok_Entity_Set_FriendlyName(this.d, x); | ||
} | ||
/** Entity short name | ||
* @type {string} */ | ||
get name() { | ||
@@ -35,2 +45,8 @@ return grok_Entity_Get_Name(this.d); | ||
/** Entity full-qualified name | ||
* @type {string} */ | ||
get nqName() { | ||
return grok_Entity_Get_nqName(this.d); | ||
} | ||
/** Entity path | ||
@@ -104,2 +120,14 @@ * @type {string} */ | ||
/** User home project | ||
* @type {Project} */ | ||
get project() { | ||
return toJs(grok_User_Get_Project(this.d)); | ||
} | ||
/** User home folder connection | ||
* @type {Project} */ | ||
get home() { | ||
return toJs(grok_User_Get_Storage(this.d)); | ||
} | ||
/** Login | ||
@@ -188,3 +216,3 @@ * @type {string} */ | ||
/** Entity name | ||
/** Project description | ||
* @type {string} */ | ||
@@ -195,3 +223,3 @@ get description() { | ||
/** Entity name | ||
/** Project changes flag | ||
* @type {string} */ | ||
@@ -202,3 +230,3 @@ get isDirty() { | ||
/** Entity name | ||
/** Project is empty flag | ||
* @type {string} */ | ||
@@ -650,9 +678,11 @@ get isEmpty() { | ||
*/ | ||
export class Package { | ||
constructor(webRoot) { | ||
this.webRoot = webRoot; | ||
this.name = ""; | ||
export class Package extends Entity { | ||
constructor(d) { | ||
super(d); | ||
if (d instanceof String) this.webRoot = d; | ||
this.version = ""; | ||
} | ||
/** Override init() method to provide package-specific initialization. | ||
@@ -667,2 +697,11 @@ * It is guaranteed to get called exactly once before the execution of any function below. | ||
/** load package | ||
* @returns {Promise<Package>} */ | ||
async load() { | ||
return new Promise((resolve, reject) => | ||
grok_Dapi_Packages_Load(this.name, (data) => resolve(data), (e) => reject(e))); | ||
} | ||
/** Returns credentials for package | ||
@@ -669,0 +708,0 @@ * @returns {Promise<Credentials>} */ |
@@ -475,11 +475,3 @@ import {Viewer} from "./viewer.js"; | ||
export class GridCellRenderer { | ||
get name() { | ||
throw 'Not implemented'; | ||
} | ||
get cellType() { | ||
throw 'Not implemented'; | ||
} | ||
export class CanvasRenderer { | ||
get defaultWidth() { | ||
@@ -499,12 +491,27 @@ return null; | ||
* @param {number} h | ||
* @param {GridCell} gridCell | ||
* @param {GridCellStyle} cellStyle | ||
* @param {Object} value | ||
* @param {Object} context | ||
**/ | ||
render(g, x, y, w, h, gridCell, cellStyle) { | ||
render(g, x, y, w, h, value, context) { | ||
throw 'Not implemented'; | ||
} | ||
} | ||
export class GridCellRenderer extends CanvasRenderer { | ||
get name() { | ||
throw 'Not implemented'; | ||
} | ||
get cellType() { | ||
throw 'Not implemented'; | ||
} | ||
renderInternal(g, x, y, w, h, gridCell, cellStyle) { | ||
this.render(g, x, y, w, h, new GridCell(gridCell), new GridCellStyle(cellStyle)); | ||
} | ||
static register(renderer) { | ||
grok_GridCellRenderer_Register(renderer); | ||
} | ||
} |
@@ -261,2 +261,12 @@ import {DataFrame} from "./dataframe"; | ||
} | ||
/** Saves audit record to Datagrok back-end | ||
* @param {string} message | ||
* @param {object} params | ||
* @param {string} type = 'log'*/ | ||
log(message, params, type) { | ||
if (type == null) | ||
type = 'log'; | ||
grok_Audit(type, message, toDart(params)); | ||
} | ||
} | ||
@@ -263,0 +273,0 @@ |
@@ -44,5 +44,7 @@ import {Property} from "./entities"; | ||
return new TypedEventArgs(d); | ||
let wrapper = grok_GetWrapper(d); | ||
if (wrapper != null) | ||
return wrapper; | ||
if (type === TYPE.PROPERTY) | ||
@@ -49,0 +51,0 @@ return new Property(d); |
@@ -152,5 +152,6 @@ /** | ||
* @param {Function} handler (item) => {...} | ||
* @param {Function} renderer (item) => {...} | ||
* @returns {HTMLElement} | ||
* */ | ||
export function comboPopup(icon: HTMLElement, items: string[], handler: (item: any) => void): HTMLElement | ||
export function comboPopup(icon: HTMLElement, items: string[], handler: (item: any) => void, renderer: (item: any) => HTMLElement | null): HTMLElement | ||
@@ -157,0 +158,0 @@ /** Creates a visual table based on [map]. */ |
92
ui.js
@@ -76,4 +76,11 @@ /** | ||
/** @returns {HTMLCanvasElement} */ | ||
export function canvas() { | ||
return element("CANVAS"); | ||
export function canvas(height = null, width = null) { | ||
let result = element("CANVAS"); | ||
if (height == null && width == null) { | ||
$(result).height(height); | ||
$(result).width(width); | ||
$(result).prop('height', `${height}px`); | ||
$(result).prop('width', `${width}px`); | ||
} | ||
return result; | ||
} | ||
@@ -151,6 +158,6 @@ | ||
return null; | ||
if (x instanceof DG.Widget) | ||
return x.root; | ||
if (typeof x.root !== 'undefined') | ||
return x.root; | ||
if (x instanceof Widget) | ||
return x.root; | ||
if (typeof x.wrap === 'function') { | ||
@@ -205,2 +212,9 @@ if (x.length === 1) | ||
/** Renders inline text, calling [renderMarkup] for each non-HTMLElement | ||
* @param {object[]} objects | ||
* @returns {HTMLElement}. */ | ||
export function inlineText(objects) { | ||
return span(objects.map((item) => render(item))); | ||
} | ||
/** | ||
@@ -212,2 +226,4 @@ * @param {object[]} children | ||
export function div(children = [], options = null) { | ||
if (!Array.isArray(children)) | ||
children = [children]; | ||
let d = document.createElement('div'); | ||
@@ -271,6 +287,7 @@ if (children != null) { | ||
* @param {Function} handler (item) => {...} | ||
* @param {Function} renderer (item) => {...} | ||
* @returns {HTMLElement} | ||
* */ | ||
export function comboPopup(caption, items, handler) { | ||
return grok_UI_ComboPopup(caption, items, handler); | ||
export function comboPopup(caption, items, handler, renderer=null) { | ||
return grok_UI_ComboPopup(caption, items, handler, renderer !== null ? (item) => renderer(toJs(item)) : null); | ||
} | ||
@@ -578,6 +595,16 @@ | ||
/** @returns {CanvasRenderer} */ | ||
getCanvasRenderer() { | ||
return null; | ||
} | ||
/** @returns {GridCellRenderer} */ | ||
getGridCellRenderer() { | ||
return null; | ||
} | ||
/** Renders icon for the item. | ||
* @param x - item | ||
* @returns {Element} */ | ||
renderIcon(x) { | ||
renderIcon(x, context = null) { | ||
return ui.divText(this.getCaption(x)); | ||
@@ -589,3 +616,3 @@ } | ||
* @returns {Element} */ | ||
renderMarkup(x) { | ||
renderMarkup(x, context = null) { | ||
return ui.divText(this.getCaption(x)); | ||
@@ -597,3 +624,3 @@ } | ||
* @returns {Element} */ | ||
renderTooltip(x) { | ||
renderTooltip(x, context = null) { | ||
return ui.divText(this.getCaption(x)); | ||
@@ -605,3 +632,3 @@ } | ||
* @returns {Element} */ | ||
renderCard(x) { | ||
renderCard(x, context = null) { | ||
return ui.divText(this.getCaption(x)); | ||
@@ -613,3 +640,3 @@ } | ||
* @returns {Element} */ | ||
renderProperties(x) { | ||
renderProperties(x, context = null) { | ||
return ui.divText(this.getCaption(x)); | ||
@@ -621,3 +648,3 @@ } | ||
* @returns {Element} */ | ||
renderView(x) { | ||
renderView(x, context = null) { | ||
return this.renderProperties(x); | ||
@@ -627,10 +654,27 @@ } | ||
/** Gets called once upon the registration of meta export class. */ | ||
init() { | ||
} | ||
init() { } | ||
/** Registers entity handler. | ||
* @param {JsEntityMeta} meta */ | ||
static register(meta) { | ||
grok_Meta_Register(meta); | ||
let cellRenderer = meta.getGridCellRenderer(); | ||
if (cellRenderer != null) | ||
DG.GridCellRenderer.register(cellRenderer); | ||
} | ||
/** @returns {JsEntityMeta[]} */ | ||
static list() { | ||
return toJs(grok_Meta_List()); | ||
} | ||
/** | ||
* @param {Object} x | ||
* @returns {JsEntityMeta} | ||
* */ | ||
static forEntity(x) { | ||
return toJs(grok_Meta_ForEntity(toDart(x))); | ||
} | ||
/** | ||
* Registers a function that takes applicable objects an the only argument. | ||
@@ -650,2 +694,20 @@ * It will be suggested to run in the context menu for that object, and | ||
export class EntityMetaDartProxy extends JsEntityMeta { | ||
constructor(d) { | ||
super(); | ||
this.d = d; | ||
} | ||
get type() { return grok_Meta_Get_Type(this.d); } | ||
isApplicable(x) { return grok_Meta_IsApplicable(this.d, toDart(x)); } | ||
getCaption(x) { return grok_Meta_Get_Name(this.d); }; | ||
renderIcon(x, context = null) { return grok_Meta_RenderIcon(x); } | ||
renderMarkup(x, context = null) { return grok_Meta_RenderMarkup(x); } | ||
renderTooltip(x, context = null) { return grok_Meta_RenderTooltip(x); } | ||
renderCard(x, context = null) { return grok_Meta_RenderCard(x); } | ||
renderProperties(x, context = null) { return grok_Meta_RenderProperties(x); } | ||
renderView(x, context = null) { return grok_Meta_RenderProperties(x); } | ||
} | ||
export function box(item, options = null) { | ||
@@ -692,3 +754,3 @@ if (item instanceof DG.Widget) { | ||
let c = div(items, options); | ||
$(c).append(items).addClass('ui-block'); | ||
$(c).addClass('ui-block'); | ||
return c; | ||
@@ -695,0 +757,0 @@ } |
377804
11006