From 0539eb740f9ca9a4ea0204377c375ad39e40f2c6 Mon Sep 17 00:00:00 2001 From: mgerb42 Date: Fri, 9 Sep 2016 20:57:34 +0000 Subject: [PATCH 01/13] working on api for getting unique list of dates --- client/js/app.js | 2 +- client/js/components/sensors/SensorList.js | 6 +- client/js/components/sensors/SensorList.scss | 2 +- server/controller/api/sensor.go | 65 +++++++++----------- server/model/daily_sensor/daily_sensor.go | 50 ++++++++++++--- server/route/route.go | 3 +- 6 files changed, 76 insertions(+), 52 deletions(-) diff --git a/client/js/app.js b/client/js/app.js index 9560bed..fe60721 100644 --- a/client/js/app.js +++ b/client/js/app.js @@ -39,7 +39,7 @@ ReactDOM.render(( - + diff --git a/client/js/components/sensors/SensorList.js b/client/js/components/sensors/SensorList.js index c1dfa1f..afdd47a 100644 --- a/client/js/components/sensors/SensorList.js +++ b/client/js/components/sensors/SensorList.js @@ -20,8 +20,8 @@ export default class SensorList extends React.Component { this.openLink = this.openLink.bind(this); } - openLink(){ - browserHistory.push("/"); + openLink(location){ + browserHistory.push(`/sensor/${location}`); this.props.toggleOff(); } @@ -29,7 +29,7 @@ export default class SensorList extends React.Component { const date = new Date(sensor.updated); return ( -
+
{this.openLink(sensor.location)}}>

{sensor.temperature}°f

diff --git a/client/js/components/sensors/SensorList.scss b/client/js/components/sensors/SensorList.scss index 893884f..758923a 100644 --- a/client/js/components/sensors/SensorList.scss +++ b/client/js/components/sensors/SensorList.scss @@ -9,7 +9,7 @@ padding: 1em; &:hover{ - background-color: gray; + background-color: #D1D1D1; } .item + .item{ diff --git a/server/controller/api/sensor.go b/server/controller/api/sensor.go index 5dd87be..f4e5dc5 100644 --- a/server/controller/api/sensor.go +++ b/server/controller/api/sensor.go @@ -61,6 +61,7 @@ func HandleSensorRequest(w http.ResponseWriter, r *http.Request, ps httprouter.P storedData.Month = int(t.Month()) storedData.MonthName = t.Month().String() storedData.Year = t.Year() + storedData.Updated = t err := storedData.StoreData() @@ -134,21 +135,7 @@ func HandleSensorByLocation(w http.ResponseWriter, r *http.Request, ps httproute s, err := daily_sensor.GetAllSensorInfo(location) - var response string - - if err != nil { - log.Println(err) - response = "{message : \"Error loading data from database\"" - } else { - js, err := json.MarshalIndent(s, "", " ") - - if err != nil { - log.Println(err) - response = "{message : \"Error loading data from database\"" - } else { - response = string(js) - } - } + response := createResponse(s, err) fmt.Fprint(w, response) } @@ -162,21 +149,7 @@ func HandleSensorByLocationYear(w http.ResponseWriter, r *http.Request, ps httpr s, err := daily_sensor.GetAllSensorInfoByYear(location, year) - var response string - - if err != nil { - log.Println(err) - response = "{message : \"Error loading data from database\"" - } else { - js, err := json.MarshalIndent(s, "", " ") - - if err != nil { - log.Println(err) - response = "{message : \"Error loading data from database\"" - } else { - response = string(js) - } - } + response := createResponse(s, err) fmt.Fprint(w, response) } @@ -191,21 +164,41 @@ func HandleSensorByLocationMonth(w http.ResponseWriter, r *http.Request, ps http s, err := daily_sensor.GetAllSensorInfoByMonth(location, year, monthname) + response := createResponse(s, err) + + fmt.Fprint(w, response) +} + +/* +func HandleUniqueDates(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { + + location := ps.ByName("location") + + w.Header().Set("Content-Type", "application/json") + + s, err := daily_sensor.GetUniqueSensorDates(location) + + response := createResponse(s, err) + + fmt.Fprint(w, response) +} +*/ +func createResponse(s []daily_sensor.Data, err error) string{ var response string if err != nil { log.Println(err) response = "{message : \"Error loading data from database\"" } else { - js, err := json.MarshalIndent(s, "", " ") + js, err1 := json.MarshalIndent(s, "", " ") - if err != nil { - log.Println(err) + if err1 != nil { + log.Println(err1) response = "{message : \"Error loading data from database\"" } else { response = string(js) } } - - fmt.Fprint(w, response) -} + + return response +} \ No newline at end of file diff --git a/server/model/daily_sensor/daily_sensor.go b/server/model/daily_sensor/daily_sensor.go index 99837bb..0dc8f27 100644 --- a/server/model/daily_sensor/daily_sensor.go +++ b/server/model/daily_sensor/daily_sensor.go @@ -16,22 +16,24 @@ const ( type Data struct { ID bson.ObjectId `bson:"_id,omitempty"` - MaxTemp float64 `json:"maxtemp" bson:"maxtemp"` - MinTemp float64 `json:"mintemp" bson:"mintemp"` - Location string `json:"location" bson:"location"` - Month int `json:"month" bson:"month"` - MonthName string `json:"monthname" bson:"monthname"` - Day int `json:"day" bson:"day"` - Year int `json:"year" bson:"year"` + MaxTemp float64 `json:"maxtemp,omitempty" bson:"maxtemp"` + MinTemp float64 `json:"mintemp,omitempty" bson:"mintemp"` + Location string `json:"location,omitempty" bson:"location"` + Month int `json:"month,omitempty" bson:"month"` + MonthName string `json:"monthname,omitempty" bson:"monthname"` + Day int `json:"day,omitempty" bson:"day"` + Year int `json:"year,omitempty" bson:"year"` + Updated time.Time `json:"updated" bson:"updated"` } //convert struct to json string -func (s *Data) toJson() string { +func (s *Data) ToJson() string { b, err := json.MarshalIndent(s, "", " ") if err != nil { - log.Println(err.Error) + log.Println(err) + return "{message : \"Error loading data from database\"" } return string(b) @@ -73,7 +75,7 @@ func (s *Data) UpdateData() error { c := session.DB(db.Mongo.Info.Database).C(collection) colQuerier := bson.M{"location": s.Location, "month": s.Month, "monthname": s.MonthName, "day": s.Day, "year": s.Year} - change := bson.M{"$set": bson.M{"maxtemp": s.MaxTemp, "mintemp": s.MinTemp}} + change := bson.M{"$set": bson.M{"maxtemp": s.MaxTemp, "mintemp": s.MinTemp, "updated": time.Now()}} err := c.Update(colQuerier, change) @@ -198,3 +200,31 @@ func GetAllSensorInfoByMonth(sensor_location string, year int, monthname string) return d, errors.New("Query failed") } } + +/* +func GetUniqueSensorDates(sensor_location string) ([]Data, error){ + d := []Data{} + + if db.Mongo.Connected() == true { + + session := db.Mongo.Session.Copy() + defer session.Close() + + c := session.DB(db.Mongo.Info.Database).C(collection) + + err := c.Pipe([]bson.M{{"$match": bson.M{"location": sensor_location}}, + {"$project": bson.M{""}}, + {"$sort": bson.M{"year": -1, "month": 1}}}).All(&d) + + if err != nil { + log.Println(err) + return d, nil + } + + return d, nil + + } else { + return d, errors.New("Query failed") + } +} +*/ \ No newline at end of file diff --git a/server/route/route.go b/server/route/route.go index 8d7b9a6..6875f33 100644 --- a/server/route/route.go +++ b/server/route/route.go @@ -20,7 +20,8 @@ func Routes() *httprouter.Router { r.GET("/api/sensor/:location", api.HandleSensorByLocation) r.GET("/api/sensor/:location/:year", api.HandleSensorByLocationYear) r.GET("/api/sensor/:location/:year/:monthname", api.HandleSensorByLocationMonth) - + //r.GET("/api/sensor/:uniquedates", api.HandleUniqueDates) + r.GET("/discord", controller.DiscordRedirect) r.GET("/vpn", controller.VPNRedirect) r.GET("/camera", controller.CameraRedirect) From e2cb0969d71df3468f471cf78f304591a04b3298 Mon Sep 17 00:00:00 2001 From: mgerb42 Date: Sat, 10 Sep 2016 20:42:30 +0000 Subject: [PATCH 02/13] added end point for getting unique list of dates --- server/controller/api/sensor.go | 41 +++++++++++++++++++---- server/model/daily_sensor/daily_sensor.go | 18 ++++++---- server/route/route.go | 2 +- 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/server/controller/api/sensor.go b/server/controller/api/sensor.go index f4e5dc5..1105779 100644 --- a/server/controller/api/sensor.go +++ b/server/controller/api/sensor.go @@ -149,7 +149,21 @@ func HandleSensorByLocationYear(w http.ResponseWriter, r *http.Request, ps httpr s, err := daily_sensor.GetAllSensorInfoByYear(location, year) - response := createResponse(s, err) + var response string + + if err != nil { + log.Println(err) + response = "{message : \"Error loading data from database\"" + } else { + js, err := json.MarshalIndent(s, "", " ") + + if err != nil { + log.Println(err) + response = "{message : \"Error loading data from database\"" + } else { + response = string(js) + } + } fmt.Fprint(w, response) } @@ -164,12 +178,25 @@ func HandleSensorByLocationMonth(w http.ResponseWriter, r *http.Request, ps http s, err := daily_sensor.GetAllSensorInfoByMonth(location, year, monthname) - response := createResponse(s, err) + var response string + + if err != nil { + log.Println(err) + response = "{message : \"Error loading data from database\"" + } else { + js, err := json.MarshalIndent(s, "", " ") + + if err != nil { + log.Println(err) + response = "{message : \"Error loading data from database\"" + } else { + response = string(js) + } + } fmt.Fprint(w, response) } -/* func HandleUniqueDates(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { location := ps.ByName("location") @@ -182,7 +209,7 @@ func HandleUniqueDates(w http.ResponseWriter, r *http.Request, ps httprouter.Par fmt.Fprint(w, response) } -*/ + func createResponse(s []daily_sensor.Data, err error) string{ var response string @@ -190,10 +217,10 @@ func createResponse(s []daily_sensor.Data, err error) string{ log.Println(err) response = "{message : \"Error loading data from database\"" } else { - js, err1 := json.MarshalIndent(s, "", " ") + js, err := json.MarshalIndent(s, "", " ") - if err1 != nil { - log.Println(err1) + if err != nil { + log.Println(err) response = "{message : \"Error loading data from database\"" } else { response = string(js) diff --git a/server/model/daily_sensor/daily_sensor.go b/server/model/daily_sensor/daily_sensor.go index 0dc8f27..1a5e806 100644 --- a/server/model/daily_sensor/daily_sensor.go +++ b/server/model/daily_sensor/daily_sensor.go @@ -23,7 +23,7 @@ type Data struct { MonthName string `json:"monthname,omitempty" bson:"monthname"` Day int `json:"day,omitempty" bson:"day"` Year int `json:"year,omitempty" bson:"year"` - Updated time.Time `json:"updated" bson:"updated"` + Updated time.Time `json:"updated,omitempty" bson:"updated"` } //convert struct to json string @@ -132,7 +132,6 @@ func GetAllSensorInfo(sensor_location string) ([]Data, error) { c := session.DB(db.Mongo.Info.Database).C(collection) - //err := c.Find(bson.M{"location": sensor_location}).Sort("-year, -month").All(&d) err := c.Pipe([]bson.M{{"$match": bson.M{"location": sensor_location}}, {"$sort": bson.M{"year": -1, "month": 1}}}).All(&d) @@ -201,9 +200,13 @@ func GetAllSensorInfoByMonth(sensor_location string, year int, monthname string) } } -/* +type UniqueDates struct{ + Dates []Data `json:"dates" bson:"dates"` +} + func GetUniqueSensorDates(sensor_location string) ([]Data, error){ d := []Data{} + temp := UniqueDates{}; if db.Mongo.Connected() == true { @@ -213,9 +216,11 @@ func GetUniqueSensorDates(sensor_location string) ([]Data, error){ c := session.DB(db.Mongo.Info.Database).C(collection) err := c.Pipe([]bson.M{{"$match": bson.M{"location": sensor_location}}, - {"$project": bson.M{""}}, - {"$sort": bson.M{"year": -1, "month": 1}}}).All(&d) - + {"$group": bson.M{"_id": "null", "dates": bson.M{"$addToSet": bson.M{"month": "$month", "monthname": "$monthname", "year": "$year"}}}}, + }).One(&temp) + + d = temp.Dates; + if err != nil { log.Println(err) return d, nil @@ -227,4 +232,3 @@ func GetUniqueSensorDates(sensor_location string) ([]Data, error){ return d, errors.New("Query failed") } } -*/ \ No newline at end of file diff --git a/server/route/route.go b/server/route/route.go index 6875f33..90a6efe 100644 --- a/server/route/route.go +++ b/server/route/route.go @@ -20,7 +20,7 @@ func Routes() *httprouter.Router { r.GET("/api/sensor/:location", api.HandleSensorByLocation) r.GET("/api/sensor/:location/:year", api.HandleSensorByLocationYear) r.GET("/api/sensor/:location/:year/:monthname", api.HandleSensorByLocationMonth) - //r.GET("/api/sensor/:uniquedates", api.HandleUniqueDates) + r.GET("/api/uniquedates/:location", api.HandleUniqueDates) r.GET("/discord", controller.DiscordRedirect) r.GET("/vpn", controller.VPNRedirect) From e558fe5da24d93a499e9247de4499054e59faa78 Mon Sep 17 00:00:00 2001 From: mgerb42 Date: Sat, 10 Sep 2016 20:51:00 +0000 Subject: [PATCH 03/13] minor fix --- server/controller/api/sensor.go | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/server/controller/api/sensor.go b/server/controller/api/sensor.go index 1105779..03ff980 100644 --- a/server/controller/api/sensor.go +++ b/server/controller/api/sensor.go @@ -149,21 +149,7 @@ func HandleSensorByLocationYear(w http.ResponseWriter, r *http.Request, ps httpr s, err := daily_sensor.GetAllSensorInfoByYear(location, year) - var response string - - if err != nil { - log.Println(err) - response = "{message : \"Error loading data from database\"" - } else { - js, err := json.MarshalIndent(s, "", " ") - - if err != nil { - log.Println(err) - response = "{message : \"Error loading data from database\"" - } else { - response = string(js) - } - } + response := createResponse(s, err) fmt.Fprint(w, response) } @@ -178,21 +164,7 @@ func HandleSensorByLocationMonth(w http.ResponseWriter, r *http.Request, ps http s, err := daily_sensor.GetAllSensorInfoByMonth(location, year, monthname) - var response string - - if err != nil { - log.Println(err) - response = "{message : \"Error loading data from database\"" - } else { - js, err := json.MarshalIndent(s, "", " ") - - if err != nil { - log.Println(err) - response = "{message : \"Error loading data from database\"" - } else { - response = string(js) - } - } + response := createResponse(s, err) fmt.Fprint(w, response) } From e5d340df5d7e7cfef0484a317cc81ea3c1785427 Mon Sep 17 00:00:00 2001 From: mgerb42 Date: Tue, 13 Sep 2016 04:37:56 +0000 Subject: [PATCH 04/13] fixed end point - fixed posts in metadata --- client/js/app.js | 2 +- client/js/components/Post.js | 2 +- client/js/components/sensors/SensorInfo.js | 20 ++++++++++++++++ client/js/redux/actions/app.js | 8 +++++-- client/js/redux/actions/sensor.js | 27 ++++++++++++++++++++++ client/js/redux/constants/sensor.js | 5 ++-- client/js/redux/reducers/sensor.js | 18 ++++++++++++++- metadata.js | 11 +++++---- package.json | 3 ++- server/model/daily_sensor/daily_sensor.go | 24 ++++++++++++++----- 10 files changed, 102 insertions(+), 18 deletions(-) diff --git a/client/js/app.js b/client/js/app.js index fe60721..7a19d31 100644 --- a/client/js/app.js +++ b/client/js/app.js @@ -38,7 +38,7 @@ ReactDOM.render(( - + diff --git a/client/js/components/Post.js b/client/js/components/Post.js index 188153b..d340785 100644 --- a/client/js/components/Post.js +++ b/client/js/components/Post.js @@ -21,7 +21,7 @@ export default class Post extends React.Component { componentDidMount() { const params = this.props.params; - this.props.appActions.fetchPost(params.category, params.post); + this.props.appActions.fetchPost(params.post, params.category); } render() { diff --git a/client/js/components/sensors/SensorInfo.js b/client/js/components/sensors/SensorInfo.js index dcd0f3b..c45bd2f 100644 --- a/client/js/components/sensors/SensorInfo.js +++ b/client/js/components/sensors/SensorInfo.js @@ -1,11 +1,31 @@ import React from 'react'; +let location, sensor, actions, uniqueDates; + export default class SensorInfo extends React.Component{ componentDidMount(){ + location = this.props.params.location; + actions = this.props.sensorActions; + sensor = this.props.sensor; + + actions.fetchUniqueDates(location); + + /* this.props.sensorActions.fetchSensorInfoYear('Grand Meadow', '2016'); this.props.sensorActions.fetchSensorInfoMonth('Grand Meadow', '2016', 'May'); + this.props.sensorActions.fetchUniqueDates('Grand Meadow'); + */ } + + componentWillReceiveProps(){ + if(sensor.fetchedUniqueDates){ + uniqueDates = sensor.uniqueDates; + + //!sensor.fetchedInfoMonth ? actions.fetchSensorInfoMonth(location, ) + } + } + render(){ return(
Test123
diff --git a/client/js/redux/actions/app.js b/client/js/redux/actions/app.js index b1c9018..5759223 100644 --- a/client/js/redux/actions/app.js +++ b/client/js/redux/actions/app.js @@ -44,10 +44,14 @@ export function fetchPreview() { } } -export function fetchPost(category, post) { +//adjust url according to parameters +//mainly used to load md files in the parent directory within /posts +export function fetchPost(post, category = null) { + let url; return (dispatch) => { dispatch(fetching()); - return fetch(`/public/posts/${category}/${post}.md`) + url = category !== null || typeof category === 'undefined' ? `/public/posts/${category}/${post}.md` : `/public/posts/${post}.md`; + return fetch(url) .then(response => response.text()) .then(response => { dispatch(loadPost(response)); diff --git a/client/js/redux/actions/sensor.js b/client/js/redux/actions/sensor.js index e356e99..3467e8d 100644 --- a/client/js/redux/actions/sensor.js +++ b/client/js/redux/actions/sensor.js @@ -22,6 +22,13 @@ function loadSensorInfoMonth(sensor_info){ } } +function loadUniqueDates(dates){ + return{ + type: types.LOAD_UNIQUE_DATES, + dates + } +} + function fetchingList(){ return { type: types.FETCHING_LIST @@ -40,6 +47,12 @@ function fetchingInfoMonth(){ } } +function fetchingUniqueDates(){ + return { + type: types.FETCHING_UNIQUE_DATES + } +} + export function fetchSensorList(){ return (dispatch) => { dispatch(fetchingList()); @@ -80,4 +93,18 @@ export function fetchSensorInfoMonth(location, year, month){ console.log(error); }); } +} + +export function fetchUniqueDates(location){ + return (dispatch) => { + dispatch(fetchingUniqueDates()); + return fetch(`/api/uniquedates/${location}`) + .then(response => response.json()) + .then(json => { + dispatch(loadUniqueDates(json)); + }) + .catch(error => { + console.log(error); + }); + } } \ No newline at end of file diff --git a/client/js/redux/constants/sensor.js b/client/js/redux/constants/sensor.js index ae93469..39587d0 100644 --- a/client/js/redux/constants/sensor.js +++ b/client/js/redux/constants/sensor.js @@ -2,9 +2,10 @@ export const LOAD_SENSOR_LIST = 'LOAD_SENSOR_LIST'; export const LOAD_SENSOR_INFO_YEAR = 'LOAD_SENSOR_INFO_YEAR'; export const LOAD_SENSOR_INFO_MONTH = 'LOAD_SENSOR_INFO_MONTH'; - +export const LOAD_UNIQUE_DATES = 'LOAD_UNIQUE_DATES'; //fetching export const FETCHING_LIST = 'FETCHING_LIST'; export const FETCHING_INFO_YEAR = 'FETCHING_INFO_YEAR'; -export const FETCHING_INFO_MONTH = 'FETCHING_INFO_MONTH'; \ No newline at end of file +export const FETCHING_INFO_MONTH = 'FETCHING_INFO_MONTH'; +export const FETCHING_UNIQUE_DATES = 'FETCHING_UNIQUE_DATES'; \ No newline at end of file diff --git a/client/js/redux/reducers/sensor.js b/client/js/redux/reducers/sensor.js index 8d5a4af..3b28d23 100644 --- a/client/js/redux/reducers/sensor.js +++ b/client/js/redux/reducers/sensor.js @@ -6,19 +6,23 @@ const defaultState = { list : [], infoMonth: [], infoYear: [], + uniqueDates: {}, fetchingList: false, fetchingInfoMonth: false, fetchingInfoYear: false, + fetchingUniqueDates: false, fetchedList: false, fetchedInfoMonth: false, - fetchedInfoYear: false + fetchedInfoYear: false, + fetchedUniqueDates: false }; //default reducer export default function app(state = defaultState, action) { switch(action.type){ + //fetching functions - we use a fetching state to display loading images case types.FETCHING_LIST: return Object.assign({}, state, { fetchingList: true, @@ -34,7 +38,13 @@ export default function app(state = defaultState, action) { fetchingInfoYear: true, fetchedInfoYear: false }); + case types:FETCHING_UNIQUE_DATES: + return Object.assign({}, state, { + fetchingUniqueDates: true, + fetchedUniqueDates: false + }); + //other functions case types.LOAD_SENSOR_LIST: return Object.assign({}, state, { list: action.sensor_list, @@ -53,6 +63,12 @@ export default function app(state = defaultState, action) { fetchingInfoYear: false, fetchedInfoYear: true }); + case types.LOAD_UNIQUE_DATES: + return Object.assign({}, state, { + uniqueDates: action.dates, + fetchingUniqueDates: false, + fetchedUniqueDates: true + }); } //return present state if no actions get called return state; diff --git a/metadata.js b/metadata.js index fa3bce8..476a068 100644 --- a/metadata.js +++ b/metadata.js @@ -19,13 +19,15 @@ marked.setOptions({ } }); -const dir = './posts/'; +const rootDirectory = './posts/'; const json = { posts: [] }; //do everything synchronously to keep posts ordered -function parse_dir(dir, folder_name){ +//we are not worried about execution time since this script only runs once when building +//ignores files that are not in a directory +function parse_dir(dir, folder_name = null){ const posts = fs.readdirSync(dir); for(let post of posts){ @@ -33,7 +35,7 @@ function parse_dir(dir, folder_name){ if(stats.isDirectory()){ parse_dir(dir + post + '/', post); - } else { + } else if(folder_name !== null){ const file = fs.readFileSync(dir+post, 'utf8'); const tokens = marked.lexer(file, null); const temp = { @@ -49,7 +51,8 @@ function parse_dir(dir, folder_name){ } //recursively parse posts directory for all markdown files -parse_dir(dir, 'posts'); +//folder defaults to null and immediate child files are not added to json +parse_dir(rootDirectory); //sort posts by date json.posts.sort((a, b) => { diff --git a/package.json b/package.json index 72b6bf9..0788873 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "dev": "webpack-dev-server --content-base public --inline --hot --history-api-fallback", "get_dependencies": "go get ./server && npm install", "prod": "export NODE_ENV=production && webpack -p && babel-node metadata.js && go build ./server/mywebsite.go", - "prod-win": "set NODE_ENV=production && webpack -p && babel-node metadata.js && go build ./server/mywebsite.go" + "prod-win": "set NODE_ENV=production && webpack -p && babel-node metadata.js && go build ./server/mywebsite.go", + "watch": "webpack --watch --colors --progress" }, "repository": { "type": "git", diff --git a/server/model/daily_sensor/daily_sensor.go b/server/model/daily_sensor/daily_sensor.go index 1a5e806..4b45a29 100644 --- a/server/model/daily_sensor/daily_sensor.go +++ b/server/model/daily_sensor/daily_sensor.go @@ -200,13 +200,17 @@ func GetAllSensorInfoByMonth(sensor_location string, year int, monthname string) } } +//I need to find a better implementation of this +//MongoDB $addToSet creates an array of objecta +//this ends up being a different type than the Data struct above +//it would be nice to make all MongoDB queries load directly into a Data struct type UniqueDates struct{ Dates []Data `json:"dates" bson:"dates"` } func GetUniqueSensorDates(sensor_location string) ([]Data, error){ d := []Data{} - temp := UniqueDates{}; + //temp := UniqueDates{}; if db.Mongo.Connected() == true { @@ -214,12 +218,20 @@ func GetUniqueSensorDates(sensor_location string) ([]Data, error){ defer session.Close() c := session.DB(db.Mongo.Info.Database).C(collection) - - err := c.Pipe([]bson.M{{"$match": bson.M{"location": sensor_location}}, - {"$group": bson.M{"_id": "null", "dates": bson.M{"$addToSet": bson.M{"month": "$month", "monthname": "$monthname", "year": "$year"}}}}, - }).One(&temp) - d = temp.Dates; + err := c.Pipe([]bson.M{bson.M{"$match": bson.M{"location": sensor_location}}, + {"$group": bson.M{"_id": "null", "dates": bson.M{"$addToSet": bson.M{"month": "$month", "monthname": "$monthname", "year": "$year"}}}}, + {"$unwind": "$dates"}, + {"$project": bson.M{"_id": 0, "month": "$dates.month", "monthname": "$dates.monthname", "year": "$dates.year"}}, + {"$sort": bson.M{"year": 1, "month": 1}}, + + }).All(&d) + + //d = temp.Dates; + + test12, _ := json.MarshalIndent(d, "", " ") + + log.Println(string(test12)) if err != nil { log.Println(err) From 4354dfe4586a96e7c8d868644e43c9f555c213dc Mon Sep 17 00:00:00 2001 From: mgerb42 Date: Wed, 14 Sep 2016 13:07:18 +0000 Subject: [PATCH 05/13] added autoprefixer --- client/assets/scss/main.scss | 1 + package.json | 4 +++- webpack.config.js | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/client/assets/scss/main.scss b/client/assets/scss/main.scss index d90879e..25b126c 100644 --- a/client/assets/scss/main.scss +++ b/client/assets/scss/main.scss @@ -88,6 +88,7 @@ hr { display: flex; flex: 1; justify-content: center; + align-items: center; } .btn { diff --git a/package.json b/package.json index 0788873..96412e7 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "build": "webpack && babel-node metadata.js", "c9": "webpack-dev-server --port $PORT --host $IP --hot --content-base dist --history-api-fallback", "check_gzip_size": "gzip -9 -c ./public/client.min.js | wc -c | numfmt --to=iec-i --suffix=B --padding=10", - "deploy" : "npm run get_dependencies && npm run prod && ./mywebsite", + "deploy": "npm run get_dependencies && npm run prod && ./mywebsite", "dev": "webpack-dev-server --content-base public --inline --hot --history-api-fallback", "get_dependencies": "go get ./server && npm install", "prod": "export NODE_ENV=production && webpack -p && babel-node metadata.js && go build ./server/mywebsite.go", @@ -25,6 +25,7 @@ }, "homepage": "https://github.com/mgerb/mywebsite#readme", "dependencies": { + "autoprefixer": "^6.4.1", "babel": "^6.5.2", "babel-cli": "^6.11.4", "babel-core": "^6.13.2", @@ -45,6 +46,7 @@ "marked": "^0.3.6", "ncp": "^2.0.0", "node-sass": "^3.8.0", + "postcss-loader": "^0.13.0", "react": "^15.3.0", "react-dom": "^15.3.0", "react-redux": "^4.4.5", diff --git a/webpack.config.js b/webpack.config.js index 3b6726a..447595f 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -2,6 +2,7 @@ var debug = process.env.NODE_ENV !== "production"; var webpack = require('webpack'); var path = require('path'); var HtmlWebpackPlugin = require('html-webpack-plugin'); +var autoprefixer = require('autoprefixer'); module.exports = { devtool: debug ? "inline-sourcemap" : null, @@ -17,7 +18,7 @@ module.exports = { plugins: ['react-html-attrs', 'transform-class-properties', 'transform-decorators-legacy'], } }, - { test: /\.scss$/, loader: "style-loader!css-loader!sass-loader"}, + { test: /\.scss$/, loader: "style-loader!css-loader!postcss-loader!sass-loader"}, { test: /\.css$/, loader: "style-loader!css-loader" }, { test: /\.png$/, loader: "url-loader?limit=100000&name=images/[hash].[ext]" }, { test: /\.jpg$/, loader: "url-loader?limit=100000&name=images/[hash].[ext]" }, @@ -32,6 +33,7 @@ module.exports = { } ] }, + postcss: function(){ return [autoprefixer]}, output: { path: __dirname + "/public/", publicPath: "/public/", From 2f45864fcc1be1d26e9e0a30c8ad6171e6ef1f33 Mon Sep 17 00:00:00 2001 From: mgerb42 Date: Wed, 14 Sep 2016 20:12:41 +0000 Subject: [PATCH 06/13] adjusted end points again --- server/controller/api/sensor.go | 16 ++++++++++- server/model/daily_sensor/daily_sensor.go | 33 ++++++++++++----------- server/model/raw_sensor/raw_sensor.go | 11 +++++--- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/server/controller/api/sensor.go b/server/controller/api/sensor.go index 03ff980..5fefa2d 100644 --- a/server/controller/api/sensor.go +++ b/server/controller/api/sensor.go @@ -177,7 +177,21 @@ func HandleUniqueDates(w http.ResponseWriter, r *http.Request, ps httprouter.Par s, err := daily_sensor.GetUniqueSensorDates(location) - response := createResponse(s, err) + var response string + + if err != nil { + log.Println(err) + response = "{message : \"Error loading data from database\"" + } else { + js, err := json.MarshalIndent(s, "", " ") + + if err != nil { + log.Println(err) + response = "{message : \"Error loading data from database\"" + } else { + response = string(js) + } + } fmt.Fprint(w, response) } diff --git a/server/model/daily_sensor/daily_sensor.go b/server/model/daily_sensor/daily_sensor.go index 4b45a29..8fd03a0 100644 --- a/server/model/daily_sensor/daily_sensor.go +++ b/server/model/daily_sensor/daily_sensor.go @@ -203,14 +203,25 @@ func GetAllSensorInfoByMonth(sensor_location string, year int, monthname string) //I need to find a better implementation of this //MongoDB $addToSet creates an array of objecta //this ends up being a different type than the Data struct above -//it would be nice to make all MongoDB queries load directly into a Data struct +//it would be nice to make all MongoDB queries load directly into a Data struct +/* type UniqueDates struct{ Dates []Data `json:"dates" bson:"dates"` } +*/ -func GetUniqueSensorDates(sensor_location string) ([]Data, error){ - d := []Data{} - //temp := UniqueDates{}; +type Years struct { + Year int `json:"year", bson:"year"` + Months []Month `json:"months", bson:"months"` +} + +type Month struct { + Month int `json:"month", bson:"month"` + MonthName string `json:"monthname", bson:"monthname"` +} + +func GetUniqueSensorDates(sensor_location string) ([]Years, error){ + d := []Years{} if db.Mongo.Connected() == true { @@ -220,19 +231,11 @@ func GetUniqueSensorDates(sensor_location string) ([]Data, error){ c := session.DB(db.Mongo.Info.Database).C(collection) err := c.Pipe([]bson.M{bson.M{"$match": bson.M{"location": sensor_location}}, - {"$group": bson.M{"_id": "null", "dates": bson.M{"$addToSet": bson.M{"month": "$month", "monthname": "$monthname", "year": "$year"}}}}, - {"$unwind": "$dates"}, - {"$project": bson.M{"_id": 0, "month": "$dates.month", "monthname": "$dates.monthname", "year": "$dates.year"}}, - {"$sort": bson.M{"year": 1, "month": 1}}, + bson.M{"$group": bson.M{"_id": "$year", "months": bson.M{"$addToSet": bson.M{"month": "$month", "monthname": "$monthname"}}}}, + bson.M{"$project": bson.M{"year": "$_id", "months": "$months"}}, }).All(&d) - //d = temp.Dates; - - test12, _ := json.MarshalIndent(d, "", " ") - - log.Println(string(test12)) - if err != nil { log.Println(err) return d, nil @@ -243,4 +246,4 @@ func GetUniqueSensorDates(sensor_location string) ([]Data, error){ } else { return d, errors.New("Query failed") } -} +} \ No newline at end of file diff --git a/server/model/raw_sensor/raw_sensor.go b/server/model/raw_sensor/raw_sensor.go index 9b91b54..560fda8 100644 --- a/server/model/raw_sensor/raw_sensor.go +++ b/server/model/raw_sensor/raw_sensor.go @@ -59,9 +59,10 @@ func (s *Data) StoreData() error { //handle queries for all sensors page type DataStore_AllSensors struct { - ID string `json:"location" bson:"_id"` - Temperature float64 `json:"temperature" bson:"temperature"` - Updated time.Time `json:"updated" bson:"updated"` + ID bson.ObjectId `bson:"_id,omitempty"` + Location string `json:"location", bson:"location"` + Temperature float64 `json:"temperature" bson:"temperature"` + Updated time.Time `json:"updated" bson:"updated"` } //get latest update from each unique sensor @@ -78,7 +79,9 @@ func GetAllSensors() ([]DataStore_AllSensors, error) { err := c.Pipe([]bson.M{{"$group": bson.M{"_id": "$location", "temperature": bson.M{"$last": "$temperature"}, "updated": bson.M{"$last": "$updated"}}}, - bson.M{"$sort": bson.M{"_id": 1}}}).All(&s) + bson.M{"$sort": bson.M{"_id": 1}}, + bson.M{"$project": bson.M{"location": "$_id", "temperature": "$temperature", "updated": "$updated"}}, + }).All(&s) if err != nil { return s, nil From e03b3eae256fda934a7bd40c1a280db96ac9baa5 Mon Sep 17 00:00:00 2001 From: mgerb42 Date: Wed, 14 Sep 2016 20:44:04 +0000 Subject: [PATCH 07/13] redux functionality for sensor page --- client/js/components/sensors/SensorInfo.js | 54 ++++++++++++++-------- client/js/redux/actions/sensor.js | 22 ++++++++- client/js/redux/constants/sensor.js | 6 ++- client/js/redux/reducers/sensor.js | 13 ++++++ 4 files changed, 75 insertions(+), 20 deletions(-) diff --git a/client/js/components/sensors/SensorInfo.js b/client/js/components/sensors/SensorInfo.js index c45bd2f..84b46e3 100644 --- a/client/js/components/sensors/SensorInfo.js +++ b/client/js/components/sensors/SensorInfo.js @@ -1,34 +1,52 @@ import React from 'react'; -let location, sensor, actions, uniqueDates; +let location, sensor, actions, uniqueDates, fetchedAll; export default class SensorInfo extends React.Component{ componentDidMount(){ location = this.props.params.location; - actions = this.props.sensorActions; - sensor = this.props.sensor; - - actions.fetchUniqueDates(location); - - /* - this.props.sensorActions.fetchSensorInfoYear('Grand Meadow', '2016'); - this.props.sensorActions.fetchSensorInfoMonth('Grand Meadow', '2016', 'May'); - this.props.sensorActions.fetchUniqueDates('Grand Meadow'); - */ + this.props.sensorActions.fetchUniqueDates(location); } - componentWillReceiveProps(){ - if(sensor.fetchedUniqueDates){ - uniqueDates = sensor.uniqueDates; - - //!sensor.fetchedInfoMonth ? actions.fetchSensorInfoMonth(location, ) - } + loadYearOptions = (date, index) => { + return ( + + ); + } + + loadMonthOptions = (date, index) => { + return ( + + ); + } + + onYearChange(event){ + this.props.sensorActions.setSelectedYearIndex(parseInt(event.target.value)); + } + + onMonthChange(event){ + this.props.sensorActions.setSelectedMonthIndex(parseInt(event.target.value)); } render(){ + sensor = this.props.sensor; return( -
Test123
+
+ + + +
); } } \ No newline at end of file diff --git a/client/js/redux/actions/sensor.js b/client/js/redux/actions/sensor.js index 3467e8d..3394c55 100644 --- a/client/js/redux/actions/sensor.js +++ b/client/js/redux/actions/sensor.js @@ -29,6 +29,20 @@ function loadUniqueDates(dates){ } } +export function setSelectedYearIndex(index){ + return{ + type: types.SET_SELECTED_YEAR_INDEX, + index + } +} + +export function setSelectedMonthIndex(index){ + return{ + type: types.SET_SELECTED_MONTH_INDEX, + index + } +} + function fetchingList(){ return { type: types.FETCHING_LIST @@ -102,9 +116,15 @@ export function fetchUniqueDates(location){ .then(response => response.json()) .then(json => { dispatch(loadUniqueDates(json)); + if(json.length > 0){ + let year = json[0].year; + let month = json[0].months[0].monthname; + dispatch(fetchSensorInfoYear(location, year)); + dispatch(fetchSensorInfoMonth(location, year, month)); + } }) .catch(error => { console.log(error); }); } -} \ No newline at end of file +} diff --git a/client/js/redux/constants/sensor.js b/client/js/redux/constants/sensor.js index 39587d0..a277743 100644 --- a/client/js/redux/constants/sensor.js +++ b/client/js/redux/constants/sensor.js @@ -8,4 +8,8 @@ export const LOAD_UNIQUE_DATES = 'LOAD_UNIQUE_DATES'; export const FETCHING_LIST = 'FETCHING_LIST'; export const FETCHING_INFO_YEAR = 'FETCHING_INFO_YEAR'; export const FETCHING_INFO_MONTH = 'FETCHING_INFO_MONTH'; -export const FETCHING_UNIQUE_DATES = 'FETCHING_UNIQUE_DATES'; \ No newline at end of file +export const FETCHING_UNIQUE_DATES = 'FETCHING_UNIQUE_DATES'; + +//indexes +export const SET_SELECTED_YEAR_INDEX = 'SET_SELECTED_YEAR_INDEX'; +export const SET_SELECTED_MONTH_INDEX = 'SET_SELECTED_MONTH_INDEX'; \ No newline at end of file diff --git a/client/js/redux/reducers/sensor.js b/client/js/redux/reducers/sensor.js index 3b28d23..5d74606 100644 --- a/client/js/redux/reducers/sensor.js +++ b/client/js/redux/reducers/sensor.js @@ -8,6 +8,9 @@ const defaultState = { infoYear: [], uniqueDates: {}, + selectedYearIndex: 0, + selectedMonthIndex: 0, + fetchingList: false, fetchingInfoMonth: false, fetchingInfoYear: false, @@ -69,6 +72,16 @@ export default function app(state = defaultState, action) { fetchingUniqueDates: false, fetchedUniqueDates: true }); + + //indexes + case types.SET_SELECTED_YEAR_INDEX: + return Object.assign({}, state, { + selectedYearIndex: action.index + }); + case types.SET_SELECTED_MONTH_INDEX: + return Object.assign({}, state, { + selectedMonthIndex: action.index + }); } //return present state if no actions get called return state; From 922e3c9cef1529efdb5c2a1d64a51b290cefc93a Mon Sep 17 00:00:00 2001 From: mgerb42 Date: Thu, 15 Sep 2016 20:36:43 +0000 Subject: [PATCH 08/13] more work on charts --- client/assets/scss/Content.scss | 1 + client/js/components/sensors/SensorInfo.js | 122 ++++++++++++++----- client/js/components/sensors/SensorInfo.scss | 15 +++ client/js/redux/actions/sensor.js | 30 ++--- client/js/redux/constants/sensor.js | 6 +- client/js/redux/reducers/sensor.js | 34 ++---- package.json | 2 + 7 files changed, 128 insertions(+), 82 deletions(-) create mode 100644 client/js/components/sensors/SensorInfo.scss diff --git a/client/assets/scss/Content.scss b/client/assets/scss/Content.scss index 9c41fdf..fa8132f 100644 --- a/client/assets/scss/Content.scss +++ b/client/assets/scss/Content.scss @@ -2,6 +2,7 @@ flex: 1; flex-wrap: wrap; min-width: 0; + min-height: 500px; .post+ .post { margin-top: 2em; } diff --git a/client/js/components/sensors/SensorInfo.js b/client/js/components/sensors/SensorInfo.js index 84b46e3..2f8663e 100644 --- a/client/js/components/sensors/SensorInfo.js +++ b/client/js/components/sensors/SensorInfo.js @@ -1,52 +1,110 @@ import React from 'react'; +import Loading from '../utils/Loading'; +import { + LineChart, + Line, + XAxis, + YAxis, + CartesianGrid, + Tooltip, + Legend +} +from 'recharts'; -let location, sensor, actions, uniqueDates, fetchedAll; +import './SensorInfo.scss'; -export default class SensorInfo extends React.Component{ - - componentDidMount(){ - location = this.props.params.location; +export default class SensorInfo extends React.Component { + + componentDidMount() { + let location = this.props.params.location; this.props.sensorActions.fetchUniqueDates(location); } - + loadYearOptions = (date, index) => { return ( ); } - + loadMonthOptions = (date, index) => { return ( ); } - - onYearChange(event){ - this.props.sensorActions.setSelectedYearIndex(parseInt(event.target.value)); + + onChange(event, type) { + let location = this.props.params.location, + sensor = this.props.sensor, + actions = this.props.sensorActions, + yearIndex = sensor.selectedYearIndex, + monthIndex = sensor.selectedMonthIndex; + + if (type === 'year') { + yearIndex = parseInt(event.target.value); + monthIndex = 0; + } + else if (type === 'month') { + monthIndex = parseInt(event.target.value); + } + + let year = sensor.uniqueDates[yearIndex].year; + let monthname = sensor.uniqueDates[yearIndex].months[monthIndex].monthname; + + actions.setSelectedMonthIndex(monthIndex); + actions.setSelectedYearIndex(yearIndex); + this.props.sensorActions.fetchSensorInfoMonth(location, year, monthname); + } + + filterData(data) { + let filteredData = []; + + for (let d of data) { + filteredData.push({ + name: d.day, + max: d.maxtemp, + min: d.mintemp + }); + } + + return filteredData; } - onMonthChange(event){ - this.props.sensorActions.setSelectedMonthIndex(parseInt(event.target.value)); - } - - render(){ - sensor = this.props.sensor; - return( -
- - - + render() { + let sensor = this.props.sensor; + let data = this.filterData(sensor.info); + + return ( +
+
+ + + +
+
+ {sensor.fetchedInfo ? + + + + + + + + + + : } +
- ); + ); } } \ No newline at end of file diff --git a/client/js/components/sensors/SensorInfo.scss b/client/js/components/sensors/SensorInfo.scss new file mode 100644 index 0000000..6b3016c --- /dev/null +++ b/client/js/components/sensors/SensorInfo.scss @@ -0,0 +1,15 @@ +.SensorInfo{ + flex: 1; + display: flex; + flex-direction: column; + justify-content: center; + + .selector-row{ + display: flex; + justify-content: center; + } + + .recharts-wrapper{ + flex: 1; + } +} \ No newline at end of file diff --git a/client/js/redux/actions/sensor.js b/client/js/redux/actions/sensor.js index 3394c55..cd2f74d 100644 --- a/client/js/redux/actions/sensor.js +++ b/client/js/redux/actions/sensor.js @@ -8,16 +8,9 @@ function loadSensorList(sensor_list){ } } -function loadSensorInfoYear(sensor_info){ +function loadSensorInfo(sensor_info){ return{ - type: types.LOAD_SENSOR_INFO_YEAR, - sensor_info - } -} - -function loadSensorInfoMonth(sensor_info){ - return{ - type: types.LOAD_SENSOR_INFO_MONTH, + type: types.LOAD_SENSOR_INFO, sensor_info } } @@ -49,15 +42,9 @@ function fetchingList(){ } } -function fetchingInfoYear(){ +function fetchingInfo(){ return { - type: types.FETCHING_INFO_YEAR - } -} - -function fetchingInfoMonth(){ - return { - type: types.FETCHING_INFO_MONTH + type: types.FETCHING_INFO } } @@ -83,11 +70,11 @@ export function fetchSensorList(){ export function fetchSensorInfoYear(location, year){ return (dispatch) => { - dispatch(fetchingInfoYear()); + dispatch(fetchingInfo()); return fetch(`/api/sensor/${location}/${year}`) .then(response => response.json()) .then(json => { - dispatch(loadSensorInfoYear(json)); + dispatch(loadSensorInfo(json)); }) .catch(error => { console.log(error); @@ -97,11 +84,11 @@ export function fetchSensorInfoYear(location, year){ export function fetchSensorInfoMonth(location, year, month){ return (dispatch) => { - dispatch(fetchingInfoMonth()); + dispatch(fetchingInfo()); return fetch(`/api/sensor/${location}/${year}/${month}`) .then(response => response.json()) .then(json => { - dispatch(loadSensorInfoMonth(json)); + dispatch(loadSensorInfo(json)); }) .catch(error => { console.log(error); @@ -119,7 +106,6 @@ export function fetchUniqueDates(location){ if(json.length > 0){ let year = json[0].year; let month = json[0].months[0].monthname; - dispatch(fetchSensorInfoYear(location, year)); dispatch(fetchSensorInfoMonth(location, year, month)); } }) diff --git a/client/js/redux/constants/sensor.js b/client/js/redux/constants/sensor.js index a277743..a23112b 100644 --- a/client/js/redux/constants/sensor.js +++ b/client/js/redux/constants/sensor.js @@ -1,13 +1,11 @@ //constants export const LOAD_SENSOR_LIST = 'LOAD_SENSOR_LIST'; -export const LOAD_SENSOR_INFO_YEAR = 'LOAD_SENSOR_INFO_YEAR'; -export const LOAD_SENSOR_INFO_MONTH = 'LOAD_SENSOR_INFO_MONTH'; +export const LOAD_SENSOR_INFO = 'LOAD_SENSOR_INFO'; export const LOAD_UNIQUE_DATES = 'LOAD_UNIQUE_DATES'; //fetching export const FETCHING_LIST = 'FETCHING_LIST'; -export const FETCHING_INFO_YEAR = 'FETCHING_INFO_YEAR'; -export const FETCHING_INFO_MONTH = 'FETCHING_INFO_MONTH'; +export const FETCHING_INFO = 'FETCHING_INFO_YEAR'; export const FETCHING_UNIQUE_DATES = 'FETCHING_UNIQUE_DATES'; //indexes diff --git a/client/js/redux/reducers/sensor.js b/client/js/redux/reducers/sensor.js index 5d74606..7fbfaa2 100644 --- a/client/js/redux/reducers/sensor.js +++ b/client/js/redux/reducers/sensor.js @@ -4,21 +4,18 @@ import * as types from '../constants/sensor'; //defaults - const defaultState = { list : [], - infoMonth: [], - infoYear: [], + info: [], uniqueDates: {}, selectedYearIndex: 0, selectedMonthIndex: 0, fetchingList: false, - fetchingInfoMonth: false, - fetchingInfoYear: false, + fetchingInfo: false, fetchingUniqueDates: false, fetchedList: false, - fetchedInfoMonth: false, - fetchedInfoYear: false, + fetchedInfo: false, fetchedUniqueDates: false }; @@ -31,15 +28,10 @@ export default function app(state = defaultState, action) { fetchingList: true, fetchedList: false }); - case types.FETCHING_INFO_MONTH: + case types.FETCHING_INFO: return Object.assign({}, state, { - fetchingInfoMonth: true, - fetchedInfoMonth: false - }); - case types.FETCHING_INFO_YEAR: - return Object.assign({}, state, { - fetchingInfoYear: true, - fetchedInfoYear: false + fetchingInfo: true, + fetchedInfo: false }); case types:FETCHING_UNIQUE_DATES: return Object.assign({}, state, { @@ -54,17 +46,11 @@ export default function app(state = defaultState, action) { fetchingList: false, fetchedList: true }); - case types.LOAD_SENSOR_INFO_MONTH: + case types.LOAD_SENSOR_INFO: return Object.assign({}, state, { - infoMonth: action.sensor_info, - fetchingInfoMonth: false, - fetchedInfoMonth: true - }); - case types.LOAD_SENSOR_INFO_YEAR: - return Object.assign({}, state, { - infoYear: action.sensor_info, - fetchingInfoYear: false, - fetchedInfoYear: true + info: action.sensor_info, + fetchingInfo: false, + fetchedInfo: true }); case types.LOAD_UNIQUE_DATES: return Object.assign({}, state, { diff --git a/package.json b/package.json index 96412e7..ef7fd3b 100644 --- a/package.json +++ b/package.json @@ -48,10 +48,12 @@ "node-sass": "^3.8.0", "postcss-loader": "^0.13.0", "react": "^15.3.0", + "react-addons-transition-group": "^15.3.1", "react-dom": "^15.3.0", "react-redux": "^4.4.5", "react-router": "^2.6.1", "react-router-redux": "^4.0.5", + "recharts": "^0.14.1", "redux": "^3.5.2", "redux-logger": "^2.6.1", "redux-thunk": "^2.1.0", From 5e5db2698d1e97296ca716c8a2a54a00b9fb05b8 Mon Sep 17 00:00:00 2001 From: mgerb42 Date: Fri, 16 Sep 2016 19:02:38 +0000 Subject: [PATCH 09/13] almost finished with chart --- client/assets/scss/Content.scss | 1 - client/assets/scss/main.scss | 13 +++ client/js/components/sensors/SensorInfo.css | 15 ++++ .../js/components/sensors/SensorInfo.css.map | 7 ++ client/js/components/sensors/SensorInfo.js | 83 ++++++++----------- client/js/components/sensors/SensorInfo.scss | 17 ++-- client/js/components/sensors/chartOptions.js | 30 +++++++ client/js/redux/reducers/sensor.js | 2 +- package.json | 3 +- 9 files changed, 113 insertions(+), 58 deletions(-) create mode 100644 client/js/components/sensors/SensorInfo.css create mode 100644 client/js/components/sensors/SensorInfo.css.map create mode 100644 client/js/components/sensors/chartOptions.js diff --git a/client/assets/scss/Content.scss b/client/assets/scss/Content.scss index fa8132f..9c41fdf 100644 --- a/client/assets/scss/Content.scss +++ b/client/assets/scss/Content.scss @@ -2,7 +2,6 @@ flex: 1; flex-wrap: wrap; min-width: 0; - min-height: 500px; .post+ .post { margin-top: 2em; } diff --git a/client/assets/scss/main.scss b/client/assets/scss/main.scss index 25b126c..7095df4 100644 --- a/client/assets/scss/main.scss +++ b/client/assets/scss/main.scss @@ -55,6 +55,19 @@ hr { border-top: 1px solid #eee; } +select{ + background-color: #fff; + border: 1px solid #ccc; + border-radius: 0.2em; + height: 35px; + color: #555; + &:focus{ + border-color: #66afe9; + outline: 0; + box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6); + } +} + .Footer, .Main { display: flex; diff --git a/client/js/components/sensors/SensorInfo.css b/client/js/components/sensors/SensorInfo.css new file mode 100644 index 0000000..fa108b7 --- /dev/null +++ b/client/js/components/sensors/SensorInfo.css @@ -0,0 +1,15 @@ +.SensorInfo { + flex: 1; + display: flex; + flex-direction: column; + align-items: center; + flex-wrap: wrap; + min-width: 0; + width: 80%; } + .SensorInfo .selector-row { + margin-left: auto; + margin-right: auto; } + .SensorInfo .selector-row select + select { + margin-left: 5px; } + +/*# sourceMappingURL=SensorInfo.css.map */ diff --git a/client/js/components/sensors/SensorInfo.css.map b/client/js/components/sensors/SensorInfo.css.map new file mode 100644 index 0000000..fdb5015 --- /dev/null +++ b/client/js/components/sensors/SensorInfo.css.map @@ -0,0 +1,7 @@ +{ +"version": 3, +"mappings": "AAAA,WAAW;EACP,IAAI,EAAE,CAAC;EACP,OAAO,EAAE,IAAI;EACb,cAAc,EAAE,MAAM;EACtB,WAAW,EAAE,MAAM;EACnB,SAAS,EAAE,IAAI;EACf,SAAS,EAAE,CAAC;EACZ,KAAK,EAAE,GAAG;EACV,yBAAa;IACT,WAAW,EAAE,IAAI;IACjB,YAAY,EAAE,IAAI;IAClB,yCAAa;MACT,WAAW,EAAE,GAAG", +"sources": ["SensorInfo.scss"], +"names": [], +"file": "SensorInfo.css" +} \ No newline at end of file diff --git a/client/js/components/sensors/SensorInfo.js b/client/js/components/sensors/SensorInfo.js index 2f8663e..7265edb 100644 --- a/client/js/components/sensors/SensorInfo.js +++ b/client/js/components/sensors/SensorInfo.js @@ -1,18 +1,17 @@ import React from 'react'; import Loading from '../utils/Loading'; +import _chartjs from 'chart.js'; +import Chart from 'react-chartjs'; import { - LineChart, - Line, - XAxis, - YAxis, - CartesianGrid, - Tooltip, - Legend + Options, + Data } -from 'recharts'; +from './chartOptions'; import './SensorInfo.scss'; +const LineChart = Chart.Line; + export default class SensorInfo extends React.Component { componentDidMount() { @@ -20,6 +19,13 @@ export default class SensorInfo extends React.Component { this.props.sensorActions.fetchUniqueDates(location); } + componentWillReceiveProps(nextProps) { + let currentLocation = this.props.params.location, + nextLocation = nextProps.params.location; + + currentLocation !== nextLocation ? this.props.sensorActions.fetchUniqueDates(nextLocation) : null; + } + loadYearOptions = (date, index) => { return ( @@ -56,54 +62,37 @@ export default class SensorInfo extends React.Component { } filterData(data) { - let filteredData = []; + let temp = JSON.parse(JSON.stringify(Data)); for (let d of data) { - filteredData.push({ - name: d.day, - max: d.maxtemp, - min: d.mintemp - }); + let label = `${d.month}/${d.day}`; + temp.labels.push(label); + temp.datasets[0].data.push(d.maxtemp); + temp.datasets[1].data.push(d.mintemp); } - - return filteredData; + + return temp; } - + render() { let sensor = this.props.sensor; let data = this.filterData(sensor.info); - + return (
-
- - - -
-
- {sensor.fetchedInfo ? - - - - - - - - - - : } -
+ {sensor.fetchedUniqueDates ? +
+ + + +
+ : } + + {sensor.fetchedUniqueDates ? : null}
); } diff --git a/client/js/components/sensors/SensorInfo.scss b/client/js/components/sensors/SensorInfo.scss index 6b3016c..ce6f49c 100644 --- a/client/js/components/sensors/SensorInfo.scss +++ b/client/js/components/sensors/SensorInfo.scss @@ -2,14 +2,15 @@ flex: 1; display: flex; flex-direction: column; - justify-content: center; - + align-items: center; + min-width: 0; + width: 80%; .selector-row{ - display: flex; - justify-content: center; - } - - .recharts-wrapper{ - flex: 1; + margin-left: auto; + margin-right: auto; + margin-bottom: 1em; + select+select{ + margin-left: 5px; + } } } \ No newline at end of file diff --git a/client/js/components/sensors/chartOptions.js b/client/js/components/sensors/chartOptions.js new file mode 100644 index 0000000..42d1062 --- /dev/null +++ b/client/js/components/sensors/chartOptions.js @@ -0,0 +1,30 @@ +export const Options = { + responsive: true, + scaleOverride: true, + scaleSteps: 20, + scaleStartValue: 0, + scaleStepWidth: 5 +}; + +export let Data = { + labels: [], + datasets: [{ + label: "Max Temperature °F", + fillColor: "rgba(255,100,100,0)", + strokeColor: "rgba(255,100,100,1)", + pointColor: "rgba(255,100,100,1)", + pointStrokeColor: "#fff", + pointHighlightFill: "#fff", + pointHighlightStroke: "rgba(255,100,100,1)", + data: [] + }, { + label: "Min Temperature °F", + fillColor: "rgba(151,187,205,0)", + strokeColor: "rgba(151,187,205,1)", + pointColor: "rgba(151,187,205,1)", + pointStrokeColor: "#fff", + pointHighlightFill: "#fff", + pointHighlightStroke: "rgba(151,187,205,1)", + data: [] + }] +}; \ No newline at end of file diff --git a/client/js/redux/reducers/sensor.js b/client/js/redux/reducers/sensor.js index 7fbfaa2..bb32411 100644 --- a/client/js/redux/reducers/sensor.js +++ b/client/js/redux/reducers/sensor.js @@ -33,7 +33,7 @@ export default function app(state = defaultState, action) { fetchingInfo: true, fetchedInfo: false }); - case types:FETCHING_UNIQUE_DATES: + case types.FETCHING_UNIQUE_DATES: return Object.assign({}, state, { fetchingUniqueDates: true, fetchedUniqueDates: false diff --git a/package.json b/package.json index ef7fd3b..501ff0d 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "babel-preset-es2015": "^6.13.2", "babel-preset-react": "^6.11.1", "babel-preset-stage-0": "^6.5.0", + "chart.js": "^1.1.1", "css-loader": "^0.23.1", "exports-loader": "^0.6.3", "file-loader": "^0.9.0", @@ -49,11 +50,11 @@ "postcss-loader": "^0.13.0", "react": "^15.3.0", "react-addons-transition-group": "^15.3.1", + "react-chartjs": "^0.8.0", "react-dom": "^15.3.0", "react-redux": "^4.4.5", "react-router": "^2.6.1", "react-router-redux": "^4.0.5", - "recharts": "^0.14.1", "redux": "^3.5.2", "redux-logger": "^2.6.1", "redux-thunk": "^2.1.0", From d00d069744967ae7a441e8858092420da4bda986 Mon Sep 17 00:00:00 2001 From: mgerb42 Date: Fri, 16 Sep 2016 20:06:20 +0000 Subject: [PATCH 10/13] fixed end point ordering --- server/model/daily_sensor/daily_sensor.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/model/daily_sensor/daily_sensor.go b/server/model/daily_sensor/daily_sensor.go index 8fd03a0..0a80db1 100644 --- a/server/model/daily_sensor/daily_sensor.go +++ b/server/model/daily_sensor/daily_sensor.go @@ -233,6 +233,10 @@ func GetUniqueSensorDates(sensor_location string) ([]Years, error){ err := c.Pipe([]bson.M{bson.M{"$match": bson.M{"location": sensor_location}}, bson.M{"$group": bson.M{"_id": "$year", "months": bson.M{"$addToSet": bson.M{"month": "$month", "monthname": "$monthname"}}}}, bson.M{"$project": bson.M{"year": "$_id", "months": "$months"}}, + bson.M{"$unwind": "$months"}, + bson.M{"$sort": bson.M{"months.month": -1}}, + bson.M{"$group": bson.M{"_id": "$year", "months": bson.M{"$push": "$months"}}}, + bson.M{"$project": bson.M{"year": "$_id", "months": "$months"}}, }).All(&d) From 11a91412c1ff9f95b595f893cd11c65cb7b9ad59 Mon Sep 17 00:00:00 2001 From: mgerb42 Date: Fri, 16 Sep 2016 20:39:41 +0000 Subject: [PATCH 11/13] more chart --- client/assets/scss/main.scss | 1 - client/js/components/sensors/SensorInfo.css | 15 -------------- .../js/components/sensors/SensorInfo.css.map | 7 ------- client/js/components/sensors/SensorInfo.js | 15 ++++++++------ client/js/components/sensors/SensorInfo.scss | 6 +++--- client/js/components/sensors/chartOptions.js | 20 +++++++++---------- 6 files changed, 22 insertions(+), 42 deletions(-) delete mode 100644 client/js/components/sensors/SensorInfo.css delete mode 100644 client/js/components/sensors/SensorInfo.css.map diff --git a/client/assets/scss/main.scss b/client/assets/scss/main.scss index 7095df4..f2ffce6 100644 --- a/client/assets/scss/main.scss +++ b/client/assets/scss/main.scss @@ -25,7 +25,6 @@ h5, h6 { margin: 0; font-weight: 400; - line-height: 1em; } p { diff --git a/client/js/components/sensors/SensorInfo.css b/client/js/components/sensors/SensorInfo.css deleted file mode 100644 index fa108b7..0000000 --- a/client/js/components/sensors/SensorInfo.css +++ /dev/null @@ -1,15 +0,0 @@ -.SensorInfo { - flex: 1; - display: flex; - flex-direction: column; - align-items: center; - flex-wrap: wrap; - min-width: 0; - width: 80%; } - .SensorInfo .selector-row { - margin-left: auto; - margin-right: auto; } - .SensorInfo .selector-row select + select { - margin-left: 5px; } - -/*# sourceMappingURL=SensorInfo.css.map */ diff --git a/client/js/components/sensors/SensorInfo.css.map b/client/js/components/sensors/SensorInfo.css.map deleted file mode 100644 index fdb5015..0000000 --- a/client/js/components/sensors/SensorInfo.css.map +++ /dev/null @@ -1,7 +0,0 @@ -{ -"version": 3, -"mappings": "AAAA,WAAW;EACP,IAAI,EAAE,CAAC;EACP,OAAO,EAAE,IAAI;EACb,cAAc,EAAE,MAAM;EACtB,WAAW,EAAE,MAAM;EACnB,SAAS,EAAE,IAAI;EACf,SAAS,EAAE,CAAC;EACZ,KAAK,EAAE,GAAG;EACV,yBAAa;IACT,WAAW,EAAE,IAAI;IACjB,YAAY,EAAE,IAAI;IAClB,yCAAa;MACT,WAAW,EAAE,GAAG", -"sources": ["SensorInfo.scss"], -"names": [], -"file": "SensorInfo.css" -} \ No newline at end of file diff --git a/client/js/components/sensors/SensorInfo.js b/client/js/components/sensors/SensorInfo.js index 7265edb..50128af 100644 --- a/client/js/components/sensors/SensorInfo.js +++ b/client/js/components/sensors/SensorInfo.js @@ -3,8 +3,8 @@ import Loading from '../utils/Loading'; import _chartjs from 'chart.js'; import Chart from 'react-chartjs'; import { - Options, - Data + ChartOptions, + DataTemplate } from './chartOptions'; @@ -62,8 +62,9 @@ export default class SensorInfo extends React.Component { } filterData(data) { - let temp = JSON.parse(JSON.stringify(Data)); - + let temp = JSON.parse(JSON.stringify(DataTemplate)); + + console.log(temp); for (let d of data) { let label = `${d.month}/${d.day}`; temp.labels.push(label); @@ -77,11 +78,11 @@ export default class SensorInfo extends React.Component { render() { let sensor = this.props.sensor; let data = this.filterData(sensor.info); - return (
{sensor.fetchedUniqueDates ?
+

{this.props.params.location}

@@ -92,7 +93,9 @@ export default class SensorInfo extends React.Component {
: } - {sensor.fetchedUniqueDates ? : null} + {sensor.fetchedUniqueDates && sensor.fetchedInfo + ? + : null}
); } diff --git a/client/js/components/sensors/SensorInfo.scss b/client/js/components/sensors/SensorInfo.scss index ce6f49c..fe0d781 100644 --- a/client/js/components/sensors/SensorInfo.scss +++ b/client/js/components/sensors/SensorInfo.scss @@ -6,10 +6,10 @@ min-width: 0; width: 80%; .selector-row{ - margin-left: auto; - margin-right: auto; + display: flex; + justify-content: center; margin-bottom: 1em; - select+select{ + select{ margin-left: 5px; } } diff --git a/client/js/components/sensors/chartOptions.js b/client/js/components/sensors/chartOptions.js index 42d1062..f2bac62 100644 --- a/client/js/components/sensors/chartOptions.js +++ b/client/js/components/sensors/chartOptions.js @@ -1,21 +1,21 @@ -export const Options = { +export const ChartOptions = { responsive: true, - scaleOverride: true, - scaleSteps: 20, - scaleStartValue: 0, - scaleStepWidth: 5 + // scaleOverride: true, + //scaleSteps: 20, + // scaleStartValue: 0, + //scaleStepWidth: 5 }; -export let Data = { +export let DataTemplate = { labels: [], datasets: [{ label: "Max Temperature °F", - fillColor: "rgba(255,100,100,0)", - strokeColor: "rgba(255,100,100,1)", - pointColor: "rgba(255,100,100,1)", + fillColor: "rgba(220,220,220,0.2)", + strokeColor: "rgba(220,220,220,1)", + pointColor: "rgba(220,220,220,1)", pointStrokeColor: "#fff", pointHighlightFill: "#fff", - pointHighlightStroke: "rgba(255,100,100,1)", + pointHighlightStroke: "rgba(220,220,220,1)", data: [] }, { label: "Min Temperature °F", From 87d941804ae4affaa289d7484b34cc76f5e32f8d Mon Sep 17 00:00:00 2001 From: mgerb42 Date: Sun, 18 Sep 2016 17:13:21 +0000 Subject: [PATCH 12/13] getting ready to ship --- client/assets/scss/Content.scss | 2 ++ client/assets/scss/Footer.scss | 9 +++++++++ client/assets/scss/Header.scss | 12 ++++++++++++ client/assets/scss/main.scss | 14 -------------- client/js/components/Footer.js | 2 +- client/js/components/Header.js | 2 ++ client/js/components/sensors/SensorInfo.js | 13 +++++++------ client/js/components/sensors/SensorInfo.scss | 3 ++- client/js/components/sensors/SensorList.js | 7 ++++++- client/js/components/sensors/SensorList.scss | 7 +++++++ client/js/components/utils/AboutMe.js | 8 +++++++- client/js/redux/actions/sensor.js | 5 +++++ client/js/redux/store.js | 5 ++++- package.json | 4 ++-- 14 files changed, 66 insertions(+), 27 deletions(-) create mode 100644 client/assets/scss/Header.scss diff --git a/client/assets/scss/Content.scss b/client/assets/scss/Content.scss index 9c41fdf..e854a2b 100644 --- a/client/assets/scss/Content.scss +++ b/client/assets/scss/Content.scss @@ -2,6 +2,7 @@ flex: 1; flex-wrap: wrap; min-width: 0; + min-height: 600px; .post+ .post { margin-top: 2em; } @@ -14,6 +15,7 @@ width: 7em; text-align: right; margin-left: -8em; + line-height: 2.5em; } } .intro { diff --git a/client/assets/scss/Footer.scss b/client/assets/scss/Footer.scss index 061b49d..4075b42 100644 --- a/client/assets/scss/Footer.scss +++ b/client/assets/scss/Footer.scss @@ -7,4 +7,13 @@ border-color: #DADADA; font-weight: 300; margin-top: 1em; + + display: flex; + padding-right: calc(50% - 997px / 2); + padding-left: calc(50% - 997px / 2); + &:after, + &:before { + content: " "; + width: 1em; + } } diff --git a/client/assets/scss/Header.scss b/client/assets/scss/Header.scss new file mode 100644 index 0000000..cad250d --- /dev/null +++ b/client/assets/scss/Header.scss @@ -0,0 +1,12 @@ +.Header { + width: 100%; + background: url("../images/header.jpg"); + background-size: cover; + height: 30em; + border-bottom: solid; + border-width: 1px; + border-color: #DADADA; + h1 { + text-align: center; + } +} \ No newline at end of file diff --git a/client/assets/scss/main.scss b/client/assets/scss/main.scss index f2ffce6..d9994ca 100644 --- a/client/assets/scss/main.scss +++ b/client/assets/scss/main.scss @@ -67,7 +67,6 @@ select{ } } -.Footer, .Main { display: flex; padding-right: calc(50% - 997px / 2); @@ -83,19 +82,6 @@ select{ padding-top: 1em; } -.Header { - width: 100%; - background: url("../images/header.jpg"); - background-size: cover; - height: 30em; - border-bottom: solid; - border-width: 1px; - border-color: #DADADA; - h1 { - text-align: center; - } -} - .Loading { display: flex; flex: 1; diff --git a/client/js/components/Footer.js b/client/js/components/Footer.js index 068eea4..f56f106 100644 --- a/client/js/components/Footer.js +++ b/client/js/components/Footer.js @@ -7,7 +7,7 @@ export default class Footer extends React.Component { render() { return ( ); } diff --git a/client/js/components/Header.js b/client/js/components/Header.js index 491e357..0257a8b 100644 --- a/client/js/components/Header.js +++ b/client/js/components/Header.js @@ -1,6 +1,8 @@ import React from 'react'; import {bubble} from '../../assets/js/bubble'; +import '../../assets/scss/Header.scss'; + export default class Header extends React.Component { componentDidMount() { bubble(); diff --git a/client/js/components/sensors/SensorInfo.js b/client/js/components/sensors/SensorInfo.js index 50128af..14b94c8 100644 --- a/client/js/components/sensors/SensorInfo.js +++ b/client/js/components/sensors/SensorInfo.js @@ -14,18 +14,20 @@ const LineChart = Chart.Line; export default class SensorInfo extends React.Component { - componentDidMount() { + componentWillMount() { let location = this.props.params.location; this.props.sensorActions.fetchUniqueDates(location); } - componentWillReceiveProps(nextProps) { + componentWillUpdate(nextProps) { let currentLocation = this.props.params.location, nextLocation = nextProps.params.location; - - currentLocation !== nextLocation ? this.props.sensorActions.fetchUniqueDates(nextLocation) : null; + + if (currentLocation !== nextLocation){ + this.props.sensorActions.fetchUniqueDates(nextLocation); + } } - + loadYearOptions = (date, index) => { return ( @@ -64,7 +66,6 @@ export default class SensorInfo extends React.Component { filterData(data) { let temp = JSON.parse(JSON.stringify(DataTemplate)); - console.log(temp); for (let d of data) { let label = `${d.month}/${d.day}`; temp.labels.push(label); diff --git a/client/js/components/sensors/SensorInfo.scss b/client/js/components/sensors/SensorInfo.scss index fe0d781..8257112 100644 --- a/client/js/components/sensors/SensorInfo.scss +++ b/client/js/components/sensors/SensorInfo.scss @@ -4,11 +4,12 @@ flex-direction: column; align-items: center; min-width: 0; + min-height: 600px; width: 80%; .selector-row{ display: flex; justify-content: center; - margin-bottom: 1em; + margin-bottom: 2em; select{ margin-left: 5px; } diff --git a/client/js/components/sensors/SensorList.js b/client/js/components/sensors/SensorList.js index afdd47a..e55db14 100644 --- a/client/js/components/sensors/SensorList.js +++ b/client/js/components/sensors/SensorList.js @@ -35,7 +35,12 @@ export default class SensorList extends React.Component {

{sensor.location}

- Updated: {date.toLocaleString('en-us', options)} + Updated: {date.toLocaleString('en-us', options)} + {Date.now() - date < 420000 + ? Connected + : Disconnected + } +
); diff --git a/client/js/components/sensors/SensorList.scss b/client/js/components/sensors/SensorList.scss index 758923a..0f95e13 100644 --- a/client/js/components/sensors/SensorList.scss +++ b/client/js/components/sensors/SensorList.scss @@ -25,4 +25,11 @@ } } + .connected{ + color: green; + } + .disconnected{ + color: red; + } + } \ No newline at end of file diff --git a/client/js/components/utils/AboutMe.js b/client/js/components/utils/AboutMe.js index f9dd82d..fd4588f 100644 --- a/client/js/components/utils/AboutMe.js +++ b/client/js/components/utils/AboutMe.js @@ -1,4 +1,5 @@ import React from 'react'; +import {Link} from 'react-router'; import me from '../../../assets/images/me.jpg'; @@ -12,7 +13,10 @@ export default class AboutMe extends React.Component{

My name is Mitchell and I have a passion for software development. I am currently a software engineer and enjoy working on personal projects in my free time.

- +

+ + Home +

eMail @@ -25,10 +29,12 @@ export default class AboutMe extends React.Component{ GitHub

+ {/*

Resume

+ */}
); } diff --git a/client/js/redux/actions/sensor.js b/client/js/redux/actions/sensor.js index cd2f74d..b97c5f2 100644 --- a/client/js/redux/actions/sensor.js +++ b/client/js/redux/actions/sensor.js @@ -96,9 +96,14 @@ export function fetchSensorInfoMonth(location, year, month){ } } +//this is called to initialize the sensor info page +//reloads unique dates and resets indexes +//then fetches new data for chart export function fetchUniqueDates(location){ return (dispatch) => { dispatch(fetchingUniqueDates()); + dispatch(setSelectedMonthIndex(0)); + dispatch(setSelectedYearIndex(0)); return fetch(`/api/uniquedates/${location}`) .then(response => response.json()) .then(json => { diff --git a/client/js/redux/store.js b/client/js/redux/store.js index b28f24c..3e62523 100644 --- a/client/js/redux/store.js +++ b/client/js/redux/store.js @@ -6,7 +6,10 @@ import {syncHistoryWithStore} from 'react-router-redux'; import reducers from './reducers/reducers'; -const middleware = applyMiddleware(thunk, logger()); +const debug = process.env.NODE_ENV !== "production"; + +//run redux logger if we are in dev mode +const middleware = debug ? applyMiddleware(thunk, logger()) : applyMiddleware(thunk); //create the new store with default state as an empty object const store = createStore(reducers, {}, middleware); diff --git a/package.json b/package.json index 501ff0d..d9969dd 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,8 @@ "deploy": "npm run get_dependencies && npm run prod && ./mywebsite", "dev": "webpack-dev-server --content-base public --inline --hot --history-api-fallback", "get_dependencies": "go get ./server && npm install", - "prod": "export NODE_ENV=production && webpack -p && babel-node metadata.js && go build ./server/mywebsite.go", - "prod-win": "set NODE_ENV=production && webpack -p && babel-node metadata.js && go build ./server/mywebsite.go", + "prod": "export NODE_ENV=production && webpack -p --define process.env.NODE_ENV='\"production\"' --progress --colors && babel-node metadata.js && go build ./server/mywebsite.go", + "prod-win": "set NODE_ENV=production && webpack -p --define process.env.NODE_ENV='\"production\"' --progress --colors && babel-node metadata.js && go build ./server/mywebsite.go", "watch": "webpack --watch --colors --progress" }, "repository": { From b5c75465795c2d0892d9924a21f4c30e9d4671fb Mon Sep 17 00:00:00 2001 From: mgerb42 Date: Sun, 18 Sep 2016 18:15:30 +0000 Subject: [PATCH 13/13] fixed css --- client/js/components/sensors/SensorInfo.js | 5 +++++ client/js/components/sensors/SensorInfo.scss | 3 +++ client/js/components/sensors/SensorList.js | 4 ++-- client/js/components/sensors/SensorList.scss | 7 ++++++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/client/js/components/sensors/SensorInfo.js b/client/js/components/sensors/SensorInfo.js index 14b94c8..f1e35f7 100644 --- a/client/js/components/sensors/SensorInfo.js +++ b/client/js/components/sensors/SensorInfo.js @@ -1,4 +1,6 @@ import React from 'react'; +import {Link} from 'react-router'; + import Loading from '../utils/Loading'; import _chartjs from 'chart.js'; import Chart from 'react-chartjs'; @@ -97,6 +99,9 @@ export default class SensorInfo extends React.Component { {sensor.fetchedUniqueDates && sensor.fetchedInfo ? : null} + {sensor.fetchedUniqueDates && sensor.fetchedInfo + ?
Home
+ : null} ); } diff --git a/client/js/components/sensors/SensorInfo.scss b/client/js/components/sensors/SensorInfo.scss index 8257112..9045ded 100644 --- a/client/js/components/sensors/SensorInfo.scss +++ b/client/js/components/sensors/SensorInfo.scss @@ -14,4 +14,7 @@ margin-left: 5px; } } + .home{ + margin-top: 1em; + } } \ No newline at end of file diff --git a/client/js/components/sensors/SensorList.js b/client/js/components/sensors/SensorList.js index e55db14..b83029c 100644 --- a/client/js/components/sensors/SensorList.js +++ b/client/js/components/sensors/SensorList.js @@ -30,10 +30,10 @@ export default class SensorList extends React.Component { return (
{this.openLink(sensor.location)}}> -
+

{sensor.temperature}°f

-
+

{sensor.location}

Updated: {date.toLocaleString('en-us', options)} {Date.now() - date < 420000 diff --git a/client/js/components/sensors/SensorList.scss b/client/js/components/sensors/SensorList.scss index 0f95e13..ba5f99d 100644 --- a/client/js/components/sensors/SensorList.scss +++ b/client/js/components/sensors/SensorList.scss @@ -12,8 +12,13 @@ background-color: #D1D1D1; } - .item + .item{ + .temperature{ + flex: .5; + } + + .info{ margin-left: 1em; + flex: 1; } h2{