Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare widget to be used on ck-website #8

Merged
merged 2 commits into from
Nov 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion module/dashboard/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def display(args):
"""

# Filter and pass some arguments from command line to browser
extra_url = { key:args[key] for key in args if key in ['scenario'] }
extra_url = { key:args[key] for key in args if key in ['scenario', 'global'] }
extra_url = "&".join("{0}={1}".format(key, extra_url[key]) for key in extra_url)

args['action'] = 'start'
Expand Down
23 changes: 12 additions & 11 deletions wfe/dashboard/ck-repo-widget/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -1569,14 +1569,20 @@ var CkRepoWdiget = function () {

_createClass(CkRepoWdiget, [{
key: 'init',
value: function init(rootId, headerId, loadingLayerId) {
value: function init(argsMap) {
var _this9 = this;

// If this widget is running on local machine, e.g. launched through `ck widget nntest`
this.isLocalRun = true;
this.isLocalRun = (typeof argsMap.isLocalRun === 'undefined' ? true : argsMap.isLocalRun);
// Scenario filters available workflows
this.scenario = argsMap.scenario || '';

let rootId = argsMap.rootId || '#ck-repo-widget';
let headerId = argsMap.headerId || '#ck-repo-widget-header';
let loadingLayerId = argsMap.loadingLayerId || '#ck-repo-widget-loading-layer';

// Url where to get data from
const kApiUrl = (this.isLocalRun ? 'http://localhost:3344/' : 'http://cknowledge.org/repo/json.php');
const kApiUrl = argsMap.apiUrlPrefix || (this.isLocalRun ? '/web' : 'http://cknowledge.org/repo/json.php');
var kActionGetData = 'get_raw_data';
var kActionGetConfig = 'get_raw_config';

Expand Down Expand Up @@ -1814,11 +1820,11 @@ var CkRepoWdiget = function () {
colorRange: ['#0000FF', '#00FFFF', '#00FF00', '#FFFF00', '#FF0000']
})];

// Scenario filters available workflows
if (this.scenario != null) {
// Scenario filters available workflows
if (this.scenario !== '') {
workflows = workflows.filter(w => w.moduleUoa == this.scenario);
}
var defaultWorkflow = workflows[0];
var defaultWorkflow = workflows[3] || workflows[0];

var showWorkflow = function showWorkflow(workflow) {
_this9.selectedWorkflow = workflow;
Expand Down Expand Up @@ -2338,11 +2344,6 @@ var CkRepoWdiget = function () {
dom.plotTooltipContainer.selectAll('*').remove();
dom.tableContainer.selectAll('*').remove();
}
}, {
key: 'setScenario',
value: function setScenario(scenario_name) {
this.scenario = scenario_name;
}
}, {
key: '_getInfoHtml',
value: function _getInfoHtml() {
Expand Down
20 changes: 11 additions & 9 deletions wfe/dashboard/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,18 @@
<script src="$#ck_url_template_pull#$js/plugins/plugins.js"></script>

<script type="text/javascript">
let url = new URL(window.location.href);
let scenario = url.searchParams.get("scenario");
function initWidget() {
let url = new URL(window.location.href);
let apiUrlPrefix = (url.searchParams.get('global') === 'yes' ? 'http://cKnowledge.org/repo/json.php' : '/web' );

const widget = new CkRepoWdiget();
widget.setScenario(scenario);
widget.init(
'#ck-repo-widget',
'#ck-repo-widget-header',
'#ck-repo-widget-loading-layer'
);
const widget = new CkRepoWdiget();
widget.init({
apiUrlPrefix: apiUrlPrefix,
isLocalRun: true,
scenario: url.searchParams.get("scenario"),
});
}
initWidget();
</script>
</body>
</html>