Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Dave Scotese javascript #205

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 83 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Maps4All [![Circle CI](https://circleci.com/gh/hack4impact/maps4all.svg?style=svg)](https://circleci.com/gh/hack4impact/maps4all) [![Code Climate](https://codeclimate.com/github/hack4impact/maps4all/badges/gpa.svg)](https://codeclimate.com/github/hack4impact/maps4all) [![Test Coverage](https://codeclimate.com/github/hack4impact/maps4all/badges/coverage.svg)](https://codeclimate.com/github/hack4impact/maps4all/coverage) [![Issue Count](https://codeclimate.com/github/hack4impact/maps4all/badges/issue_count.svg)](https://codeclimate.com/github/hack4impact/maps4all)
# Maps4All [![Circle CI](https://circleci.com/gh/hack4impact/maps4all.svg?style=svg)](https://circleci.com/gh/hack4impact/maps4all) [![Code Climate](https://codeclimate.com/github/hack4impact/maps4all/badges/gpa.svg)](https://codeclimate.com/github/hack4impact/maps4all) [![Test Coverage](https://codeclimate.com/github/hack4impact/maps4all/badges/coverage.svg)](https://codeclimate.com/github/hack4impact/maps4all/coverage) [![Issue Count](https://codeclimate.com/github/hack4impact/maps4all/badges/issue_count.svg)](https://codeclimate.com/github/hack4impact/maps4all)

## Team Members

Expand All @@ -23,6 +23,16 @@ A generalized Flask application for displaying location-based resources on a map

## Setting up

If you have not yet done so, visit maps4all.org and create an account. This will guide you through the creation of your Heroku account and the installation of the Heroku tools.

### Windows 10

To develop locally on Windows 10, we (@sbue and myself, independently) used Windows Subsystem for Linux and additionally installed Heroku CLI in Ubuntu terminal and deployed with the client. This runs the app on Heroku servers, but you can run it locally too.

#### Editing local files

Check https://superuser.com/questions/1083962/windows-linux-subsystem-accessing-files-outside-of-ubuntu to see how you can deal with the fact that Windows' "subsystem for Linux" doesn't work very well when you edit files the Linux subsystem will use directly from Windows. It's best to go through the bash shell to create or edit files.

##### Clone the repo

```
Expand All @@ -31,7 +41,7 @@ $ cd maps4all
```

##### Initialize a virtualenv

```
$ pip install virtualenv
$ virtualenv -p python3 venv
Expand Down Expand Up @@ -134,77 +144,77 @@ Then navigate to `http://localhost:5000` on your preferred browser to open the w


```
├── Procfile
├── README.md
├── app
   ├── __init__.py
   ├── account
      ├── __init__.py
      ├── forms.py
      └── views.py
   ├── admin
      ├── __init__.py
      ├── forms.py
      └── views.py
   ├── assets
      ├── scripts
         ├── app.js
         └── vendor
         ├── jquery.min.js
         ├── semantic.min.js
         └── tablesort.min.js
      └── styles
      ├── app.scss
      └── vendor
      └── semantic.min.css
   ├── assets.py
   ├── decorators.py
   ├── email.py
   ├── main
      ├── __init__.py
      ├── errors.py
      ├── forms.py
      └── views.py
   ├── models.py
   ├── static
      ├── fonts
         └── vendor
      ├── images
      └── styles
         └── app.css
   ├── templates
      ├── account
         ├── email
         ├── login.html
         ├── manage.html
         ├── register.html
         ├── reset_password.html
         └── unconfirmed.html
      ├── admin
         ├── index.html
         ├── manage_user.html
         ├── new_user.html
         └── registered_users.html
      ├── errors
      ├── layouts
         └── base.html
      ├── macros
         ├── form_macros.html
         └── nav_macros.html
      ├── main
         └── index.html
      └── partials
      ├── _flashes.html
      └── _head.html
   └── utils.py
├── config.py
├── manage.py
├── requirements
   ├── common.txt
   └── dev.txt
└── tests
├── test_basics.py
└── test_user_model.py
??? Procfile
??? README.md
??? app
?   ??? __init__.py
?   ??? account
?   ?   ??? __init__.py
?   ?   ??? forms.py
?   ?   ??? views.py
?   ??? admin
?   ?   ??? __init__.py
?   ?   ??? forms.py
?   ?   ??? views.py
?   ??? assets
?   ?   ??? scripts
?   ?   ?   ??? app.js
?   ?   ?   ??? vendor
?   ?   ?   ??? jquery.min.js
?   ?   ?   ??? semantic.min.js
?   ?   ?   ??? tablesort.min.js
?   ?   ??? styles
?   ?   ??? app.scss
?   ?   ??? vendor
?   ?   ??? semantic.min.css
?   ??? assets.py
?   ??? decorators.py
?   ??? email.py
?   ??? main
?   ?   ??? __init__.py
?   ?   ??? errors.py
?   ?   ??? forms.py
?   ?   ??? views.py
?   ??? models.py
?   ??? static
?   ?   ??? fonts
?   ?   ?   ??? vendor
?   ?   ??? images
?   ?   ??? styles
?   ?      ??? app.css
?   ??? templates
?   ?   ??? account
?   ?   ?   ??? email
?   ?   ?   ??? login.html
?   ?   ?   ??? manage.html
?   ?   ?   ??? register.html
?   ?   ?   ??? reset_password.html
?   ?   ?   ??? unconfirmed.html
?   ?   ??? admin
?   ?   ?   ??? index.html
?   ?   ?   ??? manage_user.html
?   ?   ?   ??? new_user.html
?   ?   ?   ??? registered_users.html
?   ?   ??? errors
?   ?   ??? layouts
?   ?   ?   ??? base.html
?   ?   ??? macros
?   ?   ?   ??? form_macros.html
?   ?   ?   ??? nav_macros.html
?   ?   ??? main
?   ?   ?   ??? index.html
?   ?   ??? partials
?   ?   ??? _flashes.html
?   ?   ??? _head.html
?   ??? utils.py
??? config.py
??? manage.py
??? requirements
?   ??? common.txt
?   ??? dev.txt
??? tests
??? test_basics.py
??? test_user_model.py
```

## License
Expand Down
22 changes: 22 additions & 0 deletions app/admin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,28 @@ def change_site_style():
app_name=SiteAttribute.get_value("ORG_NAME"))


@admin.route('/customize-site/script', methods=['GET', 'POST'])
@login_required
@admin_required
def add_javascript():
"""Add to a site's javascript."""
if request.method == 'POST':
script_attr = SiteAttribute.get("EXTRA_SCRIPT")

url = request.form['url']
script_attr.value = url

db.session.add(script_attr)
db.session.commit()

flash('Custom javascript successfully uploaded or replaced.')

return redirect(url_for('admin.customize_site'))

return render_template('admin/customize_site.html',
app_name=SiteAttribute.get_value("ORG_NAME"))


@admin.route('/customize-site/twilio', methods=['GET', 'POST'])
@login_required
def change_twilio_credentials():
Expand Down
2 changes: 1 addition & 1 deletion app/assets/scripts/descriptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ $(document).ready(function () {

// This is for the new descriptor page
$("#desc_type").change(function() {
if ($(this).val() === "Option") {
if ($(this).val() === "option") {
$("#values-div").show();
} else {
$("#values-div").hide();
Expand Down
22 changes: 22 additions & 0 deletions app/templates/admin/customize_site.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
('admin.change_site_logo', 'Change logo'),
('admin.change_site_style', 'Change style'),
('admin.change_twilio_credentials', 'Change Twilio credentials'),
('admin.add_javascript', 'Add Javascript'),
] %}

{% macro navigation(items) %}
Expand Down Expand Up @@ -49,6 +50,11 @@ <h2 class="ui header">
<i class="upload icon"></i>
Upload
</button>
{% elif request.endpoint == 'admin.add_javascript' %}
<button onclick="openPickerScript()" class="ui labeled icon button">
<i class="upload icon"></i>
Upload
</button>
{% else %}
<table class="ui compact definition table">
<tr><td>Name</td><td>{{ app_name }}</td></tr>
Expand Down Expand Up @@ -120,6 +126,22 @@ <h2 class="ui header">
}
});
}

function openPickerScript() {
fsClient.pick({
fromSources:["local_file_system","googledrive","dropbox"],
maxFiles:1,
minFiles:1,
accept:[".js"],
startUploadingWhenMaxFilesReached: true,
}).then(function(response) {
if (response.filesFailed.length != 0) {
alert("An error occurred. Please share this with the developer: " + JSON.stringify(response));
} else {
post("{{ url_for('admin.add_javascript') }}", {'url': response.filesUploaded[0].url});
}
});
}
</script>

{% endblock %}
3 changes: 3 additions & 0 deletions app/templates/partials/_head.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
{% assets 'vendor_js' %}<script type="text/javascript" src="{{ ASSET_URL }}"></script>{% endassets %}
{% assets 'app_js' %}<script type="text/javascript" src="{{ ASSET_URL }}"></script>{% endassets %}

<!-- for custom javascript -->
<script type="text/javascript" src="{{ extra_script }}"></script>

<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css?family=Fjalla+One|Francois+One|Martel+Sans:900|Montserrat:900|Ruda|Vesper+Libre:900|Work+Sans:900" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Catamaran:300|Quicksand|Raleway:300|Work+Sans:300" rel="stylesheet">
Expand Down
3 changes: 2 additions & 1 deletion app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def inject_name():
return dict(site_name=SiteAttribute.get_value("ORG_NAME"),
logo_url=SiteAttribute.get_value("SITE_LOGO"),
style_timestamp=SiteAttribute.get_value("STYLE_TIME"),
style_sheet=SiteAttribute.get_value("STYLE_SHEET"))
style_sheet=SiteAttribute.get_value("STYLE_SHEET"),
extra_script=SiteAttribute.get_value("EXTRA_SCRIPT"))

app.add_template_global(index_for_role)

Expand Down
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Config:
RQ_DEFAULT_PASSWORD = url.password
RQ_DEFAULT_DB = 0

FILEPICKER_API_KEY = os.environ.get('FILEPICKER_API_KEY')
FILEPICKER_API_KEY = 'A3vAepVXiRleXVywQ8fkRzin' or os.environ.get('FILEPICKER_API_KEY')

@staticmethod
def init_app(app):
Expand Down