Merge pull request #33 from chaoticbackup/development

Development
This commit is contained in:
DanudeSandstorm 2018-02-01 23:56:31 -05:00 committed by GitHub
commit 34913705c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 167 additions and 276 deletions

File diff suppressed because one or more lines are too long

View File

@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Chaotic Backup</title>
<meta name="description" content="Chaotic Backup">
<link rel="stylesheet" type="text/css" href="/src/css/legacy.css">
<style>
html, body, div, span, a, p, ul, li, h1, code, nav {
margin: 0;
@ -85,7 +86,6 @@
</head>
<body>
<div id="root"></div>
<!-- single page app in bundle.js -->
<script src="/build/bundle.js"></script>
</body>
</html>

View File

@ -1,6 +1,6 @@
{
"name": "chaoticbackup",
"version": "1.0.1",
"version": "1.1.0",
"description": "Chaotic Backup",
"scripts": {
"start": "webpack-dev-server -d --inline --host 0.0.0.0 --history-api-fallback --progress",
@ -32,6 +32,7 @@
"babel-eslint": "^8.0.0",
"babel-loader": "^6.2.10",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-polyfill": "^6.26.0",
"babel-preset-es2015": "^6.18.0",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-1": "^6.16.0",

View File

@ -1,6 +1,6 @@
import 'whatwg-fetch';
import loki from 'lokijs';
import {observable, autorun} from "mobx";
import {observable, observe} from "mobx";
class API {
@observable portal = null;
@ -60,8 +60,8 @@ class API {
setupDB() {
try {
this.portal = new CollectionDB(this);
this.cards = new CollectionDB(this);
this.portal = new CollectionDB(this, 'portal');
this.cards = new CollectionDB(this, 'cards');
}
catch (err) {
console.log('setting up database failed', err);
@ -91,60 +91,36 @@ class API {
};
}
// Input format
// [{cards: 'attacks'}, {portal: 'attacks'}]
async buildCollection(input) {
return await Promise.all(input.map((item) => {
return new Promise((resolve, reject) => {
if ('cards' in item)
return this.cards.setupType(item.cards, resolve);
if ('portal' in item)
return this.portal.setupType(item.portal, resolve);
console.log('cards or portal');
return reject();
});
}));
}
}
export default API.getInstance();
// export default new API();
class CollectionDB {
@observable built = []; // Keeps track of what collections have been populated
// Keeps track of what collections have been populated
@observable building = {};
constructor(API) {
constructor(API, format) {
this.api = API;
// ignoring persistence for now
// this.setupDB();
//autorun(() => console.log(this.creatures));
let db = new loki("chaotic_portal.db");
this.attacks = db.addCollection('attacks');
this.battlegear = db.addCollection('battlegear');
this.creatures = db.addCollection('creatures');
this.locations = db.addCollection('locations');
this.mugic = db.addCollection('mugic');
this.db = db;
this.format = format;
this.setupDB();
}
// setupDB() {
// var self = this;
// let db = new loki("chaotic_portal.db", { autosave: true, autoload: true, autoloadCallback: databaseInitialize, autosaveInterval: 4000, persistenceMethod: 'localStorage' });
// this.db = db;
// let databaseInitialize = () => {
// var entries;
// if ((entries = db.getCollection("attacks")) === null)
// entries = db.addCollection("attacks");
// self.attacks = entries;
// if ((entries = db.getCollection("battlegear")) === null)
// entries = db.addCollection("battlegear");
// self.battlegear = entries;
// console.log(db.getCollection("creatures"));
// if ((entries = db.getCollection("creatures")) === null)
// entries = db.addCollection("creatures");
// self.creatures = db.addCollection('creatures');
// if ((entries = db.getCollection("locations")) === null)
// entries = db.addCollection("locations");
// self.locations = entries
// if ((entries = db.getCollection("mugic")) === null)
// entries = db.addCollection("mugic");
// self.mugic = entries;
// };
// }
setup(spreadsheet, type, callback) {
getSpreadsheetData(spreadsheet, type, callback) {
this.api.getSpreadsheet(spreadsheet, (data) => {
callback(data.map((item) => {
let temp = {};
@ -158,39 +134,67 @@ class CollectionDB {
});
}
setupAttacks(type="portal") {
this.setup(this.api.urls.Attacks[type], "Attack", (data) => {
this.attacks.insert(data);
this.built.push("attacks_"+type);
});
// example format
// this.setup(this.api.urls.Attacks["portal"], "Attack", (data) => {});
async setupType(type, resolve) {
if (this.building[type]) {
if (this.building[type] == "built") {
return resolve();
}
if (this.building[type] == "building") {
const disposer = observe(building[type], (change) => {
disposer();
resolve();
});
return disposer;
}
}
else {
this.building[type] = "building";
let uc_type = type.charAt(0).toUpperCase() + type.slice(1);
return this.getSpreadsheetData(this.api.urls[uc_type][this.format], uc_type, (data) => {
this[type].insert(data);
this.building[type] = "built";
resolve();
});
}
}
setupBattlegear(type="portal") {
this.setup(this.api.urls.Battlegear[type], "Battlegear", (data) => {
this.battlegear.insert(data);
this.built.push("battlegear_"+type);
});
}
setupDB() {
// ignoring persistence for now
let db = new loki("chaotic_portal.db");
this.attacks = db.addCollection('attacks');
this.battlegear = db.addCollection('battlegear');
this.creatures = db.addCollection('creatures');
this.locations = db.addCollection('locations');
this.mugic = db.addCollection('mugic');
this.db = db;
setupCreatures(type="portal") {
this.setup(this.api.urls.Creatures[type], "Creature", (data) => {
this.creatures.insert(data);
this.built.push("creatures_"+type);
});
}
// let db = new loki("chaotic_portal.db", { autosave: true, autoload: true, autoloadCallback: databaseInitialize, autosaveInterval: 4000, persistenceMethod: 'localStorage' });
// this.db = db;
setupLocations(type="portal") {
this.setup(this.api.urls.Locations[type], "Location", (data) => {
this.locations.insert(data);
this.built.push("locations_"+type);
});
}
// let databaseInitialize = () => {
// var entries;
// if ((entries = db.getCollection("attacks")) === null)
// entries = db.addCollection("attacks");
// this.attacks = entries;
setupMugic(type="portal") {
this.setup(this.api.urls.Mugic[type], "Mugic", (data) => {
this.mugic.insert(data);
this.built.push("mugic_"+type);
});
}
// if ((entries = db.getCollection("battlegear")) === null)
// entries = db.addCollection("battlegear");
// this.battlegear = entries;
// console.log(db.getCollection("creatures"));
// if ((entries = db.getCollection("creatures")) === null)
// entries = db.addCollection("creatures");
// this.creatures = db.addCollection('creatures');
// if ((entries = db.getCollection("locations")) === null)
// entries = db.addCollection("locations");
// this.locations = entries
// if ((entries = db.getCollection("mugic")) === null)
// entries = db.addCollection("mugic");
// this.mugic = entries;
// };
}
}

View File

@ -20,13 +20,13 @@ export default class CardList extends React.Component {
}
return cards.map((card, i) => {
switch (card.gsx$type) {
case "Attack":
case "Attacks":
return (<Attack attack={card} key={i} setImage={this.props.setImage.bind(this)}/>);
case "Battlegear":
return (<Battlegear battlegear={card} key={i} setImage={this.props.setImage.bind(this)}/>);
case "Creature":
case "Creatures":
return (<Creature creature={card} key={i} setImage={this.props.setImage.bind(this)}/>);
case "Location":
case "Locations":
return (<Location location={card} key={i} setImage={this.props.setImage.bind(this)}/>);
case "Mugic":
return (<Mugic mugic={card} key={i} setImage={this.props.setImage.bind(this)}/>);

View File

@ -8,6 +8,7 @@ import SearchForm from './Search';
@inject((stores, props, context) => props) @observer
export default class Home extends React.Component {
@observable loaded = false;
@observable n = 10;
@observable p = 1;
@observable content = [];
@ -23,42 +24,18 @@ export default class Home extends React.Component {
}
render() {
if (this.props.children) {
return (<div>{this.props.children}</div>);
}
let loading = false;
const store = API;
if (store.urls === null ||
store.portal === null ||
store.cards === null) {
if (API.urls === null ||
API.portal === null ||
API.cards === null) {
return (<span>Loading...</span>);
}
// Load all the data
if (!store.cards.built.includes("attacks_cards")) {
store.cards.setupAttacks("cards");
return (<span>Loading...</span>);
}
if (!store.cards.built.includes("battlegear_cards")) {
store.cards.setupBattlegear("cards");
return (<span>Loading...</span>);
}
if (!store.cards.built.includes("creatures_cards")) {
store.cards.setupCreatures("cards");
return (<span>Loading...</span>);
}
if (!store.cards.built.includes("locations_cards")) {
store.cards.setupLocations("cards");
return (<span>Loading...</span>);
}
if (!store.cards.built.includes("mugic_cards")) {
store.cards.setupMugic("cards");
if (this.loaded == false) {
API.buildCollection([{'cards': 'attacks'}, , {'cards': 'battlegear'}, {'cards': 'creatures'}, {'cards': 'locations'}, {'cards': 'mugic'}])
.then(() => {
this.loaded = true;
});
return (<span>Loading...</span>);
}

View File

@ -1,6 +1,6 @@
import React from 'react';
import { render } from 'react-dom';
import { BrowserRouter as Router, Link, Route } from 'react-router-dom';
import { BrowserRouter as Router, Link, Route, withRouter } from 'react-router-dom';
import {observer, inject} from 'mobx-react';
import s from '../styles/app.style';
@ -11,11 +11,12 @@ import Collection from './collection/index';
import Portal from './portal/index';
import Home from './Home';
// const BlockAvoider = withRouter(Base)
render(
<Router>
<div>
<Route path="*" component={Base}/>
</div>
{/* <BlockAvoider /> */}
<Base path="/*" href="/" />
</Router>
, document.getElementById('root'),
);
@ -33,16 +34,16 @@ function Routing(props) {
);
}
const language = "ENG";
const bkgrnd = "05";
function Base(props) {
// Configuration for the language and background
// Images managed in css file
const language = "ENG";
const bkgrnd = "05";
const children = <Routing {...props} />;
return (
<div>
<link rel="stylesheet" type="text/css" href="/src/css/legacy.css" />
<div className="fix-pgBkgrnd-repeat-x">
<div className={"fix-img-bkgrnd fix-img-bkgrnd_"+bkgrnd}></div>
</div>

View File

@ -1,6 +1,7 @@
import React from 'react';
import Interactive from 'react-interactive';
import { Link, Route } from 'react-router-dom';
import {observable} from 'mobx';
import {observer, inject} from 'mobx-react';
import s from '../../../styles/app.style';
import API from '../../SpreadsheetData';
@ -8,6 +9,7 @@ import Attack from '../Single/Attack';
@inject((stores, props, context) => props) @observer
export default class Attacks extends React.Component {
@observable loaded = false;
render() {
@ -20,19 +22,15 @@ export default class Attacks extends React.Component {
return (<span>Loading...</span>);
}
if (!API.cards.built.includes("attacks_cards")) {
API.cards.setupAttacks("cards");
if (this.loaded == false) {
API.buildCollection([{'cards': 'attacks'}, {'portal': 'attacks'}])
.then(() => {
this.loaded = true;
});
return (<span>Loading...</span>);
}
if (!API.portal.built.includes("attacks_portal")) {
API.portal.setupAttacks("portal");
return (<span>Loading...</span>);
}
const attacks = API.portal.attacks.data;
const output = attacks.map((attack, i) => {
const output = API.portal.attacks.data.map((attack, i) => {
const card_data = API.cards.attacks.findOne({'gsx$name': attack.gsx$name});
return (
<div key={i}>

View File

@ -1,6 +1,7 @@
import React from 'react';
import Interactive from 'react-interactive';
import { Link, Route } from 'react-router-dom';
import {observable} from 'mobx';
import {observer, inject} from 'mobx-react';
import s from '../../../styles/app.style';
import API from '../../SpreadsheetData';
@ -8,10 +9,9 @@ import SingleBattlegear from '../Single/Battlegear';
@inject((stores, props, context) => props) @observer
export default class Battlegear extends React.Component {
@observable loaded = false;
render() {
let path = this.props.location.pathname.split("/");
if (path[path.length-1] == "") path.pop(); // Remove trailing backslash
@ -21,13 +21,11 @@ export default class Battlegear extends React.Component {
return (<span>Loading...</span>);
}
if (!API.cards.built.includes("battlegear_cards")) {
API.cards.setupBattlegear("cards");
return (<span>Loading...</span>);
}
if (!API.portal.built.includes("battlegear_portal")) {
API.portal.setupBattlegear("portal");
if (this.loaded == false) {
API.buildCollection([{'cards': 'battlegear'}, {'portal': 'battlegear'}])
.then(() => {
this.loaded = true;
});
return (<span>Loading...</span>);
}

View File

@ -1,6 +1,7 @@
import React from 'react';
import Interactive from 'react-interactive';
import { Link, Route } from 'react-router-dom';
import {observable} from 'mobx';
import {observer, inject} from 'mobx-react';
import s from '../../../styles/app.style';
import API from '../../SpreadsheetData';
@ -8,13 +9,13 @@ import Creature from '../Single/Creature';
@inject((stores, props, context) => props) @observer
export default class Creatures extends React.Component {
@observable loaded = false;
// ** Process the tribe ** //
// /portal/Creatures/
// /portal/Creatures/{Tribe}
// The first / gets counted
render() {
let path = this.props.location.pathname.split("/");
if (path[path.length-1] == "") path.pop(); // Remove trailing backslash
@ -24,13 +25,11 @@ export default class Creatures extends React.Component {
return (<span>Loading...</span>);
}
if (!API.cards.built.includes("creatures_cards")) {
API.cards.setupCreatures("cards");
return (<span>Loading...</span>);
}
if (!API.portal.built.includes("creatures_portal")) {
API.portal.setupCreatures("portal");
if (this.loaded == false) {
API.buildCollection([{'cards': 'creatures'}, {'portal': 'creatures'}])
.then(() => {
this.loaded = true;
});
return (<span>Loading...</span>);
}

View File

@ -1,6 +1,7 @@
import React from 'react';
import Interactive from 'react-interactive';
import { Link, Route } from 'react-router-dom';
import {observable} from 'mobx';
import {observer, inject} from 'mobx-react';
import s from '../../../styles/app.style';
import API from '../../SpreadsheetData';
@ -8,6 +9,7 @@ import Location from '../Single/Location';
@inject((stores, props, context) => props) @observer
export default class Locations extends React.Component {
@observable loaded = false;
render() {
@ -20,13 +22,11 @@ export default class Locations extends React.Component {
return (<span>Loading...</span>);
}
if (!API.cards.built.includes("locations_cards")) {
API.cards.setupLocations("cards");
return (<span>Loading...</span>);
}
if (!API.portal.built.includes("locations_portal")) {
API.portal.setupLocations("portal");
if (this.loaded == false) {
API.buildCollection([{'cards': 'locations'}, {'portal': 'locations'}])
.then(() => {
this.loaded = true;
});
return (<span>Loading...</span>);
}

View File

@ -1,6 +1,7 @@
import React from 'react';
import Interactive from 'react-interactive';
import { Link, Route } from 'react-router-dom';
import {observable} from 'mobx';
import {observer, inject} from 'mobx-react';
import s from '../../../styles/app.style';
import API from '../../SpreadsheetData';
@ -8,6 +9,7 @@ import SingleMugic from '../Single/Mugic';
@inject((stores, props, context) => props) @observer
export default class Mugic extends React.Component {
@observable loaded = false;
// ** Process the tribe ** //
// /portal/Mugic/
@ -25,13 +27,11 @@ export default class Mugic extends React.Component {
return (<span>Loading...</span>);
}
if (!API.cards.built.includes("mugic_cards")) {
API.cards.setupMugic("cards");
return (<span>Loading...</span>);
}
if (!API.portal.built.includes("mugic_portal")) {
API.portal.setupMugic("portal");
if (this.loaded == false) {
API.buildCollection([{'cards': 'mugic'}, {'portal': 'mugic'}])
.then(() => {
this.loaded = true;
});
return (<span>Loading...</span>);
}

View File

@ -1,6 +1,7 @@
import React from 'react';
import Interactive from 'react-interactive';
import { Link, Route } from 'react-router-dom';
import {observable} from 'mobx';
import {observer, inject} from 'mobx-react';
import loki from 'lokijs';
import s from '../../../styles/app.style';
@ -10,6 +11,7 @@ import Mugic from '../Single/Mugic';
@inject((stores, props, context) => props) @observer
export default class Tribes extends React.Component {
@observable loaded = false;
constructor() {
super();
@ -55,23 +57,11 @@ export default class Tribes extends React.Component {
);
}
if (!API.cards.built.includes("mugic_cards")) {
API.cards.setupMugic("cards");
return (<span>Loading...</span>);
}
if (!API.portal.built.includes("mugic_portal")) {
API.portal.setupMugic("portal");
return (<span>Loading...</span>);
}
if (!API.cards.built.includes("creatures_cards")) {
API.cards.setupCreatures("cards");
return (<span>Loading...</span>);
}
if (!API.portal.built.includes("creatures_portal")) {
API.portal.setupCreatures("portal");
if (this.loaded == false) {
API.buildCollection([{'cards': 'creatures'}, {'portal': 'creatures'}, {'cards': 'mugic'}, {'portal': 'mugic'}])
.then(() => {
this.loaded = true;
});
return (<span>Loading...</span>);
}
@ -100,7 +90,7 @@ export default class Tribes extends React.Component {
url = "/portal/" + tribe + "/Mugic/" + encodeURIComponent(card.gsx$name);
}
if (card.gsx$type == "Creature") {
if (card.gsx$type == "Creatures") {
card_data = API.cards.creatures.findOne({'gsx$name': card.gsx$name});
url = "/portal/" + tribe + "/Creatures/" + encodeURIComponent(card.gsx$name);
}

View File

@ -21,22 +21,6 @@ export default class SingleAttack extends React.Component {
let name = decodeURIComponent(path[3]);
if (API.urls === null ||
API.portal === null ||
API.cards === null) {
return (<span>Loading...</span>);
}
if (!API.cards.built.includes("attacks_cards")) {
API.cards.setupAttacks("cards");
return (<span>Loading...</span>);
}
if (!API.portal.built.includes("attacks_portal")) {
API.portal.setupAttacks("portal");
return (<span>Loading...</span>);
}
const attack = API.portal.attacks.findOne({'gsx$name': name});
if (!attack) {
return(<PageNotFound location={this.props.location}/>);

View File

@ -22,22 +22,6 @@ export default class SingleBattlegear extends React.Component {
let name = decodeURIComponent(path[3]);
if (API.urls === null ||
API.portal === null ||
API.cards === null) {
return (<span>Loading...</span>);
}
if (!API.cards.built.includes("battlegear_cards")) {
API.cards.setupBattlegear("cards");
return (<span>Loading...</span>);
}
if (!API.portal.built.includes("battlegear_portal")) {
API.portal.setupBattlegear("portal");
return (<span>Loading...</span>);
}
const battlegear = API.portal.battlegear.findOne({'gsx$name': name});
if (!battlegear) {
return(<PageNotFound location={this.props.location}/>);

View File

@ -18,22 +18,6 @@ export default class SingleCreature extends React.Component {
let path = this.props.location.pathname.split("/");
if (path[path.length-1] == "") path.pop(); // Remove trailing backslash
if (API.urls === null ||
API.portal === null ||
API.cards === null) {
return (<span>Loading...</span>);
}
if (!API.cards.built.includes("creatures_cards")) {
API.cards.setupCreatures("cards");
return (<span>Loading...</span>);
}
if (!API.portal.built.includes("creatures_portal")) {
API.portal.setupCreatures("portal");
return (<span>Loading...</span>);
}
const name = (() => {
if (path.length >= 5) return decodeURIComponent(path[4]);
if (path.length == 4) return decodeURIComponent(path[3]);

View File

@ -22,22 +22,6 @@ export default class SingleLocation extends React.Component {
let name = decodeURIComponent(path[3]);
if (API.urls === null ||
API.portal === null ||
API.cards === null) {
return (<span>Loading...</span>);
}
if (!API.cards.built.includes("locations_cards")) {
API.cards.setupLocations("cards");
return (<span>Loading...</span>);
}
if (!API.portal.built.includes("locations_portal")) {
API.portal.setupLocations("portal");
return (<span>Loading...</span>);
}
const location = API.portal.locations.findOne({'gsx$name': name});
if (!location) {
return(<PageNotFound location={this.props.location}/>);

View File

@ -18,22 +18,6 @@ export default class SingleMugic extends React.Component {
let path = this.props.location.pathname.split("/");
if (path[path.length-1] == "") path.pop(); // Remove trailing backslash
if (API.urls === null ||
API.portal === null ||
API.cards === null) {
return (<span>Loading...</span>);
}
if (!API.cards.built.includes("mugic_cards")) {
API.cards.setupMugic("cards");
return (<span>Loading...</span>);
}
if (!API.portal.built.includes("mugic_portal")) {
API.portal.setupMugic("portal");
return (<span>Loading...</span>);
}
const name = (() => {
if (path.length >= 5) return decodeURIComponent(path[4]);
if (path.length == 4) return decodeURIComponent(path[3]);

View File

@ -2,7 +2,7 @@ import webpack from 'webpack';
import path from 'path';
export default {
entry: `${__dirname}/src/components/index.js`,
entry: ['babel-polyfill', `${__dirname}/src/components/index.js`],
output: {
path: `${__dirname}/build`,
publicPath: '/build/',