Use query parameters rather than long path

This commit is contained in:
Cmdr McDonald
2016-11-21 10:06:14 +00:00
parent e4830811b0
commit 8857aba53f
7 changed files with 22 additions and 12 deletions

View File

@@ -84,13 +84,13 @@
"dependencies": {
"babel-polyfill": "*",
"classnames": "^2.2.0",
"browserify-zlib": "ipfs/coriolis-data",
"browserify-zlib": "ipfs/browserify-zlib",
"coriolis-data": "EDCD/coriolis-data",
"d3": "3.5.16",
"fbemitter": "^2.0.0",
"lodash": "^4.15.0",
"lz-string": "^1.4.4",
"react-number-editor": "^4.0.2",
"react-number-editor": "Athanasius/react-number-editor.git#miggy",
"react": "^15.0.1",
"react-dom": "^15.0.1",
"superagent": "^1.4.0"

View File

@@ -68,7 +68,10 @@ export default class Coriolis extends React.Component {
};
Router('', (r) => this._setPage(ShipyardPage, r));
Router('/import?', (r) => this._importBuild(r));
Router('/import/:data', (r) => this._importBuild(r));
Router('/outfit/?', (r) => this._setPage(OutfittingPage, r));
Router('/outfit/:ship/?', (r) => this._setPage(OutfittingPage, r));
Router('/outfit/:ship/:code?', (r) => this._setPage(OutfittingPage, r));
Router('/compare/:name?', (r) => this._setPage(ComparisonPage, r));
Router('/comparison/:code', (r) => this._setPage(ComparisonPage, r));

View File

@@ -2,6 +2,7 @@ import React from 'react';
import TranslatedComponent from './TranslatedComponent';
import Link from './Link';
import cn from 'classnames';
import { outfitURL } from '../utils/UrlGenerators';
import { SizeMap } from '../shipyard/Constants';
@@ -71,7 +72,7 @@ export default class ComparisonTable extends TranslatedComponent {
* @return {React.Component} Table row
*/
_buildRow(build, facets, formats, units) {
let url = `/outfit/${build.id}/${build.toString()}?bn=${build.buildName}`;
let url = outfitURL(build.id, build.toString(), build.buildName)
let cells = [
<td key='s' className='tl'><Link href={url}>{build.name}</Link></td>,
<td key='bn' className='tl'><Link href={url}>{build.buildName}</Link></td>

View File

@@ -29,12 +29,14 @@ export default class Modification extends TranslatedComponent {
/**
* Update modification given a value.
* @param {Number} value The value to set
* @param {Number} value The value to set. This comes in as a string and must be stored in state as a string,
* because it needs to allow illegal 'numbers' ('-', '1.', etc) when the user is typing
* in a value by hand
*/
_updateValue(value) {
const name = this.props.name;
let scaledValue = Math.floor(Number(value) * 100);
let scaledValue = Math.round(Number(value) * 100);
// Limit to +1000% / -100%
if (scaledValue > 100000) {
scaledValue = 100000;

View File

@@ -294,7 +294,7 @@ export default class OutfittingPage extends Page {
<div id='overview'>
<h1>{ship.name}</h1>
<div id='build'>
<input value={newBuildName} onChange={this._buildNameChange} placeholder={translate('Enter Name')} maxLength={50} />
<input value={newBuildName || ''} onChange={this._buildNameChange} placeholder={translate('Enter Name')} maxLength={50} />
<button onClick={canSave && this._saveBuild} disabled={!canSave} onMouseOver={termtip.bind(null, 'save')} onMouseOut={hide}>
<FloppyDisk className='lg' />
</button>

View File

@@ -4,6 +4,7 @@ import Ship from './Ship';
import * as ModuleUtils from './ModuleUtils';
import * as Utils from '../utils/UtilityFunctions';
import LZString from 'lz-string';
import { outfitURL } from '../utils/UrlGenerators';
const STANDARD = ['powerPlant', 'thrusters', 'frameShiftDrive', 'lifeSupport', 'powerDistributor', 'sensors', 'fuelTank'];
@@ -84,7 +85,7 @@ export function toDetailedBuild(buildName, ship) {
ship: ship.name,
references: [{
name: 'Coriolis.io',
url: `https://coriolis.edcd.io/outfit/${ship.id}/${code}?bn=${encodeURIComponent(buildName)}`,
url: 'https://coriolis.edcd.io' + outfitURL(ship.id, code, buildName),
code,
shipId: ship.id
}],

View File

@@ -6,15 +6,18 @@
* @return {String} URL
*/
export function outfitURL(shipId, code, buildName) {
let parts = ['/outfit/', shipId];
let path = '/outfit/' + shipId;
let sepChar = '?';
if (code) {
parts.push('/', code);
path = path + sepChar + 'code=' + encodeURIComponent(code);
sepChar = '&';
}
if (buildName) {
parts.push('?bn=', encodeURIComponent(buildName));
}
return parts.join('');
path = path + sepChar + 'bn=' + encodeURIComponent(buildName);
}
return path;
}