forked from FarmBot/Farmbot-Web-App
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a588a4
commit a3c7489
Showing
423 changed files
with
159 additions
and
3,332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
To get started, <a href="https://www.clahub.com/agreements/FarmBot/Farmbot-Web-API">sign the Contributor License Agreement</a>. | ||
To get started, <a href="https://www.clahub.com/agreements/FarmBot/farmbot-web-frontend">sign the Contributor License Agreement</a>. |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
web: bin/rails server -p $PORT -e $RAILS_ENV | ||
worker: worker bundle exec rake jobs:work | ||
webpack: ./frontend/node_modules/webpack/bin/webpack.js --config frontend/tools/webpack.config.dev.js | ||
worker: bundle exec rake jobs:work | ||
webpack: ./node_modules/webpack/bin/webpack.js --config tools/webpack.config.dev.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,130 +1,63 @@ | ||
[](https://codeclimate.com/github/FarmBot/farmbot-web-app) | ||
[](https://codeclimate.com/github/FarmBot/farmbot-web-app) | ||
[](https://travis-ci.org/FarmBot/farmbot-web-frontend) | ||
[](https://codebeat.co/projects/github-com-rickcarlino-farmbot-web-frontend-master) | ||
[](https://coveralls.io/github/FarmBot/farmbot-web-frontend?branch=master) (we're working on it) | ||
# Do I need this? | ||
|
||
# Q: Do I need this? | ||
This repository is intended for *software developers* who wish to modify the frontend of the FarmBot Web App or host it on their own server. **If you are not a developer**, you are highly encouraged to use the free hosted web app at [my.farmbot.io](http://my.farmbot.io/). | ||
|
||
This repository is intended for *software developers* who wish to modify the [Farmbot Web App](http://my.farmbot.io/). **If you are not a developer**, you are highly encouraged to use [the publicly available web app](http://my.farmbot.io/). Running a server is a non-trivial task which will require an intermediate background in Ruby, SQL and Linux system administration. | ||
If you would like to report a problem with the web app, please [submit an issue](https://github.com/FarmBot/farmbot-web-frontend/issues/new). | ||
|
||
If you are a developer interested in contributing or would like to provision your own server, you are in the right place. | ||
# FarmBot Web Frontend | ||
|
||
# Q: What is the Farmbot Web API? | ||
This is the Javascript / HTML / CSS of the FarmBot web app. It depends on a [backend API](https://github.com/FarmBot/Farmbot-Web-API) (my.farmbot.io by default). | ||
|
||
This Repo is the RESTful JSON API for Farmbot. This includes things like storage of user data, plant data, authorization tokens and a variety of other resources. | ||
# Developer Setup | ||
|
||
The key responsibility of the API is *information and permissions management*. This should not be confused with device control, which is done via [MQTT](https://github.com/FarmBot/mqtt-gateway). | ||
**[LATEST STABLE VERSION IS HERE](https://github.com/FarmBot/farmbot-web-frontend/releases)** :star: :star: :star: | ||
|
||
# Q: Can I see some example API requests? | ||
0. [Install node](https://nodejs.org/en/download/) if you haven't already. | ||
1. [Install Google Chrome](https://www.google.com/chrome/) for best app experience. | ||
2. `git clone https://github.com/FarmBot/farmbot-web-frontend.git` | ||
3. `cd farmbot-web-frontend` | ||
4. `npm install` | ||
5. `npm start` | ||
6. Visit `http://localhost:8080/` | ||
|
||
For a list of example API requests and responses, see our [reference documentation](https://gist.github.com/RickCarlino/10db2df375d717e9efdd3c2d9d8932af). If you wish to write an add-on application that uses the FarmBot API, please let us know in an issue. We are happy to answer any specific questions you may have. | ||
# Deploy to Production | ||
|
||
# Q: How do I Setup an API locally? | ||
**NOTE:** The [Web API](https://github.com/FarmBot/Farmbot-Web-API) deployment will automatically build the latest version of the frontend and mount it in the web server. The instructions below are intended for reference purposes, or for users who wish to host their frontend code on a different server than their API. | ||
|
||
## Prerequisites | ||
1. (optional, usually not needed) If you have an NPM module that needs to get baked into the build, pass the NPM modules name in as `NPM_ADDON=foo` | ||
2. run `npm run build` | ||
3. Copy the contents of `/app` into your webserver and it will be accessible via `/`. | ||
4. Visit `/` on your web server to verify installation. | ||
5. [Submit an issue](https://github.com/FarmBot/farmbot-web-frontend/issues/new?title=Installation%20Failure) if you hit problems during the installation. | ||
|
||
Your machine will need the following: | ||
# Debugging external devices (DEV ONLY) | ||
|
||
0. A Linux or Mac based machine. We do not support windows at this time. | ||
0. [Ruby 2.3.3](http://rvm.io/rvm/install) | ||
1. [ImageMagick](https://www.imagemagick.org/script/index.php) (`brew install imagemagick` (Mac) or `sudo apt-get install imagemagick` (Ubuntu)) | ||
2. [Node JS > v6](https://nodejs.org/en/download/) | ||
3. [`libpq-dev` and `postgresql`](http://stackoverflow.com/questions/6040583/cant-find-the-libpq-fe-h-header-when-trying-to-install-pg-gem/6040822#6040822) | ||
|
||
### Setup | ||
|
||
0. `git clone https://github.com/FarmBot/Farmbot-Web-API` | ||
0. `cd Farmbot-Web-API` | ||
0. [Install `libpq-dev` and `postgresql`](http://stackoverflow.com/questions/6040583/cant-find-the-libpq-fe-h-header-when-trying-to-install-pg-gem/6040822#6040822) | ||
0. `bundle install` | ||
0. **MOST IMPORTANT STEP**. Copy `config/database.example.yml` to `config/database.yml`. In GNU/Linux or Mac: `mv config/database.example.yml config/database.yml`. **Please read the instructions inside the file. Replace the example values provided with real world values.** | ||
0. Give permission to create a database* | ||
0. `rake db:create:all db:migrate db:seed` | ||
0. (optional) Verify installation with `RAILS_ENV=test rake db:create db:migrate && rspec spec`. | ||
0. `MQTT_HOST=your_mqtt_server_domain rails s -b 0.0.0.0` where `your_mqtt_server_domain` is the IP or domain name of the MQTT server (see next step). The MQTT server does not need to be running yet. | ||
0. Now that the API server is running, [provision an MQTT server](https://github.com/FarmBot/mqtt-gateway). | ||
0. Initialize background workers in a seperate process: `rails jobs:work`. For production setups, this is a required step. | ||
0. (REQUIRES NODE JS > v6) Run `./install_frontend.sh` to build the latest frontend app. You may also run the frontend on a seperate server. The [frontend repository](https://github.com/FarmBot/farmbot-web-frontend) has more info on this if you wish to do so. For most users, `./install_frontend.sh` should be sufficient. | ||
0. Open [localhost:3000](http://localhost:3000). The application is now ready for use. | ||
0. [Raise an issue](https://github.com/FarmBot/Farmbot-Web-API/issues/new?title=Installation%20Failure) if you hit problems with any of these steps. | ||
|
||
\*Give permission to `user` to create database: | ||
``` | ||
sudo -u postgres createuser user | ||
sudo -u postgres psql | ||
ALTER USER "user" WITH SUPERUSER; | ||
[Weinre](https://www.npmjs.com/package/weinre) is included in this project. | ||
To utilize it, head over to the `/src` directory of the app, add a file called | ||
`config.json`, and populate it with this: | ||
``` | ||
|
||
# Q: Is Dokku / Docker supported? | ||
|
||
Doku (a Docker management system) is partially supported. Pull requests welcome. Please see `deployment.md` for more information. | ||
|
||
# Config Settings (important) | ||
|
||
We try our best to follow the [12 Factor Methodology](https://12factor.net/). Part of that means using ENV variables as a means of [storing configuration](https://12factor.net/config). **Your server won't run without setting ENV variables first**. | ||
|
||
You can accomplish this by setting the ENV variables directly from your shell / server management tool or by writing an `application.yml` file. | ||
|
||
See `config/application.example.yml` for a list of all the variables that must be set. | ||
|
||
**Encryption keys**: Encryption keys will be autogenerated if not present. They can be reset using `rake keys:generate`. If `ENV['RSA_KEY']` is set, it will be used in place of the `*.pem` files. Useful for environments like Heroku, where file system access is not allowed. | ||
|
||
**We can't fix issues we don't know about.** Please submit an issue if you are having trouble installing on your local machine. | ||
|
||
# Q: How can I Generate an API token? | ||
|
||
You must pass a `token` string into most HTTP requests under the `Authorization: ` request header. | ||
|
||
Here's what a response looks like when you request a token: | ||
|
||
```json | ||
{ | ||
"token": { | ||
"unencoded": { | ||
"sub": "[email protected]", | ||
"iat": 1459109728, | ||
"jti": "922a5a0d-0b3a-4767-9318-1e41ae600352", | ||
"iss": "http://localhost:3000/", | ||
"exp": 1459455328, | ||
"mqtt": "localhost", | ||
"bot": "aa7bb37f-5ba3-4654-b2e4-58ed5746508c" | ||
}, | ||
"encoded": | ||
// THE IMPORTANT PART IS HERE!!: | ||
"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJ0ZXN0MTIzQHRlc3QuY29tIiwiaWF0IjoxNDU5MTA5NzI4LCJqdGkiOiI5MjJhNWEwZC0wYjNhLTQ3NjctOTMxOC0xZTQxYWU2MDAzNTIiLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjMwMDAvIiwiZXhwIjoxNDU5NDU1MzI4LCJtcXR0IjoibG9jYWxob3N0IiwiYm90IjoiYWE3YmIzN2YtNWJhMy00NjU0LWIyZTQtNThlZDU3NDY1MDhjIn0.KpkNGR9YH68AF3iHP48GormqXzspBJrDGm23aMFGyL_eRIN8iKzy4gw733SaJgFjmebJOqZkz3cly9P5ZpCKwlaxAyn9RvfjQgFcUK0mywWAAvKp5lHfOFLhBBGICTW1r4HcZBgY1zTzVBw4BqS4zM7Y0BAAsflYRdl4dDRG_236p9ETCj0MSYxFagfLLLq0W63943jSJtNwv_nzfqi3TTi0xASB14k5vYMzUDXrC-Z2iBdgmwAYUZUVTi2HsfzkIkRcTZGE7l-rF6lvYKIiKpYx23x_d7xGjnQb8hqbDmLDRXZJnSBY3zGY7oEURxncGBMUp4F_Yaf3ftg4Ry7CiA" | ||
} | ||
"ip_address": "YOUR-IP-ADDRESS" | ||
} | ||
``` | ||
Then, in your console, `weinre --boundHost YOUR-IP-ADDRESS --httpPort 8081`. | ||
This should run in tandem with the rest of your project. | ||
Then navigate to http://YOUR-IP-ADDRESS:8081/client/#anonymous. | ||
After adding the `config.json`, you may be required to `npm start` again. | ||
|
||
**Important:** The response is provided as JSON for human readability. For your `Authorization` header, you will only be using `data.token.encoded`. In this example, it's the string starting with `eyJ0eXAiOiJ...` | ||
|
||
## Via CURL | ||
|
||
``` | ||
curl -H "Content-Type: application/json" \ | ||
-X POST \ | ||
-d '{"user":{"email":"[email protected]","password":"password123"}}' \ | ||
https://my.farmbot.io/api/tokens | ||
``` | ||
|
||
## Via JQuery | ||
|
||
Since the API supports [CORS](http://enable-cors.org/), you can generate your token right in the browser. | ||
|
||
Here's an example: | ||
# Want to Help? | ||
|
||
```javascript | ||
$.ajax({ | ||
url: "https://my.farmbot.io/api/tokens", | ||
type: "POST", | ||
data: JSON.stringify({user: {email: '[email protected]', password: 'password123'}}), | ||
contentType: "application/json", | ||
success: function (data) { | ||
// You can now use your token: | ||
var MY_SHINY_TOKEN = data.token.encoded; | ||
} | ||
}); | ||
``` | ||
Check out the [Low Hanging Fruit](https://github.com/FarmBot/farmbot-web-frontend/search?l=typescript&q=TODO&utf8=%E2%9C%93). | ||
|
||
Also, if you're experiencing UI/UX issues, please include any possible specifications (device type, device OS, and device browser) to help in the debugging process. Bonus points for GIFs and screenshots. :fist: | ||
|
||
# Want to Help? | ||
# Translating the app into your language | ||
Thanks for your interest in internationalizing the FarmBot web app! To add translations: | ||
|
||
[Low Hanging Fruit](https://github.com/FarmBot/Farmbot-Web-API/search?utf8=%E2%9C%93&q=todo). [Raise an issue](https://github.com/FarmBot/Farmbot-Web-API/issues/new?title=Question%20about%20a%20TODO) if you have any questions. | ||
1. Fork this repo | ||
2. Create a `yy.js` file in ``/public/app-resources/languages/`` where `yy` is your language's [language code](http://www.science.co.il/Language/Locale-codes.php). Eg: `ru` for Russian. If your language already has a file, then you can skip this step. | ||
3. Search the application for calls to `t()`. Any file that imports `from "i18next"` will have strings that require translation. | ||
4. When you have updated or added new translations, commit/push your changes and submit a pull request. |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.