/*!
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
import React from 'react';
import Common from '../../../../common/Common';
import iconPlus from '../../../../../../../../res/ecomp/asdc/sequencer/sprites/icons/plus.svg';
import iconOpen from '../../../../../../../../res/ecomp/asdc/sequencer/sprites/icons/open.svg';
/**
* Toolbar view. Buttons offered in the toolbar depend on the mode. Unless in demo mode,
* all you get are the buttons for toggling between JSON/YAML/Designer.
*/
export default class Toolbar extends React.Component {
// ///////////////////////////////////////////////////////////////////////////////////////////////
/**
* Construct view.
*/
constructor(props, context) {
super(props, context);
this.application = Common.assertType(this.props.application, 'Object');
this.editor = Common.assertType(this.props.editor, 'Object');
this.mode = 'design';
}
// ///////////////////////////////////////////////////////////////////////////////////////////////
/**
* Set editor mode, one of {design, json, yaml}.
* @param mode
*/
setMode(mode = 'design') {
this.mode = mode;
}
// ///////////////////////////////////////////////////////////////////////////////////////////////
/**
* Render into the DOM.
*/
render() {
const demo = this.application.getOptions().demo;
const demoCss = demo ? '' : 'asdc-hide';
return (
);
}
// ///////////////////////////////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////////////////////////////
/**
* Initialize eventhandlers.
* @private
*
_initEvents() {
$('button.asdcs-button-open', this.$el).click(() => {
this._doDemoOpen();
});
$('button.asdcs-button-new', this.$el).click(() => {
this._doDemoNew();
});
$('button.asdcs-button-save', this.$el).click(() => {
this._doDemoSave();
});
$('button.asdcs-button-upload', this.$el).click(() => {
this._doDemoUpload();
});
$('button.asdcs-button-download', this.$el).click(() => {
this._doDemoDownload();
});
$('button.asdcs-button-validate', this.$el).click(() => {
this._doDemoValidate();
});
$('button.asdcs-button-json', this.$el).click((e) => {
if ($(e.target).hasClass('asdcs-active')) {
return;
}
this.editor.toggleToJSON();
});
$('button.asdcs-button-yaml', this.$el).click((e) => {
if ($(e.target).hasClass('asdcs-active')) {
return;
}
this.editor.toggleToYAML();
});
$('button.asdcs-button-design', this.$el).click((e) => {
if ($(e.target).hasClass('asdcs-active')) {
return;
}
this.editor.toggleToDesign();
});
}
*/
// ///////////////////////////////////////////////////////////////////////////////////////////////
/**
* Demo action.
*
_doDemoOpen() {
const complete = function complete() {
const sequencer = this.application.getSequencer();
const scenarios = sequencer.getDemoScenarios();
sequencer.setModel(scenarios.getECOMP());
};
this.application.showConfirmDialog('[DEMO MODE] Open a canned DEMO sequence ' +
'via the public #setModel() API?', complete);
}
*/
// ///////////////////////////////////////////////////////////////////////////////////////////////
/**
* Demo action.
*
_doDemoNew() {
const complete = function complete() {
const sequencer = this.application.getSequencer();
sequencer.newModel();
};
this.application.showConfirmDialog('[DEMO MODE] Create an empty sequence via the ' +
'public #newModel() API?', complete);
}
*/
// ///////////////////////////////////////////////////////////////////////////////////////////////
/**
* Demo action.
*
_doDemoSave() {
const sequencer = this.application.getSequencer();
Logger.info(`[DEMO MODE] model:\n${JSON.stringify(sequencer.getModel(), null, 4)}`);
this.application.showInfoDialog('[DEMO MODE] Retrieved model via the public #getModel ' +
'API and logged its JSON to the console.');
}
*/
// ///////////////////////////////////////////////////////////////////////////////////////////////
/**
* Demo action.
*
_doDemoUpload() {
const sequencer = this.application.getSequencer();
const svg = sequencer.getSVG();
// console.log(`[DEMO MODE] SVG:\n${svg}`);
const $control = this.$el.closest('.asdcs-control');
Logger.info(`parent: ${$control.length}`);
const $form = $('form.asdcs-export', $control);
Logger.info(`form: ${$form.length}`);
$('input[name=svg]', $form).val(svg);
try {
$form.submit();
} catch (e) {
Logger.error(e);
this.application.showErrorDialog('[DEMO MODE] Export service not available. Retrieved ' +
'SVG via the public #getSVG API and dumped it to the console.');
}
}
*/
// ///////////////////////////////////////////////////////////////////////////////////////////////
/**
* Demo action.
*
_doDemoDownload() {
const json = JSON.stringify(this.application.getSequencer().getModel());
const $control = this.$el.closest('.asdcs-control');
const $a = $('').appendTo($control);
$a.attr('href', `data:application/json;charset=utf-8,${encodeURIComponent(json)}`);
$a[0].click();
$a.remove();
}
*/
// ///////////////////////////////////////////////////////////////////////////////////////////////
/**
* Demo action.
*
_doDemoValidate() {
this.application.showInfoDialog('[DEMO MODE] Dumping validation result to the console.');
const errors = this.application.getModel().validate();
Logger.info(`[DEMO MODE] Validation: ${JSON.stringify(errors, null, 4)}`);
}
*/
}
Toolbar.propTypes = {
application: React.PropTypes.object.isRequired,
editor: React.PropTypes.object.isRequired,
};