diff --git a/src/app/components/Header.jsx b/src/app/components/Header.jsx
index 7818231a..c05e6236 100644
--- a/src/app/components/Header.jsx
+++ b/src/app/components/Header.jsx
@@ -9,6 +9,8 @@ import { Cogs, CoriolisLogo, Hammer, Help, Rocket, StatsBars } from './SvgIcons'
import { Ships } from 'coriolis-data/dist';
import Persist from '../stores/Persist';
import { toDetailedExport } from '../shipyard/Serializer';
+import Ship from '../shipyard/Ship';
+import ModalBatchOrbis from './ModalBatchOrbis';
import ModalDeleteAll from './ModalDeleteAll';
import ModalExport from './ModalExport';
import ModalHelp from './ModalHelp';
@@ -235,6 +237,39 @@ export default class Header extends TranslatedComponent {
/>);
};
+ _uploadAllBuildsToOrbis(e) {
+ e.preventDefault();
+ const data = Persist.getBuilds();
+ let postObject = [];
+ for (const ship in data) {
+ for (const code in data[ship]) {
+ const shipModel = ship;
+ if (!shipModel) {
+ throw 'No such ship found: "' + ship + '"';
+ }
+ const shipTemplate = Ships[shipModel];
+ const shipPostObject = {};
+ let shipInstance = new Ship(shipModel, shipTemplate.properties, shipTemplate.slots);
+ shipInstance.buildWith(null);
+ shipInstance.buildFrom(data[ship][code]);
+ shipPostObject.coriolisId = shipInstance.id;
+ shipPostObject.coriolisShip = shipInstance;
+
+ shipPostObject.coriolisShip.url = window.location.origin + outfitURL(shipModel, data[ship][code], code);
+ shipPostObject.title = code || shipInstance.id;
+ shipPostObject.description = code || shipInstance.id;
+ shipPostObject.ShipName = shipInstance.id;
+ shipPostObject.Ship = shipInstance.id;
+ postObject.push(shipPostObject);
+ }
+ }
+ console.log(postObject);
+
+ this.context.showModal();
+ }
+
/**
* Show export modal with detailed export
* @param {SyntheticEvent} e Event
@@ -430,6 +465,7 @@ export default class Header extends TranslatedComponent {
{translate('builds')} & {translate('comparisons')}
{translate('backup')}
{translate('detailed export')}
+ {translate('upload all builds to orbis')}
{translate('import')}
{translate('delete all')}
diff --git a/src/app/components/ModalBatchOrbis.jsx b/src/app/components/ModalBatchOrbis.jsx
new file mode 100644
index 00000000..83a32955
--- /dev/null
+++ b/src/app/components/ModalBatchOrbis.jsx
@@ -0,0 +1,92 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import request from 'superagent';
+import TranslatedComponent from './TranslatedComponent';
+import { orbisUpload } from '../utils/ShortenUrl';
+import Persist from '../stores/Persist';
+
+/**
+ * Permalink modal
+ */
+export default class ModalBatchOrbis extends TranslatedComponent {
+
+ static propTypes = {
+ ships: PropTypes.any.isRequired
+ };
+
+ /**
+ * Constructor
+ * @param {Object} props React Component properties
+ */
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ orbisCreds: Persist.getOrbisCreds(),
+ resp: ''
+ };
+ }
+
+ /**
+ * Send ship to Orbis.zone
+ * @param {SyntheticEvent} e React Event
+ */
+ sendToOrbis(e) {
+ let agent;
+ try {
+ agent = request.agent(); // apparently this crashes somehow
+ } catch (e) {
+ console.error(e);
+ }
+ if (!agent) {
+ agent = request;
+ }
+ const API_ORBIS = 'http://localhost:3030/api/builds/add/batch';
+ return new Promise((resolve, reject) => {
+ try {
+ agent
+ .post(API_ORBIS)
+ .withCredentials()
+ .redirects(0)
+ .set('Content-Type', 'application/json')
+ .send(this.props.ships)
+ .end((err, response) => {
+ console.log(response);
+ if (err) {
+ console.error(err);
+ this.setState({ resp: response.text });
+ reject('Bad Request');
+ } else {
+ this.setState({ resp: 'All builds uploaded. Check https://orbis.zone' });
+ resolve('All builds uploaded. Check https://orbis.zone');
+ }
+ });
+ } catch (e) {
+ console.log(e);
+ reject(e.message ? e.message : e);
+ }
+ });
+ }
+
+ /**
+ * Render the modal
+ * @return {React.Component} Modal Content
+ */
+ render() {
+ let translate = this.context.language.translate;
+ this.sendToOrbis = this.sendToOrbis.bind(this);
+
+ return e.stopPropagation() }>
+
{translate('permalink')}
+
+
Log in / signup to Orbis
+
+
{translate('success')}
+
e.target.select() }/>
+
+
Orbis.zone is currently in a trial period, and may be wiped at any time as development progresses. Some elements are also still placeholders.
+
+
+
;
+ }
+}