Skip to content
This repository has been archived by the owner on Nov 29, 2017. It is now read-only.

Commit

Permalink
Merge pull request #24 from web-pal/v0.1.0-beta.3
Browse files Browse the repository at this point in the history
V0.1.0 beta.3
  • Loading branch information
VladimirPal authored Oct 20, 2016
2 parents 9b4cb19 + 84a6057 commit d7a04ae
Show file tree
Hide file tree
Showing 33 changed files with 19,330 additions and 107 deletions.
76 changes: 44 additions & 32 deletions app/actions/currentTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import * as types from '../constants/currentTableConstants';
// INITIALIZE //
export function connectDB(params, callback) {
return (dispatch) => {
DB.connect(params, (connect, err) => {
DB.connect(params, (connect, err, sshError) => {
dispatch({ type: types.CONNECT, connect, err });
callback.apply(null, [connect, err]);
callback.apply(null, [connect, err, sshError]);
});
};
}

export function dropConnection() {
return {
type: types.DROP_CONNECTION
return (dispatch) => {
dispatch({ type: types.DROP_CONNECTION });
dispatch({ type: types.RESET_STATE });
};
}

Expand All @@ -39,34 +40,37 @@ export function addColumn() {
// READ //
export function initStructure() {
return (dispatch, getState) => {
dispatch({
type: types.STRUCTURE_INIT_STATE,
finish: true
});
dispatch(startFetching());
const { tableName, structureTable } = getState().currentTable;
DB.getTableConstraints(tableName)
.then(
(constraints) => {
dispatch({
type: types.GET_TABLE_CONSTRAINTS,
constraints
});
return DB.getTableOid([{ table_name: tableName }]);
}
)
.then(
tables => DB.getNotNullConstraints(structureTable, tables[0].oid)
)
.then(
(constraints) => {
dispatch({
type: types.GET_TABLE_CONSTRAINTS,
constraints,
});
dispatch(stopFetching());
}
);
// TODO: define empty database more obviously
if (tableName) {
dispatch({
type: types.STRUCTURE_INIT_STATE,
finish: true
});
dispatch(startFetching());
DB.getTableConstraints(tableName)
.then(
(constraints) => {
dispatch({
type: types.GET_TABLE_CONSTRAINTS,
constraints
});
return DB.getTableOid([{ table_name: tableName }]);
}
)
.then(
tables => DB.getNotNullConstraints(structureTable, tables[0].oid)
)
.then(
(constraints) => {
dispatch({
type: types.GET_TABLE_CONSTRAINTS,
constraints,
});
dispatch(stopFetching());
}
);
}
};
}

Expand All @@ -90,12 +94,19 @@ function startFetching(tableName) {
};
}

function stopFetching() {
export function stopFetching() {
return {
type: types.STOP_FETCHING
};
}


export function clearTableName() {
return {
type: types.CLEAR_TABLE_NAME
};
}

function returnContent(params = {}) {
return {
type: types.GET_TABLE_CONTENT,
Expand Down Expand Up @@ -403,6 +414,7 @@ export function dropConstraint(constraintName, columnName, constraintType) {
constraintType
};
}

export function removeColumn(columnName) {
return {
type: types.REMOVE_COLUMN,
Expand Down
2 changes: 0 additions & 2 deletions app/actions/favorites.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ export function getFavorites() {
};
}


export function toggleFavoriteSwitcher() {
return {
type: types.TOGGLE_FAV_SWITCHER
};
}

18 changes: 15 additions & 3 deletions app/actions/tables.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import DB from '../db';

import * as types from '../constants/tablesConstants';
import { stopFetching } from './currentTable';

export function setCurrentTable(tableName) {
return {
Expand Down Expand Up @@ -66,21 +67,32 @@ export function getTables(clear = undefined) {
}
DB.getTables()
.then(
tables => DB.getTableOid(tables),
(tables) => {
if (tables.length) {
return DB.getTableOid(tables);
}
return tables;
},
(error) => {
reject(error);
}
)
.then(
tables => DB.getForeignKeys(tables)
(tables) => {
if (tables.length) {
return DB.getForeignKeys(tables);
}
dispatch(stopFetching());
return tables;
}
)
.then(
(tables) => {
dispatch({
type: types.GET_TABLES,
tables
});
resolve(tables[0].table_name);
resolve(tables.length ? tables[0].table_name : '');
}
);
});
Expand Down
12 changes: 12 additions & 0 deletions app/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,17 @@
s0.parentNode.insertBefore(script, s0);
}());
</script>
<!-- start Mixpanel -->
<script type="text/javascript">
(function() {
if (process.env.NODE_ENV !== 'development') {
(function(e,a){if(!a.__SV){var b=window;try{var c,l,i,j=b.location,g=j.hash;c=function(a,b){return(l=a.match(RegExp(b+"=([^&]*)")))?l[1]:null};g&&c(g,"state")&&(i=JSON.parse(decodeURIComponent(c(g,"state"))),"mpeditor"===i.action&&(b.sessionStorage.setItem("_mpcehash",g),history.replaceState(i.desiredHash||"",e.title,j.pathname+j.search)))}catch(m){}var k,h;window.mixpanel=a;a._i=[];a.init=function(b,c,f){function e(b,a){var c=a.split(".");2==c.length&&(b=b[c[0]],a=c[1]);b[a]=function(){b.push([a].concat(Array.prototype.slice.call(arguments,
0)))}}var d=a;"undefined"!==typeof f?d=a[f]=[]:f="mixpanel";d.people=d.people||[];d.toString=function(b){var a="mixpanel";"mixpanel"!==f&&(a+="."+f);b||(a+=" (stub)");return a};d.people.toString=function(){return d.toString(1)+".people (stub)"};k="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config reset people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
for(h=0;h<k.length;h++)e(d,k[h]);a._i.push([b,c,f])};a.__SV=1.2;b=e.createElement("script");b.type="text/javascript";b.async=!0;b.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";c=e.getElementsByTagName("script")[0];c.parentNode.insertBefore(b,c)}})(document,window.mixpanel||[]);
mixpanel.init("");
}
}());
</script>
<!-- end Mixpanel -->
</body>
</html>
54 changes: 33 additions & 21 deletions app/components/Base/BaseComponent.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { PropTypes } from 'react';
import React, { PropTypes, Component } from 'react';
import { connect } from 'react-redux';

import MainSidebar from '../Main/Sidebar/MainSidebar';
Expand All @@ -8,32 +8,44 @@ import MainContent from '../Main/Content/MainContent';
import Header from '../Base/Header/Header';
import ContextMenu from '../Base/ContextMenu/ContextMenu';
import UpdatesModal from '../Connect/Content/UpdatesModal/UpdatesModal';
import { startAppMixpanelEvent } from '../../helpers';

const propTypes = {
isConnected: PropTypes.bool
};

const BaseComponent = props =>
<div id="wrapper" className="">
<ContextMenu />
{props.isConnected ?
<div className="flex-row max-height">
<div className="flex-col left-pane">
<Header />
<MainSidebar />
</div>
<MainContent />
</div> :
<div className="flex-col max-height">
<Header />
class BaseComponent extends Component {
componentDidMount() {
startAppMixpanelEvent();
}

render() {
const { isConnected } = this.props;
return (
<div id="wrapper">
<ContextMenu />
{isConnected ?
<div className="flex-row max-height">
<UpdatesModal />
<ConnectSidebar />
<ReduxFormBase />
</div>
</div>
}
</div>;
<div className="flex-col left-pane">
<Header />
<MainSidebar />
</div>
<MainContent />
</div> :
<div className="flex-col max-height">
<Header />
<div className="flex-row max-height">
<UpdatesModal />
<ConnectSidebar />
<ReduxFormBase />
</div>
</div>
}
</div>
);
}
}


BaseComponent.propTypes = propTypes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class FavSwitcherComponent extends Component {
<hr />
<div className="btn-block">
<button className="btn btn-plain btn--block-centered" onClick={this.handleClick}>
<i className="fa fa-plus" onClick={toggleFavoriteSwitcher} />
<i className="fa fa-plus" />
&#160;New Connection
</button>
</div>
Expand Down
5 changes: 4 additions & 1 deletion app/components/Base/LaddaButton/LaddaButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ class LaddaButton extends Component {
}

render() {
const { children, ...laddaProps } = this.props;
/* Because loadding prop should be separated from other props */
/* eslint-disable no-unused-vars */
const { children, loading, ...laddaProps } = this.props;
/* eslint-enable no-unused-vars */

return (
<button {...laddaProps} ref={(c) => { this.node = c; }}>
Expand Down
2 changes: 2 additions & 0 deletions app/components/Connect/Content/ReduxFormBase.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React, { Component } from 'react';
import ReduxFormMain from './ReduxFormMain';
import { mixPanelTrack } from '../../../helpers';

const { shell } = require('electron');


class ReduxFormBase extends Component {
static onClick(ev) {
ev.preventDefault();
mixPanelTrack('Open web-pal.com');
shell.openExternal('http://web-pal.com?ref=dbglass');
}

Expand Down
26 changes: 17 additions & 9 deletions app/components/Connect/Content/ReduxFormMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import LaddaButton from '../../Base/LaddaButton/LaddaButton';

import { renderField, renderCheckbox } from './InputComponents';

import { mixPanelTrack } from '../../../helpers';

const propTypes = {
handleSubmit: PropTypes.func.isRequired,
reset: PropTypes.func.isRequired,
Expand Down Expand Up @@ -51,23 +53,28 @@ class ReduxFormMain extends Component {
}

handleSubmit = (values) => {
mixPanelTrack('Connect click');
this.setState({ error: null });
const data = Object.assign(
{}, values.toObject(), { privateKey: this.state.sshKey || this.props.sshKey }
);
const promise = new Promise(resolve => this.props.connectDB(data, (flag, err) => {
resolve(err);
const promise = new Promise(resolve => this.props.connectDB(data, (flag, err, sshError) => {
resolve({ err, sshError });
}));
return promise.then((err) => {
if (err) {
this.setState({ error: err });
throw new SubmissionError({
database: err, _error: 'Auth failed!' }
);
return promise.then((result) => {
if (result.err) {
mixPanelTrack('Connect error', { error: result.err });
this.setState({ error: result.err });
const errorObj = { _error: 'Auth failed' };
throw new SubmissionError(errorObj);
} else {
mixPanelTrack('Connect success');
}
});
}

handleSave = () => {
mixPanelTrack('Save favorite click');
const data = Object.assign({}, this.props.formValues, { privateKey: this.state.sshKey });
if (data.id) {
this.props.updateFavorite(data);
Expand All @@ -80,6 +87,7 @@ class ReduxFormMain extends Component {
}

handleRemove = () => {
mixPanelTrack('Remove favorite click');
this.props.removeFavorite(this.props.formValues.id);
this.props.setCurrent(null);
}
Expand All @@ -98,7 +106,7 @@ class ReduxFormMain extends Component {
onSubmit={handleSubmit(this.handleSubmit)}
>
<div className="form-panel right-padded flex-col flex--half">
<span>{this.state.error}</span>
<span style={{ color: 'red' }}>{this.state.error}</span>
<Field
type="hidden"
name="id"
Expand Down
3 changes: 3 additions & 0 deletions app/components/Connect/Content/ReduxFormSSH.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React, { PropTypes, Component } from 'react';
import { Field } from 'redux-form/immutable';
import { renderRadio, renderField } from './InputComponents';

import { mixPanelTrack } from '../../../helpers';

const os = require('electron').remote.require('os');
const path = require('electron').remote.require('path');
const { dialog } = require('electron').remote;
Expand All @@ -22,6 +24,7 @@ class ReduxFormSSH extends Component {
}

showDialog = (event) => {
mixPanelTrack('Show SSH key dialog');
event.preventDefault();
const defaultPath = path.join(os.homedir(), '.ssh');
dialog.showOpenDialog({ defaultPath, properties: ['openFile'] }, (file) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const request = require('request');
const semver = require('semver');

export default function checkVersion(callback) {
const currentVersion = 'v0.1.0-beta.2';
const currentVersion = 'v0.1.0-beta.3';

const options = {
url: 'https://api.github.com/repos/web-pal/DBGlass/releases/latest',
Expand Down
Loading

0 comments on commit d7a04ae

Please sign in to comment.