window.MapCanvasShared = window.MapCanvasShared || {};
|
|
(function (shared) {
|
shared.buildReplayTarget = function (type, deviceNo, stationId, title, detail) {
|
return {
|
type: type || '',
|
deviceNo: deviceNo == null ? null : Number(deviceNo),
|
stationId: stationId == null ? null : Number(stationId),
|
title: title || '',
|
detail: detail || ''
|
};
|
};
|
|
shared.isTaskNoInRange = function (taskNo, range) {
|
if (!range) {
|
return false;
|
}
|
var start = parseInt(range.start, 10);
|
var end = parseInt(range.end, 10);
|
if (isNaN(start) || isNaN(end)) {
|
return false;
|
}
|
return taskNo >= start && taskNo <= end;
|
};
|
|
shared.getStationTaskClass = function (taskNo, stationTaskRange) {
|
if (!(taskNo > 0)) {
|
return null;
|
}
|
var range = stationTaskRange || {};
|
if (shared.isTaskNoInRange(taskNo, range.inbound)) {
|
return 'machine-pakin';
|
}
|
if (shared.isTaskNoInRange(taskNo, range.outbound)) {
|
return 'machine-pakout';
|
}
|
return null;
|
};
|
|
shared.registerMapRuntimeDefinition = function (definition) {
|
shared._mapRuntimeDefinition = definition || null;
|
return shared._mapRuntimeDefinition;
|
};
|
|
shared.getMapRuntimeDefinition = function () {
|
return shared._mapRuntimeDefinition || null;
|
};
|
|
shared.createMapRuntimeContext = function (options) {
|
var definition = shared.getMapRuntimeDefinition();
|
if (!definition) {
|
throw new Error('Map runtime definition is not registered.');
|
}
|
|
var runtimeOptions = options || {};
|
var host = runtimeOptions.host || {};
|
var data = typeof definition.data === 'function' ? definition.data.call(host) : {};
|
var props = runtimeOptions.props || {};
|
var refs = runtimeOptions.refs || {};
|
|
Object.keys(data || {}).forEach(function (key) {
|
if (typeof host[key] === 'undefined') {
|
host[key] = data[key];
|
}
|
});
|
|
Object.keys(props).forEach(function (key) {
|
host[key] = props[key];
|
});
|
|
host.$refs = host.$refs || {};
|
Object.keys(refs).forEach(function (key) {
|
host.$refs[key] = refs[key];
|
});
|
|
if (runtimeOptions.el) {
|
host.$el = runtimeOptions.el;
|
}
|
if (typeof runtimeOptions.emit === 'function') {
|
host.$emit = runtimeOptions.emit;
|
}
|
if (typeof host.$emit !== 'function') {
|
host.$emit = function () {};
|
}
|
|
host.__mapRuntimeDefinition = definition;
|
host.__mapRuntimeOptions = runtimeOptions;
|
host.ownsPixiApp = runtimeOptions.ownsPixiApp !== false;
|
host.pixiStageHost = runtimeOptions.stageHost || null;
|
host.pixiStageTransformTarget = runtimeOptions.transformTarget || null;
|
|
Object.keys(definition.methods || {}).forEach(function (name) {
|
host[name] = definition.methods[name].bind(host);
|
});
|
|
return host;
|
};
|
|
shared.mountMapRuntime = function (runtime, options) {
|
if (!runtime) {
|
throw new Error('Map runtime is required.');
|
}
|
var runtimeOptions = options || {};
|
var definition = runtime.__mapRuntimeDefinition || shared.getMapRuntimeDefinition();
|
if (!definition) {
|
throw new Error('Map runtime definition is not registered.');
|
}
|
|
if (runtimeOptions.app) {
|
runtime.pixiApp = runtimeOptions.app;
|
}
|
if (runtimeOptions.el) {
|
runtime.$el = runtimeOptions.el;
|
}
|
runtime.$refs = runtime.$refs || {};
|
Object.keys(runtimeOptions.refs || {}).forEach(function (key) {
|
runtime.$refs[key] = runtimeOptions.refs[key];
|
});
|
if (typeof runtimeOptions.emit === 'function') {
|
runtime.$emit = runtimeOptions.emit;
|
}
|
if (runtimeOptions.props) {
|
Object.keys(runtimeOptions.props).forEach(function (key) {
|
runtime[key] = runtimeOptions.props[key];
|
});
|
}
|
runtime.ownsPixiApp = runtimeOptions.ownsPixiApp !== false;
|
runtime.pixiStageHost = runtimeOptions.stageHost || runtime.pixiStageHost || null;
|
runtime.pixiStageTransformTarget = runtimeOptions.transformTarget || runtime.pixiStageTransformTarget || null;
|
|
if (typeof definition.mounted === 'function') {
|
definition.mounted.call(runtime);
|
}
|
return runtime;
|
};
|
|
shared.destroyMapRuntime = function (runtime) {
|
if (!runtime) {
|
return;
|
}
|
var definition = runtime.__mapRuntimeDefinition || shared.getMapRuntimeDefinition();
|
if (definition && typeof definition.beforeDestroy === 'function') {
|
definition.beforeDestroy.call(runtime);
|
}
|
};
|
})(window.MapCanvasShared);
|