Commit 27da13f1 by Chaiwith Santaweesuk

fix feed

parent 9a3a094c
......@@ -14,11 +14,11 @@ export const SmCard = props => {
<h6>{smdata.smtitle}</h6>
<Row style={{ alignItems: 'center' }}>
<Col>
{smdata.iconType === 'max' ? (
{smdata.iconType == 'max' ? (
<FaArrowUp {...iconStyle} />
) : smdata.iconType === 'min' ? (
) : smdata.iconType == 'min' ? (
<FaArrowDown {...iconStyle} />
) : smdata.iconType === 'money' ? (
) : smdata.iconType == 'money' ? (
<FaMoneyBillAlt {...iconStyle} />
) : (
<FaUserFriends {...iconStyle} />
......@@ -49,20 +49,41 @@ const DataCard = props => {
// if (Object.keys(mapValues).includes(key)) {
// mapValues[key] += allValues[index][1];
let key = allValues[index][0];
if(breakdown=="minutes"){
// if (breakdown=="minutes") {
// key = moment(parseInt(allValues[index][0])).minutes(Math.round(moment(parseInt(allValues[index][0])).minutes() / 5) * 5);
// }
// else if (breakdown=="hours") {
// key = moment(parseInt(allValues[index][0])).minutes(Math.round(moment(parseInt(allValues[index][0])).minutes() / 60) * 60);
// }
// else if (breakdown=="days") {
// key = moment(parseInt(allValues[index][0])).hours(0).minutes(0);
// }
// else if (breakdown=="weeks") {
// key = moment(parseInt(allValues[index][0])).startOf('week').hours(0).minutes(0);
// }
// else if (breakdown=="months") {
// key = moment(parseInt(allValues[index][0])).startOf('month').hours(0).minutes(0);
// }
if (breakdown == "minutes") {
key = moment(parseInt(allValues[index][0])).minutes(Math.round(moment(parseInt(allValues[index][0])).minutes() / 5) * 5);
// timestamp = key.valueOf().toString().substring(0, 8) + "00000";
} else if (breakdown == "hours") {
key = moment(parseInt(allValues[index][0])).minutes(0);
// timestamp = key.valueOf().toString().substring(0, 8) + "00000";
}
else if(breakdown=="hours"){
key = moment(parseInt(allValues[index][0])).minutes(Math.round(moment(parseInt(allValues[index][0])).minutes() / 60) * 60);
else if (breakdown == "days") {
key = moment(parseInt(allValues[index][0])).hours(1).minutes(0);
// timestamp = key.valueOf().toString().substring(0, 8) + "00000";
}
else if(breakdown=="days"){
key = moment(parseInt(allValues[index][0])).hours(0).minutes(0);
}
else if(breakdown=="weeks"){
key = moment(parseInt(allValues[index][0])).startOf('week').hours(0).minutes(0);
else if (breakdown == "weeks") {
key = moment(parseInt(allValues[index][0])).startOf('week').hours(1).minutes(0);
// timestamp = key.valueOf().toString().substring(0, 8) + "00000";
}
else if(breakdown=="months"){
key = moment(parseInt(allValues[index][0])).startOf('month').hours(0).minutes(0);
else if (breakdown == "months") {
key = moment(parseInt(allValues[index][0])).startOf('month').hours(1).minutes(0);
// timestamp = key.valueOf().toString().substring(0, 8) + "00000";
}
const timestamp = key.valueOf().toString().substring(0, 8) + "00000";
if (Object.keys(mapValues).includes(timestamp)) {
......@@ -122,7 +143,7 @@ const DataCard = props => {
</Card>
<Row>
{data.detail.map((item, index) =>
data.detail.length === 1 ? (
data.detail.length == 1 ? (
<Col key={index} md={12} style={{ marginTop: '.7em' }}>
<SmCard
backgroundColor={data.backgroundColor}
......@@ -136,7 +157,7 @@ const DataCard = props => {
md={6}
style={{
marginTop: '.7em',
paddingLeft: !props.isMobileSized ? (index % 2 === 0 ? '15px' : '7.5px') : '15px',
paddingLeft: !props.isMobileSized ? (index % 2 == 0 ? '15px' : '7.5px') : '15px',
paddingRight: !props.isMobileSized ? (index % 2 !== 0 ? '15px' : '7.5px') : '15px',
}}
>
......
......@@ -38,8 +38,8 @@ class GetDataSelection extends Component {
const { allLocationInfo } = this.props;
const startDateTimeStamp = moment(startDate).valueOf();
const endDateTimeStamp = moment(endDate).valueOf();
const devices = allLocationInfo.find(element => element.locationid === location).devicesId;
const type = allLocationInfo.find(element => element.locationid === location).type;
const devices = allLocationInfo.find(element => element.locationid == location).devicesId;
const type = allLocationInfo.find(element => element.locationid == location).type;
this.props.getSelectedFeed(
devices,
location,
......@@ -64,8 +64,8 @@ class GetDataSelection extends Component {
};
componentDidUpdate = (prevProps, prevState) => {
if (prevProps.selectedFeed!=this.props.selectedFeed) {
this.setState({location: this.props.selectedFeed.location})
if (prevProps.selectedFeed != this.props.selectedFeed) {
this.setState({ location: this.props.selectedFeed.location })
}
};
......@@ -74,10 +74,10 @@ class GetDataSelection extends Component {
let start = this.state.startDate.format('DD MMM YY');
let end = this.state.endDate.format('DD MMM YY');
let label = start + ' - ' + end;
if (start === end) {
if (start == end) {
label = start;
}
return (
<Col>
<Form.Label>Get data from</Form.Label>
......@@ -100,8 +100,8 @@ class GetDataSelection extends Component {
);
})
) : (
<option value="">Loading...</option>
)}
<option value="">Loading...</option>
)}
</Form.Control>
</Col>
<Col md>
......
......@@ -19,9 +19,9 @@ export default class Mapbox extends Component {
// if (this.props.allLocationInfo) {
// if (prevProps.selectedFeed !== this.props.selectedFeed) {
// if(this.props.selectedFeed.type=="door"){
// const data1 = this.props.allLocationInfo.filter(location => location.type === "door");
// const data1 = this.props.allLocationInfo.filter(location => location.type == "door");
// const { location } = this.props.selectedFeed;
// const currentIndex = data1.findIndex(element => element.locationid === location);
// const currentIndex = data1.findIndex(element => element.locationid == location);
// this.setState({
// data: data1,
// center: data1[currentIndex].position,
......@@ -40,7 +40,7 @@ export default class Mapbox extends Component {
// };
componentDidUpdate = (prevProps, prevState) => {
if(prevProps.active!=this.props.active){
if (prevProps.active != this.props.active) {
this.setState({
data: this.props.data,
center: this.props.center,
......@@ -119,7 +119,7 @@ export default class Mapbox extends Component {
</Map>
</Col>
);
}
}
......
......@@ -5,7 +5,7 @@ export default function PrivateRoute({ component: Component, authenticated, ...r
return (
<Route
{...rest}
render={props => (authenticated === true ? <Component {...props} {...rest} /> : <Redirect to="/login" />)}
render={props => (authenticated == true ? <Component {...props} {...rest} /> : <Redirect to="/login" />)}
/>
);
}
......@@ -8,7 +8,7 @@ import logger from 'redux-logger';
import App from './App';
import './styles.scss';
let middleware = process.env.NODE_ENV === `development` ? applyMiddleware(thunk, logger) : applyMiddleware(thunk);
let middleware = process.env.NODE_ENV == `development` ? applyMiddleware(thunk, logger) : applyMiddleware(thunk);
const store = createStore(rootReducer, middleware);
......
......@@ -15,18 +15,18 @@ export const getAllDevicesInfo = () => async (dispatch, getState) => {
const currentUid = fireStoreReducer.fireStoreCurrentUser.uid;
const locationId = await db
.collection('membership')
.doc(currentUid)
.get();
.collection('membership')
.doc(currentUid)
.get();
let allLocationId = Object.keys(locationId.data());
let allLocationInfo = [];
let allDeviceInfo = [];
let allDeviceId = [];
for (let i = 0, len = allLocationId.length; i < len; i++) {
const locationInfo = await db
.collection('location')
.doc(allLocationId[i])
.get();
.collection('location')
.doc(allLocationId[i])
.get();
let info = locationInfo.data();
let locationData = {};
locationData.locationid = allLocationId[i];
......@@ -38,16 +38,16 @@ export const getAllDevicesInfo = () => async (dispatch, getState) => {
let devicesId = Object.keys(info.devices);
devicesId.forEach(async device => {
const deviceInfo = await db
.collection('device')
.doc(device)
.get();
.collection('device')
.doc(device)
.get();
allDeviceId.push(device);
allDeviceInfo.push({location: allLocationId[i], deviceid: device, name: deviceInfo.data().name});
allDeviceInfo.push({ location: allLocationId[i], deviceid: device, name: deviceInfo.data().name });
locationData.devicesId.push(device);
});
allLocationInfo.push(locationData);
if (i === allLocationId.length - 1) {
if (i == allLocationId.length - 1) {
dispatch(getAllDevicesInfoAction(allLocationInfo.sort((a, b) => a.name.localeCompare(b.name)), allLocationId, allDeviceInfo, allDeviceId));
}
}
......@@ -69,7 +69,7 @@ export const getAllDevicesInfo = () => async (dispatch, getState) => {
// devicedata.position = [devicedata.location._long, devicedata.location._lat];
// console.log(devicedata);
// allDeviceInfo.push(devicedata);
// if (i === allDeviceId.length - 1) {
// if (i == allDeviceId.length - 1) {
// console.log(allDeviceInfo);
// console.log(allDeviceId);
// dispatch(getAllDevicesInfoAction(allDeviceInfo, allDeviceId));
......
......@@ -24,13 +24,13 @@ export const getFeedData = () => async (dispatch, getState) => {
const { devices, range, breakdown } = selectedFeedReducer.selectedFeed;
const attrList = [
{ tag: "['Current Cash']", aggregator: 'last' },
{ tag: 'Revenue', aggregator: 'sum' },
{ tag: 'Remote', aggregator: 'sum' },
{ tag: 'People', aggregator: 'sum' },
{ tag: 'Fingerprint', aggregator: 'sum' },
{ tag: 'Keycard', aggregator: 'sum' }
];
{ tag: "['Current Cash']", aggregator: 'last' },
{ tag: 'Revenue', aggregator: 'sum' },
{ tag: 'Remote', aggregator: 'sum' },
{ tag: 'People', aggregator: 'sum' },
{ tag: 'Fingerprint', aggregator: 'sum' },
{ tag: 'Keycard', aggregator: 'sum' }
];
let metrics = [];
devices.forEach(device => {
attrList.forEach(element => {
......@@ -61,8 +61,8 @@ export const getFeedData = () => async (dispatch, getState) => {
const q_data = {
start_absolute: range.startDate,
end_absolute: range.endDate,
metrics : metrics
metrics: metrics
};
try {
......@@ -82,26 +82,28 @@ export const getFeedData = () => async (dispatch, getState) => {
let fingerPrintFeedList = [];
let keycardFeedList = [];
response.data.queries.forEach(query => {
if(query.results[0].tags.attr=="['Current Cash']"){
currentFeedList.push({ deviceId: query.results[0].name, value: query.results[0].values});
if (query.results[0].tags.attr == "['Current Cash']") {
currentFeedList.push({ deviceId: query.results[0].name, value: query.results[0].values });
}
else if(query.results[0].tags.attr=="Revenue"){
revenueFeedList.push({ deviceId: query.results[0].name, value: query.results[0].values});
else if (query.results[0].tags.attr == "Revenue") {
revenueFeedList.push({ deviceId: query.results[0].name, value: query.results[0].values });
}
else if(query.results[0].tags.attr=="Remote"){
remoteFeedList.push({ deviceId: query.results[0].name, value: query.results[0].values});
else if (query.results[0].tags.attr == "Remote") {
remoteFeedList.push({ deviceId: query.results[0].name, value: query.results[0].values });
}
else if(query.results[0].tags.attr=="People"){
peopleFeedList.push({ deviceId: query.results[0].name, value: query.results[0].values});
else if (query.results[0].tags.attr == "People") {
peopleFeedList.push({ deviceId: query.results[0].name, value: query.results[0].values });
}
else if(query.results[0].tags.attr=="Fingerprint"){
fingerPrintFeedList.push({ deviceId: query.results[0].name, value: query.results[0].values});
else if (query.results[0].tags.attr == "Fingerprint") {
fingerPrintFeedList.push({ deviceId: query.results[0].name, value: query.results[0].values });
}
else if(query.results[0].tags.attr=="Keycard"){
keycardFeedList.push({ deviceId: query.results[0].name, value: query.results[0].values});
else if (query.results[0].tags.attr == "Keycard") {
keycardFeedList.push({ deviceId: query.results[0].name, value: query.results[0].values });
}
});
// console.log(peopleFeedList)
// console.log(revenueFeedList)
// console.log(currentFeedList)
dispatch(
getFeedDataAction({
currentFeed: currentFeedList || [],
......
......@@ -11,15 +11,15 @@
// opt-in, read https://bit.ly/CRA-PWA
const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/)
window.location.hostname == 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname == '[::1]' ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/)
);
export function register(config) {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
if (process.env.NODE_ENV == 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
if (publicUrl.origin !== window.location.origin) {
......@@ -41,7 +41,7 @@ export function register(config) {
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit https://bit.ly/CRA-PWA'
'worker. To learn more, visit https://bit.ly/CRA-PWA'
);
});
} else {
......@@ -62,14 +62,14 @@ function registerValidSW(swUrl, config) {
return;
}
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (installingWorker.state == 'installed') {
if (navigator.serviceWorker.controller) {
// At this point, the updated precached content has been fetched,
// but the previous service worker will still serve the older
// content until all client tabs are closed.
console.log(
'New content is available and will be used when all ' +
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
);
// Execute callback
......@@ -102,7 +102,7 @@ function checkValidServiceWorker(swUrl, config) {
.then(response => {
// Ensure service worker exists, and that we really are getting a JS file.
const contentType = response.headers.get('content-type');
if (response.status === 404 || (contentType != null && contentType.indexOf('javascript') === -1)) {
if (response.status == 404 || (contentType !== null && contentType.indexOf('javascript') == -1)) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => {
registration.unregister().then(() => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment