Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: DO NOT MERGE - Introduce prettier for coding style #95

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,12 @@

```
$ npm run test:watch
```
```

## CONTRIBUTING

Use Prettier to format your code.

```
$ npm run prettier
```
47 changes: 25 additions & 22 deletions client/app/actions/AppActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,29 @@ import { requestOauth } from '../utils/fetch';

const cookie = cookieDough();

export const checkToken = () => (dispatch) => {
const token = cookie.get('token');
if (!token) {
return browserHistory.push('/login');
}
return requestOauth('/cookies', 'POST', { token })
.then(data => dispatch({
type: types.CHECKTOKEN,
access_token: data.results.access_token,
token: data.results.token,
userId: data.results.userId,
userName: data.results.userName,
email: data.results.email,
userImage: data.results.userImage,
isAdmin: data.results.isAdmin,
}))
.catch(error => browserHistory.push(`/login?errorMsg=${error}`));
};
export const checkToken = () =>
dispatch => {
const token = cookie.get('token');
if (!token) {
return browserHistory.push('/login');
}
return requestOauth('/cookies', 'POST', { token })
.then(data =>
dispatch({
type: types.CHECKTOKEN,
access_token: data.results.access_token,
token: data.results.token,
userId: data.results.userId,
userName: data.results.userName,
email: data.results.email,
userImage: data.results.userImage,
isAdmin: data.results.isAdmin,
}))
.catch(error => browserHistory.push(`/login?errorMsg=${error}`));
};

export const signOut = () => (dispatch) => {
cookie.remove('token');
return dispatch({ type: types.SIGNOUT });
};
export const signOut = () =>
dispatch => {
cookie.remove('token');
return dispatch({ type: types.SIGNOUT });
};
20 changes: 12 additions & 8 deletions client/app/actions/DashboardActions.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import types from '../constants/DashboardActionTypes';
import { request } from '../utils/fetch';

export const retrieveDashboard = () => (dispatch, getState) => {
return request('/dashboard', 'GET', getState().main.access_token)
.then((data) => {
return dispatch({
type: types.RETRIEVEDASHBOARD,
data: data.data,
export const retrieveDashboard = () =>
(dispatch, getState) => {
return request(
'/dashboard',
'GET',
getState().main.access_token
).then(data => {
return dispatch({
type: types.RETRIEVEDASHBOARD,
data: data.data,
});
});
});
}
};
46 changes: 31 additions & 15 deletions client/app/actions/DeviceActions.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
import types from '../constants/DeviceActionTypes';
import { request } from '../utils/fetch';

export const retrieveDeviceList = () => (dispatch, getState) =>
request('/devices', 'GET', getState().main.access_token)
.then(data => dispatch({
type: types.RETRIEVEDEVICELIST,
data: data.data,
}));
export const retrieveDeviceList = () =>
(dispatch, getState) =>
request('/devices', 'GET', getState().main.access_token).then(data =>
dispatch({
type: types.RETRIEVEDEVICELIST,
data: data.data,
}));

export const editDevice = (id, data) => (dispatch, getState) =>
request(`/devices/${id}`, 'PUT', data, getState().main.access_token)
.then(() => {
export const editDevice = (id, data) =>
(dispatch, getState) =>
request(
`/devices/${id}`,
'PUT',
data,
getState().main.access_token
).then(() => {
retrieveDeviceList()(dispatch, getState);
});

export const deleteDevice = id => (dispatch, getState) =>
request(`/devices/${id}`, 'DELETE', {}, getState().main.access_token)
.then(() => {
export const deleteDevice = id =>
(dispatch, getState) =>
request(
`/devices/${id}`,
'DELETE',
{},
getState().main.access_token
).then(() => {
retrieveDeviceList()(dispatch, getState);
});

export const uploadDeviceImage = file => (dispatch, getState) =>
request('/upload/image?type=device', 'POST_FORM_DATA', file, getState().main.access_token)
.catch(() => Promise.reject());
export const uploadDeviceImage = file =>
(dispatch, getState) =>
request(
'/upload/image?type=device',
'POST_FORM_DATA',
file,
getState().main.access_token
).catch(() => Promise.reject());
54 changes: 38 additions & 16 deletions client/app/actions/DeviceDetailActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,52 @@ import types from '../constants/DeviceActionTypes';
import { retrieveDeviceList } from './deviceActions';
import { request } from '../utils/fetch';

export const retrieveDevice = id => (dispatch, getState) =>
request(`/devices/${id}`, 'GET', getState().main.access_token)
.then(data => dispatch({
type: types.RETRIEVEDEVICE,
data: data.data,
}));
export const retrieveDevice = id =>
(dispatch, getState) =>
request(`/devices/${id}`, 'GET', getState().main.access_token).then(data =>
dispatch({
type: types.RETRIEVEDEVICE,
data: data.data,
}));

export const editDevice = (id, data) => (dispatch, getState) =>
request(`/devices/${id}`, 'PUT', data, getState().main.access_token)
.then(() => {
export const editDevice = (id, data) =>
(dispatch, getState) =>
request(
`/devices/${id}`,
'PUT',
data,
getState().main.access_token
).then(() => {
retrieveDevice(id)(dispatch, getState);
});

export const deleteDevice = id => (dispatch, getState) =>
request(`/devices/${id}`, 'DELETE', {}, getState().main.access_token)
.then(() => {
export const deleteDevice = id =>
(dispatch, getState) =>
request(
`/devices/${id}`,
'DELETE',
{},
getState().main.access_token
).then(() => {
browserHistory.push('/devices/');
retrieveDeviceList()(dispatch, getState);
});

export const retrieveDatachannelDatapoint =
(deviceId, deviceKey, datachannelId, start, end) => (dispatch, getState) =>
request(`/devices/${deviceId}/datachannels/${datachannelId}/datapoints?${start ? `start=${start}&` : ''}${end ? `end=${end}` : ''}`, 'GET_DATAPOINTS', deviceKey, getState().main.access_token)
.then(data => dispatch({
export const retrieveDatachannelDatapoint = (
deviceId,
deviceKey,
datachannelId,
start,
end
) =>
(dispatch, getState) =>
request(
`/devices/${deviceId}/datachannels/${datachannelId}/datapoints?${start ? `start=${start}&` : ''}${end ? `end=${end}` : ''}`,
'GET_DATAPOINTS',
deviceKey,
getState().main.access_token
).then(data =>
dispatch({
type: types.RETRIVEDATACHANNELDATAPOINT,
data: data.data,
deviceId,
Expand Down
27 changes: 14 additions & 13 deletions client/app/actions/LoginActions.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import types from '../constants/LoginTypes';

const getQuery = function(name) {
const getQuery = function(name) {
var match;
var pl = /\+/g; /* Regex for replacing addition symbol with a space */
var pl = /\+/g; /* Regex for replacing addition symbol with a space */
var search = /([^&=]+)=?([^&]*)/g;
var query = window.location.search.substring(1);
var query = window.location.search.substring(1);
var decode = function(s) {
return decodeURIComponent(s.replace(pl, ' '));
};

var urlParams = {};
while (match = search.exec(query)) {
while ((match = search.exec(query))) {
urlParams[decode(match[1])] = decode(match[2]);
}

return urlParams[name];
};

export const detectErrorMsg = (aaa) => (dispatch) => {
const msg = getQuery('errorMsg');
if (msg) {
return dispatch({
type: types.ERRORMSG,
errorMsg: msg
});
}
}
export const detectErrorMsg = aaa =>
dispatch => {
const msg = getQuery('errorMsg');
if (msg) {
return dispatch({
type: types.ERRORMSG,
errorMsg: msg,
});
}
};
Loading